You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2015/10/11 20:40:12 UTC
[2/3] incubator-groovy git commit: reinstate linecolumn checker test
suite
reinstate linecolumn checker test suite
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/9436c55f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/9436c55f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/9436c55f
Branch: refs/heads/GROOVY_2_4_X
Commit: 9436c55fc5a14a20bc503c46c9a837753c846ff6
Parents: 33a73b7
Author: paulk <pa...@asert.com.au>
Authored: Sun Oct 11 22:42:07 2015 +1000
Committer: pascalschumacher <pa...@gmx.net>
Committed: Sun Oct 11 20:35:50 2015 +0200
----------------------------------------------------------------------
.../groovy/ast/ClassCodeVisitorSupport.java | 5 +
.../org/codehaus/groovy/ast/LineColumnCheck.txt | 10 +-
.../groovy/ast/LineColumnCheckTest.groovy | 29 ++++++
.../groovy/ast/LineColumnCheckTestSuite.java | 98 ++++++++++++++++++++
.../codehaus/groovy/ast/LineColumnChecker.java | 2 +-
5 files changed, 139 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/9436c55f/src/main/org/codehaus/groovy/ast/ClassCodeVisitorSupport.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/ClassCodeVisitorSupport.java b/src/main/org/codehaus/groovy/ast/ClassCodeVisitorSupport.java
index c675b9e..848f270 100644
--- a/src/main/org/codehaus/groovy/ast/ClassCodeVisitorSupport.java
+++ b/src/main/org/codehaus/groovy/ast/ClassCodeVisitorSupport.java
@@ -100,6 +100,11 @@ public abstract class ClassCodeVisitorSupport extends CodeVisitorSupport impleme
}
}
+ public void visitBlockStatement(BlockStatement block) {
+ visitStatement(block);
+ super.visitBlockStatement(block);
+ }
+
protected void visitClassCodeContainer(Statement code) {
if (code != null) code.visit(this);
}
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/9436c55f/src/test/org/codehaus/groovy/ast/LineColumnCheck.txt
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/ast/LineColumnCheck.txt b/src/test/org/codehaus/groovy/ast/LineColumnCheck.txt
index 669836f..002c263 100644
--- a/src/test/org/codehaus/groovy/ast/LineColumnCheck.txt
+++ b/src/test/org/codehaus/groovy/ast/LineColumnCheck.txt
@@ -13,23 +13,25 @@ public class Test {
[FieldNode,(2:24),(2:34)][ConstantExpression,(2:33),(2:34)];
[FieldNode,(3:2),(3:26)][ConstantExpression,(3:16),(3:26)]
-###ifelse:::
+###ifElse:::
if (expression) {
} else {
}
-:::[IfStatement,(1:1),(5:2)];[BlockStatement,(1:17),(3:3)];
+:::[IfStatement,(1:1),(5:2)];
+[BooleanExpression,(1:5),(1:15)][VariableExpression,(1:5),(1:15)];
+[BlockStatement,(1:17),(3:3)];
[BlockStatement,(3:8),(5:2)]
-###ifwithoutElse:::
+###ifWithoutElse:::
if (expression) {
}
:::[IfStatement,(1:1),(4:2)];[BlockStatement,(1:17),(4:2)]
-###ifElseif:::
+###ifElseIf:::
if (expression) {
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/9436c55f/src/test/org/codehaus/groovy/ast/LineColumnCheckTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/ast/LineColumnCheckTest.groovy b/src/test/org/codehaus/groovy/ast/LineColumnCheckTest.groovy
new file mode 100644
index 0000000..f78f355
--- /dev/null
+++ b/src/test/org/codehaus/groovy/ast/LineColumnCheckTest.groovy
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.codehaus.groovy.ast
+
+import junit.textui.TestRunner
+
+class LineColumnCheckTest extends GroovyTestCase {
+ // TODO simplify by having suite directly included rather than via TestRunner
+ // or better yet make whole suite a single Parameterized test
+ void testLineColumnInfo() {
+ assert TestRunner.run(LineColumnCheckTestSuite.suite()).wasSuccessful()
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/9436c55f/src/test/org/codehaus/groovy/ast/LineColumnCheckTestSuite.java
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/ast/LineColumnCheckTestSuite.java b/src/test/org/codehaus/groovy/ast/LineColumnCheckTestSuite.java
new file mode 100644
index 0000000..3e3ec60
--- /dev/null
+++ b/src/test/org/codehaus/groovy/ast/LineColumnCheckTestSuite.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.codehaus.groovy.ast;
+
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+
+import junit.framework.TestSuite;
+
+/**
+ * Tests the LineColumn information in file specified in TEST_FILE_PATH
+ *
+ * The file in the specified path should look like:
+ *
+ * ###<testname>:::
+ * <source code from which the AST will be built>
+ * :::<expected AST output>
+ *
+ * The section above can be repeated for every new TestCase
+ *
+ * The AST output from the visitor is quite big. Also for small source code snippets. Therefore
+ * it is possible to only specify the nodes that you want to check and separate them with a semicolon.
+ * A semicolon is also needed when you begin with a new line.
+ * Bsp:
+ * [TryCatchStatement,(1:1),(9:2)][BlockStatement,(1:5),(3:3)];
+ * [CatchStatement,(3:3),(5:3)][BlockStatement,(3:12),(5:3)];
+ * [CatchStatement,(5:3),(7:3)][BlockStatement,(5:12),(7:3)];
+ * [BlockStatement,(7:3),(9:2)][BlockStatement,(7:11),(9:2)]
+ *
+ * [<NodeType>,(<line>:<column>),(<lastLine>:<lastColumn>)]
+ *
+ * @author <a href="mailto:martin.kempf@gmail.com">Martin Kempf</a>
+ *
+ */
+public class LineColumnCheckTestSuite extends TestSuite {
+
+ public static final String TEST_FILE_PATH = "./src/test/org/codehaus/groovy/ast/LineColumnCheck.txt";
+
+ public static TestSuite suite() {
+ TestSuite ts = new TestSuite("LineColumnCheckTestSuite");
+ String content;
+ try {
+ content = getContent(new FileReader(TEST_FILE_PATH));
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ String[] tests = content.split("###");
+ String testName = "";
+ String source = "";
+ String expected;
+ for (String test : tests) {
+ String[] slicedTests = test.split(":::");
+ for (int ii = 0; ii < slicedTests.length; ii++) {
+ if (ii % 3 == 0) {
+ testName = slicedTests[ii];
+ } else if (ii % 3 == 1) {
+ source = slicedTests[ii].trim();
+ } else if (ii % 3 == 2) {
+ expected = slicedTests[ii].trim();
+ ts.addTest(new LineColumnChecker(testName, source, expected));
+ }
+ }
+ }
+ return ts;
+ }
+
+ private static String getContent(Reader reader) {
+ int character;
+ StringBuilder content = new StringBuilder();
+ try {
+ while ((character = reader.read()) != -1) {
+ content.append((char) character);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return content.toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/9436c55f/src/test/org/codehaus/groovy/ast/LineColumnChecker.java
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/ast/LineColumnChecker.java b/src/test/org/codehaus/groovy/ast/LineColumnChecker.java
index 1200a38..3694c4b 100644
--- a/src/test/org/codehaus/groovy/ast/LineColumnChecker.java
+++ b/src/test/org/codehaus/groovy/ast/LineColumnChecker.java
@@ -64,7 +64,7 @@ import org.junit.Ignore;
* @author <a href="mailto:martin.kempf@gmail.com">Martin Kempf</a>
*
*/
-@Ignore("helper class for manual testing")
+@Ignore("helper class for LineColumnCheckTestSuite")
public class LineColumnChecker extends ASTTest {
private LineCheckVisitor visitor;