Return-Path: X-Original-To: apmail-freemarker-notifications-archive@minotaur.apache.org Delivered-To: apmail-freemarker-notifications-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D2E4918387 for ; Sat, 19 Dec 2015 14:23:13 +0000 (UTC) Received: (qmail 55070 invoked by uid 500); 19 Dec 2015 14:23:13 -0000 Delivered-To: apmail-freemarker-notifications-archive@freemarker.apache.org Received: (qmail 55049 invoked by uid 500); 19 Dec 2015 14:23:13 -0000 Mailing-List: contact notifications-help@freemarker.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@freemarker.incubator.apache.org Delivered-To: mailing list notifications@freemarker.incubator.apache.org Received: (qmail 55040 invoked by uid 99); 19 Dec 2015 14:23:13 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 19 Dec 2015 14:23:13 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 525621804AF for ; Sat, 19 Dec 2015 14:23:13 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.226 X-Spam-Level: * X-Spam-Status: No, score=1.226 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.554] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id RmT0GiGgP7Jj for ; Sat, 19 Dec 2015 14:23:11 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 1FA9142A6A for ; Sat, 19 Dec 2015 14:23:11 +0000 (UTC) Received: (qmail 54834 invoked by uid 99); 19 Dec 2015 14:23:10 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 19 Dec 2015 14:23:10 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 72DA3E098D; Sat, 19 Dec 2015 14:23:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ddekany@apache.org To: notifications@freemarker.incubator.apache.org Date: Sat, 19 Dec 2015 14:23:13 -0000 Message-Id: In-Reply-To: <8b87d048b0044dfeb17fb503cacfc690@git.apache.org> References: <8b87d048b0044dfeb17fb503cacfc690@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [4/8] incubator-freemarker git commit: (AST location information test) (AST location information test) Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/cd6857c1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/cd6857c1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/cd6857c1 Branch: refs/heads/2.3 Commit: cd6857c18bd178fe0c480d8ac469e0fdcd09a0aa Parents: 448d50b Author: ddekany Authored: Thu Dec 17 23:57:13 2015 +0100 Committer: ddekany Committed: Thu Dec 17 23:57:13 2015 +0100 ---------------------------------------------------------------------- src/test/java/freemarker/core/ASTTest.java | 19 ++++- .../resources/freemarker/core/ast-locations.ast | 87 ++++++++++++++++++++ .../resources/freemarker/core/ast-locations.ftl | 10 +++ 3 files changed, 114 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cd6857c1/src/test/java/freemarker/core/ASTTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/freemarker/core/ASTTest.java b/src/test/java/freemarker/core/ASTTest.java index 1981ba6..8edb85e 100644 --- a/src/test/java/freemarker/core/ASTTest.java +++ b/src/test/java/freemarker/core/ASTTest.java @@ -22,6 +22,7 @@ package freemarker.core; import java.io.FileNotFoundException; import java.io.IOException; +import freemarker.core.ASTPrinter.Options; import freemarker.template.utility.StringUtil; import freemarker.test.utility.FileTestCase; @@ -67,13 +68,27 @@ public class ASTTest extends FileTestCase { testAST("ast-nestedignoredchildren"); } + public void testLocations() throws Exception { + testASTWithLocations("ast-locations"); + } + private void testAST(String testName) throws FileNotFoundException, IOException { + testAST(testName, null); + } + + private void testASTWithLocations(String testName) throws FileNotFoundException, IOException { + Options options = new Options(); + options.setShowLocation(true); + testAST(testName, options); + } + + private void testAST(String testName, Options ops) throws FileNotFoundException, IOException { final String templateName = testName + ".ftl"; assertExpectedFileEqualsString( testName + ".ast", - ASTPrinter.getASTAsString(templateName, normalizeLineBreaks(templateName))); + ASTPrinter.getASTAsString(templateName, normalizeLineBreaks(templateName), ops)); } - + private String normalizeLineBreaks(final String templateName) throws FileNotFoundException, IOException { return StringUtil.replace(loadResource(templateName), "\r\n", "\n").replace('\r', '\n'); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cd6857c1/src/test/resources/freemarker/core/ast-locations.ast ---------------------------------------------------------------------- diff --git a/src/test/resources/freemarker/core/ast-locations.ast b/src/test/resources/freemarker/core/ast-locations.ast new file mode 100644 index 0000000..1d94637 --- /dev/null +++ b/src/test/resources/freemarker/core/ast-locations.ast @@ -0,0 +1,87 @@ +#mixed_content // f.c.MixedContent; Location 1:1-10:33 + #if // f.c.ConditionalBlock; Location 1:1-1:15 + - condition: exp // f.c.Identifier; Location 1:6-1:8 + - AST-node subtype: "0" // Integer + #if // f.c.ConditionalBlock; Location 2:1-2:16 + - condition: exp // f.c.Identifier; Location 2:6-2:8 + - AST-node subtype: "0" // Integer + #text // f.c.TextBlock; Location 2:10-2:10 + - content: "1" // String + #text // f.c.TextBlock; Location 2:17-2:17 + - content: "\n" // String + #if // f.c.ConditionalBlock; Location 3:1-3:20 + - condition: exp // f.c.Identifier; Location 3:6-3:8 + - AST-node subtype: "0" // Integer + ${...} // f.c.DollarVariable; Location 3:10-3:13 + - content: 1 // f.c.NumberLiteral; Location 3:12-3:12 + #text // f.c.TextBlock; Location 3:14-3:14 + - content: "2" // String + #text // f.c.TextBlock; Location 3:21-3:21 + - content: "\n" // String + #if-#elseif-#else-container // f.c.IfBlock; Location 4:1-4:22 + #if // f.c.ConditionalBlock; Location 4:1-4:9 + - condition: exp // f.c.Identifier; Location 4:6-4:8 + - AST-node subtype: "0" // Integer + #else // f.c.ConditionalBlock; Location 4:10-4:16 + - condition: null // Null + - AST-node subtype: "1" // Integer + #if-#elseif-#else-container // f.c.IfBlock; Location 5:1-5:24 + #if // f.c.ConditionalBlock; Location 5:1-5:10 + - condition: exp // f.c.Identifier; Location 5:6-5:8 + - AST-node subtype: "0" // Integer + #text // f.c.TextBlock; Location 5:10-5:10 + - content: "1" // String + #else // f.c.ConditionalBlock; Location 5:11-5:18 + - condition: null // Null + - AST-node subtype: "1" // Integer + #text // f.c.TextBlock; Location 5:18-5:18 + - content: "1" // String + #text // f.c.TextBlock; Location 5:25-5:25 + - content: "\n" // String + #if-#elseif-#else-container // f.c.IfBlock; Location 6:1-6:32 + #if // f.c.ConditionalBlock; Location 6:1-6:14 + - condition: exp // f.c.Identifier; Location 6:6-6:8 + - AST-node subtype: "0" // Integer + ${...} // f.c.DollarVariable; Location 6:10-6:13 + - content: 1 // f.c.NumberLiteral; Location 6:12-6:12 + #text // f.c.TextBlock; Location 6:14-6:14 + - content: "2" // String + #else // f.c.ConditionalBlock; Location 6:15-6:26 + - condition: null // Null + - AST-node subtype: "1" // Integer + ${...} // f.c.DollarVariable; Location 6:22-6:25 + - content: 1 // f.c.NumberLiteral; Location 6:24-6:24 + #text // f.c.TextBlock; Location 6:26-6:26 + - content: "2" // String + #text // f.c.TextBlock; Location 6:33-6:33 + - content: "\n" // String + #if-#elseif-#else-container // f.c.IfBlock; Location 7:1-7:28 + #if // f.c.ConditionalBlock; Location 7:1-7:9 + - condition: exp // f.c.Identifier; Location 7:6-7:8 + - AST-node subtype: "0" // Integer + #elseif // f.c.ConditionalBlock; Location 7:10-7:22 + - condition: exp // f.c.Identifier; Location 7:19-7:21 + - AST-node subtype: "2" // Integer + #if-#elseif-#else-container // f.c.IfBlock; Location 8:1-8:29 + #if // f.c.ConditionalBlock; Location 8:1-8:9 + - condition: exp // f.c.Identifier; Location 8:6-8:8 + - AST-node subtype: "0" // Integer + #elseif // f.c.ConditionalBlock; Location 8:10-8:23 + - condition: exp // f.c.Identifier; Location 8:19-8:21 + - AST-node subtype: "2" // Integer + #text // f.c.TextBlock; Location 8:23-8:23 + - content: "1" // String + #text // f.c.TextBlock; Location 8:30-8:30 + - content: "\n" // String + #attempt // f.c.AttemptBlock; Location 9:1-9:31 + - error handler: #recover // f.c.RecoveryBlock; Location 9:11-9:20 + #recover // f.c.RecoveryBlock; Location 9:11-9:20 + #attempt // f.c.AttemptBlock; Location 10:1-10:33 + - error handler: #recover // f.c.RecoveryBlock; Location 10:12-10:22 + #text // f.c.TextBlock; Location 10:22-10:22 + - content: "1" // String + #text // f.c.TextBlock; Location 10:11-10:11 + - content: "1" // String + #recover // f.c.RecoveryBlock; Location 10:12-10:22 + #text // f.c.TextBlock; Location 10:22-10:22 + - content: "1" // String http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cd6857c1/src/test/resources/freemarker/core/ast-locations.ftl ---------------------------------------------------------------------- diff --git a/src/test/resources/freemarker/core/ast-locations.ftl b/src/test/resources/freemarker/core/ast-locations.ftl new file mode 100644 index 0000000..cecc19e --- /dev/null +++ b/src/test/resources/freemarker/core/ast-locations.ftl @@ -0,0 +1,10 @@ +<#if exp> +<#if exp>1 +<#if exp>${1}2 +<#if exp><#else> +<#if exp>1<#else>1 +<#if exp>${1}2<#else>${1}2 +<#if exp><#elseif exp> +<#if exp><#elseif exp>1 +<#attempt><#recover> +<#attempt>1<#recover>1 \ No newline at end of file