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);
}
Aggregations