summaryrefslogtreecommitdiff
path: root/test/files/pos
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2007-01-24 15:20:25 +0000
committerBurak Emir <emir@epfl.ch>2007-01-24 15:20:25 +0000
commit0ef0f40ae31bf8a1e3d5b9c6eea7ef5b5a073192 (patch)
tree0bb95122566e05dcc1f81322f3a3740d2e1a81cd /test/files/pos
parent1cbef2171c91fd0e001b4d0c1570c07017877044 (diff)
downloadscala-0ef0f40ae31bf8a1e3d5b9c6eea7ef5b5a073192.tar.gz
scala-0ef0f40ae31bf8a1e3d5b9c6eea7ef5b5a073192.tar.bz2
scala-0ef0f40ae31bf8a1e3d5b9c6eea7ef5b5a073192.zip
moved working tests to files
Diffstat (limited to 'test/files/pos')
-rw-r--r--test/files/pos/bug402.scala7
-rw-r--r--test/files/pos/bug419.scala11
-rw-r--r--test/files/pos/bug430.scala20
-rw-r--r--test/files/pos/bug443.scala14
-rw-r--r--test/files/pos/bug796.scala26
-rw-r--r--test/files/pos/gosh.scala44
-rw-r--r--test/files/pos/init.scala14
-rw-r--r--test/files/pos/unapplyComplex.scala37
-rw-r--r--test/files/pos/unapplyContexts2.scala11
-rw-r--r--test/files/pos/unapplyGeneric.scala11
-rw-r--r--test/files/pos/unapplyNeedsMemberType.scala25
-rw-r--r--test/files/pos/unapplySeq.scala26
12 files changed, 246 insertions, 0 deletions
diff --git a/test/files/pos/bug402.scala b/test/files/pos/bug402.scala
new file mode 100644
index 0000000000..a5a3df4825
--- /dev/null
+++ b/test/files/pos/bug402.scala
@@ -0,0 +1,7 @@
+object Main {
+ def main(args: Array[String]): Unit = {
+ val x: Any = 2
+ System.out.println((0.5).isInstanceOf[Int]);
+ System.out.println(x.isInstanceOf[Int]);
+ }
+}
diff --git a/test/files/pos/bug419.scala b/test/files/pos/bug419.scala
new file mode 100644
index 0000000000..65dcb04356
--- /dev/null
+++ b/test/files/pos/bug419.scala
@@ -0,0 +1,11 @@
+trait Bar {
+ class Config {}
+ var config: Config; // aha, traits can have variables?
+}
+
+object Foo extends Bar {
+
+ class FooConfig extends Config;
+ var config: Config = new FooConfig() // or not
+
+}
diff --git a/test/files/pos/bug430.scala b/test/files/pos/bug430.scala
new file mode 100644
index 0000000000..7e3e7eaaec
--- /dev/null
+++ b/test/files/pos/bug430.scala
@@ -0,0 +1,20 @@
+object Test extends Application {
+ def foo[T <% Ordered[T]](x: T): Unit = System.out.println(""+(x < x)+" "+(x <= x))
+ def bar(x: Unit ): Unit = foo(x);
+ def bar(x: Boolean): Unit = foo(x);
+ def bar(x: Byte ): Unit = foo(x);
+ def bar(x: Short ): Unit = foo(x);
+ def bar(x: Int ): Unit = foo(x);
+ def bar(x: Long ): Unit = foo(x);
+ def bar(x: Float ): Unit = foo(x);
+ def bar(x: Double ): Unit = foo(x);
+ bar(())
+ bar(true)
+ bar(1: byte)
+ bar(1: short)
+ bar('a')
+ bar(1)
+ bar(1l)
+ bar(1.0f)
+ bar(1.0)
+}
diff --git a/test/files/pos/bug443.scala b/test/files/pos/bug443.scala
new file mode 100644
index 0000000000..5b83e9d2cb
--- /dev/null
+++ b/test/files/pos/bug443.scala
@@ -0,0 +1,14 @@
+object Test {
+
+ def lookup(): Option[Pair[String, String]] =
+ (null: Option[Pair[String, String]]) match {
+ case Some(Pair(_, _)) =>
+ if (true)
+ Some(Pair(null, null))
+ else
+ lookup() match {
+ case Some(_) => Some(null)
+ case None => None
+ }
+ }
+}
diff --git a/test/files/pos/bug796.scala b/test/files/pos/bug796.scala
new file mode 100644
index 0000000000..756c103e7c
--- /dev/null
+++ b/test/files/pos/bug796.scala
@@ -0,0 +1,26 @@
+/** I know what I am doing is wrong -- since I am about to look into
+ * this bug, I add a test in pending/pos... however, I am afraid that
+ * once this bug is fixed, this test case might go into test/pos
+ * there it adds to the huge number of tiny little test cases.
+ *
+ * Ideally, an option in the bugtracking system would automatically
+ * handle "pos" bugs.
+ */
+object Test extends Application {
+
+ object Twice {
+ def apply(x: int) = x * 2
+ def unapply(x: int): Option[Tuple1[int]] =
+ if (x % 2 == 0) Some(Tuple1(x / 2))
+ else None
+ }
+
+ def test(x: int) = x match {
+ case Twice(y) => "x is two times "+y
+ case _ => "x is odd"
+ }
+
+ Console.println(test(3))
+ Console.println(test(4))
+
+}
diff --git a/test/files/pos/gosh.scala b/test/files/pos/gosh.scala
new file mode 100644
index 0000000000..c4cd3df80b
--- /dev/null
+++ b/test/files/pos/gosh.scala
@@ -0,0 +1,44 @@
+object ShapeTest extends Application {
+
+ class Point(x : int, y : int) {
+ override def toString() = "[" + x + "," + y + "]"
+ }
+
+ abstract class Shape {
+ def draw() : unit
+ }
+
+ class Line(s : Point, e : Point) extends Shape {
+ def draw() : unit = { Console.println("draw line " + s + "," + e) }
+ }
+
+ abstract class Foo {
+ type T <: Object
+
+ def show(o : T) : unit
+ def print() : unit = {Console.println("in Foo")}
+ }
+
+ abstract class ShapeFoo extends Foo {
+ type T <: Shape
+ def show(o : T) : unit = { o.draw() }
+ override def print() : unit = {Console.println("in ShapeFoo")}
+ }
+
+ class LineFoo extends ShapeFoo {
+ type T = Line
+ override def print() : unit = {Console.println("in LineFoo")}
+ }
+
+ val p1 = new Point(1,4)
+ val p2 = new Point(12, 28)
+
+ val l1 = new Line(p1, p2)
+
+
+ val l = new ShapeFoo{ // ** //
+ type T = Line // ** //
+ override def print() : unit = {Console.println("in LineFoo")} // ** //
+ }
+ l.show(l1) // ** //
+}
diff --git a/test/files/pos/init.scala b/test/files/pos/init.scala
new file mode 100644
index 0000000000..c51446c804
--- /dev/null
+++ b/test/files/pos/init.scala
@@ -0,0 +1,14 @@
+class Foo {
+
+ var cnt = 0
+
+ class Bar {
+ cnt = cnt + 1
+ val id = cnt
+ }
+}
+
+object Test extends Application {
+ val foo = new Foo
+ Console.println((new foo.Bar).id)
+}
diff --git a/test/files/pos/unapplyComplex.scala b/test/files/pos/unapplyComplex.scala
new file mode 100644
index 0000000000..54080eb86f
--- /dev/null
+++ b/test/files/pos/unapplyComplex.scala
@@ -0,0 +1,37 @@
+trait Complex extends Product2[double,double]
+
+class ComplexRect(val _1:double, val _2:double) extends Complex {
+ override def toString = "ComplexRect("+_1+","+_2+")"
+}
+
+class ComplexPolar(val _1:double, val _2:double) extends Complex {
+ override def toString = "ComplexPolar("+_1+","+_2+")"
+}
+
+object ComplexRect {
+ def unapply(z:Complex): Option[Complex] = {
+ if(z.isInstanceOf[ComplexRect]) Some(z) else z match {
+ case ComplexPolar(mod, arg) =>
+ Some(new ComplexRect(mod*Math.cos(arg), mod*Math.sin(arg)))
+} } }
+
+object ComplexPolar {
+ def unapply(z:Complex): Option[Complex] = {
+ if(z.isInstanceOf[ComplexPolar]) Some(z) else z match {
+ case ComplexRect(re,im) =>
+ Some(new ComplexPolar(Math.sqrt(re*re + im*im), Math.atan(re/im)))
+} } }
+
+object Test {
+ def main(args:Array[String]) = {
+ new ComplexRect(1,1) match {
+ case ComplexPolar(mod,arg) => // z @ ???
+ Console.println("mod"+mod+"arg"+arg)
+ }
+ val Komplex = ComplexRect
+ new ComplexPolar(Math.sqrt(2),Math.Pi / 4.0) match {
+ case Komplex(re,im) => // z @ ???
+ Console.println("re"+re+" im"+im)
+ }
+ }
+}
diff --git a/test/files/pos/unapplyContexts2.scala b/test/files/pos/unapplyContexts2.scala
new file mode 100644
index 0000000000..fcf1e2ff62
--- /dev/null
+++ b/test/files/pos/unapplyContexts2.scala
@@ -0,0 +1,11 @@
+trait Analyzer {
+ val WILDCARD = "23"
+}
+
+trait Contexts2 requires Analyzer {
+ class Context {
+ def collect(sels: List[String]): List[String] = sels match {
+ case List(WILDCARD) => val dummy = WILDCARD; Nil
+ }
+ }
+}
diff --git a/test/files/pos/unapplyGeneric.scala b/test/files/pos/unapplyGeneric.scala
new file mode 100644
index 0000000000..bf88816885
--- /dev/null
+++ b/test/files/pos/unapplyGeneric.scala
@@ -0,0 +1,11 @@
+object Bar {
+ def unapply[A,B](bar:Bar[A,B]) = Some(bar)
+}
+
+class Bar[A,B](val _1:A, val _2:B) extends Product2[A,B]
+
+object Test {
+ new Bar(2, 'a') match {
+ case Bar(x,y) =>
+ }
+}
diff --git a/test/files/pos/unapplyNeedsMemberType.scala b/test/files/pos/unapplyNeedsMemberType.scala
new file mode 100644
index 0000000000..b423257e04
--- /dev/null
+++ b/test/files/pos/unapplyNeedsMemberType.scala
@@ -0,0 +1,25 @@
+// error with -Xunapply, (because of missing call to memberType?)
+
+trait Gunk[a] {
+
+ type Seq
+
+ object Cons {
+ def unapply(s: Seq) = unapply_Cons(s)
+ }
+ def unapply_Cons(s: Any): Option[Tuple2[a, Seq]]
+}
+
+class Join[a] extends Gunk[a] {
+ type Seq = JoinSeq
+
+ abstract class JoinSeq
+ case class App(xs: Seq, ys: Seq) extends JoinSeq
+
+ def append(s1: Seq, s2: Seq): Seq = s1 // mock implementation
+
+ def unapply_Cons(s: Any) = s match {
+ case App(Cons(x, xs), ys) => Some(Pair(x, append(xs, ys)))
+ case _ => null
+ }
+}
diff --git a/test/files/pos/unapplySeq.scala b/test/files/pos/unapplySeq.scala
new file mode 100644
index 0000000000..aac211de5a
--- /dev/null
+++ b/test/files/pos/unapplySeq.scala
@@ -0,0 +1,26 @@
+object FooSeq {
+ def unapplySeq(x:Any): Option[Product2[Int,Seq[String]]] = {
+ if(x.isInstanceOf[Bar]) {
+ val y = x.asInstanceOf[Bar]
+ Some({y.size, y.name})
+ } else None
+ }
+
+ def main(args:Array[String]) = {
+ val b = new Bar
+ b match {
+ case FooSeq(s:Int,_,n:String) => Console.println("size "+s+" name "+n)
+ }
+ b.size = 54
+ b.name = List("large","L")
+ b match {
+ case FooSeq(s:Int,_,n:String) => Console.println("size "+s+" name "+n)
+ }
+ }
+}
+
+class Bar {
+ var size: Int = 50
+ var name: Seq[String] = List("medium","M")
+}
+