KT-2752: add basic tests for JsName

This commit is contained in:
Alexey Andreev
2016-05-30 14:26:24 +03:00
parent 5e3aa33b13
commit 5ce158f297
44 changed files with 300 additions and 157 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ package foo
import test.*
// CHECK_CONTAINS_NO_CALLS: testClassObject
// CHECK_CONTAINS_NO_CALLS: testClassObject_0
internal fun testFinalInline(): String {
return Z().finalInline({"final"})
@@ -17,7 +17,7 @@ public fun log(s: String): String {
import utils.*
// CHECK_CONTAINS_NO_CALLS: test
// CHECK_CONTAINS_NO_CALLS: test_0
internal fun test(s: String): String = log(s + ";")
@@ -12,7 +12,7 @@ public fun <T, R> apply(x: T, fn: (T)->R): R =
import utils.*
// CHECK_CONTAINS_NO_CALLS: test
// CHECK_CONTAINS_NO_CALLS: test_0
internal fun multiplyBy2(x: Int): Int = x * 2
@@ -9,7 +9,7 @@ public fun sum(x: Int, y: Int): Int =
// MODULE: main(lib)
// FILE: main.kt
// CHECK_CONTAINS_NO_CALLS: test
// CHECK_CONTAINS_NO_CALLS: test_0
internal fun test(x: Int, y: Int): Int = utils.sum(x, y)
@@ -13,7 +13,7 @@ public fun <T, R> apply(x: T, fn: T.()->R): R =
import utils.*
// CHECK_CONTAINS_NO_CALLS: test
// CHECK_CONTAINS_NO_CALLS: test_0
internal class A(val n: Int)
+1 -1
View File
@@ -13,7 +13,7 @@ public fun <T, R> apply(x: T, fn: (T)->R): R =
import utils.*
// CHECK_CONTAINS_NO_CALLS: test
// CHECK_CONTAINS_NO_CALLS: test_0
internal fun test(x: Int): Int = apply(x) { it * 2 }
@@ -13,7 +13,7 @@ public fun <T, R> apply(x: T, fn: (T)->R): R =
import utils.*
// CHECK_CONTAINS_NO_CALLS: test
// CHECK_CONTAINS_NO_CALLS: test_0
internal fun test(x: Int, y: Int): Int = apply(x) { it + y }
@@ -15,7 +15,7 @@ public fun <T, R> apply(x: T, fn: (T)->R): R {
import utils.*
// CHECK_CONTAINS_NO_CALLS: test
// CHECK_CONTAINS_NO_CALLS: test_0
internal fun test(x: Int, y: Int): Int = apply(x) { it + 1 } * y
+1 -1
View File
@@ -14,7 +14,7 @@ public class A(public val x: Int) {
import utils.*
// CHECK_CONTAINS_NO_CALLS: test
// CHECK_CONTAINS_NO_CALLS: test_0
internal fun test(a: A, y: Int): Int = a.plus(y)
+1 -1
View File
@@ -13,7 +13,7 @@ public fun sum(x: Int, y: Int): Int =
import utils.*
// CHECK_CONTAINS_NO_CALLS: test
// CHECK_CONTAINS_NO_CALLS: test_0
internal fun test(x: Int, y: Int): Int = sum(x, y)
+18
View File
@@ -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"
}
+15
View File
@@ -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"
}
+22
View File
@@ -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"
}
@@ -1,30 +0,0 @@
/*
* Copy of JVM-backend test
* Found at: compiler/testData/codegen/boxInline/trait/trait.1.kt
*/
package foo
import test.*
// CHECK_CONTAINS_NO_CALLS: testClassObject_0
internal fun testFinalInline(): String {
return Z().finalInline({"final"})
}
internal fun testFinalInline2(instance: InlineTrait): String {
return instance.finalInline({"final2"})
}
internal fun testClassObject(): String {
return InlineTrait.finalInline({"classobject"})
}
fun box(): String {
if (testFinalInline() != "final") return "test1: ${testFinalInline()}"
if (testFinalInline2(Z()) != "final2") return "test2: ${testFinalInline2(Z())}"
if (testClassObject() != "classobject") return "test3: ${testClassObject()}"
return "OK"
}
@@ -1,12 +0,0 @@
import utils.*
// CHECK_CONTAINS_NO_CALLS: test_0
internal fun test(s: String): String = log(s + ";")
fun box(): String {
assertEquals("a;", test("a"))
assertEquals("a;b;", test("b"))
return "OK"
}
@@ -1,13 +0,0 @@
import utils.*
// CHECK_CONTAINS_NO_CALLS: test_0
internal fun multiplyBy2(x: Int): Int = x * 2
internal fun test(x: Int): Int = apply(x, ::multiplyBy2)
fun box(): String {
assertEquals(6, test(3))
return "OK"
}
@@ -1,10 +0,0 @@
// CHECK_CONTAINS_NO_CALLS: test_0
internal fun test(x: Int, y: Int): Int = utils.sum(x, y)
fun box(): String {
assertEquals(3, test(1, 2))
assertEquals(5, test(2, 3))
return "OK"
}
@@ -1,13 +0,0 @@
import utils.*
// CHECK_CONTAINS_NO_CALLS: test_0
internal class A(val n: Int)
internal fun test(a: A, m: Int): Int = apply(a) { n * m }
fun box(): String {
assertEquals(6, test(A(2), 3))
return "OK"
}
@@ -1,11 +0,0 @@
import utils.*
// CHECK_CONTAINS_NO_CALLS: test_0
internal fun test(x: Int): Int = apply(x) { it * 2 }
fun box(): String {
assertEquals(6, test(3))
return "OK"
}
@@ -1,11 +0,0 @@
import utils.*
// CHECK_CONTAINS_NO_CALLS: test_0
internal fun test(x: Int, y: Int): Int = apply(x) { it + y }
fun box(): String {
assertEquals(3, test(1, 2))
return "OK"
}
@@ -1,11 +0,0 @@
import utils.*
// CHECK_CONTAINS_NO_CALLS: test_0
internal fun test(x: Int, y: Int): Int = apply(x) { it + 1 } * y
fun box(): String {
assertEquals(6, test(1, 3))
return "OK"
}
@@ -1,11 +0,0 @@
import utils.*
// CHECK_CONTAINS_NO_CALLS: test_0
internal fun test(a: A, y: Int): Int = a.plus(y)
fun box(): String {
assertEquals(5, test(A(2), 3))
return "OK"
}
@@ -1,12 +0,0 @@
import utils.*
// CHECK_CONTAINS_NO_CALLS: test_0
internal fun test(x: Int, y: Int): Int = sum(x, y)
fun box(): String {
assertEquals(3, test(1, 2))
assertEquals(5, test(2, 3))
return "OK"
}