From 17e2b1c2a6f69ba74e79c30d1e44195fe732e3e3 Mon Sep 17 00:00:00 2001 From: Gilles Dubochet Date: Fri, 16 Dec 2005 18:20:15 +0000 Subject: Removed old scala tests from new Scala core mod... Removed old scala tests from new Scala core module. --- test/files/jvm/JavaInteraction.check | 4 - test/files/jvm/JavaInteraction.scala | 24 --- test/files/jvm/RunTimeTypes.check | 72 -------- test/files/jvm/RunTimeTypes.scala | 200 ---------------------- test/files/jvm/bug281.check | 0 test/files/jvm/bug281.scala | 14 -- test/files/jvm/serialization.check | 100 ----------- test/files/jvm/serialization.scala | 316 ----------------------------------- test/files/jvm/xml01.check | 24 --- test/files/jvm/xml01.scala | 205 ----------------------- test/files/jvm/xmlLiterals.check | 71 -------- test/files/jvm/xmlLiterals.scala | 306 --------------------------------- test/files/jvm/xmlstuff.check | 43 ----- test/files/jvm/xmlstuff.scala | 278 ------------------------------ 14 files changed, 1657 deletions(-) delete mode 100644 test/files/jvm/JavaInteraction.check delete mode 100644 test/files/jvm/JavaInteraction.scala delete mode 100644 test/files/jvm/RunTimeTypes.check delete mode 100644 test/files/jvm/RunTimeTypes.scala delete mode 100644 test/files/jvm/bug281.check delete mode 100644 test/files/jvm/bug281.scala delete mode 100644 test/files/jvm/serialization.check delete mode 100644 test/files/jvm/serialization.scala delete mode 100644 test/files/jvm/xml01.check delete mode 100644 test/files/jvm/xml01.scala delete mode 100644 test/files/jvm/xmlLiterals.check delete mode 100644 test/files/jvm/xmlLiterals.scala delete mode 100644 test/files/jvm/xmlstuff.check delete mode 100644 test/files/jvm/xmlstuff.scala (limited to 'test/files/jvm') diff --git a/test/files/jvm/JavaInteraction.check b/test/files/jvm/JavaInteraction.check deleted file mode 100644 index fb9d3cdd8c..0000000000 --- a/test/files/jvm/JavaInteraction.check +++ /dev/null @@ -1,4 +0,0 @@ -p.x = 5 -p.c = java.awt.Color[r=255,g=0,b=0] -p.getX() = 5.0 -p.getC() = java.awt.Color[r=255,g=0,b=0] diff --git a/test/files/jvm/JavaInteraction.scala b/test/files/jvm/JavaInteraction.scala deleted file mode 100644 index 70eacebaf8..0000000000 --- a/test/files/jvm/JavaInteraction.scala +++ /dev/null @@ -1,24 +0,0 @@ -//############################################################################ -// Test Java interaction -//############################################################################ -// $Id$ - -import java.awt.Color; -import java.awt.Point; - -class ColoredPoint(x: Int, y: Int, c_ : Color) extends Point(x, y) { - val c: Color = c_; - def getC(): Color = c; -} - -object Test { - def main(args: Array[String]): Unit = { - val p = new ColoredPoint(5,7,Color.RED); - System.out.println("p.x = " + p.x); - System.out.println("p.c = " + p.c); - System.out.println("p.getX() = " + p.getX()); - System.out.println("p.getC() = " + p.getC()); - } -} - -//############################################################################ diff --git a/test/files/jvm/RunTimeTypes.check b/test/files/jvm/RunTimeTypes.check deleted file mode 100644 index 63624a0f1e..0000000000 --- a/test/files/jvm/RunTimeTypes.check +++ /dev/null @@ -1,72 +0,0 @@ -===== polymorphic classes -true -true -true -true -===== nested classes -true -true -true -true -true -true -true -===== classes nested inside functions -true -true -true -===== type paramater variance -true -true -true -true -true -true -true -true -true -true -true -true -true -true -true -true -true -===== singleton types -true -true -===== compound types -true -true -true -true -true -true -true -true -true -true -true -true -===== null -true -true -true -true -true -===== default value -true -true -true -true -true -true -true -true -true -===== arrays -true -true -true -true diff --git a/test/files/jvm/RunTimeTypes.scala b/test/files/jvm/RunTimeTypes.scala deleted file mode 100644 index 41911a7cce..0000000000 --- a/test/files/jvm/RunTimeTypes.scala +++ /dev/null @@ -1,200 +0,0 @@ -class C[T](x: T) { override def toString(): String = x.toString(); } - -object TestPolymorphicClasses { - def main(args: Array[String]): Unit = { - Console.println("===== polymorphic classes"); - Console.println(new C("true")); - Console.println(new C(true)); - Console.println((new C("a")).isInstanceOf[C[String]]); - Console.println(!(new C(42)).isInstanceOf[C[String]]); - } -} - -class Outer { - class Inner; -} - -class SubOuter extends Outer { - class SubInner extends Inner; -} - -object TestNestedClasses { - def main(args: Array[String]): Unit = { - Console.println("===== nested classes"); - val o1 = new Outer; - val i1 = new o1.Inner; - val o2 = new Outer; - val i2 = new o2.Inner; - Console.println( i1.isInstanceOf[o1.Inner]); - Console.println( i2.isInstanceOf[o2.Inner]); - Console.println(!i1.isInstanceOf[o2.Inner]); - Console.println(!i2.isInstanceOf[o1.Inner]); - val so1 = new SubOuter; - val si1 = new so1.SubInner; - val i3 = new so1.Inner; - Console.println( si1.isInstanceOf[so1.Inner]); - Console.println(!si1.isInstanceOf[o1.Inner]); - Console.println(! i3.isInstanceOf[so1.SubInner]); -// Console.println( i3.isInstanceOf[Outer#SubInner]); -// Console.println( i3.isInstanceOf[Outer#Inner]); - } -} - -object TestClassesInsideFunctions { - def f(x: String): ScalaObject = { - class C { override def toString() = x; }; - new C - } - def main(args: Array[String]): Unit = { - Console.println("===== classes nested inside functions"); - val c1 = f("true"); - val c2 = f("true"); - Console.println(c1); - Console.println(c2); - Console.println(!c1.getScalaType().isSameType(c2.getScalaType())); - } -} - -class Invariant[T]; -class Covariant[+T]; -class Contravariant[-T]; - -class MultiVariant[T1, -T2, +T3, T4, -T5, +T6]; - -object TestVariance { - def main(args: Array[String]): Unit = { - Console.println("===== type paramater variance"); - val invO = new Invariant[Object]; - val invS = new Invariant[String]; - Console.println( invO.isInstanceOf[Invariant[Object]]); - Console.println(!invO.isInstanceOf[Invariant[String]]); - Console.println(!invS.isInstanceOf[Invariant[Object]]); - Console.println( invS.isInstanceOf[Invariant[String]]); - val covO = new Covariant[Object]; - val covS = new Covariant[String]; - Console.println( covO.isInstanceOf[Covariant[Object]]); - Console.println(!covO.isInstanceOf[Covariant[String]]); - Console.println( covS.isInstanceOf[Covariant[Object]]); - Console.println( covS.isInstanceOf[Covariant[String]]); - val conO = new Contravariant[Object]; - val conS = new Contravariant[String]; - Console.println( conO.isInstanceOf[Contravariant[Object]]); - Console.println( conO.isInstanceOf[Contravariant[String]]); - Console.println(!conS.isInstanceOf[Contravariant[Object]]); - Console.println( conS.isInstanceOf[Contravariant[String]]); - val mulO = new MultiVariant[Object,Object,Object,Object,Object,Object]; - val mulS = new MultiVariant[String,String,String,String,String,String]; - Console.println( mulO.isInstanceOf[MultiVariant[Object,Object,Object,Object,Object,Object]]); - Console.println( mulO.isInstanceOf[MultiVariant[Object,String,Object,Object,String,Object]]); - Console.println( mulS.isInstanceOf[MultiVariant[String,String,String,String,String,String]]); - Console.println(!mulS.isInstanceOf[MultiVariant[Object,Object,Object,Object,Object,Object]]); - Console.println( mulS.isInstanceOf[MultiVariant[String,String,Object,String,String,Object]]); - } -} - -object TestSingletonTypes { - def main(args: Array[String]): Unit = { - Console.println("===== singleton types"); - val x: String = "x"; - val y: String = "y"; - Console.println( x.isInstanceOf[x.type]); - Console.println(!x.isInstanceOf[y.type]); - } -} - -object TestCompoundTypes { - class C, D; - - def main(args: Array[String]): Unit = { - Console.println("===== compound types"); - val c = new C; - val d = new D; - Console.println(!c.isInstanceOf[C with D]); - Console.println(!c.isInstanceOf[D with C]); - Console.println(!d.isInstanceOf[C with D]); - Console.println(!d.isInstanceOf[D with C]); - - val cd = new C with D; - val dc = new D with C; - Console.println(cd.isInstanceOf[C]); - Console.println(cd.isInstanceOf[D]); - Console.println(cd.isInstanceOf[C with D]); - Console.println(cd.isInstanceOf[D with C]); - Console.println(dc.isInstanceOf[C]); - Console.println(dc.isInstanceOf[D]); - Console.println(dc.isInstanceOf[C with D]); - Console.println(dc.isInstanceOf[D with C]); - } -} - -object TestNull { - class C; - def main(args: Array[String]): Unit = { - Console.println("===== null"); - Console.println(!null.isInstanceOf[Any]); - Console.println(!null.isInstanceOf[AnyRef]); - Console.println(!null.isInstanceOf[AllRef]); - Console.println(!null.isInstanceOf[C]); - Console.println((null.asInstanceOf[AnyRef]) == null); - try { - Console.println(null.asInstanceOf[Any]); - Console.println("false (THIS SHOULD NOT BE PRINTED!!!)"); - } catch { - case _: ClassCastException => () - } - } -} - -object TestDefaultValue { - def defaultValue[T]: T = { - class Cell[T] { var x: T = _; } - return (new Cell[T]).x; - } - - class C; - - def main(args: Array[String]): Unit = { - Console.println("===== default value"); - Console.println(defaultValue[Boolean] == false); - Console.println(defaultValue[Byte] == 0.asInstanceOf[Byte]); - Console.println(defaultValue[Short] == 0.asInstanceOf[Short]); - Console.println(defaultValue[Int] == 0); - Console.println(defaultValue[Long] == 0.asInstanceOf[Long]); - Console.println(defaultValue[Float] == 0.asInstanceOf[Float]); - Console.println(defaultValue[Double] == 0.asInstanceOf[Double]); - Console.println(defaultValue[String] == null); - Console.println(defaultValue[C] == null); - } -} - -object TestArrays { - def isInst[T](x: Any): Boolean = x.isInstanceOf[T]; - - def main(args: Array[String]): Unit = { - Console.println("===== arrays"); - - import java.lang.reflect.{Array => JArray}; - - val iArray = JArray.newInstance(Integer.TYPE, 5); - Console.println(iArray.isInstanceOf[Array[Int]]); - Console.println(isInst[Array[Int]](iArray)); - - val oArray = JArray.newInstance(Class.forName("java.lang.Object"), 5); - Console.println(oArray.isInstanceOf[Array[Object]]); - Console.println(isInst[Array[Object]](oArray)); - } -} - -object Test { - def main(args: Array[String]): Unit = { - TestPolymorphicClasses.main(args); - TestNestedClasses.main(args); - TestClassesInsideFunctions.main(args); - TestVariance.main(args); - TestSingletonTypes.main(args); - TestCompoundTypes.main(args); - TestNull.main(args); - TestDefaultValue.main(args); - TestArrays.main(args); - } -} diff --git a/test/files/jvm/bug281.check b/test/files/jvm/bug281.check deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/files/jvm/bug281.scala b/test/files/jvm/bug281.scala deleted file mode 100644 index 5f8c15b6ae..0000000000 --- a/test/files/jvm/bug281.scala +++ /dev/null @@ -1,14 +0,0 @@ -//############################################################################ -// Bug 281 - -class Bug281A extends java.util.Hashtable { - class B { def f = rehash() }; -} - -object Test { - def main(args: Array[String]): Unit = { - val a = new Bug281A; - val b = new a.B; - b.f - } -} diff --git a/test/files/jvm/serialization.check b/test/files/jvm/serialization.check deleted file mode 100644 index 9e846c3060..0000000000 --- a/test/files/jvm/serialization.check +++ /dev/null @@ -1,100 +0,0 @@ -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 = -y4 = -x4(2): 4 - y4(2): 4 - -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 = {buffers -> 20, layers -> 2, title -> 3} -y = {buffers -> 20, layers -> 2, title -> 3} -x equals y: true - y equals x: true - -x = {1} -y = {1} -x equals y: true - y equals x: true - -x = {5, 3} -y = {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(c, b, a) -y = Stack(c, b, a) -x equals y: true - y equals x: true - -x = {42 -> FortyTwo} -y = {42 -> FortyTwo} -x equals y: true - y equals x: true - -x = {0, 2} -y = {0, 2} -x equals y: true - y equals x: true - -x = {title -> 3, buffers -> 20, layers -> 2} -y = {title -> 3, buffers -> 20, layers -> 2} -x equals y: true - y equals x: true - -x = {0, 8, 9} -y = {0, 8, 9} -x equals y: true - y equals x: true - -x = {title, buffers, layers} -y = {title, buffers, layers} -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 = title -y = title -x equals y: true - y equals x: true - -x =
Last NameFirst Name
Tom20
Bob22
James19
-y =
Last NameFirst Name
Tom20
Bob22
James19
-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 - diff --git a/test/files/jvm/serialization.scala b/test/files/jvm/serialization.scala deleted file mode 100644 index f55af0d46f..0000000000 --- a/test/files/jvm/serialization.scala +++ /dev/null @@ -1,316 +0,0 @@ -//############################################################################ -// Serialization -//############################################################################ -// $Id$ - -import java.lang.System; - -object EqualityTest { - def check[A, B](x: A, y: B): Unit = { - System.out.println("x = " + x); - System.out.println("y = " + y); - System.out.println( - "x equals y: " + (x equals y) + " - y equals x: " + (y equals x)); - System.out.println(); - } -} - -object Serialize { - def write[A](o: A): Array[Byte] = { // throws Exception - val ba = new java.io.ByteArrayOutputStream(512); - val out = new java.io.ObjectOutputStream(ba); - out.writeObject(o); - out.close(); - ba.toByteArray() - } - def read[A](buffer: Array[Byte]): A = { // throws Exception - val in = - new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer)); - in.readObject().asInstanceOf[A] - } -} - -//############################################################################ -// Test classes in package "scala" - -[serializable] -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]) = - (a1.length == a2.length) && - (Iterator.range(0, a1.length) forall { i => a1(i) == a2(i) }); - val x1 = Nil; - val x2 = None; - val x3 = Array(1, 2, 3); - val x4 = x: Int => 2 * x; - - try { - val y1: List[All] = Serialize.read(Serialize.write(x1)); - val y2: Option[All] = Serialize.read(Serialize.write(x2)); - val y3: Array[Int] = Serialize.read(Serialize.write(x3)); - val y4: Function[Int, Int] = Serialize.read(Serialize.write(x4)); - - System.out.println("x1 = " + x1); - System.out.println("y1 = " + y1); - System.out.println("x1 eq y1: " + (x1 eq y1) + " - y1 eq x1: " + (y1 eq x1)); - System.out.println(); - System.out.println("x2 = " + x2); - System.out.println("y2 = " + y2); - System.out.println("x2 eq y2: " + (x2 eq y2) + " - y2 eq x2: " + (y2 eq x2)); - System.out.println(); - System.out.println("x3 = " + arrayToString(x3)); - System.out.println("y3 = " + arrayToString(y3)); - System.out.println("arrayEquals(x3, y3): " + arrayEquals(x3, y3)); - System.out.println(); - System.out.println("x4 = "); - System.out.println("y4 = "); - System.out.println("x4(2): " + x4(2) + " - y4(2): " + y4(2)); - System.out.println(); - } - catch { - case e: Exception => - e.printStackTrace(); - System.out.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] - .incl(Pair("buffers", 20)) - .incl(Pair("layers", 2)) - .incl(Pair("title", 3)); - - val x3 = new BitSet(4, Array(2), true); - - val x4 = new ListSet[Int]().incl(3).incl(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]().incl(2).incl(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 => - System.out.println("Error in Test2_immutable: " + e); - } -} - -//############################################################################ -// Test classes in package "scala.collection.mutable" - -object Test3_mutable { - import scala.collection.mutable.{BitSet,HashMap,HashSet,LinkedList, - Queue,Stack}; - - val x1 = new HashMap[String, Int]; - x1 ++= Test2_immutable.x1; - - val x2 = new BitSet(); - x2.set(0); - x2.set(8); - x2.set(9); - - val x3 = new HashSet[String]; - x3 ++= Test2_immutable.x1.map(p => p._1); - - val x4 = new LinkedList[Int](2, null); - x4.append(new LinkedList(3, null)); - - val x5 = new Queue[Int]; - x5 ++= Test2_immutable.x1.map(p => p._2); - - val x6 = new Stack[Int]; - x6 ++= x5; - - try { - 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)); - - EqualityTest.check(x1, y1); - EqualityTest.check(x2, y2); - EqualityTest.check(x3, y3); - EqualityTest.check(x4, y4); - EqualityTest.check(x5, y5); - EqualityTest.check(x6, y6); - } - catch { - case e: Exception => - System.out.println("Error in Test3_mutable: " + e); - } -} - -//############################################################################ -// Test classes in package "scala.xml" - -object Test4_xml { - import scala.xml.{Elem}; - - val x1 = title; - - case class Person(name: String, age: Int); - - class AddressBook(a: Person*) { - private val people: List[Person] = a.toList; - def toXHTML = - - - - - - { for (val p <- people) yield - - - - } -
Last NameFirst Name
{ p.name } { p.age.toString() }
; - } - - val people = new AddressBook( - Person("Tom", 20), - Person("Bob", 22), - Person("James", 19)); - - val x2 = - - - { people.toXHTML } - - ; - - 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 => - System.out.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 => - System.out.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 => - System.out.println("Error in Test6: " + e); - } -} - -//############################################################################ -// Test code - -object Test { - def main(args: Array[String]): Unit = { - Test1_scala; - Test2_immutable; - Test3_mutable; - Test4_xml; - Test5; - Test6 - } -} - -//############################################################################ - diff --git a/test/files/jvm/xml01.check b/test/files/jvm/xml01.check deleted file mode 100644 index dd05157794..0000000000 --- a/test/files/jvm/xml01.check +++ /dev/null @@ -1,24 +0,0 @@ -passed ok -equality -passed ok -passed ok -passed ok -passed ok -passed ok -xpath \ -passed ok -passed ok -passed ok -passed ok -passed ok -passed ok -passed ok -passed ok -xpath \\ DESCENDANTS -passed ok -passed ok -passed ok -Peter BunemanDan SuciuData on ze web -attribute value normalization -passed ok -passed ok diff --git a/test/files/jvm/xml01.scala b/test/files/jvm/xml01.scala deleted file mode 100644 index 1e54ae9e19..0000000000 --- a/test/files/jvm/xml01.scala +++ /dev/null @@ -1,205 +0,0 @@ -import java.io.StringReader; -import org.xml.sax.InputSource; -import scala.xml._; -import scala.util.logging._; - -import scala.testing.UnitTest._ ; - -object Test { - def main(args:Array[String]) = { - val e: scala.xml.MetaData = Null; //Node.NoAttributes; - val sc: scala.xml.NamespaceBinding = TopScope; - - val xmlFile1 = ""; - 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 )); - - Console.println("equality"); - assertEquals(c, parsedxml11); - assertEquals(parsedxml1, parsedxml11); - assertSameElements( List(parsedxml1), List(parsedxml11)); - assertSameElements( Iterator.fromArray(Predef.Array(parsedxml1)).toList, List(parsedxml11)); - - val x2 = "Peter BunemanDan SuciuData on ze web"; - - 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 = "Peter BunemanDan SuciuData on ze webJohn MitchellFoundations of Programming Languages"; - val isrc2 = new InputSource( new StringReader( xmlFile2 ) ); - val parsedxml2 = XML.load( isrc2 ); - - // xmlFile2/book -> book,book - Console.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")) - ) - - ); - 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") - ) - ); - - - assertSameElements( - - parsedxml2 \\ "title", - - List( - Elem(null,"title", e, sc, Text("Data on ze web")), - Elem(null,"title", e, sc, Text("Foundations of Programming Languages"))) - ); - - - Console.println( - (parsedxml2 \\ "book" ){ n:Node => n \ "title" == "Data on ze web" } - ); - - // test unicode escapes backslash u - - Console println ("attribute value normalization"); - val xmlAttrValueNorm = ""; - { - 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'); - } - { - 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'); - } - - } - - -} diff --git a/test/files/jvm/xmlLiterals.check b/test/files/jvm/xmlLiterals.check deleted file mode 100644 index 455284bf76..0000000000 --- a/test/files/jvm/xmlLiterals.check +++ /dev/null @@ -1,71 +0,0 @@ -Test01Literals -passed ok -passed ok -passed ok -ws trimming in patterns -passed ok -passed ok - - -Test02Embed -passed ok -passed ok -passed ok -passed ok -passed ok -passed ok -passed ok -passed ok -passed ok -Test03Servlet -ModularFormatting

Welcome

What follows is an example of modular formatting.

message

1a23.23

message

message


Complicated layout tasks can be encapsulated and outsourced.

Bye!

- - - ModularFormatting - - -

Welcome

-

What follows is an example of modular formatting.

-

- - - - -
-

message

-
-

-

1a23.23

-

- - - - -
-

message

-
- - - - - -
-

message

-
-

-
-

Complicated layout tasks can be encapsulated and outsourced.

-

Bye!

- - -Test04 -List(,Text,) - -passed ok -passed ok -passed ok -Test05Ref -{ - { -namespace - diff --git a/test/files/jvm/xmlLiterals.scala b/test/files/jvm/xmlLiterals.scala deleted file mode 100644 index 3548975fe1..0000000000 --- a/test/files/jvm/xmlLiterals.scala +++ /dev/null @@ -1,306 +0,0 @@ -//############################################################################ -// XML Literals -//############################################################################ -// $Id$ - -import scala.testing.UnitTest._ ; - -import scala.xml._ ; -import scala.collection.immutable ; - - -object Test { - - val e = Node.NoAttributes; - - /* a helper function to compare up to whitespace */ - - def noWS(x:String):String = { - val res = new StringBuffer(); - var i = 0; while( i < x.length() ) { - val c = x.charAt( i ); - c match { - case ' ' | '\n' | '\t' => - case _ => res.append( c ) - } - i = i + 1; - } - res.toString(); - } - - - object Test01Literals { - - - - /* === tags, elements === */ - - assertEquals( .toString(), - .toString()); /* ws in tags */ - - assertEquals( .toString(), - noWS( .toString())); - - val xx3 = - - - ; - - val x3 = xx3.toString(); /* ws in element content */ - - //Console.println("tmp1:"+x3); - //Console.println("tmp2:"+Elem(null,"mars",e,TopScope).toString() ); - assertEquals( noWS( x3 ), - Elem(null,"hello",e,TopScope, - Elem(null,"world",e,TopScope), - Elem(null,"test",e,TopScope), - Elem(null,"mars",e,TopScope)).toString() ); - - - Console.println("ws trimming in patterns"); - - assertEquals( true, match { - case => true; - case _ => false;} ); - - - /* === attributes === */ - - val z = - -

Hello World

-

Check the scala page!

- - .toString(); - - assertEquals( noWS( z ), noWS( - Elem(null,"html",e,TopScope, - Elem(null,"body",e,TopScope, - Elem(null,"h1",e,TopScope,Text("Hello World")), - Elem(null,"p",e,TopScope,Text("Check the "), - Elem(null,"a", e,TopScope,Text("scala")) - % (new UnprefixedAttribute("href","scala.epfl.ch",Null)), - Text("page!")) - ) % new UnprefixedAttribute("background","#FFFFFF",Null) - ).toString() - )); - - /* === attributes are Scala expr === */ - - val testValue = "This is a test."; - val testValue2 = 42; - val page = ; - val page2 = ; - - Console.println( page.toString() ); - Console.println( page2.toString() ); - - } - - object Test02Embed { - - /* === embedded Scala blocks === */ - - def computeDate() = { - Elem(null,"date", e, TopScope, Text("now!")); - } - /* embedding Scala strings as text and elements */ - val sc = { "World" }{ Text("42") }{ computeDate() }; - - assertEquals( sc.child.elements.toList, - List( Text("World"), Text("42"), Elem(null, "date", e,TopScope, Text("now!") ) ) ); - - assertEquals( sc.toString(), - Elem(null,"hello",e,TopScope,Text("World42"),Elem(null,"date",e,TopScope, Text("now!"))).toString() ); - - def foo( m:Node ):String = m match { - case => "hello node" - case => "hallo node" - case { z } => "test node:"+z - case { e1:Node }{ e2:Node }{ _* } => e1.toString() + e2.toString(); - } - - assertEquals( foo(), "hello node" ); - assertEquals( foo(), "hallo node" ); - assertEquals( foo(42), "test node:42" ); - assertEquals( foo(), - .toString() + .toString() ); - - val rows = - 1.11.2 - - - 2.12.2 - ; - - assertEquals( noWS( rows.toList.toString() ), - noWS( List(Elem(null,"tr",e,TopScope, - Elem(null,"td",e,TopScope,Text("1.1")),Elem(null,"td",e,TopScope, Text("1.2")) - ), - Elem(null,"tr",e,TopScope, - Elem(null,"td",e,TopScope,Text("2.1")),Elem(null,"td",e,TopScope,Text("2.2")) - ) - ).toString() ) - ); - val rows2 = ; - val rows3 = a b c d ; - - // these are not equal as comments are valid XML Info items. - assertEquals( rows2, Elem(null,"tr",e,TopScope,Comment(" an XML comment "),ProcInstr("pinotext",""),ProcInstr("pi","text"))); - - assertEquals( rows3, Elem(null,"tr",e,TopScope,Text("a"),Comment(" an XML comment "),Text("b"),ProcInstr("pinotext",""),Text("c"),ProcInstr("pi","text"),Text("d"))); - - } - -object Test03Servlet { - - val headerMsg = Text("What follows is an example of modular formatting."); - val footerMsg = Text("Complicated layout tasks can be encapsulated and outsourced."); - - /** helper function for the main page, provides header and a footer - */ - def page( ns:Seq[Node] ) = { - - - ModularFormatting - - -

Welcome

-

- {headerMsg } -

-

- { ns } -

-

- { 1 } {'a'} { 23.23 } -

-

- { for(val n <- ns.toList) yield { n::n::Nil } } -

-
-

- {footerMsg} -

-

Bye!

- - - } - - /** applies beautify to every element in a sequence - */ - def beautify( xs:Seq[Node] ):Seq[Node] = xs.toList.map { beautify } - - /** this is a recursive procedure that adds some attributes to the tree - */ - def beautify( n:Node ):Node = n match { - case {xs @ _* } => - { xs } - - case { xs @ _* }
=> - { beautify( xs )}
- - case Elem(null, label, _, _, xs @ _* ) => - new Elem(null, label, e, TopScope, beautify( xs ):_*) - - case _ => n - } - - /** this function will take a node and put it in a table - */ - def format( msg:Node ):Node = { - - - - -
{ msg }
- } - - /** returns a highlighted text node with the string given as arguemnt. if it - * is null, supplies a default string. - */ - def getMessage( x:String ) = { - if( x == null ) -

This could be YOUR message !

- else -

{ Text( x ) }

- } - - /** the entry method - */ - def doGetXML() = { - beautify( page( List( format( getMessage( "message" ) )) )); - //page( List( format( theMessage ))); - } - - def main( args:Array[String] ) = { - val x = doGetXML(); - Console.println( x ); - Console.println( new PrettyPrinter( 80, 2 ).format( x )); - } - -} - - - object Test04 { - val sequence = - Text - ; - - Console.println( sequence ); - - val onlyOne = ; - - Console.println( onlyOne ); - - val tryBrace = Now escaped {{ braces } ; - assertEquals( tryBrace, Elem(null,"try",e,TopScope,Text("Now escaped { braces }"))); - - val tryBrace2 = cool ?; - assertEquals( tryBrace2.attribute("myAttrib"), "7" ); - - /* Scala comments are not allowed in XML literals. see neg(2) */ - val zzz = /* no comment */; - assertEquals( zzz, Elem(null,"hello", e,TopScope, Text("/* no comment */"))); - - } - - - def test05main = { - val x1s = {.toString(); - Console.println( x1s ); - val x2 =  {.toString(); - Console.println( x2 ); - } - - def test06 = { - - val foo = - - - ; - - Console.println( foo ); - - } - - - def main( args:Array[String] ):Unit = { - Console.println("Test01Literals"); - Test01Literals; - Console.println("Test02Embed"); - Test02Embed; - Console.println("Test03Servlet"); - Test03Servlet.main( args ); - Console.println("Test04"); - Test04; - Console.println("Test05Ref"); - test05main; - Console.println("namespace"); - test06;{ - } - } - - -} - diff --git a/test/files/jvm/xmlstuff.check b/test/files/jvm/xmlstuff.check deleted file mode 100644 index 2f3424b524..0000000000 --- a/test/files/jvm/xmlstuff.check +++ /dev/null @@ -1,43 +0,0 @@ -NodeSeq -passed ok -passed ok - - 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 - -patterns -passed ok -passed ok -passed ok -namespaces -passed ok -passed ok -passed ok -validation - elements -passed ok -passed ok -passed ok -passed ok -validation - attributes -passed ok -passed ok -passed ok -passed ok -passed ok diff --git a/test/files/jvm/xmlstuff.scala b/test/files/jvm/xmlstuff.scala deleted file mode 100644 index 96d7317aab..0000000000 --- a/test/files/jvm/xmlstuff.scala +++ /dev/null @@ -1,278 +0,0 @@ -import java.io.StringReader; -import org.xml.sax.InputSource; -import scala.testing.UnitTest._ ; -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 { - val x = att.apply({}); - } catch { - case scala.xml.MalformedAttributeException(msg) => - Console.println(msg); - ex = true; - } - return ex; - } - - def main(args:Array[String]) = { - - //val e: scala.xml.MetaData = null; //Node.NoAttributes; - //val sc: scala.xml.NamespaceBinding = null; - - // ------------------------------------------ tests for class NodeSeq - - /** - Console.println("checking wellformed attributes"); - { - import scala.xml.{ UnprefixedAttribute, Null } - assertTrue(catcher {x:Unit => new UnprefixedAttribute("key", "<", Null)}); // < illegal - assertTrue(catcher(x:Unit => new UnprefixedAttribute("key", "&", Null))); // & illegal - assertTrue(catcher(x:Unit => new UnprefixedAttribute("key", "a&a", Null))); // & illegal - assertTrue(catcher(x:Unit => new UnprefixedAttribute("key", "a&a;&", Null))); // 2nd & - - assertFalse(catcher(x:Unit => new UnprefixedAttribute("key", "a&a; <<", Null))); - } -*/ - -/* -checking wellformed attributes -< not allowed in attribute value -passed ok -malformed entity reference in attribute value [&] -passed ok -malformed entity reference in attribute value [a&a] -passed ok -malformed entity reference in attribute value [a&a;&] -passed ok -passed ok -*/ - - Console.println("NodeSeq"); - import scala.xml.Utility.view ; - - val p = - - - - ; - - val pelems_1 = for( val x <- p \ "bar"; val y <- p \ "baz" ) yield { - Text(x.attribute("value").toString() + y.attribute("bazValue").toString()+ "!") - }; - val pelems_2 = new NodeSeq { val theSeq = List(Text("38!"),Text("58!")) }; - assertSameElements(pelems_1, pelems_2); - assertSameElements( - p \\ "@value", new NodeSeq { val theSeq = List(Text("3"), Text("5")) } - ); - - - /* // more test cases !!! - val test =
; - - Console.println(test \ "@name"); - - val x = test.attributes.nodes; - Console.println("trying to print"); - val it = x.elements; - while(it.hasNext) { - val c = it.next; - Console.println(c); - Console.println("c.label == @name? "+(c.label == "@name")); - } - */ - - /* - for(val c <- x) { - Console.println(x); - } - */ - - val books = - - Blabla - Blubabla - Baaaaaaalabla - ; - - val reviews = - - Blabla - - Hallo Welt. - - - Blubabla - - Hello Blu - - - Blubabla - - rem 2 - - - ; - - Console.println( new scala.xml.PrettyPrinter(80, 5).formatNodes ( - for( val t <- books \\ "title"; - val r <- reviews \\ "entry"; - r \ "title" == t) yield - - { t } - { r \ "remarks" } - - )); - - // example - Console.println( - for( val t @ Blabla <- new NodeSeq { val theSeq = books.child }.asList) - 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 - - ; - - Console.println( new scala.xml.PrettyPrinter(80, 5).formatNodes ( - for( val t <- addrBook \\ "entry"; - val r <- phoneBook \\ "entry"; - t \ "name" == r \ "name") yield - - { t.child } - { r \ "phone" } - - )); - - /* patterns */ - Console.println("patterns"); - assertEquals( match { case => true; case _ => false; }, - true); - - assertEquals( - - - match { case x @ - - if x.attribute("foo") == "bar" => true; - case _ => false; }, - true); - - assertEquals( - - crazy text world - match { case - crazy text world - => true; - case _ => false; }, - true); - - - /* namespaces */ - // begin tmp - Console.println("namespaces"); - val cuckoo = - - - ; - assertEquals( cuckoo.namespace, "http://cuckoo.com"); - for( val n <- cuckoo.child ) { - assertEquals( n.namespace, "http://cuckoo.com"); - } - // end tmp - /* - -DEPRECATED, don't support namespaces in pattern match anymore -*/ - /* - assertEquals( true, cuckoo match { - case - - - => true; - case _ => false; }); -*/ - /* - // begin tmp - assertEquals( false, cuckoo match { - case - - - => true; - case _ => false; }); - // end tmp - */ - Console.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"))) ))); - - } - assertEquals( vtor( ), true ); - { - import scala.xml.dtd.MIXED; - import scala.xml.dtd.ContentModel._; - - vtor.setContentModel( - MIXED( - Alt(Letter(ElemName("bar")), - Letter(ElemName("baz")), - Letter(ElemName("bal"))))); - } - - assertEquals( vtor( ), true ); - assertEquals( vtor( abcdedgh ), true ); - assertEquals( vtor( ), false ); - - Console.println("validation - attributes"); - vtor.setContentModel(null); - vtor.setMetaData(List()); - assertEquals( vtor( ), false ); - - { - import scala.xml.dtd._ ; - vtor.setMetaData(List(AttrDecl("bar","CDATA",IMPLIED))); - } - assertEquals( vtor( ), false ); - assertEquals( vtor( ), true ); - - { - import scala.xml.dtd._ ; - vtor.setMetaData(List(AttrDecl("bar","CDATA",REQUIRED))); - } - assertEquals( vtor( ), false ); - assertEquals( vtor( ), true ); - - } -} -- cgit v1.2.3