[JS IR BE] Fix and refactor interop tests

This commit is contained in:
Svyatoslav Kuzmich
2019-02-14 19:43:22 +03:00
parent 569187a751
commit a736756ceb
37 changed files with 54 additions and 58 deletions
@@ -1,5 +1,8 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1284
// TODO: Design Unit materialization and Unit.asDynamic() in JS IR BE
var log = ""
fun foo() {
+1
View File
@@ -1,4 +1,5 @@
// IGNORE_BACKEND: JS_IR
// KJS_WITH_FULL_RUNTIME
// EXPECTED_REACHABLE_NODES: 1556
package foo
+3 -2
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1300
open class M() {
open var b: Int = 0
@@ -18,7 +17,9 @@ class N() : M() {
fun box(): String {
val n = N()
println("a: " + n.a + " b: " + n.b + " superb: " + n.superb)
n.a
n.b
n.superb
if (n.b == 3 && n.a == 4 && n.superb == 3) return "OK";
return "fail";
}
+3 -2
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1296
interface M {
var backingB: Int
@@ -25,7 +24,9 @@ class N() : M {
fun box(): String {
val n = N()
println("a: " + n.a + " b: " + n.b + " superb: " + n.superb)
n.a
n.b
n.superb
if (n.b == 3 && n.a == 4 && n.superb == 3) return "OK";
return "fail";
}
@@ -1,3 +1,3 @@
function createWrongObject() {
return new (JS_TESTS.foo.C);
return new (JS_TESTS.C);
}
@@ -1,7 +1,6 @@
// IGNORE_BACKEND: JS_IR
// KJS_WITH_FULL_RUNTIME
// SKIP_MINIFICATION
// This test assumes that external JS code calls Kotlin code directly
package foo
open class A
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1289
package foo
@@ -11,11 +10,11 @@ fun bar(s: String): Int {
fun testWhen() {
global = ""
when(arrayOf(bar("A"),2,3)) {
arrayOf(1) -> println("1")
arrayOf(2) -> println("2")
else -> println("else")
arrayOf(1) -> bar("1")
arrayOf(2) -> bar("2")
else -> bar("else")
}
assertEquals("A", global)
assertEquals("Aelse", global)
}
@@ -1,4 +1,5 @@
// IGNORE_BACKEND: JS_IR
// KJS_WITH_FULL_RUNTIME
// SKIP_MINIFICATION
// This test uses eval to access root package, therefore DCE can't infer usage of corresponding functions
package foo
@@ -1,5 +1,6 @@
// LANGUAGE_VERSION: 1.3
// IGNORE_BACKEND: JS_IR
// KJS_WITH_FULL_RUNTIME
// EXPECTED_REACHABLE_NODES: 1566
package foo
@@ -1,4 +1,5 @@
// IGNORE_BACKEND: JS_IR
// KJS_WITH_FULL_RUNTIME
// EXPECTED_REACHABLE_NODES: 1323
fun <T> checkThrown(x: T, block: (T) -> Any?): Unit? {
return try {
@@ -1,4 +1,5 @@
// IGNORE_BACKEND: JS_IR
// KJS_WITH_FULL_RUNTIME
// EXPECTED_REACHABLE_NODES: 1230
// GENERATE_SOURCE_MAPS
// FILE: Enum.kt
@@ -1,4 +1,5 @@
// IGNORE_BACKEND: JS_IR
// KJS_WITH_FULL_RUNTIME
// SKIP_MINIFICATION
// This test uses eval
open class A {
@@ -1,4 +1,4 @@
// IGNORE_BACKEND: JS_IR
// KJS_WITH_FULL_RUNTIME
// EXPECTED_REACHABLE_NODES: 1681
/*
* Copy of JVM-backend test
@@ -171,7 +171,7 @@ inline fun testBodyHtmlNoInline(crossinline f: () -> String) : String {
fun box(): String {
var expected = testAllInline({"x"});
print(expected + " " + testHtmlNoInline({"x"}))
expected + " " + testHtmlNoInline({"x"})
if (expected != testHtmlNoInline({"x"})) return "fail 1: ${testHtmlNoInline({"x"})}\nbut expected\n${expected} "
if (expected != testBodyNoInline({"x"})) return "fail 2: ${testBodyNoInline({"x"})}\nbut expected\n${expected} "
+1 -1
View File
@@ -1,4 +1,4 @@
// IGNORE_BACKEND: JS_IR
// KJS_WITH_FULL_RUNTIME
// EXPECTED_REACHABLE_NODES: 1524
package foo
@@ -1,4 +1,5 @@
// IGNORE_BACKEND: JS_IR
// KJS_WITH_FULL_RUNTIME
// EXPECTED_REACHABLE_NODES: 1519
package foo
@@ -1,4 +1,5 @@
// IGNORE_BACKEND: JS_IR
// KJS_WITH_FULL_RUNTIME
// EXPECTED_REACHABLE_NODES: 1519
package foo
+1 -1
View File
@@ -1,4 +1,4 @@
// IGNORE_BACKEND: JS_IR
// KJS_WITH_FULL_RUNTIME
// EXPECTED_REACHABLE_NODES: 1514
package foo
@@ -1,4 +1,5 @@
// IGNORE_BACKEND: JS_IR
// KJS_WITH_FULL_RUNTIME
// EXPECTED_REACHABLE_NODES: 1530
external fun p(m: String): String
+1 -3
View File
@@ -1,6 +1,4 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1290
package foo
object A {
@JsName("js_method") fun f() = "method"
@@ -9,7 +7,7 @@ object A {
}
fun test() = js("""
var a = JS_TESTS.foo.A;
var a = JS_TESTS.A;
return a.js_method() + ";" + a.js_property;
""")
+2 -4
View File
@@ -1,6 +1,4 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1294
package foo
@JsName("AA") object A {
@JsName("foo") fun bar() = "A.foo"
@@ -11,12 +9,12 @@ package foo
}
fun testA() = js("""
var a = JS_TESTS.foo.AA;
var a = JS_TESTS.AA;
return a.foo();
""")
fun testB() = js("""
var b = new JS_TESTS.foo.BB();
var b = new JS_TESTS.BB();
return b.foo();
""")
+1 -3
View File
@@ -1,6 +1,4 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1295
package foo
open class A {
@JsName("js_f") open fun f(x: Int) = "A.f($x)"
@@ -11,7 +9,7 @@ class B : A() {
}
fun test() = js("""
var module = JS_TESTS.foo;
var module = JS_TESTS;
return new (module.A)().js_f(23) + ";" + new (module.B)().js_f(42);
""")
@@ -1,6 +1,4 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1290
package foo
interface A {
@JsName("js_f") fun f(x: Int): String
@@ -11,7 +9,7 @@ class B : A {
}
fun test() = js("""
var module = JS_TESTS.foo;
var module = JS_TESTS;
return new (module.B)().js_f(23);
""")
+1 -2
View File
@@ -1,13 +1,12 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1290
package foo
object A {
@JsName("js_f") private fun f(x: Int) = "f($x)"
}
fun test() = js("""
return JS_TESTS.foo.A.js_f(23);
return JS_TESTS.A.js_f(23);
""")
fun box(): String {
@@ -1,13 +1,12 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1288
package foo
class A(val x: String) {
@JsName("A_int") constructor(x: Int) : this("int $x")
}
fun test() = js("""
return JS_TESTS.foo.A_int(23).x;
return JS_TESTS.A_int(23).x;
""")
fun box(): String {
+1 -3
View File
@@ -1,6 +1,4 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1291
package foo
object A {
@JsName("js_f") fun f(x: Int) = "f($x)"
@@ -13,7 +11,7 @@ object A {
}
fun test() = js("""
var a = JS_TESTS.foo.A;
var a = JS_TESTS.A;
return a.js_f(23) + ";" + a.js_g(42) + ";" + a.js_p + ";" + a.js_q;
""")
@@ -1,4 +1,4 @@
function bar(a) {
a.foo_za3lpa$();
a.foo_za3lpa$(99);
a.foo();
a.foo(99);
}
@@ -5,6 +5,7 @@ package foo
var global = ""
open class A {
@JsName("foo")
open fun foo(x: Int = 23) {
global += "A.foo($x);"
}
+1 -3
View File
@@ -1,6 +1,4 @@
// IGNORE_BACKEND: JS_IR
// SKIP_MINIFICATION
package foo
val top = "TOP LEVEL"
@@ -11,7 +9,7 @@ fun box(): String {
assertEquals(5, eval("3 + 2"))
val PACKAGE = "JS_TESTS.foo"
val PACKAGE = "JS_TESTS"
assertEquals(top, eval("$PACKAGE.top"))
return "OK"
+1
View File
@@ -1,4 +1,5 @@
// IGNORE_BACKEND: JS_IR
// KJS_WITH_FULL_RUNTIME
// SKIP_MINIFICATION
// This test uses eval
// SKIP_NODE_JS
+1
View File
@@ -1,4 +1,5 @@
// IGNORE_BACKEND: JS_IR
// KJS_WITH_FULL_RUNTIME
// EXPECTED_REACHABLE_NODES: 1229
package foo
@@ -1,5 +1,6 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1545
// KJS_WITH_FULL_RUNTIME
package foo
object EmptyObject {}
@@ -1,6 +1,4 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1291
package foo
class A {
val x: Int
@@ -16,7 +14,7 @@ class A {
val A.z: Int
@JsName("getZ_") get() = 42
fun getPackage() = js("return JS_TESTS.foo")
fun getPackage() = js("return JS_TESTS")
fun box(): String {
val a = A()
@@ -1,4 +1,5 @@
// IGNORE_BACKEND: JS_IR
// KJS_WITH_FULL_RUNTIME
// EXPECTED_REACHABLE_NODES: 1325
package foo
@@ -1,6 +1,4 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1288
package foo
val x: Int
@JsName("getX_") get() = 23
@@ -12,7 +10,7 @@ var y: Int = 0
}
fun getPackage() = js("return JS_TESTS.foo")
fun getPackage() = js("return JS_TESTS")
fun box(): String {
assertEquals(23, x)
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1224
interface A {
fun foo(): String
@@ -10,13 +9,14 @@ class B : A {
fun box(): String {
val b = B::class.js
val c = js("""
val c = js("""(function() {
function C() {
b.call(this);
};
C.prototype = Object.create(b.prototype);
C.prototype.constructor = C;
new C();
return new C();
})()
""")
if (c !is B) return "fail: c !is B"
@@ -1,12 +1,11 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1293
package foo
class Fail(message: String) : Exception(message)
fun test(testName: String, actual: Any, expectedAsString: String) {
val expected = eval("[$expectedAsString]") as Array<in Any>
fun test(testName: String, actual: Any, expectedAsString: String?, expectedAsArray: Array<in Any>? = null) {
val expected = expectedAsArray ?: eval("[$expectedAsString]") as Array<in Any>
val expectedJs: dynamic = expected
val actualJs: dynamic = actual
if (expectedJs.length != actualJs.length) {
@@ -29,7 +28,7 @@ fun box(): String {
test("byteArrayOf", byteArrayOf(0, 1, 2, 3, 4), "0, 1, 2, 3, 4")
test("shortArrayOf", shortArrayOf(0, 1, 2, 3, 4), "0, 1, 2, 3, 4")
test("intArray,", intArrayOf(0, 1, 2, 3, 4), "0, 1, 2, 3, 4")
test("longArrayOf", longArrayOf(0, 1, 2, 3, 4), "kotlin.Long.fromInt(0), kotlin.Long.fromInt(1), kotlin.Long.fromInt(2), kotlin.Long.fromInt(3), kotlin.Long.fromInt(4)")
test("longArrayOf", longArrayOf(0, 1, 2, 3, 4), null, expectedAsArray = arrayOf(0L, 1L, 2L, 3L, 4L))
test("floatArrayOf", floatArrayOf(0.0f, 1.0f, 2.0f, 3.0f, 4.0f), "0.0, 1.0, 2.0, 3.0, 4.0")
test("doubleArrayOf", doubleArrayOf(0.0, 1.1, 2.2, 3.3, 4.4), "0.0, 1.1, 2.2, 3.3, 4.4")
}
@@ -1,6 +1,4 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1301
package foo
public interface A {
fun foo() {
@@ -11,7 +9,7 @@ public interface B : A {
}
}
external class Function(vararg args: String)
external class Function(args: String, body: String)
val hasProp = Function("obj, prop", "return obj[prop] !== undefined") as ((Any, String) -> Boolean)
@@ -27,7 +25,7 @@ fun box(): String {
if (!hasProp(b, "foo")) return "B hasn't foo"
if (!hasProp(b, "boo")) return "B hasn't boo"
val PREFIX = "_.foo"
val PREFIX = "_"
if (eval("$PREFIX.A") == null) return "$PREFIX.A not found"
if (eval("$PREFIX.B") == null) return "$PREFIX.B not found"
if (eval("$PREFIX.A === $PREFIX.B") as Boolean) return "A and B refer to the same object"