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