Search in sources :

Example 21 with SoyFileSetNode

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

the class ResolveExpressionTypesVisitorTest method testLegacyObjectMapLiteral.

@Test
public void testLegacyObjectMapLiteral() {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param pi: int}", "{@param pf: float}", "{let $map: [1: $pi, 2:$pf]/}", "{assertType('legacy_object_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 22 with SoyFileSetNode

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

the class ResolveExpressionTypesVisitorTest method testMapToLegacyObjectMap.

@Test
public void testMapToLegacyObjectMap() {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param m: map<string, int>}", "{assertType('legacy_object_map<string,int>', mapToLegacyObjectMap($m))}", "{assertType('legacy_object_map<null,null>', mapToLegacyObjectMap(map()))}", "")).addSoyFunction(ASSERT_TYPE_FUNCTION).parse().fileSet();
    assertTypes(soyTree);
}
Also used : SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 23 with SoyFileSetNode

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

the class ResolveExpressionTypesVisitorTest method testConditionalOperatorDataFlowTypeNarrowing.

@Test
public void testConditionalOperatorDataFlowTypeNarrowing() {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param pa: bool|null}", "{@param pb: bool}", "{@param pc: [a : int|null]}", // #0 must be non-null
    "{assertType('bool', $pa ? $pa : $pb)}", // #1 must be non-null
    "{assertType('bool', $pa != null ?: $pb)}", "{assertType('bool', $pa ?: $pb)}", "{assertType('int', $pc.a ? $pc.a : 0)}", "{if not $pc.a}{assertType('int|null', $pc.a)}{/if}")).addSoyFunction(ASSERT_TYPE_FUNCTION).parse().fileSet();
    assertTypes(soyTree);
}
Also used : SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 24 with SoyFileSetNode

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

the class ResolveExpressionTypesVisitorTest method testArithmeticOps.

@Test
public void testArithmeticOps() {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param pa: ?}", "{@param pi: int}", "{@param pf: float}", "{assertType('?', $pa + $pa)}", "{assertType('int', $pi + $pi)}", "{assertType('float', $pf + $pf)}", "{assertType('?', $pa - $pa)}", "{assertType('int', $pi - $pi)}", "{assertType('float', $pf - $pf)}", "{assertType('?', $pa * $pa)}", "{assertType('int', $pi * $pi)}", "{assertType('float', $pf * $pf)}", "{assertType('float', $pa / $pa)}", "{assertType('float', $pi / $pi)}", "{assertType('float', $pf / $pf)}", "{assertType('?', $pa % $pa)}", "{assertType('int', $pi % $pi)}", "{assertType('float', $pf % $pf)}", "{assertType('?', -$pa)}", "{assertType('int', -$pi)}", "{assertType('float', -$pf)}")).declaredSyntaxVersion(SyntaxVersion.V2_0).addSoyFunction(ASSERT_TYPE_FUNCTION).typeRegistry(TYPE_REGISTRY).parse().fileSet();
    assertTypes(soyTree);
}
Also used : SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 25 with SoyFileSetNode

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

the class ResolveExpressionTypesVisitorTest method testLogicalOps.

@Test
public void testLogicalOps() {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param pa: ?}", "{@param pi: int}", "{@param pf: float}", "{assertType('bool', $pa and $pa)}", "{assertType('bool', $pi and $pi)}", "{assertType('bool', $pf and $pf)}", "{assertType('bool', $pa or $pa)}", "{assertType('bool', $pi or $pi)}", "{assertType('bool', $pf or $pf)}", "{assertType('bool', not $pa)}", "{assertType('bool', not $pi)}", "{assertType('bool', not $pf)}")).declaredSyntaxVersion(SyntaxVersion.V1_0).typeRegistry(TYPE_REGISTRY).addSoyFunction(ASSERT_TYPE_FUNCTION).parse().fileSet();
    new ResolveNamesVisitor(ErrorReporter.exploding()).exec(soyTree);
    createResolveExpressionTypesVisitor().exec(soyTree);
    assertTypes(soyTree);
}
Also used : 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