aboutsummaryrefslogtreecommitdiff
path: root/src/test/kotlin/util/ColorCodeTest.kt
blob: d9de36a0f9d10d9c5eca968578f319ac3f8e51a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package moe.nea.firmament.test.util

import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import net.minecraft.Bootstrap
import net.minecraft.SharedConstants
import moe.nea.firmament.util.removeColorCodes


class ColorCodeTest {
    @Test
    fun testWhatever() {
        Assertions.assertEquals("", "".removeColorCodes().toString())
        Assertions.assertEquals("", "§".removeColorCodes().toString())
        Assertions.assertEquals("", "§a".removeColorCodes().toString())
        Assertions.assertEquals("ab", "a§ab".removeColorCodes().toString())
        Assertions.assertEquals("ab", "a§ab§§".removeColorCodes().toString())
        Assertions.assertEquals("abc", "a§ab§§c".removeColorCodes().toString())
        Assertions.assertEquals("bc", "§ab§§c".removeColorCodes().toString())
        Assertions.assertEquals("b§lc", "§ab§l§§c".removeColorCodes(true).toString())
        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()
        )
    }
}