Package net.sf.lapg.templates.api.impl

Examples of net.sf.lapg.templates.api.impl.TemplatesFacade


    }
    if (options.isUseDefaultTemplates()) {
      loaders.add(new ClassTemplateLoader(getClass().getClassLoader(), "net/sf/lapg/gen/templates", "utf8"));
    }

    TemplatesFacade env = new TemplatesFacadeExt(new GrammarNavigationFactory(options.getTemplateName()), loaders.toArray(new IBundleLoader[loaders.size()]), notifier);
    EvaluationContext context = new EvaluationContext(map);
    context.setVariable("util", new TemplateStaticMethods());
    context.setVariable("$", "lapg_gg.sym");
    env.executeTemplate(options.getTemplateName() + ".main", context, null, null);
  }
View Full Code Here


  // loop.ltp
  public void testLoops() {
    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));

    // test 1
    String q = env.executeTemplate("loop.loop1", new EvaluationContext(h), null, null);
    Assert.assertEquals("Hmm: \n\n0: a\n1: b\n\n", q);

    // test 2
    q = env.executeTemplate("loop.loop2", new EvaluationContext(h), null, null);
    Assert.assertEquals("\nHmm: \n\n0: a\n1: b\n\n", q);

    // test 3
    h.put("list", new String[] {});
    q = env.executeTemplate("loop.loop2", new EvaluationContext(h), null, null);
    Assert.assertEquals("\nHmm: \n\n\n", q);
  }
View Full Code Here

    Assert.assertEquals("\nHmm: \n\n\n", q);
  }

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

    // test 1
    String q = env.executeTemplate("eval.eval1", null, null, null);
    Assert.assertEquals("w1 is bad\nw2 is bad\nt4 is bad\n", q);
  }
View Full Code Here

    Assert.assertEquals("w1 is bad\nw2 is bad\nt4 is bad\n", q);
  }

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

    // test 1
    String q = env.executeTemplate("query.a", new EvaluationContext(new Object()), null, null);
    Assert.assertEquals("\n123\n", q);
  }
View Full Code Here

    Assert.assertEquals("\n88 - 67\n99 - 45\n77 - 54\n\n", q);
  }

  // filter.ltp
  public void testMap() {
    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.map1", context, null, null);
    Assert.assertEquals("[nbsss -> a3,a45 -> 943q,ano -> yes]\n", q);
  }
View Full Code Here

    String q = env.executeTemplate("filter.map1", context, null, null);
    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);

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

    q = env.executeTemplate("filter.collectorStd", context, null, null);
    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

    String q = env.executeTemplate("filter.collector1", context, null, null);
    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);

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

    Assert.assertEquals("a -> yo1; daa -> yo2; xb -> yo3; 1a -> yo4; ", q);
  }

  // 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

  // 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);

    // test 2
    q = env.executeTemplate("format.useformat", context, null, null);
    Assert.assertEquals("\nstatic int a[] {\n  1,2,aa,4,5,\n6,7,8,9,10,\n11,12,13,14,\n15,16,17,19,\n20,21,22,23,\n24,25\n};\n\n", q);

    // test 3
    q = env.executeTemplate("format.useCall2", context, null, null);
    Assert.assertEquals("Table is mine\n", q);

    // test 4
    q = env.executeTemplate("format.useCall3", context, null, null);
    Assert.assertEquals("site is mine\n", q);
  }
View Full Code Here

TOP

Related Classes of net.sf.lapg.templates.api.impl.TemplatesFacade

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.