summaryrefslogtreecommitdiff
path: root/test/files
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2007-01-03 15:56:13 +0000
committerMartin Odersky <odersky@gmail.com>2007-01-03 15:56:13 +0000
commita961d3dcd6f93ee006cff1d386052bf62326739a (patch)
tree5af3312932236340708522dfd078f32beed20519 /test/files
parent02a45e20bb6f68808708dca377bc72ccaf5bba3d (diff)
downloadscala-a961d3dcd6f93ee006cff1d386052bf62326739a.tar.gz
scala-a961d3dcd6f93ee006cff1d386052bf62326739a.tar.bz2
scala-a961d3dcd6f93ee006cff1d386052bf62326739a.zip
1.
Diffstat (limited to 'test/files')
-rw-r--r--test/files/jvm/xml01.scala2
-rw-r--r--test/files/neg/bug846.check6
-rwxr-xr-xtest/files/neg/bug846.scala13
-rwxr-xr-xtest/files/pos/bounds.scala11
-rwxr-xr-xtest/files/pos/nested2.scala9
-rw-r--r--test/files/run/Course-2002-10.scala18
-rw-r--r--test/files/run/collections.check28
-rwxr-xr-xtest/files/run/collections.scala100
-rw-r--r--test/files/run/infix.check2
-rwxr-xr-xtest/files/run/infix.scala12
-rw-r--r--test/files/run/tuples.check2
-rwxr-xr-xtest/files/run/tuples.scala8
12 files changed, 201 insertions, 10 deletions
diff --git a/test/files/jvm/xml01.scala b/test/files/jvm/xml01.scala
index 8c99cfd358..b0a3044fc1 100644
--- a/test/files/jvm/xml01.scala
+++ b/test/files/jvm/xml01.scala
@@ -177,7 +177,7 @@ object Test {
//Text("John Mitchell"),
Elem(null,"title",e,sc,Text("Foundations of Programming Languages"))
//Text("Foundations of Programming Languages")
- )
+ ): Seq[Node]
);
// test group node
diff --git a/test/files/neg/bug846.check b/test/files/neg/bug846.check
new file mode 100644
index 0000000000..b60b4c7125
--- /dev/null
+++ b/test/files/neg/bug846.check
@@ -0,0 +1,6 @@
+bug846.scala:9 error: type mismatch;
+ found : scala.Null(null)
+ required: B
+ if (a != null) f(a) else null
+ ^
+one error found
diff --git a/test/files/neg/bug846.scala b/test/files/neg/bug846.scala
new file mode 100755
index 0000000000..be105a71aa
--- /dev/null
+++ b/test/files/neg/bug846.scala
@@ -0,0 +1,13 @@
+package test;
+trait Test {
+ type Bar;
+ trait FooImpl;
+ trait Bob {
+ def bar : Bar with FooImpl;
+ }
+ def ifn[A,B](a : A)(f : A => B): B =
+ if (a != null) f(a) else null
+ val bob : Bob = null;
+ val bar = ifn(bob)(.bar);
+ assert(bar == null);
+}
diff --git a/test/files/pos/bounds.scala b/test/files/pos/bounds.scala
new file mode 100755
index 0000000000..5bc5cf89dc
--- /dev/null
+++ b/test/files/pos/bounds.scala
@@ -0,0 +1,11 @@
+trait Map[A, +C] {
+ def ++ [B1 >: C] (kvs: Iterable[Pair[A, B1]]): Map[A, B1] = this
+ def ++ [B1 >: C] (kvs: Iterator[Pair[A, B1]]): Map[A, B1] = this
+}
+
+class ListMap[A, +B] extends Map[A, B] {}
+
+object ListMap {
+ def empty[X, Y] = new ListMap[X, Y]
+ def apply[A1, B2](elems: Pair[A1, B2]*): Map[A1, B2] = empty[A1,B2].++(elems.elements)
+}
diff --git a/test/files/pos/nested2.scala b/test/files/pos/nested2.scala
new file mode 100755
index 0000000000..302688a0ef
--- /dev/null
+++ b/test/files/pos/nested2.scala
@@ -0,0 +1,9 @@
+class C[A] {
+ class D[B] {
+ }
+}
+
+object Test {
+ val x = new C[String]
+ val y: C[String]#D[int] = new x.D[int]
+}
diff --git a/test/files/run/Course-2002-10.scala b/test/files/run/Course-2002-10.scala
index 258b6dc8fd..79c760afee 100644
--- a/test/files/run/Course-2002-10.scala
+++ b/test/files/run/Course-2002-10.scala
@@ -31,9 +31,9 @@ object M1 {
Stream.cons(s.head, partialSums(s.tail) map (x => x + s.head));
def euler(s: Stream[double]): Stream[double] = {
- val nm1 = s at 0;
- val n = s at 1;
- val np1 = s at 2;
+ val nm1 = s apply 0;
+ val n = s apply 1;
+ val np1 = s apply 2;
Stream.cons(np1 - ((np1 - n)*(np1 - n) / (nm1 - 2*n + np1)),euler(s.tail))
};
@@ -68,9 +68,9 @@ object M1 {
var i = 0;
while (i < 10) {
Console.print("pi("+i+") = ");
- Console.print(str(pi0.at(i)) + ", ");
- Console.print(str(pi1.at(i)) + ", ");
- Console.print(str(pi2.at(i)) + "\n");
+ Console.print(str(pi0.apply(i)) + ", ");
+ Console.print(str(pi1.apply(i)) + ", ");
+ Console.print(str(pi2.apply(i)) + "\n");
i = i + 1;
}
Console.print("pi = ");
@@ -81,9 +81,9 @@ object M1 {
i = 0;
while (i < 10) {
Console.print("ln("+i+") = ");
- Console.print(str(ln0.at(i)) + ", ");
- Console.print(str(ln1.at(i)) + ", ");
- Console.print(str(ln2.at(i)) + "\n");
+ Console.print(str(ln0.apply(i)) + ", ");
+ Console.print(str(ln1.apply(i)) + ", ");
+ Console.print(str(ln2.apply(i)) + "\n");
i = i + 1;
}
Console.print("ln = ");
diff --git a/test/files/run/collections.check b/test/files/run/collections.check
new file mode 100644
index 0000000000..ad92767fa6
--- /dev/null
+++ b/test/files/run/collections.check
@@ -0,0 +1,28 @@
+***** immutable.ListSet:
+test1: 14005
+test2: 25005003
+test3: 25005003
+***** immutable.TreeSet:
+test1: 14005
+test2: 25005003
+test3: 25005003
+***** mutable.HashSet:
+test1: 14005
+test2: 25005003
+test3: 25005003
+***** immutable.ListMap:
+test1: 14005
+test2: 1013003
+test3: 1013003
+***** immutable.TreeMap:
+test1: 14005
+test2: 1013003
+test3: 1013003
+***** immutable.UnBalancedTreeMap:
+test1: 14005
+test2: 1013003
+test3: 1013003
+***** mutable.HashMap:
+test1: 14005
+test2: 25005003
+test3: 25005003
diff --git a/test/files/run/collections.scala b/test/files/run/collections.scala
new file mode 100755
index 0000000000..5e97b2df38
--- /dev/null
+++ b/test/files/run/collections.scala
@@ -0,0 +1,100 @@
+import collection._
+
+object Test extends Application {
+
+ val printTime = false
+
+ def sum[A](xs: Iterable[int]) = (0 /: xs)((x, y) => x + y)
+
+ def time(op: => unit): unit = {
+ val start = System.currentTimeMillis;
+ op
+ if (printTime) Console.println(" time = "+(System.currentTimeMillis - start)+"ms")
+ }
+
+ def test(msg: String, s0: collection.immutable.Set[int]) = {
+ Console.println("***** "+msg+":")
+ var s = s0
+ s = s + 2
+ s = s + (3, 4000, 10000)
+ Console.println("test1: "+sum(s))
+ time {
+ s = s ++ (List.range(0, 5000) map (2*))
+ Console.println("test2: "+sum(s))
+ }
+ time {
+ var x = 0
+ for (val i <- (0 to 10000))
+ if (s contains i) x = x + i
+ Console.println("test3: "+x)
+ }
+ }
+
+ def test(msg: String, s0: collection.mutable.Set[int]) = {
+ Console.println("***** "+msg+":")
+ var s = s0
+ s = s + 2
+ s = s + (3, 4000, 10000)
+ Console.println("test1: "+sum(s))
+ time {
+ s = s ++ (List.range(0, 5000) map (2*))
+ Console.println("test2: "+sum(s))
+ }
+ time {
+ var x = 0
+ for (val i <- (0 to 10000))
+ if (s contains i) x = x + i
+ Console.println("test3: "+x)
+ }
+ }
+
+ def test(msg: String, s0: collection.immutable.Map[int, int]) = {
+ Console.println("***** "+msg+":")
+ var s = s0
+ s = s + (2 -> 2)
+ s = s + (3 -> 3, 4000 -> 4000, 10000 -> 10000)
+ Console.println("test1: "+sum(s map (._2)))
+ time {
+ s = s ++ (List.range(0, 1000) map (x => x * 2 -> x * 2))
+ Console.println("test2: "+sum(s map (._2)))
+ }
+ time {
+ var x = 0
+ for (val i <- (0 to 10000))
+ s get i match {
+ case Some(i) => x = x + i
+ case None =>
+ }
+ Console.println("test3: "+x)
+ }
+ }
+
+ def test(msg: String, s0: collection.mutable.Map[int, int]) = {
+ Console.println("***** "+msg+":")
+ var s = s0
+ s = s + (2 -> 2)
+ s = s + (3 -> 3, 4000 -> 4000, 10000 -> 10000)
+ Console.println("test1: "+sum(s map (._2)))
+ time {
+ s = s ++ (List.range(0, 5000) map (x => x * 2 -> x * 2))
+ Console.println("test2: "+sum(s map (._2)))
+ }
+ time {
+ var x = 0
+ for (val i <- (0 to 10000))
+ s get i match {
+ case Some(i) => x = x + i
+ case None =>
+ }
+ Console.println("test3: "+x)
+ }
+ }
+
+ test("immutable.ListSet", new immutable.ListSet[int])
+ test("immutable.TreeSet", new immutable.TreeSet[int])
+ test("mutable.HashSet", new mutable.HashSet[int])
+ test("immutable.ListMap", new immutable.ListMap[int, int])
+ test("immutable.TreeMap", new immutable.TreeMap[int, int])
+ test("immutable.UnBalancedTreeMap", new immutable.UnbalancedTreeMap[int, int])
+ test("mutable.HashMap", new mutable.HashMap[int, int])
+}
diff --git a/test/files/run/infix.check b/test/files/run/infix.check
new file mode 100644
index 0000000000..dd0457b776
--- /dev/null
+++ b/test/files/run/infix.check
@@ -0,0 +1,2 @@
+op(op(op(null,0,0),1,1),2,2)
+OK
diff --git a/test/files/run/infix.scala b/test/files/run/infix.scala
new file mode 100755
index 0000000000..9df07ac317
--- /dev/null
+++ b/test/files/run/infix.scala
@@ -0,0 +1,12 @@
+case class op(x: op, y: int, z: int) {
+ def op(y: int, z: int) = new op(this, y, z)
+}
+
+object Test extends Application {
+ val xs = new op(null, 0, 0) op (1, 1) op (2, 2)
+ Console.println(xs)
+ xs match {
+ case null op (0, 0) op (1, 1) op (2, 2) => Console.println("OK")
+ }
+}
+
diff --git a/test/files/run/tuples.check b/test/files/run/tuples.check
new file mode 100644
index 0000000000..731f2746c9
--- /dev/null
+++ b/test/files/run/tuples.check
@@ -0,0 +1,2 @@
+{1,abc,true}
+OK
diff --git a/test/files/run/tuples.scala b/test/files/run/tuples.scala
new file mode 100755
index 0000000000..c6dcda4af8
--- /dev/null
+++ b/test/files/run/tuples.scala
@@ -0,0 +1,8 @@
+object Test extends Application {
+ var xyz: {int, String, boolean} = _
+ xyz = { 1, "abc", true }
+ Console.println(xyz)
+ xyz match {
+ case { 1, "abc", true } => Console.println("OK")
+ }
+}