separate compiler and plugin tests

This commit is contained in:
Dmitry Jemerov
2011-10-20 16:19:02 +02:00
parent a80398098b
commit ec6dec0d37
586 changed files with 69 additions and 42 deletions
@@ -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,9 @@
class C() {
fun getInstance(): Runnable = C
class object: Runnable {
override fun run(): Unit { }
}
}
fun foo() = C().getInstance()
@@ -0,0 +1,13 @@
abstract open class Default {
abstract fun defaultValue(): Int
}
class MyInt() {
class object : Default {
override fun defaultValue(): Int = 610
}
}
fun toDefault<T: Any>(t: T) where class object T: Default = T.defaultValue()
fun box(): String = if (toDefault<MyInt>(MyInt()) == 610) "OK" else "fail"
@@ -0,0 +1,7 @@
fun box() : String {
return apply( "OK", {(arg: String) => arg } )
}
fun apply(arg : String, f : fun (p:String) : String) : String {
return f(arg)
}
@@ -0,0 +1,7 @@
fun box() : String {
return if (apply( 5, {(arg: Int) => arg + 13 } ) == 18) "OK" else "fail"
}
fun apply(arg : Int, f : fun (p:Int) : Int) : Int {
return f(arg)
}
@@ -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,8 @@
fun box() : String {
val cl = 39
return if (sum(200, { val ff = {cl}; ff() }) == 239) "OK" else "FAIL"
}
fun sum(arg:Int, f : fun () : Int) : Int {
return arg + f()
}
@@ -0,0 +1,8 @@
fun box() : String {
val cl = 39
return if (sum(200, { val m = { val r = { cl }; r() }; m() }) == 239) "OK" else "FAIL"
}
fun sum(arg:Int, f : fun () : Int) : Int {
return arg + f()
}
@@ -0,0 +1,12 @@
class Point(val x:Int, val y:Int) {
fun mul() : fun (scalar:Int):Point {
return { (scalar:Int):Point => Point(x * scalar, y * scalar) }
}
}
val m = Point(2, 3).mul() : fun (scalar:Int):Point
fun box() : String {
val answer = m(5)
return if (answer.x == 10 && answer.y == 15) "OK" else "FAIL"
}
@@ -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,13 @@
class Point(val x : Int, val y : Int)
fun box() : String {
val answer = apply(Point(3, 5), { Point.(scalar : Int) : Point =>
Point(x * scalar, y * scalar)
})
return if (answer.x == 6 && answer.y == 10) "OK" else "FAIL"
}
fun apply(arg:Point, f : fun Point.(scalar : Int) : Point) : Point {
return arg.f(2)
}
@@ -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 class InnerBase() {
}
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 @@
class Foo() : java.util.ArrayList<Int>()
@@ -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>
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) {
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,8 @@
class SimpleClass() {
fun foo() = 610
}
fun test() : Int {
val c = SimpleClass()
return c.foo()
}
@@ -0,0 +1,12 @@
class Outer() {
class Inner() {
val outer: Outer get() = this@Outer
}
public val x : Inner = Inner()
}
fun box() : String {
val o = Outer()
return if (o === o.x.outer) "OK" else "fail"
}
@@ -0,0 +1,25 @@
import java.util.*
class ArrayWrapper<T>() {
val contents = ArrayList<T>()
fun add(item: T) {
contents.add(item)
}
fun plus(b: ArrayWrapper<T>): ArrayWrapper<T> {
val result = ArrayWrapper<T>()
result.contents.addAll(contents)
result.contents.addAll(b.contents)
return result
}
}
fun box(): String {
val v1 = ArrayWrapper<String>()
val v2 = ArrayWrapper<String>()
v1.add("foo")
v2.add("bar")
val v3 = v1 + v2
return if (v3.contents.size() == 2) "OK" else "fail"
}
@@ -0,0 +1,26 @@
import java.util.*
class ArrayWrapper<T>() {
val contents = ArrayList<T>()
fun add(item: T) {
contents.add(item)
}
fun plusAssign(rhs: ArrayWrapper<T>) {
contents.addAll(rhs.contents)
}
fun get(index: Int): T {
return contents.get(index)
}
}
fun box(): String {
val v1 = ArrayWrapper<String>()
val v2 = ArrayWrapper<String>()
v1.add("foo")
v2.add("bar")
v1 += v2
return if (v1.contents.size() == 2) "OK" else "fail"
}
@@ -0,0 +1,30 @@
import java.util.*
class ArrayWrapper<T>() {
val contents = ArrayList<T>()
fun add(item: T) {
contents.add(item)
}
fun plusAssign(rhs: ArrayWrapper<T>): ArrayWrapper<T> {
val result = ArrayWrapper<T>()
result.contents.addAll(contents)
result.contents.addAll(rhs.contents)
return result
}
fun get(index: Int): T {
return contents.get(index)
}
}
fun box(): String {
val v1 = ArrayWrapper<String>()
val v2 = ArrayWrapper<String>()
v1.add("foo")
val v3 = v1
v2.add("bar")
v1 += v2
return if (v1.contents.size() == 2 && v3.contents.size() == 1) "OK" else "fail"
}
@@ -0,0 +1,30 @@
import java.util.*
class ArrayWrapper<T>() {
val contents = ArrayList<T>()
fun add(item: T) {
contents.add(item)
}
fun plus(rhs: ArrayWrapper<T>): ArrayWrapper<T> {
val result = ArrayWrapper<T>()
result.contents.addAll(contents)
result.contents.addAll(rhs.contents)
return result
}
fun get(index: Int): T {
return contents.get(index)
}
}
fun box(): String {
val v1 = ArrayWrapper<String>()
val v2 = ArrayWrapper<String>()
v1.add("foo")
val v3 = v1
v2.add("bar")
v1 += v2
return if (v1.contents.size() == 2 && v3.contents.size() == 1) "OK" else "fail"
}
@@ -0,0 +1,28 @@
import java.util.*
class ArrayWrapper<T>() {
val contents = ArrayList<T>()
fun add(item: T) {
contents.add(item)
}
fun minus(): ArrayWrapper<T> {
val result = ArrayWrapper<T>()
result.contents.addAll(contents)
Collections.reverse(result.contents)
return result
}
fun get(index: Int): T {
return contents.get(index)
}
}
fun box(): String {
val v1 = ArrayWrapper<String>()
v1.add("foo")
v1.add("bar")
val v2 = -v1
return if (v2[0] == "bar" && v2[1] == "foo") "OK" else "fail"
}
@@ -0,0 +1,33 @@
open class Base() {
val plain = 239
public val read : Int
get() = 239
public var readwrite : Int = 0
get() = $readwrite + 1
set(n : Int) {
$readwrite = n
}
}
trait Abstract {}
class Derived1() : Base(), Abstract {}
class Derived2() : Abstract, Base() {}
fun code(s : Base) : Int {
if (s.plain != 239) return 1
if (s.read != 239) return 2
s.readwrite = 238
if (s.readwrite != 239) return 3
return 0
}
fun test(s : Base) : Boolean = code(s) == 0
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,16 @@
class Outer() {
val s = "xyzzy"
open class InnerBase(public val name: String) {
}
class InnerDerived(): InnerBase(s) {
}
val x = InnerDerived()
}
fun box() : String {
val o = Outer()
return if (o.x.name != "xyzzy") "fail" else "OK"
}
@@ -0,0 +1,20 @@
// Changed when traits were introduced. May not make sense any more
trait Left {}
open class Right() {
open fun f() = 42
}
class D() : Left, Right() {
override fun f() = 239
}
fun box() : String {
val r : Right = Right()
val d : D = D()
if (r.f() != 42) return "Fail #1"
if (d.f() != 239) return "Fail #2"
return "OK"
}
@@ -0,0 +1,8 @@
class C(val n: Int, val s: String) {
this(n: Int): this(n, "foo") { }
}
fun box(): String {
val c = C(10)
return if (c.s == "foo") "OK" else "fail"
}
@@ -0,0 +1,8 @@
class Box<T>(t: T) {
var value = t
}
fun box(): String {
val box: Box<Int> = Box<Int>(1)
return if (box.value == 1) "OK" else "fail"
}
@@ -0,0 +1,5 @@
class SimpleClass {
fun foo() : Int {
return 0;
}
}
@@ -0,0 +1,7 @@
fun box() : String {
return invoker( {"OK"} )
}
fun invoker(gen : fun () : String) : String {
return gen()
}
@@ -0,0 +1,7 @@
fun box() : String {
return if (int_invoker( { 7 } ) == 7) "OK" else "fail"
}
fun int_invoker(gen : fun () : Int) : Int {
return gen()
}