From 3eec3da5113b311fac67aa8bcfb95405d3d12ad7 Mon Sep 17 00:00:00 2001 From: Konstantin Anisimov Date: Tue, 6 Dec 2016 16:28:31 +0300 Subject: [PATCH] TEST: tests for instanceof are modified to take in account null and nullable --- backend.native/tests/build.gradle | 3 +- .../tests/codegen/basics/check_type.kt | 43 +++++++------------ 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 4015e76f2c3..0b466d4f72b 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -252,7 +252,8 @@ task objectBasic(type: UnitKonanTest) { source = "codegen/klass/basic.kt" } -task check_type(type: UnitKonanTest) { +task check_type(type: RunKonanTest) { + goldValue = "true\nfalse\ntrue\ntrue\ntrue\ntrue\n" source = "codegen/basics/check_type.kt" } diff --git a/backend.native/tests/codegen/basics/check_type.kt b/backend.native/tests/codegen/basics/check_type.kt index fe21db31457..1a89a880c8b 100644 --- a/backend.native/tests/codegen/basics/check_type.kt +++ b/backend.native/tests/codegen/basics/check_type.kt @@ -4,13 +4,14 @@ class B() {} //-----------------------------------------------------------------------------// -fun isTypeOf(a: Any) : Boolean { +fun isTypeOf(a: Any?) : Boolean { return a is A } -fun check_type(): Boolean { - val a = A() - return isTypeOf(a) +//-----------------------------------------------------------------------------// + +fun isTypeNullableOf(a: Any?) : Boolean { + return a is A? } //-----------------------------------------------------------------------------// @@ -19,34 +20,20 @@ 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 -//} \ No newline at end of file +fun main(args: Array) { + + println(isTypeOf(A())) + println(isTypeOf(null)) + println(isTypeNullableOf(A())) + println(isTypeNullableOf(null)) + println(isNotTypeOf(B())) + println(isTypeOfInterface(A())) +}