summaryrefslogtreecommitdiff
path: root/examples/scala-js/compiler/src/test/scala/scala/scalajs/compiler/test/JSDynamicLiteralTest.scala
diff options
context:
space:
mode:
authorHaoyi Li <haoyi@haoyi-mbp.corp.dropbox.com>2014-11-26 00:45:31 -0800
committerHaoyi Li <haoyi@haoyi-mbp.corp.dropbox.com>2014-11-26 00:45:31 -0800
commit24f31e120f9537faede7a174bb09ee35f64e1ce4 (patch)
tree06ffc3ecc7847789008352b7e2b7c040dad48907 /examples/scala-js/compiler/src/test/scala/scala/scalajs/compiler/test/JSDynamicLiteralTest.scala
parentb89ce9cbf79363f8cab09186a5d7ba94bc0af02a (diff)
parent2c4b142503bd2d871e6818b5cab8c38627d9e4a0 (diff)
downloadhands-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/compiler/src/test/scala/scala/scalajs/compiler/test/JSDynamicLiteralTest.scala')
-rw-r--r--examples/scala-js/compiler/src/test/scala/scala/scalajs/compiler/test/JSDynamicLiteralTest.scala102
1 files changed, 102 insertions, 0 deletions
diff --git a/examples/scala-js/compiler/src/test/scala/scala/scalajs/compiler/test/JSDynamicLiteralTest.scala b/examples/scala-js/compiler/src/test/scala/scala/scalajs/compiler/test/JSDynamicLiteralTest.scala
new file mode 100644
index 0000000..bc1a1b4
--- /dev/null
+++ b/examples/scala-js/compiler/src/test/scala/scala/scalajs/compiler/test/JSDynamicLiteralTest.scala
@@ -0,0 +1,102 @@
+package scala.scalajs.compiler.test
+
+import scala.scalajs.compiler.test.util._
+import org.junit.Test
+
+class JSDynamicLiteralTest extends DirectTest with TestHelpers {
+
+ override def preamble =
+ """import scala.scalajs.js.Dynamic.{ literal => lit }
+ """
+
+ @Test
+ def callApplyOnly = {
+
+ // selectDynamic (with any name)
+ expr"""
+ lit.helloWorld
+ """.fails() // Scala error, no string checking due to versions
+
+ // applyDynamicNamed with wrong method name
+ expr"""
+ lit.helloWorld(a = "a")
+ """ hasErrors
+ """
+ |newSource1.scala:3: error: js.Dynamic.literal does not have a method named helloWorld
+ | lit.helloWorld(a = "a")
+ | ^
+ """
+
+ // applyDynamic with wrong method name
+ expr"""
+ lit.helloWorld("a" -> "a")
+ """ hasErrors
+ """
+ |newSource1.scala:3: error: js.Dynamic.literal does not have a method named helloWorld
+ | lit.helloWorld("a" -> "a")
+ | ^
+ """
+
+ }
+
+ @Test
+ def goodTypesOnly = {
+
+ // Bad value type (applyDynamic)
+ """
+ class A {
+ val x = new Object()
+ def foo = lit("a" -> x)
+ }
+ """.fails()
+
+ // Bad key type (applyDynamic)
+ """
+ class A {
+ val x = Seq()
+ def foo = lit(x -> "a")
+ }
+ """.fails()
+
+ // Bad value type (applyDynamicNamed)
+ """
+ class A {
+ val x = new Object()
+ def foo = lit(a = x)
+ }
+ """.fails()
+
+ }
+
+ @Test
+ def noNonLiteralMethodName = {
+
+ // applyDynamicNamed
+ """
+ class A {
+ val x = "string"
+ def foo = lit.applyDynamicNamed(x)()
+ }
+ """ hasErrors
+ """
+ |newSource1.scala:5: error: js.Dynamic.literal.applyDynamicNamed may not be called directly
+ | def foo = lit.applyDynamicNamed(x)()
+ | ^
+ """
+
+ // applyDynamic
+ """
+ class A {
+ val x = "string"
+ def foo = lit.applyDynamic(x)()
+ }
+ """ hasErrors
+ """
+ |newSource1.scala:5: error: js.Dynamic.literal.applyDynamic may not be called directly
+ | def foo = lit.applyDynamic(x)()
+ | ^
+ """
+
+ }
+
+}