Search in sources :

Example 56 with ErrorReporter

use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.

the class ResolveExpressionTypesVisitorTest method testLegacyObjectMapLiteralAsRecord_duplicateKeys.

@Test
public void testLegacyObjectMapLiteralAsRecord_duplicateKeys() {
    ErrorReporter reporter = ErrorReporter.createForTest();
    SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{let $map: ['a': 1, 'a': 2]/}")).declaredSyntaxVersion(SyntaxVersion.V2_0).errorReporter(reporter).typeRegistry(TYPE_REGISTRY).parse().fileSet();
    assertThat(Iterables.getOnlyElement(reporter.getErrors()).message()).isEqualTo("Record literals with duplicate keys are not allowed.  Duplicate key: 'a'");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 57 with ErrorReporter

use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.

the class ResolveNamesVisitorTest method assertResolveNamesFails.

private void assertResolveNamesFails(String expectedError, String fileContent) {
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    SoyFileSetParserBuilder.forFileContents(fileContent).declaredSyntaxVersion(SyntaxVersion.V2_0).errorReporter(errorReporter).typeRegistry(typeRegistry).parse();
    assertThat(errorReporter.getErrors()).hasSize(1);
    assertThat(errorReporter.getErrors().get(0).message()).isEqualTo(expectedError);
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter)

Example 58 with ErrorReporter

use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.

the class ResolvePackageRelativeCssNamesVisitorTest method testWithComponentName.

@Test
public void testWithComponentName() {
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    compileTemplate("{namespace boo}\n\n" + "/** Test template. */\n" + "{template .foo cssbase=\"ns.bar\"}\n" + "  {@param goo: string}\n" + "  <p class=\"{css($goo, '%AAA')}\">\n" + "{/template}\n", errorReporter);
    assertThat(errorReporter.getErrors()).hasSize(1);
    assertThat(errorReporter.getErrors().get(0).message()).isEqualTo("Package-relative class name '%AAA' cannot be used with component expression.");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 59 with ErrorReporter

use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.

the class RewriteGenderMsgsVisitorTest method testMaxTwoGendersWithGenderPluralSelect.

@Test
public void testMaxTwoGendersWithGenderPluralSelect() {
    String soyCode = "" + "{@param userGender : ?}\n" + "{@param gender1 : ?}\n" + "{@param gender2 : ?}\n" + "{@param name2 : ?}\n" + "{@param numPhotos : ?}\n" + "{msg genders=\"$userGender, $gender2\" desc=\"\"}\n" + "  {select $gender1}\n" + "    {case 'female'}\n" + "      {plural $numPhotos}\n" + "        {case 1}Find her face in {$name2}'s photo\n" + "        {default}Find her face in {$name2}'s photos\n" + "      {/plural}\n" + "    {default}\n" + "      {plural $numPhotos}\n" + "        {case 1}Find their face in {$name2}'s photo\n" + "        {default}Find their face in {$name2}'s photos\n" + "      {/plural}\n" + "  {/select}\n" + "{/msg}\n";
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    SoyFileSetParserBuilder.forTemplateContents(soyCode).errorReporter(errorReporter).parse().fileSet();
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("A msg with 'plural' can contain at most 2 gender expressions between the " + "'genders' attribute and 'select' command (otherwise, combinatorial explosion " + "would cause a gigantic generated message).");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 60 with ErrorReporter

use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.

the class RewriteGenderMsgsVisitorTest method testMaxThreeGenders.

@Test
public void testMaxThreeGenders() {
    String soyCode = "" + "{@param userGender : ?}\n" + "{@param targetGender1 : ?}\n" + "{@param targetGender2 : ?}\n" + "{@param groupOwnerGender : ?}\n" + "{@param targetName1 : ?}\n" + "{@param targetName2 : ?}\n" + "{@param groupOwnerName : ?}\n" + "{msg genders=\"$userGender, $targetGender1, $targetGender2, $groupOwnerGender\"" + "    desc=\"...\"}\n" + "  You added {$targetName1} and {$targetName2} to {$groupOwnerName}'s group.\n" + "{/msg}\n";
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    SoyFileSetParserBuilder.forTemplateContents(soyCode).errorReporter(errorReporter).parse();
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Attribute 'genders' should contain 1-3 expressions.");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Aggregations

ErrorReporter (com.google.template.soy.error.ErrorReporter)70 Test (org.junit.Test)45 SoyFileSetNode (com.google.template.soy.soytree.SoyFileSetNode)19 TemplateNode (com.google.template.soy.soytree.TemplateNode)11 SoyError (com.google.template.soy.error.SoyError)7 MsgNode (com.google.template.soy.soytree.MsgNode)5 RawTextNode (com.google.template.soy.soytree.RawTextNode)3 SoyNode (com.google.template.soy.soytree.SoyNode)3 ArrayList (java.util.ArrayList)3 Point (com.google.template.soy.base.SourceLocation.Point)2 ExprNode (com.google.template.soy.exprtree.ExprNode)2 ClassData (com.google.template.soy.jbcsrc.internal.ClassData)2 SoyFileNode (com.google.template.soy.soytree.SoyFileNode)2 TemplateRegistry (com.google.template.soy.soytree.TemplateRegistry)2 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 SourceLocation (com.google.template.soy.base.SourceLocation)1 IncrementingIdGenerator (com.google.template.soy.base.internal.IncrementingIdGenerator)1 SoyFileSupplier (com.google.template.soy.base.internal.SoyFileSupplier)1 SoyJarFileWriter (com.google.template.soy.base.internal.SoyJarFileWriter)1