JS: move more test to box tests
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
|
||||
package lib
|
||||
|
||||
object O {
|
||||
val x = "O"
|
||||
|
||||
val y = "K"
|
||||
}
|
||||
|
||||
class C {
|
||||
typealias B = O
|
||||
}
|
||||
|
||||
typealias A = O
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
package foo
|
||||
|
||||
import lib.*
|
||||
|
||||
fun box() = A.x + C.B.y
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// FILE: a.kt
|
||||
package foo
|
||||
|
||||
import bar.*
|
||||
|
||||
open class A() {
|
||||
open fun f() = 3;
|
||||
}
|
||||
|
||||
open class C() : B() {
|
||||
override fun f() = 5
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (A().f() != 3) return "fail1"
|
||||
if (B().f() != 4) return "fail2"
|
||||
if (C().f() != 5) return "fail3"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// FILE: b.kt
|
||||
package bar
|
||||
|
||||
import foo.A
|
||||
|
||||
open class B() : A() {
|
||||
override fun f() = 4
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// FILE: a.kt
|
||||
package a.foo
|
||||
|
||||
fun box() = (b.foo.A().tadada(b.foo.A()))
|
||||
|
||||
|
||||
// FILE: b.kt
|
||||
package b.foo
|
||||
|
||||
class A() {
|
||||
fun tadada(a: A) = "OK"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// FILE: a.kt
|
||||
package a.foo
|
||||
|
||||
import b.foo.*
|
||||
|
||||
fun box() = (A().tadada(A()))
|
||||
|
||||
|
||||
// FILE: b.kt
|
||||
package b.foo
|
||||
|
||||
class A() {
|
||||
fun tadada(a: A) = "OK"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// FILE: a.kt
|
||||
package bar
|
||||
|
||||
fun f() = 3;
|
||||
|
||||
|
||||
// FILE: b.kt
|
||||
package foo
|
||||
|
||||
import bar.*
|
||||
|
||||
fun box() = if (f() == 3) "OK" else "fail"
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// FILE: a.kt
|
||||
package a.foo
|
||||
|
||||
fun box() = b.bar.f()
|
||||
|
||||
|
||||
// FILE: b.kt
|
||||
package b.bar
|
||||
|
||||
fun f() = "OK"
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// FILE: a.kt
|
||||
package foo
|
||||
|
||||
val a = 2
|
||||
|
||||
fun box() = if ((a + bar.a) == 5) "OK" else "fail"
|
||||
|
||||
|
||||
// FILE: b.kt
|
||||
package bar
|
||||
|
||||
val a = 3
|
||||
@@ -0,0 +1,55 @@
|
||||
// FILE: a.kt
|
||||
package bar
|
||||
|
||||
fun topLevelFun(s: String) = "topLevelFun: ${s}";
|
||||
|
||||
var topLevelVar = 100
|
||||
|
||||
val topLevelVal = 200
|
||||
|
||||
class A(val v: String) {
|
||||
fun memA(s: String) = "memA: ${v} ${s}"
|
||||
var propVar: Int = 1000
|
||||
val propVal: Int = 2000
|
||||
var text: String = "text"
|
||||
}
|
||||
|
||||
fun A.ext1(s: String): String = "A.ext1: ${this.v} ${s}"
|
||||
|
||||
var A.extProp: String
|
||||
get() = "${this.text}"
|
||||
set(value) {
|
||||
this.text = value
|
||||
}
|
||||
|
||||
|
||||
// FILE: b.kt
|
||||
package foo
|
||||
|
||||
import bar.*
|
||||
|
||||
fun A.ext2(s: String): String = "A.ext2: ${this.v} ${s}"
|
||||
|
||||
fun box(): String {
|
||||
|
||||
assertEquals("topLevelFun: A", (::topLevelFun)("A"))
|
||||
assertEquals("A.ext1: test B", (A::ext1)(A("test"), "B"))
|
||||
assertEquals("A.ext2: test B", (A::ext2)(A("test"), "B"))
|
||||
assertEquals("memA: test C", (A::memA)(A("test"), "C"))
|
||||
|
||||
assertEquals(100, ::topLevelVar.get())
|
||||
::topLevelVar.set(500)
|
||||
assertEquals(500, ::topLevelVar.get())
|
||||
assertEquals(200, ::topLevelVal.get())
|
||||
val a = A("test")
|
||||
assertEquals(1000, (A::propVar).get(a))
|
||||
A::propVar.set(a, 5000)
|
||||
assertEquals(5000, (A::propVar).get(a))
|
||||
assertEquals(2000, (A::propVal).get(a))
|
||||
|
||||
assertEquals("text", (A::extProp).get(a))
|
||||
(A::extProp).set(a, "new text")
|
||||
assertEquals("new text", (A::extProp).get(a))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// FILE: a.kt
|
||||
package a.foo
|
||||
|
||||
fun box() = if (b.foo.f() == 1) "OK" else "fail"
|
||||
|
||||
|
||||
// FILE: b.kt
|
||||
package b.foo
|
||||
|
||||
fun f() = 1
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// FILE: a.kt
|
||||
package a.foo
|
||||
|
||||
import b.foo.f
|
||||
|
||||
fun box() = if (f() == 1) "OK" else "fail"
|
||||
|
||||
|
||||
// FILE: b.kt
|
||||
package b.foo
|
||||
|
||||
fun f() = 1
|
||||
@@ -0,0 +1,10 @@
|
||||
package foo
|
||||
|
||||
class Box<T>(t: T) {
|
||||
var value = t
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val box: Box<Int> = Box<Int>(1)
|
||||
return if (box.value == 1) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package foo
|
||||
|
||||
public fun <T> List<T>.some(): T = this[0]
|
||||
public fun String.some(): Char = this[0]
|
||||
public val <T> List<T>.some: T get() = this[1]
|
||||
public val String.some: Char get() = this[1]
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val data = listOf("foo", "bar")
|
||||
|
||||
assertEquals("foo", data.some())
|
||||
assertEquals("bar", data.some)
|
||||
assertEquals('f', "foo".some())
|
||||
assertEquals('a', "bar".some)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package foo
|
||||
|
||||
class A() {
|
||||
|
||||
fun eval() = 3
|
||||
fun eval(a: Int) = 4
|
||||
fun eval(a: String) = 5
|
||||
fun eval(a: String, b: Int) = 6
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
if (A().eval() != 3) return "fail1"
|
||||
if (A().eval(2) != 4) return "fail2"
|
||||
if (A().eval("3") != 5) return "fail3"
|
||||
if (A().eval("a", 3) != 6) return "fail4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package foo
|
||||
|
||||
interface TraitA
|
||||
interface TraitB
|
||||
|
||||
public open abstract class Node<T : TraitA>() where T : TraitB {
|
||||
public abstract fun bar(arg: T): String
|
||||
public abstract fun bar(arg: TraitA): String
|
||||
public abstract fun bar(arg: TraitB): String
|
||||
}
|
||||
|
||||
class ClassAB : TraitA, TraitB
|
||||
|
||||
public class MyNode : Node<ClassAB>() {
|
||||
override fun bar(arg: ClassAB): String = "MyNode.bar(ClassAB)"
|
||||
override fun bar(arg: TraitA): String = "MyNode.bar(TraitA)"
|
||||
override fun bar(arg: TraitB): String = "MyNode.bar(TraitB)"
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
|
||||
var node = MyNode()
|
||||
val traitA: TraitA = ClassAB()
|
||||
val traitB: TraitB = ClassAB()
|
||||
assertEquals("MyNode.bar(ClassAB)", node.bar(ClassAB()))
|
||||
assertEquals("MyNode.bar(TraitA)", node.bar(traitA))
|
||||
assertEquals("MyNode.bar(TraitB)", node.bar(traitB))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
fun Int.foo() {
|
||||
}
|
||||
fun String.foo() {
|
||||
}
|
||||
|
||||
val Int.bar: Int get() = 1
|
||||
val String.bar: Int get() = 2
|
||||
|
||||
fun box(): String {
|
||||
val a = 43
|
||||
if (a.bar != 1) return "a.bar != 1, it: ${a.bar}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// See KT-11823
|
||||
package foo
|
||||
|
||||
class Outer(val x: Int) {
|
||||
inner class Inner() {
|
||||
fun foo() = { x }
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(23, Outer(23).Inner().foo()())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// See KT-11823
|
||||
package foo
|
||||
|
||||
class Outer(val x: Int) {
|
||||
inner class Inner() {
|
||||
fun foo(): Int {
|
||||
class A {
|
||||
fun bar() = x
|
||||
}
|
||||
return A().bar()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(23, Outer(23).Inner().foo())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package foo
|
||||
|
||||
class EntryImplementor() : Map.Entry<String, String> {
|
||||
override val key: String
|
||||
get() = "foo"
|
||||
override val value: String
|
||||
get() = "bar"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val entry = EntryImplementor()
|
||||
var stringResult = "${entry.key}${entry.value}"
|
||||
if (stringResult != "foobar") return "failed1: $stringResult"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
open class A(val x: Int, val y: Int) {
|
||||
inner class B(val z: Int) {
|
||||
fun foo() = x + y + z
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A(2, 3)
|
||||
val b = a.B(4)
|
||||
return if (b.foo() == 9) "OK" else "failure"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
class X {
|
||||
val a = Y.foo
|
||||
|
||||
object Y {
|
||||
val foo = 23
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(23, X().a)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package foo
|
||||
|
||||
var i = 0
|
||||
|
||||
abstract class Base {
|
||||
val base = "b" + i++
|
||||
inner class Inner {
|
||||
fun o() = "O" + base
|
||||
fun k() = "K" + base
|
||||
}
|
||||
}
|
||||
|
||||
class Child : Base()
|
||||
|
||||
fun box(): String {
|
||||
var result = ""
|
||||
result += Child().Inner().o()
|
||||
|
||||
fun Child.f() {
|
||||
result += Inner().k()
|
||||
}
|
||||
Child().f()
|
||||
|
||||
return if (result == "Ob0Kb1") "OK" else result
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package foo
|
||||
|
||||
open class A(val x: Int) {
|
||||
class B : A(5)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (A(7).x + A.B().x == 12) "OK" else "failed"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package foo
|
||||
|
||||
interface A {
|
||||
fun foo(): String
|
||||
fun bar() = "A.bar;"
|
||||
|
||||
class B {
|
||||
fun foo() = "A.B.foo;"
|
||||
fun bar() = "A.B.bar;"
|
||||
}
|
||||
|
||||
class C : A {
|
||||
override fun foo() = "A.C.foo;"
|
||||
}
|
||||
|
||||
class D : A {
|
||||
override fun foo() = "A.D.foo;"
|
||||
override fun bar() = "A.D.bar;"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("A.B.foo;", A.B().foo())
|
||||
assertEquals("A.B.bar;", A.B().bar())
|
||||
|
||||
assertEquals("A.C.foo;", A.C().foo())
|
||||
assertEquals("A.bar;", A.C().bar())
|
||||
|
||||
assertEquals("A.D.foo;", A.D().foo())
|
||||
assertEquals("A.D.bar;", A.D().bar())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
function B(value) {
|
||||
this.foo = 100 + value;
|
||||
}
|
||||
B.prototype = {};
|
||||
B.prototype.bar = function() {
|
||||
return this.foo + 1000;
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
package foo
|
||||
|
||||
open class A {
|
||||
@native class B(value: Int = 0) {
|
||||
val foo: Int
|
||||
get() = noImpl
|
||||
fun bar(): Int = noImpl
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var b = A.B(23)
|
||||
if (b.foo != 123) return "failed1: ${b.foo}"
|
||||
if (b.bar() != 1123) return "failed2: ${b.bar()}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// See KT-6201
|
||||
package foo
|
||||
|
||||
var log = ""
|
||||
|
||||
class A() {
|
||||
init {
|
||||
log += "A"
|
||||
}
|
||||
|
||||
object B {
|
||||
init {
|
||||
log += "B"
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
log += ".bar"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
A()
|
||||
log += ";"
|
||||
A.B.bar()
|
||||
|
||||
assertEquals("A;B.bar", log)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package foo
|
||||
|
||||
class A(val x: Int) {
|
||||
inner class B() {
|
||||
inner class C() {
|
||||
var result = 0
|
||||
|
||||
constructor(y: Boolean) : this() {
|
||||
result = x
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(23, A(23).B().C(true).result)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
inner class B {
|
||||
val x = foo();
|
||||
}
|
||||
|
||||
class C {
|
||||
val x = foo();
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun foo(): String {
|
||||
return "foo_result";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = A().B().x
|
||||
if (result != "foo_result") {
|
||||
return "fail1_" + result
|
||||
}
|
||||
result = A.C().x
|
||||
if (result != "foo_result") {
|
||||
return "fail2_" + result
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
function A(x) {
|
||||
this.x = x;
|
||||
}
|
||||
A.prototype = {
|
||||
foo : function() {
|
||||
return this.x;
|
||||
}
|
||||
};
|
||||
|
||||
A.B = function(value) {
|
||||
this.value = value;
|
||||
};
|
||||
A.B.prototype = {
|
||||
bar : function() {
|
||||
return 10000 + this.value;
|
||||
}
|
||||
};
|
||||
|
||||
A.C = function(outer, value) {
|
||||
this.outer = outer;
|
||||
this.value = value;
|
||||
};
|
||||
A.C.prototype = {
|
||||
bar : function() {
|
||||
return this.outer.foo() + this.value + 10000;
|
||||
},
|
||||
dec : function() {
|
||||
this.outer.x--;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
package foo
|
||||
|
||||
@native class A(x: Int) {
|
||||
var x: Int
|
||||
get() = noImpl
|
||||
set(value) = noImpl
|
||||
|
||||
fun foo(): Int = noImpl
|
||||
|
||||
class B(val value: Int) {
|
||||
fun bar(): Int = noImpl
|
||||
}
|
||||
|
||||
inner class C(val value: Int) {
|
||||
fun bar(): Int = noImpl
|
||||
fun dec(): Unit = noImpl
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var b = A.B(23)
|
||||
if (b.bar() != 10023) return "failed1: ${b.bar()}"
|
||||
|
||||
var c = A(11).C(23)
|
||||
if (c.bar() != 10034) return "failed2: ${c.bar()}"
|
||||
c.dec()
|
||||
if (c.bar() != 10033) return "failed3: ${c.bar()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
val q = "baz"
|
||||
|
||||
object A {
|
||||
val x = "foo"
|
||||
|
||||
class B {
|
||||
val y = x + "_bar"
|
||||
val z = q + "_bar"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = A.B().y
|
||||
if (result != "foo_bar") {
|
||||
return "failed1_" + result
|
||||
}
|
||||
result = A.B().z
|
||||
if (result != "baz_bar") {
|
||||
return "failed2_" + result
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
class Outer() {
|
||||
inner class Inner() {
|
||||
val outer: Outer get() = this@Outer
|
||||
}
|
||||
|
||||
public val x : Inner = Inner()
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val o = Outer()
|
||||
return if (o === o.x.outer) "OK" else "fail"
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package foo
|
||||
|
||||
open class A(private val bar: String = "1") {
|
||||
inner class B : A("2") {
|
||||
fun foo(a: A): String {
|
||||
return bar + a.bar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var r = ""
|
||||
|
||||
r = A().B().foo(A("3"))
|
||||
if (r != "13") return "r = $r"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package foo
|
||||
|
||||
open class D {
|
||||
open val name = "D"
|
||||
fun boo() = "D[$name]::boo;"
|
||||
}
|
||||
|
||||
open class Z : D() {
|
||||
override val name = "Z"
|
||||
fun bar() = "Z[$name]::bar;"
|
||||
private fun baz() = "Z[$name]::baz;"
|
||||
|
||||
inner class X : Z() {
|
||||
override val name = "X"
|
||||
fun foo() = "X[$name]::foo;"
|
||||
|
||||
fun test() {
|
||||
assertEquals("X[X]::foo;", this.foo())
|
||||
assertEquals("Z[Z]::bar;", this@Z.bar())
|
||||
|
||||
assertEquals("Z[X]::bar;", super.bar())
|
||||
assertEquals("Z[X]::bar;", super<Z>.bar())
|
||||
assertEquals("D[Z]::boo;", super@Z.boo())
|
||||
|
||||
assertEquals("X[X]::foo;", foo())
|
||||
assertEquals("Z[X]::bar;", bar())
|
||||
assertEquals("Z[Z]::baz;", baz())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
Z().X().test()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package foo
|
||||
|
||||
fun testShortConversions(c: Short): Boolean {
|
||||
if (c.toDouble() != 3.0) {
|
||||
return false
|
||||
}
|
||||
if (c.toFloat() != 3.toFloat()) {
|
||||
return false
|
||||
}
|
||||
if (c.toByte() != 3.toByte()) {
|
||||
return false
|
||||
}
|
||||
if (c.toInt() != 3) {
|
||||
return false
|
||||
}
|
||||
if (c.toShort() != 3.toShort()) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun testByteConversions(c: Byte): Boolean {
|
||||
if (c.toDouble() != 3.0) {
|
||||
return false
|
||||
}
|
||||
if (c.toFloat() != 3.toFloat()) {
|
||||
return false
|
||||
}
|
||||
if (c.toByte() != 3.toByte()) {
|
||||
return false
|
||||
}
|
||||
if (c.toInt() != 3) {
|
||||
return false
|
||||
}
|
||||
if (c.toShort() != 3.toShort()) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (!testShortConversions(3)) return "fail: testShortConversions"
|
||||
if (!testByteConversions(3)) return "fail: testByteConversions"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
|
||||
assertEquals(65, 321.0.toByte())
|
||||
assertEquals(-56, 200.0.toByte())
|
||||
|
||||
assertEquals(65, 321.0f.toByte())
|
||||
assertEquals(-56, 200.0f.toByte())
|
||||
|
||||
assertEquals(65, 321L.toByte())
|
||||
assertEquals(-56, 200L.toByte())
|
||||
|
||||
assertEquals(65, 321.toByte())
|
||||
assertEquals(-56, 200.toByte())
|
||||
|
||||
assertEquals(65, (321.toShort()).toByte())
|
||||
assertEquals(-56, (200.toShort()).toByte())
|
||||
|
||||
assertEquals(-1, 65535.0.toShort())
|
||||
assertEquals(-1, 65535.0f.toShort())
|
||||
assertEquals(-1, 65535L.toShort())
|
||||
assertEquals(-1, 65535.toShort())
|
||||
|
||||
assertEquals(65535, 65535.2.toInt())
|
||||
assertEquals(23, 23.6f.toInt())
|
||||
assertEquals(-12, -12.4.toShort())
|
||||
assertEquals(-12, -12.4.toByte())
|
||||
|
||||
assertEquals('\u0419', (-654311).toChar())
|
||||
assertEquals('\u0419', (-654311.0).toChar())
|
||||
assertEquals('\u0419', (-654311.0f).toChar())
|
||||
|
||||
val longX: Long = 9223372034707292481L
|
||||
assertEquals("9223372034707292481", longX.toString())
|
||||
val doubleX: Double = safeParseDouble("9223372034707292481")!!
|
||||
assertEquals(doubleX, longX.toDouble())
|
||||
assertEquals(doubleX, longX.toFloat())
|
||||
|
||||
assertEquals(-2147483327, longX.toInt())
|
||||
assertEquals(321, longX.toShort())
|
||||
assertEquals(65, longX.toByte())
|
||||
assertEquals('\u0141', longX.toChar())
|
||||
|
||||
val intX: Int = longX.toInt()
|
||||
assertEquals(321, intX.toShort())
|
||||
assertEquals(65, intX.toByte())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package foo
|
||||
|
||||
fun testForNumber(numberX: Number) {
|
||||
assertEquals(true, 65.0 == numberX.toDouble())
|
||||
assertEquals(true, 65.0f == numberX.toFloat())
|
||||
assertEquals(true, 65L == numberX.toLong())
|
||||
assertEquals(true, 65 == numberX.toInt())
|
||||
assertEquals(true, 65.toShort() == numberX.toShort())
|
||||
assertEquals(true, 65.toByte() == numberX.toByte())
|
||||
assertEquals(true, 'A' == numberX.toChar())
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
testForNumber(65.0)
|
||||
testForNumber(65.0f)
|
||||
testForNumber(65L)
|
||||
testForNumber(65)
|
||||
testForNumber(65.toShort())
|
||||
testForNumber(65.toByte())
|
||||
|
||||
var doubleX: Double = 65.0
|
||||
assertEquals(true, 65.0 == doubleX.toDouble())
|
||||
assertEquals(true, 65.0f == doubleX.toFloat())
|
||||
assertEquals(true, 65L == doubleX.toLong())
|
||||
assertEquals(true, 65 == doubleX.toInt())
|
||||
assertEquals(true, 65.toShort() == doubleX.toShort())
|
||||
assertEquals(true, 65.toByte() == doubleX.toByte())
|
||||
assertEquals(true, 'A' == doubleX.toChar())
|
||||
|
||||
var floatX: Float = 65.0f
|
||||
assertEquals(true, 65.0 == floatX.toDouble())
|
||||
assertEquals(true, 65.0f == floatX.toFloat())
|
||||
assertEquals(true, 65L == floatX.toLong())
|
||||
assertEquals(true, 65 == floatX.toInt())
|
||||
assertEquals(true, 65.toShort() == floatX.toShort())
|
||||
assertEquals(true, 65.toByte() == floatX.toByte())
|
||||
assertEquals(true, 'A' == floatX.toChar())
|
||||
|
||||
val longX: Long = 65L
|
||||
assertEquals(true, 65.0 == longX.toDouble())
|
||||
assertEquals(true, 65.0f == longX.toFloat())
|
||||
assertEquals(true, 65L == longX.toLong())
|
||||
assertEquals(true, 65 == longX.toInt())
|
||||
assertEquals(true, 65.toShort() == longX.toShort())
|
||||
assertEquals(true, 65.toByte() == longX.toByte())
|
||||
assertEquals(true, 'A' == longX.toChar())
|
||||
|
||||
val intX: Int = 65
|
||||
assertEquals(true, 65.0 == intX.toDouble())
|
||||
assertEquals(true, 65.0f == intX.toFloat())
|
||||
assertEquals(true, 65L == intX.toLong())
|
||||
assertEquals(true, 65 == intX.toInt())
|
||||
assertEquals(true, 65.toShort() == intX.toShort())
|
||||
assertEquals(true, 65.toByte() == intX.toByte())
|
||||
assertEquals(true, 'A' == intX.toChar())
|
||||
|
||||
val shortX: Short = 65.toShort()
|
||||
assertEquals(true, 65.0 == shortX.toDouble())
|
||||
assertEquals(true, 65.0f == shortX.toFloat())
|
||||
assertEquals(true, 65L == shortX.toLong())
|
||||
assertEquals(true, 65 == shortX.toInt())
|
||||
assertEquals(true, 65.toShort() == shortX.toShort())
|
||||
assertEquals(true, 65.toByte() == shortX.toByte())
|
||||
assertEquals(true, 'A' == shortX.toChar())
|
||||
|
||||
val byteX: Byte = 65.toByte()
|
||||
assertEquals(true, 65.0 == byteX.toDouble())
|
||||
assertEquals(true, 65.0f == byteX.toFloat())
|
||||
assertEquals(true, 65L == byteX.toLong())
|
||||
assertEquals(true, 65 == byteX.toInt())
|
||||
assertEquals(true, 65.toShort() == byteX.toShort())
|
||||
assertEquals(true, 65.toByte() == byteX.toByte())
|
||||
assertEquals(true, 'A' == byteX.toChar())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
if (3 / 4 != 0) {
|
||||
return "fail11"
|
||||
}
|
||||
if (-5 / 4 != -1) {
|
||||
return "fail2"
|
||||
}
|
||||
if ((3.0 / 4.0 - 0.75) > 0.01) {
|
||||
return "fail3"
|
||||
}
|
||||
if ((-10.0 / 4.0 + 2.5) > 0.01) {
|
||||
return "fail44"
|
||||
}
|
||||
val i1: Int = 5
|
||||
val i2: Int = 2
|
||||
if (i1 / i2 != 2) {
|
||||
return "fail55"
|
||||
}
|
||||
val i3: Short = 5
|
||||
val i4: Short = 2
|
||||
if (i3 / i4 != 2) {
|
||||
return "fail6"
|
||||
}
|
||||
val i5: Byte = 5
|
||||
val i6: Byte = 2
|
||||
if (i5 / i6 != 2) {
|
||||
return "fail7"
|
||||
}
|
||||
|
||||
val f1: Double = 5.0
|
||||
val f2: Double = 2.0
|
||||
if ((f1 / f2 - 2.5) > 0.01) {
|
||||
return "fail8"
|
||||
}
|
||||
|
||||
val f3: Float = 5.0.toFloat()
|
||||
val f4: Float = 2.0.toFloat()
|
||||
if ((f3 / f4 - 2.5.toFloat()) > 0.01) {
|
||||
return "fail9"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val c: Double = 3.6
|
||||
if (c.toDouble() != 3.6) {
|
||||
return "fail1"
|
||||
}
|
||||
if (c.toFloat() != 3.6.toFloat()) {
|
||||
return "fail2"
|
||||
}
|
||||
if (c.toByte() != 3.toByte()) {
|
||||
return "fail3"
|
||||
}
|
||||
if (c.toInt() != 3) {
|
||||
return "fail4"
|
||||
}
|
||||
if (c.toShort() != 3.toShort()) {
|
||||
return "fail5"
|
||||
}
|
||||
|
||||
val cn: Double = -3.6
|
||||
if (cn.toDouble() != -3.6) {
|
||||
return "fail6"
|
||||
}
|
||||
if (cn.toFloat() != -3.6.toFloat()) {
|
||||
return "fail7"
|
||||
}
|
||||
if (cn.toByte() != (-3).toByte()) {
|
||||
return "fail8"
|
||||
}
|
||||
if (cn.toInt() != -3) {
|
||||
return "fail9"
|
||||
}
|
||||
if (cn.toShort() != (-3).toShort()) {
|
||||
return "fail10"
|
||||
}
|
||||
|
||||
val f: Float = 3.6.toFloat()
|
||||
if (f.toDouble() != 3.6) {
|
||||
return "fail11"
|
||||
}
|
||||
if (f.toFloat() != 3.6.toFloat()) {
|
||||
return "fail12"
|
||||
}
|
||||
if (f.toByte() != 3.toByte()) {
|
||||
return "fail13"
|
||||
}
|
||||
if (f.toInt() != 3) {
|
||||
return "fail14"
|
||||
}
|
||||
if (f.toShort() != 3.toShort()) {
|
||||
return "fail15"
|
||||
}
|
||||
|
||||
val fn: Float = -3.6.toFloat()
|
||||
if (fn.toDouble() != -3.6) {
|
||||
return "fail16"
|
||||
}
|
||||
if (fn.toFloat() != -3.6.toFloat()) {
|
||||
return "fail17"
|
||||
}
|
||||
if (fn.toByte() != (-3).toByte()) {
|
||||
return "fail18"
|
||||
}
|
||||
if (fn.toInt() != -3) {
|
||||
return "fail19"
|
||||
}
|
||||
if (fn.toShort() != (-3).toShort()) {
|
||||
return "fail20"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val i = 0x80000000 + 0x8000000
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val c: Int = 3
|
||||
if (c.toDouble() != 3.0) {
|
||||
return "fail1"
|
||||
}
|
||||
if (c.toFloat() != 3.toFloat()) {
|
||||
return "fail2"
|
||||
}
|
||||
if (c.toByte() != 3.toByte()) {
|
||||
return "fail3"
|
||||
}
|
||||
if (c.toInt() != 3) {
|
||||
return "fail4"
|
||||
}
|
||||
if (c.toShort() != 3.toShort()) {
|
||||
return "fail5"
|
||||
}
|
||||
val c2: Int = -5
|
||||
if (c2.toShort() != (-5).toShort()) {
|
||||
return "fail6"
|
||||
}
|
||||
if (c2.toFloat() != -5.toFloat()) {
|
||||
return "fail7"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// http://youtrack.jetbrains.com/issue/KT-5345
|
||||
// KT-5345 (Javascript) Type mismatch on Int / Float division
|
||||
// If any of Number operands is floating-point, the result should be float too.
|
||||
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(0.5f, 1 / 2.0f, "Int / Float")
|
||||
assertEquals(0.5, 1 / 2.0, "Int / Double")
|
||||
|
||||
assertEquals(0.5f, 1.toShort() / 2.0f, "Short / Float")
|
||||
assertEquals(0.5, 1.toShort() / 2.0, "Short / Double")
|
||||
|
||||
assertEquals(0.5f, 1.toByte() / 2.0f, "Byte / Float")
|
||||
assertEquals(0.5, 1.toByte() / 2.0, "Byte / Double")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package foo
|
||||
|
||||
fun test(a: Int, b: Int, expected: Int): String {
|
||||
val result = a / b
|
||||
if (expected == result) return "OK"
|
||||
return "$a / $b = $result. Expected $expected"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var r = test(10, 3, 3)
|
||||
if (r != "OK") return r
|
||||
|
||||
r = test(49, 6, 8)
|
||||
if (r != "OK") return r
|
||||
|
||||
if (2133 / 3 / 7 / (91 / 5) != 5) return "2133 / 3 / 7 / (91 / 5) != 5"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val arr = LongArray(2)
|
||||
|
||||
val expected: Long = 0
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(expected, arr[0])
|
||||
assertEquals(expected, arr[1])
|
||||
|
||||
arr[0] = 2432902008176640000L
|
||||
assertEquals(2432902008176640000L, arr[0])
|
||||
|
||||
val arr1 = longArrayOf(1,2,3, 2432902008176640000L)
|
||||
assertEquals(1L, arr1[0])
|
||||
assertEquals(2L, arr1[1])
|
||||
assertEquals(3L, arr1[2])
|
||||
assertEquals(2432902008176640000L, arr1[3])
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package foo
|
||||
|
||||
fun fact(n: Int): Long = if (n == 1) 1L else n * fact(n - 1)
|
||||
|
||||
fun fib(n: Int): Long {
|
||||
var a = 0L
|
||||
var b = 1L
|
||||
for (i in 2..n) {
|
||||
var tmp = a
|
||||
a = b
|
||||
b = b + tmp
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
assertEquals(30.0, 10L + 20.0)
|
||||
assertEquals(30.0f, 10L + 20.0f)
|
||||
assertEquals(30L, 10L + 20L)
|
||||
assertEquals(30L, 10L + 20)
|
||||
assertEquals(30L, 10L + 20.toShort())
|
||||
assertEquals(30L, 10L + 20.toByte())
|
||||
|
||||
assertEquals(30.0, 20.0 + 10L)
|
||||
assertEquals(30.0f, 20.0f + 10L)
|
||||
assertEquals(20L, 10 + 10L)
|
||||
assertEquals(20L, 10.toShort() + 10L)
|
||||
assertEquals(20L, 10.toByte() + 10L)
|
||||
|
||||
assertEquals(20L, 30 - 10L)
|
||||
|
||||
assertEquals(100L, 10 * 10L)
|
||||
assertEquals(100.0, 10.0 * 10L)
|
||||
|
||||
assertEquals(100L, 10L * 10)
|
||||
assertEquals(100.0, 10L * 10.0)
|
||||
|
||||
assertEquals(100L, 1000L / 10)
|
||||
assertEquals(100L, 1000 / 10L)
|
||||
|
||||
assertEquals(100.0, 1000L / 10.0)
|
||||
assertEquals(100.0, 1000.0 / 10L)
|
||||
|
||||
assertEquals(2L, 100L % 7)
|
||||
assertEquals(2L, 100 % 7L)
|
||||
|
||||
assertEquals(2432902008176640000L, fact(20))
|
||||
assertEquals(12586269025L, fib(50))
|
||||
assertEquals(7540113804746346429L, fib(92))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
|
||||
assertEquals(65536L, 1L shl 16)
|
||||
assertEquals(1L, 65536L shr 16)
|
||||
|
||||
assertEquals(-1L, -1L shr 48)
|
||||
assertEquals(65535L, -1L ushr 48)
|
||||
|
||||
assertEquals(-1L, 0L.inv())
|
||||
|
||||
assertEquals(0b1000L, 0b1100L and 0b1010L)
|
||||
assertEquals(0b1110L, 0b1100L or 0b1010L)
|
||||
assertEquals(0b0110L, 0b1100L xor 0b1010L)
|
||||
|
||||
assertEquals(0xab88ac0021L, 0xabcdef0123L and 0xefaabcdef1L)
|
||||
assertEquals(0xefefffdff3L, 0xabcdef0123L or 0xefaabcdef1L)
|
||||
assertEquals(0x446753dfd2L, 0xabcdef0123L xor 0xefaabcdef1L)
|
||||
assertEquals(-737894400292, 0xabcdef0123L.inv())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
|
||||
assertEquals(true, 10.0 < 20L, "Double.compareTo(Long)")
|
||||
assertEquals(true, 10.0 < 7540113804746346429L, "Double.compareTo(Long)")
|
||||
|
||||
assertEquals(true, 10.0f < 20L, "Float.compareTo(Long)")
|
||||
assertEquals(true, 10.0f < 7540113804746346429L, "Float.compareTo(Long)")
|
||||
|
||||
assertEquals(true, 10L < 20L, "Long.compareTo(Long)")
|
||||
assertEquals(true, 10 < 20L, "Int.compareTo(Long)")
|
||||
assertEquals(true, 10 < 7540113804746346429L, "Int.compareTo(Long)")
|
||||
|
||||
assertEquals(true, 10.toShort() < 20L, "Short.compareTo(Long)")
|
||||
assertEquals(true, 10.toShort() < 7540113804746346429L, "Short.compareTo(Long)")
|
||||
assertEquals(true, 10.toByte() < 20L, "Byte.compareTo(Long)")
|
||||
assertEquals(true, 10.toByte() < 7540113804746346429L, "Byte.compareTo(Long)")
|
||||
|
||||
assertEquals(true, 10L < 20.0, "Long.compareTo(Double)")
|
||||
assertEquals(false, 7540113804746346429L < 20.0, "Long.compareTo(Double)")
|
||||
|
||||
assertEquals(true, 10L < 20.0f, "Long.compareTo(Float)")
|
||||
assertEquals(true, 7540113804746346429L > 20.0f, "Long.compareTo(Float)")
|
||||
assertEquals(false, 7540113804746346429L < 20.0f, "Long.compareTo(Float)")
|
||||
|
||||
assertEquals(true, 10L < 20, "Long.compareTo(Int)")
|
||||
assertEquals(true, 7540113804746346429L > 20, "Long.compareTo(Int)")
|
||||
assertEquals(false, 7540113804746346429L < 20, "Long.compareTo(Int)")
|
||||
|
||||
assertEquals(true, 10L < 20.toShort(), "Long.compareTo(Short)")
|
||||
assertEquals(true, 7540113804746346429L > 20.toShort(), "Long.compareTo(Short)")
|
||||
assertEquals(false, 7540113804746346429L < 20.toShort(), "Long.compareTo(Short)")
|
||||
|
||||
assertEquals(true, 10L < 20.toByte(), "Long.compareTo(Byte)")
|
||||
assertEquals(true, 7540113804746346429L > 20.toByte(), "Long.compareTo(Byte)")
|
||||
assertEquals(false, 7540113804746346429L < 20.toByte(), "Long.compareTo(Byte)")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(true, 10L == 10L, "Long == Long")
|
||||
assertEquals(true, 10L != 11L, "Long != Long")
|
||||
|
||||
val x1: Long? = 10L
|
||||
val x2: Long? = 10L
|
||||
assertEquals(false, x1 == null, "Long? == null")
|
||||
assertEquals(false, null == x1, "null == Long?")
|
||||
assertEquals(true, x1 == 10L, "Long? == Long")
|
||||
assertEquals(true, 10L == x1, "Long == Long?")
|
||||
assertEquals(true, x1 == x2, "Long? == Long?")
|
||||
|
||||
val x3: Long? = null
|
||||
val x4: Long? = null
|
||||
assertEquals(true, x3 == null, "Long?(null) == null")
|
||||
assertEquals(true, null == x3, "null == Long?(null)")
|
||||
assertEquals(false, x3 == 10L, "Long?(null) == Long")
|
||||
assertEquals(false, 10L == x3, "Long == Long?(null)")
|
||||
assertEquals(false, x3 == x1, "Long?(null) == Long?")
|
||||
assertEquals(true, x3 == x4, "Long?(null) == Long?(null)")
|
||||
|
||||
val number1: Number = 10L
|
||||
val number2: Number = 10L
|
||||
assertEquals(true, number1 == number2, "Number == Number")
|
||||
assertEquals(true, number1 == 10L, "Number == Long")
|
||||
assertEquals(true, number1 != 11L, "Number != Long")
|
||||
assertEquals(true, 10L == number1, "Long == Number")
|
||||
assertEquals(true, 11L != number1, "Long != Number")
|
||||
|
||||
val y1: Any = 10L
|
||||
var y2: Any = 10
|
||||
var y3: Any? = null
|
||||
assertEquals(true, y1 == 10L, "Any == Long")
|
||||
assertEquals(true, 10L == y1, "Long == Any 1")
|
||||
assertEquals(false, 10L == y2, "Long == Any 2")
|
||||
assertEquals(false, 10L == y3, "Long == Any?(null)")
|
||||
assertEquals(true, x3 == y3, "Long?(null) == Any?(null)")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var l1: Long = 0x12344478935690
|
||||
var l2: Long = 0x12344478935698
|
||||
var diff: Long = l2 - l1
|
||||
l1 += (diff / 2)
|
||||
l2 -= (diff / 2)
|
||||
|
||||
assertEquals(l1, l2, "When L1 == L2")
|
||||
assertEquals(l1.hashCode(), l2.hashCode(), "L1.hashCode() == L2.hashCode()")
|
||||
|
||||
var l3: Any = l2
|
||||
assertEquals(l1.hashCode(), l3.hashCode(), "Any(Long).hashCode()")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
|
||||
var x: Long = 2L
|
||||
x++
|
||||
assertEquals(3L, x)
|
||||
++x
|
||||
assertEquals(4L, x)
|
||||
|
||||
var y = x++
|
||||
assertEquals(4L, y)
|
||||
assertEquals(5L, x)
|
||||
|
||||
y = ++x
|
||||
assertEquals(6L, y)
|
||||
assertEquals(6L, x)
|
||||
|
||||
x--
|
||||
assertEquals(5L, x)
|
||||
--x
|
||||
assertEquals(4L, x)
|
||||
|
||||
y = +x
|
||||
assertEquals(4L, y)
|
||||
|
||||
y = -x
|
||||
assertEquals(-4L, y)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package foo
|
||||
|
||||
var global: String = ""
|
||||
|
||||
fun id(s: String, value: Int): Int {
|
||||
global += s
|
||||
return value
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
assertEquals(-1, 1.compareTo(2))
|
||||
assertEquals(-1, (1 as Comparable<Int>).compareTo(2))
|
||||
|
||||
assertEquals(-1, 1.compareTo(2L))
|
||||
assertEquals(-1, 1.compareTo(2L))
|
||||
assertEquals(-1, 1.compareTo(7540113804746346429L))
|
||||
assertEquals(-1, 1.compareTo(2.toShort()))
|
||||
assertEquals(-1, 1.compareTo(2.toByte()))
|
||||
assertEquals(-1, 1.compareTo(2.0))
|
||||
assertEquals(-1, 1.compareTo(2.0f))
|
||||
|
||||
assertEquals(1, 10.compareTo(2L))
|
||||
assertEquals(1, 10.compareTo(2))
|
||||
assertEquals(1, 10.compareTo(2.toShort()))
|
||||
assertEquals(1, 10.compareTo(2.toByte()))
|
||||
assertEquals(1, 10.compareTo(2.0))
|
||||
assertEquals(1, 10.compareTo(2.0f))
|
||||
|
||||
assertEquals(0, 2.compareTo(2L))
|
||||
assertEquals(0, 2.compareTo(2))
|
||||
assertEquals(0, 2.compareTo(2.toShort()))
|
||||
assertEquals(0, 2.compareTo(2.toByte()))
|
||||
assertEquals(0, 2.compareTo(2.0))
|
||||
assertEquals(0, 2.compareTo(2.0f))
|
||||
|
||||
assertEquals(-1, 1.toShort().compareTo(2L))
|
||||
assertEquals(-1, 1.toShort().compareTo(7540113804746346429L))
|
||||
assertEquals(-1, 1.toShort().compareTo(2))
|
||||
assertEquals(-1, 1.toShort().compareTo(2.toShort()))
|
||||
assertEquals(-1, (1.toShort() as Comparable<Short>).compareTo(2.toShort()))
|
||||
assertEquals(-1, 1.toShort().compareTo(2.toByte()))
|
||||
assertEquals(-1, 1.toShort().compareTo(2.0))
|
||||
assertEquals(-1, 1.toShort().compareTo(2.0f))
|
||||
|
||||
assertEquals(1, 10.toByte().compareTo(2L))
|
||||
assertEquals(-1, 10.toByte().compareTo(7540113804746346429L))
|
||||
assertEquals(1, 10.toByte().compareTo(2))
|
||||
assertEquals(1, 10.toByte().compareTo(2.toShort()))
|
||||
assertEquals(1, 10.toByte().compareTo(2.toByte()))
|
||||
assertEquals(1, (10.toByte() as Comparable<Byte>).compareTo(2.toByte()))
|
||||
assertEquals(1, 10.toByte().compareTo(2.0))
|
||||
assertEquals(1, 10.toByte().compareTo(2.0f))
|
||||
|
||||
assertEquals(0, 2.0.compareTo(2L))
|
||||
assertEquals(-1, 2.0.compareTo(7540113804746346429L))
|
||||
assertEquals(0, 2.0.compareTo(2))
|
||||
assertEquals(0, 2.0.compareTo(2.toShort()))
|
||||
assertEquals(0, 2.0.compareTo(2.toByte()))
|
||||
assertEquals(0, 2.0.compareTo(2.0))
|
||||
assertEquals(0, (2.0 as Comparable<Double>).compareTo(2.0))
|
||||
assertEquals(0, 2.0.compareTo(2.0f))
|
||||
|
||||
assertEquals(1, 3.0f.compareTo(2L))
|
||||
assertEquals(-1, 3.0f.compareTo(7540113804746346429L))
|
||||
assertEquals(1, 3.0f.compareTo(2))
|
||||
assertEquals(1, 3.0f.compareTo(2.toShort()))
|
||||
assertEquals(1, 3.0f.compareTo(2.toByte()))
|
||||
assertEquals(1, 3.0f.compareTo(2.0))
|
||||
assertEquals(1, 3.0f.compareTo(2.0f))
|
||||
assertEquals(1, (3.0f as Comparable<Float>).compareTo(2.0f))
|
||||
|
||||
assertEquals(1, 10L.compareTo(2L))
|
||||
assertEquals(-1, 10L.compareTo(7540113804746346429L))
|
||||
assertEquals(1, (10L as Comparable<Long>).compareTo(2L))
|
||||
assertEquals(1, 10L.compareTo(2))
|
||||
assertEquals(1, 10L.compareTo(2.toShort()))
|
||||
assertEquals(1, 10L.compareTo(2.toByte()))
|
||||
assertEquals(1, 10L.compareTo(2.0))
|
||||
assertEquals(1, 10L.compareTo(2.0f))
|
||||
|
||||
assertEquals(0, 'A'.compareTo('A'))
|
||||
|
||||
assertEquals(-1, 1L.compareTo(2L))
|
||||
assertEquals(-1, 1L.compareTo(2))
|
||||
assertEquals(-1, 1L.compareTo(2.toShort()))
|
||||
assertEquals(-1, 1L.compareTo(2.toByte()))
|
||||
assertEquals(-1, 1L.compareTo(2.0))
|
||||
assertEquals(-1, 1L.compareTo(2.0f))
|
||||
|
||||
assertEquals(0, 7540113804746346429L.compareTo(7540113804746346429L))
|
||||
assertEquals(1, 7540113804746346429L.compareTo(2L))
|
||||
assertEquals(0, 2L.compareTo(2L))
|
||||
assertEquals(0, 2L.compareTo(2))
|
||||
assertEquals(0, 2L.compareTo(2.toShort()))
|
||||
assertEquals(0, 2L.compareTo(2.toByte()))
|
||||
assertEquals(0, 2L.compareTo(2.0))
|
||||
assertEquals(0, 2L.compareTo(2.0f))
|
||||
|
||||
assertEquals(1, 10L.compareTo(2L))
|
||||
assertEquals(1, 10L.compareTo(2))
|
||||
assertEquals(1, 10L.compareTo(2.toShort()))
|
||||
assertEquals(1, 10L.compareTo(2.toByte()))
|
||||
assertEquals(1, 10L.compareTo(2.0))
|
||||
assertEquals(1, 10L.compareTo(2.0f))
|
||||
|
||||
assertEquals(-1, 1L.compareTo(2L))
|
||||
assertEquals(-1, 1L.compareTo(2))
|
||||
assertEquals(-1, 1L.compareTo(2.toShort()))
|
||||
assertEquals(-1, 1L.compareTo(2.toByte()))
|
||||
assertEquals(-1, 1L.compareTo(2.0))
|
||||
assertEquals(-1, 1L.compareTo(2.0f))
|
||||
|
||||
assertEquals(0, 2L.compareTo(2L))
|
||||
assertEquals(0, 2L.compareTo(2))
|
||||
assertEquals(0, 2L.compareTo(2.toShort()))
|
||||
assertEquals(0, 2L.compareTo(2.toByte()))
|
||||
assertEquals(0, 2L.compareTo(2.0))
|
||||
assertEquals(0, 2L.compareTo(2.0f))
|
||||
|
||||
assertEquals(1, id("A", 10).compareTo(id("B", 5)))
|
||||
assertEquals("AB", global)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user