Search in sources :

Example 1 with AwaitExpression

use of org.sonar.plugins.python.api.tree.AwaitExpression in project sonar-python by SonarSource.

the class PythonTreeMakerTest method await_expression.

@Test
public void await_expression() {
    setRootRule(PythonGrammar.TEST);
    AwaitExpression expr = (AwaitExpression) parse("await x", treeMaker::expression);
    assertThat(expr.getKind()).isEqualTo(Tree.Kind.AWAIT);
    assertThat(expr.awaitToken().value()).isEqualTo("await");
    assertThat(expr.expression().getKind()).isEqualTo(Tree.Kind.NAME);
    assertThat(expr.children()).hasSize(2);
    BinaryExpression awaitWithPower = binaryExpression("await a ** 3");
    assertThat(awaitWithPower.getKind()).isEqualTo(Tree.Kind.POWER);
    assertThat(awaitWithPower.leftOperand().getKind()).isEqualTo(Tree.Kind.AWAIT);
    assertThat(awaitWithPower.rightOperand().getKind()).isEqualTo(Tree.Kind.NUMERIC_LITERAL);
}
Also used : AwaitExpression(org.sonar.plugins.python.api.tree.AwaitExpression) BinaryExpression(org.sonar.plugins.python.api.tree.BinaryExpression) Test(org.junit.Test) RuleTest(org.sonar.python.parser.RuleTest)

Aggregations

Test (org.junit.Test)1 AwaitExpression (org.sonar.plugins.python.api.tree.AwaitExpression)1 BinaryExpression (org.sonar.plugins.python.api.tree.BinaryExpression)1 RuleTest (org.sonar.python.parser.RuleTest)1