tests: Update external tests (1.1.2-dev-393)

This commit is contained in:
Ilya Matveev
2017-03-13 12:38:08 +03:00
committed by ilmat192
parent ac56fccb15
commit bc074e6d39
3178 changed files with 22396 additions and 696 deletions
@@ -0,0 +1,14 @@
interface T {
fun foo(): String
}
val o = object : T {
val a = "OK"
val f = {
a
}()
override fun foo() = f
}
fun box() = o.foo()
@@ -0,0 +1,11 @@
open class A {
protected fun foo() = "OK"
}
class B {
companion object : A()
fun bar() = foo()
}
fun box() = B().bar()
@@ -0,0 +1,53 @@
public abstract class FList<T>() {
public abstract val head: T
public abstract val tail: FList<T>
public abstract val empty: Boolean
companion object {
val emptyFList = object: FList<Any>() {
public override val head: Any
get() = throw UnsupportedOperationException();
public override val tail: FList<Any>
get() = this
public override val empty: Boolean
get() = true
}
}
operator fun plus(head: T): FList<T> = object : FList<T>() {
override public val head: T
get() = head
override public val empty: Boolean
get() = false
override public val tail: FList<T>
get() = this@FList
}
}
public fun <T> emptyFList(): FList<T> = FList.emptyFList as FList<T>
public fun <T> FList<T>.reverse(where: FList<T> = emptyFList<T>()) : FList<T> =
if(empty) where else tail.reverse(where + head)
operator fun <T> FList<T>.iterator(): Iterator<T> = object: Iterator<T> {
private var cur: FList<T> = this@iterator
override public fun next(): T {
val res = cur.head
cur = cur.tail
return res
}
override public fun hasNext(): Boolean = !cur.empty
}
fun box() : String {
var r = ""
for(s in (emptyFList<String>() + "O" + "K").reverse()) {
r += s
}
return r
}
@@ -0,0 +1,16 @@
var result = "OK"
class A {
companion object {
var z = result
fun patchResult() {
result = "fail"
}
}
}
fun box(): String {
A.patchResult()
return A.z
}
@@ -0,0 +1,16 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
public open class Test() {
open public fun test() : Unit {
System.out?.println(hello)
}
companion object {
private val hello : String? = "Hello"
}
}
fun box() : String {
Test().test()
return "OK"
}
@@ -0,0 +1,16 @@
class A(val value: String)
fun A.test(): String {
val o = object {
val z: String
init {
val x = value + "K"
z = x
}
}
return o.z
}
fun box(): String {
return A("O").test()
}
@@ -0,0 +1,50 @@
// TARGET_BACKEND: JVM
public object SomeObject {
private val workerThread = object : Thread() {
override fun run() {
foo()
}
}
init {
workerThread.start()
}
private fun foo() : Unit {
}
}
public class SomeClass() {
inner class Inner {
val copy = list
}
private val list = ArrayList<String>()
var status : Throwable? = null
private val workerThread = object : Thread() {
public override fun run() {
try {
list.add("123")
list.add("33")
Inner().copy.add("444")
}
catch(t: Throwable) {
status = t
}
}
}
init {
workerThread.start()
workerThread.join()
}
}
public fun box(): String {
var obj = SomeClass()
return if (obj.status == null) "OK" else {
(obj.status as java.lang.Throwable).printStackTrace()
"failed"
}
}
@@ -0,0 +1,28 @@
enum class Color(val rgb : Int) {
RED(0xFF0000),
GREEN(0x00FF00),
BLUE(0x0000FF)
}
enum class Direction {
NORTH,
SOUTH,
WEST,
EAST
}
fun bar(c: Color) = when (c) {
Color.RED -> 1
Color.GREEN -> 2
Color.BLUE -> 3
}
fun foo(d: Direction) = when(d) {
Direction.NORTH -> 1
Direction.SOUTH -> 2
Direction.WEST -> 3
Direction.EAST -> 4
}
fun box() : String =
if (foo(Direction.EAST) == 4 && bar(Color.GREEN) == 2) "OK" else "fail"
@@ -0,0 +1,8 @@
abstract class Foo<T> {
fun hello(id: T) = "O$id"
}
class Bar: Foo<String>() {
}
fun box() = Bar().hello("K")
@@ -0,0 +1,16 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
fun box(): String {
return object {
fun foo(): String {
val f = {}
object : Runnable {
public override fun run() {
f()
}
}
return "OK"
}
}.foo()
}
@@ -0,0 +1,18 @@
class C {
public object Obj {
val o = "O"
object InnerObj {
fun k() = "K"
}
class D {
val ko = "KO"
}
}
}
fun box(): String {
val res = C.Obj.o + C.Obj.InnerObj.k() + C.Obj.D().ko
return if (res == "OKKO") "OK" else "Fail: $res"
}
@@ -0,0 +1,10 @@
fun box() : String {
var a = 1
object {
init {
a = 2
}
}
return if (a == 2) "OK" else "fail"
}
@@ -0,0 +1,13 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
fun box() : String {
var a = 1
(object: Runnable {
override public fun run() {
a = 2
}
}).run()
return if (a == 2) "OK" else "fail"
}
@@ -0,0 +1,16 @@
class A() {
fun ok() = Foo.Bar.bar() + Foo.Bar.barv
private object Foo {
fun foo() = "O"
val foov = "K"
public object Bar {
fun bar() = foo()
val barv = foov
}
}
}
fun box() = A().ok()
@@ -0,0 +1,9 @@
class Clazz {
companion object {
val a = object {
fun run(x: String) = x
}
}
}
fun box() = "OK"
@@ -0,0 +1,7 @@
open class A {
fun foo() = "OK"
}
fun box() = object : A() {
fun bar() = super<A>.foo()
}.bar()
@@ -0,0 +1,15 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
object Obj {
class Inner() {
fun ok() = "OK"
}
}
fun box() : String {
val klass = Class.forName("Obj\$Inner")!!
val cons = klass.getConstructors()!![0]
val inner = cons.newInstance(*(arrayOfNulls<String>(0) as Array<String>))
return "OK"
}
@@ -0,0 +1,16 @@
open class X(private val n: String) {
fun foo(): String {
return object : X("inner") {
fun print(): String {
return n;
}
}.print()
}
}
fun box() : String {
return X("OK").foo()
}
@@ -0,0 +1,12 @@
interface N
open class Base(n: N)
class Derived : Base(object: N{}) {
}
fun box() : String {
Derived()
return "OK"
}
@@ -0,0 +1,24 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
class Identifier<T>(t : T?, myHasDollar : Boolean) {
private val myT : T?
public fun getName() : T? { return myT }
companion object {
open public fun <T> init(name : T?) : Identifier<T> {
val id = Identifier<T>(name, false)
return id
}
}
init {
myT = t
}
}
fun box() : String {
var i3 : Identifier<String?>? = Identifier.init<String?>("name")
System.out?.println(i3?.getName())
return "OK"
}
@@ -0,0 +1,31 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
package while_bug_1
import java.io.*
open class AllEvenNum() {
companion object {
open public fun main(args : Array<String?>?) : Unit {
var i : Int = 1
while ((i <= 100)) {
{
if (((i % 2) == 0))
{
System.out?.print((i.toString() + ","))
}
}
i = i + 1
}
}
}
}
fun box() : String {
AllEvenNum.main(arrayOfNulls<String>(0))
return "OK"
}
@@ -0,0 +1,18 @@
enum class Test {
A,
B,
C
}
fun checkA(a: Test) = when(a) {
Test.B -> false
Test.A -> true
else -> false
}
fun box() : String {
if(!checkA(Test.A)) return "fail"
if( checkA(Test.C)) return "fail"
if( checkA(Test.B)) return "fail"
return "OK"
}
@@ -0,0 +1,17 @@
object O {
val mmmap = HashMap<String, Int>();
init {
fun doStuff() {
mmmap.put("two", 2)
}
doStuff()
}
}
fun box(): String {
val r = O.mmmap["two"]
if (r != 2) return "Fail: $r"
return "OK"
}
@@ -0,0 +1,5 @@
object A {
fun result() = "OK"
}
fun box(): String = A.result()
@@ -0,0 +1,10 @@
open class A {
companion object {
protected fun foo() = "OK"
}
class B : A() {
fun bar() = foo()
}
}
fun box() = A.B().bar()
@@ -0,0 +1,18 @@
open class A (val s: Int) {
open fun foo(): Int {
return s
}
}
object Outer: A(1) {
object O: A(2) {
override fun foo(): Int {
val s = super<A>.foo()
return s + 3
}
}
}
fun box() : String {
return if (Outer.O.foo() == 5) "OK" else "fail"
}
@@ -0,0 +1,12 @@
class A {
val x: Any get() {
return object : Inner() {
override fun toString() = foo()
}
}
open inner class Inner
fun foo() = "OK"
}
fun box(): String = A().x.toString()
@@ -0,0 +1,10 @@
fun box(): String {
var boo = "OK"
var foo = object {
val bar = object {
val baz = boo
}
}
return foo.bar.baz
}
@@ -0,0 +1,6 @@
object A {
val a = "OK"
val b = A.a
}
fun box() = A.b
@@ -0,0 +1,18 @@
class C(x: Int, val y: Int) {
fun initChild(x0: Int): Any {
var x = x0
return object {
override fun toString(): String {
x = x + y
return "child" + x
}
}
}
val child = initChild(x)
}
fun box(): String {
val c = C(10, 3)
return if (c.child.toString() == "child13" && c.child.toString() == "child16" && c.child.toString() == "child19") "OK" else "fail"
}
@@ -0,0 +1,17 @@
package p
private class C(val y: Int) {
val initChild = { ->
object {
override fun toString(): String {
return "child" + y
}
}
}
}
fun box(): String {
val c = C(3).initChild
val x = c().toString()
return if (x == "child3") "OK" else x
}
@@ -0,0 +1,24 @@
public inline fun <T> T.with(f: T.() -> Unit): T {
this.f()
return this
}
public class Cls {
val string = "Cls"
val buffer = StringBuilder().with {
append(string)
}
}
public object Obj {
val string = "Obj"
val buffer = StringBuilder().with {
append(string)
}
}
fun box(): String {
if (Cls().buffer.toString() != "Cls") return "Fail class"
if (Obj.buffer.toString() != "Obj") return "Fail object"
return "OK"
}
@@ -0,0 +1,16 @@
open class A {
open fun foo(): Int {
return 2
}
}
object O: A() {
override fun foo(): Int {
val s = super<A>.foo()
return s + 3
}
}
fun box() : String {
return if (O.foo() == 5) "OK" else "fail"
}
@@ -0,0 +1,21 @@
open class A {
open fun foo(): Int {
return 2
}
}
interface T {
open fun foo(): Int {
return 3
}
}
object O: A(), T {
override fun foo(): Int {
return super<A>.foo() + super<T>.foo()
}
}
fun box() : String {
return if (O.foo() == 5) "OK" else "fail"
}
@@ -0,0 +1,16 @@
class A(val result: String)
fun a(body: A.() -> String): String {
val r = A("OK")
return r.body()
}
object C {
private fun A.f() = result
val g = a {
f()
}
}
fun box() = C.g
@@ -0,0 +1,20 @@
interface T
object Foo {
private fun foo(p: T) = p
private val v: Int = {
val x = foo(O)
42
}()
private object O : T
val result = v
}
fun box(): String {
val foo = Foo
if (foo.result != 42) return "Fail: ${foo.result}"
return "OK"
}
@@ -0,0 +1,7 @@
open class A(open val v: String)
fun A.a(newv: String) = object: A("fail") {
override val v = this@a.v + newv
}
fun box() = A("O").a("K").v
@@ -0,0 +1,7 @@
// KT-5159
object Test {
val a = "OK"
}
fun box(): String = Test?.a
@@ -0,0 +1,7 @@
object A {
val x: Int = 610
}
fun box() : String {
return if (A.x != 610) "fail" else "OK"
}
@@ -0,0 +1,10 @@
open class A(open val v: String) {
}
open class B(open val v: String) {
fun a(newv: String) = object: A("fail") {
override val v = this@B.v + newv
}
}
fun box() = B("O").a("K").v
@@ -0,0 +1,18 @@
// KT-5869
operator fun <T> Iterator<T>.iterator(): Iterator<T> = this
fun box(): String {
val iterator = object : Iterator<Int> {
var i = 0
override fun next() = i++
override fun hasNext() = i < 5
}
var result = ""
for (i in iterator) {
result += i
}
return if (result == "01234") "OK" else "Fail $result"
}
@@ -0,0 +1,50 @@
import C.f
import C.p
import C.ext
import C.g1
import C.g2
import C.fromClass
import C.fromInterface
import C.genericFromSuper
interface I<G> {
fun <T> T.fromInterface(): T = this
fun genericFromSuper(g: G) = g
}
open class BaseClass {
val <T> T.fromClass: T
get() = this
}
object C: BaseClass(), I<String> {
fun f(s: Int) = 1
fun f(s: String) = 2
fun Boolean.f() = 3
var p: Int = 4
val Int.ext: Int
get() = 6
fun <T> g1(t: T): T = t
val <T> T.g2: T
get() = this
}
fun box(): String {
if (f(1) != 1) return "1"
if (f("s") != 2) return "2"
if (true.f() != 3) return "3"
if (p != 4) return "4"
p = 5
if (p != 5) return "5"
if (5.ext != 6) return "6"
if (g1("7") != "7") return "7"
if ("8".g2 != "8") return "8"
if (9.fromInterface() != 9) return "9"
if ("10".fromClass != "10") return "10"
if (genericFromSuper("11") != "11") return "11"
return "OK"
}
@@ -0,0 +1,52 @@
import Class.C.f
import Class.C.p
import Class.C.ext
import Class.C.g1
import Class.C.g2
import Class.C.fromClass
import Class.C.fromInterface
import Class.C.genericFromSuper
interface I<G> {
fun <T> T.fromInterface(): T = this
fun genericFromSuper(g: G) = g
}
open class BaseClass {
val <T> T.fromClass: T
get() = this
}
class Class {
companion object C: BaseClass(), I<String> {
fun f(s: Int) = 1
fun f(s: String) = 2
fun Boolean.f() = 3
var p: Int = 4
val Int.ext: Int
get() = 6
fun <T> g1(t: T): T = t
val <T> T.g2: T
get() = this
}
}
fun box(): String {
if (f(1) != 1) return "1"
if (f("s") != 2) return "2"
if (true.f() != 3) return "3"
if (p != 4) return "4"
p = 5
if (p != 5) return "5"
if (5.ext != 6) return "6"
if (g1("7") != "7") return "7"
if ("8".g2 != "8") return "8"
if (9.fromInterface() != 9) return "9"
if ("10".fromClass != "10") return "10"
if (genericFromSuper("11") != "11") return "11"
return "OK"
}