Search in sources :

Example 6 with ErrorReporter

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

the class TemplateNodeTest method testInvalidStrictTemplates.

@Test
public void testInvalidStrictTemplates() {
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    parse("{namespace ns}\n" + "{template .boo autoescape=\"deprecated-noncontextual\" kind=\"text\"}{/template}", errorReporter);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("kind=\"...\" attribute is only valid with autoescape=\"strict\".");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 7 with ErrorReporter

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

the class TemplateNodeTest method testCommandTextErrors.

@Test
public void testCommandTextErrors() {
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    parse("{namespace ns}\n{template requirecss=\"strict\"}{/template}", errorReporter);
    assertThat(errorReporter.getErrors()).hasSize(2);
    assertThat(errorReporter.getErrors().get(0).message()).isEqualTo("Template name 'requirecss' must be relative to the file namespace, i.e. a dot " + "followed by an identifier.");
    assertThat(errorReporter.getErrors().get(1).message()).isEqualTo("parse error at '=': expected attribute name, }, identifier, or .");
    errorReporter = ErrorReporter.createForTest();
    parse("{namespace ns}\n{template .foo autoescape=\"}{/template}", errorReporter);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Unexpected end of file.  Did you forget to close an attribute value or a comment?");
    errorReporter = ErrorReporter.createForTest();
    parse("{namespace ns}\n{template .foo autoescape=\"false\"}{/template}", errorReporter);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Invalid value for attribute 'autoescape', expected one of " + "[deprecated-contextual, deprecated-noncontextual].");
    // assertion inside no-arg templateBasicNode() is that there is no exception.
    parse("{namespace ns}\n{template .foo autoescape=\n\t\r \"deprecated-contextual\"}{/template}");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 8 with ErrorReporter

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

the class TemplateRegistryTest method testDuplicateDefaultDeltemplates.

@Test
public void testDuplicateDefaultDeltemplates() {
    String file = "{namespace ns}\n" + "/** Foo. */\n" + "{deltemplate foo.bar}\n" + "{/deltemplate}\n" + "/** Foo. */\n" + "{deltemplate foo.bar}\n" + "{/deltemplate}\n";
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    SoyFileSetParserBuilder.forFileContents(file).errorReporter(errorReporter).parse();
    assertThat(errorReporter.getErrors()).hasSize(1);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Delegate template 'foo.bar' already has a default defined at no-path:3:1.");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 9 with ErrorReporter

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

the class TemplateRegistryTest method testDuplicateBasicTemplates.

@Test
public void testDuplicateBasicTemplates() {
    String file = "{namespace ns}\n" + "/** Foo. */\n" + "{template .foo}\n" + "{/template}\n" + "/** Foo. */\n" + "{template .foo}\n" + "{/template}\n";
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    SoyFileSetParserBuilder.forFileContents(file).errorReporter(errorReporter).parse();
    assertThat(errorReporter.getErrors()).hasSize(1);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Template 'ns.foo' already defined at no-path:3:1.");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 10 with ErrorReporter

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

the class TemplateRegistryTest method testDuplicateDeltemplatesInSameDelpackage.

@Test
public void testDuplicateDeltemplatesInSameDelpackage() {
    String file = "{delpackage foo}\n" + "{namespace ns}\n" + "/** Foo. */\n" + "{deltemplate foo.bar}\n" + "{/deltemplate}\n" + "/** Foo. */\n" + "{deltemplate foo.bar}\n" + "{/deltemplate}\n";
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    SoyFileSetParserBuilder.forFileContents(file).errorReporter(errorReporter).parse();
    assertThat(errorReporter.getErrors()).hasSize(1);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Delegate template 'foo.bar' already defined in delpackage foo: no-path:4:1");
}
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