use of com.google.template.soy.error.ErrorReporter 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.ErrorReporter 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.ErrorReporter in project closure-templates by google.
the class TemplateSubject method doParse.
private ErrorReporter doParse() {
SoyFileSupplier sourceFile = SoyFileSupplier.Factory.create("{namespace test}\n" + "{template .foo}\n" + actual() + "\n" + "{/template}", SoyFileKind.SRC, "example.soy");
ErrorReporter errorReporter = ErrorReporter.create(ImmutableMap.of(sourceFile.getFilePath(), sourceFile));
SoyFileSetNode fileSet = SoyFileSetParserBuilder.forSuppliers(sourceFile).errorReporter(errorReporter).parse().fileSet();
fileNode = fileSet.numChildren() == 1 ? fileSet.getChild(0) : null;
return errorReporter;
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class SoyUtils method parseCompileTimeGlobals.
/**
* Parses a globals file in the format created by {@link #generateCompileTimeGlobalsFile} into a
* map from global name to primitive value.
*
* @param inputSource A source that returns a reader for the globals file.
* @return The parsed globals map.
* @throws IOException If an error occurs while reading the globals file.
* @throws IllegalStateException If the globals file is not in the correct format.
*/
public static ImmutableMap<String, PrimitiveData> parseCompileTimeGlobals(CharSource inputSource) throws IOException {
Builder<String, PrimitiveData> compileTimeGlobalsBuilder = ImmutableMap.builder();
ErrorReporter errorReporter = ErrorReporter.exploding();
try (BufferedReader reader = inputSource.openBufferedStream()) {
int lineNum = 1;
for (String line = reader.readLine(); line != null; line = reader.readLine(), ++lineNum) {
if (line.startsWith("//") || line.trim().length() == 0) {
continue;
}
SourceLocation sourceLocation = new SourceLocation("globals", lineNum, 1, lineNum, 1);
Matcher matcher = COMPILE_TIME_GLOBAL_LINE.matcher(line);
if (!matcher.matches()) {
errorReporter.report(sourceLocation, INVALID_FORMAT, line);
continue;
}
String name = matcher.group(1);
String valueText = matcher.group(2).trim();
ExprNode valueExpr = SoyFileParser.parseExprOrDie(valueText);
// TODO: Consider allowing non-primitives (e.g. list/map literals).
if (!(valueExpr instanceof PrimitiveNode)) {
if (valueExpr instanceof GlobalNode || valueExpr instanceof VarRefNode) {
errorReporter.report(sourceLocation, INVALID_VALUE, valueExpr.toSourceString());
} else {
errorReporter.report(sourceLocation, NON_PRIMITIVE_VALUE, valueExpr.toSourceString());
}
continue;
}
// Default case.
compileTimeGlobalsBuilder.put(name, InternalValueUtils.convertPrimitiveExprToData((PrimitiveNode) valueExpr));
}
}
return compileTimeGlobalsBuilder.build();
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class HtmlRewritePassTest method testUnmatchedContextChangingCloseTagUnquotedAttributeValue.
@Test
public void testUnmatchedContextChangingCloseTagUnquotedAttributeValue() {
// matched script is fine
runPass("<script>xxx</script>");
// unmatched closing div is fine.
runPass("</div>");
for (String tag : new String[] { "</script>", "</style>", "</title>", "</textarea>", "</xmp>" }) {
ErrorReporter errorReporter = ErrorReporter.createForTest();
runPass(tag, errorReporter);
assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).named("error message for: %s", tag).isEqualTo("Unexpected close tag for context-changing tag.");
}
}
Aggregations