blob: bc1a1b48dc5867c5ac1319e2c22ffd2f4aa78338 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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)()
| ^
"""
}
}
|