Search in sources :

Example 11 with Decl

use of abs.frontend.ast.Decl in project abstools by abstools.

the class WizardUtilsTests method testValidateInterface.

@Test
public void testValidateInterface() {
    ModuleDecl mockDecl = mock(ModuleDecl.class);
    List<Decl> list = new List<Decl>();
    InterfaceDecl m1 = mock(InterfaceDecl.class);
    InterfaceDecl m2 = mock(InterfaceDecl.class);
    when(m1.getName()).thenReturn("Interface1");
    when(m2.getName()).thenReturn("Interface2");
    list.add(m1);
    list.add(m2);
    when(mockDecl.getDecls()).thenReturn(list);
    String valid1 = "A";
    String valid2 = "Abc3";
    String valid3 = "ABC3";
    String invalid1 = "";
    String invalid2 = "a";
    String invalid3 = "a.b";
    String invalid4 = ";";
    String invalid5 = "module";
    String invalid6 = "Interface1";
    String invalid7 = "Interface2";
    assertTrue(validateInterface(valid1, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateInterface(valid2, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateInterface(valid3, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateInterface(invalid1, mockDecl).equals(ErrorType.ERROR_NO_NAME));
    assertTrue(validateInterface(invalid2, mockDecl).equals(ErrorType.ERROR_NO_UPPER_CASE));
    assertTrue(validateInterface(invalid3, mockDecl).equals(ErrorType.ERROR_NO_UPPER_CASE));
    assertTrue(validateInterface(invalid4, mockDecl).equals(ErrorType.ERROR_INVALID_NAME));
    assertTrue(validateInterface(invalid5, mockDecl).equals(ErrorType.ERROR_KEYWORD));
    assertTrue(validateInterface(invalid6, mockDecl).equals(ErrorType.ERROR_DUPLICATE_NAME));
    assertTrue(validateInterface(invalid7, mockDecl).equals(ErrorType.ERROR_DUPLICATE_NAME));
}
Also used : ModuleDecl(abs.frontend.ast.ModuleDecl) InterfaceDecl(abs.frontend.ast.InterfaceDecl) ModuleDecl(abs.frontend.ast.ModuleDecl) ClassDecl(abs.frontend.ast.ClassDecl) Decl(abs.frontend.ast.Decl) List(abs.frontend.ast.List) InterfaceDecl(abs.frontend.ast.InterfaceDecl) Test(org.junit.Test)

Example 12 with Decl

use of abs.frontend.ast.Decl in project abstools by abstools.

the class PartialFunctionTest method assertHasFunction.

private FunctionDecl assertHasFunction(Model model, String regex) {
    FunctionDecl result = getFunction(model, Pattern.compile(regex));
    String errorMessage = "No expanded function with name " + regex + " created" + " (functions: " + getFunctions(model) + ")";
    assertNotNull(errorMessage, result);
    Decl decl = model.lookup(new KindedName(Kind.FUN, result.getName()));
    assertFalse("Could not lookup function " + result.getName(), decl.isUnknown());
    return result;
}
Also used : PartialFunctionDecl(abs.frontend.ast.PartialFunctionDecl) FunctionDecl(abs.frontend.ast.FunctionDecl) Decl(abs.frontend.ast.Decl) KindedName(abs.frontend.typechecker.KindedName) PartialFunctionDecl(abs.frontend.ast.PartialFunctionDecl) FunctionDecl(abs.frontend.ast.FunctionDecl)

Example 13 with Decl

use of abs.frontend.ast.Decl in project abstools by abstools.

the class RecoverTest method assertContainsDeclWithName.

private void assertContainsDeclWithName(Model m, String name) {
    boolean found = false;
    for (Decl d : m.getCompilationUnit(0).getModuleDecl(0).getDecls()) {
        if (d.getName().equals(name)) {
            found = true;
        }
    }
    assertTrue("Did not found decl with name " + name, found);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Decl(abs.frontend.ast.Decl)

Example 14 with Decl

use of abs.frontend.ast.Decl in project abstools by abstools.

the class DeltaAddFunctionalTest method addDataType.

@Test
public void addDataType() throws DeltaModellingException {
    Model model = assertParseOk("module M;" + "data O = O;" + "delta I; uses M;" + "adds data X<A> = X(A a) | N;" + "adds data Y = K | Y(Int i);");
    Decl dataO = findDecl(model, "M", "O");
    assertNotNull(dataO);
    assertThat(dataO, instanceOf(DataTypeDecl.class));
    DeltaDecl delta = findDelta(model, "I");
    assertNotNull(delta);
    assertThat(delta, instanceOf(DeltaDecl.class));
    Decl dataX = findDecl(model, "M", "X");
    assertNull(dataX);
    Decl dataY = findDecl(model, "M", "Y");
    assertNull(dataY);
    model.applyDelta(delta);
    dataX = findDecl(model, "M", "X");
    assertNotNull(dataX);
    assertThat(dataX, instanceOf(ParametricDataTypeDecl.class));
    dataY = findDecl(model, "M", "Y");
    assertNotNull(dataY);
    assertThat(dataY, instanceOf(DataTypeDecl.class));
}
Also used : Model(abs.frontend.ast.Model) DataTypeDecl(abs.frontend.ast.DataTypeDecl) ParametricDataTypeDecl(abs.frontend.ast.ParametricDataTypeDecl) TypeSynDecl(abs.frontend.ast.TypeSynDecl) FunctionDecl(abs.frontend.ast.FunctionDecl) Decl(abs.frontend.ast.Decl) DeltaDecl(abs.frontend.ast.DeltaDecl) DeltaDecl(abs.frontend.ast.DeltaDecl) ParametricDataTypeDecl(abs.frontend.ast.ParametricDataTypeDecl) DataTypeDecl(abs.frontend.ast.DataTypeDecl) ParametricDataTypeDecl(abs.frontend.ast.ParametricDataTypeDecl) Test(org.junit.Test)

Example 15 with Decl

use of abs.frontend.ast.Decl in project abstools by abstools.

the class DeltaAddFunctionalTest method addTypeSyn.

@Test
public void addTypeSyn() throws DeltaModellingException {
    Model model = assertParseOk("module M;" + "type X = Int;" + "delta I; uses M;" + "adds type Y = X;");
    Decl typeX = findDecl(model, "M", "X");
    assertNotNull(typeX);
    assertThat(typeX, instanceOf(TypeSynDecl.class));
    DeltaDecl delta = findDelta(model, "I");
    assertNotNull(delta);
    assertThat(delta, instanceOf(DeltaDecl.class));
    Decl typeY = findDecl(model, "M", "Y");
    assertNull(typeY);
    model.applyDelta(delta);
    typeY = findDecl(model, "M", "Y");
    assertNotNull(typeY);
    assertThat(typeY, instanceOf(TypeSynDecl.class));
}
Also used : Model(abs.frontend.ast.Model) DataTypeDecl(abs.frontend.ast.DataTypeDecl) ParametricDataTypeDecl(abs.frontend.ast.ParametricDataTypeDecl) TypeSynDecl(abs.frontend.ast.TypeSynDecl) FunctionDecl(abs.frontend.ast.FunctionDecl) Decl(abs.frontend.ast.Decl) DeltaDecl(abs.frontend.ast.DeltaDecl) DeltaDecl(abs.frontend.ast.DeltaDecl) TypeSynDecl(abs.frontend.ast.TypeSynDecl) Test(org.junit.Test)

Aggregations

Decl (abs.frontend.ast.Decl)17 ClassDecl (abs.frontend.ast.ClassDecl)9 InterfaceDecl (abs.frontend.ast.InterfaceDecl)8 ModuleDecl (abs.frontend.ast.ModuleDecl)7 DataTypeDecl (abs.frontend.ast.DataTypeDecl)6 ParametricDataTypeDecl (abs.frontend.ast.ParametricDataTypeDecl)6 TypeSynDecl (abs.frontend.ast.TypeSynDecl)6 Test (org.junit.Test)6 FunctionDecl (abs.frontend.ast.FunctionDecl)5 Model (abs.frontend.ast.Model)4 AbsASTBuilderUtil.getDecl (abs.backend.tests.AbsASTBuilderUtil.getDecl)3 DeltaDecl (abs.frontend.ast.DeltaDecl)3 TypeParameterDecl (abs.frontend.ast.TypeParameterDecl)3 List (abs.frontend.ast.List)2 MainBlock (abs.frontend.ast.MainBlock)2 HasCogs (abs.frontend.analyser.HasCogs)1 Annotation (abs.frontend.ast.Annotation)1 Block (abs.frontend.ast.Block)1 CompilationUnit (abs.frontend.ast.CompilationUnit)1 DataTypeUse (abs.frontend.ast.DataTypeUse)1