Search in sources :

Example 1 with SubstituteArrayLengthTemplate

use of spoon.test.template.testclasses.SubstituteArrayLengthTemplate in project spoon by INRIA.

the class TemplateArrayAccessTest method testArrayLengthAccess.

@Test
public void testArrayLengthAccess() throws Exception {
    // contract: the template engine replaces length of collection of parameter values by number
    Launcher spoon = new Launcher();
    spoon.addTemplateResource(new FileSystemFile("./src/test/java/spoon/test/template/testclasses/SubstituteArrayLengthTemplate.java"));
    spoon.buildModel();
    Factory factory = spoon.getFactory();
    CtClass<?> resultKlass = factory.Class().create("Result");
    CtStatement result = new SubstituteArrayLengthTemplate(new String[] { "a", null, "b" }).apply(resultKlass);
    assertEquals("if (3 > 0);", result.toString());
}
Also used : CtStatement(spoon.reflect.code.CtStatement) Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) FileSystemFile(spoon.support.compiler.FileSystemFile) SubstituteArrayLengthTemplate(spoon.test.template.testclasses.SubstituteArrayLengthTemplate) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Launcher (spoon.Launcher)1 CtStatement (spoon.reflect.code.CtStatement)1 Factory (spoon.reflect.factory.Factory)1 FileSystemFile (spoon.support.compiler.FileSystemFile)1 SubstituteArrayLengthTemplate (spoon.test.template.testclasses.SubstituteArrayLengthTemplate)1