JS: create new common directory for all generated tests, migrate several tests there

This commit is contained in:
Alexey Andreev
2016-08-26 16:44:48 +03:00
parent 34a57f863b
commit 2bf0199959
321 changed files with 2123 additions and 2001 deletions
@@ -0,0 +1,12 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
abstract class A {
abstract fun foo(): String
}
class B : A() {
override fun foo() = "OK"
}
fun box(): String = (A::foo)(B())
@@ -0,0 +1,25 @@
package foo
class A {
val s = "sA"
fun memBar(other: String): String = s +":memBar:" + other
}
fun A.extBar(other: String):String = s + ":extBar:" + other
fun box():String {
fun A.locExtBar(other: String):String = s + ":locExtBar:" + other
val a = A()
var r = (A::memBar)(a, "!!")
if (r != "sA:memBar:!!") return r
r = (A::extBar)(a, "!!")
if (r != "sA:extBar:!!") return r
r = (A::locExtBar)(a, "!!")
if (r != "sA:locExtBar:!!") return r
return "OK"
}
@@ -0,0 +1,32 @@
package foo
fun run(a: A, arg: String, funRef:(A, String) -> String): String {
return funRef(a, arg)
}
class A {
val s = "sA"
fun memBar(other: String): String = s +":memBar:" + other
}
fun A.extBar(other: String):String = s + ":extBar:" + other
fun box():String {
fun A.locExtBar(other: String):String = s + ":locExtBar:" + other
val a = A()
var r = run(a, "!!", A::memBar)
if (r != "sA:memBar:!!") return r
r = run(a, "!!", A::extBar)
if (r != "sA:extBar:!!") return r
r = run(a, "!!", A::locExtBar)
if (r != "sA:locExtBar:!!") return r
r = run(a, "!!") { a: A, other: String -> a.s + ":literal:" + other }
if (r != "sA:literal:!!") return r
return "OK"
}
@@ -0,0 +1,14 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
class A {
fun bar(k: Int) = k
fun result() = (A::bar)(this, 111)
}
fun box(): String {
val result = A().result()
if (result != 111) return "Fail $result"
return "OK"
}
@@ -0,0 +1,15 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
class A {
fun o() = 111
fun k(k: Int) = k
}
fun A.bar() = (A::o)(this) + (A::k)(this, 222)
fun box(): String {
val result = A().bar()
if (result != 333) return "Fail $result"
return "OK"
}
@@ -0,0 +1,12 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
class A {
fun foo() = "OK"
}
fun box(): String {
val x = A::foo
var r = x(A())
return r
}
@@ -0,0 +1,13 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
class A {
fun foo(result: String):String = result
}
fun box(): String {
val x = A::foo
var r = x(A(), "OK")
return r
}
@@ -0,0 +1,17 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
class A {
var result = "Fail"
fun foo() {
result = "OK"
}
}
fun box(): String {
val a = A()
val x = A::foo
x(a)
return a.result
}
@@ -0,0 +1,17 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
class A {
var result = "Fail"
fun foo(newResult: String) {
result = newResult
}
}
fun box(): String {
val a = A()
val x = A::foo
x(a, "OK")
return a.result
}
@@ -0,0 +1,16 @@
package foo
open class A {
open fun foo(a:String,b:String): String = "fooA:" + a + b
}
class B : A() {
override fun foo(a:String,b:String): String = "fooB:" + a + b
}
fun box(): String {
val b = B()
var ref = A::foo
val result = ref(b, "1", "2")
return (if (result == "fooB:12") "OK" else result)
}
@@ -0,0 +1,12 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
package foo
fun box(): String {
var result = "Fail"
fun changeToOK() { result = "OK" }
val ok = ::changeToOK
ok()
return result
}
@@ -0,0 +1,8 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
class A {
var result = "OK"
}
fun box() = (::A)().result
@@ -0,0 +1,6 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
class A(val result: String)
fun box() = (::A)("OK").result
@@ -0,0 +1,21 @@
package foo
class A(val x:Int) {
var s = "sA"
init {
s += ":init:" + x
}
}
class B(val arg1:String, val arg2:String) {
var msg = ""
init {
msg = arg1 + arg2
}
}
fun box():String {
val ref = ::A
var result = ref(1).s + (::B)("23", "45").msg
return (if (result == "sA:init:12345") "OK" else result)
}
@@ -0,0 +1,9 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
package foo
class A
fun box(): String {
fun A.foo() = "OK"
return (A::foo)(A())
}
@@ -0,0 +1,10 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
class A {
fun result() = (A::bar)(this, "OK")
}
fun A.bar(x: String) = x
fun box() = A().result()
@@ -0,0 +1,10 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
class A
fun A.foo() = (A::bar)(this, "OK")
fun A.bar(x: String) = x
fun box() = A().foo()
@@ -0,0 +1,27 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
fun <T> run(arg1: A, arg2: T, funRef:(A, T) -> T): T {
return funRef(arg1, arg2)
}
class A {
var xx: Int = 100
}
fun A.bar(x: Int): Int {
this.xx = this.xx * 2
return x
}
fun box(): String {
val funRef = A::bar
val obj = A()
var result = funRef(obj, 25)
if (result != 25 || obj.xx != 200) return "fail1: result = $result, expected 25; obj.xx = $obj.xx, expected 200"
result = run(A(), 25, funRef)
if (result != 25 || obj.xx != 200) return "fail2: result = $result, expected 25; obj.xx = $obj.xx, expected 200"
return "OK"
}
@@ -0,0 +1,21 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
fun run(arg1: A, funRef:A.() -> String): String {
return arg1.funRef()
}
class A
fun A.foo() = "OK"
fun box(): String {
val x = A::foo
var r = x(A())
if (r != "OK") return r
r = run(A(), A::foo)
if (r != "OK") return r
return "OK"
}
@@ -0,0 +1,19 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
fun run(arg1: A, arg2: String, funRef:A.(String) -> String): String {
return arg1.funRef(arg2)
}
class A
fun A.foo(result: String) = result
fun box(): String {
val x = A::foo
var r = x(A(), "OK")
if (r != "OK") return r
r = run(A(), "OK", A::foo)
return "OK"
}
@@ -0,0 +1,18 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
class A {
var result = "Fail"
}
fun A.foo() {
result = "OK"
}
fun box(): String {
val a = A()
val x = A::foo
x(a)
return a.result
}
@@ -0,0 +1,26 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
fun run(arg1: A, arg2: String, funRef:A.(String) -> Unit): Unit {
return arg1.funRef(arg2)
}
class A {
var result = "Fail"
}
fun A.foo(newResult: String) {
result = newResult
}
fun box(): String {
val a = A()
val x = A::foo
x(a, "OK")
if (a.result != "OK") return a.result
val a1 = A()
run(a1, "OK", A::foo)
return a.result
}
@@ -0,0 +1,7 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
package foo
fun box(): String {
fun Int.is42With(that: Int) = this + 2 * that == 42
return if ((Int::is42With)(16, 13)) "OK" else "Fail"
}
@@ -0,0 +1,14 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
package foo
class A
fun box(): String {
var result = "Fail"
fun A.ext() { result = "OK" }
val f = A::ext
f(A())
return result
}
@@ -0,0 +1,22 @@
package foo
fun Int.sum0(other: Int): Int = this + other
fun box(): String {
fun Int.sum1(other: Int): Int = this + other
val sum2 = fun Int.(other: Int): Int = this + other
var x = 10
x = x.sum0(5)
x = x.sum1(5)
x = x.sum2(5)
var y = 10
y = (Int::sum0)(y, 5)
y = (Int::sum1)(y, 5)
y = y.sum2(5)
var result:String = (if (x == y && x == 25) "OK" else "x=${x} y=${y}")
return result
}
@@ -0,0 +1,13 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
package foo
fun box(): String {
fun foo(): String {
fun bar() = "OK"
val ref = ::bar
return ref()
}
val ref = ::foo
return ref()
}
@@ -0,0 +1,10 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
package foo
fun foo(until: Int): String {
fun bar(x: Int): String =
if (x == until) "OK" else bar(x + 1)
return (::bar)(0)
}
fun box() = foo(10)
@@ -0,0 +1,7 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
package foo
fun box(): String {
fun foo() = "OK"
return (::foo)()
}
@@ -0,0 +1,10 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
package foo
fun box(): String {
val result = "OK"
fun foo() = result
return (::foo)()
}
@@ -0,0 +1,7 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
package foo
fun box(): String {
fun foo(s: String) = s
return (::foo)("OK")
}
@@ -0,0 +1,8 @@
package foo
fun box(): String {
var s = "abc"
assertEquals("ABC", (String::toUpperCase)(s))
return "OK"
}
@@ -0,0 +1,22 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
fun <T> run(arg1: T, arg2: T, funRef:(T,T) -> T): T {
return funRef(arg1, arg2)
}
fun tmp(o: Int, k: Int) = o + k
class A {
fun bar() = (::tmp)(111, 222)
}
fun box(): String {
val result = A().bar()
if (result != 333) return "Fail $result"
var r = run(111, 222, ::tmp)
if (result != 333) return "Fail $result"
return "OK"
}
@@ -0,0 +1,22 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
fun <T> run(arg1: T, arg2: T, funRef:(T,T) -> T): T {
return funRef(arg1, arg2)
}
fun tmp(o: Int, k: Int) = o + k
class A
fun A.bar() = (::tmp)(111, 222)
fun box(): String {
val result = A().bar()
if (result != 333) return "Fail $result"
var r = run(111, 222, ::tmp)
if (result != 333) return "Fail $result"
return "OK"
}
@@ -0,0 +1,20 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
fun run(funRef:() -> String): String {
return funRef()
}
fun bar() = "OK"
fun box(): String {
val x = ::bar
var r = x()
if (r != "OK") return r
r = run(::bar)
if (r != "OK") return r
return "OK"
}
@@ -0,0 +1,18 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
package foo
fun run(arg: Int, funRef:(Int) -> Int): Int {
return funRef(arg)
}
fun inc(x: Int) = x + 1
fun box(): String {
val funRef = ::inc
if (funRef(5) != 6) return "fail1"
if (run(5, funRef) != 6) return "fail2"
if (run(5) {x -> x + 1} != 6) return "fail3"
return "OK"
}
@@ -0,0 +1,18 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
package foo
var state = 23
fun box(): String {
fun incrementState(inc: Int) {
state += inc
}
val inc = ::incrementState
inc(12)
inc(-5)
inc(27)
inc(-15)
return if (state == 42) "OK" else "Fail $state"
}