aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/textutil.kt2
-rw-r--r--src/test/kotlin/moe/nea/firmament/test/ColorCode.kt35
2 files changed, 36 insertions, 1 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/textutil.kt b/src/main/kotlin/moe/nea/firmament/util/textutil.kt
index 1d61332..cfe548d 100644
--- a/src/main/kotlin/moe/nea/firmament/util/textutil.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/textutil.kt
@@ -93,7 +93,7 @@ fun CharSequence.removeColorCodes(keepNonColorCodes: Boolean = false): String {
}
val Text.unformattedString: String
- get() = string.removeColorCodes().toString()
+ get() = string.removeColorCodes()
fun Text.transformEachRecursively(function: (Text) -> Text): Text {
diff --git a/src/test/kotlin/moe/nea/firmament/test/ColorCode.kt b/src/test/kotlin/moe/nea/firmament/test/ColorCode.kt
index 737534e..b8968aa 100644
--- a/src/test/kotlin/moe/nea/firmament/test/ColorCode.kt
+++ b/src/test/kotlin/moe/nea/firmament/test/ColorCode.kt
@@ -25,4 +25,39 @@ class ColorCode {
Assertions.assertEquals("b§lc§l", "§ab§l§§c§l".removeColorCodes(true).toString())
Assertions.assertEquals("§lb§lc", "§l§ab§l§§c".removeColorCodes(true).toString())
}
+
+ @Test
+ fun testEdging() {
+ Assertions.assertEquals("", "§".removeColorCodes())
+ Assertions.assertEquals("a", "a§".removeColorCodes())
+ Assertions.assertEquals("b", "§ab§".removeColorCodes())
+ }
+
+ @Test
+ fun `testDouble§`() {
+ Assertions.assertEquals("1", "§§1".removeColorCodes())
+ }
+
+ @Test
+ fun testKeepNonColor() {
+ Assertions.assertEquals("§k§l§m§n§o§r", "§k§l§m§f§n§o§r".removeColorCodes(true))
+ }
+
+ @Test
+ fun testPlainString() {
+ Assertions.assertEquals("bcdefgp", "bcdefgp".removeColorCodes())
+ Assertions.assertEquals("", "".removeColorCodes())
+ }
+
+ @Test
+ fun testSomeNormalTestCases() {
+ Assertions.assertEquals(
+ "You are not currently in a party.",
+ "§r§cYou are not currently in a party.§r".removeColorCodes()
+ )
+ Assertions.assertEquals(
+ "Ancient Necron's Chestplate ✪✪✪✪",
+ "§dAncient Necron's Chestplate §6✪§6✪§6✪§6✪".removeColorCodes()
+ )
+ }
}