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