summaryrefslogtreecommitdiff
path: root/test/files/jvm
diff options
context:
space:
mode:
authorGilles Dubochet <gilles.dubochet@epfl.ch>2005-12-16 18:20:15 +0000
committerGilles Dubochet <gilles.dubochet@epfl.ch>2005-12-16 18:20:15 +0000
commit17e2b1c2a6f69ba74e79c30d1e44195fe732e3e3 (patch)
treebb804b4038eb6d0dee58b77cea8bd2dcc6f42dc4 /test/files/jvm
parente70a1a24ef7a7b596a92e1853fd44e96f36ad245 (diff)
downloadscala-17e2b1c2a6f69ba74e79c30d1e44195fe732e3e3.tar.gz
scala-17e2b1c2a6f69ba74e79c30d1e44195fe732e3e3.tar.bz2
scala-17e2b1c2a6f69ba74e79c30d1e44195fe732e3e3.zip
Removed old scala tests from new Scala core mod...
Removed old scala tests from new Scala core module.
Diffstat (limited to 'test/files/jvm')
-rw-r--r--test/files/jvm/JavaInteraction.check4
-rw-r--r--test/files/jvm/JavaInteraction.scala24
-rw-r--r--test/files/jvm/RunTimeTypes.check72
-rw-r--r--test/files/jvm/RunTimeTypes.scala200
-rw-r--r--test/files/jvm/bug281.check0
-rw-r--r--test/files/jvm/bug281.scala14
-rw-r--r--test/files/jvm/serialization.check100
-rw-r--r--test/files/jvm/serialization.scala316
-rw-r--r--test/files/jvm/xml01.check24
-rw-r--r--test/files/jvm/xml01.scala205
-rw-r--r--test/files/jvm/xmlLiterals.check71
-rw-r--r--test/files/jvm/xmlLiterals.scala306
-rw-r--r--test/files/jvm/xmlstuff.check43
-rw-r--r--test/files/jvm/xmlstuff.scala278
14 files changed, 0 insertions, 1657 deletions
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
--- a/test/files/jvm/bug281.check
+++ /dev/null
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 = <na>
-y4 = <na>
-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 = <html><title>title</title><body></body></html>
-y = <html><title>title</title><body></body></html>
-x equals y: true - y equals x: true
-
-x = <html><body><table cellspacing="0" cellpadding="2"><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 cellspacing="0" cellpadding="2"><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
-
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 = <na>");
- System.out.println("y4 = <na>");
- 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 = <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 =>
- 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
-<book><author>Peter Buneman</author><author>Dan Suciu</author><title>Data on ze web</title></book>
-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 = "<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 ));
-
- 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 = "<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
- 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 = "<personne id='p0003' nom='&#x015e;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');
- }
- {
- 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
-<testTag ab="bkla" value="This is a test."></testTag>
-<testTag bla="foo" value="42"></testTag>
-Test02Embed
-passed ok
-passed ok
-passed ok
-passed ok
-passed ok
-passed ok
-passed ok
-passed ok
-passed ok
-Test03Servlet
-<html><head><title>ModularFormatting</title></head><body><h2>Welcome</h2><p>What follows is an example of modular formatting.</p><p><table align="center"><tr><td bgcolor="#AAAAFF" color="#222255"><h1>message</h1></td></tr></table></p><p>1a23.23</p><p><table align="center"><tr><td bgcolor="#AAAAFF" color="#222255"><h1>message</h1></td></tr></table> <table align="center"><tr><td bgcolor="#AAAAFF" color="#222255"><h1>message</h1></td></tr></table></p><hr></hr><p>Complicated layout tasks can be encapsulated and outsourced.</p><h2>Bye!</h2></body></html>
-<html>
- <head>
- <title>ModularFormatting</title>
- </head>
- <body>
- <h2>Welcome</h2>
- <p>What follows is an example of modular formatting.</p>
- <p>
- <table align="center">
- <tr>
- <td bgcolor="#AAAAFF" color="#222255">
- <h1>message</h1>
- </td>
- </tr>
- </table>
- </p>
- <p>1a23.23</p>
- <p>
- <table align="center">
- <tr>
- <td bgcolor="#AAAAFF" color="#222255">
- <h1>message</h1>
- </td>
- </tr>
- </table>
-
- <table align="center">
- <tr>
- <td bgcolor="#AAAAFF" color="#222255">
- <h1>message</h1>
- </td>
- </tr>
- </table>
- </p>
- <hr></hr>
- <p>Complicated layout tasks can be encapsulated and outsourced.</p>
- <h2>Bye!</h2>
- </body>
-</html>
-Test04
-List(<foo></foo>,<bar>Text</bar>,<foo></foo>)
-<foo></foo>
-passed ok
-passed ok
-passed ok
-Test05Ref
-<foo>{</foo>
-<foo>&nbsp;{<bar><baz></baz></bar><bar></bar></foo>
-namespace
-<bar:foo xmlns:bar="www.bar.com" xmlns="www.baz.com"><baz></baz></bar:foo>
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( <hello></hello>.toString(),
- <hello ></hello>.toString()); /* ws in tags */
-
- assertEquals( <hello></hello>.toString(),
- noWS(<hello > </hello>.toString()));
-
- val xx3 = <hello>
- <world></world>
- <test/>
- <mars></mars></hello>;
-
- 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, <hello> <world/> </hello> match {
- case <hello> <world/> </hello> => true;
- case _ => false;} );
-
-
- /* === attributes === */
-
- val z = <html>
- <body background="#FFFFFF">
- <h1>Hello World</h1>
- <p>Check the <a href="scala.epfl.ch">scala</a> page!</p>
- </body>
- </html>.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 = <testTag value={ testValue } ab="bkla" />;
- val page2 = <testTag value={testValue2.toString()} bla="foo"></testTag>;
-
- 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 = <hello>{ "World" }{ Text("42") }{ computeDate() }</hello>;
-
- 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/> => "hello node"
- case <hallo ></hallo > => "hallo node"
- case <test>{ z }</test> => "test node:"+z
- case <list>{ e1:Node }{ e2:Node }{ _* }</list> => e1.toString() + e2.toString();
- }
-
- assertEquals( foo(<hello/>), "hello node" );
- assertEquals( foo(<hallo/>), "hallo node" );
- assertEquals( foo(<test>42</test>), "test node:42" );
- assertEquals( foo(<list><a/><b><c/></b><d/><d/></list>),
- <a/>.toString() + <b><c/></b>.toString() );
-
- val rows = <tr>
- <td>1.1</td><td>1.2</td>
- </tr>
- <tr>
- <td>2.1</td><td>2.2</td>
- </tr>;
-
- 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 = <tr><!-- an XML comment --><?pinotext?><?pi text?></tr>;
- val rows3 = <tr> a <!-- an XML comment --> b <?pinotext?> c <?pi text?> d </tr>;
-
- // 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] ) = {
- <html>
- <head>
- <title>ModularFormatting</title>
- </head>
- <body>
- <h2>Welcome</h2>
- <p>
- {headerMsg }
- </p>
- <p>
- { ns }
- </p>
- <p>
- { 1 } {'a'} { 23.23 }
- </p>
- <p>
- { for(val n <- ns.toList) yield { n::n::Nil } }
- </p>
- <hr/>
- <p>
- {footerMsg}
- </p>
- <h2>Bye!</h2>
- </body>
- </html>
- }
-
- /** 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 <td>{xs @ _* }</td> =>
- <td bgcolor="#AAAAFF" color="#222255">{ xs }</td>
-
- case <table>{ xs @ _* }</table> =>
- <table align="center">{ beautify( xs )}</table>
-
- 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 = {
- <table>
- <tr>
- <td>{ msg }</td>
- </tr>
- </table>
- }
-
- /** 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 )
- <h1> This could be YOUR message ! </h1>
- else
- <h1> { Text( x ) } </h1>
- }
-
- /** 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 = <foo/>
- <bar>Text</bar>
- <foo/>;
-
- Console.println( sequence );
-
- val onlyOne = <foo/>;
-
- Console.println( onlyOne );
-
- val tryBrace = <try>Now escaped {{ braces } </try>;
- assertEquals( tryBrace, Elem(null,"try",e,TopScope,Text("Now escaped { braces }")));
-
- val tryBrace2 = <try myAttrib={(3+4).toString() }> cool ?</try>;
- assertEquals( tryBrace2.attribute("myAttrib"), "7" );
-
- /* Scala comments are not allowed in XML literals. see neg(2) */
- val zzz = <hello>/* no comment */</hello>;
- assertEquals( zzz, Elem(null,"hello", e,TopScope, Text("/* no comment */")));
-
- }
-
-
- def test05main = {
- val x1s = <foo>&#0123;</foo>.toString();
- Console.println( x1s );
- val x2 = <foo>&nbsp;&#x7b;<bar><baz/></bar><bar/></foo>.toString();
- Console.println( x2 );
- }
-
- def test06 = {
-
- val foo =
- <bar:foo xmlns:bar="www.bar.com" xmlns="www.baz.com">
- <baz/>
- </bar: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
-<result>
- <title>Blabla</title>
- <remarks>Hallo Welt.</remarks>
-</result><result>
- <title>Blubabla</title>
- <remarks>Hello Blu</remarks>
-</result><result>
- <title>Blubabla</title>
- <remarks>rem 2</remarks>
-</result>
-List(<book><title>Blabla</title></book>)
-<result>
- <name>John</name>
-
- <street>Elm Street</street>
-
- <city>Dolphin City</city>
- <phone where="work">+41 21 693 68 67</phone>
-
- <phone where="mobile">+41 79 602 23 23</phone>
-</result>
-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; &lt;&lt;", 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 = <foo>
- <bar gt='ga' value="3"/>
- <baz bazValue="8"/>
- <bar value="5" gi='go'/>
- </foo>;
-
- 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 = <a name="bar"/>;
-
- 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 =
- <bks>
- <book><title>Blabla</title></book>
- <book><title>Blubabla</title></book>
- <book><title>Baaaaaaalabla</title></book>
- </bks>;
-
- val reviews =
- <reviews>
- <entry><title>Blabla</title>
- <remarks>
- Hallo Welt.
- </remarks>
- </entry>
- <entry><title>Blubabla</title>
- <remarks>
- Hello Blu
- </remarks>
- </entry>
- <entry><title>Blubabla</title>
- <remarks>
- rem 2
- </remarks>
- </entry>
- </reviews>;
-
- Console.println( new scala.xml.PrettyPrinter(80, 5).formatNodes (
- for( val t <- books \\ "title";
- val r <- reviews \\ "entry";
- r \ "title" == t) yield
- <result>
- { t }
- { r \ "remarks" }
- </result>
- ));
-
- // example
- Console.println(
- for( val t @ <book><title>Blabla</title></book> <- new NodeSeq { val theSeq = books.child }.asList)
- yield t
- );
-val phoneBook =
- <phonebook>
- <descr>
- This is the <b>phonebook</b> of the
- <a href="http://acme.org">ACME</a> corporation.
- </descr>
- <entry>
- <name>John</name>
- <phone where="work"> +41 21 693 68 67</phone>
- <phone where="mobile">+41 79 602 23 23</phone>
- </entry>
- </phonebook>;
-
-
-val addrBook =
- <addrbook>
- <descr>
- This is the <b>addressbook</b> of the
- <a href="http://acme.org">ACME</a> corporation.
- </descr>
- <entry>
- <name>John</name>
- <street> Elm Street</street>
- <city>Dolphin City</city>
- </entry>
- </addrbook>;
-
- Console.println( new scala.xml.PrettyPrinter(80, 5).formatNodes (
- for( val t <- addrBook \\ "entry";
- val r <- phoneBook \\ "entry";
- t \ "name" == r \ "name") yield
- <result>
- { t.child }
- { r \ "phone" }
- </result>
- ));
-
- /* patterns */
- Console.println("patterns");
- assertEquals(<hello/> match { case <hello/> => true; case _ => false; },
- true);
-
- assertEquals(
- <hello foo="bar">
- <world/>
- </hello> match { case x @ <hello>
- <world/>
- </hello> if x.attribute("foo") == "bar" => true;
- case _ => false; },
- true);
-
- assertEquals(
- <hello foo="bar">
- crazy text world
- </hello> match { case <hello>
- crazy text world
- </hello> => true;
- case _ => false; },
- true);
-
-
- /* namespaces */
- // begin tmp
- Console.println("namespaces");
- val cuckoo = <cuckoo xmlns="http://cuckoo.com">
- <foo/>
- <bar/>
- </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 <cuckoo xmlns="http://cuckoo.com">
- <foo/>
- <bar/>
- </cuckoo> => true;
- case _ => false; });
-*/
- /*
- // begin tmp
- assertEquals( false, cuckoo match {
- case <cuckoo>
- <foo/>
- <bar/>
- </cuckoo> => 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( <foo><bar/><baz/><baz/></foo> ), 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( <foo><bar/><baz/><baz/></foo> ), true );
- assertEquals( vtor( <foo>ab<bar/>cd<baz/>ed<baz/>gh</foo> ), true );
- assertEquals( vtor( <foo> <ugha/> <bugha/> </foo> ), false );
-
- Console.println("validation - attributes");
- vtor.setContentModel(null);
- vtor.setMetaData(List());
- assertEquals( vtor( <foo bar="hello"/> ), false );
-
- {
- import scala.xml.dtd._ ;
- vtor.setMetaData(List(AttrDecl("bar","CDATA",IMPLIED)));
- }
- assertEquals( vtor( <foo href="http://foo.com" bar="hello"/> ), false );
- assertEquals( vtor( <foo bar="hello"/> ), true );
-
- {
- import scala.xml.dtd._ ;
- vtor.setMetaData(List(AttrDecl("bar","CDATA",REQUIRED)));
- }
- assertEquals( vtor( <foo href="http://foo.com" /> ), false );
- assertEquals( vtor( <foo bar="http://foo.com" /> ), true );
-
- }
-}