use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class HtmlRewritePassTest method testBadTagName.
@Test
public void testBadTagName() {
ErrorReporter errorReporter = ErrorReporter.createForTest();
runPass("<3 >", errorReporter);
assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Illegal tag name character.");
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class HtmlRewritePassTest method testHtmlCommentWithPrintNode.
@Test
public void testHtmlCommentWithPrintNode() {
ErrorReporter errorReporter = ErrorReporter.createForTest();
TemplateNode node;
// Print node.
node = runPass("<!--{$foo}-->", errorReporter);
assertThatASTString(node).isEqualTo(Joiner.on('\n').join("HTML_COMMENT_NODE", " PRINT_NODE", ""));
assertThatSourceString(node).isEqualTo("<!--{$foo}-->");
// Mixed print node and raw text node.
node = runPass("<!--{$foo}hello{$bar}-->", errorReporter);
assertThatASTString(node).isEqualTo(Joiner.on('\n').join("HTML_COMMENT_NODE", " PRINT_NODE", " RAW_TEXT_NODE", " PRINT_NODE", ""));
assertThatSourceString(node).isEqualTo("<!--{$foo}hello{$bar}-->");
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class HtmlRewritePassTest method testHtmlCommentWithOnlyRawTextNode.
@Test
public void testHtmlCommentWithOnlyRawTextNode() {
ErrorReporter errorReporter = ErrorReporter.createForTest();
TemplateNode node;
// The most common test case.
node = runPass("<!--foo-->", errorReporter);
assertThatASTString(node).isEqualTo(Joiner.on('\n').join("HTML_COMMENT_NODE", " RAW_TEXT_NODE", ""));
assertThatSourceString(node).isEqualTo("<!--foo-->");
// Empty comment is allowed.
node = runPass("<!---->", errorReporter);
assertThatASTString(node).isEqualTo(Joiner.on('\n').join("HTML_COMMENT_NODE", ""));
assertThatSourceString(node).isEqualTo("<!---->");
// White spaces should be preserved.
node = runPass("<!-- foo -->", errorReporter);
assertThatASTString(node).isEqualTo(Joiner.on('\n').join("HTML_COMMENT_NODE", " RAW_TEXT_NODE", ""));
assertThatSourceString(node).isEqualTo("<!-- foo -->");
// script tag within HTML comment should be treated as raw text.
node = runPass("<!-- <script>alert(\"Hi\");</script> -->", errorReporter);
assertThatASTString(node).isEqualTo(Joiner.on('\n').join("HTML_COMMENT_NODE", " RAW_TEXT_NODE", ""));
assertThatSourceString(node).isEqualTo("<!-- <script>alert(\"Hi\");</script> -->");
// This is fine since we never start a HTML comment, so it is treated as raw text.
node = runPass("-->", errorReporter);
assertThatASTString(node).isEqualTo(Joiner.on('\n').join("RAW_TEXT_NODE", ""));
assertThatSourceString(node).isEqualTo("-->");
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class HtmlRewritePassTest method testBadAttributeName.
@Test
public void testBadAttributeName() {
ErrorReporter errorReporter = ErrorReporter.createForTest();
runPass("<div foo-->", errorReporter);
assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Illegal attribute name character.");
errorReporter = ErrorReporter.createForTest();
runPass("<div 0a>", errorReporter);
assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("Illegal attribute name character.");
// these are fine, for weird reasons. afaik, these characters aren't allowed by any defined
// html attributes... but we'll allow them since some users are using them for weird reasons.
// polymer uses _src and _style apparently
runPass("<div _src='foo'>");
runPass("<div $src='foo'>");
runPass("<div $src_='foo'>");
}
use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.
the class ResolveExpressionTypesVisitorTest method assertResolveExpressionTypesFails.
/**
* Assertions function that checks to make sure that name resolution fails with the expected
* exception.
*
* @param fileContent The template source.
* @param expectedError The expected failure message (a substring).
*/
private void assertResolveExpressionTypesFails(String expectedError, String fileContent) {
ErrorReporter errorReporter = ErrorReporter.createForTest();
SoyFileSetParserBuilder.forFileContents(fileContent).declaredSyntaxVersion(SyntaxVersion.V2_0).errorReporter(errorReporter).typeRegistry(TYPE_REGISTRY).parse();
assertThat(errorReporter.getErrors()).hasSize(1);
assertThat(errorReporter.getErrors().get(0).message()).isEqualTo(expectedError);
}
Aggregations