JS backend: testFiles -> testData
This commit is contained in:
@@ -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)()
|
||||
}
|
||||
Reference in New Issue
Block a user