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'");
}
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);
}
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.");
}
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).");
}
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.");
}
Aggregations