JS: create new common directory for all generated tests, migrate several tests there
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
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(): String {
|
||||
if (A().d() == 5 && B().d() == 6 && B().t() == 7) return "OK"
|
||||
return "fail"
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
class A() {
|
||||
|
||||
}
|
||||
|
||||
fun A.one() = 1
|
||||
fun A.two() = one() + one()
|
||||
|
||||
fun box(): String {
|
||||
return if (A().two() == 2) "OK" else "fail"
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
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) {
|
||||
operator fun hasNext(): Boolean = enumerator.hasMoreElements()
|
||||
|
||||
operator fun next() = enumerator.getNext()
|
||||
}
|
||||
|
||||
operator fun SimpleEnumerator.iterator(): SimpleEnumeratorWrapper {
|
||||
return SimpleEnumeratorWrapper(this)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var o = ""
|
||||
val enumerator = SimpleEnumerator()
|
||||
for (s in enumerator) {
|
||||
o += s;
|
||||
}
|
||||
|
||||
if (o != "1") return "fail: $o"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
fun Int.same(): Int {
|
||||
return this
|
||||
}
|
||||
|
||||
fun Int.quadruple(): Int {
|
||||
return same() * 4;
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if ((3 + 4).quadruple() == 28) "OK" else "fail"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
class M() {
|
||||
var m = 0
|
||||
|
||||
fun eval() {
|
||||
var d = {
|
||||
var c = fun Int.(): Int = this + 3
|
||||
m += 3.c()
|
||||
}
|
||||
d();
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var a = M()
|
||||
if (a.m != 0) return "fail1: ${a.m}";
|
||||
a.eval()
|
||||
if (a.m != 6) return "fail2: ${a.m}";
|
||||
|
||||
return "OK";
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package foo
|
||||
|
||||
fun apply(i: Int, f: Int.(Int) -> Int) = i.f(1);
|
||||
|
||||
fun box(): String {
|
||||
return if (apply(1, { i -> i + this }) == 2) "OK" else "fail"
|
||||
}
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
public class Foo {
|
||||
|
||||
public fun blah(): Int {
|
||||
return 5
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public fun Foo.fooImp(): String {
|
||||
return "impl" + blah()
|
||||
}
|
||||
|
||||
public fun Foo.fooExp(): String {
|
||||
return "expl" + this.blah()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var a = Foo()
|
||||
if (a.fooImp() != "impl5") return "fail1: ${a.fooImp()}"
|
||||
if (a.fooExp() != "expl5") return "fail2: ${a.fooExp()}"
|
||||
return "OK";
|
||||
}
|
||||
+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(): String {
|
||||
var a = Foo()
|
||||
if (a.fooImp != 6) return "fail1: ${a.fooImp}"
|
||||
if (a.fooExp != 11) return "fail2: ${a.fooExp}"
|
||||
return "OK";
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
class A(var a: Int) {
|
||||
fun eval() = f();
|
||||
}
|
||||
|
||||
fun A.f(): Int {
|
||||
a = 3
|
||||
return 10
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A(4)
|
||||
return if ((a.eval() == 10) && (a.a == 3)) "OK" else "fail"
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
fun Int.same(): Int {
|
||||
return this
|
||||
}
|
||||
|
||||
fun Int.quadruple(): Int {
|
||||
return same() * 4;
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (3.quadruple() == 12) "OK" else "fail"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package foo
|
||||
|
||||
fun <T> T.toPrefixedString(prefix: String = "", suffix: String = "") = prefix + toString() + suffix
|
||||
|
||||
fun box(): String {
|
||||
return if (("mama".toPrefixedString(suffix = "321", prefix = "papa") == "papamama321")) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package foo
|
||||
|
||||
fun Int.quadruple(): Int {
|
||||
return this * 4;
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (3.quadruple() == 12) "OK" else "fail"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
open class A() {
|
||||
open fun c() = 2
|
||||
}
|
||||
|
||||
class B() : A() {
|
||||
}
|
||||
|
||||
fun B.d() = c() + 3
|
||||
|
||||
fun box(): String {
|
||||
return if (B().d() == 5) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
class A(var a: Int) {
|
||||
|
||||
fun Int.modify(): Int {
|
||||
return this * 3;
|
||||
}
|
||||
|
||||
fun eval() = a.modify();
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A(4)
|
||||
return if (a.eval() == 12) "OK" else "fail"
|
||||
}
|
||||
@@ -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(): String {
|
||||
return if ((A(4).eval() == 12) && (A(2).eval() == 6) && (B(3).eval() == 1)) "OK" else "fail"
|
||||
}
|
||||
Reference in New Issue
Block a user