pattern matching for tuple and expression patterns

This commit is contained in:
Dmitry Jemerov
2011-07-06 15:24:34 +02:00
parent 3fe728dff6
commit 0c85c53c64
2 changed files with 54 additions and 0 deletions
@@ -1,6 +1,7 @@
package org.jetbrains.jet.codegen;
import jet.NoPatternMatchedException;
import jet.Tuple2;
import java.lang.reflect.Method;
@@ -61,4 +62,11 @@ public class PatternMatchingTest extends CodegenTestCase {
Method foo = generateFunction();
assertEquals("x", foo.invoke(null, ""));
}
public void testTuplePattern() throws Exception {
loadText("fun foo(x: Tuple2<Any, Any>) = when(x) { is (1,2) => \"one,two\"; else => \"something\" }");
Method foo = generateFunction();
assertEquals("one,two", foo.invoke(null, new Tuple2<Integer, Integer>(1, 2)));
assertEquals("something", foo.invoke(null, new Tuple2<String, String>("not", "tuple")));
}
}