Search in sources :

Example 1 with PatternVarDecl

use of org.abs_models.frontend.ast.PatternVarDecl in project abstools by abstools.

the class VarResolutionTest method testNestedPatternVar.

@Test
public void testNestedPatternVar() {
    Model m = assertParse("data Foo = Bar(Bool); def Bool m(Foo f) = case f { Bar(y) => y; };");
    assertThat(getFirstCaseExpr(m), instanceOf(VarUse.class));
    ConstructorPattern p = (ConstructorPattern) getFirstCasePattern(m);
    PatternVarDecl decl = ((PatternVar) p.getParam(0)).getVar();
    assertEquals("y", decl.getName());
}
Also used : Model(org.abs_models.frontend.ast.Model) PatternVar(org.abs_models.frontend.ast.PatternVar) VarUse(org.abs_models.frontend.ast.VarUse) PatternVarDecl(org.abs_models.frontend.ast.PatternVarDecl) ConstructorPattern(org.abs_models.frontend.ast.ConstructorPattern) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 2 with PatternVarDecl

use of org.abs_models.frontend.ast.PatternVarDecl in project abstools by abstools.

the class VarResolutionTest method testPatternVar.

@Test
public void testPatternVar() {
    Model m = assertParse(" def Bool f(Bool b) = case b { True => False; x => !x; };");
    NegExp ne = (NegExp) getSecondCaseExpr(m);
    VarUse v = (VarUse) ne.getOperand();
    PatternVarDecl decl = (PatternVarDecl) v.getDecl();
    assertEquals("x", decl.getName());
}
Also used : NegExp(org.abs_models.frontend.ast.NegExp) Model(org.abs_models.frontend.ast.Model) VarUse(org.abs_models.frontend.ast.VarUse) PatternVarDecl(org.abs_models.frontend.ast.PatternVarDecl) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Aggregations

FrontendTest (org.abs_models.frontend.FrontendTest)2 Model (org.abs_models.frontend.ast.Model)2 PatternVarDecl (org.abs_models.frontend.ast.PatternVarDecl)2 VarUse (org.abs_models.frontend.ast.VarUse)2 Test (org.junit.Test)2 ConstructorPattern (org.abs_models.frontend.ast.ConstructorPattern)1 NegExp (org.abs_models.frontend.ast.NegExp)1 PatternVar (org.abs_models.frontend.ast.PatternVar)1