From c5a31b47ef182e4de3ec58d5ce5624e65fe11015 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Thu, 15 Oct 2020 18:11:17 +0200 Subject: Fix class cast exception when creating the ancestry tree --- plugins/base/src/test/kotlin/model/ClassesTest.kt | 62 +++++++++++++++++------ 1 file changed, 47 insertions(+), 15 deletions(-) (limited to 'plugins/base/src/test') diff --git a/plugins/base/src/test/kotlin/model/ClassesTest.kt b/plugins/base/src/test/kotlin/model/ClassesTest.kt index bb7bac2d..b6787126 100644 --- a/plugins/base/src/test/kotlin/model/ClassesTest.kt +++ b/plugins/base/src/test/kotlin/model/ClassesTest.kt @@ -460,32 +460,40 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class } } - @Test fun genericAnnotationClass() { + @Test + fun genericAnnotationClass() { inlineModelTest( """annotation class Foo() {}""" ) { - with((this / "classes" / "Foo").cast()){ - generics.map { it.name to it.bounds.first().name } equals listOf("A" to "Any", "B" to "Any", "C" to "Any", "D" to "Number") + with((this / "classes" / "Foo").cast()) { + generics.map { it.name to it.bounds.first().name } equals listOf( + "A" to "Any", + "B" to "Any", + "C" to "Any", + "D" to "Number" + ) } } } - @Test fun nestedGenericClasses(){ + @Test + fun nestedGenericClasses() { inlineModelTest( """ |class Outer { | inner class Inner { } |} """.trimMargin() - ){ - with((this / "classes" / "Outer").cast()){ + ) { + with((this / "classes" / "Outer").cast()) { val inner = classlikes.single().cast() inner.generics.map { it.name to it.bounds.first().name } equals listOf("INNER" to "Any", "T" to "OUTER") } } } - @Test fun allImplementedInterfaces() { + @Test + fun allImplementedInterfaces() { inlineModelTest( """ | interface Highest { } @@ -494,14 +502,16 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class | interface LowerImplInterface: Lower { } | class Tested : HighestImpl(), LowerImplInterface { } """.trimIndent() - ){ - with((this / "classes" / "Tested").cast()){ - extra[ImplementedInterfaces]?.interfaces?.entries?.single()?.value?.map { it.dri.sureClassNames }?.sorted() equals listOf("Highest", "Lower", "LowerImplInterface").sorted() + ) { + with((this / "classes" / "Tested").cast()) { + extra[ImplementedInterfaces]?.interfaces?.entries?.single()?.value?.map { it.dri.sureClassNames } + ?.sorted() equals listOf("Highest", "Lower", "LowerImplInterface").sorted() } } } - @Test fun multipleClassInheritance() { + @Test + fun multipleClassInheritance() { inlineModelTest( """ | open class A { } @@ -515,7 +525,8 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class } } - @Test fun multipleClassInheritanceWithInterface(){ + @Test + fun multipleClassInheritanceWithInterface() { inlineModelTest( """ | open class A { } @@ -524,10 +535,31 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class | interface Y : X { } | class Tested : B(), Y { } """.trimIndent() - ){ + ) { with((this / "classes" / "Tested").cast()) { - supertypes.entries.single().value.map { it.typeConstructor.dri.sureClassNames to it.kind }.sortedBy { it.first } equals listOf("B" to KotlinClassKindTypes.CLASS, "Y" to KotlinClassKindTypes.INTERFACE) + supertypes.entries.single().value.map { it.typeConstructor.dri.sureClassNames to it.kind } + .sortedBy { it.first } equals listOf( + "B" to KotlinClassKindTypes.CLASS, + "Y" to KotlinClassKindTypes.INTERFACE + ) + } + } + } + + @Test + fun doublyTypealiasedException() { + inlineModelTest( + """ + | typealias B = RuntimeException + | typealias A = B + """.trimMargin() + ) { + with((this / "classes" / "A").cast()) { + extra[ExceptionInSupertypes].assertNotNull("Typealias A should have ExceptionInSupertypes in its extra field") + } + with((this / "classes" / "B").cast()) { + extra[ExceptionInSupertypes].assertNotNull("Typealias B should have ExceptionInSupertypes in its extra field") } } } -} \ No newline at end of file +} -- cgit