JS backend: testFiles -> testData
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package foo
|
||||
|
||||
open class A() {
|
||||
open fun c() = 2
|
||||
}
|
||||
|
||||
class B() : A() {
|
||||
override fun c() = 3
|
||||
}
|
||||
|
||||
fun B.t() = d() + 1
|
||||
|
||||
fun A.d() = c() + 3
|
||||
|
||||
fun box(): Boolean {
|
||||
return A().d() == 5 && B().d() == 6 && B().t() == 7
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
class A() {
|
||||
|
||||
}
|
||||
|
||||
fun A.one() = 1
|
||||
fun A.two() = one() + one()
|
||||
|
||||
fun box(): Boolean {
|
||||
return (A().two() == 2)
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package foo
|
||||
|
||||
class SimpleEnumerator {
|
||||
private var counter = 0
|
||||
|
||||
fun getNext(): String {
|
||||
counter++;
|
||||
return counter.toString()
|
||||
}
|
||||
|
||||
fun hasMoreElements(): Boolean = counter < 1
|
||||
}
|
||||
|
||||
class SimpleEnumeratorWrapper(private val enumerator: SimpleEnumerator) {
|
||||
fun hasNext(): Boolean = enumerator.hasMoreElements()
|
||||
|
||||
fun next() = enumerator.getNext()
|
||||
}
|
||||
|
||||
fun SimpleEnumerator.iterator(): SimpleEnumeratorWrapper {
|
||||
return SimpleEnumeratorWrapper(this)
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
var o = ""
|
||||
val enumerator = SimpleEnumerator()
|
||||
for (s in enumerator) {
|
||||
o += s;
|
||||
}
|
||||
|
||||
return o == "1"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
fun Int.same(): Int {
|
||||
return this
|
||||
}
|
||||
|
||||
fun Int.quadruple(): Int {
|
||||
return same() * 4;
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
return ((3 + 4).quadruple() == 28)
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
class M() {
|
||||
var m = 0
|
||||
|
||||
fun eval() {
|
||||
var d = {
|
||||
var c = { Int.() -> this + 3 }
|
||||
m += 3.c()
|
||||
}
|
||||
d();
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
var a = M()
|
||||
if (a.m != 0) return false;
|
||||
a.eval()
|
||||
if (a.m != 6) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package foo
|
||||
|
||||
fun apply(i: Int, f: Int.(Int) -> Int) = i.f(1);
|
||||
|
||||
fun box(): Boolean {
|
||||
return apply(1, { i -> i + this }) == 2
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
public class Foo {
|
||||
|
||||
public fun blah(): Int {
|
||||
return 5
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public inline fun Foo.fooImp(): String {
|
||||
return "impl" + blah()
|
||||
}
|
||||
|
||||
public inline fun Foo.fooExp(): String {
|
||||
return "expl" + this.blah()
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
var a = Foo()
|
||||
if (a.fooImp() != "impl5") return false
|
||||
if (a.fooExp() != "expl5") return false
|
||||
return true;
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
class Foo {
|
||||
fun blah(value: Int): Int {
|
||||
return value + 1
|
||||
}
|
||||
}
|
||||
|
||||
val Foo.fooImp: Int
|
||||
get() {
|
||||
return blah(5)
|
||||
}
|
||||
|
||||
val Foo.fooExp: Int
|
||||
get() {
|
||||
return this.blah(10)
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
var a = Foo()
|
||||
if (a.fooImp != 6) return false
|
||||
if (a.fooExp != 11) return false
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
class A(var a: Int) {
|
||||
fun eval() = f();
|
||||
}
|
||||
|
||||
fun A.f(): Int {
|
||||
a = 3
|
||||
return 10
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
val a = A(4)
|
||||
return (a.eval() == 10) && (a.a == 3)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
fun Int.same(): Int {
|
||||
return this
|
||||
}
|
||||
|
||||
fun Int.quadruple(): Int {
|
||||
return same() * 4;
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
return (3.quadruple() == 12)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun <T> ArrayList<T>.findAll(predicate: (T) -> Boolean): ArrayList<T> {
|
||||
val result = ArrayList<T>()
|
||||
for (t in this) {
|
||||
if (predicate(t)) result.add(t)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val list: ArrayList<Int> = ArrayList<Int>()
|
||||
|
||||
list.add(2)
|
||||
list.add(3)
|
||||
list.add(5)
|
||||
|
||||
|
||||
val m: ArrayList<Int> = list.findAll<Int>({(name: Int) -> name < 4 })
|
||||
return if (m.size() == 2) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package foo
|
||||
|
||||
fun <T> T.toPrefixedString(prefix: String = "", suffix: String = "") = prefix + toString() + suffix
|
||||
|
||||
fun box(): Boolean {
|
||||
return ("mama".toPrefixedString(suffix = "321", prefix = "papa") == "papamama321")
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package foo
|
||||
|
||||
fun Int.quadruple(): Int {
|
||||
return this * 4;
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
return (3.quadruple() == 12)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
open class A() {
|
||||
open fun c() = 2
|
||||
}
|
||||
|
||||
class B() : A() {
|
||||
}
|
||||
|
||||
fun B.d() = c() + 3
|
||||
|
||||
fun box(): Boolean {
|
||||
return B().d() == 5
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
class A(var a: Int) {
|
||||
|
||||
fun Int.modify(): Int {
|
||||
return this * 3;
|
||||
}
|
||||
|
||||
fun eval() = a.modify();
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
val a = A(4)
|
||||
return (a.eval() == 12)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package foo
|
||||
|
||||
open class A(var a: Int) {
|
||||
|
||||
open fun Int.modify(): Int {
|
||||
return this * 3;
|
||||
}
|
||||
|
||||
fun eval() = a.modify();
|
||||
}
|
||||
|
||||
class B(a: Int) : A(a) {
|
||||
override fun Int.modify(): Int {
|
||||
return this - 2;
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
return (A(4).eval() == 12) && (A(2).eval() == 6) && (B(3).eval() == 1)
|
||||
}
|
||||
Reference in New Issue
Block a user