mirror of
https://github.com/apple/pkl.git
synced 2026-06-12 08:34:27 +02:00
codegen-java/kotlin: Fix generation of hashCode methods (#802)
codegen-java: - use `pattern.pattern()` instead of `pattern` in hashCode method (consistent with equals method) codegen-kotlin: - use `regex.pattern` instead of `regex` in hashCode method (consistent with equals method) - if a data class has a Regex property, generate not only an equals method but also a hashCode method
This commit is contained in:
@@ -561,6 +561,26 @@ class KotlinCodeGeneratorTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `data class with Regex property has custom equals and hashCode methods`() {
|
||||
val kotlinCode =
|
||||
generateKotlinCode(
|
||||
"""
|
||||
module my.mod
|
||||
|
||||
class Person {
|
||||
age: Int
|
||||
name: Regex
|
||||
}
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
|
||||
assertThat(kotlinCode)
|
||||
.contains("if (this.name.pattern != other.name.pattern) return false")
|
||||
.contains("result = 31 * result + Objects.hashCode(this.name.pattern)")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `recursive types`() {
|
||||
val kotlinCode =
|
||||
|
||||
@@ -139,7 +139,7 @@ object Mod {
|
||||
result = 31 * result + Objects.hashCode(this.container)
|
||||
result = 31 * result + Objects.hashCode(this.container2)
|
||||
result = 31 * result + Objects.hashCode(this.other)
|
||||
result = 31 * result + Objects.hashCode(this.regex)
|
||||
result = 31 * result + Objects.hashCode(this.regex.pattern)
|
||||
result = 31 * result + Objects.hashCode(this.any)
|
||||
result = 31 * result + Objects.hashCode(this.nonNull)
|
||||
result = 31 * result + Objects.hashCode(this.enum)
|
||||
|
||||
Reference in New Issue
Block a user