Search in sources :

Example 1 with SoyError

use of com.google.template.soy.error.SoyError in project closure-templates by google.

the class TemplateParserTest method testMultipleErrors.

@Test
public void testMultipleErrors() throws ParseException {
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    parseTemplateContent(// Invalid callee name
    "{call .123 /}\n" + // Invalid callee name
    "{delcall 456 /}\n" + // Invalid foreach var
    "{for foo in bar}{/for}\n" + // Missing let var
    "{let /}\n", errorReporter);
    List<SoyError> errors = errorReporter.getErrors();
    assertThat(errors).hasSize(4);
    assertThat(errors.get(0).message()).isEqualTo("parse error at '1': expected identifier");
    assertThat(errors.get(1).message()).isEqualTo("parse error at '4': expected identifier or .");
    assertThat(errors.get(2).message()).isEqualTo("parse error at 'foo': expected variable");
    assertThat(errors.get(3).message()).isEqualTo("parse error at '/}': expected variable");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) SoyError(com.google.template.soy.error.SoyError) Test(org.junit.Test)

Example 2 with SoyError

use of com.google.template.soy.error.SoyError in project closure-templates by google.

the class TemplateSubject method causesError.

public TemplateSubject causesError(SoyErrorKind error) {
    ErrorReporter errorReporter = doParse();
    SoyError report = getFirstReport(error, errorReporter);
    if (report == null) {
        failWithRawMessage("%s should have failed to parse with <%s>, instead had errors: %s", actualAsString(), error, errorReporter.getErrors());
    }
    actualSourceLocation = report.location();
    return this;
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) SoyError(com.google.template.soy.error.SoyError)

Example 3 with SoyError

use of com.google.template.soy.error.SoyError in project closure-templates by google.

the class TemplateSubject method causesError.

public TemplateSubject causesError(String message) {
    ErrorReporter errorReporter = doParse();
    SoyError report = getFirstReport(message, errorReporter);
    if (report == null) {
        failWithRawMessage("%s should have failed to parse with <%s>, instead had errors: %s", actualAsString(), message, errorReporter.getErrors());
    }
    actualSourceLocation = report.location();
    return this;
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) SoyError(com.google.template.soy.error.SoyError)

Example 4 with SoyError

use of com.google.template.soy.error.SoyError in project closure-templates by google.

the class RewriteGenderMsgsVisitorTest method testErrorIfCannotGenNoncollidingBaseNames.

@Test
public void testErrorIfCannotGenNoncollidingBaseNames() {
    String soyCode = "" + "{@param userGender : ?}\n" + "{@param gender : ?}\n" + "{@param owner : ?}\n" + "{msg genders=\"$userGender, $gender\" desc=\"Button text.\"}\n" + "  You joined {$owner}'s community.\n" + "{/msg}\n";
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    SoyFileSetParserBuilder.forTemplateContents(soyCode).errorReporter(errorReporter).parse().fileSet();
    List<String> actualMessages = new ArrayList<>();
    for (SoyError error : errorReporter.getErrors()) {
        actualMessages.add(error.message());
    }
    assertThat(actualMessages).contains("Cannot generate noncolliding base names for vars. " + "Colliding expressions: '$gender' and '$userGender'. " + "Add explicit base names with the 'phname' attribute.");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) ArrayList(java.util.ArrayList) SoyError(com.google.template.soy.error.SoyError) Test(org.junit.Test)

Example 5 with SoyError

use of com.google.template.soy.error.SoyError in project closure-templates by google.

the class SoyConformanceTest method getViolations.

private ImmutableList<SoyError> getViolations(String textProto, SoyFileSetParserBuilder builder) {
    ValidatedConformanceConfig config = parseConfigProto(textProto);
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    builder.setConformanceConfig(config).errorReporter(errorReporter).parse();
    ImmutableList<SoyError> errors = errorReporter.getErrors();
    Set<SoyErrorKind> expectedErrorKinds = new HashSet<>();
    for (RuleWithWhitelists rule : config.getRules()) {
        expectedErrorKinds.add(rule.getRule().error);
    }
    for (SoyError actualError : errors) {
        if (!expectedErrorKinds.contains(actualError.errorKind())) {
            throw new AssertionError("Found non-conformance error!: " + actualError + "\nexpected kind to be one of: " + expectedErrorKinds + " actual is: " + actualError.errorKind());
        }
    }
    return errors;
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) SoyErrorKind(com.google.template.soy.error.SoyErrorKind) SoyError(com.google.template.soy.error.SoyError) HashSet(java.util.HashSet)

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