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