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 2019/01/31 09:40:30 UTC

[groovy] 02/02: additional XML test tweaks (formatting and spelling)

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit ad8c74b554839fce118dd29e6b61ab17074c9e73
Author: Paul King <pa...@asert.com.au>
AuthorDate: Thu Jan 31 19:39:00 2019 +1000

    additional XML test tweaks (formatting and spelling)
---
 ...gory.groovy => UserGuideDOMCategoryTest.groovy} | 31 ++++-----
 .../spec/test/UserGuideMarkupBuilderTest.groovy    | 81 +++++++++++-----------
 .../UserGuideStreamingMarkupBuilderTest.groovy     | 20 +++---
 .../src/spec/test/UserGuideXmlParserTest.groovy    | 66 +++++++++---------
 .../src/spec/test/UserGuideXmlSlurperTest.groovy   | 12 ++--
 .../src/spec/test/UserGuideXmlUtilTest.groovy      |  6 +-
 6 files changed, 105 insertions(+), 111 deletions(-)

diff --git a/subprojects/groovy-xml/src/spec/test/UserGuideDOMCategory.groovy b/subprojects/groovy-xml/src/spec/test/UserGuideDOMCategoryTest.groovy
similarity index 76%
rename from subprojects/groovy-xml/src/spec/test/UserGuideDOMCategory.groovy
rename to subprojects/groovy-xml/src/spec/test/UserGuideDOMCategoryTest.groovy
index 40754fa..9ef6a1b 100644
--- a/subprojects/groovy-xml/src/spec/test/UserGuideDOMCategory.groovy
+++ b/subprojects/groovy-xml/src/spec/test/UserGuideDOMCategoryTest.groovy
@@ -18,13 +18,12 @@
  */
 package groovy.xml
 
-import groovy.xml.DOMBuilder
 import groovy.xml.dom.DOMCategory
 
 /**
-* Tests for the Groovy Xml user guide related to DOMCategory.
-*/
-class UserGuideDOMCategoryTest  extends GroovyTestCase {
+ * Tests for the Groovy Xml user guide related to DOMCategory.
+ */
+class UserGuideDOMCategoryTest extends GroovyTestCase {
 
     // tag::testXML[]
     static def CAR_RECORDS = '''
@@ -42,19 +41,19 @@ class UserGuideDOMCategoryTest  extends GroovyTestCase {
         <record type='price'>Most Valuable Car at $15 million</record>
       </car>
     </records>
-  '''
-  // end::testXML[]
+    '''
+    // end::testXML[]
 
-  void testExample1() {
-      // tag::testExample1[]
-      def reader = new StringReader(CAR_RECORDS)
-      def doc = DOMBuilder.parse(reader) //<1>
-      def records = doc.documentElement
+    void testExample1() {
+        // tag::testExample1[]
+        def reader = new StringReader(CAR_RECORDS)
+        def doc = DOMBuilder.parse(reader) //<1>
+        def records = doc.documentElement
 
-      use(DOMCategory) { // <2>
-          assert records.car.size() == 3
-      }
-      // end::testExample1[]
-  }
+        use(DOMCategory) { // <2>
+            assert records.car.size() == 3
+        }
+        // end::testExample1[]
+    }
 
 }
diff --git a/subprojects/groovy-xml/src/spec/test/UserGuideMarkupBuilderTest.groovy b/subprojects/groovy-xml/src/spec/test/UserGuideMarkupBuilderTest.groovy
index e872053..8c833dc 100644
--- a/subprojects/groovy-xml/src/spec/test/UserGuideMarkupBuilderTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/UserGuideMarkupBuilderTest.groovy
@@ -18,13 +18,12 @@
  */
 package groovy.xml
 
-import groovy.xml.MarkupBuilder
 import org.codehaus.groovy.tools.xml.DomToGroovy
 
 /**
-* Tests for the Groovy Xml user guide related to MarkupBuilderTest.
-*/
-class UserGuideMarkupBuilderTest  extends GroovyTestCase {
+ * Tests for the Groovy Xml user guide related to MarkupBuilderTest.
+ */
+class UserGuideMarkupBuilderTest extends GroovyTestCase {
 
     void createCarsTest() {
         // tag::createCarsTest[]
@@ -32,13 +31,13 @@ class UserGuideMarkupBuilderTest  extends GroovyTestCase {
         def xml = new MarkupBuilder(writer) // <1>
 
         xml.records() { // <2>
-            car(name:'HSV Maloo', make:'Holden', year:2006) {
+            car(name: 'HSV Maloo', make: 'Holden', year: 2006) {
                 country('Australia')
-                record(type:'speed', 'Production Pickup Truck with speed of 271kph')
+                record(type: 'speed', 'Production Pickup Truck with speed of 271kph')
             }
-            car(name:'Royale', make:'Bugatti', year:1931) {
+            car(name: 'Royale', make: 'Bugatti', year: 1931) {
                 country('France')
-                record(type:'price', 'Most Valuable Car at $15 million')
+                record(type: 'price', 'Most Valuable Car at $15 million')
             }
         }
 
@@ -98,15 +97,15 @@ class UserGuideMarkupBuilderTest  extends GroovyTestCase {
         def xmlMarkup = new MarkupBuilder(xmlWriter)
 
         xmlMarkup
-            .'x:movies'('xmlns:x':'http://www.groovy-lang.org') { // <1>
-                'x:movie'(id: 1, 'the godfather')
-                'x:movie'(id: 2, 'ronin')
-            }
+                .'x:movies'('xmlns:x': 'http://www.groovy-lang.org') { // <1>
+            'x:movie'(id: 1, 'the godfather')
+            'x:movie'(id: 2, 'ronin')
+        }
 
         def movies =
-            new XmlSlurper() // <2>
-                .parseText(xmlWriter.toString())
-                .declareNamespace(x:'http://www.groovy-lang.org')
+                new XmlSlurper() // <2>
+                        .parseText(xmlWriter.toString())
+                        .declareNamespace(x: 'http://www.groovy-lang.org')
 
         assert movies.'x:movie'.last().@id == 2
         assert movies.'x:movie'.last().text() == 'ronin'
@@ -119,22 +118,22 @@ class UserGuideMarkupBuilderTest  extends GroovyTestCase {
         def xmlMarkup = new MarkupBuilder(xmlWriter)
 
         xmlMarkup
-            .'x:movies'('xmlns:x':'http://www.groovy-lang.org') {
-                (1..3).each { n -> // <1>
-                    'x:movie'(id: n, "the godfather $n")
-                    if (n % 2 == 0) { // <2>
-                        'x:movie'(id: n, "the godfather $n (Extended)")
-                    }
+                .'x:movies'('xmlns:x': 'http://www.groovy-lang.org') {
+            (1..3).each { n -> // <1>
+                'x:movie'(id: n, "the godfather $n")
+                if (n % 2 == 0) { // <2>
+                    'x:movie'(id: n, "the godfather $n (Extended)")
                 }
             }
+        }
 
         def movies =
-            new XmlSlurper()
-                .parseText(xmlWriter.toString())
-                .declareNamespace(x:'http://www.groovy-lang.org')
+                new XmlSlurper()
+                        .parseText(xmlWriter.toString())
+                        .declareNamespace(x: 'http://www.groovy-lang.org')
 
         assert movies.'x:movie'.size() == 4
-        assert movies.'x:movie'*.text().every { name -> name.startsWith('the')}
+        assert movies.'x:movie'*.text().every { name -> name.startsWith('the') }
         // end::testComplexUse1[]
     }
 
@@ -155,23 +154,23 @@ class UserGuideMarkupBuilderTest  extends GroovyTestCase {
             return builder
         }
 
-        xmlMarkup.'x:movies'('xmlns:x':'http://www.groovy-lang.org') {
+        xmlMarkup.'x:movies'('xmlns:x': 'http://www.groovy-lang.org') {
             buildMovieList(xmlMarkup) // <2>
         }
 
         def movies =
-            new XmlSlurper()
-                .parseText(xmlWriter.toString())
-                .declareNamespace(x:'http://www.groovy-lang.org')
+                new XmlSlurper()
+                        .parseText(xmlWriter.toString())
+                        .declareNamespace(x: 'http://www.groovy-lang.org')
 
         assert movies.'x:movie'.size() == 4
-        assert movies.'x:movie'*.text().every { name -> name.startsWith('the')}
+        assert movies.'x:movie'*.text().every { name -> name.startsWith('the') }
         // end::testComplexUse2[]
     }
 
     void testDOMToGroovy() {
         // tag::testDOMToGroovy[]
-        def songs  = """
+        def songs = """
             <songs>
               <song>
                 <title>Here I go</title>
@@ -180,19 +179,19 @@ class UserGuideMarkupBuilderTest  extends GroovyTestCase {
             </songs>
         """
 
-        def builder     =
-            javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder()
+        def builder =
+                javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder()
 
-            def inputStream = new ByteArrayInputStream(songs.bytes)
-            def document    = builder.parse(inputStream)
-            def output      = new StringWriter()
-            def converter   = new DomToGroovy(new PrintWriter(output)) // <1>
+        def inputStream = new ByteArrayInputStream(songs.bytes)
+        def document = builder.parse(inputStream)
+        def output = new StringWriter()
+        def converter = new DomToGroovy(new PrintWriter(output)) // <1>
 
-            converter.print(document) // <2>
+        converter.print(document) // <2>
 
-            String xmlRecovered  =
+        String xmlRecovered =
                 new GroovyShell()
-                .evaluate("""
+                        .evaluate("""
                    def writer = new StringWriter()
                    def builder = new groovy.xml.MarkupBuilder(writer)
                    builder.${output}
@@ -200,7 +199,7 @@ class UserGuideMarkupBuilderTest  extends GroovyTestCase {
                    return writer.toString()
                 """) // <3>
 
-            assert new XmlSlurper().parseText(xmlRecovered).song.title.text() == 'Here I go' // <4>
+        assert new XmlSlurper().parseText(xmlRecovered).song.title.text() == 'Here I go' // <4>
         // end::testDOMToGroovy[]
     }
 
diff --git a/subprojects/groovy-xml/src/spec/test/UserGuideStreamingMarkupBuilderTest.groovy b/subprojects/groovy-xml/src/spec/test/UserGuideStreamingMarkupBuilderTest.groovy
index a0681bd..17a2e92 100644
--- a/subprojects/groovy-xml/src/spec/test/UserGuideStreamingMarkupBuilderTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/UserGuideStreamingMarkupBuilderTest.groovy
@@ -18,28 +18,26 @@
  */
 package groovy.xml
 
-import groovy.xml.StreamingMarkupBuilder
-
 /**
-* Tests for the Groovy Xml user guide related to StreamingMarkupBuilderTest.
-*/
-class UserGuideStreamingMarkupBuilderTest  extends GroovyTestCase {
+ * Tests for the Groovy Xml user guide related to StreamingMarkupBuilderTest.
+ */
+class UserGuideStreamingMarkupBuilderTest extends GroovyTestCase {
 
     void testSimpleExample() {
         // tag::testSimpleExample[]
         def xml = new StreamingMarkupBuilder().bind { // <1>
             records {
-                car(name:'HSV Maloo', make:'Holden', year:2006) { // <2>
+                car(name: 'HSV Maloo', make: 'Holden', year: 2006) { // <2>
                     country('Australia')
-                    record(type:'speed', 'Production Pickup Truck with speed of 271kph')
+                    record(type: 'speed', 'Production Pickup Truck with speed of 271kph')
                 }
-                car(name:'P50', make:'Peel', year:1962) {
+                car(name: 'P50', make: 'Peel', year: 1962) {
                     country('Isle of Man')
-                    record(type:'size', 'Smallest Street-Legal Car at 99cm wide and 59 kg in weight')
+                    record(type: 'size', 'Smallest Street-Legal Car at 99cm wide and 59 kg in weight')
                 }
-                car(name:'Royale', make:'Bugatti', year:1931) {
+                car(name: 'Royale', make: 'Bugatti', year: 1931) {
                     country('France')
-                    record(type:'price', 'Most Valuable Car at $15 million')
+                    record(type: 'price', 'Most Valuable Car at $15 million')
                 }
             }
         }
diff --git a/subprojects/groovy-xml/src/spec/test/UserGuideXmlParserTest.groovy b/subprojects/groovy-xml/src/spec/test/UserGuideXmlParserTest.groovy
index ffbfea3..65d34c5 100644
--- a/subprojects/groovy-xml/src/spec/test/UserGuideXmlParserTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/UserGuideXmlParserTest.groovy
@@ -18,12 +18,10 @@
  */
 package groovy.xml
 
-import groovy.util.GroovyTestCase
-
 /**
-* Tests for the Groovy Xml user guide related to XmlParser.
-*/
-class UserGuideXmlParserTest  extends GroovyTestCase {
+ * Tests for the Groovy Xml user guide related to XmlParser.
+ */
+class UserGuideXmlParserTest extends GroovyTestCase {
 
     // tag::responseBookXml[]
     def xml = """
@@ -31,8 +29,8 @@ class UserGuideXmlParserTest  extends GroovyTestCase {
         <value>
             <books>
                 <book id="2">
-                    <title>Don Xijote</title>
-                    <author id="1">Manuel De Cervantes</author>
+                    <title>Don Quixote</title>
+                    <author id="1">Miguel de Cervantes</author>
                 </book>
             </books>
         </value>
@@ -62,9 +60,9 @@ class UserGuideXmlParserTest  extends GroovyTestCase {
         def parser = new XmlParser()
         def response = parser.parseText(xml)
         def numberOfResults = parser.createNode(
-            response,
-            new QName("numberOfResults"),
-            [:]
+                response,
+                new QName("numberOfResults"),
+                [:]
         )
 
         numberOfResults.value = "1"
@@ -78,9 +76,9 @@ class UserGuideXmlParserTest  extends GroovyTestCase {
         def response = parser.parseText(xml)
 
         response.appendNode(
-            new QName("numberOfResults"),
-            [:],
-            "1"
+                new QName("numberOfResults"),
+                [:],
+                "1"
         )
 
         response.numberOfResults.text() == "1"
@@ -89,34 +87,34 @@ class UserGuideXmlParserTest  extends GroovyTestCase {
 
     void testModifyingNodes1() {
         // tag::testModifyingNodes1[]
-         def response = new XmlParser().parseText(xml)
-
-      /* Use the same syntax as groovy.xml.MarkupBuilder */
-         response.value.books.book[0].replaceNode{ // <1>
-             book(id:"3"){
-                 title("To Kill a Mockingbird")
-                 author(id:"3","Harper Lee")
-             }
-         }
-
-         def newNode = response.value.books.book[0]
-
-         assert newNode.name() == "book"
-         assert newNode.@id == "3"
-         assert newNode.title.text() == "To Kill a Mockingbird"
-         assert newNode.author.text() == "Harper Lee"
-         assert newNode.author.@id.first() == "3"
+        def response = new XmlParser().parseText(xml)
+
+        /* Use the same syntax as groovy.xml.MarkupBuilder */
+        response.value.books.book[0].replaceNode { // <1>
+            book(id: "3") {
+                title("To Kill a Mockingbird")
+                author(id: "3", "Harper Lee")
+            }
+        }
+
+        def newNode = response.value.books.book[0]
+
+        assert newNode.name() == "book"
+        assert newNode.@id == "3"
+        assert newNode.title.text() == "To Kill a Mockingbird"
+        assert newNode.author.text() == "Harper Lee"
+        assert newNode.author.@id.first() == "3"
         // end::testModifyingNodes1[]
     }
 
     void testSettingAttributes1() {
         // tag::testSettingAttributes1[]
-         def parser = new XmlParser()
-         def response = parser.parseText(xml)
+        def parser = new XmlParser()
+        def response = parser.parseText(xml)
 
-         response.@numberOfResults = "1"
+        response.@numberOfResults = "1"
 
-         assert response.@numberOfResults == "1"
+        assert response.@numberOfResults == "1"
         // end::testSettingAttributes1[]
     }
 
diff --git a/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy b/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy
index 41b5c10..94a5f27 100644
--- a/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy
@@ -29,8 +29,8 @@ class UserGuideXmlSlurperTest extends GroovyTestCase {
             <value>
                 <books>
                     <book available="20" id="1">
-                        <title>Don Xijote</title>
-                        <author id="1">Miguel De Cervantes</author>
+                        <title>Don Quixote</title>
+                        <author id="1">Miguel de Cervantes</author>
                     </book>
                     <book available="14" id="2">
                         <title>Catcher in the Rye</title>
@@ -41,8 +41,8 @@ class UserGuideXmlSlurperTest extends GroovyTestCase {
                        <author id="3">Lewis Carroll</author>
                    </book>
                    <book available="5" id="4">
-                       <title>Don Xijote</title>
-                       <author id="4">Miguel De Cervantes</author>
+                       <title>Don Quixote</title>
+                       <author id="4">Miguel de Cervantes</author>
                    </book>
                </books>
            </value>
@@ -72,7 +72,7 @@ class UserGuideXmlSlurperTest extends GroovyTestCase {
         def response = new XmlSlurper().parseText(books)
         def authorResult = response.value.books.book[0].author
 
-        assert authorResult.text() == 'Miguel De Cervantes'
+        assert authorResult.text() == 'Miguel de Cervantes'
         // end::testGettingANodeText[]
     }
 
@@ -165,7 +165,7 @@ class UserGuideXmlSlurperTest extends GroovyTestCase {
             }
         }
 
-        assert response.value.books.book[0].title.text() == "Don Xijote"
+        assert response.value.books.book[0].title.text() == "Don Quixote"
 
         /* That mkp is a special namespace used to escape away from the normal building mode
            of the builder and get access to helper markup methods
diff --git a/subprojects/groovy-xml/src/spec/test/UserGuideXmlUtilTest.groovy b/subprojects/groovy-xml/src/spec/test/UserGuideXmlUtilTest.groovy
index b43e0c4..e817d32 100644
--- a/subprojects/groovy-xml/src/spec/test/UserGuideXmlUtilTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/UserGuideXmlUtilTest.groovy
@@ -29,8 +29,8 @@ class UserGuideXmlUtilTest extends GroovyTestCase {
         <value>
             <books>
                 <book id="2">
-                    <title>Don Xijote</title>
-                    <author id="1">Miguel De Cervantes</author>
+                    <title>Don Quixote</title>
+                    <author id="1">Miguel de Cervantes</author>
                 </book>
             </books>
         </value>
@@ -45,7 +45,7 @@ class UserGuideXmlUtilTest extends GroovyTestCase {
         def nodeAsText = XmlUtil.serialize(nodeToSerialize)
 
         assert nodeAsText ==
-                XmlUtil.serialize('<?xml version="1.0" encoding="UTF-8"?><author id="1">Miguel De Cervantes</author>')
+                XmlUtil.serialize('<?xml version="1.0" encoding="UTF-8"?><author id="1">Miguel de Cervantes</author>')
         // end::testGettingANode[]
     }