From 3187670ae8fa4a22fb52180afabfe308d8daf365 Mon Sep 17 00:00:00 2001 From: Olivier Blanvillain Date: Sat, 4 Feb 2017 21:36:18 +0100 Subject: [PATCH 1/3] Move js tests to shared --- {js => shared}/src/test/scala/scala/xml/ReuseNodesTest.scala | 0 {js => shared}/src/test/scala/scala/xml/XMLSyntaxTest.scala | 0 {js => shared}/src/test/scala/scala/xml/XMLTest.scala | 0 .../src/test/scala/scala/xml/parsing/PiParsingTest.scala | 0 .../src/test/scala/scala/xml/parsing/Ticket0632Test.scala | 0 .../src/test/scala/scala/xml/pull/XMLEventReaderTest.scala | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename {js => shared}/src/test/scala/scala/xml/ReuseNodesTest.scala (100%) rename {js => shared}/src/test/scala/scala/xml/XMLSyntaxTest.scala (100%) rename {js => shared}/src/test/scala/scala/xml/XMLTest.scala (100%) rename {js => shared}/src/test/scala/scala/xml/parsing/PiParsingTest.scala (100%) rename {js => shared}/src/test/scala/scala/xml/parsing/Ticket0632Test.scala (100%) rename {js => shared}/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala (100%) diff --git a/js/src/test/scala/scala/xml/ReuseNodesTest.scala b/shared/src/test/scala/scala/xml/ReuseNodesTest.scala similarity index 100% rename from js/src/test/scala/scala/xml/ReuseNodesTest.scala rename to shared/src/test/scala/scala/xml/ReuseNodesTest.scala diff --git a/js/src/test/scala/scala/xml/XMLSyntaxTest.scala b/shared/src/test/scala/scala/xml/XMLSyntaxTest.scala similarity index 100% rename from js/src/test/scala/scala/xml/XMLSyntaxTest.scala rename to shared/src/test/scala/scala/xml/XMLSyntaxTest.scala diff --git a/js/src/test/scala/scala/xml/XMLTest.scala b/shared/src/test/scala/scala/xml/XMLTest.scala similarity index 100% rename from js/src/test/scala/scala/xml/XMLTest.scala rename to shared/src/test/scala/scala/xml/XMLTest.scala diff --git a/js/src/test/scala/scala/xml/parsing/PiParsingTest.scala b/shared/src/test/scala/scala/xml/parsing/PiParsingTest.scala similarity index 100% rename from js/src/test/scala/scala/xml/parsing/PiParsingTest.scala rename to shared/src/test/scala/scala/xml/parsing/PiParsingTest.scala diff --git a/js/src/test/scala/scala/xml/parsing/Ticket0632Test.scala b/shared/src/test/scala/scala/xml/parsing/Ticket0632Test.scala similarity index 100% rename from js/src/test/scala/scala/xml/parsing/Ticket0632Test.scala rename to shared/src/test/scala/scala/xml/parsing/Ticket0632Test.scala diff --git a/js/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala b/shared/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala similarity index 100% rename from js/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala rename to shared/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala From 0e43f6be172113a057961ebd11ca43b545026a0d Mon Sep 17 00:00:00 2001 From: Olivier Blanvillain Date: Sat, 4 Feb 2017 21:48:06 +0100 Subject: [PATCH 2/3] Remove two empty test classes (these tested nothing) --- .../test/scala/scala/xml/ReuseNodesTest.scala | 58 ------------------- .../scala/xml/pull/XMLEventReaderTest.scala | 19 ------ 2 files changed, 77 deletions(-) delete mode 100644 shared/src/test/scala/scala/xml/ReuseNodesTest.scala delete mode 100644 shared/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala diff --git a/shared/src/test/scala/scala/xml/ReuseNodesTest.scala b/shared/src/test/scala/scala/xml/ReuseNodesTest.scala deleted file mode 100644 index 75f67efaf..000000000 --- a/shared/src/test/scala/scala/xml/ReuseNodesTest.scala +++ /dev/null @@ -1,58 +0,0 @@ -package scala.xml - -import scala.xml.transform._ -import org.junit.Test -import org.junit.Assert.assertTrue -import org.junit.Assert.assertEquals -import org.junit.runner.RunWith -/** - * This test verify that after the tranform, the resultant xml node - * uses as many old nodes as possible. - * - * Three transformers class for case - - * One for orginal, one for modified, and one proposed which shows - * all are equivalent when it comes to reusing as many nodes as possible - */ -object ReuseNodesTest { - - class OriginalTranformr(rules: RewriteRule*) extends RuleTransformer(rules:_*) { - override def transform(ns: Seq[Node]): Seq[Node] = { - val xs = ns.toStream map transform - val (xs1, xs2) = xs zip ns span { case (x, n) => unchanged(n, x) } - - if (xs2.isEmpty) ns - else (xs1 map (_._2)) ++ xs2.head._1 ++ transform(ns drop (xs1.length + 1)) - } - override def transform(n:Node): Seq[Node] = super.transform(n) - } - - class ModifiedTranformr(rules: RewriteRule*) extends RuleTransformer(rules:_*) { - override def transform(ns: Seq[Node]): Seq[Node] = { - val changed = ns flatMap transform - - if (changed.length != ns.length || (changed, ns).zipped.exists(_ != _)) changed - else ns - } - override def transform(n:Node): Seq[Node] = super.transform(n) - } - - class AlternateTranformr(rules: RewriteRule*) extends RuleTransformer(rules:_*) { - override def transform(ns: Seq[Node]): Seq[Node] = { - val xs = ns.toStream map transform - val (xs1, xs2) = xs zip ns span { case (x, n) => unchanged(n, x) } - - if (xs2.isEmpty) ns - else (xs1 map (_._2)) ++ xs2.head._1 ++ transform(ns drop (xs1.length + 1)) - } - override def transform(n:Node): Seq[Node] = super.transform(n) - } - - def rewriteRule = new RewriteRule { - override def transform(n: Node): NodeSeq = n match { - case n if n.label == "change" => Elem( - n.prefix, "changed", n.attributes, n.scope, n.child.isEmpty, n.child : _*) - case _ => n - } - } - -} diff --git a/shared/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala b/shared/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala deleted file mode 100644 index 6cfd4e872..000000000 --- a/shared/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala +++ /dev/null @@ -1,19 +0,0 @@ -package scala.xml -package pull - -import org.junit.Test -import org.junit.Assert.{assertFalse, assertTrue} - -import scala.io.Source -import scala.xml.parsing.FatalError - -class XMLEventReaderTest { - - val src = Source.fromString("!") - - private def toSource(s: String) = new Source { - val iter = s.iterator - override def reportError(pos: Int, msg: String, out: java.io.PrintStream = Console.err) {} - } - -} From 2eafecbdbf58c8c1be530bf0dd4335098092916d Mon Sep 17 00:00:00 2001 From: Olivier Blanvillain Date: Sat, 4 Feb 2017 21:49:25 +0100 Subject: [PATCH 3/3] Remove duplicated shared/jvm tests, prepend JVM to test classes when required Moving jv tests to shared introduced name conflicts on the duplicated calsses, the rename solves that --- .../test/scala/scala/xml/XMLSyntaxTest.scala | 57 +-- jvm/src/test/scala/scala/xml/XMLTest.scala | 333 +----------------- .../scala/xml/parsing/PiParsingTest.scala | 13 +- .../scala/xml/parsing/Ticket0632Test.scala | 8 +- 4 files changed, 6 insertions(+), 405 deletions(-) diff --git a/jvm/src/test/scala/scala/xml/XMLSyntaxTest.scala b/jvm/src/test/scala/scala/xml/XMLSyntaxTest.scala index fa250b416..16155bc58 100644 --- a/jvm/src/test/scala/scala/xml/XMLSyntaxTest.scala +++ b/jvm/src/test/scala/scala/xml/XMLSyntaxTest.scala @@ -8,62 +8,7 @@ import org.junit.Assert.assertTrue import org.junit.Assert.assertFalse import org.junit.Assert.assertEquals -class XMLSyntaxTest { - - private def handle[A](x: Node): A = { - x.child(0).asInstanceOf[Atom[A]].data - } - - @Test - def test1(): Unit = { - val xNull = {null} // these used to be Atom(unit), changed to empty children - assertTrue(xNull.child sameElements Nil) - - val x0 = {} // these used to be Atom(unit), changed to empty children - val x00 = { } // dto. - val xa = { "world" } - - assertTrue(x0.child sameElements Nil) - assertTrue(x00.child sameElements Nil) - assertEquals("world", handle[String](xa)) - - val xb = { 1.5 } - assertEquals(1.5, handle[Double](xb), 0.0) - - val xc = { 5 } - assertEquals(5, handle[Int](xc)) - - val xd = { true } - assertEquals(true, handle[Boolean](xd)) - - val xe = { 5:Short } - assertEquals((5:Short), handle[Short](xe)) - - val xf = { val x = 27; x } - assertEquals(27, handle[Int](xf)) - - val xg = { List(1,2,3,4) } - assertEquals("1 2 3 4", xg.toString) - assertFalse(xg.child.map(_.isInstanceOf[Text]).exists(identity)) - - val xh = { for(x <- List(1,2,3,4) if x % 2 == 0) yield x } - assertEquals("2 4", xh.toString) - assertFalse(xh.child.map(_.isInstanceOf[Text]).exists(identity)) - } - - /** see SVN r13821 (emir): support for , - * so that Options can be used for optional attributes. - */ - @Test - def test2(): Unit = { - val x1: Option[Seq[Node]] = Some(hello) - val n1 = ; - assertEquals(x1, n1.attribute("key")) - - val x2: Option[Seq[Node]] = None - val n2 = ; - assertEquals(x2, n2.attribute("key")) - } +class XMLSyntaxTestJVM { @Test def test3(): Unit = { diff --git a/jvm/src/test/scala/scala/xml/XMLTest.scala b/jvm/src/test/scala/scala/xml/XMLTest.scala index c86184ffd..aea258486 100644 --- a/jvm/src/test/scala/scala/xml/XMLTest.scala +++ b/jvm/src/test/scala/scala/xml/XMLTest.scala @@ -17,212 +17,13 @@ import java.io.StringReader import scala.collection.Iterable import scala.xml.Utility.sort -object XMLTest { +object XMLTestJVM { val e: scala.xml.MetaData = Null //Node.NoAttributes val sc: scala.xml.NamespaceBinding = TopScope } -class XMLTest { - import XMLTest.{ e, sc } - - @UnitTest - def nodeSeq: Unit = { - val p = - - - - - - val pelems_1 = for (x <- p \ "bar"; y <- p \ "baz") yield { - Text(x.attributes("value").toString + y.attributes("bazValue").toString + "!") - }; - - val pelems_2 = NodeSeq.fromSeq(List(Text("38!"), Text("58!"))); - assertTrue(pelems_1 sameElements pelems_2) - assertTrue(Text("8") sameElements (p \\ "@bazValue")) - } - - @UnitTest - def queryBooks: Unit = { - val books = - - Blabla - Blubabla - Baaaaaaalabla - ; - - val reviews = - - - Blabla - - Hallo Welt. - - - - Blubabla - - Hello Blu - - - - Blubabla - - rem 2 - - - ; - - val results1 = new scala.xml.PrettyPrinter(80, 5).formatNodes( - for ( - t <- books \\ "title"; - r <- reviews \\ "entry" if (r \ "title") xml_== t - ) yield - { t } - { r \ "remarks" } - ); - val results1Expected = """ - | Blabla - | Hallo Welt. - | - | Blubabla - | Hello Blu - | - | Blubabla - | rem 2 - |""".stripMargin - assertEquals(results1Expected, results1) - - { - val actual = for (t @ Blabla <- NodeSeq.fromSeq(books.child).toList) - yield t - val expected = List(Blabla) - assertEquals(expected, actual) - } - - } - - @UnitTest - def queryPhoneBook: Unit = { - val phoneBook = - - - This is thephonebook - of the - ACME - corporation. - - - John - +41 21 693 68 67 - +41 79 602 23 23 - - ; - - val addrBook = - - - This is theaddressbook - of the - ACME - corporation. - - - John - Elm Street - Dolphin City - - ; - - val actual: String = new scala.xml.PrettyPrinter(80, 5).formatNodes( - for ( - t <- addrBook \\ "entry"; - r <- phoneBook \\ "entry" if (t \ "name") xml_== (r \ "name") - ) yield - { t.child } - { r \ "phone" } - ) - val expected = """| - | John - | Elm Street - | Dolphin City - | +41 21 693 68 67 - | +41 79 602 23 23 - |""".stripMargin - assertEquals(expected, actual) - } - - @UnitTest - def namespaces: Unit = { - val cuckoo = - - - ; - assertEquals("http://cuckoo.com", cuckoo.namespace) - for (n <- cuckoo \ "_") { - assertEquals("http://cuckoo.com", n.namespace) - } - } - - @UnitTest - def namespacesWithNestedXmls: Unit = { - val foo = - val bar = {foo} - val expected = """""" - val actual = bar.toString - assertEquals(expected, actual) - } - - @UnitTest - def validationOfElements: Unit = { - val vtor = new scala.xml.dtd.ElementValidator(); - { - import scala.xml.dtd.ELEMENTS - import scala.xml.dtd.ContentModel._ - vtor.setContentModel( - ELEMENTS( - Sequ( - Letter(ElemName("bar")), - Star(Letter(ElemName("baz")))))); - } - assertTrue(vtor()) - - { - import scala.xml.dtd.MIXED - import scala.xml.dtd.ContentModel._ - - vtor.setContentModel( - MIXED( - Alt(Letter(ElemName("bar")), - Letter(ElemName("baz")), - Letter(ElemName("bal"))))); - } - - assertTrue(vtor()) - assertTrue(vtor(abcdedgh)) - assertFalse(vtor( )) - } - - def validationfOfAttributes: Unit = { - val vtor = new scala.xml.dtd.ElementValidator(); - vtor.setContentModel(null) - vtor.setMetaData(List()) - assertFalse(vtor()) - - { - import scala.xml.dtd._ - vtor setMetaData List(AttrDecl("bar", "CDATA", IMPLIED)) - } - assertFalse(vtor()) - assertTrue(vtor()) - - { - import scala.xml.dtd._ - vtor.setMetaData(List(AttrDecl("bar", "CDATA", REQUIRED))) - } - assertFalse(vtor()) - assertTrue(vtor()) - } +class XMLTestJVM { + import XMLTestJVM.{ e, sc } def Elem(prefix: String, label: String, attributes: MetaData, scope: NamespaceBinding, child: Node*): Elem = scala.xml.Elem.apply(prefix, label, attributes, scope, minimizeEmpty = true, child: _*) @@ -344,21 +145,6 @@ class XMLTest { Elem(null, "title", e, sc, Text("Foundations of Programming Languages")))) } - @UnitTest - def groupNode = { - val zx1: Node = Group { } - val zy1: Node = { zx1 } - assertEquals("", zy1.toString) - - assertEquals("", - Group { List(, zy1, zx1) }.toString) - - val zz1 = - - assertTrue(zx1 xml_== zz1) - assertTrue(zz1.length == 3) - } - @UnitTest def unparsed = { // println("attribute value normalization") @@ -386,119 +172,6 @@ class XMLTest { assertTrue(n.attributes.get("BAR", n, "attr").nonEmpty) } - @UnitTest - def dodgyNamespace = { - val x = - assertTrue(x.toString.matches(".*xmlns:dog=\"http://dog.com\".*")); - } - - import NodeSeq.seqToNodeSeq - - val ax = - - - - val cx = - crazy text world - - - val bx = - - @UnitTest - def XmlEx = { - assertTrue((ax \ "@foo") xml_== "bar") // uses NodeSeq.view! - assertTrue((ax \ "@foo") xml_== xml.Text("bar")) // dto. - assertTrue((bx \ "@foo") xml_== "bar&x") // dto. - assertTrue((bx \ "@foo") xml_sameElements List(xml.Text("bar&x"))) - assertTrue("" == bx.toString) - } - - @UnitTest - def XmlEy { - val z = ax \ "@{the namespace from outer space}foo" - assertTrue((ax \ "@{the namespace from outer space}foo") xml_== "baz") - assertTrue((cx \ "@{the namespace from outer space}foo") xml_== "baz") - - try { - ax \ "@" - assertTrue(false) - } catch { - case _: IllegalArgumentException => - } - try { - ax \ "@{" - assertTrue(false) - } catch { - case _: IllegalArgumentException => - } - try { - ax \ "@{}" - assertTrue(false) - } catch { - case _: IllegalArgumentException => - } - - } - - @UnitTest - def comment = - assertEquals("", toString) - - @UnitTest - def weirdElem = - assertEquals("", toString) - - @UnitTest - def escape = - assertEquals(""" - "Come, come again, whoever you are, come! -Heathen, fire worshipper or idolatrous, come! -Come even if you broke your penitence a hundred times, -Ours is the portal of hope, come as you are." - Mevlana Celaleddin Rumi""", toString) // this guy will escaped, and rightly so - - @UnitTest - def unparsed2 = { - object myBreak extends scala.xml.Unparsed("
") - assertEquals("
", { myBreak } toString) // shows use of unparsed - } - - @UnitTest - def justDontFail = { - match { - case scala.xml.QNode("gaga", "foo", md, child @ _*) => - } - - match { - case scala.xml.Node("foo", md, child @ _*) => - } - } - - @UnitTest - def ioPosition = { - val out = new ByteArrayOutputStream - Console.withErr(out) { - Console.withOut(out) { - try { - xml.parsing.ConstructingParser.fromSource(io.Source.fromString(""), false).document() - } catch { - case e: Exception => println(e.getMessage) - } - } - } - out.flush() - assertEquals( - """:1:5: '/' expected instead of '' ^ -:1:5: name expected, but char '' cannot start a name ^ -expected closing tag of foo -""", out.toString) - } - def f(s: String) = { { diff --git a/jvm/src/test/scala/scala/xml/parsing/PiParsingTest.scala b/jvm/src/test/scala/scala/xml/parsing/PiParsingTest.scala index e9769d374..d002eeb36 100644 --- a/jvm/src/test/scala/scala/xml/parsing/PiParsingTest.scala +++ b/jvm/src/test/scala/scala/xml/parsing/PiParsingTest.scala @@ -6,7 +6,7 @@ import org.junit.runner.RunWith import org.junit.runners.JUnit4 import scala.xml.JUnitAssertsForXML.assertEquals -class PiParsingTest { +class PiParsingTestJVM { import scala.io.Source.fromString @@ -21,12 +21,6 @@ class PiParsingTest { assertEquals(expected, parseNoWS("ab")) } - @Test - def piNoWSLiteral: Unit = { - val expected = "ab" - assertEquals(expected, ab) - } - @Test def piNoWSloadString: Unit = { val expected = "ab" @@ -44,10 +38,5 @@ class PiParsingTest { val expected = " a b " assertEquals(expected, xml.XML.loadString(" a b ")) } - @Test - def piLiteral: Unit = { - val expected = " a b " - assertEquals(expected, a b ) - } } diff --git a/jvm/src/test/scala/scala/xml/parsing/Ticket0632Test.scala b/jvm/src/test/scala/scala/xml/parsing/Ticket0632Test.scala index 7a6b71a71..3691071fa 100644 --- a/jvm/src/test/scala/scala/xml/parsing/Ticket0632Test.scala +++ b/jvm/src/test/scala/scala/xml/parsing/Ticket0632Test.scala @@ -6,7 +6,7 @@ import org.junit.runner.RunWith import org.junit.runners.JUnit4 import scala.xml.JUnitAssertsForXML.assertEquals -class Ticket0632Test { +class Ticket0632TestJVM { import scala.io.Source.fromString import scala.xml.parsing.ConstructingParser.fromSource @@ -18,8 +18,6 @@ class Ticket0632Test { val expected = "" assertEquals(expected, parse("")) assertEquals(expected, xml.XML.loadString("")) - assertEquals(expected, ) - assertEquals(expected, ) } @Test @@ -27,8 +25,6 @@ class Ticket0632Test { val expected = "" assertEquals(expected, xml.XML.loadString("")) assertEquals(expected, parse("")) - assertEquals(expected, ) - assertEquals(expected, ) } @Test @@ -36,8 +32,6 @@ class Ticket0632Test { val expected = "" assertEquals(expected, xml.XML.loadString("")) assertEquals(expected, parse("")) - assertEquals(expected, ) - assertEquals(expected, ) } }