Search in sources :

Example 36 with ErrorReporter

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

Example 37 with ErrorReporter

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

Example 38 with ErrorReporter

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

Example 39 with ErrorReporter

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);
}
Also used : ExprNode(com.google.template.soy.exprtree.ExprNode) ErrorReporter(com.google.template.soy.error.ErrorReporter) ArrayList(java.util.ArrayList)

Example 40 with ErrorReporter

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");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Aggregations

ErrorReporter (com.google.template.soy.error.ErrorReporter)70 Test (org.junit.Test)45 SoyFileSetNode (com.google.template.soy.soytree.SoyFileSetNode)19 TemplateNode (com.google.template.soy.soytree.TemplateNode)11 SoyError (com.google.template.soy.error.SoyError)7 MsgNode (com.google.template.soy.soytree.MsgNode)5 RawTextNode (com.google.template.soy.soytree.RawTextNode)3 SoyNode (com.google.template.soy.soytree.SoyNode)3 ArrayList (java.util.ArrayList)3 Point (com.google.template.soy.base.SourceLocation.Point)2 ExprNode (com.google.template.soy.exprtree.ExprNode)2 ClassData (com.google.template.soy.jbcsrc.internal.ClassData)2 SoyFileNode (com.google.template.soy.soytree.SoyFileNode)2 TemplateRegistry (com.google.template.soy.soytree.TemplateRegistry)2 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 SourceLocation (com.google.template.soy.base.SourceLocation)1 IncrementingIdGenerator (com.google.template.soy.base.internal.IncrementingIdGenerator)1 SoyFileSupplier (com.google.template.soy.base.internal.SoyFileSupplier)1 SoyJarFileWriter (com.google.template.soy.base.internal.SoyJarFileWriter)1