use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class HtmlRewritePassTest method testHtmlCommentWithControlFlow.
@Test
public void testHtmlCommentWithControlFlow() {
ErrorReporter errorReporter = ErrorReporter.createForTest();
TemplateNode node;
// Control flow structure should be preserved.
node = runPass("<!-- {if $foo} foo {else} bar {/if} -->", errorReporter);
assertThatASTString(node).isEqualTo(Joiner.on('\n').join("HTML_COMMENT_NODE", " RAW_TEXT_NODE", " IF_NODE", " IF_COND_NODE", " RAW_TEXT_NODE", " IF_ELSE_NODE", " RAW_TEXT_NODE", " RAW_TEXT_NODE", ""));
assertThatSourceString(node).isEqualTo("<!-- {if $foo} foo {else} bar {/if} -->");
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class HtmlRewritePassTest method testBadHtmlComment.
@Test
public void testBadHtmlComment() {
ErrorReporter errorReporter = ErrorReporter.createForTest();
// These are examples that we haven't closed the HTML comments.
for (String text : new String[] { "<!--", "<!-- --", "<!--->" }) {
errorReporter = ErrorReporter.createForTest();
runPass(text, errorReporter);
assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).named("error message for: %s", text).isEqualTo("template changes context from 'pcdata' to 'html comment'. " + "Did you forget to close the html comment?");
}
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class ResolveExpressionTypesVisitorTest method testMapLiteral_duplicateKeys.
@Test
public void testMapLiteral_duplicateKeys() {
ErrorReporter reporter = ErrorReporter.createForTest();
SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{let $map: map('a': 1, 'a': 2)/}")).declaredSyntaxVersion(SyntaxVersion.V2_0).errorReporter(reporter).typeRegistry(TYPE_REGISTRY).parse().fileSet();
assertThat(Iterables.getOnlyElement(reporter.getErrors()).message()).isEqualTo("Map 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 RewriteGenderMsgsVisitorTest method testMaxTwoGendersWithPlural.
@Test
public void testMaxTwoGendersWithPlural() {
String soyCode = "" + "{@param userGender : ?}\n" + "{@param gender1 : ?}\n" + "{@param gender2 : ?}\n" + "{@param numPhotos : ?}\n" + "{@param name1 : ?}\n" + "{@param name2 : ?}\n" + "{msg genders=\"$userGender, $gender1, $gender2\" desc=\"\"}\n" + " {plural $numPhotos}\n" + " {case 1}Find {$name1}'s face in {$name2}'s photo\n" + " {default}Find {$name1}'s face in {$name2}'s photos\n" + " {/plural}\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 testRewriteWithPlural.
@Test
public void testRewriteWithPlural() {
String soyCode = "" + "{@param num : ?}\n" + "{@param userGender : ?}\n" + "{msg genders=\"$userGender\" desc=\"...\"}\n" + " {plural $num}{case 1}Send it{default}Send {$num}{/plural}\n" + "{/msg}\n";
ErrorReporter boom = ErrorReporter.exploding();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forTemplateContents(soyCode).errorReporter(boom).parse().fileSet();
// After.
MsgNode msgAfterRewrite = (MsgNode) SharedTestUtils.getNode(soyTree, 0, 0);
assertEquals(// Note: Still has genders="..." in command text.
"{msg desc=\"...\" genders=\"$userGender\"}" + "{select $userGender}" + "{case 'female'}{plural $num}{case 1}Send it{default}Send {$num}{/plural}" + "{case 'male'}{plural $num}{case 1}Send it{default}Send {$num}{/plural}" + "{default}{plural $num}{case 1}Send it{default}Send {$num}{/plural}" + "{/select}", msgAfterRewrite.toSourceString());
// ------ Test that it has same msg id as equivalent msg using 'select'. ------
String soyCodeUsingSelect = "" + "{@param num : ?}\n" + "{@param userGender : ?}\n" + "{msg desc=\"...\"}\n" + " {select $userGender}\n" + " {case 'female'}{plural $num}{case 1}Send it{default}Send {$num}{/plural}\n" + " {case 'male'}{plural $num}{case 1}Send it{default}Send {$num}{/plural}\n" + " {default}{plural $num}{case 1}Send it{default}Send {$num}{/plural}\n" + " {/select}\n" + "{/msg}\n";
SoyFileSetNode soyTreeUsingSelect = SoyFileSetParserBuilder.forTemplateContents(soyCodeUsingSelect).parse().fileSet();
MsgNode msgUsingSelect = (MsgNode) SharedTestUtils.getNode(soyTreeUsingSelect, 0, 0);
assertThat(MsgUtils.computeMsgIdForDualFormat(msgAfterRewrite)).isEqualTo(MsgUtils.computeMsgIdForDualFormat(msgUsingSelect));
}
Aggregations