Search in sources :

Example 81 with SoyFileSetNode

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

the class ResolveExpressionTypesVisitorTest method testConcatLists.

@Test
public void testConcatLists() {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{assertType('list<string>', concatLists(['1'], ['2']))}", "{assertType('list<int>', concatLists([1], [2]))}", "{assertType('list<int>', concatLists([1], []))}", "{assertType('list<int>', concatLists([], [1]))}", "{assertType('list<int>', concatLists(true ? [] : [1], [2]))}", "{assertType('list<null>', concatLists([], []))}", "{assertType('list<int|string>', concatLists([1], [\"2\"]))}")).addSoyFunction(ASSERT_TYPE_FUNCTION).parse().fileSet();
    assertTypes(soyTree);
}
Also used : SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 82 with SoyFileSetNode

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

the class ResolveExpressionTypesVisitorTest method testBuiltinFunctionTyping.

@Test
public void testBuiltinFunctionTyping() {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@inject list: list<int|null>}", "{for $item in $list}", "   {assertType('int', index($item))}", "   {assertType('bool', isLast($item))}", "   {assertType('bool', isFirst($item))}", "   {assertType('int|null', $item)}", "   {assertType('int', checkNotNull($item))}", "   {assertType('string', css('foo'))}", "   {assertType('string', xid('bar'))}", "{/for}")).addSoyFunction(ASSERT_TYPE_FUNCTION).parse().fileSet();
    assertTypes(soyTree);
}
Also used : SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 83 with SoyFileSetNode

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

the class ResolveExpressionTypesVisitorTest method testMapLiteral.

@Test
public void testMapLiteral() {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param pi: int}", "{@param pf: float}", "{let $map: map(1: $pi, 2:$pf)/}", "{assertType('map<int,float|int>', $map)}")).declaredSyntaxVersion(SyntaxVersion.V2_0).typeRegistry(TYPE_REGISTRY).addSoyFunction(ASSERT_TYPE_FUNCTION).parse().fileSet();
    assertTypes(soyTree);
}
Also used : SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 84 with SoyFileSetNode

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

the class ResolveNamesVisitorTest method testMultipleLocals.

@Test
public void testMultipleLocals() {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{let $la: 1 /}", "{let $lb: $la /}", "{let $lc: $lb /}")).parse().fileSet();
    new ResolveNamesVisitor(ErrorReporter.exploding()).exec(soyTree);
    TemplateNode n = soyTree.getChild(0).getChild(0);
    // 3 because each new $la binding is a 'new variable'
    assertThat(n.getMaxLocalVariableTableSize()).isEqualTo(3);
    LetValueNode firstLet = (LetValueNode) n.getChild(0);
    LetValueNode secondLet = (LetValueNode) n.getChild(1);
    LetValueNode thirdLet = (LetValueNode) n.getChild(2);
    assertThat(firstLet.getVar().localVariableIndex()).isEqualTo(0);
    assertThat(secondLet.getVar().localVariableIndex()).isEqualTo(1);
    assertThat(thirdLet.getVar().localVariableIndex()).isEqualTo(2);
    assertThat(((VarRefNode) secondLet.getExpr().getRoot()).getDefnDecl()).isEqualTo(firstLet.getVar());
    assertThat(((VarRefNode) thirdLet.getExpr().getRoot()).getDefnDecl()).isEqualTo(secondLet.getVar());
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) LetValueNode(com.google.template.soy.soytree.LetValueNode) VarRefNode(com.google.template.soy.exprtree.VarRefNode) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 85 with SoyFileSetNode

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

the class ResolveNamesVisitorTest method testLetReferencedInsideAttributeValue.

@Test
public void testLetReferencedInsideAttributeValue() {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{let $t: 1 /}<{$t}>")).parse().fileSet();
    TemplateNode n = soyTree.getChild(0).getChild(0);
    VarRefNode node = Iterables.getOnlyElement(SoyTreeUtils.getAllNodesOfType(n, VarRefNode.class));
    assertThat(node.getDefnDecl().kind()).isEqualTo(VarDefn.Kind.LOCAL_VAR);
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) VarRefNode(com.google.template.soy.exprtree.VarRefNode) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) 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