use of org.sonar.plugins.python.api.tree.ComprehensionIf in project sonar-python by SonarSource.
the class PythonTreeMakerTest method list_comprehension_with_if.
@Test
public void list_comprehension_with_if() {
setRootRule(PythonGrammar.TEST);
ComprehensionExpression comprehension = (ComprehensionExpression) parse("[x+1 for x in [42, 43] if x%2==0]", treeMaker::expression);
assertThat(comprehension.getKind()).isEqualTo(Tree.Kind.LIST_COMPREHENSION);
ComprehensionFor forClause = comprehension.comprehensionFor();
assertThat(forClause.nestedClause().getKind()).isEqualTo(Tree.Kind.COMP_IF);
ComprehensionIf ifClause = (ComprehensionIf) forClause.nestedClause();
assertThat(ifClause.ifToken().value()).isEqualTo("if");
assertThat(ifClause.condition().getKind()).isEqualTo(Tree.Kind.COMPARISON);
assertThat(ifClause.nestedClause()).isNull();
assertThat(ifClause.children()).hasSize(2);
}
Aggregations