Search in sources :

Example 6 with SoyError

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]);
    }
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) SoyError(com.google.template.soy.error.SoyError)

Example 7 with SoyError

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);
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) SoyError(com.google.template.soy.error.SoyError)

Aggregations

ErrorReporter (com.google.template.soy.error.ErrorReporter)7 SoyError (com.google.template.soy.error.SoyError)7 Test (org.junit.Test)2 SoyErrorKind (com.google.template.soy.error.SoyErrorKind)1 SoyFileSetNode (com.google.template.soy.soytree.SoyFileSetNode)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1