diff options
author | Martin Odersky <odersky@gmail.com> | 2009-05-08 16:33:15 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2009-05-08 16:33:15 +0000 |
commit | 14a631a5fec42d04d0723355a0b93e482b5e4662 (patch) | |
tree | f639c2a22e89e193b9abea391993ecfd4d5326ee /test/files/jvm | |
parent | 2379eb4ebbd28c8892b50a1d9fa8a687099eea4d (diff) | |
download | scala-14a631a5fec42d04d0723355a0b93e482b5e4662.tar.gz scala-14a631a5fec42d04d0723355a0b93e482b5e4662.tar.bz2 scala-14a631a5fec42d04d0723355a0b93e482b5e4662.zip |
massive new collections checkin.
Diffstat (limited to 'test/files/jvm')
-rw-r--r-- | test/files/jvm/manifests.check | 16 | ||||
-rw-r--r-- | test/files/jvm/serialization.check | 190 | ||||
-rwxr-xr-x | test/files/jvm/serialization.scala | 421 | ||||
-rwxr-xr-x | test/files/jvm/t1652.check | 2 | ||||
-rw-r--r-- | test/files/jvm/xml01.check | 8 | ||||
-rw-r--r-- | test/files/jvm/xml01.scala | 231 | ||||
-rw-r--r-- | test/files/jvm/xml02.scala | 2 |
7 files changed, 11 insertions, 859 deletions
diff --git a/test/files/jvm/manifests.check b/test/files/jvm/manifests.check index bfcd6a20eb..f8ef5b203c 100644 --- a/test/files/jvm/manifests.check +++ b/test/files/jvm/manifests.check @@ -5,11 +5,11 @@ x=1, m=int x=abc, m=java.lang.String x='abc, m=scala.Symbol -x=List(()), m=scala.List[void] -x=List(true), m=scala.List[boolean] -x=List(1), m=scala.List[int] -x=List(abc), m=scala.List[java.lang.String] -x=List('abc), m=scala.List[scala.Symbol] +x=List(()), m=scala.collection.immutable.List[void] +x=List(true), m=scala.collection.immutable.List[boolean] +x=List(1), m=scala.collection.immutable.List[int] +x=List(abc), m=scala.collection.immutable.List[java.lang.String] +x=List('abc), m=scala.collection.immutable.List[scala.Symbol] x=[Z, m=Array[boolean] x=[C, m=Array[char] @@ -24,12 +24,12 @@ x=(abc,xyz), m=scala.Tuple2[java.lang.String, java.lang.String] x=('abc,'xyz), m=scala.Tuple2[scala.Symbol, scala.Symbol] x=Test$, m=Test$ -x=scala.List$, m=scala.List$ +x=scala.collection.immutable.List$, m=scala.collection.immutable.List$ x=Foo, m=Foo[int] -x=Foo, m=Foo[scala.List[int]] +x=Foo, m=Foo[scala.collection.immutable.List[int]] x=Foo, m=Foo[Foo[int]] -x=Foo, m=Foo[scala.List[Foo[int]]] +x=Foo, m=Foo[scala.collection.immutable.List[Foo[int]]] x=Test1$$anon$1, m=Test1$$anon$1 diff --git a/test/files/jvm/serialization.check b/test/files/jvm/serialization.check deleted file mode 100644 index d6782410c8..0000000000 --- a/test/files/jvm/serialization.check +++ /dev/null @@ -1,190 +0,0 @@ -x0 = List(1, 2, 3) -y0 = List(1, 2, 3) -x0 eq y0: false - y0 eq x0: false -x0 equals y0: true - y0 equals x0: true - -x1 = List() -y1 = List() -x1 eq y1: true - y1 eq x1: true - -x2 = None -y2 = None -x2 eq y2: true - y2 eq x2: true - -x3 = Array[1,2,3] -y3 = Array[1,2,3] -arrayEquals(x3, y3): true - -x4 = <na> -y4 = <na> -x4(2): 4 - y4(2): 4 - -x5 = 'hello -y5 = 'hello -x5 eq y5: true - y5 eq x5: true -x5 equals y5: true - y5 equals x5: true - -x6 = (BannerLimit,12345) -y6 = (BannerLimit,12345) -x6 eq y6: false - y6 eq x6: false -x6 equals y6: true - y6 equals x6: true - -x7 = {scala.BigDecimal$RoundingMode(0), scala.BigDecimal$RoundingMode(1), scala.BigDecimal$RoundingMode(2), scala.BigDecimal$RoundingMode(3), scala.BigDecimal$RoundingMode(4), scala.BigDecimal$RoundingMode(5), scala.BigDecimal$RoundingMode(6), scala.BigDecimal$RoundingMode(7)} -y7 = {scala.BigDecimal$RoundingMode(0), scala.BigDecimal$RoundingMode(1), scala.BigDecimal$RoundingMode(2), scala.BigDecimal$RoundingMode(3), scala.BigDecimal$RoundingMode(4), scala.BigDecimal$RoundingMode(5), scala.BigDecimal$RoundingMode(6), scala.BigDecimal$RoundingMode(7)} -x7 eq y7: true - y7 eq x7: true -x7 equals y7: true - y7 equals x7: true - -x8 = {Test1_scala$WeekDay(0), Test1_scala$WeekDay(1), Test1_scala$WeekDay(2), Test1_scala$WeekDay(3), Test1_scala$WeekDay(4), Test1_scala$WeekDay(5), Test1_scala$WeekDay(6)} -y8 = {Test1_scala$WeekDay(0), Test1_scala$WeekDay(1), Test1_scala$WeekDay(2), Test1_scala$WeekDay(3), Test1_scala$WeekDay(4), Test1_scala$WeekDay(5), Test1_scala$WeekDay(6)} -x8 eq y8: true - y8 eq x8: true -x8 equals y8: true - y8 equals x8: true - -x9 = scala.BigDecimal$RoundingMode(0) -y9 = scala.BigDecimal$RoundingMode(0) -x9 eq y9: true - y9 eq x9: true -x9 equals y9: true - y9 equals x9: true - -x10 = Test1_scala$WeekDay(0) -y10 = Test1_scala$WeekDay(0) -x10 eq y10: true - y10 eq x10: true -x10 equals y10: true - y10 equals x10: true - -x9 eq x10: false - x10 eq x9: false -x9 equals x10: false - x10 equals x9: false -x9 eq y10: false - y10 eq x9: false -x9 equals y10: false - y10 equals x9: false - -x = List((buffers,20), (layers,2), (title,3)) -y = List((buffers,20), (layers,2), (title,3)) -x equals y: true - y equals x: true - -x = Map(buffers -> 20, layers -> 2, title -> 3) -y = Map(buffers -> 20, layers -> 2, title -> 3) -x equals y: true - y equals x: true - -x = Set(2, 3) -y = Set(2, 3) -x equals y: true - y equals x: true - -x = Set(5, 3) -y = Set(5, 3) -x equals y: true - y equals x: true - -x = Queue(a, b, c) -y = Queue(a, b, c) -x equals y: true - y equals x: true - -x = Stack(a, b, c) -y = Stack(a, b, c) -x equals y: true - y equals x: true - -x = Map(42 -> FortyTwo) -y = Map(42 -> FortyTwo) -x equals y: true - y equals x: true - -x = Set(0, 2) -y = Set(0, 2) -x equals y: true - y equals x: true - -x = ArrayBuffer(one, two) -y = ArrayBuffer(one, two) -x equals y: true - y equals x: true - -x = Map(title -> 3, buffers -> 20, layers -> 2) -y = Map(title -> 3, buffers -> 20, layers -> 2) -x equals y: true - y equals x: true - -x = Set(0, 8, 9) -y = Set(0, 8, 9) -x equals y: true - y equals x: true - -x = Set(layers, buffers, title) -y = Set(layers, buffers, title) -x equals y: true - y equals x: true - -x = LinkedList(2, 3) -y = LinkedList(2, 3) -x equals y: true - y equals x: true - -x = Queue(20, 2, 3) -y = Queue(20, 2, 3) -x equals y: true - y equals x: true - -x = Stack(20, 2, 3) -y = Stack(20, 2, 3) -x equals y: true - y equals x: true - -x = ListBuffer(white, black) -y = ListBuffer(white, black) -x equals y: true - y equals x: true - -x = <html><title>title</title><body/></html> -y = <html><title>title</title><body/></html> -x equals y: true - y equals x: true - -x = <html> - <body> - <table cellpadding="2" cellspacing="0"> - <tr> - <th>Last Name</th> - <th>First Name</th> - </tr> - <tr> - <td> Tom </td> - <td> 20 </td> - </tr><tr> - <td> Bob </td> - <td> 22 </td> - </tr><tr> - <td> James </td> - <td> 19 </td> - </tr> - </table> - </body> - </html> -y = <html> - <body> - <table cellpadding="2" cellspacing="0"> - <tr> - <th>Last Name</th> - <th>First Name</th> - </tr> - <tr> - <td> Tom </td> - <td> 20 </td> - </tr><tr> - <td> Bob </td> - <td> 22 </td> - </tr><tr> - <td> James </td> - <td> 19 </td> - </tr> - </table> - </body> - </html> -x equals y: true - y equals x: true - -x = Tim -y = Tim -x equals y: true - y equals x: true - -x = Bob -y = Bob -x equals y: true - y equals x: true - -x = John -y = John -x equals y: true - y equals x: true - -x = Bill -y = Bill -x equals y: true - y equals x: true - -x = Paul -y = Paul -x equals y: true - y equals x: true - -x = <function> -y = <function> -x equals y: false - y equals x: false - diff --git a/test/files/jvm/serialization.scala b/test/files/jvm/serialization.scala deleted file mode 100755 index 516fa16de2..0000000000 --- a/test/files/jvm/serialization.scala +++ /dev/null @@ -1,421 +0,0 @@ -//############################################################################ -// Serialization -//############################################################################ -// $Id: serialization.scala 15934 2008-08-26 12:10:05Z michelou $ - -import java.lang.System - -object EqualityTest { - def check[A, B](x: A, y: B) { - println("x = " + x) - println("y = " + y) - println("x equals y: " + (x equals y) + " - y equals x: " + (y equals x)) - println() - } -} - -object Serialize { - @throws(classOf[java.io.IOException]) - def write[A](o: A): Array[Byte] = { - val ba = new java.io.ByteArrayOutputStream(512) - val out = new java.io.ObjectOutputStream(ba) - out.writeObject(o) - out.close() - ba.toByteArray() - } - @throws(classOf[java.io.IOException]) - @throws(classOf[ClassNotFoundException]) - def read[A](buffer: Array[Byte]): A = { - val in = - new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer)) - in.readObject().asInstanceOf[A] - } -} - -//############################################################################ -// Test classes in package "scala" - -object Test1_scala { - - private def arrayToString[A](arr: Array[A]): String = - List.fromArray(arr).mkString("Array[",",","]") - - private def arrayEquals[A, B](a1: Array[A], a2: Array[B]): Boolean = - (a1.length == a2.length) && - (Iterator.range(0, a1.length) forall { i => a1(i) == a2(i) }) - - @serializable - object WeekDay extends Enumeration { - type WeekDay = Value - val Monday, Tuesday, Wednesday, Thusday, Friday, Saturday, Sunday = Value - } - import WeekDay._, BigDecimal._, RoundingMode._ - - val x0 = List(1, 2, 3) - val x1 = Nil - val x2 = None - val x3 = Array(1, 2, 3) - val x4 = { x: Int => 2 * x } - val x5 = 'hello - val x6 = ("BannerLimit", 12345) - val x7 = BigDecimal.RoundingMode - val x8 = WeekDay - val x9 = ROUND_UP - val x10 = Monday - - try { - val y0: List[Int] = Serialize.read(Serialize.write(x0)) - val y1: List[Nothing] = Serialize.read(Serialize.write(x1)) - val y2: Option[Nothing] = Serialize.read(Serialize.write(x2)) - val y3: Array[Int] = Serialize.read(Serialize.write(x3)) - val y4: Function[Int, Int] = Serialize.read(Serialize.write(x4)) - val y5: Symbol = Serialize.read(Serialize.write(x5)) - val y6: (String, Int) = Serialize.read(Serialize.write(x6)) - val y7: RoundingMode.type = Serialize.read(Serialize.write(x7)) - val y8: WeekDay.type = Serialize.read(Serialize.write(x8)) - val y9: RoundingMode = Serialize.read(Serialize.write(x9)) - val y10: WeekDay = Serialize.read(Serialize.write(x10)) - - println("x0 = " + x0) - println("y0 = " + y0) - println("x0 eq y0: " + (x0 eq y0) + " - y0 eq x0: " + (y0 eq x0)) - println("x0 equals y0: " + (x0 equals y0) + " - y0 equals x0: " + (y0 equals x0)) - println() - println("x1 = " + x1) - println("y1 = " + y1) - println("x1 eq y1: " + (x1 eq y1) + " - y1 eq x1: " + (y1 eq x1)) - println() - println("x2 = " + x2) - println("y2 = " + y2) - println("x2 eq y2: " + (x2 eq y2) + " - y2 eq x2: " + (y2 eq x2)) - println() - println("x3 = " + arrayToString(x3)) - println("y3 = " + arrayToString(y3)) - println("arrayEquals(x3, y3): " + arrayEquals(x3, y3)) - println() - println("x4 = <na>") - println("y4 = <na>") - println("x4(2): " + x4(2) + " - y4(2): " + y4(2)) - println() - println("x5 = " + x5) - println("y5 = " + y5) - println("x5 eq y5: " + (x5 eq y5) + " - y5 eq x5: " + (y5 eq x5)) - println("x5 equals y5: " + (x5 equals y5) + " - y5 equals x5: " + (y5 equals x5)) - println() - println("x6 = " + x6) - println("y6 = " + y6) - println("x6 eq y6: " + (x6 eq y6) + " - y6 eq x6: " + (y6 eq x6)) - println("x6 equals y6: " + (x6 equals y6) + " - y6 equals x6: " + (y6 equals x6)) - println() - println("x7 = " + x7) - println("y7 = " + y7) - println("x7 eq y7: " + (x7 eq y7) + " - y7 eq x7: " + (y7 eq x7)) - println("x7 equals y7: " + (x7 equals y7) + " - y7 equals x7: " + (y7 equals x7)) - println() - println("x8 = " + x8) - println("y8 = " + y8) - println("x8 eq y8: " + (x8 eq y8) + " - y8 eq x8: " + (y8 eq x8)) - println("x8 equals y8: " + (x8 equals y8) + " - y8 equals x8: " + (y8 equals x8)) - println() - println("x9 = " + x9) - println("y9 = " + y9) - println("x9 eq y9: " + (x9 eq y9) + " - y9 eq x9: " + (y9 eq x9)) - println("x9 equals y9: " + (x9 equals y9) + " - y9 equals x9: " + (y9 equals x9)) - println() - println("x10 = " + x10) - println("y10 = " + y10) - println("x10 eq y10: " + (x10 eq y10) + " - y10 eq x10: " + (y10 eq x10)) - println("x10 equals y10: " + (x10 equals y10) + " - y10 equals x10: " + (y10 equals x10)) - println() - println("x9 eq x10: " + (x9 eq x10) + " - x10 eq x9: " + (x10 eq x9)) - println("x9 equals x10: " + (x9 equals x10) + " - x10 equals x9: " + (x10 equals x9)) - println("x9 eq y10: " + (x9 eq y10) + " - y10 eq x9: " + (y10 eq x9)) - println("x9 equals y10: " + (x9 equals y10) + " - y10 equals x9: " + (y10 equals x9)) - println() - } - catch { - case e: Exception => - e.printStackTrace() - println("Error in Test1_scala: " + e) - } -} - -//############################################################################ -// Test classes in package "scala.collection.immutable" - -@serializable -object Test2_immutable { - import scala.collection.immutable.{ - BitSet, ListMap, ListSet, Queue, Stack, TreeSet, TreeMap} - - val x1 = List( - Pair("buffers", 20), - Pair("layers", 2), - Pair("title", 3) - ) - - val x2 = new ListMap[String, Int] + ("buffers" -> 20, "layers" -> 2, "title" -> 3) - - val x3 = { - val bs = new collection.mutable.BitSet() - bs += 2; bs += 3 - bs.toImmutable - } - - val x4 = new ListSet[Int]() + 3 + 5 - - val x5 = new Queue("a", "b", "c") - - val x6 = new Stack().push("a", "b", "c") - - val x7 = new TreeMap[Int, String] + (42 -> "FortyTwo") - - val x8 = new TreeSet[Int]() + 2 + 0 - - try { - val y1: List[Pair[String, Int]] = Serialize.read(Serialize.write(x1)) - val y2: ListMap[String, Int] = Serialize.read(Serialize.write(x2)) - val y3: BitSet = Serialize.read(Serialize.write(x3)) - val y4: ListSet[Int] = Serialize.read(Serialize.write(x4)) - val y5: Queue[String] = Serialize.read(Serialize.write(x5)) - val y6: Stack[String] = Serialize.read(Serialize.write(x6)) - val y7: TreeMap[Int, String] = Serialize.read(Serialize.write(x7)) - val y8: TreeSet[Int] = Serialize.read(Serialize.write(x8)) - - EqualityTest.check(x1, y1) - EqualityTest.check(x2, y2) - EqualityTest.check(x3, y3) - EqualityTest.check(x4, y4) - EqualityTest.check(x5, y5) - EqualityTest.check(x6, y6) - EqualityTest.check(x7, y7) - EqualityTest.check(x8, y8) - } - catch { - case e: Exception => - println("Error in Test2_immutable: " + e) - throw e - } -} - -//############################################################################ -// Test classes in package "scala.collection.mutable" - -object Test3_mutable { - import scala.collection.mutable.{ - ArrayBuffer, BitSet, HashMap, HashSet, History, LinkedList, ListBuffer, - Publisher, Queue, RevertableHistory, Stack} - - val x0 = new ArrayBuffer[String] - x0 ++= List("one", "two") - - val x2 = new BitSet() - x2 += 0 - x2 += 8 - x2 += 9 - - val x1 = new HashMap[String, Int] - x1 ++= Test2_immutable.x1 - - val x3 = new HashSet[String] - x3 ++= Test2_immutable.x1.map(p => p._1) - - @serializable - class Feed extends Publisher[String, Feed] - - val x8 = new History[String, Feed] - - val x4 = new LinkedList[Int](2, null) - x4.append(new LinkedList(3, null)) - - val x7 = new ListBuffer[String] - x7 ++= List("white", "black") - - val x5 = new Queue[Int] - x5 ++= Test2_immutable.x1.map(p => p._2) - - val x6 = new Stack[Int] - x6 ++= x5 - - try { - val y0: ArrayBuffer[String] = Serialize.read(Serialize.write(x0)) - val y1: HashMap[String, Int] = Serialize.read(Serialize.write(x1)) - val y2: BitSet = Serialize.read(Serialize.write(x2)) - val y3: HashSet[String] = Serialize.read(Serialize.write(x3)) - val y4: LinkedList[Int] = Serialize.read(Serialize.write(x4)) - val y5: Queue[Int] = Serialize.read(Serialize.write(x5)) - val y6: Stack[Int] = Serialize.read(Serialize.write(x6)) - val y7: ListBuffer[String] = Serialize.read(Serialize.write(x7)) - val y8: History[String, Feed] = Serialize.read(Serialize.write(x8)) - - EqualityTest.check(x0, y0) - EqualityTest.check(x1, y1) - EqualityTest.check(x2, y2) - EqualityTest.check(x3, y3) - EqualityTest.check(x4, y4) - EqualityTest.check(x5, y5) - EqualityTest.check(x6, y6) - EqualityTest.check(x7, y7) - //EqualityTest.check(x8, y8) //todo - } - catch { - case e: Exception => - println("Error in Test3_mutable: " + e) - } -} - -//############################################################################ -// Test classes in package "scala.xml" - -object Test4_xml { - import scala.xml.Elem - - val x1 = <html><title>title</title><body></body></html>; - - case class Person(name: String, age: Int) - - class AddressBook(a: Person*) { - private val people: List[Person] = a.toList - def toXHTML = - <table cellpadding="2" cellspacing="0"> - <tr> - <th>Last Name</th> - <th>First Name</th> - </tr> - { for (val p <- people) yield - <tr> - <td> { p.name } </td> - <td> { p.age.toString() } </td> - </tr> } - </table>; - } - - val people = new AddressBook( - Person("Tom", 20), - Person("Bob", 22), - Person("James", 19)) - - val x2 = - <html> - <body> - { people.toXHTML } - </body> - </html>; - - try { - val y1: scala.xml.Elem = Serialize.read(Serialize.write(x1)) - val y2: scala.xml.Elem = Serialize.read(Serialize.write(x2)) - - EqualityTest.check(x1, y1) - EqualityTest.check(x2, y2) - } - catch { - case e: Exception => - println("Error in Test4_xml: " + e) - } -} - -//############################################################################ -// Test user-defined classes WITHOUT nesting - -@serializable -class Person(_name: String) { - private var name = _name - override def toString() = name - override def equals(that: Any): Boolean = - that.isInstanceOf[Person] && - (name == that.asInstanceOf[Person].name) -} - -@serializable -class Employee(_name: String) { - private var name = _name - override def toString() = name -} -@serializable -object bob extends Employee("Bob") - -object Test5 { - val x1 = new Person("Tim") - val x2 = bob - - try { - val y1: Person = Serialize.read(Serialize.write(x1)) - val y2: Employee = Serialize.read(Serialize.write(x2)) - - EqualityTest.check(x1, y1) - EqualityTest.check(x2, y2) - } - catch { - case e: Exception => - println("Error in Test5: " + e) - } -} - -//############################################################################ -// Test user-defined classes WITH nesting - -@serializable -object Test6 { - @serializable - object bill extends Employee("Bill") { - val x = paul - } - @serializable - object paul extends Person("Paul") { - val x = 4 // bill; => StackOverflowException !!! - } - val x1 = new Person("John") - val x2 = bill - val x3 = paul - - try { - val y1: Person = Serialize.read(Serialize.write(x1)) - val y2: Employee = Serialize.read(Serialize.write(x2)) - val y3: Person = Serialize.read(Serialize.write(x3)) - - EqualityTest.check(x1, y1) - EqualityTest.check(x2, y2) - EqualityTest.check(x3, y3) - } - catch { - case e: Exception => - println("Error in Test6: " + e) - } -} - -object Test7 { - @serializable - class A(a: Int) { -// def this() { this(0) } - val f = (x: Int) => x + a - } - try { - val a = new A(1) - val f1: Int => Int = Serialize.read(Serialize.write(a.f)) - - EqualityTest.check(a.f, f1) - } - catch { - case e: Exception => - println("Error in Test7: " + e) - } -} - -//############################################################################ -// Test code - -object Test { - def main(args: Array[String]) { - Test1_scala - Test2_immutable - Test3_mutable - Test4_xml - Test5 - Test6 - Test7 - } -} - -//############################################################################ - diff --git a/test/files/jvm/t1652.check b/test/files/jvm/t1652.check new file mode 100755 index 0000000000..dfa480ce6e --- /dev/null +++ b/test/files/jvm/t1652.check @@ -0,0 +1,2 @@ +OK1 +OK2 diff --git a/test/files/jvm/xml01.check b/test/files/jvm/xml01.check deleted file mode 100644 index d78e6df410..0000000000 --- a/test/files/jvm/xml01.check +++ /dev/null @@ -1,8 +0,0 @@ -equality -xpath \ -xpath \\ DESCENDANTS -<book><author>Peter Buneman</author><author>Dan Suciu</author><title>Data on ze web</title></book> --- group nodes -<f><a/><b/><c/></f> -<a/><f><a/><b/><c/></f><a/><b/><c/> -attribute value normalization diff --git a/test/files/jvm/xml01.scala b/test/files/jvm/xml01.scala deleted file mode 100644 index 56d9646fa3..0000000000 --- a/test/files/jvm/xml01.scala +++ /dev/null @@ -1,231 +0,0 @@ -import java.io.StringReader -import org.xml.sax.InputSource - -import scala.testing.SUnit._ -import scala.util.logging._ -import scala.xml._ - - -object Test extends Application with Assert { - val e: scala.xml.MetaData = Null //Node.NoAttributes - val sc: scala.xml.NamespaceBinding = TopScope - - val xmlFile1 = "<hello><world/></hello>"; - val isrc1 = new InputSource(new StringReader(xmlFile1)) - val parsedxml1 = XML.load(isrc1) - val isrc11 = new InputSource(new StringReader(xmlFile1)) - val parsedxml11 = XML.load(isrc11) - - val c = new Node { - def label = "hello" - override def hashCode() = - Utility.hashCode(prefix, label, attributes.hashCode(), scope.hashCode(), child); - def child = Elem(null, "world", e, sc); - //def attributes = e; - override def text = "" - } - - assertSameElements(List(3), List(3)) - - println("equality") - assertEquals(c, parsedxml11) - assertEquals(parsedxml1, parsedxml11) - assertSameElements(List(parsedxml1), List(parsedxml11)) - assertSameElements(Array(parsedxml1).toList, List(parsedxml11)) - - val x2 = "<book><author>Peter Buneman</author><author>Dan Suciu</author><title>Data on ze web</title></book>"; - - val i = new InputSource(new StringReader(x2)) - val x2p = XML.load(i) - - assertEquals(x2p, Elem(null, "book" , e, sc, - Elem(null, "author", e, sc,Text("Peter Buneman")), - Elem(null, "author", e, sc,Text("Dan Suciu")), - Elem(null, "title" , e, sc,Text("Data on ze web")))); - - val xmlFile2 = "<bib><book><author>Peter Buneman</author><author>Dan Suciu</author><title>Data on ze web</title></book><book><author>John Mitchell</author><title>Foundations of Programming Languages</title></book></bib>"; - val isrc2 = new InputSource(new StringReader(xmlFile2)) - val parsedxml2 = XML.load(isrc2) - - // xmlFile2/book -> book,book - println("xpath \\") - - - assertSameElements(parsedxml1 \ "_" , List(Elem(null,"world", e, sc))) - - assertSameElements(parsedxml1 \ "world", List(Elem(null,"world", e, sc))) - -/* - Console.println( parsedxml2 \ "_" ); - Console.println( (parsedxml2 \ "_" ).elements); - for( val i <- (parsedxml2 \ "_" ).elements) { - Console.println( i ); - }; - */ - - assertSameElements( - parsedxml2 \ "_" , - - List( - Elem(null,"book", e, sc, - Elem(null,"author", e, sc, Text("Peter Buneman")), - Elem(null,"author", e, sc, Text("Dan Suciu")), - Elem(null,"title" , e, sc, Text("Data on ze web"))), - Elem(null,"book",e,sc, - Elem(null,"author",e,sc,Text("John Mitchell")), - Elem(null,"title",e,sc,Text("Foundations of Programming Languages")))) - ); - assertEquals( (parsedxml2 \ "author").length, 0 ); - - assertSameElements( - parsedxml2 \ "book", - - List( - Elem(null,"book",e,sc, - Elem(null,"author", e, sc, Text("Peter Buneman")), - Elem(null,"author", e, sc, Text("Dan Suciu")), - Elem(null,"title" , e, sc, Text("Data on ze web"))), - Elem(null,"book",e,sc, - Elem(null,"author", e, sc, Text("John Mitchell")), - Elem(null,"title" , e, sc, Text("Foundations of Programming Languages"))) - ) - ); - - assertSameElements( - - parsedxml2 \ "_" \ "_", - - List( - Elem(null,"author", e, sc, Text("Peter Buneman")), - Elem(null,"author", e, sc, Text("Dan Suciu")), - Elem(null,"title" , e, sc, Text("Data on ze web")), - Elem(null,"author", e, sc, Text("John Mitchell")), - Elem(null,"title" , e, sc, Text("Foundations of Programming Languages")) - ) - ); - - assertSameElements( - - parsedxml2 \ "_" \ "author", - - List( - Elem(null,"author", e, sc, Text("Peter Buneman")), - Elem(null,"author", e, sc, Text("Dan Suciu")), - Elem(null,"author", e, sc, Text("John Mitchell")) - ) - - ); - - assertSameElements( (parsedxml2 \ "_" \ "_" \ "author"), List() ); - - Console.println("xpath \\\\ DESCENDANTS"); - - assertSameElements( - - parsedxml2 \\ "author", - - List( - Elem(null,"author", e, sc, Text("Peter Buneman")), - Elem(null,"author", e, sc, Text("Dan Suciu")), - Elem(null,"author", e, sc, Text("John Mitchell")) - ) - - ); - - - assertSameElements( - - parsedxml2 \\ "title", - - List( - Elem(null,"title", e, sc, Text("Data on ze web")), - Elem(null,"title", e, sc, Text("Foundations of Programming Languages"))) - ); - - - println( - (parsedxml2 \\ "book" ){ n:Node => n \ "title" == "Data on ze web" } - ); - - assertEquals( - - (new NodeSeq { val theSeq = List( parsedxml2 ) }) \\ "_", - - List( - Elem(null,"bib",e,sc, - Elem(null,"book",e,sc, - Elem(null, "author", e, sc, Text("Peter Buneman")), - Elem(null, "author", e, sc, Text("Dan Suciu")), - Elem(null, "title" , e, sc, Text("Data on ze web"))), - Elem(null,"book",e,sc, - Elem(null,"author",e,sc,Text("John Mitchell")), - Elem(null,"title",e,sc,Text("Foundations of Programming Languages")))), - Elem(null,"book",e,sc, - Elem(null,"author",e,sc,Text("Peter Buneman")), - Elem(null,"author",e,sc,Text("Dan Suciu")), - Elem(null,"title",e,sc,Text("Data on ze web"))), - Elem(null,"author",e,sc,Text("Peter Buneman")), - //Text("Peter Buneman"), - Elem(null,"author",e,sc,Text("Dan Suciu")), - //Text("Dan Suciu"), - Elem(null,"title",e,sc,Text("Data on ze web")), - //Text("Data on ze web"), - Elem(null,"book",e,sc, - Elem(null,"author",e,sc,Text("John Mitchell")), - Elem(null,"title",e,sc,Text("Foundations of Programming Languages"))), - Elem(null,"author",e,sc,Text("John Mitchell")), - //Text("John Mitchell"), - Elem(null,"title",e,sc,Text("Foundations of Programming Languages")) - //Text("Foundations of Programming Languages") - ) - ); - - // test group node - Console println "-- group nodes" - val zx1: Node = Group { <a/><b/><c/> } - val zy1 = <f>{zx1}</f> - Console println zy1.toString() - - val zx2: Node = Group { List(<a/>,zy1,zx1) } - Console println zx2.toString() - - val zz1 = <xml:group><a/><b/><c/></xml:group> - - assertTrue(zx1 == zz1) - assertTrue(zz1.length == 3) - - // unparsed - - val uup = <xml:unparsed>&<<>""^%@$!#</xml:unparsed> - assertTrue(uup == "&<<>\"\"^%@$!#") - // test unicode escapes backslash u - - println("attribute value normalization") - val xmlAttrValueNorm = "<personne id='p0003' nom='Şahingöz' />"; - { - val isrcA = new InputSource( new StringReader(xmlAttrValueNorm) ); - val parsedxmlA = XML.load(isrcA); - val c = (parsedxmlA \ "@nom").text.charAt(0); - //Console.println("char '"+c+"' \u015e"); - assertTrue(c == '\u015e'); - } - // buraq: if the following test fails with 'character x not allowed', it is - // related to the mutable variable in a closures in MarkupParser.parsecharref - { - val isr = scala.io.Source.fromString(xmlAttrValueNorm); - val pxmlB = scala.xml.parsing.ConstructingParser.fromSource(isr,false); - val parsedxmlB = pxmlB.element(TopScope); - val c = (parsedxmlB \ "@nom").text.charAt(0); - //Console.println("char '"+c+"' \u015e"); - assertTrue(c == '\u015e'); - } - - // #60 test by round trip - - val p = scala.xml.parsing.ConstructingParser.fromSource(scala.io.Source.fromString("<foo bar:attr='&'/>"),true) - val n = p.element(new scala.xml.NamespaceBinding("bar","BAR",scala.xml.TopScope))(0) - assertFalse( n.attributes.get("BAR", n, "attr").isEmpty) - - // #547 test - assertTrue(<xml:group>hello</xml:group>.toString == "hello") -} diff --git a/test/files/jvm/xml02.scala b/test/files/jvm/xml02.scala index 52ce3a0060..ed29868898 100644 --- a/test/files/jvm/xml02.scala +++ b/test/files/jvm/xml02.scala @@ -3,7 +3,7 @@ import testing.SUnit._ object Test extends TestConsoleMain { import scala.xml.{NodeSeq, Utility} - import NodeSeq.view + import NodeSeq.seqToNodeSeq val ax = <hello foo="bar" x:foo="baz" xmlns:x="the namespace from outer space"> <world/> |