-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
935db8c
commit 0d53fd6
Showing
4 changed files
with
115 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
kopykat-ksp/src/test/kotlin/at/kopyk/MutableCollectionCopyTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package at.kopyk | ||
|
||
import org.junit.jupiter.api.Test | ||
|
||
/** | ||
* @author: xiaozhikang | ||
* @create: 2023/7/3 | ||
*/ | ||
class MutableCollectionCopyTest { | ||
@Test | ||
fun `copy property in collection`() { | ||
""" | ||
data class Group(val p: List<Person>) | ||
data class Person(val age: Int) | ||
val g1 = Group(listOf(Person(1), Person(2))) | ||
val g2 = g1.copy { p[1].age ++ } | ||
val age = g2.p[1].age | ||
""".trimIndent().evals("age" to 3) | ||
} | ||
|
||
@Test | ||
fun `copy property in collection with generic type`() { | ||
""" | ||
data class Group(val p: List<Person<String>>) | ||
data class Person<T>(val mark: T) | ||
val g1 = Group(listOf(Person("old"), Person("old"))) | ||
val g2 = g1.copy { p[1].mark = "new" } | ||
val mark = g2.p[1].mark | ||
""".trimIndent().evals("mark" to "new") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters