KT-2752: add basic tests for JsName
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package foo
|
||||
|
||||
object A {
|
||||
@JsName("js_method") fun f() = "method"
|
||||
|
||||
@JsName("js_property") val f: String get() = "property"
|
||||
}
|
||||
|
||||
fun test() = js("""
|
||||
var a = Kotlin.modules.JS_TESTS.foo.A;
|
||||
return a.js_method() + ";" + a.js_property;
|
||||
""")
|
||||
|
||||
fun box(): String {
|
||||
val result = test()
|
||||
assertEquals("method;property", result);
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package foo
|
||||
|
||||
open class A {
|
||||
@JsName("js_f") open fun f(x: Int) = "A.f($x)"
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
override fun f(x: Int) = "B.f($x)"
|
||||
}
|
||||
|
||||
fun test() = js("""
|
||||
var module = Kotlin.modules.JS_TESTS.foo;
|
||||
return new (module.A)().js_f(23) + ";" + new (module.B)().js_f(42);
|
||||
""")
|
||||
|
||||
fun box(): String {
|
||||
val result = test()
|
||||
assertEquals("A.f(23);B.f(42)", result);
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package foo
|
||||
|
||||
interface A {
|
||||
@JsName("js_f") fun f(x: Int): String
|
||||
}
|
||||
|
||||
class B : A {
|
||||
override fun f(x: Int) = "B.f($x)"
|
||||
}
|
||||
|
||||
fun test() = js("""
|
||||
var module = Kotlin.modules.JS_TESTS.foo;
|
||||
return new (module.B)().js_f(23);
|
||||
""")
|
||||
|
||||
fun box(): String {
|
||||
val result = test()
|
||||
assertEquals("B.f(23)", result);
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
object A {
|
||||
@JsName("js_f") private fun f(x: Int) = "f($x)"
|
||||
}
|
||||
|
||||
fun test() = js("""
|
||||
return Kotlin.modules.JS_TESTS.foo.A.js_f(23);
|
||||
""")
|
||||
|
||||
fun box(): String {
|
||||
val result = test()
|
||||
assertEquals("f(23)", result);
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
class A(val x: String) {
|
||||
@JsName("A_int") constructor(x: Int) : this("int $x")
|
||||
}
|
||||
|
||||
fun test() = js("""
|
||||
return Kotlin.modules.JS_TESTS.foo.A_int(23).x;
|
||||
""")
|
||||
|
||||
fun box(): String {
|
||||
val result = test()
|
||||
assertEquals("int 23", result);
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
object A {
|
||||
@JsName("js_f") fun f(x: Int) = "f($x)"
|
||||
|
||||
@JsName("js_g") fun g(x: Int) = "g($x)"
|
||||
|
||||
@JsName("js_p") val p = "p"
|
||||
|
||||
@JsName("js_q") val q: String get() = "q"
|
||||
}
|
||||
|
||||
fun test() = js("""
|
||||
var a = Kotlin.modules.JS_TESTS.foo.A;
|
||||
return a.js_f(23) + ";" + a.js_g(42) + ";" + a.js_p + ";" + a.js_q;
|
||||
""")
|
||||
|
||||
fun box(): String {
|
||||
val result = test()
|
||||
assertEquals("f(23);g(42);p;q", result);
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user