Search in sources :

Example 6 with CallBasicNode

use of com.google.template.soy.soytree.CallBasicNode in project closure-templates by google.

the class TemplateParserTest method testParseCallStmtWithPhname.

@SuppressWarnings({ "ConstantConditions" })
@Test
public void testParseCallStmtWithPhname() throws Exception {
    String templateBody = "{@param animals:?}\n" + "{msg desc=\"...\"}\n" + "  {call .booTemplate_ phname=\"booTemplate_\" /}\n" + "  {call .booTemplate_ phname=\"booTemplate_\" /}\n" + "  {delcall MySecretFeature.zooTemplate data=\"$animals\" phname=\"secret_zoo\"}\n" + "    {param zoo: 0 /}\n" + "  {/delcall}\n" + "{/msg}";
    List<StandaloneNode> nodes = ((MsgFallbackGroupNode) parseTemplateContent(templateBody, FAIL).getChild(0)).getChild(0).getChildren();
    assertEquals(3, nodes.size());
    CallBasicNode cn0 = (CallBasicNode) ((MsgPlaceholderNode) nodes.get(0)).getChild(0);
    assertEquals("BOO_TEMPLATE", cn0.genBasePhName());
    assertEquals("brittle.test.ns.booTemplate_", cn0.getCalleeName());
    assertEquals(".booTemplate_", cn0.getSourceCalleeName());
    assertEquals(false, cn0.isPassingData());
    assertEquals(false, cn0.isPassingAllData());
    assertEquals(null, cn0.getDataExpr());
    assertEquals(0, cn0.numChildren());
    CallBasicNode cn1 = (CallBasicNode) ((MsgPlaceholderNode) nodes.get(1)).getChild(0);
    CallDelegateNode cn2 = (CallDelegateNode) ((MsgPlaceholderNode) nodes.get(2)).getChild(0);
    assertEquals("SECRET_ZOO", cn2.genBasePhName());
    assertEquals("MySecretFeature.zooTemplate", cn2.getDelCalleeName());
    assertEquals(true, cn2.isPassingData());
    assertEquals(false, cn2.isPassingAllData());
    assertTrue(cn2.getDataExpr().getRoot() != null);
    assertEquals("$animals", cn2.getDataExpr().toSourceString());
    assertEquals(1, cn2.numChildren());
    // CallNodes are never same
    assertFalse(cn0.genSamenessKey().equals(cn1.genSamenessKey()));
    assertFalse(cn2.genSamenessKey().equals(cn0.genSamenessKey()));
}
Also used : StandaloneNode(com.google.template.soy.soytree.SoyNode.StandaloneNode) CallBasicNode(com.google.template.soy.soytree.CallBasicNode) CallDelegateNode(com.google.template.soy.soytree.CallDelegateNode) Test(org.junit.Test)

Example 7 with CallBasicNode

use of com.google.template.soy.soytree.CallBasicNode in project closure-templates by google.

the class TemplateParserTest method testParseBasicCallStmt.

@SuppressWarnings({ "ConstantConditions" })
@Test
public void testParseBasicCallStmt() throws Exception {
    String templateBody = "{@param too : ?}{@param animals: ?}\n" + "  {call .booTemplate_ /}\n" + "  {call foo.goo.mooTemplate data=\"all\" /}\n" + "  {call .booTemplate_ /}\n" + "  {call .zooTemplate data=\"$animals\"}\n" + "    {param yoo: round($too) /}\n" + "    {param woo kind=\"html\"}poo{/param}\n" + "    {param zoo: 0 /}\n" + "    {param doo kind=\"html\"}doopoo{/param}\n" + "  {/call}\n";
    List<StandaloneNode> nodes = parseTemplateContent(templateBody, FAIL).getChildren();
    assertThat(nodes).hasSize(4);
    CallBasicNode cn0 = (CallBasicNode) nodes.get(0);
    assertEquals("brittle.test.ns.booTemplate_", cn0.getCalleeName());
    assertEquals(".booTemplate_", cn0.getSourceCalleeName());
    assertEquals(false, cn0.isPassingData());
    assertEquals(false, cn0.isPassingAllData());
    assertEquals(null, cn0.getDataExpr());
    assertEquals("XXX", cn0.genBasePhName());
    assertEquals(0, cn0.numChildren());
    CallBasicNode cn1 = (CallBasicNode) nodes.get(1);
    assertEquals("foo.goo.mooTemplate", cn1.getCalleeName());
    assertEquals("foo.goo.mooTemplate", cn1.getSourceCalleeName());
    assertEquals(true, cn1.isPassingData());
    assertEquals(true, cn1.isPassingAllData());
    assertEquals(null, cn1.getDataExpr());
    assertFalse(cn1.genSamenessKey().equals(cn0.genSamenessKey()));
    assertEquals(0, cn1.numChildren());
    CallBasicNode cn2 = (CallBasicNode) nodes.get(2);
    assertEquals("brittle.test.ns.booTemplate_", cn2.getCalleeName());
    assertEquals(".booTemplate_", cn2.getSourceCalleeName());
    assertFalse(cn2.isPassingData());
    assertEquals(false, cn2.isPassingAllData());
    assertEquals(null, cn2.getDataExpr());
    assertEquals("XXX", cn2.genBasePhName());
    assertEquals(0, cn2.numChildren());
    CallBasicNode cn3 = (CallBasicNode) nodes.get(3);
    assertEquals("brittle.test.ns.zooTemplate", cn3.getCalleeName());
    assertEquals(".zooTemplate", cn3.getSourceCalleeName());
    assertEquals(true, cn3.isPassingData());
    assertEquals(false, cn3.isPassingAllData());
    assertTrue(cn3.getDataExpr().getRoot() != null);
    assertEquals("$animals", cn3.getDataExpr().toSourceString());
    assertEquals(4, cn3.numChildren());
    {
        final CallParamValueNode cn4cpvn0 = (CallParamValueNode) cn3.getChild(0);
        assertEquals("yoo", cn4cpvn0.getKey().identifier());
        assertEquals("round($too)", cn4cpvn0.getExpr().toSourceString());
        assertTrue(cn4cpvn0.getExpr().getRoot() instanceof FunctionNode);
    }
    {
        final CallParamContentNode cn4cpcn1 = (CallParamContentNode) cn3.getChild(1);
        assertEquals("woo", cn4cpcn1.getKey().identifier());
        assertEquals(SanitizedContentKind.HTML, cn4cpcn1.getContentKind());
        assertEquals("poo", ((RawTextNode) cn4cpcn1.getChild(0)).getRawText());
    }
    {
        final CallParamValueNode cn4cpvn2 = (CallParamValueNode) cn3.getChild(2);
        assertEquals("zoo", cn4cpvn2.getKey().identifier());
        assertEquals("0", cn4cpvn2.getExpr().toSourceString());
    }
    {
        final CallParamContentNode cn4cpcn3 = (CallParamContentNode) cn3.getChild(3);
        assertEquals("doo", cn4cpcn3.getKey().identifier());
        assertNotNull(cn4cpcn3.getContentKind());
        assertEquals(SanitizedContentKind.HTML, cn4cpcn3.getContentKind());
        assertEquals("doopoo", ((RawTextNode) cn4cpcn3.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) CallBasicNode(com.google.template.soy.soytree.CallBasicNode) RawTextNode(com.google.template.soy.soytree.RawTextNode) Test(org.junit.Test)

Example 8 with CallBasicNode

use of com.google.template.soy.soytree.CallBasicNode in project closure-templates by google.

the class FindCalleesNotInFileVisitorTest method testFindCalleesNotInFile.

@Test
public void testFindCalleesNotInFile() {
    String testFileContent = "" + "{namespace boo.foo}\n" + "\n" + "/** Test template 1. */\n" + "{template .goo autoescape=\"deprecated-noncontextual\"}\n" + "  {call .goo data=\"all\" /}\n" + "  {call .moo data=\"all\" /}\n" + "  {call boo.woo.hoo data=\"all\" /}\n" + // not defined in this file
    "{/template}\n" + "\n" + "/** Test template 2. */\n" + "{template .moo autoescape=\"deprecated-noncontextual\"}\n" + "  {for $i in range(8)}\n" + "    {call boo.foo.goo data=\"all\" /}\n" + "    {call .too data=\"all\" /}\n" + // not defined in this file
    "    {call .goo}" + "      {param a}{call .moo /}{/param}" + "      {param b}{call .zoo /}{/param}" + // not defined in this file
    "    {/call}" + "  {/for}\n" + "{/template}\n" + "\n" + "/** Test template 3. */\n" + "{deltemplate booHoo autoescape=\"deprecated-noncontextual\"}\n" + "  {call .goo data=\"all\" /}\n" + "  {call .moo data=\"all\" /}\n" + "  {call boo.hoo.roo data=\"all\" /}\n" + // not defined in this file
    "{/deltemplate}\n";
    ErrorReporter boom = ErrorReporter.exploding();
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(testFileContent).errorReporter(boom).parse().fileSet();
    SoyFileNode soyFile = soyTree.getChild(0);
    Iterable<String> calleesNotInFile = Iterables.transform(new FindCalleesNotInFileVisitor().exec(soyFile), CallBasicNode::getCalleeName);
    assertThat(calleesNotInFile).containsExactly("boo.woo.hoo", "boo.foo.too", "boo.foo.zoo", "boo.hoo.roo");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) CallBasicNode(com.google.template.soy.soytree.CallBasicNode) SoyFileNode(com.google.template.soy.soytree.SoyFileNode) Test(org.junit.Test)

Aggregations

CallBasicNode (com.google.template.soy.soytree.CallBasicNode)8 CallDelegateNode (com.google.template.soy.soytree.CallDelegateNode)3 Test (org.junit.Test)3 StandaloneNode (com.google.template.soy.soytree.SoyNode.StandaloneNode)2 HashSet (java.util.HashSet)2 SanitizedContentKind (com.google.template.soy.base.internal.SanitizedContentKind)1 ErrorReporter (com.google.template.soy.error.ErrorReporter)1 ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)1 FunctionNode (com.google.template.soy.exprtree.FunctionNode)1 VarRefNode (com.google.template.soy.exprtree.VarRefNode)1 TemplateMetadata (com.google.template.soy.jbcsrc.shared.TemplateMetadata)1 CodeChunk (com.google.template.soy.jssrc.dsl.CodeChunk)1 RequiresCollector (com.google.template.soy.jssrc.dsl.CodeChunk.RequiresCollector)1 JsExpr (com.google.template.soy.jssrc.restricted.JsExpr)1 SoyJsSrcPrintDirective (com.google.template.soy.jssrc.restricted.SoyJsSrcPrintDirective)1 SoyLibraryAssistedJsSrcPrintDirective (com.google.template.soy.jssrc.restricted.SoyLibraryAssistedJsSrcPrintDirective)1 FindCalleesNotInFileVisitor (com.google.template.soy.shared.internal.FindCalleesNotInFileVisitor)1 SoyPrintDirective (com.google.template.soy.shared.restricted.SoyPrintDirective)1 CallParamContentNode (com.google.template.soy.soytree.CallParamContentNode)1 CallParamValueNode (com.google.template.soy.soytree.CallParamValueNode)1