use of com.google.template.soy.error.SoyError in project closure-templates by google.
the class JsSrcSubject method causesErrors.
void causesErrors(String... expectedErrorMsgSubstrings) {
ErrorReporter reporter = ErrorReporter.createForTest();
this.errorReporter = reporter;
generateCode();
ImmutableList<SoyError> errors = reporter.getErrors();
assertThat(errors).hasSize(expectedErrorMsgSubstrings.length);
for (int i = 0; i < expectedErrorMsgSubstrings.length; ++i) {
assertThat(errors.get(i).message()).contains(expectedErrorMsgSubstrings[i]);
}
}
use of com.google.template.soy.error.SoyError 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);
}
Aggregations