mirror of
https://github.com/apple/pkl.git
synced 2026-08-26 21:54:03 +02:00
Sanitize block comment endings in generated Kotlin doc comments (#1830)
This commit is contained in:
@@ -2261,6 +2261,24 @@ class JavaCodeGeneratorTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `block comment escaping in doc comments`() {
|
||||
val javaCode =
|
||||
generateJavaCode(
|
||||
"""
|
||||
module my.mod
|
||||
class Person {
|
||||
/// This doc coment needs */ escaping
|
||||
foo: Int
|
||||
}
|
||||
"""
|
||||
.trimIndent(),
|
||||
JavaCodeGeneratorOptions(generateJavadoc = true),
|
||||
)
|
||||
|
||||
assertThat(javaCode).compilesSuccessfully().contains("*/")
|
||||
}
|
||||
|
||||
private fun Map<String, String>.validateContents(
|
||||
@Suppress("RemoveRedundantQualifierName") vararg assertions: kotlin.Pair<String, List<String>>
|
||||
) {
|
||||
|
||||
@@ -609,7 +609,7 @@ class KotlinCodeGenerator(
|
||||
|
||||
// do the minimum work necessary to avoid kotlin compile errors
|
||||
// generating idiomatic KDoc would require parsing doc comments, converting member links, etc.
|
||||
private fun renderAsKdoc(docComment: String): String = docComment
|
||||
private fun renderAsKdoc(docComment: String): String = docComment.replace("*/", "*/")
|
||||
|
||||
private fun PClass.toKotlinPoetName(): ClassName {
|
||||
val (packageName, moduleTypeName) = nameMapper.map(moduleName)
|
||||
|
||||
@@ -2054,6 +2054,23 @@ class KotlinCodeGeneratorTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `block comment escaping in doc comments`() {
|
||||
val kotlinCode =
|
||||
generateKotlinCode(
|
||||
"""
|
||||
class Person {
|
||||
/// This doc coment needs */ escaping
|
||||
foo: Int
|
||||
}
|
||||
"""
|
||||
.trimIndent(),
|
||||
generateKdoc = true,
|
||||
)
|
||||
|
||||
assertThat(kotlinCode).compilesSuccessfully().contains("*/")
|
||||
}
|
||||
|
||||
private fun Map<String, String>.validateContents(
|
||||
@Suppress("RemoveRedundantQualifierName") vararg assertions: kotlin.Pair<String, List<String>>
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user