Search in sources :

Example 31 with JapidAbstractCompiler

use of cn.bran.japid.compiler.JapidAbstractCompiler in project Japid by branaway.

the class CompilerTests method testReverse.

@Test
public void testReverse() throws IOException {
    String path = "tests/reverse.html";
    String src = readFile(path);
    JapidTemplate bt = new JapidTemplate(path, src);
    JapidAbstractCompiler cp = new JapidTemplateCompiler();
    cp.compile(bt);
    String srccode = bt.javaSource;
    System.out.println(srccode);
    assertTrue("invalid java code", JavaSyntaxTool.isValid(srccode));
    assertTrue(srccode.contains("p(lookupStatic(\"/x/y.html\"))"));
    assertTrue(srccode.contains("p(lookupStatic(\"/a/b/c.html\"))"));
    assertTrue(srccode.contains("p(lookup(\"com.action\", \"ad\"))"));
}
Also used : JapidAbstractCompiler(cn.bran.japid.compiler.JapidAbstractCompiler) JapidTemplate(cn.bran.japid.template.JapidTemplate) JapidTemplateCompiler(cn.bran.japid.compiler.JapidTemplateCompiler) Test(org.junit.Test)

Example 32 with JapidAbstractCompiler

use of cn.bran.japid.compiler.JapidAbstractCompiler in project Japid by branaway.

the class CompilerTests method testOpenIfCommand.

@Test
public void testOpenIfCommand() throws IOException {
    String src = readFile("JapidSample/app/japidviews/Application/ifs2.html");
    JapidTemplate bt = new JapidTemplate("Application/ifs2.html", src);
    JapidAbstractCompiler cp = new JapidTemplateCompiler();
    cp.compile(bt);
    System.out.println(bt.javaSource);
    assertTrue("invalid java code", JavaSyntaxTool.isValid(bt.javaSource));
}
Also used : JapidAbstractCompiler(cn.bran.japid.compiler.JapidAbstractCompiler) JapidTemplate(cn.bran.japid.template.JapidTemplate) JapidTemplateCompiler(cn.bran.japid.compiler.JapidTemplateCompiler) Test(org.junit.Test)

Example 33 with JapidAbstractCompiler

use of cn.bran.japid.compiler.JapidAbstractCompiler in project Japid by branaway.

the class CompilerTests method testRecursiveTags.

@Test
public void testRecursiveTags() throws IOException {
    String srcFile = "tests/recursiveTagging.html";
    String src = readFile(srcFile);
    JapidTemplate bt = new JapidTemplate("tests/recursiveTagging.html", src);
    JapidAbstractCompiler cp = new JapidTemplateCompiler();
    cp.compile(bt);
    String code = bt.javaSource;
    System.out.println(code);
    assertTrue("invalid java code", JavaSyntaxTool.isValid(bt.javaSource));
    assertTrue(code.contains("new recursiveTagging(recursiveTagging.this).render"));
}
Also used : JapidAbstractCompiler(cn.bran.japid.compiler.JapidAbstractCompiler) JapidTemplate(cn.bran.japid.template.JapidTemplate) JapidTemplateCompiler(cn.bran.japid.compiler.JapidTemplateCompiler) Test(org.junit.Test)

Example 34 with JapidAbstractCompiler

use of cn.bran.japid.compiler.JapidAbstractCompiler in project Japid by branaway.

the class CompilerTests method testNamedParams.

@Test
public void testNamedParams() throws IOException, ParseException {
    String srcFile = "tests/namedParam.html";
    String src = readFile(srcFile);
    JapidTemplate bt = new JapidTemplate("tests/namedParam.html", src);
    JapidAbstractCompiler cp = new JapidTemplateCompiler();
    cp.compile(bt);
    System.out.println(bt.javaSource);
    assertTrue("invalid java code", JavaSyntaxTool.isValid(bt.javaSource));
    assertTrue(bt.javaSource.contains("new person(namedParam.this).render(named(\"name\", \"Bing\"), named(\"age\", foo(18)))"));
//		assertTrue(bt.javaSource.contains("@Override protected void title() {"));
}
Also used : JapidAbstractCompiler(cn.bran.japid.compiler.JapidAbstractCompiler) JapidTemplate(cn.bran.japid.template.JapidTemplate) JapidTemplateCompiler(cn.bran.japid.compiler.JapidTemplateCompiler) Test(org.junit.Test)

Example 35 with JapidAbstractCompiler

use of cn.bran.japid.compiler.JapidAbstractCompiler in project Japid by branaway.

the class CompilerTests method testAnotherLayout.

@Test
public void testAnotherLayout() throws IOException, ParseException {
    String src = readFile("JapidSample/app/japidviews/_layouts/TagLayout.html");
    JapidTemplate bt = new JapidTemplate("japidviews/_layouts/TagLayout.html", src);
    JapidAbstractCompiler cp = new JapidLayoutCompiler();
    cp.compile(bt);
    String srccode = bt.javaSource;
    System.out.println(srccode);
    CompilationUnit cu = JavaSyntaxTool.parse(srccode);
    assertTrue(srccode.contains("package japidviews._layouts;"));
    assertTrue(srccode.contains("public abstract class TagLayout extends cn.bran.play.JapidTemplateBase"));
    assertTrue(srccode.contains("protected abstract void doLayout();"));
    assertTrue(srccode.contains("@Override public void layout()"));
}
Also used : CompilationUnit(japa.parser.ast.CompilationUnit) JapidAbstractCompiler(cn.bran.japid.compiler.JapidAbstractCompiler) JapidTemplate(cn.bran.japid.template.JapidTemplate) JapidLayoutCompiler(cn.bran.japid.compiler.JapidLayoutCompiler) Test(org.junit.Test)

Aggregations

JapidAbstractCompiler (cn.bran.japid.compiler.JapidAbstractCompiler)39 JapidTemplate (cn.bran.japid.template.JapidTemplate)39 Test (org.junit.Test)39 JapidTemplateCompiler (cn.bran.japid.compiler.JapidTemplateCompiler)29 CompilationUnit (japa.parser.ast.CompilationUnit)12 JapidLayoutCompiler (cn.bran.japid.compiler.JapidLayoutCompiler)10 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1