aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-05-17 14:54:53 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-05-17 14:54:53 +0200
commitfdf5354eef3d2a75458cf646c00616ca39a4e56b (patch)
tree467c565f4c2dd4d63559e3c898a384afc6a02936 /test
parenteaf2520b63fcc9fe65cf02d88c96849c4caf8177 (diff)
downloaddotty-fdf5354eef3d2a75458cf646c00616ca39a4e56b.tar.gz
dotty-fdf5354eef3d2a75458cf646c00616ca39a4e56b.tar.bz2
dotty-fdf5354eef3d2a75458cf646c00616ca39a4e56b.zip
Add switch verification test
Diffstat (limited to 'test')
-rw-r--r--test/test/DottyBytecodeTest.scala16
-rw-r--r--test/test/DottyBytecodeTests.scala48
2 files changed, 62 insertions, 2 deletions
diff --git a/test/test/DottyBytecodeTest.scala b/test/test/DottyBytecodeTest.scala
index 6b39116f8..3814b03bd 100644
--- a/test/test/DottyBytecodeTest.scala
+++ b/test/test/DottyBytecodeTest.scala
@@ -94,6 +94,22 @@ trait DottyBytecodeTest extends DottyTest {
}
/**************************** Comparison Methods ****************************/
+ def verifySwitch(method: MethodNode, shouldFail: Boolean = false, debug: Boolean = false): Boolean = {
+ val instructions = instructionsFromMethod(method)
+
+ val succ = instructions
+ .collect {
+ case x: TableSwitch => x
+ case x: LookupSwitch => x
+ }
+ .length > 0
+
+ if (debug || !succ && !shouldFail || succ && shouldFail)
+ instructions.foreach(Console.err.println)
+
+ succ
+ }
+
def sameBytecode(methA: MethodNode, methB: MethodNode) = {
val isa = instructionsFromMethod(methA)
val isb = instructionsFromMethod(methB)
diff --git a/test/test/DottyBytecodeTests.scala b/test/test/DottyBytecodeTests.scala
index 3b8308b0a..6b1562741 100644
--- a/test/test/DottyBytecodeTests.scala
+++ b/test/test/DottyBytecodeTests.scala
@@ -4,6 +4,7 @@ import org.junit.Assert._
import org.junit.Test
class TestBCode extends DottyBytecodeTest {
+ import ASMConverters._
@Test def nullChecks = {
val source = """
|class Foo {
@@ -15,11 +16,54 @@ class TestBCode extends DottyBytecodeTest {
|}
""".stripMargin
- checkBCode(source) { file =>
- val clsIn = file.lookupName("Foo.class", directory = false).input
+ checkBCode(source) { dir =>
+ val clsIn = dir.lookupName("Foo.class", directory = false).input
val clsNode = loadClassNode(clsIn)
val methodNode = getMethod(clsNode, "foo")
correctNumberOfNullChecks(2, methodNode.instructions)
}
}
+
+ /** This test verifies that simple matches are transformed if possible
+ * despite no annotation
+ */
+ @Test def basicTransformNonAnnotated = {
+ val source = """
+ |object Foo {
+ | def foo(i: Int) = i match {
+ | case 2 => println(2)
+ | case 1 => println(1)
+ | }
+ |}""".stripMargin
+
+ checkBCode(source) { dir =>
+ val moduleIn = dir.lookupName("Foo$.class", directory = false)
+ val moduleNode = loadClassNode(moduleIn.input)
+ val methodNode = getMethod(moduleNode, "foo")
+ assert(verifySwitch(methodNode))
+ }
+ }
+
+ /** This test verifies that simple matches with `@switch` annotations are
+ * indeed transformed to a switch
+ *
+ * FIXME: once issue#1258 is resolved, this should be enabled!
+ */
+ //@Test def basicTransfromAnnotated = {
+ // val source = """
+ // |object Foo {
+ // | import scala.annotation.switch
+ // | def foo(i: Int) = (i: @switch) match {
+ // | case 2 => println(2)
+ // | case 1 => println(1)
+ // | }
+ // |}""".stripMargin
+
+ // checkBCode(source) { dir =>
+ // val moduleIn = dir.lookupName("Foo$.class", directory = false)
+ // val moduleNode = loadClassNode(moduleIn.input)
+ // val methodNode = getMethod(moduleNode, "foo")
+ // assert(verifySwitch(methodNode))
+ // }
+ //}
}