use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class ResolveExpressionTypesVisitorTest method testComparisonOps.
@Test
public void testComparisonOps() {
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param pa: ?}", "{@param pi: int}", "{@param pf: float}", "{assertType('bool', $pa > $pa)}", "{assertType('bool', $pi > $pi)}", "{assertType('bool', $pf > $pf)}", "{assertType('bool', $pa >= $pa)}", "{assertType('bool', $pi >= $pi)}", "{assertType('bool', $pf >= $pf)}", "{assertType('bool', $pa < $pa)}", "{assertType('bool', $pi < $pi)}", "{assertType('bool', $pf < $pf)}", "{assertType('bool', $pa <= $pa)}", "{assertType('bool', $pi <= $pi)}", "{assertType('bool', $pf <= $pf)}", "{assertType('bool', $pa == $pa)}", "{assertType('bool', $pi == $pi)}", "{assertType('bool', $pf == $pf)}", "{assertType('bool', $pa != $pa)}", "{assertType('bool', $pi != $pi)}", "{assertType('bool', $pf != $pf)}")).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 testDataFlowTypeNarrowing_deadExpression.
@Test
public void testDataFlowTypeNarrowing_deadExpression() {
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param record: ?}", "{if $record.unknownField}", " {assertType('?', $record.unknownField)}", "{else}", " {if $record.unknownField}", // This code is dead, but we can't prove it
" {assertType('?', $record.unknownField)}", " {/if}", "{/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 testInjectedParamTypes.
@Test
public void testInjectedParamTypes() {
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@inject pa: bool}", "{@inject? pb: list<int>}", "{assertType('bool', $pa)}", "{assertType('list<int>|null', $pb)}")).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 testLegacyObjectMapLiteralAsRecord.
@Test
public void testLegacyObjectMapLiteralAsRecord() {
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param pi: int}", "{@param pf: float}", "{let $map: ['a': $pi, 'b':$pf]/}", "{assertType('[a: int, b: float]', $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 testDataRefTypesWithUnknown.
@Test
public void testDataRefTypesWithUnknown() {
// Test that data with the 'unknown' type is allowed to function as a map or list.
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param pa: ?}", "{@param pb: map<string, float>}", "{@param pc: map<int, string>}", "{assertType('?', $pa[0])}", "{assertType('?', $pa.xxx)}", "{assertType('?', $pa.xxx.yyy)}", "{assertType('float', $pb[$pa])}", "{assertType('string', $pc[$pa])}")).declaredSyntaxVersion(SyntaxVersion.V2_0).addSoyFunction(ASSERT_TYPE_FUNCTION).typeRegistry(TYPE_REGISTRY).parse().fileSet();
assertTypes(soyTree);
}
Aggregations