Search in sources :

Example 61 with SoyFileSetNode

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);
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) SoyNode(com.google.template.soy.soytree.SoyNode) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode)

Example 62 with SoyFileSetNode

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");
}
Also used : TemplateRegistry(com.google.template.soy.soytree.TemplateRegistry) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) CompiledTemplates(com.google.template.soy.jbcsrc.shared.CompiledTemplates) CompiledTemplate(com.google.template.soy.jbcsrc.shared.CompiledTemplate) Test(org.junit.Test)

Example 63 with SoyFileSetNode

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);
}
Also used : SoyFunction(com.google.template.soy.shared.restricted.SoyFunction) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 64 with SoyFileSetNode

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);
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) SoyNode(com.google.template.soy.soytree.SoyNode) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode)

Example 65 with SoyFileSetNode

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");
}
Also used : TemplateRegistry(com.google.template.soy.soytree.TemplateRegistry) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) CompiledTemplates(com.google.template.soy.jbcsrc.shared.CompiledTemplates) CompiledTemplate(com.google.template.soy.jbcsrc.shared.CompiledTemplate) Test(org.junit.Test)

Aggregations

SoyFileSetNode (com.google.template.soy.soytree.SoyFileSetNode)106 Test (org.junit.Test)81 TemplateNode (com.google.template.soy.soytree.TemplateNode)35 TemplateRegistry (com.google.template.soy.soytree.TemplateRegistry)29 ErrorReporter (com.google.template.soy.error.ErrorReporter)19 ParseResult (com.google.template.soy.SoyFileSetParser.ParseResult)13 TransitiveDepTemplatesInfo (com.google.template.soy.passes.FindTransitiveDepTemplatesVisitor.TransitiveDepTemplatesInfo)8 RawTextNode (com.google.template.soy.soytree.RawTextNode)8 MsgNode (com.google.template.soy.soytree.MsgNode)7 SoyNode (com.google.template.soy.soytree.SoyNode)6 CompiledTemplates (com.google.template.soy.jbcsrc.shared.CompiledTemplates)5 SoyMsgBundle (com.google.template.soy.msgs.SoyMsgBundle)5 PrintNode (com.google.template.soy.soytree.PrintNode)5 MsgFallbackGroupNode (com.google.template.soy.soytree.MsgFallbackGroupNode)4 SoyFileNode (com.google.template.soy.soytree.SoyFileNode)4 CompiledTemplate (com.google.template.soy.jbcsrc.shared.CompiledTemplate)3 SoyMsg (com.google.template.soy.msgs.restricted.SoyMsg)3 SoyMsgBundleImpl (com.google.template.soy.msgs.restricted.SoyMsgBundleImpl)3 PluginResolver (com.google.template.soy.soyparse.PluginResolver)3 ImmutableList (com.google.common.collect.ImmutableList)2