Test for getters/setters added

This commit is contained in:
Konstantin Anisimov
2016-11-15 16:36:48 +03:00
committed by vvlevchenko
parent f393dc3a03
commit f80697817e
5 changed files with 41 additions and 4 deletions
+8
View File
@@ -142,6 +142,14 @@ task sum (type:UnitKonanTest) {
source = "codegen/function/sum.kt"
}
task method_call(type: UnitKonanTest) {
source = "codegen/object/method_call.kt"
}
task fields(type: UnitKonanTest) {
source = "codegen/object/fields.kt"
}
/*task objectInitialization(type: UnitKonanTest) {
source = "codegen/object/initialization.kt"
}*/
@@ -0,0 +1,12 @@
extern void *resolve_symbol(const char*);
int
run_test() {
int (*globalTest)() = resolve_symbol("kfun:globalTest(Int)");
int (*getGlobal)() = resolve_symbol("kfun:<get-globalValue>()");
if (getGlobal() != 1) return 1;
if (globalTest(41) != 42) return 1;
if (getGlobal() != 42) return 1;
return 0;
}
@@ -1,6 +1,9 @@
class fields(a:Int) {
public val b:Int
get() = getB()
private var globalValue = 1
var global:Int
get() = globalValue
set(value:Int) {globalValue = value}
external fun getB():Int
fun globalTest(i:Int):Int {
global += i
return global
}
@@ -0,0 +1,9 @@
extern void *resolve_symbol(const char*);
int
run_test() {
int (*fortyTwo)() = resolve_symbol("kfun:fortyTwo()");
if (fortyTwo() != 42) return 1;
return 0;
}
@@ -0,0 +1,5 @@
class A(val a:Int) {
fun foo(i:Int) = a + i
}
fun fortyTwo() = A(41).foo(1)