use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class CanInitOutputVarVisitorTest method runTestHelper.
/**
* @param indicesToNode Series of indices for walking down to the node we want to test.
*/
private static void runTestHelper(String soyCode, boolean isSameValueAsIsComputableAsJsExprsVisitor, int... indicesToNode) {
ErrorReporter boom = ErrorReporter.exploding();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forTemplateContents(soyCode).errorReporter(boom).parse().fileSet();
SoyNode node = SharedTestUtils.getNode(soyTree, indicesToNode);
IsComputableAsJsExprsVisitor icajev = new IsComputableAsJsExprsVisitor();
CanInitOutputVarVisitor ciovv = new CanInitOutputVarVisitor(icajev);
assertThat(ciovv.exec(node).equals(icajev.exec(node))).isEqualTo(isSameValueAsIsComputableAsJsExprsVisitor);
}
use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class BytecodeCompilerTest method testDelCall_delPackageSelections.
@Test
public void testDelCall_delPackageSelections() throws IOException {
String soyFileContent1 = Joiner.on("\n").join("{namespace ns1}", "", "/***/", "{template .callerTemplate}", " {delcall myApp.myDelegate}", " {param boo: 'aaaaaah' /}", " {/delcall}", "{/template}", "", "/** */", // default implementation (doesn't use $boo)
"{deltemplate myApp.myDelegate}", " {@param boo : string}", " default", "{/deltemplate}", "");
String soyFileContent2 = Joiner.on("\n").join("{delpackage SecretFeature}", "{namespace ns2}", "", "/** */", // implementation in SecretFeature
"{deltemplate myApp.myDelegate}", " {@param boo : string}", " SecretFeature {$boo}", "{/deltemplate}", "");
String soyFileContent3 = Joiner.on("\n").join("{delpackage AlternateSecretFeature}", "{namespace ns3}", "", "/** */", // implementation in AlternateSecretFeature
"{deltemplate myApp.myDelegate}", " {@param boo : string}", " AlternateSecretFeature {call .helper data=\"all\" /}", "{/deltemplate}", "");
String soyFileContent4 = Joiner.on("\n").join("{namespace ns3}", "", "/** */", "{template .helper}", " {@param boo : string}", " {$boo}", "{/template}", "");
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(soyFileContent1, soyFileContent2, soyFileContent3, soyFileContent4).parse().fileSet();
TemplateRegistry templateRegistry = new TemplateRegistry(soyTree, ErrorReporter.exploding());
CompiledTemplates templates = BytecodeCompiler.compile(templateRegistry, false, ErrorReporter.exploding()).get();
CompiledTemplate.Factory factory = templates.getTemplateFactory("ns1.callerTemplate");
Predicate<String> activePackages = Predicates.alwaysFalse();
assertThat(renderWithContext(factory, getDefaultContext(templates, activePackages))).isEqualTo("default");
activePackages = Predicates.equalTo("SecretFeature");
assertThat(renderWithContext(factory, getDefaultContext(templates, activePackages))).isEqualTo("SecretFeature aaaaaah");
activePackages = Predicates.equalTo("AlternateSecretFeature");
assertThat(renderWithContext(factory, getDefaultContext(templates, activePackages))).isEqualTo("AlternateSecretFeature aaaaaah");
activePackages = Predicates.equalTo("NonexistentFeature");
assertThat(renderWithContext(factory, getDefaultContext(templates, activePackages))).isEqualTo("default");
}
use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class FunctionNodeTest method testResolveFunctionsVisitor.
/**
* Tests that {@link com.google.template.soy.passes.ResolveFunctionsVisitor} recurses into {@link
* FunctionNode}s that are descendants of other FunctionNodes. (This omission caused cl/101255365
* to be rolled back.)
*/
@Test
public void testResolveFunctionsVisitor() {
SoyFunction foo = new SoyFunction() {
@Override
public String getName() {
return "foo";
}
@Override
public Set<Integer> getValidArgsSizes() {
return ImmutableSet.of(1);
}
};
SoyFunction bar = new SoyFunction() {
@Override
public String getName() {
return "bar";
}
@Override
public Set<Integer> getValidArgsSizes() {
return ImmutableSet.of(1);
}
};
SoyFileSetNode root = SoyFileSetParserBuilder.forTemplateContents("<a class=\"{foo(bar(1))}\">").addSoyFunction(foo).addSoyFunction(bar).parse().fileSet();
List<FunctionNode> functionNodes = SoyTreeUtils.getAllNodesOfType(root, FunctionNode.class);
assertThat(functionNodes).hasSize(2);
assertThat(functionNodes.get(0).getSoyFunction()).isSameAs(foo);
assertThat(functionNodes.get(1).getSoyFunction()).isSameAs(bar);
}
use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class IsComputableAsJsExprsVisitorTest method runTestHelper.
/**
* @param indicesToNode Series of indices for walking down to the node we want to test.
*/
private static void runTestHelper(String soyCode, boolean expectedResult, int... indicesToNode) {
ErrorReporter boom = ErrorReporter.exploding();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forTemplateContents(soyCode).errorReporter(boom).parse().fileSet();
SoyNode node = SharedTestUtils.getNode(soyTree, indicesToNode);
assertThat(new IsComputableAsJsExprsVisitor().exec(node)).isEqualTo(expectedResult);
}
use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class BytecodeCompilerTest method testDebugSoyTemplateInfo.
@Test
public void testDebugSoyTemplateInfo() throws IOException {
String soyFileContent = Joiner.on("\n").join("{namespace ns}", "", "{template .html}", " <div>foo</div>", "{/template}", "", "{template .text kind=\"text\"}", " foo", "{/template}", "", "{template .htmlNoTag}", " foo", "{/template}");
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(soyFileContent).addHtmlAttributesForDebugging(true).parse().fileSet();
TemplateRegistry templateRegistry = new TemplateRegistry(soyTree, ErrorReporter.exploding());
CompiledTemplates templates = BytecodeCompiler.compile(templateRegistry, false, ErrorReporter.exploding()).get();
// HTML templates
CompiledTemplate.Factory factory = templates.getTemplateFactory("ns.html");
assertThat(renderWithContext(factory, getDefaultContext(templates))).isEqualTo("<div>foo</div>");
// If debugSoyTemplateInfo is enabled, we should render additional HTML comments.
assertThat(renderWithContext(factory, getDefaultContextWithDebugInfo(templates))).isEqualTo("<div data-debug-soy=\"ns.html no-path:4\">foo</div>");
// We should never render these comments for templates with kind="text".
factory = templates.getTemplateFactory("ns.text");
assertThat(renderWithContext(factory, getDefaultContext(templates))).isEqualTo("foo");
assertThat(renderWithContext(factory, getDefaultContextWithDebugInfo(templates))).isEqualTo("foo");
factory = templates.getTemplateFactory("ns.htmlNoTag");
assertThat(renderWithContext(factory, getDefaultContext(templates))).isEqualTo("foo");
assertThat(renderWithContext(factory, getDefaultContextWithDebugInfo(templates))).isEqualTo("foo");
}
Aggregations