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