mirror of
https://github.com/apple/pkl.git
synced 2026-04-21 16:01:31 +02:00
This reverts commit 7f404fff49.
The package is derived from the module name.
Having `module com.example.Foo` in Pkl
will create Kotlin `package com.example`.
Eventually, we may want to introduce a way to map
Pkl names to package names that provides finer
controls to the code generator.
This commit is contained in:
@@ -133,8 +133,7 @@ class KotlinCodeGeneratorTest {
|
||||
pklCode: String,
|
||||
generateKdoc: Boolean = false,
|
||||
generateSpringBootConfig: Boolean = false,
|
||||
implementSerializable: Boolean = false,
|
||||
kotlinPackage: String? = null,
|
||||
implementSerializable: Boolean = false
|
||||
): String {
|
||||
|
||||
val module = Evaluator.preconfigured().evaluateSchema(ModuleSource.text(pklCode))
|
||||
@@ -145,8 +144,7 @@ class KotlinCodeGeneratorTest {
|
||||
KotlinCodegenOptions(
|
||||
generateKdoc = generateKdoc,
|
||||
generateSpringBootConfig = generateSpringBootConfig,
|
||||
implementSerializable = implementSerializable,
|
||||
kotlinPackage = kotlinPackage ?: "",
|
||||
implementSerializable = implementSerializable
|
||||
)
|
||||
)
|
||||
return generator.kotlinFile
|
||||
@@ -555,92 +553,6 @@ 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