mirror of
https://github.com/apple/pkl.git
synced 2026-03-28 03:51:14 +01:00
Add setting for Kotlin package to codegen (#194)
This commit is contained in:
@@ -133,7 +133,8 @@ class KotlinCodeGeneratorTest {
|
||||
pklCode: String,
|
||||
generateKdoc: Boolean = false,
|
||||
generateSpringBootConfig: Boolean = false,
|
||||
implementSerializable: Boolean = false
|
||||
implementSerializable: Boolean = false,
|
||||
kotlinPackage: String? = null,
|
||||
): String {
|
||||
|
||||
val module = Evaluator.preconfigured().evaluateSchema(ModuleSource.text(pklCode))
|
||||
@@ -144,7 +145,8 @@ class KotlinCodeGeneratorTest {
|
||||
KotlinCodegenOptions(
|
||||
generateKdoc = generateKdoc,
|
||||
generateSpringBootConfig = generateSpringBootConfig,
|
||||
implementSerializable = implementSerializable
|
||||
implementSerializable = implementSerializable,
|
||||
kotlinPackage = kotlinPackage ?: "",
|
||||
)
|
||||
)
|
||||
return generator.kotlinFile
|
||||
@@ -553,6 +555,92 @@ class KotlinCodeGeneratorTest {
|
||||
assertCompilesSuccessfully(kotlinCode)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `custom kotlin package prefix`() {
|
||||
val kotlinCode =
|
||||
generateKotlinCode(
|
||||
"""
|
||||
module my.mod
|
||||
|
||||
class Person {
|
||||
name: String
|
||||
age: Int
|
||||
hobbies: List<String>
|
||||
friends: Map<String, Person>
|
||||
sibling: Person?
|
||||
}
|
||||
""",
|
||||
kotlinPackage = "cool.pkg.path",
|
||||
)
|
||||
|
||||
assertEqualTo(
|
||||
"""
|
||||
package cool.pkg.path.my
|
||||
|
||||
import kotlin.Long
|
||||
import kotlin.String
|
||||
import kotlin.collections.List
|
||||
import kotlin.collections.Map
|
||||
|
||||
object Mod {
|
||||
data class Person(
|
||||
val name: String,
|
||||
val age: Long,
|
||||
val hobbies: List<String>,
|
||||
val friends: Map<String, Person>,
|
||||
val sibling: Person?
|
||||
)
|
||||
}
|
||||
""",
|
||||
kotlinCode
|
||||
)
|
||||
|
||||
assertCompilesSuccessfully(kotlinCode)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `empty kotlin package prefix`() {
|
||||
val kotlinCode =
|
||||
generateKotlinCode(
|
||||
"""
|
||||
module my.mod
|
||||
|
||||
class Person {
|
||||
name: String
|
||||
age: Int
|
||||
hobbies: List<String>
|
||||
friends: Map<String, Person>
|
||||
sibling: Person?
|
||||
}
|
||||
""",
|
||||
kotlinPackage = "",
|
||||
)
|
||||
|
||||
assertEqualTo(
|
||||
"""
|
||||
package my
|
||||
|
||||
import kotlin.Long
|
||||
import kotlin.String
|
||||
import kotlin.collections.List
|
||||
import kotlin.collections.Map
|
||||
|
||||
object Mod {
|
||||
data class Person(
|
||||
val name: String,
|
||||
val age: Long,
|
||||
val hobbies: List<String>,
|
||||
val friends: Map<String, Person>,
|
||||
val sibling: Person?
|
||||
)
|
||||
}
|
||||
""",
|
||||
kotlinCode
|
||||
)
|
||||
|
||||
assertCompilesSuccessfully(kotlinCode)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `recursive types`() {
|
||||
val kotlinCode =
|
||||
|
||||
Reference in New Issue
Block a user