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());
}
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");
}
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");
}
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");
}
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());
}
}
}
}
Aggregations