Skip to content

Commit

Permalink
[K2] Fix the test `kotlin_Enum should not have obvious members via ex…
Browse files Browse the repository at this point in the history
…ternal documentable provider` for jdk >=18
  • Loading branch information
vmishenev committed Apr 15, 2024
1 parent cbb8314 commit d00e4b1
Showing 1 changed file with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.jetbrains.dokka.analysis.test.documentable

import org.jetbrains.dokka.analysis.test.OnlyDescriptors
import org.jetbrains.dokka.analysis.test.OnlySymbols
import org.jetbrains.dokka.analysis.test.api.kotlinJvmTestProject
import org.jetbrains.dokka.analysis.test.api.parse
import org.jetbrains.dokka.analysis.test.api.useServices
Expand Down Expand Up @@ -106,7 +107,7 @@ class ObviousFunctionsTest {
// when running with K2 there is no equals, hashCode, toString present
@OnlyDescriptors("#3196")
@Test
fun `kotlin_Enum should not have obvious members via external documentable provider`() {
fun `K1 - kotlin_Enum should not have obvious members via external documentable provider`() {
val project = kotlinJvmTestProject {
ktFile("SomeClass.kt") {
+"class SomeClass"
Expand All @@ -128,7 +129,8 @@ class ObviousFunctionsTest {

// inherited from java enum
val jdkEnumInheritedFunctions = when {
// starting from JDK 18, 'finalize' is not available (finalization is deprecated in JDK 18)
// starting from JDK 18,
// In K1 'finalize' is not available, but in K2 it is deprecated (finalization is deprecated in JDK 18)
javaVersion >= 18 -> setOf("clone", "getDeclaringClass", "describeConstable")
// starting from JDK 12, there is a new member in enum 'describeConstable'
javaVersion >= 12 -> setOf("clone", "getDeclaringClass", "describeConstable", "finalize")
Expand All @@ -144,6 +146,47 @@ class ObviousFunctionsTest {
}
}

@OnlySymbols("In K2 there is finalize method with the Deprecated annotation. In K1 it is unavailable")
@Test
fun `K2 - kotlin_Enum should not have obvious members via external documentable provider`() {
val project = kotlinJvmTestProject {
ktFile("SomeClass.kt") {
+"class SomeClass"
}
}

project.useServices {
val enum = externalDocumentableProvider.getClasslike(
DRI("kotlin", "Enum"),
it.context.configuration.sourceSets.single()
)
assertNotNull(enum)
assertEquals("Enum", enum.name)

val javaVersion = when (val specVersion = System.getProperty("java.specification.version")) {
"1.8" -> 8
else -> specVersion.toInt()
}

// inherited from java enum
val jdkEnumInheritedFunctions = when {
// starting from JDK 18,
// In K1 'finalize' is not available, but in K2 it is deprecated (finalization is deprecated in JDK 18)
javaVersion >= 18 -> setOf("clone", "getDeclaringClass", "describeConstable", "finalize")
// starting from JDK 12, there is a new member in enum 'describeConstable'
javaVersion >= 12 -> setOf("clone", "getDeclaringClass", "describeConstable", "finalize")
else -> setOf("clone", "getDeclaringClass", "finalize")
}

assertObviousFunctions(
expectedObviousFunctions = emptySet(),
expectedNonObviousFunctions = setOf("compareTo", "equals", "hashCode", "toString") +
jdkEnumInheritedFunctions,
actualFunctions = enum.functions
)
}
}

@Test
fun `should mark only toString, equals and hashcode as obvious for class`() {
val project = kotlinJvmTestProject {
Expand Down

0 comments on commit d00e4b1

Please sign in to comment.