summaryrefslogtreecommitdiff
path: root/test/files/jvm
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-05-19 13:39:55 +0000
committerburaq <buraq@epfl.ch>2004-05-19 13:39:55 +0000
commit2aab9b99cd911bcb59578aa3954eb49b00c2d6b8 (patch)
tree321bb7f42948946c36162ba5160719fbacc1ca46 /test/files/jvm
parentb6187294972b2ef43a34dd39448d3f3d0768e931 (diff)
downloadscala-2aab9b99cd911bcb59578aa3954eb49b00c2d6b8.tar.gz
scala-2aab9b99cd911bcb59578aa3954eb49b00c2d6b8.tar.bz2
scala-2aab9b99cd911bcb59578aa3954eb49b00c2d6b8.zip
test cases for matching
Diffstat (limited to 'test/files/jvm')
-rw-r--r--test/files/jvm/matching.check4
-rw-r--r--test/files/jvm/matching.scala71
2 files changed, 75 insertions, 0 deletions
diff --git a/test/files/jvm/matching.check b/test/files/jvm/matching.check
new file mode 100644
index 0000000000..5a60ffb236
--- /dev/null
+++ b/test/files/jvm/matching.check
@@ -0,0 +1,4 @@
+<<< bug Test1
+0
+>>> bug Test1
+
diff --git a/test/files/jvm/matching.scala b/test/files/jvm/matching.scala
new file mode 100644
index 0000000000..f991a384dd
--- /dev/null
+++ b/test/files/jvm/matching.scala
@@ -0,0 +1,71 @@
+//############################################################################
+// Run Time Bugs & Test Cases
+//############################################################################
+// $Id$
+
+import java.lang.System; // to avoid name clash with .NET's library
+
+//############################################################################
+// Test 1 - Runtime Matching creation
+
+object Test1Test {
+ import scala.collection.{immutable,Set} ;
+ import scala.runtime.matching._ ;
+ case class Foo(i:Int,c:Char,d:List[Foo]) ;
+
+ val t2 = TreeNT(2);
+ val tr1 = AnyTreeRule( ANYTREE );
+ val tr2 = TreeRule( t2, 1, ANYHEDGE );
+ val h1 = new HedgeNT(1, true);
+ val hr1 = HedgeRule( ANYHEDGE, ANYTREE, ANYHEDGE );
+ val treeTrans =
+ new immutable.TreeMap[Int,Set[TRule]]()
+ .update( 1, immutable.ListSet.Empty[TRule] + tr1 )
+ .update( 2, immutable.ListSet.Empty[TRule] + tr2 );
+ val hedgeTrans = new immutable.TreeMap[Int,Set[HRule]]()
+ .update( 1, immutable.ListSet.Empty[HRule] + hr1 );
+
+ val gram = new Grammar( treeTrans, hedgeTrans, null ) { val
+ treeInitials = immutable.ListSet.Empty[TreeNT] + t2; val
+ hedgeInitials = immutable.ListSet.Empty[HedgeNT]; def test( i:Int,
+ inp:Any ) = { if( i==1 ) inp.isInstanceOf[List[Int]] else false; } }
+
+ def main(args:Array[String]): Unit =
+ Console.println( new Matcher(gram).matches( List(1,2,3) ));
+}
+
+//############################################################################
+// Main
+
+object Test {
+ var errors: Int = 0;
+ def test(bug: String, def test: Unit): Unit = {
+ System.out.println("<<< bug " + bug);
+ try {
+ test;
+ } catch {
+ case exception => {
+ val name: String = Thread.currentThread().getName();
+ System.out.print("Exception in thread \"" + name + "\" ");
+ exception.printStackTrace();
+ System.out.println();
+ errors = errors + 1;
+ }
+ }
+ System.out.println(">>> bug " + bug);
+ System.out.println();
+ }
+
+ def main(args: Array[String]): Unit = {
+
+ test("Test1" , Test1Test.main(args));
+
+ if (errors > 0) {
+ System.out.println();
+ System.out.println(errors + " error" + (if (errors > 1) "s" else ""));
+ }
+
+ }
+}
+
+//############################################################################