JS backend: testFiles -> testData
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package foo
|
||||
|
||||
trait A {
|
||||
class object {
|
||||
val OK: String = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return A.OK
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
var a = 3
|
||||
class object {
|
||||
var a = -2
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
A.a = 2
|
||||
if (A.a != 2) return "A.a != 2, it: ${A.a}"
|
||||
|
||||
val a = A
|
||||
a.a = 3
|
||||
if (a.a != 3) return "a = A; a.a = 3; a != 3, it: ${a.a}"
|
||||
|
||||
if (A().a != 3) return "A().a != 3, it: ${A().a}"
|
||||
|
||||
val x = A()
|
||||
x.a = 4
|
||||
if (x.a != 4) return "x = A(); x.a = 4; x.a != 4, it: ${x.a}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
val a = 3
|
||||
class object {
|
||||
val a = 2
|
||||
val b = 5
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
if (A.a != 2) return "A.a != 2, it: ${A.a}"
|
||||
if (A.b != 5) return "A.b != 5, it: ${A.b}"
|
||||
|
||||
val b = A
|
||||
if (b.a != 2) return "b = A; b != 2, it: ${b.a}"
|
||||
|
||||
if (A().a != 3) return "A().a != 3, it: ${A().a}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package foo
|
||||
|
||||
open class A {
|
||||
val a = 3
|
||||
fun foo(): Int {
|
||||
return 5
|
||||
}
|
||||
class object: A() {
|
||||
val c = a
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
class object: A() {
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (A.a != 3) return "A.a != 3, it: ${A.a}"
|
||||
if (A.foo() != 5) return "A.foo() != 5, it: ${A.foo()}"
|
||||
|
||||
val a = A
|
||||
if (a.c != 3) return "a = A; a.c != 3, it: ${a.c}"
|
||||
|
||||
if (A().a != 3) return "A().a != 3, it: ${A().a}"
|
||||
|
||||
if (B.a != 3) return "B.a != 3, it: ${B.a}"
|
||||
val b = B
|
||||
if (b.foo() != 5) return "b = B; b.foo() != 5, it: ${b.foo()}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package foo
|
||||
|
||||
fun test(f: () -> String): String {
|
||||
val funLit = { f() }
|
||||
return funLit()
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
return test { "OK" }
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package foo
|
||||
|
||||
fun run<T>(f: () -> T) = f()
|
||||
|
||||
val r = "OK"
|
||||
|
||||
fun simple(s: String? = null): String {
|
||||
if (s != null) return s
|
||||
|
||||
return run {
|
||||
simple("OK")
|
||||
}
|
||||
}
|
||||
|
||||
val ok = "OK"
|
||||
fun withClosure(s: String? = null): String {
|
||||
if (s != null) return s
|
||||
|
||||
return ok + run {
|
||||
withClosure(ok)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (simple("OK") != "OK") return "failed on simple recursion"
|
||||
|
||||
if (withClosure() != ok + ok) return "failed when closure something"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package foo
|
||||
|
||||
fun run<T>(f: () -> T) = f()
|
||||
|
||||
fun funfun(): Boolean {
|
||||
val result = true
|
||||
|
||||
fun foo(): Boolean {
|
||||
fun bar() = result
|
||||
return bar()
|
||||
}
|
||||
|
||||
return foo()
|
||||
}
|
||||
|
||||
fun litlit(): Boolean {
|
||||
val result = true
|
||||
|
||||
return run {
|
||||
run { result }
|
||||
}
|
||||
}
|
||||
|
||||
fun funlit(): Boolean {
|
||||
val result = true
|
||||
|
||||
fun foo(): Boolean {
|
||||
return run { result }
|
||||
}
|
||||
|
||||
return foo()
|
||||
}
|
||||
|
||||
fun litfun(): Boolean {
|
||||
val result = true
|
||||
|
||||
return run {
|
||||
fun bar() = result
|
||||
bar()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (!funfun()) return "funfun failed"
|
||||
if (!litlit()) return "litlit failed"
|
||||
if (!funlit()) return "funlit failed"
|
||||
if (!litfun()) return "litfun failed"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package foo
|
||||
|
||||
fun run<T>(f: () -> T) = f()
|
||||
|
||||
class Fail(val message: String) : RuntimeException(message) {
|
||||
val isFail = true // workaround for exception handling
|
||||
}
|
||||
|
||||
|
||||
class A {
|
||||
var testName = ""
|
||||
fun assertEquals(actual: Int, expected: Int, message: String) =
|
||||
if (actual != expected) throw Fail("$message in $testName test.")
|
||||
|
||||
val a = 12
|
||||
var b = 1
|
||||
|
||||
fun boo(c: Int) = c
|
||||
|
||||
fun litlit() {
|
||||
testName = "litlit"
|
||||
run {
|
||||
run {
|
||||
assertEquals(a, 12, "a != 12")
|
||||
|
||||
assertEquals(b, 1, "b != 1")
|
||||
b = 23
|
||||
assertEquals(b, 23, "b != 23")
|
||||
|
||||
assertEquals(boo(34), 34, "boo(34) != 34")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun funfun() {
|
||||
testName = "funfun"
|
||||
fun foo() {
|
||||
fun bar() {
|
||||
assertEquals(a, 12, "a != 12")
|
||||
|
||||
assertEquals(b, 1, "b != 1")
|
||||
b = 23
|
||||
assertEquals(b, 23, "b != 23")
|
||||
|
||||
assertEquals(boo(34), 34, "boo(34) != 34")
|
||||
}
|
||||
bar()
|
||||
}
|
||||
foo()
|
||||
}
|
||||
|
||||
fun litfun() {
|
||||
testName = "litfun"
|
||||
run {
|
||||
fun bar() {
|
||||
assertEquals(a, 12, "a != 12")
|
||||
|
||||
assertEquals(b, 1, "b != 1")
|
||||
b = 23
|
||||
assertEquals(b, 23, "b != 23")
|
||||
|
||||
assertEquals(boo(34), 34, "boo(34) != 34")
|
||||
}
|
||||
bar()
|
||||
}
|
||||
}
|
||||
|
||||
fun funlit() {
|
||||
testName = "funlit"
|
||||
fun foo() {
|
||||
run {
|
||||
assertEquals(a, 12, "a != 12")
|
||||
|
||||
assertEquals(b, 1, "b != 1")
|
||||
b = 23
|
||||
assertEquals(b, 23, "b != 23")
|
||||
|
||||
assertEquals(boo(34), 34, "boo(34) != 34")
|
||||
}
|
||||
}
|
||||
foo()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
A().litlit()
|
||||
A().funfun()
|
||||
A().litfun()
|
||||
A().funlit()
|
||||
}
|
||||
catch(f: Fail) {
|
||||
if (!f.isFail) throw f
|
||||
return f.message
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
fun run<T>(f: () -> T) = f()
|
||||
|
||||
fun box(): Boolean {
|
||||
val t = run {
|
||||
object {
|
||||
fun boo(param: String): String {
|
||||
return run { param }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return t.boo("OK") == "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
fun test(): String {
|
||||
fun f(): String = "OK"
|
||||
|
||||
val funLit = { f() }
|
||||
return funLit()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return test()
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package foo
|
||||
|
||||
fun run<T>(f: () -> T) = f()
|
||||
|
||||
fun box(): String {
|
||||
fun simple(s: String? = null): String {
|
||||
if (s != null) return s
|
||||
|
||||
return run {
|
||||
simple("OK")
|
||||
}
|
||||
}
|
||||
|
||||
if (simple("OK") != "OK") return "failed on simple recursion"
|
||||
|
||||
val ok = "OK"
|
||||
fun withClosure(s: String? = null): String {
|
||||
if (s != null) return s
|
||||
|
||||
return ok + run {
|
||||
withClosure(ok)
|
||||
}
|
||||
}
|
||||
|
||||
if (withClosure() != ok + ok) return "failed when closure something"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package foo
|
||||
|
||||
fun run<T>(f: () -> T) = f()
|
||||
|
||||
class Foo {
|
||||
val OK = "OK";
|
||||
var result: String = ""
|
||||
{
|
||||
fun bar(s: String? = null) {
|
||||
if (s != null) {
|
||||
result = s
|
||||
return
|
||||
}
|
||||
|
||||
run {
|
||||
bar(OK)
|
||||
}
|
||||
}
|
||||
bar();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Foo().result
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
val k = { "K" }
|
||||
|
||||
fun test(): String {
|
||||
val o = { "O" }
|
||||
|
||||
val funLit = { o() + k() }
|
||||
return funLit()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return test()
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package foo
|
||||
|
||||
class A() {
|
||||
var i = 0
|
||||
|
||||
fun f() {
|
||||
for (j in 0..2) {
|
||||
foo {
|
||||
i += j
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(f: () -> Unit) {
|
||||
f()
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
val a = A()
|
||||
a.f()
|
||||
return a.i == 3
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// KT-2388
|
||||
package foo
|
||||
|
||||
var done = 0
|
||||
|
||||
object foo {
|
||||
var result = "FAIL"
|
||||
|
||||
val lambda = {
|
||||
result = "foo.lambda OK"
|
||||
done = 3
|
||||
}
|
||||
|
||||
val extLambda: Int.() -> Unit = {
|
||||
result = "foo.extLambda OK"
|
||||
done = this
|
||||
}
|
||||
}
|
||||
|
||||
class Foo {
|
||||
var result = "FAIL"
|
||||
|
||||
val lambda = {
|
||||
result = "Foo::lambda OK"
|
||||
done = -7
|
||||
}
|
||||
|
||||
val extLambda: Int.() -> Unit = {
|
||||
result = "Foo::extLambda OK"
|
||||
done = this
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = foo.lambda
|
||||
val b = foo.extLambda
|
||||
|
||||
val f = Foo()
|
||||
val c = f.lambda
|
||||
val d = f.extLambda
|
||||
|
||||
a()
|
||||
if (foo.result != "foo.lambda OK") return "foo.result = \"${foo.result}\", but expected \"foo.lambda OK\""
|
||||
if (done != 3) return "done = $done, but expected 3"
|
||||
|
||||
23.b()
|
||||
if (foo.result != "foo.extLambda OK") return "foo.result = \"${foo.result}\", but expected \"foo.extLambda OK\""
|
||||
if (done != 23) return "done = $done, but expected 23"
|
||||
|
||||
|
||||
c()
|
||||
if (f.result != "Foo::lambda OK") return "a.result = \"${f.result}\", but expected \"Foo::lambda OK\""
|
||||
if (done != -7) return "done = $done, but expected -7"
|
||||
|
||||
71.d()
|
||||
if (f.result != "Foo::extLambda OK") return "a.result = \"${f.result}\", but expected \"Foo::extLambda OK\""
|
||||
if (done != 71) return "done = $done, but expected 71"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package foo
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun box(): Boolean {
|
||||
val oneTwo = Array(2) {
|
||||
it + 1
|
||||
}
|
||||
val a = ArrayList<() -> Int>()
|
||||
for (i in oneTwo) {
|
||||
for (j in 1..2) {
|
||||
a.add({
|
||||
var res = 0
|
||||
for (t in 0..2) {
|
||||
res += i * j
|
||||
}
|
||||
res
|
||||
})
|
||||
}
|
||||
}
|
||||
var sum = 0
|
||||
for (f in a) {
|
||||
sum += f()
|
||||
}
|
||||
return (sum == 27)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package foo
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun box(): Boolean {
|
||||
val oneTwo = Array(2) {
|
||||
it + 1
|
||||
}
|
||||
val a = ArrayList<() -> Int>()
|
||||
for (i in oneTwo) {
|
||||
for (l in 1..2) {
|
||||
val j = l
|
||||
a.add({
|
||||
var res = 0
|
||||
for (t in 0..2) {
|
||||
res += i * j
|
||||
}
|
||||
res
|
||||
})
|
||||
}
|
||||
}
|
||||
var sum = 0
|
||||
for (f in a) {
|
||||
sum += f()
|
||||
}
|
||||
return (sum == 27)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package foo
|
||||
|
||||
fun bar(i: Int = 0): Int = if (i == 7) i else bar(i - 1)
|
||||
|
||||
fun box(): String {
|
||||
val a = bar(10)
|
||||
if (a != 7) return "bar(10) = $a, but expected 7"
|
||||
|
||||
fun boo(i: Int = 0): Int = if (i == 4) i else boo(i - 1)
|
||||
val b = boo(17)
|
||||
if (b != 4) return "boo(17) = $b, but expected 4"
|
||||
|
||||
fun f() = 1
|
||||
val v = 3
|
||||
fun baz(i: Int = 0): Int = if (i == v) f() + v else baz(i - 1)
|
||||
|
||||
val c = baz(10)
|
||||
if (c != 4) return "baz(10) = $c, but expected 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package foo
|
||||
|
||||
fun Any.foo(n: Int): () -> Boolean {
|
||||
var count = n
|
||||
return { --count >= 0 }
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
return 1.foo(3)() && !1.foo(0)()
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
if (f(0) != -3) {
|
||||
return false
|
||||
}
|
||||
if (f(102) != 201) {
|
||||
return false;
|
||||
}
|
||||
if (f(103) != 100) {
|
||||
return false
|
||||
}
|
||||
if (f(-100) != -100) {
|
||||
return false
|
||||
}
|
||||
if (f(-99) != -201) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
fun f(i: Int): Int {
|
||||
var j = i
|
||||
return --j + (if (j < -100) return -100 else --j) + (if (j > 100) return 100 else 0)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package foo
|
||||
|
||||
var i = 0
|
||||
|
||||
inline fun f() = i * 2
|
||||
|
||||
fun box(): Boolean {
|
||||
return (++i + f()) == 3
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
if (f(0) != 201) {
|
||||
return false
|
||||
}
|
||||
if (f(1) != 104) {
|
||||
return false
|
||||
}
|
||||
if (f(-2) != -100) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun f(i: Int): Int {
|
||||
var j = i
|
||||
return ++j + if (j != 1) {
|
||||
(if (j > 0) 100 else return -100) + 2
|
||||
}
|
||||
else 200
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package foo
|
||||
|
||||
var d = 0
|
||||
|
||||
fun f(): Int {
|
||||
d = if (d < 0) -100 else 100
|
||||
return d
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
d = d-- + f() + when(d) {
|
||||
-100 -> return true
|
||||
1 -> 1
|
||||
else -> return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
var i = 0
|
||||
val c = sum(++i, if (i == 0) return false else i + 2)
|
||||
if (c != 4) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
fun sum(a1: Int, a2: Int) = a1 + a2
|
||||
@@ -0,0 +1,10 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
var i = 0
|
||||
var t = ++i + if (i == 0) 0 else 2
|
||||
if (t != 3) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
var i = 0
|
||||
var t = ++i + when(i) {
|
||||
3 -> 4
|
||||
1 -> 2
|
||||
0 -> 1
|
||||
else -> 100
|
||||
}
|
||||
if (t != 3) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package foo
|
||||
|
||||
class A(val a: Int = 0)
|
||||
|
||||
class B(val a: Int = 0, val b: String = "a")
|
||||
|
||||
fun box(): String {
|
||||
val a0 = A()
|
||||
val a1 = A(1)
|
||||
if (a0.a != 0) return "a0.a != 0, it: ${a0.a}"
|
||||
if (a1.a != 1) return "a1.a != 1, it: ${a1.a}"
|
||||
|
||||
val b1 = B()
|
||||
if (b1.a != 0) return "b1.a != 0, it: ${b1.a}"
|
||||
if (b1.b != "a") return "b1.b != 'a', it: ${b1.b}"
|
||||
|
||||
val b2 = B(1)
|
||||
if (b2.a != 1) return "b2.a != 1, it: ${b2.a}"
|
||||
if (b2.b != "a") return "b2.b != 'a', it: ${b2.b}"
|
||||
|
||||
val b3 = B(b = "b")
|
||||
if (b3.a != 0) return "b3.a != 0, it: ${b3.a}"
|
||||
if (b3.b != "b") return "b3.b != 'b', it: ${b3.b}"
|
||||
|
||||
val b4 = B(2, "c")
|
||||
if (b4.a != 2) return "b4.a != 2, it: ${b4.a}"
|
||||
if (b4.b != "c") return "b4.b != 'c', it: ${b4.b}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package foo
|
||||
|
||||
class T4(
|
||||
val c1: Boolean,
|
||||
val c2: Boolean,
|
||||
val c3: Boolean,
|
||||
val c4: String
|
||||
) {
|
||||
override fun equals(o: Any?): Boolean {
|
||||
if (o !is T4) return false;
|
||||
return c1 == o.c1 &&
|
||||
c2 == o.c2 &&
|
||||
c3 == o.c3 &&
|
||||
c4 == o.c4
|
||||
}
|
||||
}
|
||||
|
||||
fun reformat(
|
||||
str: String,
|
||||
normalizeCase: Boolean = true,
|
||||
uppercaseFirstLetter: Boolean = true,
|
||||
divideByCamelHumps: Boolean = true,
|
||||
wordSeparator: String = " "
|
||||
) =
|
||||
T4(normalizeCase, uppercaseFirstLetter, divideByCamelHumps, wordSeparator)
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val expected = T4(true, true, true, " ")
|
||||
if (reformat("", true, true, true, " ") != expected) return "fail1"
|
||||
if (reformat("", true, true, true) != expected) return "fail2"
|
||||
if (reformat("", true, true) != expected) return "fail3"
|
||||
if (reformat("", true) != expected) return "fail4"
|
||||
if (reformat("") != expected) return "fail5"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
open class A(val a: Int = 1, val b: Int = 2)
|
||||
|
||||
class B : A(b = 3)
|
||||
|
||||
fun box(): String {
|
||||
val b = B()
|
||||
if (b.a != 1) return "b.a != 1, it: ${b.a}"
|
||||
if (b.b != 3) return "b.a != 3, it: ${b.b}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
enum class A(val a: Int = 1) {
|
||||
FIRST: A()
|
||||
SECOND: A(2)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (A.FIRST.a == 1 && A.SECOND.a == 2) {
|
||||
return "OK"
|
||||
}
|
||||
return "fail"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
enum class Foo(val a: Int = 1, val b: String) {
|
||||
B: Foo(2, "b")
|
||||
C: Foo(b = "b")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (Foo.B.a != 2 || Foo.B.b != "b") return "fail1"
|
||||
if (Foo.C.a != 1 || Foo.C.b != "b") return "fail2"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package foo
|
||||
|
||||
enum class Foo(val a: Int = 1, val b: String = "a") {
|
||||
A: Foo()
|
||||
B: Foo(2, "b")
|
||||
C: Foo(b = "b")
|
||||
D: Foo(a = 2)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (Foo.A.a != 1 || Foo.A.b != "a") return "fail1"
|
||||
if (Foo.B.a != 2 || Foo.B.b != "b") return "fail2"
|
||||
if (Foo.C.a != 1 || Foo.C.b != "b") return "fail3"
|
||||
if (Foo.D.a != 2 || Foo.D.b != "a") return "fail4"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
fun <T> T.toPrefixedString(prefix: String = "", suffix: String = "") = prefix + toString() + suffix
|
||||
|
||||
fun box(): String {
|
||||
if ("mama".toPrefixedString(suffix = "321", prefix = "papa") != "papamama321") return "fail1"
|
||||
if ("mama".toPrefixedString(prefix = "papa") != "papamama") return "fail2"
|
||||
if ("mama".toPrefixedString("papa", "239") != "papamama239") return "fail3"
|
||||
if ("mama".toPrefixedString("papa") != "papamama") return "fail4"
|
||||
if ("mama".toPrefixedString() != "mama") return "fail5"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
open abstract class B() {
|
||||
fun foo(arg: Int = 239 + 1): Int = arg
|
||||
}
|
||||
|
||||
class C() : B() {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (C().foo(10) != 10) return "fail1"
|
||||
if (C().foo() != 240) return "fail2"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
open abstract class B() {
|
||||
abstract fun foo2(arg: Int = 239): Int
|
||||
}
|
||||
|
||||
class C() : B() {
|
||||
override fun foo2(arg: Int): Int = arg
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (C().foo2() != 239) return "fail1"
|
||||
if (C().foo2(10) != 10) return "fail2"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
open class A(open val bar: Int = 2) {
|
||||
val barA = $bar
|
||||
}
|
||||
|
||||
class B(override val bar: Int = 3) : A()
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val b = B()
|
||||
if (b.bar != 3) return "b.bar != 3, it: " + b.bar
|
||||
if (b.barA != 2) return "b.barA != 2, it: " + b.barA
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
trait A {
|
||||
fun bar2(arg: Int = 239): Int
|
||||
|
||||
fun bar(arg: Int = 240): Int = bar2(arg / 2)
|
||||
}
|
||||
|
||||
open abstract class B() : A {
|
||||
override fun bar2(arg: Int): Int = arg
|
||||
}
|
||||
|
||||
class C() : B() {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (C().bar(10) != 5) return "fail1: ${C().bar(10)}"
|
||||
if (C().bar() != 120) return "fail2: ${C().bar()}"
|
||||
if (C().bar2() != 239) return "fail3: ${C().bar2()}"
|
||||
if (C().bar2(10) != 10) return "fail4: ${C().bar2(10)}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package foo
|
||||
|
||||
class Delegate {
|
||||
var inner = 1
|
||||
fun get(t: Any?, p: PropertyMetadata): Int = inner
|
||||
fun set(t: Any?, p: PropertyMetadata, i: Int) {
|
||||
inner = i
|
||||
}
|
||||
}
|
||||
|
||||
fun foo() = Delegate()
|
||||
|
||||
class A {
|
||||
var prop: Int by foo()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = A()
|
||||
if (c.prop != 1) return "fail get"
|
||||
c.prop = 2
|
||||
if (c.prop != 2) return "fail set"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package foo
|
||||
|
||||
class Delegate {
|
||||
var inner = 1
|
||||
fun get(t: Any?, p: PropertyMetadata): Int = inner
|
||||
fun set(t: Any?, p: PropertyMetadata, i: Int) {
|
||||
inner = i
|
||||
}
|
||||
}
|
||||
|
||||
val p = Delegate()
|
||||
|
||||
class A {
|
||||
var prop: Int by p
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = A()
|
||||
if (c.prop != 1) return "fail get"
|
||||
c.prop = 2
|
||||
if (c.prop != 2) return "fail set"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
class Delegate {
|
||||
fun get(t: A, p: PropertyMetadata): Int = 1
|
||||
}
|
||||
|
||||
val A.prop: Int by Delegate()
|
||||
|
||||
class A {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (A().prop == 1) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package foo
|
||||
|
||||
class Delegate {
|
||||
var inner = 1
|
||||
fun get(t: Any?, p: PropertyMetadata): Int = inner
|
||||
fun set(t: Any?, p: PropertyMetadata, i: Int) {
|
||||
inner = i
|
||||
}
|
||||
}
|
||||
|
||||
val p = Delegate()
|
||||
|
||||
class A {
|
||||
var prop: Int by p
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = A()
|
||||
if (c.prop != 1) return "fail get"
|
||||
c.prop = 2
|
||||
if (c.prop != 2) return "fail set"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
class Delegate {
|
||||
}
|
||||
|
||||
fun Delegate.get(t: Any?, p: PropertyMetadata): Int = 1
|
||||
|
||||
class A {
|
||||
val prop: Int by Delegate()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (A().prop == 1) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package foo
|
||||
|
||||
trait WithName {
|
||||
var name: String
|
||||
}
|
||||
|
||||
class GetPropertyName() {
|
||||
fun get(withName: WithName, property: PropertyMetadata): String {
|
||||
return withName.name + ":" + property.name;
|
||||
}
|
||||
fun set(withName: WithName, property: PropertyMetadata, value: String) {
|
||||
withName.name = value + ":" + property.name
|
||||
}
|
||||
}
|
||||
|
||||
class A : WithName {
|
||||
override var name = "propertyName"
|
||||
val d = GetPropertyName()
|
||||
|
||||
val a by d
|
||||
var OK by d
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
if (a.a != "propertyName:a") return "a.a != 'propertyName:a', it: " + a.a
|
||||
if (a.OK != "propertyName:OK") return "a.OK != 'propertyName:aOK', it: " + a.OK
|
||||
a.OK = "property"
|
||||
|
||||
if (a.a != "property:OK:a") return "a.a != 'property:OK:a', it: " + a.a
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
class Delegate {
|
||||
var inner = 1
|
||||
fun get(t: Any?, p: PropertyMetadata): Int = inner
|
||||
}
|
||||
|
||||
fun Delegate.set(t: Any?, p: PropertyMetadata, i: Int) {
|
||||
inner = i
|
||||
}
|
||||
|
||||
class A {
|
||||
var prop: Int by Delegate()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = A()
|
||||
if (c.prop != 1) return "fail get"
|
||||
c.prop = 2
|
||||
if (c.prop != 2) return "fail set"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package foo
|
||||
|
||||
trait WithNumber {
|
||||
var number: Int
|
||||
}
|
||||
|
||||
class IncNumber(val inc: Int) {
|
||||
fun get(withNumber: WithNumber, property: PropertyMetadata): Int {
|
||||
return withNumber.number + inc;
|
||||
}
|
||||
fun set(withNumber: WithNumber, property: PropertyMetadata, value: Int) {
|
||||
withNumber.number = value;
|
||||
}
|
||||
}
|
||||
|
||||
class A : WithNumber {
|
||||
override var number: Int = 5
|
||||
var nextNumber by IncNumber(3)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (A().nextNumber != 8) return "A().nextNumber != 8, it: ${A().nextNumber}"
|
||||
|
||||
val a = A()
|
||||
a.nextNumber = 10;
|
||||
if (a.number != 10) return "a.number != 10, it: " + a.number
|
||||
if (a.nextNumber != 13) return "a.nextNumber != 13, it: " + a.nextNumber
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package foo
|
||||
|
||||
class Delegate {
|
||||
fun get(t: Any?, p: PropertyMetadata): Int = 1
|
||||
}
|
||||
|
||||
val prop: Int by Delegate()
|
||||
|
||||
fun box(): String {
|
||||
return if (prop == 1) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package foo
|
||||
|
||||
class Delegate {
|
||||
var inner = 1
|
||||
fun get(t: Any?, p: PropertyMetadata): Int = inner
|
||||
fun set(t: Any?, p: PropertyMetadata, i: Int) {
|
||||
inner = i
|
||||
}
|
||||
}
|
||||
|
||||
var prop: Int by Delegate()
|
||||
|
||||
fun box(): String {
|
||||
if (prop != 1) return "fail get"
|
||||
prop = 2
|
||||
if (prop != 2) return "fail set"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package foo
|
||||
|
||||
trait Getter<T> {
|
||||
fun get(): T
|
||||
}
|
||||
|
||||
class Delegate<T>(val getter: Getter<T>) {
|
||||
var t: T? = null
|
||||
fun get(obj: Any, property: PropertyMetadata): T {
|
||||
if (t != null) {
|
||||
return t!!
|
||||
}
|
||||
return getter.get()
|
||||
}
|
||||
fun set(obj: Any, property: PropertyMetadata, value: T) {
|
||||
t = value
|
||||
}
|
||||
}
|
||||
|
||||
class A : Getter<Int> {
|
||||
var value = 0
|
||||
override fun get(): Int {
|
||||
return value
|
||||
}
|
||||
val delegate = Delegate(this)
|
||||
|
||||
val a by delegate
|
||||
var b by delegate
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
if (a.a != 0) return "a.a != 0"
|
||||
if (a.b != 0) return "a.b != 0"
|
||||
|
||||
a.b = 4
|
||||
if (a.a != 4) return "a.a != 4"
|
||||
if (a.b != 4) return "a.b != 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package foo
|
||||
|
||||
enum class B(open val bar: Int) {
|
||||
val x = 1
|
||||
var y = 12;
|
||||
a : B(0) {
|
||||
override val bar = 3
|
||||
{
|
||||
y = 0
|
||||
}
|
||||
}
|
||||
b : B(4) {
|
||||
}
|
||||
c : B(5)
|
||||
}
|
||||
|
||||
trait X {
|
||||
val foo: Int
|
||||
fun bar(): Int {
|
||||
return foo;
|
||||
}
|
||||
}
|
||||
|
||||
enum class Y(override val foo: Int) : X {
|
||||
m:Y(3)
|
||||
n:Y(6)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (B.a.x != 1) return "B.a.x != 1, it: ${B.a.x}"
|
||||
if (B.a.y != 0) return "B.a.y != 0, it: ${B.a.y}"
|
||||
if (B.a.bar != 3) return "B.a.bar != 3, it: ${B.a.bar}"
|
||||
|
||||
if (B.b.y != 12) return "B.b.y != 12, it: ${B.b.y}"
|
||||
if (B.b.bar != 4) return "B.b.bar != 4, it: ${B.b.bar}"
|
||||
|
||||
if (B.c.bar != 5) return "B.c.bar != 5, it: ${B.c.bar}"
|
||||
if (B.c.y != 12) return "B.c.y != 12, it: ${B.c.y}"
|
||||
|
||||
if (Y.m.bar() != 3) return "Y.m.bar() != 3, it: ${Y.m.bar()}"
|
||||
if (Y.n.bar() != 6) return "Y.n.bar() != 6, it: ${Y.m.bar()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package foo
|
||||
|
||||
enum class E {
|
||||
OK
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return E.OK.name()
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package foo
|
||||
|
||||
enum class EmptyEnum
|
||||
|
||||
enum class Simple {
|
||||
OK
|
||||
}
|
||||
|
||||
enum class A {
|
||||
a : A() {
|
||||
}
|
||||
b : A()
|
||||
c
|
||||
}
|
||||
|
||||
enum class B {
|
||||
c
|
||||
}
|
||||
fun box(): String {
|
||||
if (Simple.OK.name() != "OK") return "Simple.OK.name() != OK, it: ${Simple.OK.name()}"
|
||||
val ok = Simple.OK
|
||||
if (ok.ordinal() != 0) return "ok = Simple.Ok; ok.ordinal() != 0, it: ${ok.ordinal()}"
|
||||
|
||||
val ok2 = Simple.valueOf("OK")
|
||||
if (!ok2.equals(ok)) return "ok2 not equal ok"
|
||||
if (!ok2.identityEquals(ok)) return "ok2 not identity equal ok"
|
||||
|
||||
|
||||
if (EmptyEnum.values().size != 0) return "EmptyEnum.values().size != 0"
|
||||
|
||||
if (A.values() != array(A.a, A.b, A.c)) return "Wrong A.values(): " + A.values().toString()
|
||||
|
||||
if (A.c.toString() != "c") return "A.c.toString() != c, it: ${A.c.toString()}"
|
||||
if (A.valueOf("b") != A.b) return "A.valueOf('b') != A.b"
|
||||
if (A.a == A.b) return "A.a == A.b"
|
||||
|
||||
if (A.a.name() != "a") return "A.a.name() != a, it: ${A.a.name()}"
|
||||
if (A.b.name() != "b") return "A.b.name() != b, it: ${A.b.name()}"
|
||||
if (A.c.name() != "c") return "A.c.name() != c, it: ${A.c.name()}"
|
||||
|
||||
if (A.a.ordinal() != 0) return "A.a.ordinal() != 0, it: ${A.a.ordinal()}"
|
||||
if (A.b.ordinal() != 1) return "A.b.ordinal() != 1, it: ${A.b.ordinal()}"
|
||||
if (A.c.ordinal() != 2) return "A.c.ordinal() != 2, it: ${A.c.ordinal()}"
|
||||
|
||||
if (A.c.equals(B.c)) return "A.c.equals(B.c)"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun box(): String {
|
||||
return apply("OK", {(arg: String) -> arg })
|
||||
}
|
||||
|
||||
fun apply(arg: String, f: (p: String) -> String): String {
|
||||
return f(arg)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
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,26 @@
|
||||
// Changed when traits were introduced. May not make sense any more
|
||||
|
||||
open class Base() {
|
||||
public var v: Int = 0
|
||||
}
|
||||
|
||||
open class Left() : Base() {
|
||||
}
|
||||
trait Right : Base {
|
||||
}
|
||||
|
||||
class D() : Left(), Right
|
||||
|
||||
fun vl(l: Left): Int = l.v
|
||||
fun vr(r: Right): Int = r.v
|
||||
|
||||
fun box(): String {
|
||||
val d = D()
|
||||
d.v = 42
|
||||
|
||||
if (d.v != 42) return "Fail #1"
|
||||
if (vl(d) != 42) return "Fail #2"
|
||||
if (vr(d) != 42) return "Fail #3"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun box(): String {
|
||||
val cl = 39
|
||||
return if (sum(200, { val ff = { cl }; ff() }) == 239) "OK" else "FAIL"
|
||||
}
|
||||
|
||||
fun sum(arg: Int, f: () -> Int): Int {
|
||||
return arg + f()
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun box(): String {
|
||||
val cl = 39
|
||||
return if (sum(200, { val m = { val r = { cl }; r() }; m() }) == 239) "OK" else "FAIL"
|
||||
}
|
||||
|
||||
fun sum(arg: Int, f: () -> Int): Int {
|
||||
return arg + f()
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
class Point(val x: Int, val y: Int)
|
||||
|
||||
fun box(): String {
|
||||
val answer = apply(Point(3, 5), { Point.(scalar: Int): Point ->
|
||||
Point(x * scalar, y * scalar)
|
||||
})
|
||||
|
||||
return if (answer.x == 6 && answer.y == 10) "OK" else "FAIL"
|
||||
}
|
||||
|
||||
fun apply(arg: Point, f: Point.(scalar: Int) -> Point): Point {
|
||||
return arg.f(2)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
open class Base() {
|
||||
fun n(n: Int): Int = n + 1
|
||||
}
|
||||
|
||||
trait Abstract {
|
||||
}
|
||||
|
||||
class Derived1() : Base(), Abstract {
|
||||
}
|
||||
class Derived2() : Abstract, Base() {
|
||||
}
|
||||
|
||||
fun test(s: Base): Boolean = s.n(238) == 239
|
||||
|
||||
fun box(): String {
|
||||
if (!test(Base())) return "Fail #1"
|
||||
if (!test(Derived1())) return "Fail #2"
|
||||
if (!test(Derived2())) return "Fail #3"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class Slot() {
|
||||
var vitality: Int = 10000
|
||||
|
||||
fun increaseVitality(delta: Int) {
|
||||
vitality = vitality + delta
|
||||
if (vitality > 65535) vitality = 65535;
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val s = Slot()
|
||||
s.increaseVitality(1000)
|
||||
if (s.vitality == 11000) return "OK" else return "fail"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
open class Foo() {
|
||||
fun xyzzy(): String = "xyzzy"
|
||||
}
|
||||
|
||||
class Bar() : Foo() {
|
||||
fun test(): String = xyzzy()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val bar = Bar()
|
||||
val f = bar.test()
|
||||
return if (f == "xyzzy") "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
class C() {
|
||||
public var f: Int
|
||||
|
||||
{
|
||||
$f = 610
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
if (c.f != 610) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
fun box(): String {
|
||||
val i: Int? = 7
|
||||
val j: Int? = null
|
||||
val k = 7
|
||||
|
||||
//verify errors
|
||||
if (i == 7) {
|
||||
}
|
||||
if (7 == i) {
|
||||
}
|
||||
|
||||
if (j == 7) {
|
||||
}
|
||||
if (7 == j) {
|
||||
}
|
||||
|
||||
if (i == k) {
|
||||
}
|
||||
if (k == i) {
|
||||
}
|
||||
|
||||
if (j == k) {
|
||||
}
|
||||
if (k == j) {
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class SimpleClass() {
|
||||
fun foo() = 610
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = SimpleClass()
|
||||
if (c.foo() == 610) {
|
||||
return "OK"
|
||||
}
|
||||
return "FAIL"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import java.util.*
|
||||
|
||||
class ArrayWrapper<T>() {
|
||||
val contents = ArrayList<T>()
|
||||
|
||||
fun add(item: T) {
|
||||
contents.add(item)
|
||||
}
|
||||
|
||||
fun plus(b: ArrayWrapper<T>): ArrayWrapper<T> {
|
||||
val result = ArrayWrapper<T>()
|
||||
result.contents.addAll(contents)
|
||||
result.contents.addAll(b.contents)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val v1 = ArrayWrapper<String>()
|
||||
val v2 = ArrayWrapper<String>()
|
||||
v1.add("foo")
|
||||
v2.add("bar")
|
||||
val v3 = v1 + v2
|
||||
return if (v3.contents.size() == 2) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import java.util.*
|
||||
|
||||
class ArrayWrapper<T>() {
|
||||
val contents = ArrayList<T>()
|
||||
|
||||
fun add(item: T) {
|
||||
contents.add(item)
|
||||
}
|
||||
|
||||
fun plusAssign(rhs: ArrayWrapper<T>) {
|
||||
contents.addAll(rhs.contents)
|
||||
}
|
||||
|
||||
fun get(index: Int): T {
|
||||
return contents.get(index)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var v1 = ArrayWrapper<String>()
|
||||
val v2 = ArrayWrapper<String>()
|
||||
v1.add("foo")
|
||||
val v3 = v1
|
||||
v2.add("bar")
|
||||
v1 += v2
|
||||
return if (v1.contents.size() == 2 && v3.contents.size() == 2) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import java.util.*
|
||||
|
||||
class ArrayWrapper<T>() {
|
||||
val contents = ArrayList<T>()
|
||||
|
||||
fun add(item: T) {
|
||||
contents.add(item)
|
||||
}
|
||||
|
||||
fun plus(rhs: ArrayWrapper<T>): ArrayWrapper<T> {
|
||||
val result = ArrayWrapper<T>()
|
||||
result.contents.addAll(contents)
|
||||
result.contents.addAll(rhs.contents)
|
||||
return result
|
||||
}
|
||||
|
||||
fun get(index: Int): T {
|
||||
return contents.get(index)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var v1 = ArrayWrapper<String>()
|
||||
val v2 = ArrayWrapper<String>()
|
||||
v1.add("foo")
|
||||
val v3 = v1
|
||||
v2.add("bar")
|
||||
v1 += v2
|
||||
return if (v1.contents.size() == 2 && v3.contents.size() == 1) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import java.util.*
|
||||
|
||||
class ArrayWrapper<T>() {
|
||||
val contents = ArrayList<T>()
|
||||
|
||||
fun add(item: T) {
|
||||
contents.add(item)
|
||||
}
|
||||
|
||||
fun minus(): ArrayWrapper<T> {
|
||||
val result = ArrayWrapper<T>()
|
||||
result.contents.addAll(contents)
|
||||
var i = contents.size();
|
||||
for (a in contents) {
|
||||
result.contents[--i] = a;
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun get(index: Int): T {
|
||||
return contents.get(index)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val v1 = ArrayWrapper<String>()
|
||||
v1.add("foo")
|
||||
v1.add("bar")
|
||||
val v2 = -v1
|
||||
return if (v2[0] == "bar" && v2[1] == "foo") "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
open class Base() {
|
||||
val plain = 239
|
||||
public val read: Int
|
||||
get() = 239
|
||||
|
||||
public var readwrite: Int = 0
|
||||
get() = $readwrite + 1
|
||||
set(n: Int) {
|
||||
$readwrite = n
|
||||
}
|
||||
}
|
||||
|
||||
trait Abstract {
|
||||
}
|
||||
|
||||
class Derived1() : Base(), Abstract {
|
||||
}
|
||||
class Derived2() : Abstract, Base() {
|
||||
}
|
||||
|
||||
fun code(s: Base): Int {
|
||||
if (s.plain != 239) return 1
|
||||
if (s.read != 239) return 2
|
||||
s.readwrite = 238
|
||||
if (s.readwrite != 239) return 3
|
||||
return 0
|
||||
}
|
||||
|
||||
fun test(s: Base): Boolean = code(s) == 0
|
||||
|
||||
fun box(): String {
|
||||
if (!test(Base())) return "Fail #1"
|
||||
if (!test(Derived1())) return "Fail #2"
|
||||
if (!test(Derived2())) return "Fail #3"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// Changed when traits were introduced. May not make sense any more
|
||||
|
||||
trait Left {
|
||||
}
|
||||
open class Right() {
|
||||
open fun f() = 42
|
||||
}
|
||||
|
||||
class D() : Left, Right() {
|
||||
override fun f() = 239
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val r: Right = Right()
|
||||
val d: D = D()
|
||||
|
||||
if (r.f() != 42) return "Fail #1"
|
||||
if (d.f() != 239) return "Fail #2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun box(): String {
|
||||
return invoker({ "OK" })
|
||||
}
|
||||
|
||||
fun invoker(gen: () -> String): String {
|
||||
return gen()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun box(): String {
|
||||
return if (int_invoker({ 7 }) == 7) "OK" else "fail"
|
||||
}
|
||||
|
||||
fun int_invoker(gen: () -> Int): Int {
|
||||
return gen()
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import java.util.ArrayList
|
||||
|
||||
trait Tr {
|
||||
fun extra(): String = "_"
|
||||
}
|
||||
|
||||
class N() : ArrayList<Any>(), Tr {
|
||||
override fun add(el: Any): Boolean {
|
||||
super<ArrayList>.add(el)
|
||||
return super<ArrayList>.add(el.toString() + super<Tr>.extra() + el + extra())
|
||||
}
|
||||
|
||||
override fun extra(): String = super<Tr>.extra() + super<Tr>.extra()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val n = N()
|
||||
n.add("239")
|
||||
if (n.get(0) == "239" && n.get(1) == "239_239__") return "OK";
|
||||
return "fail";
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
open class M() {
|
||||
open var b: Int = 0
|
||||
}
|
||||
|
||||
class N() : M() {
|
||||
val a: Int
|
||||
get() {
|
||||
super.b = super.b + 1
|
||||
return super.b + 1
|
||||
}
|
||||
override var b: Int = a + 1
|
||||
|
||||
val superb: Int
|
||||
get() = super.b
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val n = N()
|
||||
println("a: " + n.a + " b: " + n.b + " superb: " + n.superb)
|
||||
if (n.b == 3 && n.a == 4 && n.superb == 3) return "OK";
|
||||
return "fail";
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class C() {
|
||||
class object {
|
||||
fun create() = C()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = C.create()
|
||||
return if (c is C) "OK" else "fail"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class C() {
|
||||
fun getInstance(): Runnable = C
|
||||
|
||||
class object: Runnable {
|
||||
override fun run(): Unit {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun foo() = C().getInstance()
|
||||
@@ -0,0 +1,13 @@
|
||||
abstract open class Default {
|
||||
abstract fun defaultValue(): Int
|
||||
}
|
||||
|
||||
class MyInt() {
|
||||
class object : Default {
|
||||
override fun defaultValue(): Int = 610
|
||||
}
|
||||
}
|
||||
|
||||
fun toDefault<T : Any>(t: T) where class object T : Default = T.defaultValue()
|
||||
|
||||
fun box(): String = if (toDefault<MyInt>(MyInt()) == 610) "OK" else "fail"
|
||||
@@ -0,0 +1,42 @@
|
||||
trait BK {
|
||||
fun x(): Int = 50
|
||||
}
|
||||
|
||||
trait K : BK {
|
||||
override fun x(): Int = super.x() * 2
|
||||
}
|
||||
|
||||
open class M() {
|
||||
open fun x(): Int = 10
|
||||
|
||||
open var y = 500
|
||||
}
|
||||
|
||||
open class N() : M(), K {
|
||||
|
||||
override fun x(): Int = 20
|
||||
|
||||
override var y = 200
|
||||
|
||||
open class C() : K {
|
||||
fun test1() = x()
|
||||
fun test2() = super<M>@N.x()
|
||||
fun test3() = super<K>@N.x()
|
||||
fun test4() = super<K>.x()
|
||||
fun test5() = y
|
||||
fun test6(): Int {
|
||||
super<M>@N.y += 200
|
||||
return super<M>@N.y
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (N().C().test1() != 100) return "test1 fail";
|
||||
if (N().C().test2() != 10) return "test2 fail";
|
||||
if (N().C().test3() != 100) return "test3 fail";
|
||||
if (N().C().test4() != 100) return "test4 fail";
|
||||
if (N().C().test5() != 200) return "test5 fail";
|
||||
if (N().C().test6() != 700) return "test6 fail";
|
||||
return "OK";
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class Foo() {
|
||||
}
|
||||
class Bar() {
|
||||
}
|
||||
|
||||
fun isInstance<T>(obj: Any?) = obj is T
|
||||
|
||||
fun isInstance2<T>(obj: Any?) = isInstance<T>(obj)
|
||||
|
||||
fun box(): String {
|
||||
if (!isInstance2<Foo>(Foo())) return "fail 1"
|
||||
if (isInstance2<Bar>(Foo())) return "fail 2"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Changed when traits were introduced. May not make sense any more
|
||||
|
||||
open class X(val x: Int) {
|
||||
}
|
||||
trait Y {
|
||||
abstract val y: Int
|
||||
}
|
||||
|
||||
class YImpl(override val y: Int) : Y {
|
||||
}
|
||||
|
||||
class Point(x: Int, yy: Int) : X(x), Y {
|
||||
override val y: Int = yy
|
||||
}
|
||||
|
||||
trait Abstract {
|
||||
}
|
||||
|
||||
class P1(x: Int, yy: Y) : Abstract, X(x), Y by yy {
|
||||
}
|
||||
class P2(x: Int, yy: Y) : X(x), Abstract, Y by yy {
|
||||
}
|
||||
class P3(x: Int, yy: Y) : X(x), Y by yy, Abstract {
|
||||
}
|
||||
class P4(x: Int, yy: Y) : Y by yy, Abstract, X(x) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (X(239).x != 239) return "FAIL #1"
|
||||
if (YImpl(239).y != 239) return "FAIL #2"
|
||||
|
||||
val p = Point(240, -1)
|
||||
if (p.x + p.y != 239) return "FAIL #3"
|
||||
|
||||
val y = YImpl(-1)
|
||||
val p1 = P1(240, y)
|
||||
if (p1.x + p1.y != 239) return "FAIL #4"
|
||||
val p2 = P2(240, y)
|
||||
if (p2.x + p2.y != 239) return "FAIL #5"
|
||||
|
||||
val p3 = P3(240, y)
|
||||
if (p3.x + p3.y != 239) return "FAIL #6"
|
||||
|
||||
val p4 = P4(240, y)
|
||||
if (p4.x + p4.y != 239) return "FAIL #7"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class Outer() {
|
||||
open class InnerBase() {
|
||||
}
|
||||
|
||||
class InnerDerived() : InnerBase() {
|
||||
}
|
||||
|
||||
public val foo: InnerBase? = InnerDerived()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val o = Outer()
|
||||
return if (o.foo === null) "fail" else "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import java.util.*
|
||||
import java.io.*
|
||||
|
||||
class World() {
|
||||
public val items: ArrayList<Item> = ArrayList<Item>
|
||||
|
||||
class Item() {
|
||||
{
|
||||
items.add(this)
|
||||
}
|
||||
}
|
||||
|
||||
val foo = Item()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val w = World()
|
||||
if (w.items.size() != 1) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
class Outer(val foo: StringBuilder) {
|
||||
class Inner() {
|
||||
fun len(): Int {
|
||||
return foo.length()
|
||||
}
|
||||
}
|
||||
|
||||
fun test(): Inner {
|
||||
return Inner()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val sb = StringBuilder("xyzzy")
|
||||
val o = Outer(sb)
|
||||
val i = o.test()
|
||||
val l = i.len()
|
||||
return if (l != 5) "fail" else "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
class Outer() {
|
||||
val s = "xyzzy"
|
||||
|
||||
open class InnerBase(public val name: String) {
|
||||
}
|
||||
|
||||
class InnerDerived() : InnerBase(s) {
|
||||
}
|
||||
|
||||
val x = InnerDerived()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val o = Outer()
|
||||
return if (o.x.name != "xyzzy") "fail" else "OK"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
trait M {
|
||||
var backingB: Int
|
||||
var b: Int
|
||||
get() = backingB
|
||||
set(value: Int) {
|
||||
backingB = value
|
||||
}
|
||||
}
|
||||
|
||||
class N() : M {
|
||||
override var backingB: Int = 0
|
||||
|
||||
val a: Int
|
||||
get() {
|
||||
super.b = super.b + 1
|
||||
return super.b + 1
|
||||
}
|
||||
override var b: Int = a + 1
|
||||
|
||||
val superb: Int
|
||||
get() = super.b
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val n = N()
|
||||
println("a: " + n.a + " b: " + n.b + " superb: " + n.superb)
|
||||
if (n.b == 3 && n.a == 4 && n.superb == 3) return "OK";
|
||||
return "fail";
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class GameError(msg: String) : Exception(msg) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val e = GameError("foo")
|
||||
return if (e.getMessage() == "foo") "OK" else "fail"
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user