Add trivial tests for KType and typeOf

More tests are available as external.
This commit is contained in:
Svyatoslav Scherbina
2019-06-18 11:42:00 +03:00
committed by SvyatoslavScherbina
parent b1c9487215
commit 3d6d8b4d6b
2 changed files with 62 additions and 0 deletions
+4
View File
@@ -1520,6 +1520,10 @@ task kclassEnumArgument(type: KonanLocalTest) {
source = "codegen/kclass/kClassEnumArgument.kt"
}
task ktype1(type: KonanLocalTest) {
source = "codegen/ktype/ktype1.kt"
}
task associatedObjects1(type: KonanLocalTest) {
source = "codegen/associatedObjects/associatedObjects1.kt"
}
@@ -0,0 +1,58 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.ktype.ktype1
import kotlin.test.*
import kotlin.reflect.*
@UseExperimental(ExperimentalStdlibApi::class)
inline fun <reified R> kType() = typeOf<R>()
inline fun <reified R> kType(obj: R) = kType<R>()
class C<T>
class D
fun <T> kTypeForCWithTypeParameter() = kType<C<T>>()
class Outer<T> {
companion object Friend
inner class Inner<S>
}
object Object
private val pkg = "codegen.ktype.ktype1"
@Test
fun testBasics1() {
assertEquals("$pkg.C<kotlin.Int?>", kType<C<Int?>>().toString())
assertEquals("$pkg.C<$pkg.C<kotlin.Any>>", kType<C<C<Any>>>().toString())
assertEquals("$pkg.C<kotlin.Any?>", kTypeForCWithTypeParameter<D>().toString())
assertEquals("$pkg.Object", kType<Object>().toString())
assertEquals("$pkg.Outer.Friend", kType<Outer.Friend>().toString())
}
@Test
fun testInner() {
val innerKType = kType<Outer<D>.Inner<String>>()
assertEquals(Outer.Inner::class, innerKType.classifier)
assertEquals(String::class, innerKType.arguments.first().type!!.classifier)
assertEquals(D::class, innerKType.arguments.last().type!!.classifier)
}
@Test
fun testAnonymousObject() {
val obj = object {}
val objType = kType(obj)
assertEquals("(non-denotable type)", objType.toString())
assertEquals(obj::class, objType.classifier)
assertTrue(objType.arguments.isEmpty())
assertFalse(objType.isMarkedNullable)
}