Package net.sf.lapg.templates.api

Examples of net.sf.lapg.templates.api.EvaluationContext


    Assert.assertEquals("[nbsss -> a3,a45 -> 943q,ano -> yes]\n", q);
  }

  public void testCollect() {
    TemplatesFacade env = new TestTemplatesFacade(new DefaultNavigationFactory(), new ClassTemplateLoader(getClass().getClassLoader(), TEMPLATES_LOCATION, TEMPLATES_CHARSET));
    EvaluationContext context = new EvaluationContext(null);
    context.setVariable("util", new DefaultStaticMethods());

    // test 1
    String q = env.executeTemplate("filter.collectorUnique", context, null, null);
    Assert.assertEquals("1A BB C D ", q);
View Full Code Here


    Assert.assertEquals("1A BB BB C D D C ", q);
  }

  public void testCollectMap() {
    TemplatesFacade env = new TestTemplatesFacade(new DefaultNavigationFactory(), new ClassTemplateLoader(getClass().getClassLoader(), TEMPLATES_LOCATION, TEMPLATES_CHARSET));
    EvaluationContext context = new EvaluationContext(null);
    context.setVariable("util", new DefaultStaticMethods());

    // test 1
    String q = env.executeTemplate("filter.collector1", context, null, null);
    Assert.assertEquals("[1a -> 1A,Bb -> BB,c -> C,d -> D]", q);
  }
View Full Code Here

    Assert.assertEquals("[1a -> 1A,Bb -> BB,c -> C,d -> D]", q);
  }

  public void testSort() {
    TemplatesFacade env = new TestTemplatesFacade(new DefaultNavigationFactory(), new ClassTemplateLoader(getClass().getClassLoader(), TEMPLATES_LOCATION, TEMPLATES_CHARSET));
    EvaluationContext context = new EvaluationContext(null);
    context.setVariable("util", new DefaultStaticMethods());

    // test 1
    String q = env.executeTemplate("filter.sorted1", context, null, null);
    Assert.assertEquals("1a -> yo4; a -> yo1; daa -> yo2; xb -> yo3; ", q);
View Full Code Here

  // arithm.ltp
  public void testArithm() {
    TemplatesFacade env = new TestTemplatesFacade(new DefaultNavigationFactory(), new ClassTemplateLoader(getClass().getClassLoader(), TEMPLATES_LOCATION, TEMPLATES_CHARSET));

    // test 1
    String q = env.executeTemplate("arithm.arithm1", new EvaluationContext(null), null, null);
    Assert.assertEquals("\n2 = 2\n\n", q);

    // test 2
    q = env.executeTemplate("arithm.arithm2", new EvaluationContext(null), null, null);
    Assert.assertEquals("\n10 = 10\n\n", q);

    // test 3
    q = env.executeTemplate("arithm.arithm3", new EvaluationContext(null), null, null);
    Assert.assertEquals("\n-1 = -1\n\n", q);

    // test 4
    q = env.executeTemplate("arithm.arithm4", new EvaluationContext(null), null, null);
    Assert.assertEquals("2 = 2\n", q);

    // test 5
    q = env.executeTemplate("arithm.arithm5", new EvaluationContext(null), null, null);
    Assert.assertEquals("true false true true false -2\n", q);

    // test 6
    q = env.executeTemplate("arithm.arithm6", new EvaluationContext(null), null, null);
    Assert.assertEquals("uh: lite1\noh: okey\n", q);
  }
View Full Code Here

    // test 1
    env.addErrors("Evaluation of `l` failed for java.util.Hashtable: null");
    env.addErrors("Assertion `list.length > 5` failed for java.util.Hashtable");
    env.addErrors("Assertion `list[1] == 'w4'` failed for java.util.Hashtable");
    env.executeTemplate("assert.assertit", new EvaluationContext(h), null, null);
    env.assertEmptyErrors();
  }
View Full Code Here

  // TODO split call & format
  public void testCall() {
    Hashtable<String,String[]> h = new Hashtable<String,String[]>();
    h.put("list", new String[] { "a", "b" });
    TemplatesFacade env = new TestTemplatesFacade(new DefaultNavigationFactory(), new ClassTemplateLoader(getClass().getClassLoader(), TEMPLATES_LOCATION, TEMPLATES_CHARSET));
    EvaluationContext context = new EvaluationContext(h);
    context.setVariable("util", new DefaultStaticMethods());

    // test 1
    String q = env.executeTemplate("format.callTempl", context, null, null);
    Assert.assertEquals("\nstatic int a[] {\n  0,\n1,\n2,\n3\n};\n\n", q);
View Full Code Here

    Hashtable<String,String[]> h = new Hashtable<String,String[]>();
    h.put("list", new String[] { "a", "b" });
    TemplatesFacade env = new TestTemplatesFacade(new DefaultNavigationFactory(),
        new StringTemplateLoader("inline", "${template overrides.my2}go next my2(${call base})\n\n${end}"),
        new ClassTemplateLoader(getClass().getClassLoader(), TEMPLATES_LOCATION, TEMPLATES_CHARSET));
    EvaluationContext context = new EvaluationContext(h);
    context.setVariable("util", new DefaultStaticMethods());

    // test 1
    String q = env.executeTemplate("overrides.my1", context, null, null);
    Assert.assertEquals("my1\n", q);
View Full Code Here

  public void testOverrides2() {
    TestTemplatesFacade env = new TestTemplatesFacade(new DefaultNavigationFactory(),
        new StringTemplateLoader("inline", "${template overrides.my1(aa)}go next my1\n\n${end}"),
        new ClassTemplateLoader(getClass().getClassLoader(), TEMPLATES_LOCATION, TEMPLATES_CHARSET));
    EvaluationContext context = new EvaluationContext(null);

    // test 1
    env.addErrors("Template `my1(aa)` is not compatible with base template `my1`");
    env.addErrors("Wrong number of arguments used while calling `my1(aa)`: should be 1 instead of 0");
    String q = env.executeTemplate("overrides.my1", context, null, null);
View Full Code Here

      @Override
      public void createFile(String name, String contents) {
        fileContent.put(name, contents);
      }
    };
    EvaluationContext context = new EvaluationContext(new String[] { "aa", "bb" });

    // test 1
    String q = env.executeTemplate("file.file1", context, null, null);
    Assert.assertEquals("", q);
    Assert.assertEquals("Next\n", fileContent.get("aaaa.txt"));
View Full Code Here

  // switch.ltp
  public void testSwitch() {
    final Map<String,Object> this_ = new HashMap<String,Object>();
    this_.put("aa", new Integer(11));
    TemplatesFacade env = new TestTemplatesFacade(new DefaultNavigationFactory(), new ClassTemplateLoader(getClass().getClassLoader(), TEMPLATES_LOCATION, TEMPLATES_CHARSET));
    EvaluationContext context = new EvaluationContext(this_);

    // test 1
    String q = env.executeTemplate("switch.check1", context, null, null);
    Assert.assertEquals("Yo", q);
View Full Code Here

TOP

Related Classes of net.sf.lapg.templates.api.EvaluationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.