Search in sources :

Example 11 with ProductDecl

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

the class ProductDeclarationTest method complexExpression.

@Test
public void complexExpression() throws WrongProgramArgumentException {
    Model model = assertParse("product P1 = {F1, F2, F3} && {F3, F4} || {F5, F6} - {F6};");
    model.evaluateAllProductDeclarations();
    ProductDecl p = model.findProduct("P1");
    Product impl = p.getProduct();
    assertEquals(2, impl.getNumFeature());
    Set<String> expected = new HashSet<>(Arrays.asList("F3", "F5"));
    Set<String> actual = new HashSet<>();
    for (Feature f : impl.getFeatures()) actual.add(f.getName());
    assertEquals(expected, actual);
}
Also used : ProductDecl(org.abs_models.frontend.ast.ProductDecl) Model(org.abs_models.frontend.ast.Model) Product(org.abs_models.frontend.ast.Product) Feature(org.abs_models.frontend.ast.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with ProductDecl

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

the class ProductDeclarationTest method validProduct.

@Test
public void validProduct() throws WrongProgramArgumentException {
    Model model = assertParse("product P1 = {F1, F2, F3};" + "root FM {" + "group allof { F1, F2, F3 }" + "}");
    model.evaluateAllProductDeclarations();
    ProductDecl p = model.findProduct("P1");
    SemanticConditionList e = new SemanticConditionList();
    typeCheck(model, p, e);
    assertEquals(0, e.getErrorCount());
}
Also used : ProductDecl(org.abs_models.frontend.ast.ProductDecl) SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) Model(org.abs_models.frontend.ast.Model) Test(org.junit.Test)

Example 13 with ProductDecl

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

the class ProductDeclarationTest method unorderedProduct.

@Test
public void unorderedProduct() throws WrongProgramArgumentException {
    Model model = assertParse("product P2 = P1;" + "product P3 = P2;" + "product P1 = {F1, F2, F3};");
    model.evaluateAllProductDeclarations();
    ProductDecl p = model.findProduct("P3");
    Product impl = p.getProduct();
    assertEquals(3, impl.getNumFeature());
    Set<String> expected = new HashSet<>(Arrays.asList("F1", "F2", "F3"));
    Set<String> actual = new HashSet<>();
    for (Feature f : impl.getFeatures()) actual.add(f.getName());
    assertEquals(expected, actual);
}
Also used : ProductDecl(org.abs_models.frontend.ast.ProductDecl) Model(org.abs_models.frontend.ast.Model) Product(org.abs_models.frontend.ast.Product) Feature(org.abs_models.frontend.ast.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with ProductDecl

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

the class ProductDeclarationTest method undeclaredProduct.

// FIXME: The correct error message is emitted, but via throwing an
// exception instead of reporting it in the condition list.  Additionally,
// the WrongProgramArgumentException is re-thrown as a RuntimeException.
// The proper fix is to just add an error to the SemanticConditionList
// instead of throwing an exception
// @Test(expected=org.abs_models.common.WrongProgramArgumentException.class)
@Test(expected = java.lang.RuntimeException.class)
public void undeclaredProduct() throws WrongProgramArgumentException {
    Model model = assertParse("product P1 = P2 && P3 || P4 || {F1, F2};");
    ProductDecl p = model.findProduct("P1");
    SemanticConditionList e = new SemanticConditionList();
    typeCheck(model, p, e);
    assertEquals(3, e.getErrorCount());
    Assert.assertEquals(ErrorMessage.UNDECLARED_PRODUCT, e.getFirstError().msg);
}
Also used : ProductDecl(org.abs_models.frontend.ast.ProductDecl) SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) Model(org.abs_models.frontend.ast.Model) Test(org.junit.Test)

Example 15 with ProductDecl

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

the class ProductDeclarationTest method productFeatureSet.

@Test
public void productFeatureSet() throws WrongProgramArgumentException {
    Model model = assertParse("product P1 = {F1, F2, F3};");
    model.evaluateAllProductDeclarations();
    ProductDecl p = model.findProduct("P1");
    Product impl = p.getProduct();
    assertEquals(3, impl.getNumFeature());
    Set<String> expected = new HashSet<>(Arrays.asList("F1", "F2", "F3"));
    Set<String> actual = new HashSet<>();
    for (Feature f : impl.getFeatures()) actual.add(f.getName());
    assertEquals(expected, actual);
}
Also used : ProductDecl(org.abs_models.frontend.ast.ProductDecl) Model(org.abs_models.frontend.ast.Model) Product(org.abs_models.frontend.ast.Product) Feature(org.abs_models.frontend.ast.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ProductDecl (org.abs_models.frontend.ast.ProductDecl)19 Model (org.abs_models.frontend.ast.Model)17 Test (org.junit.Test)16 HashSet (java.util.HashSet)11 Feature (org.abs_models.frontend.ast.Feature)10 Product (org.abs_models.frontend.ast.Product)9 SemanticConditionList (org.abs_models.frontend.analyser.SemanticConditionList)4 WrongProgramArgumentException (org.abs_models.common.WrongProgramArgumentException)3 ProductLine (org.abs_models.frontend.ast.ProductLine)3 Constraint (choco.kernel.model.constraints.Constraint)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 InternalBackendException (org.abs_models.backend.common.InternalBackendException)1 FrontendTest (org.abs_models.frontend.FrontendTest)1 DataConstructor (org.abs_models.frontend.ast.DataConstructor)1 DataConstructorExp (org.abs_models.frontend.ast.DataConstructorExp)1 DataTypeDecl (org.abs_models.frontend.ast.DataTypeDecl)1 Decl (org.abs_models.frontend.ast.Decl)1 ExpFunctionDef (org.abs_models.frontend.ast.ExpFunctionDef)1