Search in sources :

Example 51 with ErrorReporter

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.");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 52 with ErrorReporter

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}-->");
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 53 with ErrorReporter

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("-->");
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 54 with ErrorReporter

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'>");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 55 with ErrorReporter

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);
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter)

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