Search in sources :

Example 16 with FunctionNode

use of com.google.template.soy.exprtree.FunctionNode in project closure-templates by google.

the class TemplateParserTest method testParseDelegateCallStmt.

@SuppressWarnings({ "ConstantConditions" })
@Test
public void testParseDelegateCallStmt() throws Exception {
    String templateBody = "{@param animals : ?}{@param too : ?}\n" + "  {delcall booTemplate /}\n" + "  {delcall foo.goo.mooTemplate data=\"all\" /}\n" + "  {delcall MySecretFeature.zooTemplate data=\"$animals\"}\n" + "    {param yoo: round($too) /}\n" + "    {param woo kind=\"html\"}poo{/param}\n" + "  {/delcall}\n";
    List<StandaloneNode> nodes = parseTemplateContent(templateBody, FAIL).getChildren();
    assertEquals(3, nodes.size());
    CallDelegateNode cn0 = (CallDelegateNode) nodes.get(0);
    assertEquals("booTemplate", cn0.getDelCalleeName());
    assertEquals(false, cn0.isPassingData());
    assertEquals(false, cn0.isPassingAllData());
    assertEquals(null, cn0.getDataExpr());
    assertEquals("XXX", cn0.genBasePhName());
    assertEquals(0, cn0.numChildren());
    CallDelegateNode cn1 = (CallDelegateNode) nodes.get(1);
    assertEquals("foo.goo.mooTemplate", cn1.getDelCalleeName());
    assertEquals(true, cn1.isPassingData());
    assertEquals(true, cn1.isPassingAllData());
    assertEquals(null, cn1.getDataExpr());
    assertFalse(cn1.genSamenessKey().equals(cn0.genSamenessKey()));
    assertEquals(0, cn1.numChildren());
    CallDelegateNode cn2 = (CallDelegateNode) nodes.get(2);
    assertEquals("MySecretFeature.zooTemplate", cn2.getDelCalleeName());
    assertEquals(true, cn2.isPassingData());
    assertEquals(false, cn2.isPassingAllData());
    assertTrue(cn2.getDataExpr().getRoot() != null);
    assertEquals("$animals", cn2.getDataExpr().toSourceString());
    assertEquals(2, cn2.numChildren());
    CallParamValueNode cn2cpvn0 = (CallParamValueNode) cn2.getChild(0);
    assertEquals("yoo", cn2cpvn0.getKey().identifier());
    assertEquals("round($too)", cn2cpvn0.getExpr().toSourceString());
    assertTrue(cn2cpvn0.getExpr().getRoot() instanceof FunctionNode);
    CallParamContentNode cn2cpcn1 = (CallParamContentNode) cn2.getChild(1);
    assertEquals("woo", cn2cpcn1.getKey().identifier());
    assertEquals("poo", ((RawTextNode) cn2cpcn1.getChild(0)).getRawText());
}
Also used : StandaloneNode(com.google.template.soy.soytree.SoyNode.StandaloneNode) CallParamContentNode(com.google.template.soy.soytree.CallParamContentNode) FunctionNode(com.google.template.soy.exprtree.FunctionNode) CallParamValueNode(com.google.template.soy.soytree.CallParamValueNode) CallDelegateNode(com.google.template.soy.soytree.CallDelegateNode) Test(org.junit.Test)

Example 17 with FunctionNode

use of com.google.template.soy.exprtree.FunctionNode in project closure-templates by google.

the class ResolvePackageRelativeCssNamesVisitorTest method testBaseCssOnNamespace.

@Test
public void testBaseCssOnNamespace() {
    TemplateNode template = compileTemplate("{namespace boo cssbase=\"some.test.package\"}\n\n" + "/** Test template.*/\n" + "{template .foo}\n" + "  <p class=\"{css('%AAA')}\">\n" + "{/template}\n");
    PrintNode printNode = Iterables.getOnlyElement(SoyTreeUtils.getAllNodesOfType(template, PrintNode.class));
    FunctionNode cssFn = (FunctionNode) printNode.getExpr().getRoot();
    assertThat(((StringNode) cssFn.getChild(0)).getValue()).isEqualTo("someTestPackageAAA");
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) FunctionNode(com.google.template.soy.exprtree.FunctionNode) StringNode(com.google.template.soy.exprtree.StringNode) PrintNode(com.google.template.soy.soytree.PrintNode) Test(org.junit.Test)

Example 18 with FunctionNode

use of com.google.template.soy.exprtree.FunctionNode in project closure-templates by google.

the class ResolvePackageRelativeCssNamesVisitorTest method testBaseCssOnTemplate.

@Test
public void testBaseCssOnTemplate() {
    TemplateNode template = compileTemplate("{namespace boo}\n\n" + "/** Test template.  */\n" + "{template .foo cssbase=\"some.test.package\"}\n" + "  <p class=\"{css('%AAA')}\">\n" + "{/template}\n");
    PrintNode printNode = Iterables.getOnlyElement(SoyTreeUtils.getAllNodesOfType(template, PrintNode.class));
    FunctionNode cssFn = (FunctionNode) printNode.getExpr().getRoot();
    assertThat(((StringNode) cssFn.getChild(0)).getValue()).isEqualTo("someTestPackageAAA");
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) FunctionNode(com.google.template.soy.exprtree.FunctionNode) StringNode(com.google.template.soy.exprtree.StringNode) PrintNode(com.google.template.soy.soytree.PrintNode) Test(org.junit.Test)

Example 19 with FunctionNode

use of com.google.template.soy.exprtree.FunctionNode in project closure-templates by google.

the class ResolvePackageRelativeCssNamesVisitorTest method testUnprefixedNode.

@Test
public void testUnprefixedNode() {
    TemplateNode template = compileTemplate("{namespace boo cssbase=\"some.test.package\"}\n\n" + "/** Test template. */\n" + "{template .foo}\n" + "  <p class=\"{css('AAA')}\">\n" + "{/template}\n");
    PrintNode printNode = Iterables.getOnlyElement(SoyTreeUtils.getAllNodesOfType(template, PrintNode.class));
    FunctionNode cssFn = (FunctionNode) printNode.getExpr().getRoot();
    assertThat(((StringNode) cssFn.getChild(0)).getValue()).isEqualTo("AAA");
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) FunctionNode(com.google.template.soy.exprtree.FunctionNode) StringNode(com.google.template.soy.exprtree.StringNode) PrintNode(com.google.template.soy.soytree.PrintNode) Test(org.junit.Test)

Example 20 with FunctionNode

use of com.google.template.soy.exprtree.FunctionNode in project closure-templates by google.

the class InferenceEngineTest method assertTransitions.

private static void assertTransitions(SanitizedContentKind kind, String src) {
    TemplateNode template = SoyFileSetParserBuilder.forFileContents("{namespace ns}\n{template .foo" + (kind == SanitizedContentKind.HTML ? "" : " kind=\"" + Ascii.toLowerCase(kind.toString()) + '"') + " stricthtml=\"false\"}" + src + "{/template}").addSoyFunction(new AssertFunction()).desugarHtmlNodes(false).parse().fileSet().getChild(0).getChild(0);
    Inferences inferences = new Inferences(new IncrementingIdGenerator(), ImmutableListMultimap.<String, TemplateNode>of());
    InferenceEngine.inferTemplateEndContext(template, Context.getStartContextForContentKind(kind), inferences, ErrorReporter.exploding());
    for (PrintNode print : SoyTreeUtils.getAllNodesOfType(template, PrintNode.class)) {
        if (print.getExpr().getChild(0) instanceof FunctionNode) {
            FunctionNode fn = (FunctionNode) print.getExpr().getChild(0);
            if (fn.getSoyFunction() instanceof AssertFunction) {
                assertWithMessage("expected print node at " + print.getSourceLocation() + " to have context").that(contextString(inferences.getContextForNode(print))).isEqualTo(((StringNode) fn.getChild(0)).getValue());
            }
        }
    }
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) FunctionNode(com.google.template.soy.exprtree.FunctionNode) IncrementingIdGenerator(com.google.template.soy.base.internal.IncrementingIdGenerator) PrintNode(com.google.template.soy.soytree.PrintNode)

Aggregations

FunctionNode (com.google.template.soy.exprtree.FunctionNode)20 PrintNode (com.google.template.soy.soytree.PrintNode)8 StringNode (com.google.template.soy.exprtree.StringNode)7 Test (org.junit.Test)7 TemplateNode (com.google.template.soy.soytree.TemplateNode)6 ExprNode (com.google.template.soy.exprtree.ExprNode)5 IntegerNode (com.google.template.soy.exprtree.IntegerNode)4 RawTextNode (com.google.template.soy.soytree.RawTextNode)3 StandaloneNode (com.google.template.soy.soytree.SoyNode.StandaloneNode)3 SourceLocation (com.google.template.soy.base.SourceLocation)2 VarRefNode (com.google.template.soy.exprtree.VarRefNode)2 LoggingFunction (com.google.template.soy.logging.LoggingFunction)2 CallParamContentNode (com.google.template.soy.soytree.CallParamContentNode)2 CallParamValueNode (com.google.template.soy.soytree.CallParamValueNode)2 SoyType (com.google.template.soy.types.SoyType)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 IncrementingIdGenerator (com.google.template.soy.base.internal.IncrementingIdGenerator)1 CopyState (com.google.template.soy.basetree.CopyState)1 SyntaxVersionUpperBound (com.google.template.soy.basetree.SyntaxVersionUpperBound)1 ParentExprNode (com.google.template.soy.exprtree.ExprNode.ParentExprNode)1