Search in sources :

Example 41 with ErrorReporter

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

the class SoyTreeUtilsTest method testVisitAllExprs.

// -----------------------------------------------------------------------------------------------
// Tests for executing an ExprNode visitor on all expressions in a Soy tree.
@Test
public void testVisitAllExprs() {
    String testFileContent = "{namespace boo}\n" + "\n" + "/** @param items */\n" + "{template .foo}\n" + // 5 nodes
    "  {length($items) + 5}\n" + // 2 nodes
    "  {for $item in $items}\n" + // 3 nodes
    "    {$item.goo}\n" + "  {/for}\n" + "{/template}\n";
    ErrorReporter boom = ErrorReporter.exploding();
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(testFileContent).errorReporter(boom).parse().fileSet();
    CountingVisitor countingVisitor = new CountingVisitor();
    SoyTreeUtils.execOnAllV2Exprs(soyTree, countingVisitor);
    CountingVisitor.Counts counts = countingVisitor.getCounts();
    assertEquals(3, counts.numExecs);
    assertEquals(10, counts.numVisitedNodes);
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 42 with ErrorReporter

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

the class TemplateNodeTest method testInvalidParamNames.

@Test
public void testInvalidParamNames() {
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    parse("{namespace ns}\n" + "/**@param ij */\n" + "{template .boo}{/template}", errorReporter);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Invalid param name 'ij' ('ij' is for injected data).");
    errorReporter = ErrorReporter.createForTest();
    parse("{namespace ns}\n" + "{template .boo}\n" + "{@param ij : int}\n" + "{/template}", errorReporter);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Invalid param name 'ij' ('ij' is for injected data).");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 43 with ErrorReporter

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

the class TemplateNodeTest method testParamsAlreadyDeclared.

@Test
public void testParamsAlreadyDeclared() {
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    parse("{namespace ns}\n" + "/**@param foo @param goo @param? foo */\n" + "{template .boo}{/template}", errorReporter);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Param 'foo' already declared.");
    errorReporter = ErrorReporter.createForTest();
    parse("{namespace ns}\n" + "{template .boo}\n" + "{@param goo : null}{@param foo:string}{@param foo : int}\n" + "{/template}", errorReporter);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Param 'foo' already declared.");
    errorReporter = ErrorReporter.createForTest();
    parse("{namespace ns}\n" + "/**\n" + " * @param foo a soydoc param \n" + " * @param foo a soydoc param \n" + "*/\n" + "{template .boo}\n" + "{/template}", errorReporter);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Param 'foo' already declared.");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 44 with ErrorReporter

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

the class TemplateNodeTest method testInvalidRequiredCss.

@Test
public void testInvalidRequiredCss() {
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    parse("{namespace ns}\n{template .boo requirecss=\"\"}{/template}", errorReporter);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Invalid required CSS namespace name '', expected an identifier.");
    errorReporter = ErrorReporter.createForTest();
    parse("{namespace ns}\n{template .boo requirecss=\"foo boo\"}{/template}", errorReporter);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Invalid required CSS namespace name 'foo boo', expected an identifier.");
    errorReporter = ErrorReporter.createForTest();
    parse("{namespace ns}\n{template .boo requirecss=\"9vol\"}{/template}", errorReporter);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Invalid required CSS namespace name '9vol', expected an identifier.");
    errorReporter = ErrorReporter.createForTest();
    parse("{namespace ns}\n{deltemplate foo.boo requirecss=\"5ham\"}{/deltemplate}", errorReporter);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Invalid required CSS namespace name '5ham', expected an identifier.");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 45 with ErrorReporter

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

the class TemplateSubject method isWellFormed.

public void isWellFormed() {
    ErrorReporter errorReporter = doParse();
    assertThat(errorReporter.getErrors()).named("the template parsed successfully").isEmpty();
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter)

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