Move blackBoxFile() testData to box/ directory

Delete all test methods (and empty test classes), since they'll be
auto-generated
This commit is contained in:
Alexander Udalov
2013-01-25 16:13:45 +04:00
committed by Alexander Udalov
parent ecbb2f10ef
commit 41a416da60
438 changed files with 156 additions and 2005 deletions
@@ -0,0 +1,11 @@
fun Array<String>.get(index1: Int, index2: Int) = this[index1 + index2]
fun Array<String>.set(index1: Int, index2: Int, elem: String) {
this[index1 + index2] = elem
}
fun box(): String {
val s = Array<String>(1, { "" })
s[1, -1] = "O"
s[2, -2] += "K"
return s[-3, 3]
}
@@ -0,0 +1,11 @@
fun Array<String>.get(index1: Int, index2: Int) = this[index1 + index2]
fun Array<String>.set(index1: Int, index2: Int, elem: String) {
this[index1 + index2] = elem
}
fun box(): String {
val s = Array<String>(1, { "" })
s[1, -1] = "OK"
return s[-2, 2]
}
@@ -0,0 +1,6 @@
fun box(): String {
val s = IntArray(1)
s[0] = 5
s[0] += 7
return if (s[0] == 12) "OK" else "Fail ${s[0]}"
}
@@ -0,0 +1,14 @@
import java.util.ArrayList
fun ArrayList<String>.get(index1: Int, index2: Int) = this[index1 + index2]
fun ArrayList<String>.set(index1: Int, index2: Int, elem: String) {
this[index1 + index2] = elem
}
fun box(): String {
val s = ArrayList<String>(1)
s.add("")
s[1, -1] = "O"
s[2, -2] += "K"
return s[2, -2]
}
@@ -0,0 +1,13 @@
import java.util.ArrayList
fun ArrayList<String>.get(index1: Int, index2: Int) = this[index1 + index2]
fun ArrayList<String>.set(index1: Int, index2: Int, elem: String) {
this[index1 + index2] = elem
}
fun box(): String {
val s = ArrayList<String>(1)
s.add("")
s[1, -1] = "OK"
return s[2, -2]
}
@@ -0,0 +1,6 @@
fun box(): String {
for (x in BooleanArray(5)) {
if (x != false) return "Fail $x"
}
return "OK"
}
@@ -0,0 +1,6 @@
fun box(): String {
for (x in ByteArray(5)) {
if (x != 0.toByte()) return "Fail $x"
}
return "OK"
}
@@ -0,0 +1,6 @@
fun box(): String {
for (x in CharArray(5)) {
if (x != 0.toChar()) return "Fail $x"
}
return "OK"
}
@@ -0,0 +1,6 @@
fun box(): String {
for (x in DoubleArray(5)) {
if (x != 0.toDouble()) return "Fail $x"
}
return "OK"
}
@@ -0,0 +1,6 @@
fun box(): String {
for (x in FloatArray(5)) {
if (x != 0.toFloat()) return "Fail $x"
}
return "OK"
}
@@ -0,0 +1,6 @@
fun box(): String {
for (x in IntArray(5)) {
if (x != 0) return "Fail $x"
}
return "OK"
}
@@ -0,0 +1,6 @@
fun box(): String {
for (x in LongArray(5)) {
if (x != 0.toLong()) return "Fail $x"
}
return "OK"
}
@@ -0,0 +1,6 @@
fun box(): String {
for (x in ShortArray(5)) {
if (x != 0.toShort()) return "Fail $x"
}
return "OK"
}
@@ -0,0 +1,11 @@
import java.util.HashMap
fun HashMap<String, Int?>.set(index: String, elem: Int?) {
this.put(index, elem)
}
fun box(): String {
val s = HashMap<String, Int?>()
s["239"] = 239
return if (s["239"] == 239) "OK" else "Fail"
}
@@ -0,0 +1,9 @@
fun box(): String {
val a = Array<Int>(5, {it})
val x = a.indices.iterator()
while (x.hasNext()) {
val i = x.next()
if (a[i] != i) return "Fail $i ${a[i]}"
}
return "OK"
}
@@ -0,0 +1,9 @@
fun box(): String {
val a = CharArray(5)
val x = a.indices.iterator()
while (x.hasNext()) {
val i = x.next()
if (a[i] != 0.toChar()) return "Fail $i ${a[i]}"
}
return "OK"
}
@@ -0,0 +1,9 @@
fun box(): String {
val x = Array<Int>(5, { it } ).iterator()
var i = 0
while (x.hasNext()) {
if (x.next() != i) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = BooleanArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.next()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = ByteArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.next()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = ByteArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.nextByte()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = CharArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.next()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = DoubleArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.next()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = FloatArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.next()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = IntArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.next()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = LongArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.next()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = LongArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.nextLong()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = ShortArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.next()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,58 @@
fun t1 () {
val a1 = arrayOfNulls<String>(1)
a1[0] = "0" //ok
val s = a1[0] //ok
}
fun t2 () {
val a2 = Array<Int>(1,{0})
a2[0] = 0 //ok
var i = a2[0] //ok
}
fun t3 () {
val a3 = arrayOfNulls<Int>(1)
a3[0] = 0 //verify error
var j = a3[0] //ok
var k : Int = a3[0] ?: 5 //ok
}
fun t4 () {
val b1 = StrangeIntArray(10)
b1[4] = 5 //ok
var i = b1[1] //ok
}
fun t5 () {
val b2 = StrangeArray<Int>(10, 0)
b2.set(4, 5) //ok
b2[4] = 5 //verify error
var i = b2.get(2) //ok
i = b2[1] //verify error
}
fun t6() {
val b3 = StrangeArray<Int?>(10, 0)
b3.set(5, 6) //ok
b3[4] = 5 //verify error
val v = b3[1] //ok
}
fun box() : String {
return "OK"
}
class StrangeArray<T>(size: Int, private var defaultValue: T) {
fun get(index: Int): T = defaultValue
fun set(index: Int, v: T) {
defaultValue = v
}
}
class StrangeIntArray(size: Int) {
private var defaultValue = 0
fun get(index: Int): Int = defaultValue
fun set(index: Int, v: Int) {
defaultValue = v
}
}
@@ -0,0 +1,85 @@
//KT-2997 Automatically cast error (Array)
fun foo(a: Any): Int {
if (a is IntArray) {
a.get(0)
a.set(0, 1)
a.iterator()
a.indices
return a.size
}
if (a is ShortArray) {
a.get(0)
a.set(0, 1)
a.iterator()
a.indices
return a.size
}
if (a is ByteArray) {
a.get(0)
a.set(0, 1)
a.iterator()
a.indices
return a.size
}
if (a is FloatArray) {
a.get(0)
a.set(0, 1.toFloat())
a.iterator()
a.indices
return a.size
}
if (a is DoubleArray) {
a.get(0)
a.set(0, 1.0)
a.iterator()
a.indices
return a.size
}
if (a is BooleanArray) {
a.get(0)
a.set(0, false)
a.iterator()
a.indices
return a.size
}
if (a is CharArray) {
a.get(0)
a.set(0, 'a')
a.iterator()
a.indices
return a.size
}
if (a is Array<*>) {
if (a.size > 0) a.get(0)
a.iterator()
a.indices
return a.size
}
return 0
}
fun box(): String {
val iA = IntArray(1)
if (foo(iA) != 1) return "fail int[]"
val sA = ShortArray(1)
if (foo(sA) != 1) return "fail short[]"
val bA = ByteArray(1)
if (foo(bA) != 1) return "fail byte[]"
val fA = FloatArray(1)
if (foo(fA) != 1) return "fail float[]"
val dA = DoubleArray(1)
if (foo(dA) != 1) return "fail double[]"
val boolA = BooleanArray(1)
if (foo(boolA) != 1) return "fail boolean[]"
val cA = CharArray(1)
if (foo(cA) != 1) return "fail char[]"
val oA = Array<Any>(1) { 1 }
if (foo(oA) != 1) return "fail Any[]"
val sArray = Array<String>(0) { "" }
if (foo(sArray) != 0) return "fail String[]"
return "OK"
}
@@ -0,0 +1,6 @@
fun box () : String {
val s = java.util.ArrayList<String>()
s.add("foo")
s[0] += "bar"
return if(s[0] == "foobar") "OK" else "fail"
}
@@ -0,0 +1,32 @@
fun iarr(vararg a : Int) = a
fun <T> array(vararg a : T) = a
fun box() : String {
val tests = array<IntArray>(
iarr(6, 5, 4, 3, 2, 1),
iarr(1, 2),
iarr(1, 2, 3),
iarr(1, 2, 3, 4),
iarr(1)
)
var n = 0
try {
var i = 0
while (true) {
if (thirdElementIsThree(tests[i++]))
n++
}
}
catch (e : ArrayIndexOutOfBoundsException) {
// No more tests to process
}
System.out?.println(n)
return if(n == 2) "OK" else "fail"
}
fun thirdElementIsThree(a : IntArray) =
// Problematic code does not compile
// a.size >= 3 & a[2] == 3
a.size >= 3 && a[2] == 3
@@ -0,0 +1,16 @@
package array_test
fun box() : String {
var array : IntArray? = IntArray(10)
array?.set(0, 3)
if(array?.get(0) != 3) return "fail"
var a = arrayOfNulls<Array<String?>>(5)
var b = arrayOfNulls<String>(1)
b.set(0, "239")
a?.set(0, b)
if(a?.get(0)?.get(0) != "239") return "fail"
return "OK"
}
@@ -0,0 +1,2 @@
fun box() = if(arrayOfNulls<Int>(10) is Array<java.lang.Integer>) "OK" else "fail"
@@ -0,0 +1,3 @@
val <T> Array<T>.length : Int get() = this.size
fun box() = if(Array(10, {1}).length == 10) "OK" else "fail"
@@ -0,0 +1,9 @@
import java.util.*
fun <K, V> MutableMap<K, V>.set(k : K, v : V) = put(k, v)
fun box() : String {
val map = HashMap<String,String>()
map["239"] = "932"
return if(map["239"] == "932") "OK" else "fail"
}
@@ -0,0 +1,9 @@
fun IntArray.set(index: Long, elem: Int) { this[index.toInt()] = elem }
fun IntArray.get(index: Long) = this[index.toInt()]
fun box(): String {
var l = IntArray(1)
l[0.toLong()] = 4
l[0.toLong()] += 6
return if (l[0.toLong()] == 10) "OK" else "Fail"
}
@@ -0,0 +1,8 @@
class A() {
class B(val i: Int) {
}
fun test() = Array<B> (10, { B(it) })
}
fun box() = if(A().test()[5].i == 5) "OK" else "fail"
@@ -0,0 +1,11 @@
trait A<T> {
fun foo(): T
}
class B : A<String> {
override fun foo() = "OK"
}
class C(a: A<String>) : A<String> by a
fun box() = (C(B()) : A<String>).foo()
@@ -0,0 +1,15 @@
trait A<T> {
var result: T
}
class B(a: A<String>): A<String> by a
fun box(): String {
val o = object : A<String> {
override var result = "Fail"
}
val b: A<String> = B(o)
b.result = "OK"
if (b.result != "OK") return "Fail"
return (b : A<String>).result
}
@@ -0,0 +1,15 @@
trait A<T> {
fun foo(t: T) = "A"
}
class Z : A<String>
fun box(): String {
val z = Z()
return when {
z.foo("") != "A" -> "Fail #1"
(z : A<String>).foo("") != "A" -> "Fail #2"
else -> "OK"
}
}
@@ -0,0 +1,23 @@
trait A<T, U> {
fun foo(t: T, u: U) = "A"
}
trait B<U> : A<String, U>
trait C<T> : A<T, Int>
class Z : B<Int>, C<String> {
override fun foo(t: String, u: Int) = "Z"
}
fun box(): String {
val z = Z()
return when {
z.foo("", 0) != "Z" -> "Fail #1"
(z : C<String>).foo("", 0) != "Z" -> "Fail #2"
(z : B<Int>).foo("", 0) != "Z" -> "Fail #3"
(z : A<String, Int>).foo("", 0) != "Z" -> "Fail #4"
else -> "OK"
}
}
@@ -0,0 +1,12 @@
abstract class Foo<T> {
fun hello(id: T) = "Hi $id"
}
trait Tr {
fun hello(s : String)
}
class Bar: Foo<String>(), Tr {
}
fun box(): String = if (Bar().hello("Reg") == "Hi Reg") "OK" else "Fail"
@@ -0,0 +1,13 @@
open class A<T> {
open fun f(args : Array<T>) {}
}
class B(): A<String>() {
override fun f(args : Array<String>) {}
}
fun main(args: Array<String>) {
B()
}
fun box(): String = "OK"
@@ -0,0 +1,19 @@
import java.util.ArrayList
open class BaseStringList: ArrayList<String>() {
}
class StringList: BaseStringList() {
public override fun get(index: Int): String {
return "StringList.get()"
}
}
fun box(): String {
val myStringList = StringList()
myStringList.add("first element")
if (myStringList.get(0) != "StringList.get()") return "Fail #1"
if ((myStringList: BaseStringList).get(0) != "StringList.get()") return "Fail #2"
if ((myStringList: ArrayList<String>).get(0) != "StringList.get()") return "Fail #3"
return "OK"
}
@@ -0,0 +1,14 @@
open class A<R> {
open fun foo(r: R): R {return r}
}
open class B : A<String>() {
}
open class C : B() {
override fun foo(r: String): String {
return super.foo(r) + "K"
}
}
fun box() = C().foo("O")
@@ -0,0 +1,17 @@
package test
public trait FunDependencyEdge {
val from: FunctionNode
}
public trait FunctionNode
public class FunctionNodeImpl : FunctionNode
class FunDependencyEdgeImpl(override val from: FunctionNodeImpl): FunDependencyEdge {
}
fun box(): String {
(FunDependencyEdgeImpl(FunctionNodeImpl()) as FunDependencyEdge).from
return "OK"
}
@@ -0,0 +1,9 @@
trait Tr<T> {
val v: T
}
class C : Tr<String> {
override val v = "OK"
}
fun box() = C().v
@@ -0,0 +1,28 @@
open class A<T> {
open fun foo(t: T) = "A"
}
open class B<T> : A<T>()
open class C : B<String>() {
override fun foo(t: String) = "C"
}
open class D : C()
class Z : D() {
override fun foo(t: String) = "Z"
}
fun box(): String {
val z = Z()
return when {
z.foo("") != "Z" -> "Fail #1"
(z : D).foo("") != "Z" -> "Fail #2"
(z : C).foo("") != "Z" -> "Fail #3"
(z : B<String>).foo("") != "Z" -> "Fail #4"
(z : A<String>).foo("") != "Z" -> "Fail #5"
else -> "OK"
}
}
@@ -0,0 +1,23 @@
open class A<T, U, V> {
open fun foo(t: T, u: U, v: V) = "A"
}
open class B<T, V> : A<T, Int, V>()
open class C<V> : B<String, V>()
class Z : C<Double>() {
override fun foo(t: String, u: Int, v: Double) = "Z"
}
fun box(): String {
val z = Z()
return when {
z.foo("", 0, 0.0) != "Z" -> "Fail #1"
(z : C<Double>).foo("", 0, 0.0) != "Z" -> "Fail #2"
(z : B<String, Double>).foo("", 0, 0.0) != "Z" -> "Fail #3"
(z : A<String, Int, Double>).foo("", 0, 0.0) != "Z" -> "Fail #4"
else -> "OK"
}
}
@@ -0,0 +1,16 @@
trait A<T, U> {
fun foo(t: T, u: U) = "A"
}
class Z<T> : A<T, Int> {
override fun foo(t: T, u: Int) = "Z"
}
fun box(): String {
val z = Z<Int>()
return when {
z.foo(0, 0) != "Z" -> "Fail #1"
(z : A<Int, Int>).foo(0, 0) != "Z" -> "Fail #2"
else -> "OK"
}
}
@@ -0,0 +1,10 @@
public abstract class AbstractClass<T> {
public abstract val some: T
}
public class Class: AbstractClass<String>() {
public override val some: String
get() = "OK"
}
fun box(): String = Class().some
@@ -0,0 +1,13 @@
open class C {
open fun f(): Any = "C f"
}
class D() : C() {
override fun f(): String = "D f"
}
fun box(): String{
val d : C = D()
if(d.f() != "D f") return "fail f"
return "OK"
}
@@ -0,0 +1,15 @@
open class A<T> {
open var x: T = "Fail" as T
get
}
class B : A<String>() {
override var x: String = "Fail"
set
}
fun box(): String {
val a: A<String> = B()
a.x = "OK"
return a.x
}
@@ -0,0 +1,18 @@
trait A<O, K> {
val o: O
val k: K
}
trait B<K> : A<String, K>
trait C<O> : A<O, String>
class D : B<String>, C<String> {
override val o = "O"
override val k = "K"
}
fun box(): String {
val a: A<String, String> = D()
return a.o + a.k
}
@@ -0,0 +1,11 @@
trait A<T> {
var x: T
}
class B(override var x: String) : A<String>
fun box(): String {
val a: A<String> = B("Fail")
a.x = "OK"
return a.x
}
@@ -0,0 +1,13 @@
trait A<T> {
var v: T
}
class B : A<String> {
override var v: String = "Fail"
}
fun box(): String {
val a: A<String> = B()
a.v = "OK"
return a.v
}
@@ -0,0 +1,17 @@
open class A<T> {
open fun foo(t: T) = "A"
}
class Z : A<String>() {
override fun foo(t: String) = "Z"
}
fun box(): String {
val z = Z()
return when {
z.foo("") != "Z" -> "Fail #1"
(z : A<String>).foo("") != "Z" -> "Fail #2"
else -> "OK"
}
}
@@ -0,0 +1,20 @@
trait A<T> {
open fun foo(t: T) = "A"
}
enum class Z(val name: String) : A<String> {
Z1 : Z("Z1")
Z2 : Z("Z2")
override fun foo(t: String) = name
}
fun box(): String {
return when {
Z.Z1.foo("") != "Z1" -> "Fail #1"
Z.Z2.foo("") != "Z2" -> "Fail #2"
(Z.Z1 : A<String>).foo("") != "Z1" -> "Fail #3"
(Z.Z2 : A<String>).foo("") != "Z2" -> "Fail #4"
else -> "OK"
}
}
@@ -0,0 +1,17 @@
open class A<T> {
open fun <U> foo(t: T, u: U) = "A"
}
class Z : A<String>() {
override fun <U> foo(t: String, u: U) = "Z"
}
fun box(): String {
val z = Z()
return when {
z.foo("", 0) != "Z" -> "Fail #1"
(z : A<String>).foo("", 0) != "Z" -> "Fail #2"
else -> "OK"
}
}
@@ -0,0 +1,21 @@
open class A<T> {
open fun foo(t: T) = "A"
}
object Z : A<String>() {
override fun foo(t: String) = "Z"
}
fun box(): String {
val z = object : A<String>() {
override fun foo(t: String) = "z"
}
return when {
Z.foo("") != "Z" -> "Fail #1"
z.foo("") != "z" -> "Fail #2"
(Z : A<String>).foo("") != "Z" -> "Fail #3"
(z : A<String>).foo("") != "z" -> "Fail #4"
else -> "OK"
}
}
@@ -0,0 +1,16 @@
open class A<T : Number>(val t: T) {
open fun foo(): T = t
}
class Z : A<Int>(17) {
override fun foo() = 239
}
fun box(): String {
val z = Z()
return when {
z.foo() != 239 -> "Fail #1"
(z : A<Int>).foo() != 239 -> "Fail #2"
else -> "OK"
}
}
@@ -0,0 +1,17 @@
open class A<T : Number> {
open fun foo(t: T) = "A"
}
class Z : A<Int>() {
override fun foo(t: Int) = "Z"
}
fun box(): String {
val z = Z()
return when {
z.foo(0) != "Z" -> "Fail #1"
(z : A<Int>).foo(0) != "Z" -> "Fail #2"
else -> "OK"
}
}
@@ -0,0 +1,20 @@
open class A<T> {
open fun foo(t: T) = "A"
}
open class B : A<String>()
class Z : B() {
override fun foo(t: String) = "Z"
}
fun box(): String {
val z = Z()
return when {
z.foo("") != "Z" -> "Fail #1"
(z : B).foo("") != "Z" -> "Fail #2"
(z : A<String>).foo("") != "Z" -> "Fail #3"
else -> "OK"
}
}
@@ -0,0 +1,20 @@
abstract class A<T> {
abstract fun foo(t: T): String
}
abstract class B : A<String>()
class Z : B() {
override fun foo(t: String) = "Z"
}
fun box(): String {
val z = Z()
return when {
z.foo("") != "Z" -> "Fail #1"
(z : B).foo("") != "Z" -> "Fail #2"
(z : A<String>).foo("") != "Z" -> "Fail #3"
else -> "OK"
}
}
@@ -0,0 +1,19 @@
open class A<T : U, U> {
open fun foo(t: T, u: U) = "A"
}
open class B : A<Int, Number>()
class Z : B() {
override fun foo(t: Int, u: Number) = "Z"
}
fun box(): String {
val z = Z()
return when {
z.foo(0, 0) != "Z" -> "Fail #1"
(z : B).foo(0, 0) != "Z" -> "Fail #2"
(z : A<Int, Number>).foo(0, 0) != "Z" -> "Fail #3"
else -> "OK"
}
}
@@ -0,0 +1,17 @@
trait A<T> {
fun id(t: T): T
}
open class B : A<String> {
override fun id(t: String) = t
}
class C : B()
class D : A<String> by C()
fun box(): String {
val d = D()
if (d.id("") != "") return "Fail"
return (d : A<String>).id("OK")
}
@@ -0,0 +1,24 @@
trait A<T> {
open fun foo(t: T) = "A"
}
trait B : A<String>
enum class Z(val name: String) : B {
Z1 : Z("Z1")
Z2 : Z("Z2")
override fun foo(t: String) = name
}
fun box(): String {
return when {
Z.Z1.foo("") != "Z1" -> "Fail #1"
Z.Z2.foo("") != "Z2" -> "Fail #2"
(Z.Z1 : B).foo("") != "Z1" -> "Fail #3"
(Z.Z2 : B).foo("") != "Z2" -> "Fail #4"
(Z.Z1 : A<String>).foo("") != "Z1" -> "Fail #5"
(Z.Z2 : A<String>).foo("") != "Z2" -> "Fail #6"
else -> "OK"
}
}
@@ -0,0 +1,20 @@
open class A<T> {
open fun <U> foo(t: T, u: U) = "A"
}
open class B : A<String>()
class Z : B() {
override fun <U> foo(t: String, u: U) = "Z"
}
fun box(): String {
val z = Z()
return when {
z.foo("", 0) != "Z" -> "Fail #1"
(z : B).foo("", 0) != "Z" -> "Fail #2"
(z : A<String>).foo("", 0) != "Z" -> "Fail #3"
else -> "OK"
}
}
@@ -0,0 +1,25 @@
open class A<T> {
open fun foo(t: T) = "A"
}
open class B : A<String>()
object Z : B() {
override fun foo(t: String) = "Z"
}
fun box(): String {
val o = object : B() {
override fun foo(t: String) = "o"
}
return when {
Z.foo("") != "Z" -> "Fail #1"
o.foo("") != "o" -> "Fail #2"
(Z : B).foo("") != "Z" -> "Fail #3"
(o : B).foo("") != "o" -> "Fail #4"
(Z : A<String>).foo("") != "Z" -> "Fail #5"
(o : A<String>).foo("") != "o" -> "Fail #6"
else -> "OK"
}
}
@@ -0,0 +1,12 @@
open class A<T>(val t: T) {
open val foo: T = t
}
open class B : A<String>("Fail")
class Z : B() {
override val foo = "OK"
}
fun box() = (Z() : A<String>).foo
@@ -0,0 +1,20 @@
open class A<T : Number> {
open fun foo(t: T) = "A"
}
open class B : A<Int>()
class Z : B() {
override fun foo(t: Int) = "Z"
}
fun box(): String {
val z = Z()
return when {
z.foo(0) != "Z" -> "Fail #1"
(z : B).foo(0) != "Z" -> "Fail #2"
(z : A<Int>).foo(0) != "Z" -> "Fail #3"
else -> "OK"
}
}
@@ -0,0 +1,22 @@
trait A<T> {
fun foo(t: T, u: Int) = "A"
}
trait B<T, U> {
fun foo(t: T, u: U) = "B"
}
class Z : A<String>, B<String, Int> {
override fun foo(t: String, u: Int) = "Z"
}
fun box(): String {
val z = Z()
return when {
z.foo("", 0) != "Z" -> "Fail #1"
(z : A<String>).foo("", 0) != "Z" -> "Fail #2"
(z : B<String, Int>).foo("", 0) != "Z" -> "Fail #3"
else -> "OK"
}
}
@@ -0,0 +1,22 @@
trait A<T> {
fun foo(t: T) = "A"
}
trait B<T> {
fun foo(t: T) = "B"
}
class Z : A<Int>, B<Int> {
override fun foo(t: Int) = "Z"
}
fun box(): String {
val z = Z()
return when {
z.foo(0) != "Z" -> "Fail #1"
(z : A<Int>).foo(0) != "Z" -> "Fail #2"
(z : B<Int>).foo(0) != "Z" -> "Fail #3"
else -> "OK"
}
}
@@ -0,0 +1,11 @@
class C() {
class object {
fun create() = C()
}
}
fun box(): String {
val c = C.create()
return if (c is C) "OK" else "fail"
}
@@ -0,0 +1,7 @@
class A() {
class object {
val value = 10
}
}
fun box() = if (A.value == 10) "OK" else "Fail ${A.value}"
@@ -0,0 +1,12 @@
// EA-38323 - Illegal field modifiers in class: classObject field in C must be static and final
trait C {
class object {
public val FOO: String = "OK"
}
}
fun box(): String {
return C.FOO
}
@@ -0,0 +1,24 @@
trait Trait1 {
fun foo() : String
}
trait Trait2 {
fun bar() : String
}
class T1 : Trait1{
override fun foo() = "aaa"
}
class T2 : Trait2{
override fun bar() = "bbb"
}
class C(a:Trait1, b:Trait2) : Trait1 by a, Trait2 by b
fun box() : String {
val c = C(T1(),T2())
if(c.foo() != "aaa") return "fail"
if(c.bar() != "bbb") return "fail"
return "OK"
}
@@ -0,0 +1,35 @@
trait One {
public open fun foo() : Int
public open fun faz() : Int = 10
}
trait Two {
public open fun foo() : Int
public open fun quux() : Int = 100
}
class OneImpl : One {
public override fun foo() = 1
}
class TwoImpl : Two {
public override fun foo() = 2
}
class Test2(a : One, b : Two) : Two by b, One by a {
public override fun foo() = 0
}
fun box() : String {
var t2 = Test2(OneImpl(), TwoImpl())
if (t2.foo() != 0)
return "Fail #1"
if (t2.faz() != 10)
return "Fail #2"
if (t2.quux() != 100)
return "Fail #3"
if (t2 !is One)
return "Fail #4"
if (t2 !is Two)
return "Fail #5"
return "OK"
}
@@ -0,0 +1,28 @@
open trait First {
public open fun foo() : Int
}
open trait Second : First {
public open fun bar() : Int
}
class Impl : Second {
public override fun foo() = 1
public override fun bar() = 2
}
class Test(s : Second) : Second by s {}
fun box() : String {
var t = Test(Impl())
if (t.foo() != 1)
return "Fail #1"
if (t.bar() != 2)
return "Fail #2"
if (t !is First)
return "Fail #3"
if (t !is Second)
return "Fail #4"
return "OK"
}
@@ -0,0 +1,12 @@
trait A<T> {
fun foo(t: T): String
}
class Derived(a: A<Int>) : A<Int> by a
fun box(): String {
val o = object : A<Int> {
override fun foo(t: Int) = if (t == 42) "OK" else "Fail $t"
}
return Derived(o).foo(42)
}
@@ -0,0 +1,12 @@
trait A<T: Number> {
fun foo(t: T): String
}
class Derived(a: A<Int>) : A<Int> by a
fun box(): String {
val o = object : A<Int> {
override fun foo(t: Int) = if (t == 42) "OK" else "Fail $t"
}
return Derived(o).foo(42)
}
@@ -0,0 +1,12 @@
trait A<T, U> {
fun foo(t: T, u: U): String
}
class Derived(a: A<Long, Int>) : A<Long, Int> by a
fun box(): String {
val o = object : A<Long, Int> {
override fun foo(t: Long, u: Int) = if (t == u.toLong()) "OK" else "Fail $t $u"
}
return Derived(o).foo(42, 42)
}
@@ -0,0 +1,13 @@
class TestJava(r : Runnable) : Runnable by r {}
class TestRunnable() : Runnable {
public override fun run() = System.out.println("foobar")
}
fun box() : String {
var del = TestJava(TestRunnable())
del.run()
if (del !is Runnable)
return "Fail #1"
return "OK"
}
@@ -0,0 +1,34 @@
package test
trait TextField {
fun getText(): String
}
trait InputTextField : TextField {
fun setText(text: String)
}
trait MooableTextField : InputTextField {
fun moo(a: Int, b: Int, c: Int): Int
}
class SimpleTextField : MooableTextField {
private var text = ""
override fun getText() = text
override fun setText(text: String) {
this.text = text
}
override fun moo(a: Int, b: Int, c: Int) = a + b + c
}
class TextFieldWrapper(textField: MooableTextField) : MooableTextField by textField
fun box() : String {
val textField = TextFieldWrapper(SimpleTextField())
textField.setText("hello world!")
if (!textField.getText().equals("hello world!")) return "FAIL #!1"
if (textField.moo(1,2,3) != 6) return "FAIL #2"
return "OK"
}
@@ -0,0 +1,24 @@
// Changed when traits were introduced. May not make sense any more
open class Base() {
public var v : Int = 0
}
open class Left() : Base() {}
trait Right : Base {}
class D() : Left(), Right
fun vl(l : Left) : Int = l.v
fun vr(r : Right) : Int = r.v
fun box() : String {
val d = D()
d.v = 42
if (d.v != 42) return "Fail #1"
if (vl(d) != 42) return "Fail #2"
if (vr(d) != 42) return "Fail #3"
return "OK"
}
@@ -0,0 +1,7 @@
class GameError(msg: String): Exception(msg) {
}
fun box(): String {
val e = GameError("foo")
return if (e.getMessage() == "foo") "OK" else "fail"
}
@@ -0,0 +1,17 @@
open class Base() {
fun n(n : Int) : Int = n + 1
}
trait Abstract {}
class Derived1() : Base(), Abstract {}
class Derived2() : Abstract, Base() {}
fun test(s : Base) : Boolean = s.n(238) == 239
fun box() : String {
if (!test(Base())) return "Fail #1"
if (!test(Derived1())) return "Fail #2"
if (!test(Derived2())) return "Fail #3"
return "OK"
}
@@ -0,0 +1,41 @@
// Changed when traits were introduced. May not make sense any more
open class X(val x : Int) {}
trait Y {
abstract val y : Int
}
class YImpl(override val y : Int) : Y {}
class Point(x : Int, yy : Int) : X(x) , Y {
override val y : Int = yy
}
trait Abstract {}
class P1(x : Int, yy : Y) : Abstract, X(x), Y by yy {}
class P2(x : Int, yy : Y) : X(x), Abstract, Y by yy {}
class P3(x : Int, yy : Y) : X(x), Y by yy, Abstract {}
class P4(x : Int, yy : Y) : Y by yy, Abstract, X(x) {}
fun box() : String {
if (X(239).x != 239) return "FAIL #1"
if (YImpl(239).y != 239) return "FAIL #2"
val p = Point(240, -1)
if (p.x + p.y != 239) return "FAIL #3"
val y = YImpl(-1)
val p1 = P1(240, y)
if (p1.x + p1.y != 239) return "FAIL #4"
val p2 = P2(240, y)
if (p2.x + p2.y != 239) return "FAIL #5"
val p3 = P3(240, y)
if (p3.x + p3.y != 239) return "FAIL #6"
val p4 = P4(240, y)
if (p4.x + p4.y != 239) return "FAIL #7"
return "OK"
}
@@ -0,0 +1,14 @@
class Outer() {
open inner class InnerBase() {
}
inner class InnerDerived(): InnerBase() {
}
public val foo: InnerBase? = InnerDerived()
}
fun box() : String {
val o = Outer()
return if (o.foo === null) "fail" else "OK"
}
@@ -0,0 +1,13 @@
open class Foo {
fun xyzzy(): String = "xyzzy"
}
class Bar(): Foo() {
fun test(): String = xyzzy()
}
fun box() : String {
val bar = Bar()
val f = bar.test()
return if (f == "xyzzy") "OK" else "fail"
}
@@ -0,0 +1,13 @@
class C() {
public var f: Int
{
$f = 610
}
}
fun box(): String {
val c = C()
if (c.f != 610) return "fail"
return "OK"
}
@@ -0,0 +1,20 @@
import java.util.*
import java.io.*
class World() {
public val items: ArrayList<Item> = ArrayList<Item>()
inner class Item() {
{
items.add(this)
}
}
val foo = Item()
}
fun box() : String {
val w = World()
if (w.items.size() != 1) return "fail"
return "OK"
}
@@ -0,0 +1,19 @@
class Outer(val foo: StringBuilder) {
inner class Inner() {
fun len() : Int {
return foo.length()
}
}
fun test() : Inner {
return Inner()
}
}
fun box() : String {
val sb = StringBuilder("xyzzy")
val o = Outer(sb)
val i = o.test()
val l = i.len()
return if (l != 5) "fail" else "OK"
}
@@ -0,0 +1,12 @@
public class StockMarketTableModel() {
public fun getColumnCount() : Int {
return COLUMN_TITLES?.size!!
}
class object {
private val COLUMN_TITLES : Array<Int?> = arrayOfNulls<Int>(10)
}
}
fun box() : String = if(StockMarketTableModel().getColumnCount()==10) "OK" else "fail"
@@ -0,0 +1,14 @@
object RefreshQueue {
val workerThread: Thread = Thread(object : Runnable {
override fun run() {
val a = workerThread
val b = RefreshQueue.workerThread
if (a != b) throw AssertionError()
}
})
}
fun box() : String {
RefreshQueue.workerThread.run()
return "OK"
}
@@ -0,0 +1,7 @@
public class SomeClass() : java.lang.Object() {
}
public fun box():String {
System.out?.println(SomeClass().getClass())
return "OK"
}
@@ -0,0 +1,28 @@
public object SomeClass {
var bug: Any = ""
private val workerThread = object : Thread() {
override fun run() {
try {
foo()
bug = "none"
}
catch(t: Throwable) {
bug = t
}
}
}
{
workerThread.start()
}
private fun foo() : Unit {
}
}
public fun box():String {
if(SomeClass.bug is Throwable)
throw SomeClass.bug as Throwable
return "OK"
}
@@ -0,0 +1,6 @@
fun f(a : Int?, b : Int.(Int)->Int) = a?.b(1)
fun box(): String {
val x = f(1) { this+it+2 }
return if (x == 4) "OK" else "fail"
}
@@ -0,0 +1,13 @@
trait Creator<T> {
fun create() : T
}
class Actor(val code: String = "OK")
trait Factory : Creator<Actor>
class MyFactory() : Factory {
override fun create(): Actor = Actor()
}
fun box() : String = MyFactory().create().code
@@ -0,0 +1,17 @@
class MyClass(var fnc : () -> String) {
fun test(): String {
return fnc()
}
}
fun printtest() : String {
return "OK"
}
fun box(): String {
var c = MyClass({ printtest() })
return c.test()
}

Some files were not shown because too many files have changed in this diff Show More