summaryrefslogtreecommitdiff
path: root/test/files/run/exceptions.scala
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2003-08-12 14:00:07 +0000
committermichelou <michelou@epfl.ch>2003-08-12 14:00:07 +0000
commita3654375f6c94bc8eae10a6f7ead6a8bd66ef4fd (patch)
treedf6b083141564bbfc0c419a22d7eab1ba209ffcc /test/files/run/exceptions.scala
parent9d675361a36be28c25797fc2a0b4f2e1c44a366c (diff)
downloadscala-a3654375f6c94bc8eae10a6f7ead6a8bd66ef4fd.tar.gz
scala-a3654375f6c94bc8eae10a6f7ead6a8bd66ef4fd.tar.bz2
scala-a3654375f6c94bc8eae10a6f7ead6a8bd66ef4fd.zip
replaces test file mics1.scala
Diffstat (limited to 'test/files/run/exceptions.scala')
-rw-r--r--test/files/run/exceptions.scala53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/files/run/exceptions.scala b/test/files/run/exceptions.scala
new file mode 100644
index 0000000000..b89056aa78
--- /dev/null
+++ b/test/files/run/exceptions.scala
@@ -0,0 +1,53 @@
+//############################################################################
+// Exceptions
+//############################################################################
+// $Id$
+
+//############################################################################
+
+abstract class IntMap[A] {
+ def lookup(key: Int): A = match {
+ case Empty() => error("KO")
+ case _ => error("ok")
+ }
+}
+
+case class Empty[A]() extends IntMap[A];
+
+object exceptions {
+
+ def check(what: String, actual: Any, expected: Any): Unit = {
+ val success: Boolean = actual == expected;
+ System.out.print(if (success) "ok" else "KO");
+ var value: String = if (actual == null) "null" else actual.toString();
+ if (value == "\u0000") value = "\\u0000";
+ System.out.print(": " + what + " = " + value);
+ if (!success) System.out.print(" != " + expected);
+ System.out.println();
+ System.out.flush();
+ }
+
+ def test: Unit = {
+ val key = 2000;
+ val map: IntMap[String] = new Empty[String];
+ val value = try {
+ map.lookup(key)
+ } catch {
+ case e => e.getMessage()
+ }
+ check("lookup(" + key + ")", value, "KO");
+ }
+
+}
+
+//############################################################################
+
+object Test {
+
+ def main(args: Array[String]): Unit = {
+ exceptions.test;
+ }
+
+}
+
+//############################################################################