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 2018/07/09 05:22:28 UTC

groovy git commit: minor refactor: move some tests into their respective modules

Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 9dbbbffb9 -> 54d9d8188


minor refactor: move some tests into their respective modules


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/54d9d818
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/54d9d818
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/54d9d818

Branch: refs/heads/GROOVY_2_5_X
Commit: 54d9d8188fe5e0cd548490290364ec7d90b00a56
Parents: 9dbbbff
Author: Paul King <pa...@asert.com.au>
Authored: Mon Jul 9 15:22:21 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Mon Jul 9 15:22:21 2018 +1000

----------------------------------------------------------------------
 .../groovy/bugs/groovy4585/groovy4585.xml       |  32 -----
 .../groovy/bugs/groovy4585/Groovy4585Bug.groovy |  31 -----
 src/test/groovy/tree/NavigationNodeTest.groovy  |  58 ++++++++++
 src/test/groovy/tree/NavigationTest.groovy      | 116 -------------------
 .../groovy/util/DelegatingScriptTest.groovy     |  58 +++++-----
 .../groovy/bugs/groovy4585/Groovy4585Bug.groovy |  31 +++++
 .../resources/bugs/groovy4585/groovy4585.xml    |  32 +++++
 .../groovy/groovy/tree/NavigationXmlTest.groovy |  86 ++++++++++++++
 8 files changed, 237 insertions(+), 207 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/54d9d818/src/test-resources/groovy/bugs/groovy4585/groovy4585.xml
----------------------------------------------------------------------
diff --git a/src/test-resources/groovy/bugs/groovy4585/groovy4585.xml b/src/test-resources/groovy/bugs/groovy4585/groovy4585.xml
deleted file mode 100644
index 6dcf2bb..0000000
--- a/src/test-resources/groovy/bugs/groovy4585/groovy4585.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="GB2312"?>
-<!--
-
-     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.
-
--->
-<project name="projBuild" default="projBuild" basedir=".">
-    <property name="drive" value="d:\" />
-
-    <target name="projBuild">
-        <%for (int i = 0; i < names.size(); i++) {%>
-            <exec dir="\${drive}" executable="echo">
-                  <arg line="${names[i]}"/>
-            </exec>
-        <%}%>
-    </target>
-</project>

http://git-wip-us.apache.org/repos/asf/groovy/blob/54d9d818/src/test/groovy/bugs/groovy4585/Groovy4585Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/groovy4585/Groovy4585Bug.groovy b/src/test/groovy/bugs/groovy4585/Groovy4585Bug.groovy
deleted file mode 100644
index 0dc274c..0000000
--- a/src/test/groovy/bugs/groovy4585/Groovy4585Bug.groovy
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- *  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 groovy.bugs.groovy4585
-
-class Groovy4585Bug extends GroovyTestCase {
-    void test() {
-        def engineForBuildXml = new groovy.text.SimpleTemplateEngine(false)
-        engineForBuildXml.setEscapeBackslash(true)
-        def templateForBuildXml = engineForBuildXml.createTemplate(this.getClass().getResource("/groovy/bugs/groovy4585/groovy4585.xml").text)
-        String buildXmlContent = templateForBuildXml.make([names:['a', 'b', 'c']]).toString()
-
-        assert buildXmlContent.contains('<property name="drive" value="d:\\" />')
-        assert buildXmlContent.contains('<exec dir="${drive}" executable="echo">')
-    }
-}

http://git-wip-us.apache.org/repos/asf/groovy/blob/54d9d818/src/test/groovy/tree/NavigationNodeTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/tree/NavigationNodeTest.groovy b/src/test/groovy/tree/NavigationNodeTest.groovy
new file mode 100644
index 0000000..2ff997d
--- /dev/null
+++ b/src/test/groovy/tree/NavigationNodeTest.groovy
@@ -0,0 +1,58 @@
+/*
+ *  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 groovy.tree
+
+/**
+ * Simple test of tree walking for Nodes
+ *
+ * @see groovy.tree.NavigationXmlTest
+ */
+class NavigationNodeTest extends GroovyTestCase {
+
+    void testDepthFirst() {
+        def tree = createTreeFromNodeBuilder()
+        def names = tree.depthFirst().collect { it.name() }
+        assert names == ['a', 'b1', 'b2', 'c1', 'c2', 'b3', 'b4', 'c3', 'c4', 'b5']
+    }
+
+    void testBreadthFirst() {
+        def tree = createTreeFromNodeBuilder()
+        def names = tree.breadthFirst().collect { it.name() }
+        assert names == ['a', 'b1', 'b2', 'b3', 'b4', 'b5', 'c1', 'c2', 'c3', 'c4']
+    }
+
+    private static createTreeFromNodeBuilder() {
+        def b = NodeBuilder.newInstance()
+        def root = b.a(a: 5, b: 7) {
+            b1()
+            b2 {
+                c1()
+                c2()
+            }
+            b3()
+            b4 {
+                c3()
+                c4()
+            }
+            b5()
+        }
+        assert root != null
+        return root
+    }
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/54d9d818/src/test/groovy/tree/NavigationTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/tree/NavigationTest.groovy b/src/test/groovy/tree/NavigationTest.groovy
deleted file mode 100644
index 03f48ad..0000000
--- a/src/test/groovy/tree/NavigationTest.groovy
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- *  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 groovy.tree
-
-/**
- * Simple test of tree walking
- */
-class NavigationTest extends GroovyTestCase {
-
-    void testDepthFirst() {
-        def tree = createTreeFromNodeBuilder()
-        def names = tree.depthFirst().collect { it.name() }
-        assert names == ['a', 'b1', 'b2', 'c1', 'c2', 'b3', 'b4', 'c3', 'c4', 'b5']
-    }
-
-    void testBreadthFirst() {
-        def tree = createTreeFromNodeBuilder()
-        def names = tree.breadthFirst().collect { it.name() }
-        assert names == ['a', 'b1', 'b2', 'b3', 'b4', 'b5', 'c1', 'c2', 'c3', 'c4']
-    }
-
-    void testPrePostOrder() {
-        def root = createTreeFromXmlParser()
-        def combos = [[false, true], ['depthFirst', 'breadthFirst']].combinations()
-        def actual = combos.collect{ preorder, type ->
-            root."$type"(preorder)*.name()
-        }*.toString()
-        def expected = [
-            '[child1a, child1b, parent1, child2a, grandchild2, child2b, child2c, parent2, root]', // df post
-            '[root, parent1, child1a, child1b, parent2, child2a, child2b, grandchild2, child2c]', // df pre
-            '[grandchild2, child1a, child1b, child2a, child2b, child2c, parent1, parent2, root]', // bf post
-            '[root, parent1, parent2, child1a, child1b, child2a, child2b, child2c, grandchild2]'  // bf pre
-        ]
-        (0..3).each{ assert actual[it] == expected[it] }
-    }
-
-    void testPrePostOrderWithClosure() {
-        def root = createTreeFromXmlParser()
-        def combos = [[false, true], ['depthFirst', 'breadthFirst']].combinations()
-        def actual = combos.collect{ preorder, type ->
-            def names = []
-            root."$type"(preorder: preorder) { names << it.name() }
-            names
-        }*.toString()
-        def expected = [
-            '[child1a, child1b, parent1, child2a, grandchild2, child2b, child2c, parent2, root]', // df post
-            '[root, parent1, child1a, child1b, parent2, child2a, child2b, grandchild2, child2c]', // df pre
-            '[grandchild2, child1a, child1b, child2a, child2b, child2c, parent1, parent2, root]', // bf post
-            '[root, parent1, parent2, child1a, child1b, child2a, child2b, child2c, grandchild2]'  // bf pre
-        ]
-        (0..3).each{ assert actual[it] == expected[it] }
-    }
-
-    void testLevelWithClosure() {
-        def root = createTreeFromXmlParser()
-        def result = [:].withDefault { [] }
-        root.depthFirst { node, index ->
-            result[index] << node.name()
-        }
-        assert result == [1: ['root'], 2: ['parent1', 'parent2'], 4: ['grandchild2'],
-                          3: ['child1a', 'child1b', 'child2a', 'child2b', 'child2c']]
-    }
-
-    private static createTreeFromNodeBuilder() {
-        def b = NodeBuilder.newInstance()
-        def root = b.a(a: 5, b: 7) {
-            b1()
-            b2 {
-                c1()
-                c2()
-            }
-            b3()
-            b4 {
-                c3()
-                c4()
-            }
-            b5()
-        }
-        assert root != null
-        return root
-    }
-
-    private static createTreeFromXmlParser() {
-        def xml = '''
-        <root>
-          <parent1>
-            <child1a/>
-            <child1b/>
-          </parent1>
-          <parent2>
-            <child2a/>
-            <child2b><grandchild2/></child2b>
-            <child2c/>
-          </parent2>
-        </root>
-        '''
-        new XmlParser().parseText(xml)
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/groovy/blob/54d9d818/src/test/groovy/util/DelegatingScriptTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/util/DelegatingScriptTest.groovy b/src/test/groovy/util/DelegatingScriptTest.groovy
index 162ff3c..0c1f445 100644
--- a/src/test/groovy/util/DelegatingScriptTest.groovy
+++ b/src/test/groovy/util/DelegatingScriptTest.groovy
@@ -20,56 +20,58 @@ package groovy.util
 
 import org.codehaus.groovy.control.CompilerConfiguration
 import groovy.xml.MarkupBuilder
-import java.io.StringWriter
 
-public class DelegatingScriptTest extends GroovyTestCase {
-    public void testDelegatingScript() throws Exception {
-        def cc = new CompilerConfiguration();
-        cc.scriptBaseClass = DelegatingScript.class.name;
-        def sh = new GroovyShell(new Binding(), cc);
-        def script = (DelegatingScript)sh.parse("""
-            println DelegatingScript.class
-            foo(3,2){ a,b -> a*b };
-            bar='test';
-            assert 'testsetget'==bar
-        """)
+class DelegatingScriptTest extends GroovyTestCase {
+    void testDelegatingScript() throws Exception {
+        def cc = new CompilerConfiguration()
+        cc.scriptBaseClass = DelegatingScript.name
+        def sh = new GroovyShell(new Binding(), cc)
+        def script = (DelegatingScript) sh.parse('''
+            // println DelegatingScript.class
+            foo(3, 2) { a, b -> a * b }
+            bar = 'test'
+            assert 'testsetget' == bar
+        ''')
         def dsl = new MyDSL()
-        script.setDelegate(dsl);
-        script.run();
-        assert dsl.foo==6;
-        assert dsl.innerBar()=='testset';
+        script.setDelegate(dsl)
+        script.run()
+        assert dsl.foo == 6
+        assert dsl.innerBar() == 'testset'
     }
 
-    public void testUseMarkupBuilderAsDelegate() throws Exception {
+    void testUseMarkupBuilderAsDelegate() throws Exception {
         def cc = new CompilerConfiguration()
         cc.scriptBaseClass = DelegatingScript.class.name
         def sh = new GroovyShell(new Binding(), cc)
-        def script = sh.parse(''' foo{ bar() }
+        def script = sh.parse('''
+            foo{ bar() }
         ''')
         StringWriter sw = new StringWriter()
         def markupBuilder = new MarkupBuilder(sw)
         script.setDelegate(markupBuilder)
         script.run()
 
-        assert sw.toString() == """<foo>
+        assert sw.toString() == '''<foo>
   <bar />
-</foo>"""
+</foo>'''
     }
 }
 
 class MyDSL {
-    protected int foo;
-    protected String bar;
+    protected int foo
+    protected String bar
+
+    void foo(int x, int y, Closure z) { foo = z(x, y) }
 
-    public void foo(int x, int y, Closure z) { foo = z(x, y); }
-    public void setBar(String a) {
-        this.bar = a+"set";
+    void setBar(String a) {
+        this.bar = a + "set"
     }
-    public String getBar() {
-        return this.bar+"get";
+
+    String getBar() {
+        this.bar + "get"
     }
 
     String innerBar() {
-        return this.bar;
+        this.bar
     }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/54d9d818/subprojects/groovy-templates/src/test/groovy/groovy/bugs/groovy4585/Groovy4585Bug.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-templates/src/test/groovy/groovy/bugs/groovy4585/Groovy4585Bug.groovy b/subprojects/groovy-templates/src/test/groovy/groovy/bugs/groovy4585/Groovy4585Bug.groovy
new file mode 100644
index 0000000..be344f2
--- /dev/null
+++ b/subprojects/groovy-templates/src/test/groovy/groovy/bugs/groovy4585/Groovy4585Bug.groovy
@@ -0,0 +1,31 @@
+/*
+ *  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 groovy.bugs.groovy4585
+
+class Groovy4585Bug extends GroovyTestCase {
+    void test() {
+        def engineForBuildXml = new groovy.text.SimpleTemplateEngine(false)
+        engineForBuildXml.setEscapeBackslash(true)
+        def templateForBuildXml = engineForBuildXml.createTemplate(this.getClass().getResource("/bugs/groovy4585/groovy4585.xml").text)
+        String buildXmlContent = templateForBuildXml.make([names:['a', 'b', 'c']]).toString()
+
+        assert buildXmlContent.contains('<property name="drive" value="d:\\" />')
+        assert buildXmlContent.contains('<exec dir="${drive}" executable="echo">')
+    }
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/54d9d818/subprojects/groovy-templates/src/test/resources/bugs/groovy4585/groovy4585.xml
----------------------------------------------------------------------
diff --git a/subprojects/groovy-templates/src/test/resources/bugs/groovy4585/groovy4585.xml b/subprojects/groovy-templates/src/test/resources/bugs/groovy4585/groovy4585.xml
new file mode 100644
index 0000000..6dcf2bb
--- /dev/null
+++ b/subprojects/groovy-templates/src/test/resources/bugs/groovy4585/groovy4585.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="GB2312"?>
+<!--
+
+     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.
+
+-->
+<project name="projBuild" default="projBuild" basedir=".">
+    <property name="drive" value="d:\" />
+
+    <target name="projBuild">
+        <%for (int i = 0; i < names.size(); i++) {%>
+            <exec dir="\${drive}" executable="echo">
+                  <arg line="${names[i]}"/>
+            </exec>
+        <%}%>
+    </target>
+</project>

http://git-wip-us.apache.org/repos/asf/groovy/blob/54d9d818/subprojects/groovy-xml/src/test/groovy/groovy/tree/NavigationXmlTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/tree/NavigationXmlTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/tree/NavigationXmlTest.groovy
new file mode 100644
index 0000000..f9e0d37
--- /dev/null
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/tree/NavigationXmlTest.groovy
@@ -0,0 +1,86 @@
+/*
+ *  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 groovy.tree
+
+/**
+ * Simple test of tree walking for XML
+ *
+ * @see groovy.tree.NavigationNodeTest
+ */
+class NavigationXmlTest extends GroovyTestCase {
+    void testPrePostOrder() {
+        def root = createTreeFromXmlParser()
+        def combos = [[false, true], ['depthFirst', 'breadthFirst']].combinations()
+        def actual = combos.collect{ preorder, type ->
+            root."$type"(preorder)*.name()
+        }*.toString()
+        def expected = [
+            '[child1a, child1b, parent1, child2a, grandchild2, child2b, child2c, parent2, root]', // df post
+            '[root, parent1, child1a, child1b, parent2, child2a, child2b, grandchild2, child2c]', // df pre
+            '[grandchild2, child1a, child1b, child2a, child2b, child2c, parent1, parent2, root]', // bf post
+            '[root, parent1, parent2, child1a, child1b, child2a, child2b, child2c, grandchild2]'  // bf pre
+        ]
+        (0..3).each{ assert actual[it] == expected[it] }
+    }
+
+    void testPrePostOrderWithClosure() {
+        def root = createTreeFromXmlParser()
+        def combos = [[false, true], ['depthFirst', 'breadthFirst']].combinations()
+        def actual = combos.collect{ preorder, type ->
+            def names = []
+            root."$type"(preorder: preorder) { names << it.name() }
+            names
+        }*.toString()
+        def expected = [
+            '[child1a, child1b, parent1, child2a, grandchild2, child2b, child2c, parent2, root]', // df post
+            '[root, parent1, child1a, child1b, parent2, child2a, child2b, grandchild2, child2c]', // df pre
+            '[grandchild2, child1a, child1b, child2a, child2b, child2c, parent1, parent2, root]', // bf post
+            '[root, parent1, parent2, child1a, child1b, child2a, child2b, child2c, grandchild2]'  // bf pre
+        ]
+        (0..3).each{ assert actual[it] == expected[it] }
+    }
+
+    void testLevelWithClosure() {
+        def root = createTreeFromXmlParser()
+        def result = [:].withDefault { [] }
+        root.depthFirst { node, index ->
+            result[index] << node.name()
+        }
+        assert result == [1: ['root'], 2: ['parent1', 'parent2'], 4: ['grandchild2'],
+                          3: ['child1a', 'child1b', 'child2a', 'child2b', 'child2c']]
+    }
+
+    private static createTreeFromXmlParser() {
+        def xml = '''
+        <root>
+          <parent1>
+            <child1a/>
+            <child1b/>
+          </parent1>
+          <parent2>
+            <child2a/>
+            <child2b><grandchild2/></child2b>
+            <child2c/>
+          </parent2>
+        </root>
+        '''
+        new XmlParser().parseText(xml)
+    }
+
+}