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