diff --git a/build.sbt b/build.sbt index 8cd957ab7..455c86f82 100644 --- a/build.sbt +++ b/build.sbt @@ -81,6 +81,8 @@ pomExtra := ( // default value must be set here TestKeys.includeTestDependencies := true +libraryDependencies ++= Seq("junit" % "junit" % "4.11" % "test", "com.novocode" % "junit-interface" % "0.10" % "test") + // default TestKeys.partestVersion := "1.0.0-RC6" @@ -88,16 +90,34 @@ TestKeys.partestVersion := "1.0.0-RC6" // so that it can link to the compiler/lib we're using (testing) // NOTE: not sure why, but the order matters (maybe due to the binary version conflicts for xml/parser combinators pulled in for scaladoc?) libraryDependencies ++= ( - if (TestKeys.includeTestDependencies.value) - Seq("org.scala-lang.modules" %% "scala-partest-interface" % "0.2" % "test", - "org.scala-lang.modules" %% "scala-partest" % TestKeys.partestVersion.value % "test") + if (TestKeys.includeTestDependencies.value) { + /** + * Exclude all transitive dependencies of partest that include scala-.xml. + * This way we avoid having two (or more) versions of scala-xml on a classpath. + * This fixes problem described here: + * https://github.com/scala/scala-xml/pull/6#issuecomment-26614894 + * + * Note that we are using ModuleID.exclude instead of more flexible ModuleID.excludeAll + * (describe here: http://www.scala-sbt.org/release/docs/Detailed-Topics/Library-Management#exclude-transitive-dependencies) + * because only plain excludes are incorporated in generated pom.xml. There are two ways + * to address this problem: + * + * 1. Figure out how to depend on partest in non-transitive way: not include that dependency + * in generated pom.xml for scala-xml. + * 2. Declare dependencies in partest as provided so they are not includeded transitively. + * + */ + def excludeScalaXml(dep: ModuleID): ModuleID = + dep.exclude("org.scala-lang.modules", "scala-xml_2.11.0-M5"). + exclude("org.scala-lang.modules", "scala-xml_2.11.0-M4"). + exclude("org.scalacheck", "scalacheck_2.11.0-M5") + Seq("org.scala-lang.modules" % "scala-partest-interface_2.11.0-M5" % "0.2" % "test", + "org.scala-lang.modules" % "scala-partest_2.11.0-M5" % TestKeys.partestVersion.value % "test"). + map(excludeScalaXml) + } else Seq.empty ) - -// necessary for partest -- see comments in its build.sbt -conflictWarning ~= { _.copy(failOnConflict = false) } - fork in Test := true javaOptions in Test += "-Xmx1G" diff --git a/src/test/scala/scala/xml/AttributeTest.scala b/src/test/scala/scala/xml/AttributeTest.scala new file mode 100644 index 000000000..13aa7bfc6 --- /dev/null +++ b/src/test/scala/scala/xml/AttributeTest.scala @@ -0,0 +1,68 @@ +package scala.xml + +import org.junit.Test +import org.junit.Ignore +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Assert.assertTrue +import org.junit.Assert.assertFalse +import org.junit.Assert.assertEquals + +class AttributeTest { + @Test + def unprefixedAttribute: Unit = { + val x = new UnprefixedAttribute("foo","bar", Null) + assertEquals(Some(Text("bar")), x.get("foo")) + assertEquals(Text("bar"), x("foo")) + assertEquals(None, x.get("no_foo")) + assertEquals(null, x("no_foo")) + + val y = x.remove("foo") + assertEquals(Null, y) + + val z = new UnprefixedAttribute("foo", null:NodeSeq, x) + assertEquals(None, z.get("foo")) + + var appended = x append x append x append x + var len = 0; while (appended ne Null) { + appended = appended.next + len = len + 1 + } + assertEquals("removal of duplicates for unprefixed attributes in append", 1, len) + } + + @Test + def attributeWithOption: Unit = { + val x = new UnprefixedAttribute("foo", Some(Text("bar")), Null) + + assertEquals(Some(Text("bar")), x.get("foo")) + assertEquals(Text("bar"), x("foo")) + assertEquals(None, x.get("no_foo")) + assertEquals(null, x("no_foo")) + + val attr1 = Some(Text("foo value")) + val attr2 = None + val y = + assertEquals(Some(Text("foo value")), y.attributes.get("foo")) + assertEquals(Text("foo value"), y.attributes("foo")) + assertEquals(None, y.attributes.get("bar")) + assertEquals(null, y.attributes("bar")) + + val z = new UnprefixedAttribute("foo", None, x) + assertEquals(None, z.get("foo")) + } + + @Test + def attributeToString: Unit = { + val expected: String = """""" + assertEquals(expected, ().toString) + assertEquals(expected, ().toString) + } + + @Test + def attributeOperator: Unit = { + val xml = + assertEquals("apple", xml \@ "bar") + } + +} \ No newline at end of file diff --git a/src/test/scala/scala/xml/JUnitAssertsForXML.scala b/src/test/scala/scala/xml/JUnitAssertsForXML.scala new file mode 100644 index 000000000..374ed704d --- /dev/null +++ b/src/test/scala/scala/xml/JUnitAssertsForXML.scala @@ -0,0 +1,8 @@ +package scala.xml + +object JUnitAssertsForXML { + + private[xml] def assertEquals(expected: String, actual: NodeSeq): Unit = + org.junit.Assert.assertEquals(expected, actual.toString) + +} diff --git a/src/test/scala/scala/xml/MetaDataTest.scala b/src/test/scala/scala/xml/MetaDataTest.scala new file mode 100644 index 000000000..46b598c3a --- /dev/null +++ b/src/test/scala/scala/xml/MetaDataTest.scala @@ -0,0 +1,60 @@ +package scala.xml + +import org.junit.Test +import org.junit.Ignore +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Assert.assertEquals + +class MetaDataTest { + + @Test + def absentElementPrefixed1: Unit = { + // type ascription to help overload resolution pick the right variant + assertEquals(null: Object, Null("za://foo.com", TopScope, "bar")) + assertEquals(null, Null("bar")) + } + + @Test + def absentElementPrefixed2: Unit = { + assertEquals(None, Null.get("za://foo.com", TopScope, "bar" )) + assertEquals(None, Null.get("bar")) + } + + @Test + def presentElement1: Unit = { + val x = new PrefixedAttribute("zo","bar", new Atom(42), Null) + val s = new NamespaceBinding("zo","za://foo.com", TopScope) + assertEquals(new Atom(42), x("za://foo.com", s, "bar" )) + assertEquals(null, x("bar")) + assertEquals(Some(new Atom(42)), x.get("za://foo.com", s, "bar")) + assertEquals(None, x.get("bar")) + } + + @Test + def presentElement2: Unit = { + val s = new NamespaceBinding("zo","za://foo.com", TopScope) + val x1 = new PrefixedAttribute("zo","bar", new Atom(42), Null) + val x = new UnprefixedAttribute("bar","meaning", x1) + assertEquals(null, x(null, s, "bar")) + assertEquals(Text("meaning"), x("bar")) + assertEquals(None, x.get(null, s, "bar" )) + assertEquals(Some(Text("meaning")), x.get("bar")) + } + + @Test + def attributeExtractor: Unit = { + def domatch(x:Node): Node = { + x match { + case Node("foo", md @ UnprefixedAttribute(_, value, _), _*) if !value.isEmpty => + md("bar")(0) + case _ => new Atom(3) + } + } + val z = + val z2 = + assertEquals(Text("gar"), domatch(z)) + assertEquals(new Atom(3), domatch(z2)) + } + +} diff --git a/src/test/scala/scala/xml/PrintEmptyElementsTest.scala b/src/test/scala/scala/xml/PrintEmptyElementsTest.scala new file mode 100644 index 000000000..f5270b473 --- /dev/null +++ b/src/test/scala/scala/xml/PrintEmptyElementsTest.scala @@ -0,0 +1,58 @@ +package scala.xml + +import org.junit.Test +import org.junit.Ignore +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import JUnitAssertsForXML.assertEquals + +class PrintEmptyElementsTest { + + @Test + def representEmptyXMLElementsInShortForm: Unit = { + val expected: String = + """| + | + | + | + | + |is pretty cool + |""".stripMargin + // the xml snippet is not indented because indentation affects pretty printing + // results + val actual: NodeSeq = + + + + + +is pretty cool + + assertEquals(expected, actual) + } + + @Test + def programmaticLong: Unit = { + assertEquals(" ", + Elem(null, "emptiness", Null, TopScope, false) ++ Text(" ") ++ Comment("programmatic long")) + } + + @Test + def programmaticShort: Unit = { + assertEquals(" ", + Elem(null, "vide", Null, TopScope, true) ++ Text(" ") ++ Comment("programmatic short")) + } + + @Test + def programmaticShortWithAttribute: Unit = { + assertEquals(""" """, + Elem(null, "elem", Attribute("attr", Text("value"), Null), TopScope, true) ++ Text(" ") ++ Comment ("programmatic short with attribute")) + } + + @Test + def programmaticLongWithAttribute: Unit = { + assertEquals(""" """, + Elem(null, "elem2", Attribute("attr2", Text("value2"), Null), TopScope, false) ++ Text(" ") ++ Comment ("programmatic long with attribute")) + } + +} diff --git a/src/test/scala/scala/xml/UtilityTest.scala b/src/test/scala/scala/xml/UtilityTest.scala new file mode 100644 index 000000000..eba631efb --- /dev/null +++ b/src/test/scala/scala/xml/UtilityTest.scala @@ -0,0 +1,57 @@ +package scala.xml + +import org.junit.Test +import org.junit.Ignore +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Assert.assertTrue +import org.junit.Assert.assertFalse +import org.junit.Assert.assertEquals + +class UtilityTest { + + @Test + def isNameStart: Unit = { + assertTrue(Utility.isNameStart('b')) + assertFalse(Utility.isNameStart(':')) + } + + @Test + def trim: Unit = { + val x = + + + val y = xml.Utility.trim(x) + assertEquals(1, y match { case => 1 }) + + val x2 = + a b b a + + val y2 = xml.Utility.trim(x2) + assertEquals(2, y2 match { case a b b a => 2 }) + } + + @Test + def aposEscaping: Unit = { + val z = '' + val z1 = z.toString + assertEquals("''", z1) + } + + @Test + def sort: Unit = { + val q = xml.Utility.sort() + assertEquals(" a=\"2\" g=\"3\" j=\"2\" oo=\"2\"", xml.Utility.sort(q.attributes).toString) + val pp = new xml.PrettyPrinter(80,5) + assertEquals("", pp.format(q)) + } + + @Test + def issue777: Unit = { + + + + .hashCode // Bug #777 + } + +} diff --git a/src/test/scala/scala/xml/XMLEmbeddingTest.scala b/src/test/scala/scala/xml/XMLEmbeddingTest.scala new file mode 100644 index 000000000..81c69bfb3 --- /dev/null +++ b/src/test/scala/scala/xml/XMLEmbeddingTest.scala @@ -0,0 +1,23 @@ +package scala.xml + +import org.junit.Test +import org.junit.Ignore +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Assert.assertTrue +import org.junit.Assert.assertFalse +import org.junit.Assert.assertEquals + +class XMLEmbeddingTest { + + @Test + def basic: Unit = { + val ya = {{ + assertEquals("{", ya.text) + val ua = }} + assertEquals("}", ua.text) + val za = {{}}{{}}{{}} + assertEquals("{}{}{}", za.text) + } + +} \ No newline at end of file diff --git a/test/files/jvm/xml03syntax.scala b/src/test/scala/scala/xml/XMLSyntaxTest.scala similarity index 58% rename from test/files/jvm/xml03syntax.scala rename to src/test/scala/scala/xml/XMLSyntaxTest.scala index 41663681c..fa250b416 100644 --- a/test/files/jvm/xml03syntax.scala +++ b/src/test/scala/scala/xml/XMLSyntaxTest.scala @@ -1,83 +1,72 @@ -import scala.xml._ +package scala.xml -object Test { +import org.junit.Test +import org.junit.Ignore +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Assert.assertTrue +import org.junit.Assert.assertFalse +import org.junit.Assert.assertEquals + +class XMLSyntaxTest { private def handle[A](x: Node): A = { - println(x) x.child(0).asInstanceOf[Atom[A]].data } - def main(args: Array[String]) { - test1() - test2() - test3() - } - - private def test1() { + @Test + def test1(): Unit = { val xNull = {null} // these used to be Atom(unit), changed to empty children - - println(xNull.child sameElements Nil) + assertTrue(xNull.child sameElements Nil) val x0 = {} // these used to be Atom(unit), changed to empty children val x00 = { } // dto. - val xa = { "world" } - - println(x0.child sameElements Nil) - println(x00.child sameElements Nil) - println(handle[String](xa) == "world") + assertTrue(x0.child sameElements Nil) + assertTrue(x00.child sameElements Nil) + assertEquals("world", handle[String](xa)) val xb = { 1.5 } - - println(handle[Double](xb) == 1.5) + assertEquals(1.5, handle[Double](xb), 0.0) val xc = { 5 } - - println(handle[Int](xc) == 5) + assertEquals(5, handle[Int](xc)) val xd = { true } - - println(handle[Boolean](xd) == true) + assertEquals(true, handle[Boolean](xd)) val xe = { 5:Short } - - println(handle[Short](xe) == (5:Short)) + assertEquals((5:Short), handle[Short](xe)) val xf = { val x = 27; x } - - println(handle[Int](xf) == 27) + assertEquals(27, handle[Int](xf)) val xg = { List(1,2,3,4) } - - println(xg) - for (z <- xg.child) { - println(z.toString() + {if (z.isInstanceOf[Text]) "(is text node ' ')" else ""}) - } + 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 } - - println(xh) - for (z <- xh.child) { - println(z.toString() + {if (z.isInstanceOf[Text]) "(is text node ' ')" else ""}) - } - println + 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. */ - private def test2() { + @Test + def test2(): Unit = { val x1: Option[Seq[Node]] = Some(hello) val n1 = ; - println("node="+n1+", key="+n1.attribute("key")) + assertEquals(x1, n1.attribute("key")) val x2: Option[Seq[Node]] = None val n2 = ; - println("node="+n2+", key="+n2.attribute("key")) + assertEquals(x2, n2.attribute("key")) } - private def test3() { + @Test + def test3(): Unit = { // this demonstrates how to handle entities val s = io.Source.fromString(" ") object parser extends xml.parsing.ConstructingParser(s, false /*ignore ws*/) { @@ -91,7 +80,7 @@ object Test { } val parsed = parser.element(TopScope) // parse the source as element // alternatively, we could call document() - println(parsed) + assertEquals("Š", parsed.toString) } } diff --git a/src/test/scala/scala/xml/XMLTest.scala b/src/test/scala/scala/xml/XMLTest.scala new file mode 100644 index 000000000..ba88c91c5 --- /dev/null +++ b/src/test/scala/scala/xml/XMLTest.scala @@ -0,0 +1,198 @@ +package scala.xml + +import org.junit.Test +import org.junit.Ignore +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Assert.assertTrue +import org.junit.Assert.assertFalse +import org.junit.Assert.assertEquals + +class XMLTest { + + @Test + 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 = new NodeSeq { val theSeq = List(Text("38!"),Text("58!")) }; + assertTrue(pelems_1 sameElements pelems_2) + assertTrue(Text("8") sameElements (p \\ "@bazValue")) + } + + @Test + 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 <- new NodeSeq { val theSeq = books.child }.toList) + yield t + val expected = List(Blabla) + assertEquals(expected, actual) + } + + } + + @Test + def queryPhoneBook: Unit = { + val phoneBook = + + + This is the phonebook of the + ACME corporation. + + + John + +41 21 693 68 67 + +41 79 602 23 23 + + ; + + val addrBook = + + + This is the addressbook 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) + } + + @Test + def namespaces: Unit = { + val cuckoo = + + + ; + assertEquals("http://cuckoo.com", cuckoo.namespace) + for (n <- cuckoo \ "_" ) { + assertEquals("http://cuckoo.com", n.namespace) + } + } + + @Test + 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( )) + } + +} diff --git a/src/test/scala/scala/xml/parsing/Ticket0632Test.scala b/src/test/scala/scala/xml/parsing/Ticket0632Test.scala new file mode 100644 index 000000000..7a6b71a71 --- /dev/null +++ b/src/test/scala/scala/xml/parsing/Ticket0632Test.scala @@ -0,0 +1,43 @@ +package scala.xml.parsing + +import org.junit.Test +import org.junit.Ignore +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import scala.xml.JUnitAssertsForXML.assertEquals + +class Ticket0632Test { + + import scala.io.Source.fromString + import scala.xml.parsing.ConstructingParser.fromSource + import scala.xml.{NodeSeq, TopScope} + private def parse(s:String) = fromSource(fromString(s), false).element(TopScope) + + @Test + def singleAmp: Unit = { + val expected = "" + assertEquals(expected, parse("")) + assertEquals(expected, xml.XML.loadString("")) + assertEquals(expected, ) + assertEquals(expected, ) + } + + @Test + def oneAndHalfAmp: Unit = { + val expected = "" + assertEquals(expected, xml.XML.loadString("")) + assertEquals(expected, parse("")) + assertEquals(expected, ) + assertEquals(expected, ) + } + + @Test + def doubleAmp: Unit = { + val expected = "" + assertEquals(expected, xml.XML.loadString("")) + assertEquals(expected, parse("")) + assertEquals(expected, ) + assertEquals(expected, ) + } + +} diff --git a/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala b/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala new file mode 100644 index 000000000..060276531 --- /dev/null +++ b/src/test/scala/scala/xml/pull/XMLEventReaderTest.scala @@ -0,0 +1,43 @@ +package scala.xml.pull + +import org.junit.Test +import org.junit.Ignore +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Assert.assertTrue +import org.junit.Assert.assertFalse +import org.junit.Assert.assertEquals + +import scala.io.Source + +class XMLEventReaderTest { + + val src = Source.fromString("!") + + @Test + def pull: Unit = { + val er = new XMLEventReader(src) + assertTrue(er.next match { + case EvElemStart(_, "hello", _, _) => true + case _ => false + }) + assertTrue(er.next match { + case EvElemStart(_, "world", _, _) => true + case _ => false + }) + assertTrue(er.next match { + case EvElemEnd(_, "world") => true + case _ => false + }) + assertTrue(er.next match { + case EvText("!") => true + case _ => false + }) + assertTrue(er.next match { + case EvElemEnd(_, "hello") => true + case _ => false + }) + er.stop // allow thread to be garbage-collected + } + +} \ No newline at end of file diff --git a/test/files/jvm/backendBugUnapply.check b/test/files/jvm/backendBugUnapply.check deleted file mode 100644 index 9d1e7b29c..000000000 --- a/test/files/jvm/backendBugUnapply.check +++ /dev/null @@ -1,2 +0,0 @@ -baz -null diff --git a/test/files/jvm/backendBugUnapply.scala b/test/files/jvm/backendBugUnapply.scala deleted file mode 100644 index 45ee6f7d4..000000000 --- a/test/files/jvm/backendBugUnapply.scala +++ /dev/null @@ -1,17 +0,0 @@ -object Test { - import scala.xml.{Node,UnprefixedAttribute} - - def domatch(x:Node) = - x match { - case Node("foo", UnprefixedAttribute("bar", z, _), _*) => z - case _ => null - } - - def main(args: Array[String]): Unit = { - println(domatch()) - println(domatch()) - // - // assert(domatch().toString == "baz") - // assert(domatch() == null)//, domatch()) - } -} diff --git a/test/files/jvm/t0632.check b/test/files/jvm/t0632.check deleted file mode 100755 index 681bc9da9..000000000 --- a/test/files/jvm/t0632.check +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/test/files/jvm/t0632.scala b/test/files/jvm/t0632.scala deleted file mode 100644 index a2bb5aa7f..000000000 --- a/test/files/jvm/t0632.scala +++ /dev/null @@ -1,22 +0,0 @@ -object Test { -import scala.io.Source.fromString -import scala.xml.parsing.ConstructingParser.fromSource -import scala.xml.TopScope - def parse(s:String) = fromSource(fromString(s), false).element(TopScope) - def main(argv : Array[String]) : Unit = { - - println(parse("")) - println(xml.XML.loadString("")) - println() - println() - - println(xml.XML.loadString("")) - println(parse("")) - println() - println() - println(xml.XML.loadString("")) - println(parse("")) - println() - println() - } -} diff --git a/test/files/jvm/t1118.check b/test/files/jvm/t1118.check deleted file mode 100755 index d676b413c..000000000 --- a/test/files/jvm/t1118.check +++ /dev/null @@ -1,11 +0,0 @@ - - - - - -is pretty cool - - - - - diff --git a/test/files/jvm/t1118.scala b/test/files/jvm/t1118.scala deleted file mode 100755 index 3c8654724..000000000 --- a/test/files/jvm/t1118.scala +++ /dev/null @@ -1,21 +0,0 @@ -import scala.xml._ - -object Test { - def main(args: Array[String]) { - println( - - - - -is pretty cool -) - - println(Elem(null, "emptiness", Null, TopScope, false) ++ Text(" ") ++ Comment("programmatic long")) - - println(Elem(null, "vide", Null, TopScope, true) ++ Text(" ") ++ Comment("programmatic short")) - - println(Elem(null, "elem", Attribute("attr", Text("value"), Null), TopScope, true) ++ Text(" ") ++ Comment ("programmatic short with attribute")) - - println(Elem(null, "elem2", Attribute("attr2", Text("value2"), Null), TopScope, false) ++ Text(" ") ++ Comment ("programmatic long with attribute")) - } -} \ No newline at end of file diff --git a/test/files/jvm/unittest_xml.scala b/test/files/jvm/unittest_xml.scala deleted file mode 100644 index 106334e62..000000000 --- a/test/files/jvm/unittest_xml.scala +++ /dev/null @@ -1,101 +0,0 @@ -import scala.xml.{ MetaData, Null, Utility, PrefixedAttribute, UnprefixedAttribute } - -object Test { - - def main(args:Array[String]) = { - MetaDataTest.run() - UtilityTest.run() - } - - object MetaDataTest { - - import scala.xml.{ TopScope, NamespaceBinding, Node, Atom, Text } - - def domatch(x:Node): Node = { - x match { - case Node("foo", md @ UnprefixedAttribute(_, value, _), _*) if !value.isEmpty => - md("bar")(0) - case _ => new Atom(3) - } - } - - def run() { - - var x: MetaData = Null - var s: NamespaceBinding = TopScope - - // testing method def apply(uri:String, scp:NamespaceBinding, k:String): Seq[Node] - // def apply(k:String): Seq[Node] - - assert(null == x("za://foo.com", s, "bar" ), "absent element (prefixed) 1") - assert(null == x("bar"), "absent element (unprefix) 1") - - assert(None == x.get("za://foo.com", s, "bar" ), "absent element (prefixed) 2") - assert(None == x.get("bar"), "absent element (unprefix) 2") - - x = new PrefixedAttribute("zo","bar", new Atom(42), x) - s = new NamespaceBinding("zo","za://foo.com",s) - - assert(new Atom(42) == x("za://foo.com", s, "bar" ), "present element (prefixed) 3") - assert(null == x("bar"), "present element (unprefix) 3") - - assert(Some(new Atom(42)) == x.get("za://foo.com", s, "bar" ), "present element (prefixed) 4") - assert(None == x.get("bar"), "present element (unprefix) 4") - - x = new UnprefixedAttribute("bar","meaning", x) - - assert(null == x(null, s, "bar"), "present element (prefixed) 5") - assert(Text("meaning") == x("bar"), "present element (unprefix) 5") - - assert(None == x.get(null, s, "bar" ), "present element (prefixed) 6") - assert(Some(Text("meaning")) == x.get("bar"), "present element (unprefix) 6") - - val z = - val z2 = - - assert(Text("gar") == domatch(z), "attribute extractor 1") - assert(new Atom(3) == domatch(z2), "attribute extractor 2") - - } - } - - object UtilityTest { - def run() { - assert(Utility.isNameStart('b')) - assert(!Utility.isNameStart(':')) - - val x = - - - - val y = xml.Utility.trim(x) - - assert(1 == (y match { case => 1 }), "trim 1") - - val x2 = - a b b a - - - val y2 = xml.Utility.trim(x2) - - assert(2 == (y2 match { case a b b a => 2 }), "trim 2") - - val z = '' - val z1 = z.toString - - assert("''" == z1, "apos unescaped") - - val q = xml.Utility.sort() - assert(" a=\"2\" g=\"3\" j=\"2\" oo=\"2\"" == xml.Utility.sort(q.attributes).toString) - - val pp = new xml.PrettyPrinter(80,5) - assert("" == pp.format(q)) - - - - - .hashCode // Bug #777 - } - } - -} diff --git a/test/files/jvm/xml03syntax.check b/test/files/jvm/xml03syntax.check deleted file mode 100755 index 599cbad68..000000000 --- a/test/files/jvm/xml03syntax.check +++ /dev/null @@ -1,27 +0,0 @@ -true -true -true -world -true -1.5 -true -5 -true -true -true -5 -true -27 -true -1 2 3 4 -1 -2 -3 -4 -2 4 -2 -4 - -node=, key=Some(hello) -node=, key=None -Š diff --git a/test/files/jvm/xml04embed.check b/test/files/jvm/xml04embed.check deleted file mode 100644 index e71e64514..000000000 --- a/test/files/jvm/xml04embed.check +++ /dev/null @@ -1,3 +0,0 @@ -{ -} -{}{}{} diff --git a/test/files/jvm/xml04embed.scala b/test/files/jvm/xml04embed.scala deleted file mode 100644 index fa453e429..000000000 --- a/test/files/jvm/xml04embed.scala +++ /dev/null @@ -1,10 +0,0 @@ -object Test { - def main(args: Array[String]) { - val ya = {{ - println(ya.text) - val ua = }} - println(ua.text) - val za = {{}}{{}}{{}} - println(za.text) - } -} diff --git a/test/files/jvm/xmlattr.check b/test/files/jvm/xmlattr.check deleted file mode 100644 index a87420d86..000000000 --- a/test/files/jvm/xmlattr.check +++ /dev/null @@ -1,18 +0,0 @@ -true -true -true -true -true -true -removal of duplicates for unprefixed attributes in append = 1 -true -true -true -true -true -true -true -true -true - - diff --git a/test/files/jvm/xmlattr.scala b/test/files/jvm/xmlattr.scala deleted file mode 100644 index 6423268ba..000000000 --- a/test/files/jvm/xmlattr.scala +++ /dev/null @@ -1,70 +0,0 @@ -import xml.{ NodeSeq, Null, Text, UnprefixedAttribute } - -object Test { - - def main(args: Array[String]) { - UnprefixedAttributeTest() - AttributeWithOptionTest() - AttributeOutputTest() - AttributeOperatorTest() - } - - object UnprefixedAttributeTest { - def apply() { - val x = new UnprefixedAttribute("foo","bar", Null) - println(Some(Text("bar")) == x.get("foo")) - println(Text("bar") == x("foo")) - println(None == x.get("no_foo")) - println(null == x("no_foo")) - - val y = x.remove("foo") - println(Null == y) - - val z = new UnprefixedAttribute("foo", null:NodeSeq, x) - println(None == z.get("foo")) - - var appended = x append x append x append x - var len = 0; while (appended ne Null) { - appended = appended.next - len = len + 1 - } - println("removal of duplicates for unprefixed attributes in append = " + len) - } - } - - object AttributeWithOptionTest { - def apply() { - val x = new UnprefixedAttribute("foo", Some(Text("bar")), Null) - - println(Some(Text("bar")) == x.get("foo")) - println(Text("bar") == x("foo")) - println(None == x.get("no_foo")) - println(null == x("no_foo")) - - val attr1 = Some(Text("foo value")) - val attr2 = None - val y = - println(Some(Text("foo value")) == y.attributes.get("foo")); - println(Text("foo value") == y.attributes("foo")) - println(None == y.attributes.get("bar")) - println(null == y.attributes("bar")) - - val z = new UnprefixedAttribute("foo", None, x) - println(None == z.get("foo")) - } - } - - object AttributeOutputTest { - def apply() { - println() - println() - } - } - - object AttributeOperatorTest { - def apply() { - val xml = - assert(xml \@ "bar" == "apple") - } - } -} diff --git a/test/files/jvm/xmlpull.scala b/test/files/jvm/xmlpull.scala deleted file mode 100644 index 9ba7d4cf0..000000000 --- a/test/files/jvm/xmlpull.scala +++ /dev/null @@ -1,31 +0,0 @@ -import scala.xml._ -import scala.xml.pull._ -import scala.io.Source - -object Test { - - val src = Source.fromString("!") - - def main(args: Array[String]) { - var er = new XMLEventReader(src) - er.next match { - case EvElemStart(_, "hello", _, _) => //println("1") - } - er.next match { - case EvElemStart(_, "world", _, _) => //println("2") - } - er.next match { - case EvElemEnd(_, "world") => //println("3") - } - er.next match { - case EvText("!") => //println("4") - } - er.next match { - case EvElemEnd(_, "hello") => //println("5") - } - // you get the picture... - er.stop // allow thread to be garbage-collected - //println("6") - } -} - diff --git a/test/files/jvm/xmlstuff.check b/test/files/jvm/xmlstuff.check deleted file mode 100644 index e1222479f..000000000 --- a/test/files/jvm/xmlstuff.check +++ /dev/null @@ -1,22 +0,0 @@ -NodeSeq - - Blabla - Hallo Welt. - - Blubabla - Hello Blu - - Blubabla - rem 2 - -List(Blabla) - - John - Elm Street - Dolphin City - +41 21 693 68 67 - +41 79 602 23 23 - -namespaces -validation - elements -validation - attributes diff --git a/test/files/jvm/xmlstuff.scala b/test/files/jvm/xmlstuff.scala deleted file mode 100644 index 45234c713..000000000 --- a/test/files/jvm/xmlstuff.scala +++ /dev/null @@ -1,181 +0,0 @@ -import java.io.StringReader -import org.xml.sax.InputSource -import scala.xml.{Node, NodeSeq, Elem, Text, XML} - -object Test { - - /** returns true if exception was thrown */ - def catcher(att: Function1[Unit, scala.xml.MetaData]): Boolean = { - var ex = false - try { - att.apply({}) - } catch { - case scala.xml.MalformedAttributeException(msg) => - println(msg) - ex = true - } - ex - } - - def main(args: Array[String]) { - - println("NodeSeq") - - 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 = new NodeSeq { val theSeq = List(Text("38!"),Text("58!")) }; - assert(pelems_1 sameElements pelems_2) - - assert(Text("8") sameElements (p \\ "@bazValue")) - - val books = - - Blabla - Blubabla - Baaaaaaalabla - ; - - val reviews = - - Blabla - - Hallo Welt. - - - Blubabla - - Hello Blu - - - Blubabla - - rem 2 - - - ; - - println( new scala.xml.PrettyPrinter(80, 5).formatNodes ( - for (t <- books \\ "title"; - r <- reviews \\ "entry" - if (r \ "title") xml_== t) yield - - { t } - { r \ "remarks" } - - )); - - // example - println( - for (t @ Blabla <- new NodeSeq { val theSeq = books.child }.toList) - yield t - ); - val phoneBook = - - - This is the phonebook of the - ACME corporation. - - - John - +41 21 693 68 67 - +41 79 602 23 23 - - ; - - - val addrBook = - - - This is the addressbook of the - ACME corporation. - - - John - Elm Street - Dolphin City - - ; - - println( 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" } - - )); - - - /* namespaces */ - // begin tmp - println("namespaces") - val cuckoo = - - - ; - assert(cuckoo.namespace == "http://cuckoo.com") - for (n <- cuckoo \ "_" ) { - //println("n = "+n); - //println("n.prefix = "+n.prefix); - //.println("n.scope = "+n.scope); - assert( n.namespace == "http://cuckoo.com") - } - - println("validation - elements") - 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"))) ))); - - } - assert(vtor( )) - - { - import scala.xml.dtd.MIXED - import scala.xml.dtd.ContentModel._ - - vtor.setContentModel( - MIXED( - Alt(Letter(ElemName("bar")), - Letter(ElemName("baz")), - Letter(ElemName("bal"))))); - } - - assert(vtor( )) - assert(vtor(abcdedgh )) - assert(!vtor( )) - - println("validation - attributes") - vtor.setContentModel(null) - vtor.setMetaData(List()) - assert(!vtor( )) - - { - import scala.xml.dtd._ - vtor setMetaData List(AttrDecl("bar", "CDATA", IMPLIED)) - } - assert(!vtor()) - assert(vtor()) - - { - import scala.xml.dtd._ - vtor.setMetaData(List(AttrDecl("bar","CDATA",REQUIRED))) - } - assert(!vtor( )) - assert( vtor( )) - - } -}