use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class ResolveExpressionTypesVisitorTest method testMapLiteralWithStringLiteralKeysDoesNotCreateRecord.
@Test
public void testMapLiteralWithStringLiteralKeysDoesNotCreateRecord() {
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param pi: int}", "{@param pf: float}", // With the old map syntax, this would create a record type (see next test)
"{let $map: map('a': $pi, 'b':$pf)/}", "{assertType('map<string,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 testDataFlowTypeNarrowing_complexExpressions.
@Test
public void testDataFlowTypeNarrowing_complexExpressions() {
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param map: map<string, int|null>}", "{@param record: " + "[a : [nullableInt : int|null, nullableBool : bool|null]|null]}", "{if $map['a']}", " {assertType('int', $map['a'])}", "{/if}", "{if $record.a?.nullableInt}", " {assertType('int', $record.a?.nullableInt)}", "{/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 testDataFlowTypeNarrowingFailure.
@Test
public void testDataFlowTypeNarrowingFailure() {
// Test for places where type narrowing shouldn't work
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param pa: bool|null}", "{@param pb: bool}", "{if ($pa != null) != ($pb != null)}", // #0 don't know
" {assertType('bool|null', $pa)}", "{else}", // #1 don't know
" {assertType('bool|null', $pa)}", "{/if}", "{if $pa ?: $pb}", // #2 don't know
" {assertType('bool|null', $pa)}", "{/if}", "{if $pb ? $pa : false}", // #3 don't know
" {assertType('bool|null', $pa)}", "{/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 testMapLiteralWithStringKeysAsMap.
@Test
public void testMapLiteralWithStringKeysAsMap() {
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param v1: int}", "{@param v2: string}", "{@param k1: string}", "{let $map: map($k1: $v1, 'b': $v2) /}", "{assertType('map<string,int|string>', $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 testDataRefTypes.
@Test
public void testDataRefTypes() {
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param pa: bool}", "{@param pb: list<int>}", "{@param pe: map<int, map<int, string>>}", "{assertType('bool', $pa)}", "{assertType('list<int>', $pb)}", "{assertType('int', $pb[0])}", "{assertType('map<int,map<int,string>>', $pe)}", "{assertType('map<int,string>', $pe[0])}", "{assertType('string', $pe[1 + 1][2])}")).addSoyFunction(ASSERT_TYPE_FUNCTION).parse().fileSet();
assertTypes(soyTree);
}
Aggregations