Search in sources :

Example 1 with FunctionDecl

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

the class ParFnAppTest method sameAnonTwiceTwoExpansions.

@Test
public void sameAnonTwiceTwoExpansions() {
    Model m = testExpand(parse("apply((Int i) => i)(1);" + "apply((Int i) => i)(1);", applyFunction()));
    ModuleDecl module = m.lookupModule("UnitTest");
    int foundExpansions = 0;
    for (Decl decl : module.getDecls()) {
        if (decl instanceof FunctionDecl) {
            FunctionDecl fun = (FunctionDecl) decl;
            if (fun.getName().startsWith("Apply_")) {
                ++foundExpansions;
            }
        }
    }
    assertEquals(2, foundExpansions);
}
Also used : Model(abs.frontend.ast.Model) ModuleDecl(abs.frontend.ast.ModuleDecl) ModuleDecl(abs.frontend.ast.ModuleDecl) FunctionDecl(abs.frontend.ast.FunctionDecl) Decl(abs.frontend.ast.Decl) FunctionDecl(abs.frontend.ast.FunctionDecl) Test(org.junit.Test)

Example 2 with FunctionDecl

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

the class ParFnAppTest method sameAnonTwiceTwoClosureParams.

@Test
public void sameAnonTwiceTwoClosureParams() {
    Model m = testExpand(parse("Int x = 1; test(() => x, () => x)();", "def Int test(f, g)() = f() + g();"), "Test_%s_Anon\\d+");
    FunctionDecl function = getFunction(m, Pattern.compile(expandedName("Test_%s_Anon\\d+")));
    assertNotNull(function);
    assertEquals(2, function.getNumParam());
    assertEquals("X0", function.getParam(0).getName());
    assertEquals("X1", function.getParam(1).getName());
}
Also used : Model(abs.frontend.ast.Model) FunctionDecl(abs.frontend.ast.FunctionDecl) Test(org.junit.Test)

Example 3 with FunctionDecl

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

the class TreeUtilsTest method findChildrenList.

@Test
public void findChildrenList() {
    Model model = assertParseOkStdLib("def Int test(Int i) = test(1);");
    FunctionDecl functionDecl = getLastFunctionDecl(model);
    assertEquals("test", functionDecl.getName());
    List<PureExp> children = functionDecl.getFunctionDef().findChildren(PureExp.class);
    assertEquals(2, children.size());
}
Also used : Model(abs.frontend.ast.Model) PureExp(abs.frontend.ast.PureExp) FunctionDecl(abs.frontend.ast.FunctionDecl) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 4 with FunctionDecl

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

the class TreeUtilsTest method findChildrenMultipleTypes.

@Test
public void findChildrenMultipleTypes() {
    Model model = assertParseOkStdLib("def Int test(Int i) = test(1);");
    FunctionDecl functionDecl = getLastFunctionDecl(model);
    assertEquals("test", functionDecl.getName());
    FunctionDef def = functionDecl.getFunctionDef();
    Stream<PureExp> children = def.findChildren(cast(ImmutableList.of(FnApp.class, IntLiteral.class)), n -> true);
    assertNotNull(children);
    List<PureExp> result = children.distinct().collect(Collectors.toList());
    assertEquals(2, result.size());
    for (PureExp exp : result) {
        assertTrue(exp instanceof FnApp || exp instanceof IntLiteral);
    }
}
Also used : FnApp(abs.frontend.ast.FnApp) Model(abs.frontend.ast.Model) FunctionDef(abs.frontend.ast.FunctionDef) ExpFunctionDef(abs.frontend.ast.ExpFunctionDef) IntLiteral(abs.frontend.ast.IntLiteral) PureExp(abs.frontend.ast.PureExp) FunctionDecl(abs.frontend.ast.FunctionDecl) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 5 with FunctionDecl

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

the class ABSUnitTestCaseTranslator method createTestSuiteForFunction.

/**
 * Create a test suite for testing a function.
 *
 * @param testCases
 * @param testInterface
 * @param className
 * @param functionName
 */
private void createTestSuiteForFunction(List<TestCase> testCases, InterfaceDecl testInterface, String functionName) {
    // create test class ([Suite])
    final ClassDecl testClass = translatorHelper.createTestClass(testInterface);
    module.addDecl(testClass);
    // find function under test
    FunctionDecl functionUnderTest = getDecl(model, FunctionDecl.class, new DeclNamePredicate<FunctionDecl>(functionName));
    final Access access = functionUnderTest.getTypeUse();
    importModules.add(functionUnderTest.getModuleDecl().getName());
    /*
		 * Test methods and Test cases are ordered that is,
		 * test case 1 is implemented by test method 1 and so on...
		 */
    for (int i = 0; i < testCases.size(); i++) {
        console("Generating test case " + i + "...");
        TestCase testCase = testCases.get(i);
        MethodImpl method = testClass.getMethod(i);
        functionBuilder.buildTestCase(testCase, testClass, method, access, functionName);
    }
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) AbsASTBuilderUtil.findMethodImpl(abs.backend.tests.AbsASTBuilderUtil.findMethodImpl) MethodImpl(abs.frontend.ast.MethodImpl) TestCase(apet.testCases.TestCase) Access(abs.frontend.ast.Access) DeltaAccess(abs.frontend.ast.DeltaAccess) FunctionDecl(abs.frontend.ast.FunctionDecl)

Aggregations

FunctionDecl (abs.frontend.ast.FunctionDecl)18 Model (abs.frontend.ast.Model)12 Test (org.junit.Test)12 FrontendTest (abs.frontend.FrontendTest)10 PureExp (abs.frontend.ast.PureExp)8 ExpFunctionDef (abs.frontend.ast.ExpFunctionDef)6 Decl (abs.frontend.ast.Decl)3 FnApp (abs.frontend.ast.FnApp)3 FunctionDef (abs.frontend.ast.FunctionDef)3 IntLiteral (abs.frontend.ast.IntLiteral)2 Stmt (abs.frontend.ast.Stmt)2 ABSBuiltInFunctions (abs.backend.java.lib.runtime.ABSBuiltInFunctions)1 AbsASTBuilderUtil.findMethodImpl (abs.backend.tests.AbsASTBuilderUtil.findMethodImpl)1 NotImplementedYetException (abs.common.NotImplementedYetException)1 TypeError (abs.frontend.analyser.TypeError)1 ASTNode (abs.frontend.ast.ASTNode)1 Access (abs.frontend.ast.Access)1 AddExp (abs.frontend.ast.AddExp)1 ClassDecl (abs.frontend.ast.ClassDecl)1 DeltaAccess (abs.frontend.ast.DeltaAccess)1