Search in sources :

Example 1 with ReprExpression

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

the class PythonTreeMakerTest method repr_expression.

@Test
public void repr_expression() {
    setRootRule(PythonGrammar.ATOM);
    ReprExpression reprExpressionTree = (ReprExpression) parse("`1`", treeMaker::expression);
    assertThat(reprExpressionTree.getKind()).isEqualTo(Tree.Kind.REPR);
    assertThat(reprExpressionTree.firstToken().value()).isEqualTo("`");
    assertThat(reprExpressionTree.lastToken().value()).isEqualTo("`");
    assertThat(reprExpressionTree.openingBacktick().value()).isEqualTo("`");
    assertThat(reprExpressionTree.closingBacktick().value()).isEqualTo("`");
    assertThat(reprExpressionTree.expressionList().expressions()).hasSize(1);
    assertThat(reprExpressionTree.expressionList().expressions().get(0).getKind()).isEqualTo(Tree.Kind.NUMERIC_LITERAL);
    assertThat(reprExpressionTree.children()).hasSize(3);
    reprExpressionTree = (ReprExpression) parse("`x, y`", treeMaker::expression);
    assertThat(reprExpressionTree.getKind()).isEqualTo(Tree.Kind.REPR);
    assertThat(reprExpressionTree.expressionList().expressions()).hasSize(2);
    assertThat(reprExpressionTree.expressionList().children()).hasSize(3);
    assertThat(reprExpressionTree.expressionList().commas()).hasSize(1);
    assertThat(reprExpressionTree.expressionList().commas().get(0)).isSameAs(reprExpressionTree.expressionList().children().get(1));
    assertThat(reprExpressionTree.expressionList().expressions().get(0).getKind()).isEqualTo(Tree.Kind.NAME);
    assertThat(reprExpressionTree.expressionList().expressions().get(1).getKind()).isEqualTo(Tree.Kind.NAME);
}
Also used : ReprExpression(org.sonar.plugins.python.api.tree.ReprExpression) Test(org.junit.Test) RuleTest(org.sonar.python.parser.RuleTest)

Aggregations

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