summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2015-02-18 15:25:29 -0800
committerAdriaan Moors <adriaan.moors@typesafe.com>2015-02-18 15:25:29 -0800
commit9a3ea24596c9a929ad821bf18bb1bd73e569bc0a (patch)
treed2a2e196f0db07097b7e03258937c3790a37478f /test
parent7a872f4ed261947070a2937982efa9f35684a8dd (diff)
parente53165c4a3f1551624d477efd37fbb189fb750d5 (diff)
downloadscala-9a3ea24596c9a929ad821bf18bb1bd73e569bc0a.tar.gz
scala-9a3ea24596c9a929ad821bf18bb1bd73e569bc0a.tar.bz2
scala-9a3ea24596c9a929ad821bf18bb1bd73e569bc0a.zip
Merge pull request #4329 from adriaanm/followup-4235
Simpler & Scala.js-friendly `ClassTag.unapply`
Diffstat (limited to 'test')
-rw-r--r--test/junit/scala/reflect/ClassTag.scala29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/junit/scala/reflect/ClassTag.scala b/test/junit/scala/reflect/ClassTag.scala
new file mode 100644
index 0000000000..90cc981fc1
--- /dev/null
+++ b/test/junit/scala/reflect/ClassTag.scala
@@ -0,0 +1,29 @@
+package scala.reflect
+
+import org.junit.Test
+import org.junit.Assert._
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+import scala.tools.testing.AssertUtil._
+
+class Misc
+
+@RunWith(classOf[JUnit4])
+class ClassTagTest {
+ def checkNotString[A: ClassTag](a: Any) = a match { case x: String => false case x: A => true case _ => false }
+ def checkNotInt[A: ClassTag](a: Any) = a match { case x: Int => false case x: A => true case _ => false }
+ def checkNotLong[A: ClassTag](a: Any) = a match { case x: Long => false case x: A => true case _ => false }
+
+ @Test def checkMisc = assertTrue(checkNotString[Misc](new Misc))
+ @Test def checkString = assertTrue(checkNotInt[String] ("woele"))
+ @Test def checkByte = assertTrue(checkNotInt[Byte] (0.toByte))
+ @Test def checkShort = assertTrue(checkNotInt[Short] (0.toShort))
+ @Test def checkChar = assertTrue(checkNotInt[Char] (0.toChar))
+ @Test def checkInt = assertTrue(checkNotLong[Int] (0.toInt))
+ @Test def checkLong = assertTrue(checkNotInt[Long] (0.toLong))
+ @Test def checkFloat = assertTrue(checkNotInt[Float] (0.toFloat))
+ @Test def checkDouble = assertTrue(checkNotInt[Double] (0.toDouble))
+ @Test def checkBoolean = assertTrue(checkNotInt[Boolean](false))
+ @Test def checkUnit = assertTrue(checkNotInt[Unit] ({}))
+} \ No newline at end of file