use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class VerifyPhnameAttrOnlyOnPlaceholdersVisitorTest method assertInvalidSoyCode.
private void assertInvalidSoyCode(String soyCode) {
ErrorReporter errors = ErrorReporter.createForTest();
SoyFileSetParserBuilder.forTemplateContents(soyCode).errorReporter(errors).parse();
assertThat(Iterables.getOnlyElement(errors.getErrors()).message()).contains("'phname' attributes are only valid inside '{msg...' tags.");
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class ContextualAutoescaperTest method rewrite.
public SoyFileNode rewrite(String... inputs) {
ErrorReporter reporter = ErrorReporter.createForTest();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(inputs).errorReporter(reporter).allowUnboundGlobals(true).addPrintDirectives(SOY_PRINT_DIRECTIVES).runAutoescaper(true).parse().fileSet();
if (!reporter.getErrors().isEmpty()) {
SoyError soyError = reporter.getErrors().get(0);
String message = soyError.message();
if (message.startsWith(ContextualAutoescaper.AUTOESCAPE_ERROR_PREFIX)) {
// Grab the part after the prefix (and the "- " used for indentation).
message = message.substring(ContextualAutoescaper.AUTOESCAPE_ERROR_PREFIX.length() + 2);
// reporter, we can stop throwing and simply add explicit checks in the cases.
throw new RewriteError(soyError, message);
} else {
throw new IllegalStateException("Unexpected error: " + message);
}
}
return soyTree.getChild(0);
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class AddHtmlCommentsForDebugPassTest method runPass.
/**
* Parses the given input as a Soy file content, runs the AddHtmlCommentsForDebug pass and returns
* a map that contains pairs of template names and rewritten template body.
*/
private static ImmutableMap<String, String> runPass(String input, String fileName) {
String soyFile = "{namespace ns}" + input;
IncrementingIdGenerator nodeIdGen = new IncrementingIdGenerator();
ErrorReporter boom = ErrorReporter.exploding();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forSuppliers(SoyFileSupplier.Factory.create(soyFile, SoyFileKind.SRC, fileName)).errorReporter(boom).parse().fileSet();
TemplateRegistry registry = new TemplateRegistry(soyTree, boom);
// We need to run HtmlRewritePass to produce HTML nodes. Otherwise we will not add any comments.
new HtmlRewritePass(boom).run(soyTree.getChild(0), nodeIdGen);
new AddHtmlCommentsForDebugPass().run(soyTree, registry);
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
for (TemplateNode node : soyTree.getChild(0).getChildren()) {
StringBuilder sb = new StringBuilder();
node.appendSourceStringForChildren(sb);
String templateName = (node instanceof TemplateDelegateNode) ? ((TemplateDelegateNode) node).getDelTemplateName() : node.getTemplateName();
builder.put(templateName, sb.toString());
}
return builder.build();
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class CheckDelegatesVisitorTest method assertInvalidSoyFiles.
private void assertInvalidSoyFiles(String expectedErrorMsgSubstr, String... soyFileContents) {
ErrorReporter errorReporter = ErrorReporter.createForTest();
SoyFileSetParserBuilder.forFileContents(soyFileContents).errorReporter(errorReporter).parse();
assertThat(errorReporter.getErrors()).hasSize(1);
assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo(expectedErrorMsgSubstr);
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class CheckFunctionCallsVisitorTest method assertFunctionCallsInvalid.
private void assertFunctionCallsInvalid(SyntaxVersion declaredSyntaxVersion, String errorMessage, String... lines) {
ErrorReporter errorReporter = ErrorReporter.createForTest();
SoyFileSetParserBuilder.forFileContents(Joiner.on('\n').join(lines)).declaredSyntaxVersion(declaredSyntaxVersion).errorReporter(errorReporter).parse();
assertThat(errorReporter.getErrors()).hasSize(1);
assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).contains(errorMessage);
}
Aggregations