Search in sources :

Example 11 with SoyFileSetNode

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

Example 12 with SoyFileSetNode

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

Example 13 with SoyFileSetNode

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

Example 14 with SoyFileSetNode

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

Example 15 with SoyFileSetNode

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