use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class IsComputableAsJsExprsVisitorTest method runTestHelper.
/**
* @param indicesToNode Series of indices for walking down to the node we want to test.
*/
private static void runTestHelper(String soyCode, boolean expectedResult, int... indicesToNode) {
ErrorReporter boom = ErrorReporter.exploding();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forTemplateContents(soyCode).errorReporter(boom).parse().fileSet();
SoyNode node = SharedTestUtils.getNode(soyTree, indicesToNode);
assertThat(new IsComputableAsJsExprsVisitor().exec(node)).isEqualTo(expectedResult);
}
use of com.google.template.soy.error.ErrorReporter 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.ErrorReporter in project closure-templates by google.
the class SourceLocationTest method testDoesntAccessPastEnd.
@Test
public void testDoesntAccessPastEnd() {
// Make sure that if we have a token stream that ends abruptly, we don't
// look for a line number and break in a way that suppresses the real error
// message.
// JavaCC is pretty good about never using null as a token value.
ErrorReporter reporter = ErrorReporter.createForTest();
SoyFileSetParserBuilder.forSuppliers(SoyFileSupplier.Factory.create("{template t autoescape=\"deprecated-noncontextual\"}\nHello, World!\n", SoyFileKind.SRC, "broken.soy")).errorReporter(reporter).parse();
assertThat(reporter.getErrors()).isNotEmpty();
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class MsgSubstUnitBaseVarNameUtilsTest method assertErrorMsgWhenGenNoncollidingBaseNamesForExprs.
private void assertErrorMsgWhenGenNoncollidingBaseNamesForExprs(String expectedErrorMsg, String... exprTexts) {
List<ExprNode> exprs = new ArrayList<>();
for (String exprText : exprTexts) {
exprs.add(parse(exprText));
}
ErrorReporter errorReporter = ErrorReporter.createForTest();
MsgSubstUnitBaseVarNameUtils.genNoncollidingBaseNamesForExprs(exprs, "FALLBACK", errorReporter);
assertThat(errorReporter.getErrors()).hasSize(1);
assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).contains(expectedErrorMsg);
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class SoyTreeUtilsTest method testBuildAstString.
@Test
public final void testBuildAstString() throws Exception {
String testFileContent = "{namespace ns}\n" + "\n" + "{template .t}\n" + " {@param foo: string}\n" + " {@param bar: string}\n" + " {for $i in range(5)}\n" + " {if $i % 2 == 0}\n" + " {$foo}\n" + " {else}\n" + " {$bar}\n" + " {/if}\n" + " {/for}\n" + " foo\n" + "{/template}\n";
ErrorReporter boom = ErrorReporter.exploding();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(testFileContent).errorReporter(boom).parse().fileSet();
assertThat(SoyTreeUtils.buildAstString(soyTree, 2, new StringBuilder()).toString()).isEqualTo("" + " SOY_FILE_NODE\n" + " TEMPLATE_BASIC_NODE\n" + " FOR_NODE\n" + " FOR_NONEMPTY_NODE\n" + " IF_NODE\n" + " IF_COND_NODE\n" + " PRINT_NODE\n" + " IF_ELSE_NODE\n" + " PRINT_NODE\n" + " RAW_TEXT_NODE\n");
}
Aggregations