mirror of
https://github.com/apple/pkl.git
synced 2026-08-29 06:57:19 +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(
|
private fun Map<String, String>.validateContents(
|
||||||
@Suppress("RemoveRedundantQualifierName") vararg assertions: kotlin.Pair<String, List<String>>
|
@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
|
// do the minimum work necessary to avoid kotlin compile errors
|
||||||
// generating idiomatic KDoc would require parsing doc comments, converting member links, etc.
|
// 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 {
|
private fun PClass.toKotlinPoetName(): ClassName {
|
||||||
val (packageName, moduleTypeName) = nameMapper.map(moduleName)
|
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(
|
private fun Map<String, String>.validateContents(
|
||||||
@Suppress("RemoveRedundantQualifierName") vararg assertions: kotlin.Pair<String, List<String>>
|
@Suppress("RemoveRedundantQualifierName") vararg assertions: kotlin.Pair<String, List<String>>
|
||||||
) {
|
) {
|
||||||
|
|||||||
Reference in New Issue
Block a user