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