public void ParserBinaryExpressionHonornsPrecedences(SyntaxKind op1, SyntaxKind op2) { int op1Precedence = SyntaxFacts.GetBinaryOperatorPrecedence(op1); int op2Precedence = SyntaxFacts.GetBinaryOperatorPrecedence(op2); string op1Text = SyntaxFacts.GetText(op1); string op2Text = SyntaxFacts.GetText(op2); string text = $"a {op1Text} b {op2Text} c"; ExpressionSyntax expression = ParseExpression(text); if (op1Precedence >= op2Precedence) { using (var e = new AssertingEnumerator(expression)) { e.AssertNode(SyntaxKind.BinaryExpression); e.AssertNode(SyntaxKind.BinaryExpression); e.AssertNode(SyntaxKind.NameExpression); e.AssertToken(SyntaxKind.IdentifierToken, "a"); e.AssertToken(op1, op1Text); e.AssertNode(SyntaxKind.NameExpression); e.AssertToken(SyntaxKind.IdentifierToken, "b"); e.AssertToken(op2, op2Text); e.AssertNode(SyntaxKind.NameExpression); e.AssertToken(SyntaxKind.IdentifierToken, "c"); } } else { using (var e = new AssertingEnumerator(expression)) { e.AssertNode(SyntaxKind.BinaryExpression); e.AssertNode(SyntaxKind.NameExpression); e.AssertToken(SyntaxKind.IdentifierToken, "a"); e.AssertToken(op1, op1Text); e.AssertNode(SyntaxKind.BinaryExpression); e.AssertNode(SyntaxKind.NameExpression); e.AssertToken(SyntaxKind.IdentifierToken, "b"); e.AssertToken(op2, op2Text); e.AssertNode(SyntaxKind.NameExpression); e.AssertToken(SyntaxKind.IdentifierToken, "c"); } } }
public void ParserUnaryExpressionHonornsPrecedences(SyntaxKind unaryKind, SyntaxKind binaryKind) { int unaryPrecedence = SyntaxFacts.GetUnaryOperatorPrecedence(unaryKind); int binaryPrecedence = SyntaxFacts.GetBinaryOperatorPrecedence(binaryKind); string unaryText = SyntaxFacts.GetText(unaryKind); string binaryText = SyntaxFacts.GetText(binaryKind); string text = $"{unaryText} a {binaryText} b"; ExpressionSyntax expression = ParseExpression(text); if (unaryPrecedence >= binaryPrecedence) { using (var e = new AssertingEnumerator(expression)) { e.AssertNode(SyntaxKind.BinaryExpression); e.AssertNode(SyntaxKind.UnaryExpression); e.AssertToken(unaryKind, unaryText); e.AssertNode(SyntaxKind.NameExpression); e.AssertToken(SyntaxKind.IdentifierToken, "a"); e.AssertToken(binaryKind, binaryText); e.AssertNode(SyntaxKind.NameExpression); e.AssertToken(SyntaxKind.IdentifierToken, "b"); } } else { using (var e = new AssertingEnumerator(expression)) { e.AssertNode(SyntaxKind.UnaryExpression); e.AssertToken(unaryKind, unaryText); e.AssertNode(SyntaxKind.BinaryExpression); e.AssertNode(SyntaxKind.NameExpression); e.AssertToken(SyntaxKind.IdentifierToken, "a"); e.AssertToken(binaryKind, binaryText); e.AssertNode(SyntaxKind.NameExpression); e.AssertToken(SyntaxKind.IdentifierToken, "b"); } } }