Search in sources :

Example 1 with ClassDecl

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

the class WizardUtilsTests method testValidateClass.

@Test
public void testValidateClass() {
    ModuleDecl mockDecl = mock(ModuleDecl.class);
    List<Decl> list = new List<Decl>();
    ClassDecl m1 = mock(ClassDecl.class);
    ClassDecl m2 = mock(ClassDecl.class);
    when(m1.getName()).thenReturn("Class1");
    when(m2.getName()).thenReturn("Class2");
    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 = "Class1";
    String invalid7 = "Class2";
    assertTrue(validateClass(valid1, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateClass(valid2, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateClass(valid3, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateClass(invalid1, mockDecl).equals(ErrorType.ERROR_NO_NAME));
    assertTrue(validateClass(invalid2, mockDecl).equals(ErrorType.ERROR_NO_UPPER_CASE));
    assertTrue(validateClass(invalid3, mockDecl).equals(ErrorType.ERROR_NO_UPPER_CASE));
    assertTrue(validateClass(invalid4, mockDecl).equals(ErrorType.ERROR_INVALID_NAME));
    assertTrue(validateClass(invalid5, mockDecl).equals(ErrorType.ERROR_KEYWORD));
    assertTrue(validateClass(invalid6, mockDecl).equals(ErrorType.ERROR_DUPLICATE_NAME));
    assertTrue(validateClass(invalid7, mockDecl).equals(ErrorType.ERROR_DUPLICATE_NAME));
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) 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) Test(org.junit.Test)

Example 2 with ClassDecl

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

the class StringBasedABSTestRunnerGenerator method generateMainBlock.

private TestRunnerScriptBuilder generateMainBlock(TestRunnerScriptBuilder imports) {
    TestRunnerScriptBuilder builder = new TestRunnerScriptBuilder();
    builder.increaseIndent();
    Set<Type> paramNames = new HashSet<>();
    builder.append("Set<Fut<Unit>> ").append(futs).append(" = EmptySet;").newLine();
    builder.append("Fut<Unit> ").append(fut).append(";").newLine();
    for (InterfaceDecl key : tests.keySet()) {
        builder.append("//Test cases for ").append(key.getType().getQualifiedName()).newLine();
        for (ClassDecl clazz : tests.get(key)) {
            builder.append("//Test cases for implementation ").append(clazz.getName()).newLine();
            paramNames.addAll(generateTestClassImpl(key, clazz, builder));
        }
    }
    generateWaitSync(builder);
    generateImports(imports, paramNames);
    return builder;
}
Also used : Type(abs.frontend.typechecker.Type) ClassDecl(abs.frontend.ast.ClassDecl) InterfaceDecl(abs.frontend.ast.InterfaceDecl) HashSet(java.util.HashSet)

Example 3 with ClassDecl

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

the class TraitTest method removeExistingMethodInClassSucc.

@Test
public void removeExistingMethodInClassSucc() {
    Model model = assertParseOk("module M;" + "trait T = {Unit myMethod(){skip;}}  " + "class C {uses T removes Unit myMethod();;  }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    model.applyTraits();
    assertTrue(cls.getMethods().getNumChild() == 0);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) Test(org.junit.Test)

Example 4 with ClassDecl

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

the class TraitTest method frameTest.

@Test
public void frameTest() {
    Model model = assertParseOk("module M;" + " interface I { Unit x(); Unit foo(); Unit bar(); }" + " trait T = Unit x() { this.foo(); original(); this.bar();  }" + " trait T2 = { Unit x() { println(\"T2\"); } } modifies T" + " trait T3 = { Unit x() { println(\"T3\"); } } modifies T" + " class C implements I {" + "         Int i = 0;" + "         uses T2;" + "         Unit foo(){ i = i+1; }" + "         Unit bar(){ i = i-1; }" + " }" + " class C2 implements I {" + "         Int i = 0;" + "         uses T3;" + "         Unit foo(){ i = i-1; }" + "         Unit bar(){ i = i+1; }" + " }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 2);
    model.applyTraits();
    assertTrue(cls.getMethods().getNumChild() == 4);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) Test(org.junit.Test)

Example 5 with ClassDecl

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

the class TraitTest method removeExistingMethodInTrait.

@Test(expected = DeltaModellingException.class)
public void removeExistingMethodInTrait() {
    Model model = assertParseOk("module M; " + " trait T = {} removes Unit myMethod();" + " class C {uses T; Unit myMethod(){ println(\"\"); } }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 1);
    model.applyTraits();
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) Test(org.junit.Test)

Aggregations

ClassDecl (abs.frontend.ast.ClassDecl)75 Test (org.junit.Test)59 Model (abs.frontend.ast.Model)57 DeltaDecl (abs.frontend.ast.DeltaDecl)22 FrontendTest (abs.frontend.FrontendTest)12 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)12 SkipStmt (abs.frontend.ast.SkipStmt)11 DeltaTraitModifier (abs.frontend.ast.DeltaTraitModifier)7 InterfaceDecl (abs.frontend.ast.InterfaceDecl)7 MethodImpl (abs.frontend.ast.MethodImpl)7 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)7 TraitExpr (abs.frontend.ast.TraitExpr)7 MethodSig (abs.frontend.ast.MethodSig)6 ReturnStmt (abs.frontend.ast.ReturnStmt)6 AddMethodModifier (abs.frontend.ast.AddMethodModifier)5 Decl (abs.frontend.ast.Decl)5 DeltaAccess (abs.frontend.ast.DeltaAccess)5 List (abs.frontend.ast.List)5 TraitSetExpr (abs.frontend.ast.TraitSetExpr)5 CompilationUnit (abs.frontend.ast.CompilationUnit)4