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