diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2015-02-18 15:25:29 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2015-02-18 15:25:29 -0800 |
commit | 9a3ea24596c9a929ad821bf18bb1bd73e569bc0a (patch) | |
tree | d2a2e196f0db07097b7e03258937c3790a37478f /test | |
parent | 7a872f4ed261947070a2937982efa9f35684a8dd (diff) | |
parent | e53165c4a3f1551624d477efd37fbb189fb750d5 (diff) | |
download | scala-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.scala | 29 |
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 |