JS backend: testFiles -> testData
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package foo
|
||||
|
||||
class A
|
||||
|
||||
fun checkCastNullableToNotNull(): Boolean {
|
||||
val a = null
|
||||
try {
|
||||
val s = a as A
|
||||
}
|
||||
catch (e: Exception) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun checkCastNotNullToNotNull(): Boolean {
|
||||
val a = A()
|
||||
var s = a as A
|
||||
return s == a
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (!checkCastNullableToNotNull()) return "Failed when try cast Nullable to NotNull"
|
||||
if (!checkCastNotNullToNotNull()) return "Failed when try cast NotNull to NotNull"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package foo
|
||||
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
val a = null
|
||||
val s = a as A?
|
||||
if (s != null) return "Failed when try cast Nullable with null value to Nullable"
|
||||
|
||||
val b: A? = A()
|
||||
val n = b as A?
|
||||
if (n != b) return "Failed when try cast Nullable with not null value to Nullable"
|
||||
|
||||
val c = A()
|
||||
val m = c as A?
|
||||
if (m != c) return "Failed when try cast NotNull to Nullable"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun foo(a: Int) = "A.foo($a)"
|
||||
}
|
||||
|
||||
fun Any.bar() = "Any.bar()"
|
||||
fun A.bar() = "A.bar()"
|
||||
|
||||
fun boo(a: Any) = "boo(Any)"
|
||||
fun boo(a: A) = "boo(A)"
|
||||
|
||||
fun assert<T>(expected: T, actual: T, caseName: String) {
|
||||
if (expected != actual) throw Exception("Filed on $caseName, expected: $expected, actual: $actual")
|
||||
}
|
||||
|
||||
fun Any.testInTopLevel() {
|
||||
assert(bar(), "Any.bar()", "bar()")
|
||||
assert(this.bar(), "Any.bar()", "this.bar()")
|
||||
assert(boo(this), "boo(Any)", "boo(this)")
|
||||
|
||||
if (this is A) {
|
||||
assert(foo(47), "A.foo(47)", "foo(47)")
|
||||
assert(bar(), "A.bar()", "bar()")
|
||||
|
||||
assert(this.foo(47), "A.foo(47)", "this.foo(47)")
|
||||
assert(this.bar(), "A.bar()", "this.bar()")
|
||||
|
||||
assert(boo(this), "boo(A)", "boo(this: A)")
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
fun Any.test() {
|
||||
assert(bar(), "Any.bar()", "bar()")
|
||||
assert(this.bar(), "Any.bar()", "this.bar()")
|
||||
assert(boo(this), "boo(Any)", "boo(this)")
|
||||
|
||||
if (this is A) {
|
||||
assert(foo(47), "A.foo(47)", "foo(47)")
|
||||
assert(bar(), "A.bar()", "bar()")
|
||||
|
||||
assert(this.foo(47), "A.foo(47)", "this.foo(47)")
|
||||
assert(this.bar(), "A.bar()", "this.bar()")
|
||||
|
||||
assert(boo(this), "boo(A)", "boo(this: A)")
|
||||
}
|
||||
}
|
||||
|
||||
fun testInClass() {
|
||||
A().test()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
A().testInTopLevel()
|
||||
B().testInClass()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun foo(a: Int) = "A.foo($a)"
|
||||
}
|
||||
|
||||
fun Any.bar() = "Any.bar()"
|
||||
fun A.bar() = "A.bar()"
|
||||
|
||||
fun boo(a: Any) = "boo(Any)"
|
||||
fun boo(a: A) = "boo(A)"
|
||||
|
||||
fun assert<T>(expected: T, actual: T, caseName: String) {
|
||||
if (expected != actual) throw Exception("Filed on $caseName, expected: $expected, actual: $actual")
|
||||
}
|
||||
|
||||
fun testInTopLevel(a: Any) {
|
||||
assert(a.bar(), "Any.bar()", "bar()")
|
||||
assert(a.bar(), "Any.bar()", "this.bar()")
|
||||
assert(boo(a), "boo(Any)", "boo(this)")
|
||||
|
||||
if (a is A) {
|
||||
assert(a.foo(47), "A.foo(47)", "a.foo(47)")
|
||||
assert(a.bar(), "A.bar()", "a.bar()")
|
||||
assert(boo(a), "boo(A)", "boo(a: A)")
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
fun testInClass(a: Any) {
|
||||
assert(a.bar(), "Any.bar()", "bar()")
|
||||
assert(a.bar(), "Any.bar()", "this.bar()")
|
||||
assert(boo(a), "boo(Any)", "boo(this)")
|
||||
|
||||
if (a is A) {
|
||||
assert(a.foo(47), "A.foo(47)", "a.foo(47)")
|
||||
assert(a.bar(), "A.bar()", "a.bar()")
|
||||
assert(boo(a), "boo(A)", "boo(a: A)")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testInTopLevel(A())
|
||||
B().testInClass(A())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package foo
|
||||
|
||||
fun MyController(`$scope`: String): String {
|
||||
return "Hello " + `$scope` + "!"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return MyController("world")
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
class Foo(val name: String) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is Foo) {
|
||||
return false
|
||||
}
|
||||
return this.name == other.name
|
||||
}
|
||||
}
|
||||
|
||||
fun callEqualsMethod(v1: Foo?, v2: Foo?): Boolean {
|
||||
return v1 == v2
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
val a = Foo("abc")
|
||||
val b = Foo("abc")
|
||||
val c = Foo("def")
|
||||
|
||||
if (!callEqualsMethod(a, b)) return false
|
||||
if (callEqualsMethod(a, c)) return false
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
class Foo(val name: String) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is Foo) {
|
||||
return false
|
||||
}
|
||||
return this.name == other.name
|
||||
}
|
||||
}
|
||||
|
||||
fun callEqualsMethod(v1: Any?, v2: Any?): Boolean {
|
||||
return v1 == v2
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
val a = Foo("abc")
|
||||
val b = Foo("abc")
|
||||
val c = Foo("def")
|
||||
|
||||
if (!callEqualsMethod(a, b)) return false
|
||||
if (callEqualsMethod(a, c)) return false
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package foo
|
||||
|
||||
native val undefined: Any = noImpl
|
||||
|
||||
fun box(): String {
|
||||
val a: Int? = null
|
||||
val r = a == null
|
||||
if (!r || a != null)
|
||||
return "wrong result on simple nullable check"
|
||||
|
||||
//force using Kotlin.equals
|
||||
val t = null
|
||||
if (t != undefined)
|
||||
return "wrong result when compare null and undefined using Kotlin.equals"
|
||||
|
||||
var i = 0;
|
||||
fun foo(): Int? = ++i;
|
||||
if (foo() == null)
|
||||
return "wrong result on nullable check with side effects"
|
||||
|
||||
if (i != 1)
|
||||
return "wrong affects when using nullable check with side effects"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package foo
|
||||
|
||||
class Foo(val name: String) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is Foo) {
|
||||
return false
|
||||
}
|
||||
return this.name == other.name
|
||||
}
|
||||
}
|
||||
|
||||
class Bar() {
|
||||
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
val a = Foo("abc")
|
||||
val b = Foo("abc")
|
||||
val c = Foo("def")
|
||||
|
||||
if (!(a equals b)) return false
|
||||
if (a equals c) return false
|
||||
if (Bar() equals Bar()) return false
|
||||
val g = Bar()
|
||||
if (!(g equals g)) return false
|
||||
if (g equals Bar()) return false
|
||||
return true
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
val a = 2
|
||||
if (!(a equals a)) return false
|
||||
if (!(a equals 2)) return false
|
||||
if (!(a equals 2.0)) return false
|
||||
val c = "a"
|
||||
if (!("a" equals c)) return false
|
||||
if (!(null equals null)) return false
|
||||
val d = 5.6
|
||||
if (!(d.toShort() equals 5.toShort())) return false
|
||||
if (!(d.toByte() equals 5.toByte())) return false
|
||||
if (!(d.toFloat() equals 5.6.toFloat())) return false
|
||||
if (!(d.toInt() equals 5)) return false
|
||||
if (true equals false) return false
|
||||
|
||||
val n: Number = 3
|
||||
if (!(n equals 3.3.toInt())) return false
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun box(): Boolean {
|
||||
val data = ArrayList<String>()
|
||||
data.add("foo")
|
||||
data.add("bar")
|
||||
data.add("whatnot")
|
||||
val data2 = ArrayList<String>()
|
||||
data2.addAll(data)
|
||||
return data.equals(data2)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
val a = "abc"
|
||||
val b = "abc"
|
||||
val c = "def"
|
||||
|
||||
if (a != b) return false
|
||||
if (a == c) return false
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package foo
|
||||
|
||||
val a1 = arrayOfNulls<Int>(10)
|
||||
|
||||
fun box(): Boolean {
|
||||
var c = 0
|
||||
var d = 0
|
||||
a1[3] = 3
|
||||
a1[5] = 5
|
||||
|
||||
for (a: Int? in a1) {
|
||||
if (a != null) {
|
||||
c += 1;
|
||||
}
|
||||
else {
|
||||
d += 1
|
||||
}
|
||||
}
|
||||
return (c == 2) && (d == 8)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package foo
|
||||
|
||||
val a1 = arrayOfNulls<Int>(0)
|
||||
|
||||
fun box(): Boolean {
|
||||
for (a in a1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
val a1 = arrayOfNulls<Int>(0)
|
||||
|
||||
fun box(): Boolean {
|
||||
var bar = 33
|
||||
@outer for (a in array(1, 2)) {
|
||||
for (b in array(1, 4)) {
|
||||
break @outer
|
||||
}
|
||||
bar = 42
|
||||
}
|
||||
return bar == 33;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import java.util.*
|
||||
|
||||
class Lifetime() {
|
||||
val attached = ArrayList<Function0<Unit>>()
|
||||
|
||||
public fun attach(action: () -> Unit) {
|
||||
attached.add(action)
|
||||
}
|
||||
|
||||
fun close() {
|
||||
for (x in attached) x()
|
||||
attached.clear()
|
||||
}
|
||||
}
|
||||
|
||||
public class Viewable<T>() {
|
||||
val items = ArrayList<T>()
|
||||
|
||||
fun add(item: T) {
|
||||
items.add(item)
|
||||
}
|
||||
|
||||
fun remove(item: T) {
|
||||
items.remove(item)
|
||||
}
|
||||
|
||||
fun view(lifetime: Lifetime, viewer: (itemLifetime: Lifetime, item: T) -> Unit) {
|
||||
for (item in items) {
|
||||
viewer(lifetime, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun lifetime(body: (Lifetime) -> Unit) {
|
||||
val l = Lifetime()
|
||||
body(l)
|
||||
l.close()
|
||||
}
|
||||
|
||||
fun<T> Dump(items: ArrayList<T>) {
|
||||
for (item in items) {
|
||||
print(item.toString() + ", ")
|
||||
}
|
||||
println("end")
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val v = Viewable<Int>()
|
||||
val x = ArrayList<Int>()
|
||||
v.add(1)
|
||||
v.add(2)
|
||||
v.add(3)
|
||||
lifetime() {
|
||||
v.view(it) { itemLifetime, item ->
|
||||
x.add(item)
|
||||
Dump(x)
|
||||
itemLifetime.attach() {
|
||||
x.remove(item as Any);
|
||||
Dump(x);
|
||||
println("!")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
var sum = 0
|
||||
val adder = {(a: Int) -> sum += a }
|
||||
adder(3)
|
||||
adder(2)
|
||||
return sum == 5
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package foo
|
||||
|
||||
class A()
|
||||
|
||||
private val doInit = {
|
||||
A()
|
||||
}()
|
||||
|
||||
fun box(): Boolean = doInit is A
|
||||
@@ -0,0 +1,9 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
return apply("OK", {(arg: String) -> arg })
|
||||
}
|
||||
|
||||
fun apply(arg: String, f: (p: String) -> String): String {
|
||||
return f(arg)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
return if (apply(5, {(arg: Int) -> arg + 13 }) == 18) "OK" else "fail"
|
||||
}
|
||||
|
||||
fun apply(arg: Int, f: (p: Int) -> Int): Int {
|
||||
return f(arg)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
fun f(a: Int = 2, b: Int = 3) = a + b
|
||||
|
||||
fun box(): Boolean {
|
||||
if (f(1, 2) != 3) return false;
|
||||
if (f(1, 3) != 4) return false;
|
||||
if (f(3) != 6) return false;
|
||||
if (f() != 5) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
class Point(val x: Int, val y: Int) {
|
||||
fun mul(): (scalar: Int) -> Point {
|
||||
return {(scalar: Int): Point -> Point(x * scalar, y * scalar) }
|
||||
}
|
||||
}
|
||||
|
||||
val m = Point(2, 3).mul()
|
||||
|
||||
fun box(): String {
|
||||
val answer = m(5)
|
||||
return if (answer.x == 10 && answer.y == 15) "OK" else "FAIL"
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package foo
|
||||
|
||||
import java.util.*;
|
||||
|
||||
val d = {(a: Int) -> a + 1 }
|
||||
val p = {(a: Int) -> a * 3 }
|
||||
|
||||
val list = ArrayList<Function1<Int, Int>>();
|
||||
|
||||
fun chain(start: Int): Int {
|
||||
var res = start;
|
||||
for (func in list) {
|
||||
res = (func)(res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
if (chain(0) != 0) {
|
||||
return false;
|
||||
}
|
||||
list.add(d);
|
||||
if (list.get(0)(0) != 1) {
|
||||
return false;
|
||||
}
|
||||
list.add(p);
|
||||
if (list.get(1)(10) != 30) {
|
||||
return false;
|
||||
}
|
||||
if (chain(0) != 3) {
|
||||
return false;
|
||||
}
|
||||
list.add({ it * it });
|
||||
list.add({ it - 100 });
|
||||
if (chain(2) != -19) {
|
||||
return false;
|
||||
}
|
||||
if (({(a: Int) -> a * a }(3)) != 9) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package foo
|
||||
|
||||
|
||||
fun box(): Boolean {
|
||||
fun f() = 3
|
||||
|
||||
return (((f() + f()) == 6) && (b() == 24))
|
||||
}
|
||||
|
||||
|
||||
fun b(): Int {
|
||||
|
||||
fun a(): Int {
|
||||
fun c() = 4
|
||||
return c() * 3
|
||||
}
|
||||
val a = 2
|
||||
return a() * a
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
var sum = 0
|
||||
val addFive = {(a: Int) -> a + 5 }
|
||||
sum = addFive(sum)
|
||||
return sum == 5
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
fun f(a: (Int) -> Int) = a(1)
|
||||
|
||||
fun box(): Boolean {
|
||||
|
||||
if (f() {
|
||||
it + 2
|
||||
} != 3) return false
|
||||
|
||||
if (f() {(a: Int) -> a * 300 } != 300) return false;
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package foo
|
||||
|
||||
fun apply(f: (Int) -> Int, t: Int): Int {
|
||||
return f(t)
|
||||
}
|
||||
|
||||
|
||||
fun box(): Boolean {
|
||||
return apply({(a: Int) -> a + 5 }, 3) == 8
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
|
||||
fun box(): Boolean {
|
||||
return f()
|
||||
}
|
||||
|
||||
fun f(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package foo
|
||||
|
||||
fun sum(param1: Int, param2: Int): Int {
|
||||
return param1 + param2;
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
return (sum(1, 5) == 6)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
fun test(f: (Int) -> Boolean, p: Int) = f(p)
|
||||
|
||||
fun box(): Boolean {
|
||||
if (!test({ it + 1 == 2 }, 1)) return false;
|
||||
|
||||
if (!test({ it > 1 }, 3)) return false;
|
||||
|
||||
return (test({ ((it < 1) == false) }, 1))
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package foo
|
||||
|
||||
var b = 0
|
||||
|
||||
fun loop(times: Int) {
|
||||
var left = times
|
||||
while (left > 0) {
|
||||
val u = {(value: Int) ->
|
||||
b = b + 1
|
||||
}
|
||||
u(left--)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
loop(5)
|
||||
return b == 5
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
package foo
|
||||
|
||||
public fun public_baz(i: Int) {
|
||||
}
|
||||
native public fun public_baz(a: String) {
|
||||
}
|
||||
|
||||
fun internal_baz(i: Int) {
|
||||
}
|
||||
native fun internal_baz(a: String) {
|
||||
}
|
||||
|
||||
private fun private_baz(i: Int) {
|
||||
}
|
||||
native private fun private_baz(a: String) {
|
||||
}
|
||||
|
||||
public class PublicClass {
|
||||
public fun public_baz(i: Int) {
|
||||
}
|
||||
native public fun public_baz(a: String) {
|
||||
}
|
||||
|
||||
fun internal_baz(i: Int) {
|
||||
}
|
||||
native fun internal_baz(a: String) {
|
||||
}
|
||||
|
||||
private fun private_baz(i: Int) {
|
||||
}
|
||||
native private fun private_baz(a: String) {
|
||||
}
|
||||
|
||||
val call_private_baz = { private_baz(0) }
|
||||
val call_private_native_baz = { private_baz("native") }
|
||||
}
|
||||
|
||||
class InternalClass {
|
||||
public fun public_baz(i: Int) {
|
||||
}
|
||||
native public fun public_baz(a: String) {
|
||||
}
|
||||
|
||||
fun internal_baz(i: Int) {
|
||||
}
|
||||
native fun internal_baz(a: String) {
|
||||
}
|
||||
|
||||
private fun private_baz(i: Int) {
|
||||
}
|
||||
native private fun private_baz(a: String) {
|
||||
}
|
||||
|
||||
val call_private_baz = { private_baz(0) }
|
||||
val call_private_native_baz = { private_baz("native") }
|
||||
}
|
||||
|
||||
private class PrivateClass {
|
||||
public fun public_baz(i: Int) {
|
||||
}
|
||||
native public fun public_baz(a: String) {
|
||||
}
|
||||
|
||||
fun internal_baz(i: Int) {
|
||||
}
|
||||
native fun internal_baz(a: String) {
|
||||
}
|
||||
|
||||
private fun private_baz(i: Int) {
|
||||
}
|
||||
native private fun private_baz(a: String) {
|
||||
}
|
||||
|
||||
val call_private_baz = { private_baz(0) }
|
||||
val call_private_native_baz = { private_baz("native") }
|
||||
}
|
||||
|
||||
open public class OpenPublicClass {
|
||||
public fun public_baz(i: Int) {
|
||||
}
|
||||
native public fun public_baz(a: String) {
|
||||
}
|
||||
|
||||
fun internal_baz(i: Int) {
|
||||
}
|
||||
native fun internal_baz(a: String) {
|
||||
}
|
||||
|
||||
private fun private_baz(i: Int) {
|
||||
}
|
||||
native private fun private_baz(a: String) {
|
||||
}
|
||||
|
||||
val call_private_baz = { private_baz(0) }
|
||||
val call_private_native_baz = { private_baz("native") }
|
||||
}
|
||||
|
||||
open class OpenInternalClass {
|
||||
public fun public_baz(i: Int) {
|
||||
}
|
||||
native public fun public_baz(a: String) {
|
||||
}
|
||||
|
||||
fun internal_baz(i: Int) {
|
||||
}
|
||||
native fun internal_baz(a: String) {
|
||||
}
|
||||
|
||||
private fun private_baz(i: Int) {
|
||||
}
|
||||
native private fun private_baz(a: String) {
|
||||
}
|
||||
|
||||
val call_private_baz = { private_baz(0) }
|
||||
val call_private_native_baz = { private_baz("native") }
|
||||
}
|
||||
|
||||
open private class OpenPrivateClass {
|
||||
public fun public_baz(i: Int) {
|
||||
}
|
||||
native public fun public_baz(a: String) {
|
||||
}
|
||||
|
||||
fun internal_baz(i: Int) {
|
||||
}
|
||||
native fun internal_baz(a: String) {
|
||||
}
|
||||
|
||||
private fun private_baz(i: Int) {
|
||||
}
|
||||
native private fun private_baz(a: String) {
|
||||
}
|
||||
|
||||
val call_private_baz = { private_baz(0) }
|
||||
val call_private_native_baz = { private_baz("native") }
|
||||
}
|
||||
|
||||
// Helpers
|
||||
|
||||
native
|
||||
fun String.search(regexp: RegExp): Int = noImpl
|
||||
|
||||
native
|
||||
class RegExp(regexp: String, flags: String = "") {
|
||||
fun exec(s: String): Array<String>? = noImpl
|
||||
}
|
||||
|
||||
val CALEE_NAME = RegExp("""\b\w*(baz[^(]*)""")
|
||||
|
||||
fun Function0<Unit>.extractNames(): Array<String> {
|
||||
val names = CALEE_NAME.exec(this.toString())
|
||||
|
||||
if (names == null || names.size != 2) {
|
||||
throw Exception("Cannot extract function name, $names for actual = \"$this\"")
|
||||
}
|
||||
|
||||
return names
|
||||
}
|
||||
|
||||
// Testing
|
||||
|
||||
var testGroup = ""
|
||||
|
||||
fun test(expected: String, f: () -> Unit) {
|
||||
val actual = f.extractNames()
|
||||
|
||||
if (expected != actual[1]) {
|
||||
throw Exception("Failed on '$testGroup' group: expected = \"$expected\", actual[1] = \"${actual[1]}\"\n actual = $actual")
|
||||
}
|
||||
}
|
||||
|
||||
public fun stable_mangled_baz(i: Int) {
|
||||
}
|
||||
|
||||
val SIMPLE = "baz"
|
||||
val SIMPLE1 = "${SIMPLE}_1"
|
||||
val NATIVE = SIMPLE
|
||||
val STABLE = { stable_mangled_baz(0) }.extractNames()[1]
|
||||
|
||||
fun box(): String {
|
||||
testGroup = "Top Level"
|
||||
test(STABLE) { public_baz(0) }
|
||||
test(NATIVE) { public_baz("native") }
|
||||
test(SIMPLE1) { internal_baz(0) }
|
||||
test(NATIVE) { internal_baz("native") }
|
||||
test(SIMPLE1) { private_baz(0) }
|
||||
test(NATIVE) { private_baz("native") }
|
||||
|
||||
testGroup = "Public Class"
|
||||
test(STABLE) { PublicClass().public_baz(0) }
|
||||
test(NATIVE) { PublicClass().public_baz("native") }
|
||||
test(SIMPLE1) { PublicClass().internal_baz(0) }
|
||||
test(NATIVE) { PublicClass().internal_baz("native") }
|
||||
test(SIMPLE1, PublicClass().call_private_baz)
|
||||
test(NATIVE, PublicClass().call_private_native_baz)
|
||||
|
||||
testGroup = "Internal Class"
|
||||
test(SIMPLE1) { InternalClass().public_baz(0) }
|
||||
test(NATIVE) { InternalClass().public_baz("native") }
|
||||
test(SIMPLE1) { InternalClass().internal_baz(0) }
|
||||
test(NATIVE) { InternalClass().internal_baz("native") }
|
||||
test(SIMPLE1, InternalClass().call_private_baz)
|
||||
test(NATIVE, InternalClass().call_private_native_baz)
|
||||
|
||||
testGroup = "Private Class"
|
||||
test(SIMPLE1) { PrivateClass().public_baz(0) }
|
||||
test(NATIVE) { PrivateClass().public_baz("native") }
|
||||
test(SIMPLE1) { PrivateClass().internal_baz(0) }
|
||||
test(NATIVE) { PrivateClass().internal_baz("native") }
|
||||
test(SIMPLE1, PrivateClass().call_private_baz)
|
||||
test(NATIVE, PrivateClass().call_private_native_baz)
|
||||
|
||||
testGroup = "Open Public Class"
|
||||
test(STABLE) { OpenPublicClass().public_baz(0) }
|
||||
test(NATIVE) { OpenPublicClass().public_baz("native") }
|
||||
test(STABLE) { OpenPublicClass().internal_baz(0) }
|
||||
test(NATIVE) { OpenPublicClass().internal_baz("native") }
|
||||
test(STABLE, OpenPublicClass().call_private_baz)
|
||||
test(NATIVE, OpenPublicClass().call_private_native_baz)
|
||||
|
||||
testGroup = "Open Internal Class"
|
||||
test(STABLE) { OpenInternalClass().public_baz(0) }
|
||||
test(NATIVE) { OpenInternalClass().public_baz("native") }
|
||||
test(STABLE) { OpenInternalClass().internal_baz(0) }
|
||||
test(NATIVE) { OpenInternalClass().internal_baz("native") }
|
||||
test(STABLE, OpenInternalClass().call_private_baz)
|
||||
test(NATIVE, OpenInternalClass().call_private_native_baz)
|
||||
|
||||
testGroup = "Open Private Class"
|
||||
test(STABLE) { OpenPrivateClass().public_baz(0) }
|
||||
test(NATIVE) { OpenPrivateClass().public_baz("native") }
|
||||
test(STABLE) { OpenPrivateClass().internal_baz(0) }
|
||||
test(NATIVE) { OpenPrivateClass().internal_baz("native") }
|
||||
test(STABLE, OpenPrivateClass().call_private_baz)
|
||||
test(NATIVE, OpenPrivateClass().call_private_native_baz)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package foo
|
||||
|
||||
public fun equals(a: Any?): Boolean = true
|
||||
public fun hashCode(): Int = 0
|
||||
public fun toString(): String = ""
|
||||
|
||||
public class PublicClass {
|
||||
override fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
override fun hashCode(): Int = 0
|
||||
override fun toString(): String = "PublicClass"
|
||||
}
|
||||
|
||||
internal class InternalClass {
|
||||
override fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
override fun hashCode(): Int = 1
|
||||
override fun toString(): String = "InternalClass"
|
||||
|
||||
// overloads
|
||||
public fun equals(a: Any?, b: Any?): Boolean = a == b
|
||||
public fun hashCode(i: Int): Int = i
|
||||
public fun toString(s: String): String = s
|
||||
}
|
||||
|
||||
private class PrivateClass {
|
||||
override fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
override fun hashCode(): Int = 2
|
||||
override fun toString(): String = "InternalClass"
|
||||
|
||||
// overloads
|
||||
public fun equals(a: Any?, b: Any?): Boolean = a == b
|
||||
public fun hashCode(i: Int): Int = i
|
||||
public fun toString(s: String): String = s
|
||||
}
|
||||
|
||||
// Helpers
|
||||
|
||||
native
|
||||
fun String.search(regexp: RegExp): Int = noImpl
|
||||
|
||||
native
|
||||
class RegExp(regexp: String, flags: String = "") {
|
||||
fun exec(s: String): Array<String>? = noImpl
|
||||
}
|
||||
|
||||
val CALEE_NAME = RegExp("""((?:equals|hashCode|toString)[^(]*)""")
|
||||
|
||||
fun <T> Function0<T>.extractNames(): Array<String> {
|
||||
val names = CALEE_NAME.exec(this.toString(): String)
|
||||
|
||||
if (names == null || names.size != 2) {
|
||||
throw Exception("Cannot extract function name, $names for actual = \"$this\"")
|
||||
}
|
||||
|
||||
return names
|
||||
}
|
||||
|
||||
// Testing
|
||||
|
||||
var testGroup = ""
|
||||
|
||||
fun test(expected: String, f: () -> Unit) {
|
||||
val actual = f.extractNames()
|
||||
|
||||
if (expected != actual[1]) {
|
||||
throw Exception("Failed on '$testGroup' group: expected = \"$expected\", actual[1] = \"${actual[1]}\"\n actual = $actual")
|
||||
}
|
||||
}
|
||||
|
||||
val SIMPLE_EQUALS = "equals"
|
||||
val SIMPLE_HASH_CODE = "hashCode"
|
||||
val SIMPLE_TO_STRING = "toString"
|
||||
val STABLE_EQUALS = { equals(0) }.extractNames()[1]
|
||||
val STABLE_HASH_CODE = { hashCode() }.extractNames()[1]
|
||||
val STABLE_TO_STRING = { toString() }.extractNames()[1]
|
||||
|
||||
fun box(): String {
|
||||
testGroup = "Public Class"
|
||||
test(STABLE_EQUALS) { PublicClass().equals(0) }
|
||||
test(STABLE_HASH_CODE) { PublicClass().hashCode() }
|
||||
test(STABLE_TO_STRING) { PublicClass().toString() }
|
||||
|
||||
testGroup = "Internal Class"
|
||||
test(STABLE_EQUALS) { InternalClass().equals(0) }
|
||||
test(STABLE_HASH_CODE) { InternalClass().hashCode() }
|
||||
test(STABLE_TO_STRING) { InternalClass().toString() }
|
||||
//test(SIMPLE_EQUALS) { InternalClassWithPublics().equals(0, 1) }
|
||||
//test(SIMPLE_HASH_CODE) { InternalClassWithPublics().hashCode(2) }
|
||||
//test(SIMPLE_TO_STRING) { InternalClassWithPublics().toString("3") }
|
||||
|
||||
testGroup = "Private Class"
|
||||
test(STABLE_EQUALS) { PrivateClass().equals(0) }
|
||||
test(STABLE_HASH_CODE) { PrivateClass().hashCode() }
|
||||
test(STABLE_TO_STRING) { PrivateClass().toString() }
|
||||
//test(SIMPLE_EQUALS) { PrivateClassWithPublics().equals(0, 1) }
|
||||
//test(SIMPLE_HASH_CODE) { PrivateClassWithPublics().hashCode(2) }
|
||||
//test(SIMPLE_TO_STRING) { PrivateClassWithPublics().toString("3") }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package foo
|
||||
|
||||
fun internal_foo(): Int = 1
|
||||
native fun internal_foo(a: Array<Int>) = "should be ingnored"
|
||||
fun internal_foo(i: Int): Int = 2
|
||||
|
||||
fun internal_boo(i: Int): Int = 2
|
||||
fun internal_boo(s: String): Int = 3
|
||||
fun internal_boo(): Int = 1
|
||||
native fun internal_boo(a: Array<Int>) = "should be ingnored"
|
||||
|
||||
val internal_f = { internal_foo() + internal_foo(1) }
|
||||
val internal_b = { internal_boo() + internal_boo(1) }
|
||||
|
||||
|
||||
public fun public_foo(): Int = 1
|
||||
native public fun public_foo(a: Array<Int>): String = "should be ingnored"
|
||||
public fun public_foo(i: Int): Int = 2
|
||||
|
||||
public fun public_boo(i: Int): Int = 2
|
||||
public fun public_boo(s: String): Int = 3
|
||||
public fun public_boo(): Int = 1
|
||||
native public fun public_boo(a: Array<Int>): String = "should be ingnored"
|
||||
|
||||
val public_f = { public_foo() + public_foo(1) }
|
||||
val public_b = { public_boo() + public_boo(1) }
|
||||
|
||||
|
||||
native private fun private_foo(a: Array<Int>): String = "should be ingnored"
|
||||
private fun private_foo(): Int = 1
|
||||
private fun private_foo(i: Int): Int = 2
|
||||
|
||||
native private fun private_boo(a: Array<Int>): String = "should be ingnored"
|
||||
private fun private_boo(i: Int): Int = 2
|
||||
private fun private_boo(s: String): Int = 3
|
||||
private fun private_boo(): Int = 1
|
||||
|
||||
val private_f = { private_foo() + private_foo(1) }
|
||||
val private_b = { private_boo() + private_boo(1) }
|
||||
|
||||
|
||||
public fun mixed_foo(s: String): Int = 3
|
||||
fun mixed_foo(): Int = 1
|
||||
native fun mixed_foo(a: Array<Int>) = "should be ingnored"
|
||||
private fun mixed_foo(s: String, i: Int): Int = 4
|
||||
fun mixed_foo(i: Int): Int = 2
|
||||
|
||||
fun mixed_boo(i: Int): Int = 2
|
||||
private fun mixed_boo(s: String, i: Int): Int = 4
|
||||
native fun mixed_boo(a: Array<Int>) = "should be ingnored"
|
||||
public fun mixed_boo(s: String): Int = 3
|
||||
fun mixed_boo(): Int = 1
|
||||
|
||||
val mixed_f = { mixed_foo() + mixed_foo(1) + mixed_foo("str") + mixed_foo("str", 44) }
|
||||
val mixed_b = { mixed_boo() + mixed_boo(1) + mixed_boo("str") + mixed_boo("str", 44) }
|
||||
|
||||
|
||||
class TestInternal {
|
||||
fun foo(): Int = 1
|
||||
fun foo(i: Int): Int = 2
|
||||
|
||||
fun boo(i: Int): Int = 2
|
||||
fun boo(s: String): Int = 3
|
||||
fun boo(): Int = 1
|
||||
}
|
||||
|
||||
val internal_in_class_f = { TestInternal().foo() + TestInternal().foo(1) }
|
||||
val internal_in_class_b = { TestInternal().boo() + TestInternal().boo(1) }
|
||||
|
||||
|
||||
class TestPublic {
|
||||
public fun foo(): Int = 1
|
||||
public fun foo(i: Int): Int = 2
|
||||
|
||||
public fun boo(i: Int): Int = 2
|
||||
public fun boo(s: String): Int = 3
|
||||
public fun boo(): Int = 1
|
||||
}
|
||||
|
||||
val public_in_class_f = { TestPublic().foo() + TestPublic().foo(1) }
|
||||
val public_in_class_b = { TestPublic().boo() + TestPublic().boo(1) }
|
||||
|
||||
|
||||
class TestPrivate {
|
||||
private fun foo(): Int = 1
|
||||
private fun foo(i: Int): Int = 2
|
||||
|
||||
private fun boo(i: Int): Int = 2
|
||||
private fun boo(s: String): Int = 3
|
||||
private fun boo(): Int = 1
|
||||
|
||||
val f = { foo() + foo(1) }
|
||||
val b = { boo() + boo(1) }
|
||||
}
|
||||
|
||||
val private_in_class_f = TestPrivate().f
|
||||
val private_in_class_b = TestPrivate().b
|
||||
|
||||
|
||||
class TestMixed {
|
||||
public fun foo(s: String): Int = 3
|
||||
fun foo(): Int = 1
|
||||
private fun foo(s: String, i: Int): Int = 4
|
||||
fun foo(i: Int): Int = 2
|
||||
|
||||
fun boo(i: Int): Int = 2
|
||||
private fun boo(s: String, i: Int): Int = 4
|
||||
public fun boo(s: String): Int = 3
|
||||
fun boo(): Int = 1
|
||||
|
||||
val f = { foo() + foo(1) }
|
||||
val b = { boo() + boo(1) }
|
||||
}
|
||||
|
||||
val mixed_in_class_f = TestMixed().f
|
||||
val mixed_in_class_b = TestMixed().b
|
||||
|
||||
// Helpers
|
||||
native
|
||||
fun String.replace(regexp: RegExp, replacement: String): String = noImpl
|
||||
|
||||
fun String.replaceAll(regexp: String, replacement: String): String = replace(RegExp(regexp, "g"), replacement)
|
||||
|
||||
native
|
||||
class RegExp(regexp: String, flags: String)
|
||||
|
||||
//Testing
|
||||
|
||||
fun test(testName: String, ff: Any, fb: Any) {
|
||||
val f = ff.toString()
|
||||
val b = fb.toString().replaceAll("boo", "foo")
|
||||
|
||||
if (f != b) throw Exception("FAILED on ${testName}:\n f = \"$f\"\n b = \"$b\"")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test("internal", internal_f, internal_b)
|
||||
test("public", public_f, public_b)
|
||||
test("private", private_f, private_b)
|
||||
test("mixed", mixed_f, mixed_b)
|
||||
|
||||
test("internal_in_class", internal_in_class_f, internal_in_class_b)
|
||||
test("public_in_class", public_in_class_f, public_in_class_b)
|
||||
test("private_in_class", private_in_class_f, private_in_class_b)
|
||||
test("mixed_in_class", mixed_in_class_f, mixed_in_class_b)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package foo
|
||||
|
||||
fun test(x: Int, y: Int) = y - x
|
||||
|
||||
fun box(): Boolean {
|
||||
if (test(1, 2) != 1) {
|
||||
return false;
|
||||
}
|
||||
if (test(x = 1, y = 2) != 1) {
|
||||
return false;
|
||||
}
|
||||
if (test(y = 2, x = 1) != 1) {
|
||||
return false;
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
trait A {
|
||||
fun foo(i: Int) = "A"
|
||||
}
|
||||
|
||||
trait B {
|
||||
fun foo(s: String) = "B"
|
||||
}
|
||||
|
||||
class C : A, B {
|
||||
fun foo() = "C"
|
||||
}
|
||||
|
||||
fun assertEquals(expected: Any, actual: Any) {
|
||||
if (expected != actual) throw Exception("expected = $expected\nactual = $actual")
|
||||
}
|
||||
fun box(): String {
|
||||
assertEquals(C().foo(1), "A")
|
||||
assertEquals(C().foo(""), "B")
|
||||
assertEquals(C().foo(), "C")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package foo
|
||||
|
||||
fun testSize(expectedSize: Int, vararg i: Int): Boolean {
|
||||
return (i.size == expectedSize)
|
||||
}
|
||||
|
||||
fun testSum(expectedSum: Int, vararg i: Int): Boolean {
|
||||
var sum = 0
|
||||
for (j in i) {
|
||||
sum += j
|
||||
}
|
||||
|
||||
return (expectedSum == sum)
|
||||
}
|
||||
|
||||
fun testSpreadOperator(vararg args: Int): Boolean {
|
||||
var sum = 0;
|
||||
for (a in args) sum += a
|
||||
|
||||
return testSize(args.size, *args) && testSum(sum, *args)
|
||||
}
|
||||
|
||||
class Bar(val size: Int, val sum: Int) {
|
||||
fun test(vararg args: Int) = testSize(size, *args) && testSum(sum, *args)
|
||||
}
|
||||
|
||||
object obj {
|
||||
fun test(size: Int, sum: Int, vararg args: Int) = testSize(size, *args) && testSum(sum, *args)
|
||||
}
|
||||
|
||||
fun spreadInMethodCall(size: Int, sum: Int, vararg args: Int) = Bar(size, sum).test(*args)
|
||||
|
||||
fun spreadInObjectMethodCall(size: Int, sum: Int, vararg args: Int) = obj.test(size, sum, *args)
|
||||
|
||||
fun testVarargWithFunLit(vararg args: Int, f: (a: IntArray) -> Boolean): Boolean = f(args)
|
||||
|
||||
fun box(): String {
|
||||
if (!testSize(0))
|
||||
return "wrong vararg size when call function without args"
|
||||
|
||||
if (!testSum(0))
|
||||
return "wrong vararg sum (arguments) when call function without args"
|
||||
|
||||
if (!testSize(6, 1, 1, 1, 2, 3, 4))
|
||||
return "wrong vararg size when call function with some args (1)"
|
||||
|
||||
if (!testSum(30, 10, 20, 0))
|
||||
return "wrong vararg sum (arguments) when call function with some args (1)"
|
||||
|
||||
if (!testSpreadOperator(30, 10, 20, 0))
|
||||
return "failed when call function using spread operator"
|
||||
|
||||
if (!Bar(3, 30).test(10, 20, 0))
|
||||
return "failed when call method"
|
||||
|
||||
if (!spreadInMethodCall(2, 3, 1, 2))
|
||||
return "failed when call method using spread operator"
|
||||
|
||||
if (!obj.test(5, 15, 1, 2, 3, 4, 5))
|
||||
return "failed when call method of object"
|
||||
|
||||
if (!spreadInObjectMethodCall(2, 3, 1, 2))
|
||||
return "failed when call method of object using spread operator"
|
||||
|
||||
if (!testVarargWithFunLit(1, 2, 3) { args -> args.size == 3 })
|
||||
return "failed when call function with vararg and fun literal"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package foo
|
||||
|
||||
fun foo(a: Int): Int = when {
|
||||
a == 1 || a + 2 == 3 -> 5
|
||||
else -> 6
|
||||
}
|
||||
fun box(): String {
|
||||
if (foo(1) != 5) return "fail1: ${foo(1)}"
|
||||
if (foo(2) != 6) return "fail2: ${foo(1)}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package foo
|
||||
|
||||
abstract class B {
|
||||
abstract fun foo(param: String): String
|
||||
}
|
||||
|
||||
class A : B() {
|
||||
// must be here - before open fun foo(String)
|
||||
private fun foo(param: Int) = "foo(Int)"
|
||||
|
||||
fun foo() = "foo()"
|
||||
|
||||
override fun foo(param: String) = "foo(String)"
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
return A().foo("OK") == "foo(String)"
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
var box = "foo"
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package foo
|
||||
|
||||
class X
|
||||
|
||||
fun box(): String {
|
||||
val a = X()
|
||||
val b = X()
|
||||
if (!a.identityEquals(a)) return "a !== a"
|
||||
if (a.identityEquals(b)) return "X() === X()"
|
||||
val c = a
|
||||
if (!c.identityEquals(a)) return "c = a; c !== a"
|
||||
|
||||
if (X() identityEquals a) return "X() identityEquals a"
|
||||
|
||||
val t = !(X() identityEquals a)
|
||||
if (!t) return "t = !(X() identityEquals a); t == false"
|
||||
|
||||
val f = !!(X() identityEquals a)
|
||||
if (f) return "f = !!(X() identityEquals null); f == true"
|
||||
return "OK";
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
if (!null.identityEquals(null)) return "null !== null"
|
||||
if (!("ab" identityEquals "ab")) return "ab !== ab"
|
||||
if (("ab" identityEquals "a")) return "ab === a"
|
||||
|
||||
if ("0" identityEquals 0) return "'0' === 0"
|
||||
if (!(0 identityEquals 0)) return "0 !== 0"
|
||||
if (0 identityEquals 1) return "0 === 1"
|
||||
|
||||
|
||||
return "OK";
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var foo = {(x: String) -> x + "K" }
|
||||
return foo.invoke("O")
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
class Foo(val postfix: String) {
|
||||
public fun invoke(text: String): String {
|
||||
return text + postfix
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = Foo(" world!")
|
||||
return a("hello")
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
|
||||
if (!true.and(true)) {
|
||||
return false;
|
||||
}
|
||||
if (false.and(true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!true.or(false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (false.or(false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!true.or(true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (false.and(false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (false.xor(false)) {
|
||||
return false;
|
||||
}
|
||||
if (!true.xor(false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (true.xor(true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (true.not()) {
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
if (!false.not()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fun main(args: Array<String>) {
|
||||
println(true.and1(true))
|
||||
}
|
||||
|
||||
fun Boolean.and1(other: Boolean): Boolean {
|
||||
if (other == true) {
|
||||
if (this == true) {
|
||||
return true ;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package foo
|
||||
|
||||
class B {
|
||||
val d = true
|
||||
|
||||
fun f(): Boolean {
|
||||
val c = object {
|
||||
fun foo(): Boolean {
|
||||
return d
|
||||
}
|
||||
fun boo(): Boolean {
|
||||
return foo()
|
||||
}
|
||||
}
|
||||
return c.boo()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
return B().f()
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package foo
|
||||
|
||||
class Data(val rawData: Array<Int>, val width: Int, val height: Int) {
|
||||
fun get(x: Int, y: Int): ColorLike {
|
||||
return object : ColorLike {
|
||||
override val red: Int = rawData[(y * width + x) * 4 + 0];
|
||||
override val green: Int = rawData[(y * width + x) * 4 + 1];
|
||||
override val blue: Int = rawData[(y * width + x) * 4 + 2];
|
||||
}
|
||||
}
|
||||
|
||||
fun set(x: Int, y: Int, color: ColorLike) {
|
||||
rawData[(y * width + x) * 4 + 0] = color.red;
|
||||
rawData[(y * width + x) * 4 + 1] = color.green;
|
||||
rawData[(y * width + x) * 4 + 2] = color.blue;
|
||||
}
|
||||
|
||||
fun each(block: (x: Int, y: Int) -> Unit) {
|
||||
for (x in 0..width - 1) {
|
||||
for (y in 0..height - 1) {
|
||||
block(x, y)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Color(r: Int, g: Int, b: Int) : ColorLike {
|
||||
override val red: Int = r
|
||||
override val green: Int = g
|
||||
override val blue: Int = b
|
||||
}
|
||||
|
||||
trait ColorLike {
|
||||
val red: Int;
|
||||
val green: Int;
|
||||
val blue: Int;
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
val d = Data(Array(4) { 0 }, 1, 1)
|
||||
if (d[0, 0].red != 0) {
|
||||
return false
|
||||
}
|
||||
if (d[0, 0].green != 0) {
|
||||
return false
|
||||
}
|
||||
if (d[0, 0].blue != 0) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package foo
|
||||
|
||||
open class A {
|
||||
open fun foo(a: Int = 1) = a
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
override fun foo(a: Int) = a + 1
|
||||
}
|
||||
|
||||
fun box() = (B().foo() == 2)
|
||||
@@ -0,0 +1,25 @@
|
||||
package foo
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun box(): Boolean {
|
||||
val data = arrayList("foo", "bar")
|
||||
if (data.head != "foo") {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
public inline fun arrayList<T>(vararg values: T): ArrayList<T> {
|
||||
val c = ArrayList<T>()
|
||||
for (v in values) {
|
||||
c.add(v)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
public inline val <T> ArrayList<T>.head: T
|
||||
get() {
|
||||
return get(0)
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package foo
|
||||
|
||||
var c0 = 0
|
||||
var c1 = 0
|
||||
var c2 = 0
|
||||
var c3 = 0
|
||||
|
||||
fun cStr(): String {
|
||||
return "${c0}${c1}${c2}${c3}"
|
||||
}
|
||||
|
||||
fun get1(): Int {
|
||||
c3++
|
||||
return 1
|
||||
}
|
||||
|
||||
class A() {
|
||||
var p = 0
|
||||
fun get(i: Int): Int {
|
||||
c1++
|
||||
return 0
|
||||
}
|
||||
|
||||
fun set(i: Int, value: Int) {
|
||||
c2++
|
||||
}
|
||||
}
|
||||
|
||||
val a: A = A()
|
||||
get() {
|
||||
c0++
|
||||
return $a
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var d = a[1]
|
||||
if (cStr() != "1100") {
|
||||
return "Fail: d = a[1], cStr(): ${cStr()}"
|
||||
}
|
||||
|
||||
++a[1]
|
||||
if (cStr() != "2310") {
|
||||
return "Fail: ++a[1], cStr(): ${cStr()}"
|
||||
}
|
||||
|
||||
--a[1]
|
||||
if (cStr() != "3520") {
|
||||
return "Fail: --a[1], cStr(): ${cStr()}"
|
||||
}
|
||||
|
||||
++a[get1()]
|
||||
if (cStr() != "4731") {
|
||||
return "Fail: ++a[get1()], cStr(): ${cStr()}"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package foo
|
||||
|
||||
var c0 = 0
|
||||
var c1 = 0
|
||||
var c2 = 0
|
||||
|
||||
class A() {
|
||||
var p = 0
|
||||
fun divAssign(a: Int) {
|
||||
c1++;
|
||||
}
|
||||
fun times(a: Int): A {
|
||||
c2++;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
var a: A = A()
|
||||
get() {
|
||||
c0++
|
||||
return $a
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
a /= 3
|
||||
if (c0 != 1) {
|
||||
return "1"
|
||||
}
|
||||
if (c1 != 1) {
|
||||
return "2"
|
||||
}
|
||||
a *= 3
|
||||
if (c0 != 2) {
|
||||
return "3"
|
||||
}
|
||||
if (c2 != 1) {
|
||||
return "4"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
var c = 0
|
||||
|
||||
class A() {
|
||||
var p = 0;
|
||||
{
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
++A().p
|
||||
if (c != 1) {
|
||||
return false;
|
||||
}
|
||||
--A().p
|
||||
if (c != 2) {
|
||||
return false;
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package foo
|
||||
|
||||
class Range() {
|
||||
|
||||
val reversed = false;
|
||||
val start = 0;
|
||||
var count = 10;
|
||||
|
||||
fun next() = start + if (reversed) -(--count) else (--count);
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
val r = Range()
|
||||
if (r.next() != 9) {
|
||||
return false;
|
||||
}
|
||||
if (r.next() != 8) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class A(var a: Int) {
|
||||
{
|
||||
$a = 3
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = (A(1).a == 3)
|
||||
@@ -0,0 +1,21 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
if (f(null) != false) {
|
||||
return false;
|
||||
}
|
||||
if (f(2) != true) {
|
||||
return false;
|
||||
}
|
||||
if (f(1) != false) {
|
||||
return true;
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun Int.isEven() = (this % 2) == 0
|
||||
|
||||
fun f(a: Int?): Boolean {
|
||||
return a?.isEven() ?: false
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
|
||||
fun box(): Boolean {
|
||||
val a: Int? = 0
|
||||
|
||||
return (a!! + 3) == 3
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
var c = 0
|
||||
val a: Int?
|
||||
get() {
|
||||
c++
|
||||
return 2
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
return c == 0 && (a!! + 3) == 5 && c == 1
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
|
||||
fun box(): Boolean {
|
||||
val a: Int? = null
|
||||
|
||||
return (a!! + 3) == 3
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package foo
|
||||
|
||||
fun A.create(init: A.() -> Unit): A {
|
||||
init()
|
||||
return this
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
val a = A().create {
|
||||
c = 1 + t
|
||||
}
|
||||
return a.c == 4
|
||||
}
|
||||
|
||||
class A() {
|
||||
val t = 3
|
||||
var c = 2
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package foo
|
||||
|
||||
class A() {
|
||||
fun foo() = 1
|
||||
fun a(f: A.() -> Int): Int {
|
||||
return f()
|
||||
}
|
||||
}
|
||||
|
||||
var d = 0
|
||||
|
||||
val p: A.() -> Int = {
|
||||
d = foo()
|
||||
d++
|
||||
}
|
||||
|
||||
val c = A().a(p)
|
||||
|
||||
fun box() = (c == 1)
|
||||
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
class A() {
|
||||
fun lold() = true
|
||||
|
||||
val p = {
|
||||
{
|
||||
lold()
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
return A().p()
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
class A() {
|
||||
fun lold() = true
|
||||
val p: () -> Boolean
|
||||
{
|
||||
$p = { { lold() }() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): Boolean {
|
||||
return A().p()
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package foo
|
||||
|
||||
fun Any.foo1(): () -> String {
|
||||
return { "239" + this }
|
||||
}
|
||||
|
||||
fun Int.foo2(): (i: Int) -> Int {
|
||||
return { x -> x + this }
|
||||
}
|
||||
|
||||
fun fooT1<T>(t: T) = { t.toString() }
|
||||
|
||||
fun fooT2<T>(t: T) = {(x: T) -> t.toString() + x.toString() }
|
||||
|
||||
fun box(): Any? {
|
||||
if ( (10.foo1())() != "23910") return "foo1 fail"
|
||||
if ( (10.foo2())(1) != 11 ) return "foo2 fail"
|
||||
|
||||
if (1.{ Int.() -> this + 1 }() != 2) return "test 3 failed";
|
||||
if ( { 1 }() != 1) return "test 4 failed";
|
||||
if ( {(x: Int) -> x }(1) != 1) return "test 5 failed";
|
||||
if ( 1.{ Int.(x: Int) -> x + this }(1) != 2) return "test 6 failed";
|
||||
val tmp = 1.({ Int.() -> this })()
|
||||
if (tmp != 1) return "test 7 failed, res: $tmp ${tmp is Int}";
|
||||
if ( (fooT1<String>("mama"))() != "mama") return "test 8 failed";
|
||||
if ( (fooT2<String>("mama"))("papa") != "mamapapa") return "test 9 failed";
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package foo
|
||||
|
||||
fun box() = if (true) throw Exception() else false
|
||||
@@ -0,0 +1,11 @@
|
||||
package foo
|
||||
|
||||
class TabIterator : Iterator<Any?> {
|
||||
override fun hasNext(): Boolean = false
|
||||
|
||||
override fun next(): Any? {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = !TabIterator().hasNext()
|
||||
@@ -0,0 +1,109 @@
|
||||
package foo
|
||||
|
||||
import js.*
|
||||
|
||||
class RangeIterator(val start: Int, var count: Int, val reversed: Boolean) {
|
||||
|
||||
var i = start
|
||||
|
||||
fun next(): Int {
|
||||
--count
|
||||
if (reversed) {
|
||||
i--
|
||||
return i + 1
|
||||
}
|
||||
else {
|
||||
i++
|
||||
return i - 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun hasNext() = (count > 0);
|
||||
}
|
||||
|
||||
class NumberRange(val start: Int, val size: Int, val reversed: Boolean) {
|
||||
|
||||
val end: Int
|
||||
get() = if (reversed) start - size + 1 else start + size - 1
|
||||
|
||||
fun contains(number: Int): Boolean {
|
||||
if (reversed) {
|
||||
return (number <= start) && (number > start - size);
|
||||
}
|
||||
else {
|
||||
return (number >= start) && (number < start + size);
|
||||
}
|
||||
}
|
||||
|
||||
fun iterator() = RangeIterator(start, size, reversed);
|
||||
}
|
||||
|
||||
|
||||
fun box() = testRange() && testReversedRange();
|
||||
|
||||
fun testRange(): Boolean {
|
||||
|
||||
val oneToFive = NumberRange(1, 4, false);
|
||||
if (oneToFive.contains(5)) return false;
|
||||
if (oneToFive.contains(0)) return false;
|
||||
if (oneToFive.contains(-100)) return false;
|
||||
if (oneToFive.contains(10)) return false;
|
||||
if (!oneToFive.contains(1)) return false;
|
||||
if (!oneToFive.contains(2)) return false;
|
||||
if (!oneToFive.contains(3)) return false;
|
||||
if (!oneToFive.contains(4)) return false;
|
||||
if (!(oneToFive.start == 1)) return false;
|
||||
if (!(oneToFive.size == 4)) return false;
|
||||
if (!(oneToFive.end == 4)) return false;
|
||||
|
||||
var sum = 0;
|
||||
for (i in oneToFive) {
|
||||
sum += i;
|
||||
}
|
||||
for (i in oneToFive) {
|
||||
print(i)
|
||||
}
|
||||
|
||||
if (sum != 10) return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
fun testReversedRange(): Boolean {
|
||||
|
||||
println("Testing reversed range.");
|
||||
|
||||
val tenToFive = NumberRange(10, 5, true);
|
||||
|
||||
if (tenToFive.contains(5)) return false;
|
||||
if (tenToFive.contains(11)) return false;
|
||||
if (tenToFive.contains(-100)) return false;
|
||||
if (tenToFive.contains(1000)) return false;
|
||||
if (!tenToFive.contains(6)) return false;
|
||||
if (!tenToFive.contains(7)) return false;
|
||||
if (!tenToFive.contains(8)) return false;
|
||||
if (!tenToFive.contains(9)) return false;
|
||||
if (!tenToFive.contains(10)) return false;
|
||||
|
||||
if (!(tenToFive.start == 10)) return false;
|
||||
if (!(tenToFive.size == 5)) return false;
|
||||
if (!(tenToFive.end == 6)) return false;
|
||||
|
||||
for (i in tenToFive) {
|
||||
println(i)
|
||||
}
|
||||
|
||||
|
||||
var sum = 0;
|
||||
for (i in tenToFive) {
|
||||
sum += i;
|
||||
}
|
||||
|
||||
if (sum != 40) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fun main(args: Array<String>) {
|
||||
println("Hello, world!")
|
||||
println(p)
|
||||
}
|
||||
|
||||
|
||||
val p: Int
|
||||
get() {
|
||||
println("Gotcha")
|
||||
return 3
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
val y = 3
|
||||
|
||||
fun f(a: Int): Int {
|
||||
val x = 42
|
||||
val y = 50
|
||||
|
||||
return y
|
||||
}
|
||||
|
||||
fun box(): Int {
|
||||
return f(y)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package foo
|
||||
|
||||
var c = 2
|
||||
|
||||
fun loop(times: Int) {
|
||||
var left = times
|
||||
while (left > 0) {
|
||||
val u: (value: Int) -> Unit = {
|
||||
c++
|
||||
}
|
||||
u(left--)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): Any? {
|
||||
loop(5)
|
||||
return if (c == 7) return "OK" else c
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package a.b.c
|
||||
|
||||
import js.*
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println("ayee")
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
var c = 2
|
||||
|
||||
fun incC(i: Int) {
|
||||
c += c + i
|
||||
}
|
||||
|
||||
fun box(): Any? {
|
||||
for (i in 0..2) {
|
||||
incC(i)
|
||||
}
|
||||
return if (c == 20) "OK" else c
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
var c = 2
|
||||
|
||||
fun incC(i: Int) {
|
||||
c += c + i
|
||||
}
|
||||
|
||||
fun box(): Any? {
|
||||
for (i in 0..2) {
|
||||
incC(i)
|
||||
}
|
||||
return if (c == 20) "OK" else c
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package foo
|
||||
|
||||
fun lold() = true
|
||||
|
||||
val p = { { lold() }() }
|
||||
|
||||
fun box() = p() && foo.p()
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
|
||||
class A() {
|
||||
private var c: Int = 3
|
||||
private get
|
||||
private set
|
||||
|
||||
fun f() = c + 1
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
return A().f() == 4
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package foo
|
||||
|
||||
class A() {
|
||||
val p = { true }
|
||||
}
|
||||
|
||||
|
||||
fun box(): Boolean {
|
||||
return A().p()
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
var i = 0
|
||||
|
||||
fun test(): Int? = i++
|
||||
|
||||
fun box(): Boolean {
|
||||
if (i != 0) return false
|
||||
test()?.plus(1)
|
||||
if (i != 1) return false
|
||||
test()?.minus(2)
|
||||
if (i != 2) return false
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package foo
|
||||
|
||||
var s = ""
|
||||
|
||||
class A() {
|
||||
fun test(v: String) {
|
||||
s += "4"
|
||||
}
|
||||
}
|
||||
|
||||
fun f(): String {
|
||||
s += "3"
|
||||
return ""
|
||||
}
|
||||
|
||||
class B() {
|
||||
val a: A
|
||||
get() {
|
||||
s += "2"
|
||||
return A()
|
||||
}
|
||||
|
||||
fun test() {
|
||||
s += "1"
|
||||
a.test("${if (true) f() else 4}")
|
||||
s += "5"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): Any? {
|
||||
B().test()
|
||||
return if (s != "12345") s else true
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package foo
|
||||
|
||||
var p = 0
|
||||
val c = p++ // creates temporary value
|
||||
|
||||
fun box() = (p == 1) && (c == 0)
|
||||
@@ -0,0 +1,18 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
if (t(1) != 0) {
|
||||
return false
|
||||
}
|
||||
if (t(0) != 1) {
|
||||
return false
|
||||
}
|
||||
return (t(100) == 2)
|
||||
|
||||
}
|
||||
|
||||
fun t(i: Int) = when(i) {
|
||||
0 -> 1
|
||||
1 -> 0
|
||||
else -> 2
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package foo
|
||||
|
||||
val testString = "foobarbaz"
|
||||
val testStringSize = 9
|
||||
val emptyString = ""
|
||||
val startsWithParam = "foo"
|
||||
val endsWithParam = "az"
|
||||
val containsParam = "ar"
|
||||
|
||||
fun assertEquals(actual: Any, expected: Any, s: String, whatTested: String) =
|
||||
if (expected != actual) "String.$whatTested fails on \"$s\", expected: $expected, actual: $actual" else null
|
||||
|
||||
fun assertEquals(actual: Any, expected: Any, s: CharSequence, whatTested: CharSequence) =
|
||||
if (expected != actual) "CharSequence.$whatTested fails on \"$s\", expected: $expected, actual: $actual" else null
|
||||
|
||||
fun testString(s: String, expectedSize: Int): String? =
|
||||
assertEquals(s.size, expectedSize, s, "size") ?:
|
||||
assertEquals(s.length(), expectedSize, s, "length()") ?:
|
||||
assertEquals(s.length, expectedSize, s, "length") ?:
|
||||
assertEquals(s.isEmpty(), expectedSize == 0, s, "isEmpty()") ?:
|
||||
assertEquals(s.startsWith(startsWithParam), expectedSize != 0, s, "startsWith(\"$startsWithParam\")") ?:
|
||||
assertEquals(s.endsWith(endsWithParam), expectedSize != 0, s, "endsWith(\"$endsWithParam\")") ?:
|
||||
assertEquals(s.contains(containsParam), expectedSize != 0, s, "contains(\"$containsParam\")")
|
||||
|
||||
fun testCharSequence(s: CharSequence, expectedSize: Int): String? =
|
||||
assertEquals(s.size, expectedSize, s, "size") ?:
|
||||
assertEquals(s.length(), expectedSize, s, "length()") ?:
|
||||
assertEquals(s.length, expectedSize, s, "length") ?:
|
||||
assertEquals(s.isEmpty(), expectedSize == 0, s, "isEmpty()")
|
||||
|
||||
fun box(): String =
|
||||
testString(testString, testStringSize) ?:
|
||||
testString(emptyString, 0) ?:
|
||||
testCharSequence(testString, testStringSize) ?:
|
||||
testCharSequence(emptyString, 0) ?:
|
||||
"OK"
|
||||
@@ -0,0 +1,7 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var number = 3
|
||||
return ("my age is $number");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
if ("${3}" != "3") return false
|
||||
return "${3}" == "3"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package foo
|
||||
|
||||
var i = 0
|
||||
|
||||
class A() {
|
||||
override fun toString(): String {
|
||||
i++
|
||||
return "bar"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
val a = A()
|
||||
val s = "$a == $a"
|
||||
return s == "bar == bar" && i == 2
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var right = 2
|
||||
var left = 3
|
||||
return ("left = $left\nright = $right\nsum = ${left + right}\n");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val number = 3
|
||||
val s1 = "${number - 1}${number}"
|
||||
val s2 = "${5}${4}"
|
||||
return "${s1}${s2}"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package foo
|
||||
|
||||
class A(var i: Int) {
|
||||
override fun toString() = "a$i"
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
var p = A(2);
|
||||
var n = A(1);
|
||||
if ("$p$n" != "a2a1") {
|
||||
return false;
|
||||
}
|
||||
if ("${A(10)}" != "a10") {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
|
||||
val a = "bar";
|
||||
var b = "foo";
|
||||
b = a;
|
||||
return (b == "bar");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
|
||||
val a = "String";
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var name = "Hello"
|
||||
return ("o${name}o");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package foo
|
||||
|
||||
|
||||
fun box(): Boolean {
|
||||
val t1: Any = "3"
|
||||
val t2: Any = 3
|
||||
val t3: Any = "4"
|
||||
val t4: Any = 4
|
||||
if (t3 == t4) return false
|
||||
return t1 != t2
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package foo
|
||||
|
||||
// todo drop
|
||||
class Pair<F, S>(val first: F, val second: S)
|
||||
fun <F, S> F.to(second: S): Pair<F, S> = Pair(this, second)
|
||||
|
||||
fun box(): String {
|
||||
val testInput = "test data\t1foo 2 bar"
|
||||
val tests = array(
|
||||
" " to array("test", "data\t1foo", "", "2", "bar"),
|
||||
"\\s+" to array("test", "data", "1foo", "2", "bar"),
|
||||
"[sd]" to array("te", "t ", "ata\t1foo 2 bar"),
|
||||
"[\\d]" to array("test data\t", "foo ", " bar")
|
||||
)
|
||||
|
||||
for (test in tests) {
|
||||
val regexp = test.first
|
||||
val expected = test.second
|
||||
val result = testInput.split(regexp)
|
||||
|
||||
if (result != expected) return "Wrong result for '$regexp' -- Expected: $expected | Actual: $result"
|
||||
}
|
||||
|
||||
for (test in tests) {
|
||||
val regexp = test.first
|
||||
val limit = 2
|
||||
val expected = Array(limit) { test.second[it] }
|
||||
val result = testInput.split(regexp, limit)
|
||||
|
||||
if (result != expected) return "Wrong result for '$regexp' -- Expected: $expected | Actual: $result"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
class Foo(val name: String) {
|
||||
override public fun toString(): String {
|
||||
return name + "S"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = Foo("abc")
|
||||
val b = Foo("def")
|
||||
val message = "a = $a, b = $b"
|
||||
return message
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package foo
|
||||
|
||||
// test String template must have one or more entries.
|
||||
public class Fe {
|
||||
fun open(method: String, url: String, async: Boolean = true, user: String = "", password: String = "") = "$method $url $async $user $password"
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
val a = "abc"
|
||||
val b = "def"
|
||||
val message = "a = $a, b = $b"
|
||||
|
||||
if (message != "a = abc, b = def") return false
|
||||
|
||||
val v1 = null
|
||||
if ("returns null null" != "returns $v1 ${null}") return false
|
||||
|
||||
return Fe().open("22", "33") == "22 33 true "
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
class Foo(val name: String) {
|
||||
|
||||
public override fun toString(): String {
|
||||
return "Foo($name)"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = Foo("James")
|
||||
return a.toString()
|
||||
}
|
||||
Reference in New Issue
Block a user