TESTS: "for" and INSTANCEOF, NOT_INSTANCEOF, isInstanceOf on interface are added
This commit is contained in:
committed by
vvlevchenko
parent
3a49e69046
commit
c1bb762417
@@ -158,6 +158,10 @@ task fields(type: UnitKonanTest) {
|
||||
source = "$codegen/klass/basic.kt"
|
||||
} */
|
||||
|
||||
task check_type(type: UnitKonanTest) {
|
||||
source = "codegen/basics/check_type.kt"
|
||||
}
|
||||
|
||||
task aritmetic(type: UnitKonanTest) {
|
||||
source = "codegen/function/arithmetic.kt"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
|
||||
extern void *resolve_symbol(const char*);
|
||||
|
||||
int
|
||||
run_test() {
|
||||
int (*check_type)() = resolve_symbol("kfun:check_type()");
|
||||
int (*check_not_type)() = resolve_symbol("kfun:check_not_type()");
|
||||
int (*check_interface)() = resolve_symbol("kfun:check_interface()");
|
||||
|
||||
if (!check_type()) return 1;
|
||||
if (!check_not_type()) return 1;
|
||||
if (!check_interface()) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
interface I
|
||||
class A() : I {}
|
||||
class B() {}
|
||||
|
||||
//-----------------------------------------------------------------------------//
|
||||
|
||||
fun isTypeOf(a: Any) : Boolean {
|
||||
return a is A
|
||||
}
|
||||
|
||||
fun check_type(): Boolean {
|
||||
val a = A()
|
||||
return isTypeOf(a)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------//
|
||||
|
||||
fun isNotTypeOf(a: Any) : Boolean {
|
||||
return a !is A
|
||||
}
|
||||
|
||||
fun check_not_type(): Boolean {
|
||||
val b = B()
|
||||
return isNotTypeOf(b)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------//
|
||||
|
||||
fun isTypeOfInterface(a: Any) : Boolean {
|
||||
return a is I
|
||||
}
|
||||
|
||||
fun check_interface(): Boolean {
|
||||
val a = A()
|
||||
return isTypeOfInterface(a)
|
||||
}
|
||||
|
||||
//interface AI {
|
||||
// fun v():Int
|
||||
//}
|
||||
//
|
||||
//val global:Int = 1
|
||||
//class A1() : AI {
|
||||
// override fun v():Int = global
|
||||
//}
|
||||
//
|
||||
//fun smartCast(a:Any): Int {
|
||||
// if (a is AI) {
|
||||
// return a.v()
|
||||
// }
|
||||
// return 24
|
||||
//}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun cycle_for(arr: Array<Int>) : Int {
|
||||
var sum = 0
|
||||
for (i in arr) {
|
||||
sum += i
|
||||
}
|
||||
return sum
|
||||
}
|
||||
Reference in New Issue
Block a user