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");
}
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;
}
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;
}
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.");
}
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;
}
Aggregations