diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index d57ffc71554..e3fb13cb5ba 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -464,11 +464,66 @@ task boxing0(type: RunKonanTest) { source = "codegen/boxing/boxing0.kt" } -task boxing1 (type:RunKonanTest) { - disabled = true +task boxing1(type: RunKonanTest) { + goldValue = "1\nfalse\nHello\n" source = "codegen/boxing/boxing1.kt" } +task boxing2(type: RunKonanTest) { + goldValue = "1\ntrue\nother\n" + source = "codegen/boxing/boxing2.kt" +} + +task boxing3(type: RunKonanTest) { + goldValue = "42\n" + source = "codegen/boxing/boxing3.kt" +} + +task boxing4(type: RunKonanTest) { + goldValue = "16\n" + source = "codegen/boxing/boxing4.kt" +} + +task boxing5(type: RunKonanTest) { + goldValue = "16\n42\n" + source = "codegen/boxing/boxing5.kt" +} + +task boxing6(type: RunKonanTest) { + goldValue = "42\n16\n" + source = "codegen/boxing/boxing6.kt" +} + +task boxing7(type: RunKonanTest) { + goldValue = "1\n0\n" + source = "codegen/boxing/boxing7.kt" +} + +task boxing8(type: RunKonanTest) { + goldValue = "1\n\ntrue\nHello\n" + source = "codegen/boxing/boxing8.kt" +} + +task boxing9(type: RunKonanTest) { + goldValue = "1\n\ntrue\nHello\n2\n\ntrue\nHello\n3\n" + source = "codegen/boxing/boxing9.kt" +} + +task boxing10(type: RunKonanTest) { + goldValue = "Ok\n" + source = "codegen/boxing/boxing10.kt" +} + +task boxing11(type: RunKonanTest) { + goldValue = "17\n42\n" + source = "codegen/boxing/boxing11.kt" +} + +task boxing12(type: RunKonanTest) { + goldValue = "18\n" + source = "codegen/boxing/boxing12.kt" +} + task interface0(type: RunKonanTest) { goldValue = "PASSED\n" source = "runtime/basic/interface0.kt" diff --git a/backend.native/tests/codegen/boxing/boxing10.kt b/backend.native/tests/codegen/boxing/boxing10.kt new file mode 100644 index 00000000000..38969157078 --- /dev/null +++ b/backend.native/tests/codegen/boxing/boxing10.kt @@ -0,0 +1,9 @@ +fun main(args: Array) { + val FALSE: Boolean? = false + + if (FALSE != null) { + do { + println("Ok") + } while (FALSE) + } +} \ No newline at end of file diff --git a/backend.native/tests/codegen/boxing/boxing11.kt b/backend.native/tests/codegen/boxing/boxing11.kt new file mode 100644 index 00000000000..c61e4bfb315 --- /dev/null +++ b/backend.native/tests/codegen/boxing/boxing11.kt @@ -0,0 +1,12 @@ +fun printInt(x: Int) = println(x) + +class Foo(val value: Int?) { + fun foo() { + printInt(if (value != null) value else 42) + } +} + +fun main(args: Array) { + Foo(17).foo() + Foo(null).foo() +} \ No newline at end of file diff --git a/backend.native/tests/codegen/boxing/boxing12.kt b/backend.native/tests/codegen/boxing/boxing12.kt new file mode 100644 index 00000000000..631b01202b0 --- /dev/null +++ b/backend.native/tests/codegen/boxing/boxing12.kt @@ -0,0 +1,7 @@ +fun foo(x: Number) { + println(x.toByte()) +} + +fun main(args: Array) { + foo(18) +} \ No newline at end of file diff --git a/backend.native/tests/codegen/boxing/boxing2.kt b/backend.native/tests/codegen/boxing/boxing2.kt new file mode 100644 index 00000000000..eba3ae6c41b --- /dev/null +++ b/backend.native/tests/codegen/boxing/boxing2.kt @@ -0,0 +1,17 @@ +fun printInt(x: Int) = println(x) +fun printBoolean(x: Boolean) = println(x) + +fun foo(arg: Any) { + if (arg is Int) + printInt(arg) + else if (arg is Boolean) + printBoolean(arg) + else + println("other") +} + +fun main(args: Array) { + foo(1) + foo(true) + foo("Hello") +} \ No newline at end of file diff --git a/backend.native/tests/codegen/boxing/boxing3.kt b/backend.native/tests/codegen/boxing/boxing3.kt new file mode 100644 index 00000000000..c478a0b6875 --- /dev/null +++ b/backend.native/tests/codegen/boxing/boxing3.kt @@ -0,0 +1,10 @@ +fun printInt(x: Int) = println(x) + +fun foo(arg: Int?) { + if (arg != null) + printInt(arg) +} + +fun main(args: Array) { + foo(42) +} \ No newline at end of file diff --git a/backend.native/tests/codegen/boxing/boxing4.kt b/backend.native/tests/codegen/boxing/boxing4.kt new file mode 100644 index 00000000000..0874d210e66 --- /dev/null +++ b/backend.native/tests/codegen/boxing/boxing4.kt @@ -0,0 +1,10 @@ +fun printInt(x: Int) = println(x) + +fun foo(arg: Any?) { + if (arg is Int? && arg != null) + printInt(arg) +} + +fun main(args: Array) { + foo(16) +} \ No newline at end of file diff --git a/backend.native/tests/codegen/boxing/boxing5.kt b/backend.native/tests/codegen/boxing/boxing5.kt new file mode 100644 index 00000000000..1efc3114287 --- /dev/null +++ b/backend.native/tests/codegen/boxing/boxing5.kt @@ -0,0 +1,10 @@ +fun printInt(x: Int) = println(x) + +fun foo(arg: Int?) { + printInt(arg ?: 16) +} + +fun main(args: Array) { + foo(null) + foo(42) +} \ No newline at end of file diff --git a/backend.native/tests/codegen/boxing/boxing6.kt b/backend.native/tests/codegen/boxing/boxing6.kt new file mode 100644 index 00000000000..7d0a4d47115 --- /dev/null +++ b/backend.native/tests/codegen/boxing/boxing6.kt @@ -0,0 +1,10 @@ +fun printInt(x: Int) = println(x) + +fun foo(arg: Any) { + printInt(arg as? Int ?: 16) +} + +fun main(args: Array) { + foo(42) + foo("Hello") +} \ No newline at end of file diff --git a/backend.native/tests/codegen/boxing/boxing7.kt b/backend.native/tests/codegen/boxing/boxing7.kt new file mode 100644 index 00000000000..4230eb31fb8 --- /dev/null +++ b/backend.native/tests/codegen/boxing/boxing7.kt @@ -0,0 +1,15 @@ +fun printInt(x: Int) = println(x) + +fun foo(arg: Any) { + val argAsInt = try { + arg as Int + } catch (e: ClassCastException) { + 0 + } + printInt(argAsInt) +} + +fun main(args: Array) { + foo(1) + foo("Hello") +} \ No newline at end of file diff --git a/backend.native/tests/codegen/boxing/boxing8.kt b/backend.native/tests/codegen/boxing/boxing8.kt new file mode 100644 index 00000000000..e176cadf932 --- /dev/null +++ b/backend.native/tests/codegen/boxing/boxing8.kt @@ -0,0 +1,9 @@ +fun foo(vararg args: Any?) { + for (arg in args) { + println(arg.toString()) + } +} + +fun main(args: Array) { + foo(1, null, true, "Hello") +} \ No newline at end of file diff --git a/backend.native/tests/codegen/boxing/boxing9.kt b/backend.native/tests/codegen/boxing/boxing9.kt new file mode 100644 index 00000000000..32fb9aa9e37 --- /dev/null +++ b/backend.native/tests/codegen/boxing/boxing9.kt @@ -0,0 +1,13 @@ +fun foo(vararg args: Any?) { + for (arg in args) { + println(arg.toString()) + } +} + +fun bar(vararg args: Any?) { + foo(1, *args, 2, *args, 3) +} + +fun main(args: Array) { + bar(null, true, "Hello") +} \ No newline at end of file