[1/2] groovy git commit: minor refactor: slight decoupling of module dependencies

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[1/2] groovy git commit: minor refactor: slight decoupling of module dependencies

paulk
Repository: groovy
Updated Branches:
  refs/heads/master 040e8a04c -> 0a6e76dd2


minor refactor: slight decoupling of module dependencies


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

Branch: refs/heads/master
Commit: 0a6e76dd2f816eef4ce83e94a97c156ad6b2d2cc
Parents: 26cacfc
Author: Paul King <[hidden email]>
Authored: Mon Jul 9 16:28:15 2018 +1000
Committer: Paul King <[hidden email]>
Committed: Mon Jul 9 16:31:04 2018 +1000

----------------------------------------------------------------------
 build.gradle                        | 1 +
 subprojects/groovy-ant/build.gradle | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/0a6e76dd/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
index 8e0c92c..7fd5ee7 100644
--- a/build.gradle
+++ b/build.gradle
@@ -241,6 +241,7 @@ dependencies {
     antlr2 "org.apache.ant:ant-antlr:$antVersion"
 
     testCompile project(':groovy-ant')
+    testCompile project(':groovy-xml')
     testCompile project(':groovy-dateutil')
     testCompile project(':groovy-test')
     testCompile project(':groovy-macro')

http://git-wip-us.apache.org/repos/asf/groovy/blob/0a6e76dd/subprojects/groovy-ant/build.gradle
----------------------------------------------------------------------
diff --git a/subprojects/groovy-ant/build.gradle b/subprojects/groovy-ant/build.gradle
index 6fb5ba4..045cf4b 100644
--- a/subprojects/groovy-ant/build.gradle
+++ b/subprojects/groovy-ant/build.gradle
@@ -25,8 +25,11 @@ dependencies {
     runtime "org.apache.ant:ant-launcher:$antVersion"
     runtime "org.apache.ant:ant-antlr:$antVersion"
     // for groovydoc ant command
-    compile project(':groovy-groovydoc')
+    compile project(':groovy-groovydoc'), {
+        transitive = false
+    }
     testCompile project(':groovy-test')
+    testCompile project(':groovy-xml')
 }
 
 apply from: "${rootProject.projectDir}/gradle/jacoco/jacocofix.gradle"
\ No newline at end of file

Reply | Threaded
Open this post in threaded view
|

[2/2] groovy git commit: minor refactor: move some tests into their respective modules

paulk
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/26cacfc7
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/26cacfc7
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/26cacfc7

Branch: refs/heads/master
Commit: 26cacfc79882e081d079e9aea2165cf9ef6d0af2
Parents: 040e8a0
Author: Paul King <[hidden email]>
Authored: Mon Jul 9 15:22:21 2018 +1000
Committer: Paul King <[hidden email]>
Committed: Mon Jul 9 16:31:04 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/26cacfc7/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/26cacfc7/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/26cacfc7/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/26cacfc7/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/26cacfc7/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/26cacfc7/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/26cacfc7/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/26cacfc7/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)
+    }
+
+}