Search in sources :

Example 16 with SoyFileSetNode

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);
}
Also used : SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 17 with SoyFileSetNode

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);
}
Also used : SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 18 with SoyFileSetNode

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);
}
Also used : SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 19 with SoyFileSetNode

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);
}
Also used : SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 20 with SoyFileSetNode

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