JS: move more test to box tests
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
function A(b) {
|
||||
this.g = function () {
|
||||
return 2 * b;
|
||||
}
|
||||
this.m = function () {
|
||||
return b - 1;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package foo
|
||||
|
||||
@native
|
||||
class A(b: Int) {
|
||||
fun g(): Int = noImpl
|
||||
fun m(): Int = noImpl
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
if (A(2).g() != 4) {
|
||||
return "fail1"
|
||||
}
|
||||
if (A(3).m() != 2) {
|
||||
return "fail2"
|
||||
}
|
||||
val a = A(100)
|
||||
if (a.g() != 200) {
|
||||
return "fail3"
|
||||
}
|
||||
if (a.m() != 99) {
|
||||
return "fail4"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
function A(c) {
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
A.g = 3;
|
||||
A.c = "hoooray";
|
||||
@@ -0,0 +1,18 @@
|
||||
package foo
|
||||
|
||||
@native
|
||||
class A(val c: Int) {
|
||||
@native
|
||||
companion object {
|
||||
val g: Int = noImpl
|
||||
val c: String = noImpl
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (A.g != 3) return "fail1"
|
||||
if (A.c != "hoooray") return "fail2"
|
||||
if (A(2).c != 2) return "fail3"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package foo
|
||||
|
||||
val top = "TOP LEVEL"
|
||||
|
||||
fun box(): String {
|
||||
// Does't work in Rhino, but should.
|
||||
// val v = 1
|
||||
// assertEquals(3, eval("v + 2"))
|
||||
|
||||
assertEquals(5, eval("3 + 2"))
|
||||
|
||||
val PACKAGE = "kotlin.modules.JS_TESTS.foo"
|
||||
assertEquals(top, eval("$PACKAGE.top"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
function A(a) {
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
A.prototype.g = function () {
|
||||
return 2 * this.a;
|
||||
};
|
||||
|
||||
A.prototype.m = function () {
|
||||
return this.a - 1;
|
||||
};
|
||||
|
||||
A.prototype.foo = function (i) {
|
||||
return "A.foo(" + i + ")";
|
||||
};
|
||||
|
||||
A.prototype.boo = function (i) {
|
||||
return "A.boo(" + i + ")";
|
||||
};
|
||||
|
||||
A.prototype.bar = function (i) {
|
||||
return "A.bar(" + i + ")";
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package foo
|
||||
|
||||
@native
|
||||
internal 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
|
||||
}
|
||||
|
||||
internal 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,42 @@
|
||||
package foo
|
||||
|
||||
@native
|
||||
interface NativeTrait {
|
||||
val foo: String
|
||||
fun bar(a: Int): Any
|
||||
|
||||
@native("boo")
|
||||
fun baz(): String
|
||||
}
|
||||
|
||||
interface Trait : NativeTrait
|
||||
|
||||
class Class : NativeTrait {
|
||||
override val foo: String = "Class().foo"
|
||||
override fun bar(a: Int): Any = "Class().bar($a)"
|
||||
override fun baz(): String = "Class().boo()"
|
||||
}
|
||||
|
||||
class AnotherClass : Trait {
|
||||
override val foo: String = "AnotherClass().foo"
|
||||
override fun bar(a: Int): Any = "AnotherClass().bar($a)"
|
||||
override fun baz(): String = "AnotherClass().boo()"
|
||||
}
|
||||
|
||||
fun <T : NativeTrait> test(c: T, className: String) {
|
||||
assertEquals("$className().foo", c.foo)
|
||||
assertEquals("$className().bar(3)", c.bar(3))
|
||||
assertEquals("$className().boo()", c.baz())
|
||||
|
||||
val t: NativeTrait = c
|
||||
assertEquals("$className().foo", t.foo)
|
||||
assertEquals("$className().bar(3)", t.bar(3))
|
||||
assertEquals("$className().boo()", t.baz())
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(Class(), "Class")
|
||||
test(AnotherClass(), "AnotherClass")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
function Wow() {
|
||||
this.x = 1;
|
||||
this.y = 2;
|
||||
}
|
||||
|
||||
Wow.prototype.sum = function () {
|
||||
return this.x + this.y;
|
||||
};
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package foo
|
||||
|
||||
@native
|
||||
class Wow() {
|
||||
val x: Int = noImpl
|
||||
val y: Int = noImpl
|
||||
}
|
||||
|
||||
@native
|
||||
fun Wow.sum(): Int = noImpl
|
||||
|
||||
fun Wow.dblSum(): Int {
|
||||
return 2 * sum()
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
return if (Wow().dblSum() == 6) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
var chrome = {extension: {lastError:null}};
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
@native
|
||||
interface Chrome {
|
||||
val extension: Extension
|
||||
}
|
||||
|
||||
@native
|
||||
interface Extension {
|
||||
val lastError: LastError?
|
||||
}
|
||||
|
||||
@native
|
||||
interface LastError {
|
||||
val message: String
|
||||
}
|
||||
|
||||
@native
|
||||
val chrome: Chrome = noImpl
|
||||
|
||||
fun box(): String {
|
||||
val lastError = chrome.extension.lastError?.message
|
||||
return if (lastError == null) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
var classes = {"answer": 42}, classesMutable = {};
|
||||
+13
@@ -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(): String {
|
||||
classesMutable.set("why", "?")
|
||||
return if (classes.get("answer") == 42 && classesMutable.get("why") == "?") "OK" else "fail"
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
(function () {
|
||||
var c = 0;
|
||||
|
||||
kotlin.A = kotlin.createClassNow(null,
|
||||
function () {
|
||||
this.f = function (i) {
|
||||
if (i === undefined && c === 0) {
|
||||
c = 1;
|
||||
}
|
||||
if (i === 2 && c === 1) {
|
||||
c = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
kotlin.getResult = function () {
|
||||
return c === 2;
|
||||
};
|
||||
})();
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package foo
|
||||
|
||||
@library class A() {
|
||||
@library fun f() {
|
||||
}
|
||||
@library fun f(a: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
@library fun getResult() = false
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
a.f()
|
||||
a.f(2)
|
||||
return if (getResult()) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
function A(value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
A.prototype.bar = function() { return "A.bar " + this.value; };
|
||||
@@ -0,0 +1,40 @@
|
||||
package foo
|
||||
|
||||
@native
|
||||
open class A(val value: String) {
|
||||
}
|
||||
|
||||
class B : A("B") {
|
||||
fun bar(): String = "B.bar ${value}"
|
||||
var prop: String = "B prop"
|
||||
}
|
||||
|
||||
@native fun A.bar(): String = noImpl
|
||||
|
||||
@native var A.prop: String
|
||||
get() = noImpl
|
||||
set(value) = noImpl
|
||||
|
||||
fun box(): String {
|
||||
var a: A = A("A")
|
||||
val b: B = B()
|
||||
|
||||
assertEquals("A.bar A", a.bar())
|
||||
assertEquals("B.bar B", b.bar())
|
||||
|
||||
assertEquals("A.bar A", (A::bar)(a))
|
||||
assertEquals("B.bar B", (A::bar)(b))
|
||||
|
||||
a.prop = "prop"
|
||||
assertEquals("prop", a.prop)
|
||||
assertEquals("prop", (A::prop).get(a))
|
||||
|
||||
a = b
|
||||
assertEquals("B.bar B", a.bar())
|
||||
assertEquals("B.bar B", (A::bar)(a))
|
||||
|
||||
assertEquals("B prop", a.prop)
|
||||
assertEquals("B prop", (A::prop).get(a))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
function getTestObject() {
|
||||
return {
|
||||
"foo" : "boo",
|
||||
"bar" : 35,
|
||||
0 : "ok",
|
||||
1 : 2
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,92 @@
|
||||
package foo
|
||||
|
||||
@native("Object")
|
||||
class JsObject {
|
||||
@nativeGetter
|
||||
operator fun get(a: String): Any? = noImpl
|
||||
|
||||
@nativeSetter
|
||||
operator fun set(a: String, v: Any?): Unit = noImpl
|
||||
|
||||
@nativeGetter
|
||||
fun take(a: Int): Any? = noImpl
|
||||
|
||||
@nativeSetter
|
||||
fun put(a: Int, v: Any?): Unit = noImpl
|
||||
}
|
||||
|
||||
@nativeGetter
|
||||
operator fun JsObject.get(a: Int): Any? = noImpl
|
||||
|
||||
@nativeSetter
|
||||
operator fun JsObject.set(a: Int, v: Any?): Unit = noImpl
|
||||
|
||||
@nativeGetter
|
||||
fun JsObject.take(a: String): Any? = noImpl
|
||||
|
||||
@nativeSetter
|
||||
fun JsObject.put(a: String, v: Any?): Unit = noImpl
|
||||
|
||||
|
||||
object t{}
|
||||
|
||||
@native
|
||||
fun getTestObject(): JsObject = noImpl
|
||||
|
||||
fun test(obj: JsObject, key: String, oldValue: Any?, newValue: Any) {
|
||||
assertEquals(oldValue, obj[key])
|
||||
obj[key] = newValue
|
||||
assertEquals(newValue, obj[key])
|
||||
obj[key] = null
|
||||
assertEquals(null, obj[key])
|
||||
}
|
||||
|
||||
fun test(obj: JsObject, key: Int, oldValue: Any?, newValue: Any) {
|
||||
assertEquals(oldValue, obj.take(key))
|
||||
obj.put(key, newValue)
|
||||
assertEquals(newValue, obj.take(key))
|
||||
obj.put(key, null)
|
||||
assertEquals(null, obj.take(key))
|
||||
}
|
||||
|
||||
fun testExtensions(obj: JsObject, key: Int, oldValue: Any?, newValue: Any) {
|
||||
assertEquals(oldValue, obj[key])
|
||||
obj[key] = newValue
|
||||
assertEquals(newValue, obj[key])
|
||||
obj[key] = null
|
||||
assertEquals(null, obj[key])
|
||||
}
|
||||
|
||||
fun testExtensions(obj: JsObject, key: String, oldValue: Any?, newValue: Any) {
|
||||
assertEquals(oldValue, obj.take(key))
|
||||
obj.put(key, newValue)
|
||||
assertEquals(newValue, obj.take(key))
|
||||
obj.put(key, null)
|
||||
assertEquals(null, obj.take(key))
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = getTestObject()
|
||||
|
||||
test(a, "foo", "boo", "moo")
|
||||
test(a, "bar", 35, 67)
|
||||
test(a, "baz", undefined, 34)
|
||||
test(a, "qoox", undefined, t)
|
||||
test(a, 0, "ok", "OK!")
|
||||
test(a, 1, 2, 3)
|
||||
test(a, 2, undefined, "HI")
|
||||
test(a, 5, undefined, t)
|
||||
|
||||
val b = getTestObject()
|
||||
|
||||
testExtensions(b, "foo", "boo", "moo")
|
||||
testExtensions(b, "bar", 35, 67)
|
||||
testExtensions(b, "baz", undefined, 34)
|
||||
testExtensions(b, "qoox", undefined, t)
|
||||
testExtensions(b, 0, "ok", "OK!")
|
||||
testExtensions(b, 1, 2, 3)
|
||||
testExtensions(b, 2, undefined, "HI")
|
||||
testExtensions(b, 5, undefined, t)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package foo
|
||||
|
||||
@native
|
||||
class Function(vararg argsAndCode: String) {
|
||||
@nativeInvoke
|
||||
operator fun invoke(a: Any?): Any? = noImpl
|
||||
|
||||
@nativeInvoke
|
||||
fun baz(a: Any?, b: Any?): Any? = noImpl
|
||||
}
|
||||
|
||||
@nativeInvoke
|
||||
operator fun Function.invoke(a: Any?, b: Any?): Any? = noImpl
|
||||
|
||||
@nativeInvoke
|
||||
fun Function.bar(a: Any?, b: Any?): Any? = noImpl
|
||||
|
||||
object t{}
|
||||
|
||||
fun box(): String {
|
||||
val f = Function("a", "return a")
|
||||
val g = Function("a", "b", "return a + b")
|
||||
|
||||
assertEquals(1, f(1))
|
||||
assertEquals("ok", f("ok"))
|
||||
assertEquals(t, f(t))
|
||||
|
||||
assertEquals(5, g(1, 4))
|
||||
assertEquals("ok34", g("ok", 34))
|
||||
|
||||
assertEquals(5, g.baz(1, 4))
|
||||
assertEquals("ok34", g.baz("ok", 34))
|
||||
|
||||
assertEquals(5, g.bar(1, 4))
|
||||
assertEquals("ok34", g.bar("ok", 34))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
var boo = "K";
|
||||
@@ -0,0 +1,34 @@
|
||||
package foo
|
||||
|
||||
internal val PACKAGE = "kotlin.modules.JS_TESTS.foo"
|
||||
|
||||
internal fun funToString(name: String) = eval("$PACKAGE.$name.toString()") as String
|
||||
|
||||
internal @native("\"O\"") val foo: String = noImpl
|
||||
internal @native("boo") val bar: String = noImpl
|
||||
|
||||
internal class A
|
||||
internal @native("__proto__") val Any.proto: String get() = noImpl
|
||||
internal @native("__proto__") val A.proto: String get() = noImpl
|
||||
|
||||
internal fun actual(foo: String, @native("boo") bar: String) = foo + bar
|
||||
internal 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,66 @@
|
||||
var Object = createTestObject("Object", 23);
|
||||
extend(Object, {
|
||||
Object: extend(createTestObject("Object.Object", 123), { AnotherClass : createTestClass("Object.Object.Class", 42, 142) }),
|
||||
Class: createTestClass("Object.Class", 42, 142),
|
||||
Trait : createTestObject("Object.Trait", 324),
|
||||
a: createTestObject("Object.a", 34)
|
||||
});
|
||||
|
||||
var SomeClass = function () {};
|
||||
extend(SomeClass, createTestObject("Class", 77));
|
||||
extend(SomeClass, {
|
||||
Object: createTestObject("Class.Object", 55),
|
||||
Class: createTestClass("Class.Class", 66, 88),
|
||||
InnerClass: createTestInnerClass("Class.InnerClass", 57),
|
||||
Trait: createTestObject("Class.Trait", 55),
|
||||
aaa: createTestObject("Class.a", 22)
|
||||
});
|
||||
|
||||
var Trait = createTestObject("Trait", 277);
|
||||
extend(Trait, {
|
||||
SomeObject: createTestObject("Trait.Object", 90),
|
||||
Class: createTestClass("Trait.Class", 66, 88),
|
||||
SomeTrait: createTestObject("Trait.Trait", 55),
|
||||
a: createTestObject("Trait.a", 22)
|
||||
});
|
||||
|
||||
// Helpers
|
||||
|
||||
function extend(destination, source) {
|
||||
for (var property in source) {
|
||||
if (source.hasOwnProperty(property)) {
|
||||
destination[property] = source[property];
|
||||
}
|
||||
}
|
||||
return destination;
|
||||
}
|
||||
|
||||
function createTestClass(fqName, memberFunResult, staticFunResult) {
|
||||
function Class(a) {
|
||||
this.a = a;
|
||||
this.b = fqName + "().b"
|
||||
}
|
||||
|
||||
Class.prototype.test = function () { return memberFunResult };
|
||||
|
||||
extend(Class, createTestObject(fqName, staticFunResult));
|
||||
|
||||
return Class;
|
||||
}
|
||||
|
||||
function createTestInnerClass(fqName, memberFunResult) {
|
||||
function Class(parent, a) {
|
||||
this.a = a;
|
||||
this.b = fqName + "().b"
|
||||
}
|
||||
|
||||
Class.prototype.test = function () { return memberFunResult };
|
||||
}
|
||||
|
||||
function createTestObject(fqName, funResult) {
|
||||
return {
|
||||
a: fqName + ".a",
|
||||
b: fqName + ".b",
|
||||
test: function () { return funResult }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
// in object
|
||||
|
||||
assertEquals("Object.Object.a", Object.Object.a)
|
||||
assertEquals("Object.Object.b", Object.Object.b)
|
||||
assertEquals(123, Object.Object.test())
|
||||
|
||||
assertEquals("Object.Object.Class().a", Object.Object.Class("Object.Object.Class().a").a)
|
||||
assertEquals("Object.Object.Class().b", Object.Object.Class("something").b)
|
||||
assertEquals(42, Object.Object.Class("something").test())
|
||||
assertEquals("Object.Object.Class.a", Object.Object.Class.a)
|
||||
assertEquals("Object.Object.Class.b", Object.Object.Class.b)
|
||||
assertEquals(142, Object.Object.Class.test())
|
||||
|
||||
assertEquals("Object.Class().a", Object.Class("Object.Class().a").a)
|
||||
assertEquals("Object.Class().b", Object.Class("something").b)
|
||||
assertEquals(42, Object.Class("something").test())
|
||||
assertEquals("Object.Class.a", Object.Class.a)
|
||||
assertEquals("Object.Class.b", Object.Class.b)
|
||||
assertEquals(142, Object.Class.test())
|
||||
|
||||
assertEquals("Object.Trait.a", Object.Trait.a)
|
||||
assertEquals("Object.Trait.b", Object.Trait.b)
|
||||
assertEquals(324, Object.Trait.test())
|
||||
|
||||
assertEquals("Object.a.a", Object.a.a)
|
||||
assertEquals("Object.a.b", Object.a.b)
|
||||
assertEquals(34, Object.a.test())
|
||||
assertEquals("Object.b", Object.b)
|
||||
assertEquals(23, Object.test())
|
||||
|
||||
// in class
|
||||
|
||||
assertEquals("Class.Object.a", Class.Object.a)
|
||||
assertEquals("Class.Object.b", Class.Object.b)
|
||||
assertEquals(55, Class.Object.test())
|
||||
|
||||
assertEquals("Class.Class().a", Class.Class("Class.Class().a").a)
|
||||
assertEquals("Class.Class().b", Class.Class("something").b)
|
||||
assertEquals(66, Class.Class("something").test())
|
||||
assertEquals("Class.Class.a", Class.Class.a)
|
||||
assertEquals("Class.Class.b", Class.Class.b)
|
||||
assertEquals(88, Class.Class.test())
|
||||
|
||||
//TODO inner class
|
||||
// assertEquals("Class.InnerClass().a", Class().InnerClass("Class.InnerClass().a").a)
|
||||
// assertEquals("Class.InnerClass().b", Class().InnerClass("something").b)
|
||||
// assertEquals(66, Class().InnerClass("something").test())
|
||||
|
||||
assertEquals("Class.Trait.a", Class.Trait.a)
|
||||
assertEquals("Class.Trait.b", Class.Trait.b)
|
||||
assertEquals(55, Class.Trait.test())
|
||||
|
||||
assertEquals("Class.a.a", Class.a.a)
|
||||
assertEquals("Class.a.b", Class.a.b)
|
||||
assertEquals(22, Class.a.test())
|
||||
assertEquals("Class.b", Class.b)
|
||||
assertEquals(77, Class.test())
|
||||
|
||||
// in trit
|
||||
|
||||
assertEquals("Trait.Object.a", Trait.Object.a)
|
||||
assertEquals("Trait.Object.b", Trait.Object.b)
|
||||
assertEquals(90, Trait.Object.test())
|
||||
|
||||
assertEquals("Trait.Class().a", Trait.Class("Trait.Class().a").a)
|
||||
assertEquals("Trait.Class().b", Trait.Class("something").b)
|
||||
assertEquals(66, Trait.Class("something").test())
|
||||
assertEquals("Trait.Class.a", Trait.Class.a)
|
||||
assertEquals("Trait.Class.b", Trait.Class.b)
|
||||
assertEquals(88, Trait.Class.test())
|
||||
|
||||
assertEquals("Trait.Trait.a", Trait.Trait.a)
|
||||
assertEquals("Trait.Trait.b", Trait.Trait.b)
|
||||
assertEquals(55, Trait.Trait.test())
|
||||
|
||||
assertEquals("Trait.a.a", Trait.a.a)
|
||||
assertEquals("Trait.a.b", Trait.a.b)
|
||||
assertEquals(22, Trait.a.test())
|
||||
assertEquals("Trait.b", Trait.b)
|
||||
assertEquals(277, Trait.test())
|
||||
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@native
|
||||
object Object {
|
||||
object Object {
|
||||
val a: String = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
|
||||
@native("AnotherClass")
|
||||
class Class(val a: String) {
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
|
||||
companion object {
|
||||
val a: String = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Class(val a: String) {
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
|
||||
companion object {
|
||||
val a: String = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
}
|
||||
}
|
||||
|
||||
interface Trait {
|
||||
val a: String
|
||||
var b: String
|
||||
fun test(): Int = noImpl
|
||||
|
||||
companion object {
|
||||
val a: String = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
}
|
||||
}
|
||||
|
||||
val a: Trait = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
}
|
||||
|
||||
@native("SomeClass")
|
||||
class Class {
|
||||
object Object {
|
||||
val a: String = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
}
|
||||
|
||||
class Class(val a: String) {
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
|
||||
companion object {
|
||||
val a: String = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
}
|
||||
}
|
||||
|
||||
inner class InnerClass(val a: String) {
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
}
|
||||
|
||||
interface Trait {
|
||||
val a: String
|
||||
var b: String
|
||||
fun test(): Int = noImpl
|
||||
|
||||
companion object {
|
||||
val a: String = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@native("aaa")
|
||||
val a: Trait = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
}
|
||||
}
|
||||
|
||||
@native
|
||||
interface Trait {
|
||||
@native("SomeObject")
|
||||
object Object {
|
||||
val a: String = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
}
|
||||
|
||||
class Class(val a: String) {
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
|
||||
companion object {
|
||||
val a: String = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
}
|
||||
}
|
||||
|
||||
@native("SomeTrait")
|
||||
interface Trait {
|
||||
val a: String
|
||||
var b: String
|
||||
fun test(): Int = noImpl
|
||||
|
||||
companion object {
|
||||
val a: String = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val a: Trait = noImpl
|
||||
var b: String = noImpl
|
||||
fun test(): Int = noImpl
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
function A(v) {
|
||||
this.v = v;
|
||||
}
|
||||
|
||||
function nativeBox(b) {
|
||||
return b.bar(new A("foo"), function(i, s) { return "" + this.v + s + i })
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package foo
|
||||
|
||||
@native
|
||||
internal class A(val v: String)
|
||||
|
||||
internal class B {
|
||||
fun bar(a: A, extLambda: A.(Int, String) -> String): String = a.extLambda(7, "_rr_")
|
||||
}
|
||||
|
||||
@native
|
||||
internal fun nativeBox(b: B): String = noImpl
|
||||
|
||||
fun box(): String {
|
||||
val r = nativeBox(B())
|
||||
if (r != "foo_rr_7") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
function A(v) {
|
||||
this.v = v;
|
||||
}
|
||||
|
||||
function bar(a, extLambda) {
|
||||
return extLambda.call(a, 4, "boo")
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package foo
|
||||
|
||||
@native
|
||||
class A(val v: String)
|
||||
|
||||
@native
|
||||
fun bar(a: A, extLambda: A.(Int, String) -> String): String = noImpl
|
||||
|
||||
fun box(): String {
|
||||
val a = A("test")
|
||||
|
||||
val r = bar(a) { i, s -> "${this.v} $i $s"}
|
||||
if (r != "test 4 boo") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
function A(v) {
|
||||
this.v = v;
|
||||
this.m = function (i, s) {
|
||||
return "A.m " + v + " " + i + " " + s;
|
||||
}
|
||||
}
|
||||
|
||||
A.prototype.nativeExt = function (i, s) {
|
||||
return "nativeExt " + this.v + " " + i + " " + s;
|
||||
};
|
||||
|
||||
A.prototype.nativeExt2AnotherName = function (i, s) {
|
||||
return "nativeExt2 " + this.v + " " + i + " " + s;
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
package foo
|
||||
|
||||
@native
|
||||
class A(val v: String) {
|
||||
fun m(i:Int, s:String): String = noImpl
|
||||
}
|
||||
@native
|
||||
fun A.nativeExt(i:Int, s:String): String = noImpl
|
||||
|
||||
@native("nativeExt2AnotherName")
|
||||
fun A.nativeExt2(i:Int, s:String): String = noImpl
|
||||
|
||||
fun bar(a: A, extLambda: A.(Int, String) -> String): String = a.(extLambda)(4, "boo")
|
||||
|
||||
fun box(): String {
|
||||
val a = A("test")
|
||||
|
||||
assertEquals("A.m test 4 boo", a.m(4, "boo"))
|
||||
assertEquals("A.m test 4 boo", bar(a, fun A.(i, s) = (A::m)(this, i, s)))
|
||||
|
||||
assertEquals("nativeExt test 4 boo", a.nativeExt(4, "boo"))
|
||||
assertEquals("nativeExt test 4 boo", bar(a, fun A.(i, s) = (A::nativeExt)(this, i, s)))
|
||||
|
||||
assertEquals("nativeExt2 test 4 boo", a.nativeExt2(4, "boo"))
|
||||
assertEquals("nativeExt2 test 4 boo", bar(a, fun A.(i, s) = (A::nativeExt2)(this, i, s)))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
function bar(a, extLambda) {
|
||||
return extLambda.call(a, 4, "boo")
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package foo
|
||||
|
||||
open class A(val v: String) {
|
||||
open fun m(i:Int, s:String): String = "A.m ${this.v} $i $s"
|
||||
}
|
||||
|
||||
class B(v: String): A(v) {
|
||||
override fun m(i:Int, s:String): String = "B.m ${this.v} $i $s"
|
||||
}
|
||||
|
||||
@native
|
||||
fun bar(a: A, extLambda: A.(Int, String) -> String): String = noImpl
|
||||
|
||||
fun A.topLevelExt(i:Int, s:String): String = "A::topLevelExt ${this.v} $i $s"
|
||||
|
||||
fun box(): String {
|
||||
val a = A("test")
|
||||
|
||||
var r = bar(a) { i, s -> "${this.v} $i $s"}
|
||||
if (r != "test 4 boo") return r
|
||||
|
||||
fun A.LocalExt(i:Int, s:String): String = "A::LocalExt ${this.v} $i $s"
|
||||
|
||||
r = bar(a, fun A.(i, s) = (A::topLevelExt)(this, i, s))
|
||||
if (r != "A::topLevelExt test 4 boo") return r
|
||||
|
||||
r = bar(a, fun A.(i, s) = (A::LocalExt)(this, i, s))
|
||||
if (r != "A::LocalExt test 4 boo") return r
|
||||
|
||||
r = bar(a, fun A.(i, s) = (A::m)(this, i, s))
|
||||
if (r != "A.m test 4 boo") return r
|
||||
|
||||
val b = B("test")
|
||||
r = bar(b, fun A.(i, s) = (A::m)(this, i, s))
|
||||
if (r != "B.m test 4 boo") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
function nativeFun(i, s) {
|
||||
return "nativeFun " + i + " " + s;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package foo
|
||||
|
||||
@native
|
||||
fun nativeFun(i:Int, s:String): String = noImpl
|
||||
|
||||
fun bar(funRef: (Int, String) -> String): String = funRef(4, "boo")
|
||||
|
||||
fun box(): String {
|
||||
var r = nativeFun(4, "boo")
|
||||
if (r != "nativeFun 4 boo") return r
|
||||
|
||||
r = bar(::nativeFun)
|
||||
if (r != "nativeFun 4 boo") return r
|
||||
|
||||
r = (::nativeFun)(4, "boo")
|
||||
if (r != "nativeFun 4 boo") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
function run(arg0, arg1, funRef) {
|
||||
return funRef(arg0, arg1)
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
@native
|
||||
fun run(i:Int, s:String, funRef: (Int, String) -> String): String = noImpl
|
||||
|
||||
fun funTopLevel(i:Int, s:String): String = "funTopLevel $i $s"
|
||||
|
||||
fun box(): String {
|
||||
fun funLocal(i:Int, s:String): String = "funLocal $i $s"
|
||||
|
||||
// Check for lambda
|
||||
var r = run(4, "boo") { i, s -> "$i $s"}
|
||||
if (r != "4 boo") return r
|
||||
|
||||
r = run(4, "boo", ::funTopLevel)
|
||||
if (r != "funTopLevel 4 boo") return r
|
||||
|
||||
r = run(4, "boo", ::funLocal)
|
||||
if (r != "funLocal 4 boo") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
var buffer = "";
|
||||
|
||||
function writeToBuffer(a) {
|
||||
var type = typeof a;
|
||||
if (type !== "string") throw Error("Expected string argument type, but got: " + type);
|
||||
|
||||
buffer += a;
|
||||
}
|
||||
|
||||
function writelnToBuffer(a) {
|
||||
writeToBuffer(a);
|
||||
writeToBuffer("\n");
|
||||
}
|
||||
|
||||
var GLOBAL = (0, eval)("this");
|
||||
|
||||
GLOBAL.console = {
|
||||
log: writelnToBuffer
|
||||
};
|
||||
|
||||
GLOBAL.outputStream = {
|
||||
write: writeToBuffer
|
||||
};
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package foo
|
||||
|
||||
val EXPECTED = """Hello, World
|
||||
|
||||
***
|
||||
####
|
||||
"""
|
||||
|
||||
val EXPECTED_NEWLINE_FOR_EACH = """Hello
|
||||
, World
|
||||
|
||||
|
||||
|
||||
***
|
||||
##
|
||||
##
|
||||
|
||||
"""
|
||||
|
||||
@native
|
||||
var buffer: String = noImpl
|
||||
|
||||
fun test(expected: String, initCode: String, getResult: () -> String) {
|
||||
buffer = ""
|
||||
|
||||
eval("kotlin.out = new $initCode")
|
||||
|
||||
print("Hello")
|
||||
print(", World")
|
||||
print("\n")
|
||||
println()
|
||||
println("***")
|
||||
print("##")
|
||||
print("##")
|
||||
println()
|
||||
|
||||
val actual = getResult()
|
||||
|
||||
assertEquals(expected, actual, initCode)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(EXPECTED, "kotlin.NodeJsOutput(outputStream)") {
|
||||
buffer
|
||||
}
|
||||
|
||||
test(EXPECTED_NEWLINE_FOR_EACH, "kotlin.OutputToConsoleLog()") {
|
||||
buffer
|
||||
}
|
||||
|
||||
test(EXPECTED, "kotlin.BufferedOutput()") {
|
||||
eval("kotlin.out.buffer") as String
|
||||
}
|
||||
|
||||
test(EXPECTED, "kotlin.BufferedOutputToConsoleLog()") {
|
||||
buffer
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
function A(value) {
|
||||
this.value = value
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
@native
|
||||
class A {
|
||||
constructor()
|
||||
constructor(s: String)
|
||||
constructor(i: Int)
|
||||
|
||||
val value: Any?
|
||||
}
|
||||
|
||||
fun test(a: A, expectedValue: Any?, expectedTypeOfValue: String) {
|
||||
assertTrue(a is A)
|
||||
assertEquals(expectedValue, a.value)
|
||||
assertEquals(expectedTypeOfValue, jsTypeOf(a.value))
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(A(), undefined, "undefined")
|
||||
test(A("foo"), "foo", "string")
|
||||
test(A(124), 124, "number")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
function returnFalse() {
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package foo
|
||||
|
||||
@native
|
||||
fun returnFalse(): Boolean = noImpl
|
||||
|
||||
fun box() = if (!returnFalse()) "OK" else "fail"
|
||||
@@ -0,0 +1 @@
|
||||
var c = undefined;
|
||||
@@ -0,0 +1,9 @@
|
||||
package foo
|
||||
|
||||
@native
|
||||
val c: Any? = noImpl
|
||||
|
||||
fun box(): String {
|
||||
if (c != null) return "fail1"
|
||||
return if (c == null) "OK" else "fail2"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package foo
|
||||
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("number", jsTypeOf(1))
|
||||
assertEquals("number", jsTypeOf(1.2))
|
||||
assertEquals("boolean", jsTypeOf(true))
|
||||
assertEquals("string", jsTypeOf("sss"))
|
||||
assertEquals("object", jsTypeOf(null))
|
||||
assertEquals("undefined", jsTypeOf(undefined))
|
||||
assertEquals("object", jsTypeOf(object {}))
|
||||
assertEquals("object", jsTypeOf(A()))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(eval("undefined"), undefined)
|
||||
assertEquals(js("undefined"), undefined)
|
||||
|
||||
assertNotEquals(1, undefined)
|
||||
assertNotEquals("sss", undefined)
|
||||
assertNotEquals(object {}, undefined)
|
||||
|
||||
val a: dynamic = 1
|
||||
assertEquals(a.foo, undefined)
|
||||
assertNotEquals(a.toString, undefined)
|
||||
|
||||
val b: dynamic = object {val bar = ""}
|
||||
assertEquals(b.foo, undefined)
|
||||
assertNotEquals(b.bar, undefined)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
function paramCount() {
|
||||
return arguments.length
|
||||
}
|
||||
|
||||
function Bar(size, order) {
|
||||
this.size = size;
|
||||
Bar.checkOrder(order);
|
||||
}
|
||||
|
||||
Bar.order = 0;
|
||||
Bar.hasOrderProblem = false;
|
||||
Bar.checkOrder = function (expectedOrder) {
|
||||
var curOrder = Bar.order++;
|
||||
Bar.hasOrderProblem = Bar.hasOrderProblem || curOrder !== expectedOrder;
|
||||
};
|
||||
|
||||
Bar.startNewTest = function () {
|
||||
Bar.hasOrderProblem = false;
|
||||
Bar.order = 0;
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
Bar.prototype.test = function (order, dummy /*, args */) {
|
||||
Bar.checkOrder(order);
|
||||
return dummy === 1 && (arguments.length - 2) === this.size;
|
||||
};
|
||||
Bar.prototype.test2 = Bar.prototype.test;
|
||||
|
||||
function test3(bar, dummy /*, args */) {
|
||||
return dummy === 1 && (arguments.length - 2) === bar.size;
|
||||
}
|
||||
|
||||
var obj = {
|
||||
test: function (size /*, args */) {
|
||||
return (arguments.length - 1) === size;
|
||||
}
|
||||
};
|
||||
|
||||
function testNativeVarargWithFunLit(/* args, f */) {
|
||||
var args = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
|
||||
var f = arguments[arguments.length - 1];
|
||||
return typeof f === "function" && f(args);
|
||||
}
|
||||
|
||||
function sumOfParameters() {
|
||||
var size = arguments.length;
|
||||
var result = 0;
|
||||
for (var i = 0; i < size; i++) {
|
||||
result += arguments[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function sumFunValuesOnParameters() {
|
||||
var size = arguments.length - 1;
|
||||
var f = arguments[arguments.length - 1];
|
||||
var result = 0;
|
||||
for (var i = 0; i < size; i++) {
|
||||
var u = arguments[i];
|
||||
result += f(u);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function idArrayVarArg() {
|
||||
var args = Array.prototype.slice.call(arguments, 0, arguments.length);
|
||||
return args;
|
||||
}
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
package foo
|
||||
|
||||
@native
|
||||
fun paramCount(vararg a: Int): Int = noImpl
|
||||
|
||||
@native("paramCount")
|
||||
fun anotherParamCount(vararg a: Int): Int = noImpl
|
||||
|
||||
@native("paramCount")
|
||||
fun <T> genericParamCount(vararg a: T): Int = 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 = noImpl
|
||||
|
||||
@native
|
||||
fun Bar.test2(order: Int, dummy: Int, vararg args: Int): Boolean = noImpl
|
||||
|
||||
@native
|
||||
class Bar(val size: Int, order: Int = 0) {
|
||||
fun test(order: Int, dummy: Int, vararg args: Int): Boolean = noImpl
|
||||
companion object {
|
||||
fun startNewTest(): Boolean = noImpl
|
||||
var hasOrderProblem: Boolean = false
|
||||
}
|
||||
}
|
||||
|
||||
@native
|
||||
object obj {
|
||||
fun test(size: Int, vararg args: Int): Boolean = 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 = 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
|
||||
|
||||
@native
|
||||
fun sumOfParameters(x: Int, y: Int, vararg a: Int): Int = noImpl
|
||||
|
||||
@native
|
||||
fun sumFunValuesOnParameters(x: Int, y: Int, vararg a: Int, f: (Int) -> Int): Int = noImpl
|
||||
|
||||
@native
|
||||
fun <T> idArrayVarArg(vararg a: Array<T>): Array<T> = noImpl
|
||||
|
||||
fun box(): String {
|
||||
if (paramCount() != 0)
|
||||
return "failed when call native function without args"
|
||||
|
||||
if (paramCount(1) != 1) return "failed when call native function with single vararg"
|
||||
|
||||
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 (!Bar(1).test(0, 1, 1))
|
||||
return "failed when call method with single arg"
|
||||
|
||||
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"
|
||||
|
||||
val a = arrayOf(1, 2)
|
||||
assertEquals(2, genericParamCount(*a))
|
||||
assertEquals(7, genericParamCount(1, *a, *a, 1, 2))
|
||||
|
||||
assertEquals(45, sumOfParameters(1, 2, 3, 4, 5, 6, 7, 8, 9))
|
||||
assertEquals(45, sumOfParameters(1, 2, *intArrayOf(3, 4, 5, 6, 7, 8, 9)))
|
||||
assertEquals(45, sumOfParameters(1, 2, 3, 4, *intArrayOf(5, 6, 7, 8, 9)))
|
||||
assertEquals(90, sumFunValuesOnParameters(1, 2, 3, 4, 5, 6, 7, 8, 9) { 2*it })
|
||||
assertEquals(90, sumFunValuesOnParameters(1, 2, *intArrayOf(3, 4, 5, 6, 7, 8, 9)) { 2*it })
|
||||
assertEquals(90, sumFunValuesOnParameters(1, 2, 3, 4, *intArrayOf(5, 6, 7, 8, 9)) { 2*it })
|
||||
assertEquals(90, sumFunValuesOnParameters(1, 2, *intArrayOf(3, 4, 5, 6, 7), 8, 9) { 2*it })
|
||||
assertEquals(90, sumFunValuesOnParameters(1, 2, *intArrayOf(3, 4, 5), *intArrayOf(6, 7, 8, 9)) { 2*it })
|
||||
assertEquals(90, sumFunValuesOnParameters(1, 2, *intArrayOf(3, 4), 5, 6, *intArrayOf(7, 8, 9)) { 2*it })
|
||||
|
||||
assertEquals(2, idArrayVarArg(arrayOf(1), *arrayOf(arrayOf(2, 3, 4))).size)
|
||||
assertEquals(3, idArrayVarArg(arrayOf(1, 2), *arrayOf(arrayOf(3, 4), arrayOf(5, 6))).size)
|
||||
assertEquals(6, idArrayVarArg(arrayOf(1, 2), *arrayOf(arrayOf(3, 4), arrayOf(5, 6)), arrayOf(7), *arrayOf(arrayOf(8, 9), arrayOf(10, 11))).size)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user