JS backend: testFiles -> testData
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package foo
|
||||
|
||||
import js.*
|
||||
|
||||
native
|
||||
class A(b: Int) {
|
||||
fun g(): Int = js.noImpl
|
||||
fun m(): Int = js.noImpl
|
||||
}
|
||||
|
||||
|
||||
fun box(): Boolean {
|
||||
if (A(2).g() != 4) {
|
||||
return false;
|
||||
}
|
||||
if (A(3).m() != 2) {
|
||||
return false;
|
||||
}
|
||||
val a = A(100)
|
||||
if (a.g() != 200) {
|
||||
return false;
|
||||
}
|
||||
if (a.m() != 99) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package foo
|
||||
|
||||
import js.*
|
||||
|
||||
native
|
||||
class A(val c: Int) {
|
||||
native
|
||||
class object {
|
||||
val g: Int = js.noImpl
|
||||
val c: String = js.noImpl
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
if (A.g != 3) return false
|
||||
if (A.c != "hoooray") return false
|
||||
if (A(2).c != 2) return false
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package foo
|
||||
|
||||
native
|
||||
open class A(val a: Int) {
|
||||
fun g(): Int = noImpl
|
||||
fun m(): Int = noImpl
|
||||
|
||||
public open fun foo(i: Int): String = noImpl
|
||||
public fun boo(i: Int): String = noImpl
|
||||
native("bar")
|
||||
open fun baz(i: Int): String = noImpl
|
||||
}
|
||||
|
||||
class B(val b: Int) : A(b / 2) {
|
||||
override fun foo(i: Int): String = "B.foo($i: Int)"
|
||||
|
||||
fun boo(): String = "B.boo()"
|
||||
fun boo(i: String): String = "B.boo($i: String)"
|
||||
|
||||
fun bar(i: String): String = "B.bar($i: String)"
|
||||
fun bar(): String = "B.bar()"
|
||||
override fun baz(i: Int): String = "B.baz($i: Int)"
|
||||
fun bar(d: Double): String = "B.bar($d: Double)"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val b = B(10)
|
||||
|
||||
if (b !is A) return "b !is A"
|
||||
if (b.g() != 10) return "b.g() != 10, it: ${b.g()}"
|
||||
if (b.m() != 4) return "b.m() != 4, it: ${b.m()}"
|
||||
|
||||
if (b.foo(4) != "B.foo(4: Int)") return "b.foo(4) != \"B.foo(4: Int)\", it: ${b.foo(4)}"
|
||||
|
||||
if (b.boo(434) != "A.boo(434)") return "b.boo(434) != \"A.boo(434)\", it: ${b.boo(434)}"
|
||||
if (b.boo() != "B.boo()") return "b.boo() != \"B.boo()\", it: ${b.boo()}"
|
||||
if (b.boo("qlfj") != "B.boo(qlfj: String)") return "b.boo(\"qlfj\") != \"B.boo(qlfj: String)\", it: ${b.boo("qlfj")}"
|
||||
|
||||
if (b.bar("apl") != "B.bar(apl: String)") return "b.bar(\"apl\") != \"B.bar(apl: String)\", it: ${b.bar("apl")}"
|
||||
if (b.baz(34) != "B.baz(34: Int)") return "b.baz(34) != \"B.baz(34: Int)\", it: ${b.baz(34)}"
|
||||
if (b.bar() != "B.bar()") return "b.bar() != \"B.bar()\", it: ${b.bar()}"
|
||||
if (b.bar(2.213) != "B.bar(2.213: Double)") return "b.bar(2.213) != \"B.bar(2.213: Double)\", it: ${b.bar(2.213)}"
|
||||
|
||||
val a: A = b
|
||||
|
||||
if (a.foo(4) != "B.foo(4: Int)") return "a.foo(4) != \"B.foo(4: Int)\", it: ${a.foo(4)}"
|
||||
if (a.boo(434) != "A.boo(434)") return "a.boo(434) != \"A.boo(434)\", it: ${a.boo(434)}"
|
||||
if (a.baz(34) != "B.baz(34: Int)") return "a.baz(34) != \"B.baz(34: Int)\", it: ${a.baz(34)}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package foo
|
||||
|
||||
native
|
||||
class Wow() {
|
||||
val x: Int = js.noImpl
|
||||
val y: Int = js.noImpl
|
||||
}
|
||||
|
||||
native
|
||||
fun Wow.sum(): Int = js.noImpl
|
||||
|
||||
fun Wow.dblSum(): Int {
|
||||
return 2 * sum()
|
||||
}
|
||||
|
||||
|
||||
fun box(): Boolean {
|
||||
return (Wow().dblSum() == 6)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
native
|
||||
trait Chrome {
|
||||
val extension: Extension
|
||||
}
|
||||
|
||||
native
|
||||
trait Extension {
|
||||
val lastError: LastError?
|
||||
}
|
||||
|
||||
native
|
||||
trait LastError {
|
||||
val message: String
|
||||
}
|
||||
|
||||
native
|
||||
val chrome: Chrome = noImpl
|
||||
|
||||
fun box(): Boolean {
|
||||
val lastError = chrome.extension.lastError?.message
|
||||
return lastError == null
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
import java.util.HashMap
|
||||
|
||||
native
|
||||
val classes: Map<String, Any> = noImpl
|
||||
native
|
||||
val classesMutable: HashMap<String, String> = noImpl
|
||||
|
||||
fun box(): Boolean {
|
||||
classesMutable["why"] = "?"
|
||||
return classes["answer"] == 42 && classesMutable["why"] == "?"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package foo
|
||||
|
||||
library class A() {
|
||||
library fun f() {
|
||||
}
|
||||
library fun f(a: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
library fun getResult() = false
|
||||
|
||||
fun box(): Boolean {
|
||||
val a = A()
|
||||
a.f()
|
||||
a.f(2)
|
||||
return getResult()
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package foo
|
||||
|
||||
val PACKAGE = "Kotlin.modules.JS_TESTS.foo"
|
||||
|
||||
native fun eval(e: String): Any? = noImpl
|
||||
fun funToString(name: String) = eval("$PACKAGE.$name.toString()") as String
|
||||
|
||||
native("\"O\"") val foo: String = noImpl
|
||||
native("boo") val bar: String = noImpl
|
||||
|
||||
class A
|
||||
native("__proto__") val Any.proto: String = noImpl
|
||||
native("__proto__") val A.proto: String = noImpl
|
||||
|
||||
fun actual(foo: String, native("boo") bar: String) = foo + bar
|
||||
fun expected(foo: String, boo: String) = foo + boo
|
||||
|
||||
fun box(): String {
|
||||
val OK = "OK"
|
||||
|
||||
if (foo + bar != OK) return "$foo + $bar != $OK"
|
||||
|
||||
val actualAsString = funToString("actual")
|
||||
val expectedAsString = funToString("expected")
|
||||
if (actualAsString != expectedAsString) return "$actualAsString != $expectedAsString"
|
||||
if (actual("asd", "12345") != "asd12345") return "${actual("asd", "12345")} != \"asd12345\""
|
||||
|
||||
val a = A()
|
||||
val any: Any = a
|
||||
val protoA = eval("$PACKAGE.A.prototype")
|
||||
if (a.proto != any.proto || a.proto != protoA)
|
||||
return "a.proto != any.proto /*${a.proto != any.proto}*/ || a.proto != $PACKAGE.A.prototype /*${a.proto != protoA}*/"
|
||||
|
||||
return OK
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
import js.*
|
||||
|
||||
native
|
||||
fun returnFalse(): Boolean = js.noImpl
|
||||
|
||||
fun box() = !returnFalse()
|
||||
@@ -0,0 +1,11 @@
|
||||
package foo
|
||||
|
||||
import js.*
|
||||
|
||||
native
|
||||
val c: Any? = js.noImpl
|
||||
|
||||
fun box(): Boolean {
|
||||
if (c != null) return false
|
||||
return (c == null)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
import js.*
|
||||
|
||||
/*function g should return 0 if a parameter is undefined 1 if parameter is 1 and 3 if parameter is 3*/
|
||||
native
|
||||
fun f(g: (Int?) -> Int): Boolean = js.noImpl
|
||||
|
||||
|
||||
fun box(): Boolean {
|
||||
val b = {
|
||||
(a: Int?) ->
|
||||
if (a == null) {
|
||||
0
|
||||
}
|
||||
else if (a == 1) {
|
||||
1
|
||||
}
|
||||
else {
|
||||
3
|
||||
}
|
||||
}
|
||||
return f(b)
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package foo
|
||||
|
||||
import js.*
|
||||
|
||||
native
|
||||
fun paramCount(vararg a: Int): Int = js.noImpl
|
||||
|
||||
native("paramCount")
|
||||
fun anotherParamCount(vararg a: Int): Int = js.noImpl
|
||||
|
||||
// test spread operator
|
||||
fun count(vararg a: Int) = paramCount(*a)
|
||||
|
||||
// test spread operator
|
||||
fun anotherCount(vararg a: Int) = anotherParamCount(*a)
|
||||
|
||||
native
|
||||
fun test3(bar: Bar, dummy: Int, vararg args: Int): Boolean = js.noImpl
|
||||
|
||||
native
|
||||
fun Bar.test2(order: Int, dummy: Int, vararg args: Int): Boolean = js.noImpl
|
||||
|
||||
native
|
||||
class Bar(val size: Int, order: Int = 0) {
|
||||
fun test(order: Int, dummy: Int, vararg args: Int): Boolean = js.noImpl
|
||||
class object {
|
||||
fun startNewTest(): Boolean = js.noImpl
|
||||
var hasOrderProblem: Boolean = false
|
||||
}
|
||||
}
|
||||
|
||||
native
|
||||
object obj {
|
||||
fun test(size: Int, vararg args: Int): Boolean = js.noImpl
|
||||
}
|
||||
|
||||
fun spreadInMethodCall(size: Int, vararg args: Int) = Bar(size).test(0, 1, *args)
|
||||
|
||||
fun spreadInObjectMethodCall(size: Int, vararg args: Int) = obj.test(size, *args)
|
||||
|
||||
fun spreadInMethodCallWithReceiver(size: Int, vararg args: Int) = Bar(size).test2(0, 1, *args)
|
||||
|
||||
fun spreadInPackageMethodCall(size: Int, vararg args: Int) = test3(Bar(size), 1, *args)
|
||||
|
||||
native
|
||||
fun testNativeVarargWithFunLit(vararg args: Int, f: (a: IntArray) -> Boolean): Boolean = js.noImpl
|
||||
|
||||
fun testSpreadOperatorWithSafeCall(a: Bar?, expected: Boolean?, vararg args: Int): Boolean {
|
||||
return a?.test(0, 1, *args) == expected
|
||||
}
|
||||
|
||||
fun testSpreadOperatorWithSureCall(a: Bar?, vararg args: Int): Boolean {
|
||||
return a!!.test(0, 1, *args)
|
||||
}
|
||||
|
||||
fun testCallOrder(vararg args: Int) =
|
||||
Bar.startNewTest() &&
|
||||
Bar(args.size, 0).test(1, 1, *args) && Bar(args.size, 2).test(3, 1, *args) &&
|
||||
!Bar.hasOrderProblem
|
||||
|
||||
fun box(): String {
|
||||
if (paramCount() != 0)
|
||||
return "failed when call native function without args"
|
||||
|
||||
if (paramCount(1, 2, 3) != 3)
|
||||
return "failed when call native function with some args"
|
||||
|
||||
if (anotherParamCount(1, 2, 3) != 3)
|
||||
return "failed when call native function with some args witch declareted with custom name"
|
||||
|
||||
if (count() != 0)
|
||||
return "failed when call native function without args using spread operator"
|
||||
|
||||
if (count(1, 1, 1, 1) != 4)
|
||||
return "failed when call native function with some args using spread operator"
|
||||
|
||||
if (anotherCount(1, 2, 3) != 3)
|
||||
return "failed when call native function with some args using spread operator witch declareted with custom name"
|
||||
|
||||
if (!Bar(5).test(0, 1, 1, 2, 3, 4, 5))
|
||||
return "failed when call method with some args"
|
||||
|
||||
if (!spreadInMethodCall(2, 1, 2))
|
||||
return "failed when call method using spread operator"
|
||||
|
||||
if (!(obj.test(5, 1, 2, 3, 4, 5)))
|
||||
return "failed when call method of object"
|
||||
|
||||
if (!(spreadInObjectMethodCall(2, 1, 2)))
|
||||
return "failed when call method of object using spread operator"
|
||||
|
||||
if (!spreadInMethodCallWithReceiver(2, 1, 2))
|
||||
return "failed when call method using spread operator with receiver"
|
||||
|
||||
if (!spreadInPackageMethodCall(2, 1, 2))
|
||||
return "failed when call package method using spread operator"
|
||||
|
||||
if (!(testNativeVarargWithFunLit(1, 2, 3) { args -> args.size == 3 }))
|
||||
return "failed when call native function with vararg and fun literal"
|
||||
|
||||
if (!(testSpreadOperatorWithSafeCall(null, null)))
|
||||
return "failed when test spread operator with SafeCall (?.) using null receiver"
|
||||
|
||||
if (!(testSpreadOperatorWithSafeCall(Bar(3), true, 1, 2, 3)))
|
||||
return "failed when test spread operator with SafeCall (?.)"
|
||||
|
||||
if (!(testSpreadOperatorWithSureCall(Bar(3), 1, 2, 3)))
|
||||
return "failed when test spread operator with SureCall (!!)"
|
||||
|
||||
if (!(testCallOrder()))
|
||||
return "failed when test calling order when using spread operator without args"
|
||||
|
||||
if (!(testCallOrder(1, 2, 3, 4)))
|
||||
return "failed when test calling order when using spread operator with some args"
|
||||
|
||||
val baz: Bar? = Bar(1)
|
||||
if (!(baz!!)?.test(0, 1, 1))
|
||||
return "failed when combined SureCall and SafeCall, maybe we lost cached expression"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user