use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class CombineConsecutiveRawTextNodesPassTest method testCombineConsecutiveRawTextNodes_preserveSourceLocations.
@Test
public void testCombineConsecutiveRawTextNodes_preserveSourceLocations() {
String testFileContent = "{namespace boo}{template .foo}\nbl{nil}ah\n{/template}";
ErrorReporter boom = ErrorReporter.exploding();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(testFileContent).errorReporter(boom).parse().fileSet();
TemplateNode template = (TemplateNode) SharedTestUtils.getNode(soyTree);
assertThat(template.numChildren()).isEqualTo(1);
RawTextNode node = (RawTextNode) template.getChild(0);
assertThat(node.getRawText()).isEqualTo("blah");
assertThat(node.getSourceLocation().getBeginPoint()).isEqualTo(Point.create(2, 1));
assertThat(node.getSourceLocation().getEndPoint()).isEqualTo(Point.create(2, 9));
// we also know the locations of individual characters
assertThat(node.locationOf(2)).isEqualTo(Point.create(2, 8));
// split it up into 1 node per character
// arbitrary
int newId = 1;
RawTextNode c1 = node.substring(newId, 0, 1);
RawTextNode c2 = node.substring(newId, 1, 2);
RawTextNode c3 = node.substring(newId, 2, 3);
RawTextNode c4 = node.substring(newId, 3, 4);
template.removeChild(node);
template.addChildren(Arrays.asList(c1, c2, c3, c4));
assertThat(template.numChildren()).isEqualTo(4);
new CombineConsecutiveRawTextNodesPass().run(soyTree);
assertThat(template.numChildren()).isEqualTo(1);
node = (RawTextNode) template.getChild(0);
// all the data is preserved across the join operation
assertThat(node.getRawText()).isEqualTo("blah");
assertThat(node.getSourceLocation().getBeginPoint()).isEqualTo(Point.create(2, 1));
assertThat(node.getSourceLocation().getEndPoint()).isEqualTo(Point.create(2, 9));
assertThat(node.locationOf(2)).isEqualTo(Point.create(2, 8));
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class ClearSoyDocStringsVisitorTest method testClearSoyDocStrings.
@Test
public void testClearSoyDocStrings() {
String testFileContent = "{namespace boo}\n" + "\n" + "/**\n" + " * blah blah blah\n" + " *\n" + " * @param goo blah blah\n" + " */\n" + "{template .foo}\n" + " {$goo}\n" + "{/template}\n";
ErrorReporter boom = ErrorReporter.exploding();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(testFileContent).errorReporter(boom).parse().fileSet();
TemplateNode template = (TemplateNode) SharedTestUtils.getNode(soyTree);
assertThat(template.getSoyDoc()).contains("blah");
assertThat(template.getSoyDocDesc()).contains("blah");
assertThat(template.getParams().get(0).desc()).contains("blah");
new ClearSoyDocStringsVisitor().exec(soyTree);
assertThat(template.getSoyDoc()).isNull();
assertThat(template.getSoyDocDesc()).isNull();
assertThat(template.getParams().get(0).desc()).isNull();
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class FindIndirectParamsVisitorTest method testFindIndirectParams.
@Test
public void testFindIndirectParams() {
String fileContent1 = "{namespace alpha}\n" + "\n" + "/** @param? a0 @param? b3 */\n" + // 'b3' listed by alpha.zero
"{template .zero}\n" + " {call .zero data=\"all\" /}\n" + // recursive call should not cause 'a0' to be added
" {call .one data=\"all\" /}\n" + " {call .two /}\n" + " {call beta.zero /}\n" + " {call .five data=\"all\"}\n" + " {param a5: $a0 /}\n" + " {param b2: 88 /}\n" + " {/call}\n" + "{/template}\n" + "\n" + "/** @param? a1 */\n" + "{template .one}\n" + " {call .three data=\"all\" /}\n" + " {call .four /}\n" + " {$a1}\n" + "{/template}\n" + "\n" + "/** @param? a2 */\n" + "{template .two}\n" + " {$a2}\n" + "{/template}\n" + "\n" + "/** @param? a3 */\n" + "{template .three}\n" + " {call beta.one data=\"all\" /}\n" + " {$a3}\n" + "{/template}\n" + "\n" + "/** @param? a4 */\n" + "{template .four}\n" + " {call external.one /}\n" + " {$a4}\n" + "{/template}\n" + "\n" + "/** @param? a5 @param? b4 */\n" + // 'b4' listed by alpha.five
"{template .five}\n" + " {call beta.two data=\"all\" /}\n" + " {call beta.three data=\"all\" /}\n" + " {call beta.four data=\"all\" /}\n" + " {$b4}\n" + " {$a5}\n" + "{/template}\n" + "\n" + "/** @param? a6 */\n" + "{template .six}\n" + " {$a6}\n" + "{/template}\n";
String fileContent2 = "{namespace beta}\n" + "\n" + "/** @param? b0 */\n" + "{template .zero}\n" + " {$b0}\n" + "{/template}\n" + "\n" + "/** @param? b1 */\n" + "{template .one}\n" + " {call alpha.six data=\"all\" /}\n" + " {$b1}\n" + "{/template}\n" + "\n" + "/** @param? b2 */\n" + "{template .two}\n" + " {$b2}\n" + "{/template}\n" + "\n" + "/** @param? b3 */\n" + "{template .three}\n" + " {$b3}\n" + "{/template}\n" + "\n" + "/** @param? b4 */\n" + "{template .four}\n" + " {$b4}\n" + "{/template}\n";
ErrorReporter boom = ErrorReporter.exploding();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(fileContent1, fileContent2).errorReporter(boom).parse().fileSet();
TemplateRegistry registry = new TemplateRegistry(soyTree, boom);
SoyFileNode a = soyTree.getChild(0);
TemplateNode a0 = a.getChild(0);
TemplateNode a1 = a.getChild(1);
// TemplateNode a2 = a.getChild(2);
TemplateNode a3 = a.getChild(3);
// TemplateNode a4 = a.getChild(4);
TemplateNode a5 = a.getChild(5);
TemplateNode a6 = a.getChild(6);
SoyFileNode b = soyTree.getChild(1);
// TemplateNode b0 = b.getChild(0);
TemplateNode b1 = b.getChild(1);
// TemplateNode b2 = b.getChild(2);
TemplateNode b3 = b.getChild(3);
TemplateNode b4 = b.getChild(4);
IndirectParamsInfo ipi = new FindIndirectParamsVisitor(registry).exec(a0);
assertThat(ipi.mayHaveIndirectParamsInExternalCalls).isFalse();
assertThat(ipi.mayHaveIndirectParamsInExternalDelCalls).isFalse();
Map<String, TemplateParam> ipMap = ipi.indirectParams;
assertThat(ipMap).hasSize(6);
assertThat(ipMap).doesNotContainKey("a0");
assertThat(ipMap).containsKey("a1");
assertThat(ipMap).doesNotContainKey("a2");
assertThat(ipMap).containsKey("a3");
assertThat(ipMap).doesNotContainKey("a4");
assertThat(ipMap).doesNotContainKey("a5");
assertThat(ipMap).containsKey("a6");
assertThat(ipMap).doesNotContainKey("b0");
assertThat(ipMap).containsKey("b1");
assertThat(ipMap).doesNotContainKey("b2");
assertThat(ipMap).containsKey("b3");
assertThat(ipMap).containsKey("b4");
Multimap<String, TemplateNode> pktcm = ipi.paramKeyToCalleesMultimap;
assertThat(pktcm).valuesForKey("a1").isEqualTo(ImmutableSet.of(a1));
assertThat(pktcm).valuesForKey("a3").isEqualTo(ImmutableSet.of(a3));
assertThat(pktcm).valuesForKey("a6").isEqualTo(ImmutableSet.of(a6));
assertThat(pktcm).valuesForKey("b1").isEqualTo(ImmutableSet.of(b1));
assertThat(pktcm).valuesForKey("b3").isEqualTo(ImmutableSet.of(b3));
// 'b4' listed by alpha.five
assertThat(pktcm).valuesForKey("b4").isEqualTo(ImmutableSet.of(a5, b4));
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class InsertMsgsVisitorTest method testPlrselMsgsUsingSoySource.
@Test
public void testPlrselMsgsUsingSoySource() {
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(PLRSEL_TEST_FILE_CONTENT).parse().fileSet();
TemplateNode template = (TemplateNode) SharedTestUtils.getNode(soyTree);
assertThat(template.numChildren()).isEqualTo(2);
// Execute the visitor.
ErrorReporter errorReporter = ErrorReporter.createForTest();
new InsertMsgsVisitor(null, /* msgBundle */
errorReporter).insertMsgs(template);
assertThat(errorReporter.getErrors()).hasSize(2);
assertThat(errorReporter.getErrors().get(0).toString()).contains("JS code generation currently only supports plural/select messages when " + "shouldGenerateGoogMsgDefs is true.");
assertThat(errorReporter.getErrors().get(1).toString()).contains("JS code generation currently only supports plural/select messages when " + "shouldGenerateGoogMsgDefs is true.");
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class AssertStrictAutoescapingVisitorTest method parseAndGetErrors.
private ImmutableList<SoyError> parseAndGetErrors(String soyCode) {
ErrorReporter errorReporter = ErrorReporter.createForTest();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(soyCode).errorReporter(errorReporter).parse().fileSet();
new AssertStrictAutoescapingVisitor(errorReporter).exec(soyTree);
return errorReporter.getErrors();
}
Aggregations