summaryrefslogtreecommitdiff
path: root/test/files/run/overloads.scala
diff options
context:
space:
mode:
authorGilles Dubochet <gilles.dubochet@epfl.ch>2005-12-16 18:29:42 +0000
committerGilles Dubochet <gilles.dubochet@epfl.ch>2005-12-16 18:29:42 +0000
commitdf50e05006b43b007c2587549030d24b5c154398 (patch)
tree9edfb1fb5b8c04350a00c163cfcdb1fccd79e3aa /test/files/run/overloads.scala
parent17e2b1c2a6f69ba74e79c30d1e44195fe732e3e3 (diff)
downloadscala-df50e05006b43b007c2587549030d24b5c154398.tar.gz
scala-df50e05006b43b007c2587549030d24b5c154398.tar.bz2
scala-df50e05006b43b007c2587549030d24b5c154398.zip
'test-nsc' has been moved to 'test'.
Diffstat (limited to 'test/files/run/overloads.scala')
-rw-r--r--test/files/run/overloads.scala96
1 files changed, 96 insertions, 0 deletions
diff --git a/test/files/run/overloads.scala b/test/files/run/overloads.scala
new file mode 100644
index 0000000000..31664b2ea6
--- /dev/null
+++ b/test/files/run/overloads.scala
@@ -0,0 +1,96 @@
+//############################################################################
+// Overloads
+//############################################################################
+// $Id$
+
+//############################################################################
+
+object Ops {
+ def - = 0;
+ def -(c: Char) = c;
+ def -(i: Int) = i;
+
+ def -- = 0;
+ def --(c: Char) = c;
+ def --(i: Int) = i;
+}
+
+object Funcs {
+ def foo = 0;
+// def foo() = 1;
+ def foo(c: Char) = 2;
+ def foo(i: Int) = 3;
+}
+
+object M1 {
+ def f[A](x: A) = 11;
+ def f[A <: Ordered[A]](x: A) = 12;
+}
+
+object M2 {
+ def f[A <: Ordered[A]](x: A) = 21;
+ def f[A](x: A) = 22;
+}
+
+object overloads {
+
+ def check(what: String, actual: Any, expected: Any): Unit = {
+ val success: Boolean = actual == expected;
+ Console.print(if (success) "ok" else "KO");
+ var value: String = if (actual == null) "null" else actual.toString();
+ if (value == "\u0000") value = "\\u0000";
+ Console.print(": " + what + " = " + value);
+ if (!success) Console.print(" != " + expected);
+ Console.println;
+ Console.flush;
+ }
+
+ def - = 0;
+ def -(c: Char) = c;
+ def -(i: Int) = i;
+
+ def -- = 0;
+ def --(c: Char) = c;
+ def --(i: Int) = i;
+
+ def test: Unit = {
+ check("-('a')", -('a'), -97);
+ check("-(97)", -(97), -97);
+
+ check("Ops.-('a')", Ops.-('a'), 'a');
+ check("Ops.-(97)", Ops.-(97), 97);
+
+ check("--", --, 0);
+ check("--('a')", --('a'), 'a');
+ check("--(97)", --(97), 97);
+
+ check("Ops.--", Ops.--, 0);
+ check("Ops.--('a')", Ops.--('a'), 'a');
+ check("Ops.--(97)", Ops.--(97), 97);
+
+ check("Funcs.foo", Funcs.foo, 0);
+// check("Funcs.foo()", Funcs.foo(), 1);
+ check("Funcs.foo('a')", Funcs.foo('a'), 2);
+ check("Funcs.foo(97)", Funcs.foo(97), 3);
+
+ val x = 3;
+ check("M1.f(" + x +")", M1.f(x), 11);
+ check("M2.f(" + x +")", M2.f(x), 22);
+// val y = new scala.collection.mutable.Stack[Int];
+// check("M1.f(" + y +")", M1.f(y), 12);
+// check("M2.f(" + y +")", M2.f(y), 21);
+ }
+
+}
+
+//############################################################################
+
+object Test {
+
+ def main(args: Array[String]): Unit = {
+ overloads.test;
+ }
+
+}
+
+//############################################################################