Search in sources :

Example 66 with ErrorReporter

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

the class CheckTemplateVisibilityTest method testCallPrivateTemplateSameFileNameDifferentDirectory.

// There was a bug in the visibility pass where you could call private templates if the caller was
// defined in a file with the same name irrespective of directory
@Test
public void testCallPrivateTemplateSameFileNameDifferentDirectory() {
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    SoyFileSetParserBuilder.forSuppliers(SoyFileSupplier.Factory.create("{namespace ns}\n" + "/** Private template. */\n" + "{template .foo visibility=\"private\"}\n" + "oops!\n" + "{/template}", SoyFileKind.SRC, "foo/bar.soy"), SoyFileSupplier.Factory.create("{namespace ns2}\n" + "/** Public template. */\n" + "{template .bar}\n" + "{call ns.foo /}\n" + "{/template}", SoyFileKind.SRC, "baz/bar.soy")).errorReporter(errorReporter).parse();
    assertThat(errorReporter.getErrors()).hasSize(1);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("ns.foo has private access in foo/bar.soy.");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 67 with ErrorReporter

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

the class CheckTemplateVisibilityTest method testCallPrivateTemplateFromSameNamespaceButDifferentFile.

@Test
public void testCallPrivateTemplateFromSameNamespaceButDifferentFile() {
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    SoyFileSetParserBuilder.forFileContents("{namespace ns}\n" + "/** Private template. */\n" + "{template .foo visibility=\"private\"}\n" + "oops!\n" + "{/template}", "{namespace ns}\n" + "/** Public template. */\n" + "{template .bar}\n" + "{call .foo /}\n" + "{/template}").errorReporter(errorReporter).parse();
    assertThat(errorReporter.getErrors()).hasSize(1);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("ns.foo has private access in no-path.");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 68 with ErrorReporter

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

the class CheckTemplateParamsVisitorTest method soyDocErrorsFor.

private static ImmutableList<SoyError> soyDocErrorsFor(String... soyFileContents) {
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    SoyFileSetParserBuilder.forFileContents(soyFileContents).declaredSyntaxVersion(SyntaxVersion.V1_0).errorReporter(errorReporter).parse();
    return errorReporter.getErrors();
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter)

Example 69 with ErrorReporter

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

the class FindCalleesNotInFileVisitorTest method testFindCalleesNotInFile.

@Test
public void testFindCalleesNotInFile() {
    String testFileContent = "" + "{namespace boo.foo}\n" + "\n" + "/** Test template 1. */\n" + "{template .goo autoescape=\"deprecated-noncontextual\"}\n" + "  {call .goo data=\"all\" /}\n" + "  {call .moo data=\"all\" /}\n" + "  {call boo.woo.hoo data=\"all\" /}\n" + // not defined in this file
    "{/template}\n" + "\n" + "/** Test template 2. */\n" + "{template .moo autoescape=\"deprecated-noncontextual\"}\n" + "  {for $i in range(8)}\n" + "    {call boo.foo.goo data=\"all\" /}\n" + "    {call .too data=\"all\" /}\n" + // not defined in this file
    "    {call .goo}" + "      {param a}{call .moo /}{/param}" + "      {param b}{call .zoo /}{/param}" + // not defined in this file
    "    {/call}" + "  {/for}\n" + "{/template}\n" + "\n" + "/** Test template 3. */\n" + "{deltemplate booHoo autoescape=\"deprecated-noncontextual\"}\n" + "  {call .goo data=\"all\" /}\n" + "  {call .moo data=\"all\" /}\n" + "  {call boo.hoo.roo data=\"all\" /}\n" + // not defined in this file
    "{/deltemplate}\n";
    ErrorReporter boom = ErrorReporter.exploding();
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(testFileContent).errorReporter(boom).parse().fileSet();
    SoyFileNode soyFile = soyTree.getChild(0);
    Iterable<String> calleesNotInFile = Iterables.transform(new FindCalleesNotInFileVisitor().exec(soyFile), CallBasicNode::getCalleeName);
    assertThat(calleesNotInFile).containsExactly("boo.woo.hoo", "boo.foo.too", "boo.foo.zoo", "boo.hoo.roo");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) CallBasicNode(com.google.template.soy.soytree.CallBasicNode) SoyFileNode(com.google.template.soy.soytree.SoyFileNode) Test(org.junit.Test)

Example 70 with ErrorReporter

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

the class GenJsExprsVisitorTest method generateChunks.

private static List<CodeChunk.WithValue> generateChunks(String soyCode, int... indicesToNode) {
    ErrorReporter boom = ErrorReporter.exploding();
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forTemplateContents(soyCode).errorReporter(boom).parse().fileSet();
    SoyNode node = SharedTestUtils.getNode(soyTree, indicesToNode);
    UniqueNameGenerator nameGenerator = JsSrcNameGenerators.forLocalVariables();
    GenJsExprsVisitor visitor = JsSrcTestUtils.createGenJsExprsVisitorFactory().create(TranslationContext.of(SoyToJsVariableMappings.startingWith(LOCAL_VAR_TRANSLATIONS), CodeChunk.Generator.create(nameGenerator), nameGenerator), AliasUtils.IDENTITY_ALIASES, boom);
    return visitor.exec(node);
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) SoyNode(com.google.template.soy.soytree.SoyNode) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) UniqueNameGenerator(com.google.template.soy.base.internal.UniqueNameGenerator)

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