Minor: move function expression tests to separate directory
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
val foo1 = fun Any.(): String {
|
||||
return "239" + this
|
||||
}
|
||||
|
||||
val foo2 = fun Int.(i : Int) : Int = this + i
|
||||
|
||||
fun <T> fooT1() = fun (t : T) = t.toString()
|
||||
|
||||
annotation class A
|
||||
|
||||
fun box() : String {
|
||||
if(10.foo1() != "23910") return "foo1 fail"
|
||||
if(10.foo2(1) != 11) return "foo2 fail"
|
||||
|
||||
if(1.(fun Int.() = this + 1)() != 2) return "test 3 failed";
|
||||
if( (fun () = 1)() != 1) return "test 4 failed";
|
||||
if( (fun (i: Int) = i)(1) != 1) return "test 5 failed";
|
||||
if( 1.(fun Int.(i: Int) = i + this)(1) != 2) return "test 6 failed";
|
||||
if( (fooT1<String>()("mama")) != "mama") return "test 7 failed";
|
||||
|
||||
val a = [A] fun Int.() = this + 1 //
|
||||
if (1.a() != 2) return "test 8 failed"
|
||||
val b = ( fun Int.() = this + 1)
|
||||
if (1.a() != 2) return "test 9 failed"
|
||||
val c = (@c fun Int.() = this + 1)
|
||||
if (1.a() != 2) return "test 10 failed"
|
||||
|
||||
val d = @d fun (): Int { return@d 4}
|
||||
if (d() != 4) return "test 11 failed"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
val foo1 = fun Any.name(): String {
|
||||
return "239" + this
|
||||
}
|
||||
|
||||
val foo2 = fun Int.name(i : Int) : Int = this + i
|
||||
|
||||
fun <T> fooT1() = fun name(t : T) = t.toString()
|
||||
|
||||
annotation class A
|
||||
|
||||
fun box() : String {
|
||||
if(10.foo1() != "23910") return "foo1 fail"
|
||||
if(10.foo2(1) != 11) return "foo2 fail"
|
||||
|
||||
if(1.(fun Int.name() = this + 1)() != 2) return "test 3 failed";
|
||||
if( (fun name() = 1)() != 1) return "test 4 failed";
|
||||
if( (fun name(i: Int) = i)(1) != 1) return "test 5 failed";
|
||||
if( 1.(fun Int.name(i: Int) = i + this)(1) != 2) return "test 6 failed";
|
||||
if( (fooT1<String>()("mama")) != "mama") return "test 7 failed";
|
||||
|
||||
val a = [A] fun Int.name() = this + 1 // name
|
||||
if (1.a() != 2) return "test 8 failed"
|
||||
val b = ( fun Int.name() = this + 1)
|
||||
if (1.a() != 2) return "test 9 failed"
|
||||
val c = (@c fun Int.name() = this + 1)
|
||||
if (1.a() != 2) return "test 10 failed"
|
||||
|
||||
val d = fun name(): Int { return@name 4}
|
||||
if (d() != 4) return "test 11 failed"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
|
||||
fun Int.thisRef1() = fun () = this
|
||||
fun Int.thisRef2() = fun (): Int {return this}
|
||||
|
||||
fun <T> T.genericThisRef1() = fun () = this
|
||||
fun <T> T.genericThisRef2() = fun (): T {return this}
|
||||
|
||||
val Int.valThisRef1: () -> Int get() = fun () = this
|
||||
val Int.valThisRef2: () -> Int get() = fun (): Int {return this}
|
||||
|
||||
val <T> T.valGenericThisRef1: ()->T get() = fun () = this
|
||||
val <T> T.valGenericThisRef2: ()->T get() = fun (): T {return this}
|
||||
|
||||
val <T> T.withLabel1: ()->T get() = fun () = this@withLabel1
|
||||
val <T> T.withLabel2: ()->T get() = fun (): T {return this@withLabel2}
|
||||
|
||||
fun box(): String {
|
||||
if (1.thisRef1()() != 1) return "Test 1 failed"
|
||||
if (2.thisRef2()() != 2) return "Test 2 failed"
|
||||
|
||||
if (3.genericThisRef1()() != 3) return "Test 3 failed"
|
||||
if (4.genericThisRef2()() != 4) return "Test 4 failed"
|
||||
|
||||
if (5.valThisRef1() != 5) return "Test 5 failed"
|
||||
if (6.valThisRef2() != 6) return "Test 6 failed"
|
||||
|
||||
if (7.valGenericThisRef1() != 7) return "Test 7 failed"
|
||||
if (8.valGenericThisRef2() != 8) return "Test 8 failed"
|
||||
|
||||
if ("bar".withLabel1() != "bar") return "Test 9 failed"
|
||||
if ("bar".withLabel2() != "bar") return "Test 10 failed"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
fun Any.foo1() : ()-> String {
|
||||
return { "239" + this }
|
||||
}
|
||||
|
||||
fun Int.foo2() : (i : Int) -> Int {
|
||||
return { x -> x + this }
|
||||
}
|
||||
|
||||
fun fooT1<T>(t : T) = { t.toString() }
|
||||
|
||||
fun fooT2<T>(t: T) = { x:T -> t.toString() + x.toString() }
|
||||
|
||||
fun box() : String {
|
||||
if( (10.foo1())() != "23910") return "foo1 fail"
|
||||
if( (10.foo2())(1) != 11 ) return "foo2 fail"
|
||||
|
||||
if(1.(fun Int.() = this + 1)() != 2) return "test 3 failed";
|
||||
if( {1}() != 1) return "test 4 failed";
|
||||
if( {x : Int -> x}(1) != 1) return "test 5 failed";
|
||||
if( 1.(fun Int.(x: Int) = x + this)(1) != 2) return "test 6 failed";
|
||||
if( 1.(fun Int.() = this)() != 1) return "test 7 failed";
|
||||
if( (fooT1<String>("mama"))() != "mama") return "test 8 failed";
|
||||
if( (fooT2<String>("mama"))("papa") != "mamapapa") return "test 9 failed";
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user