diff options
author | Haoyi Li <haoyi@haoyi-mbp.corp.dropbox.com> | 2014-11-26 00:45:31 -0800 |
---|---|---|
committer | Haoyi Li <haoyi@haoyi-mbp.corp.dropbox.com> | 2014-11-26 00:45:31 -0800 |
commit | 24f31e120f9537faede7a174bb09ee35f64e1ce4 (patch) | |
tree | 06ffc3ecc7847789008352b7e2b7c040dad48907 /examples/scala-js/test-suite/src/test/scala/scala/scalajs/testsuite/compiler/ReflectionTest.scala | |
parent | b89ce9cbf79363f8cab09186a5d7ba94bc0af02a (diff) | |
parent | 2c4b142503bd2d871e6818b5cab8c38627d9e4a0 (diff) | |
download | hands-on-scala-js-24f31e120f9537faede7a174bb09ee35f64e1ce4.tar.gz hands-on-scala-js-24f31e120f9537faede7a174bb09ee35f64e1ce4.tar.bz2 hands-on-scala-js-24f31e120f9537faede7a174bb09ee35f64e1ce4.zip |
Merge commit '2c4b142503bd2d871e6818b5cab8c38627d9e4a0' as 'examples/scala-js'
Diffstat (limited to 'examples/scala-js/test-suite/src/test/scala/scala/scalajs/testsuite/compiler/ReflectionTest.scala')
-rw-r--r-- | examples/scala-js/test-suite/src/test/scala/scala/scalajs/testsuite/compiler/ReflectionTest.scala | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/examples/scala-js/test-suite/src/test/scala/scala/scalajs/testsuite/compiler/ReflectionTest.scala b/examples/scala-js/test-suite/src/test/scala/scala/scalajs/testsuite/compiler/ReflectionTest.scala new file mode 100644 index 0000000..3e1d7a2 --- /dev/null +++ b/examples/scala-js/test-suite/src/test/scala/scala/scalajs/testsuite/compiler/ReflectionTest.scala @@ -0,0 +1,69 @@ +/* __ *\ +** ________ ___ / / ___ __ ____ Scala.js Test Suite ** +** / __/ __// _ | / / / _ | __ / // __/ (c) 2013, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ |/_// /_\ \ http://scala-js.org/ ** +** /____/\___/_/ |_/____/_/ | |__/ /____/ ** +** |/____/ ** +\* */ +package scala.scalajs.testsuite.compiler + +import scala.language.implicitConversions + +import scala.scalajs.js + +import org.scalajs.jasminetest.JasmineTest + +/** Tests the little reflection we support */ +object ReflectionTest extends JasmineTest { + + describe("Scala.js Reflection (through java.lang.Class)") { + it("should append $ to class name of objects") { + expect(TestObject.getClass.getName).toEqual( + "scala.scalajs.testsuite.compiler.ReflectionTest$TestObject$") + } + + it("should support isInstance") { + class A + class B extends A + val b = new B + expect(classOf[A].isInstance(b)).toBeTruthy + expect(classOf[A].isInstance("hello")).toBeFalsy + } + + it("getClass() for normal types") { + class Foo { + def bar() = super.getClass() + } + val foo = new Foo + expect(foo.getClass() eq classOf[Foo]).toBeTruthy + expect(foo.bar() eq classOf[Foo]).toBeTruthy + } + + it("getClass() for anti-boxed primitive types") { + implicit def classAsAny(c: java.lang.Class[_]): js.Any = + c.asInstanceOf[js.Any] + expect((false: Any).getClass).toBe(classOf[java.lang.Boolean]) + expect(('a': Any).getClass).toBe(classOf[java.lang.Character]) + expect((1.toByte: Any).getClass).toBe(classOf[java.lang.Byte]) + expect((1.toShort: Any).getClass).toBe(classOf[java.lang.Byte]) + expect((1: Any).getClass).toBe(classOf[java.lang.Byte]) + expect((1L: Any).getClass).toBe(classOf[java.lang.Long]) + expect((1.5f: Any).getClass).toBe(classOf[java.lang.Float]) + expect((1.5: Any).getClass).toBe(classOf[java.lang.Float]) + expect(((): Any).getClass).toBe(classOf[scala.runtime.BoxedUnit]) + } + + it("Class.isAssignableFrom should mimic runtime type tests behavior - #879") { + expect(classOf[Short].isAssignableFrom(classOf[Byte])).toBeTruthy + expect(classOf[Byte].isAssignableFrom(classOf[Byte])).toBeTruthy + expect(classOf[Byte].isAssignableFrom(classOf[Short])).toBeFalsy + expect(classOf[Int].isAssignableFrom(classOf[Byte])).toBeTruthy + expect(classOf[Double].isAssignableFrom(classOf[Int])).toBeTruthy + expect(classOf[Int].isAssignableFrom(classOf[Double])).toBeFalsy + expect(classOf[Long].isAssignableFrom(classOf[Int])).toBeFalsy + } + } + + object TestObject + +} |