From 323cd55125f1485c71c49568aa919e5311c6263f Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Fri, 3 May 2024 17:25:52 +0200 Subject: Add hover/click events back to custom chat messages (#1516) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../hannibal2/skyhanni/test/ComponentSpanTest.kt | 25 +++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/test/java/at/hannibal2/skyhanni') diff --git a/src/test/java/at/hannibal2/skyhanni/test/ComponentSpanTest.kt b/src/test/java/at/hannibal2/skyhanni/test/ComponentSpanTest.kt index 9b5f40829..7bef032c7 100644 --- a/src/test/java/at/hannibal2/skyhanni/test/ComponentSpanTest.kt +++ b/src/test/java/at/hannibal2/skyhanni/test/ComponentSpanTest.kt @@ -28,6 +28,19 @@ class ComponentSpanTest { require(span.slice(4, 11).intoComponent().formattedText == "§r5§r§c12345§r1§r") } + @Test + fun testRemovePrefix() { + val component = text("12345") { + appendSibling(text("12345")) + appendSibling(text("12345§r")) + }.intoSpan() + val prefixRemoved = component.removePrefix("123") + require(prefixRemoved.getText() == "451234512345§r") + require(component.stripHypixelMessage().getText() == "123451234512345") + require(component.stripHypixelMessage().slice().getText() == "123451234512345") + require(component.slice(0, 0).slice(0, 0).getText() == "") + } + @Test fun testRegex() { val component = text("12345") { @@ -37,16 +50,18 @@ class ComponentSpanTest { appendSibling(text("12345")) } Pattern.compile("[0-9]*(?[a-z]+)[0-9]*").matchStyledMatcher(component) { - require(group("middle")?.sampleStyleAtStart()?.color == EnumChatFormatting.RED) + require(groupOrThrow("middle")?.sampleStyleAtStart()?.color == EnumChatFormatting.RED) } val middlePartExtracted = Pattern.compile("[0-9]*(?[0-9][a-z]+[0-9])[0-9]*").matchStyledMatcher(component) { - require(group("middle")?.sampleComponents()?.size == 3) - require(group("middle")?.sampleStyles()?.find { it.color != null }?.color == EnumChatFormatting.RED) - group("middle") + require(groupOrThrow("middle")?.sampleComponents()?.size == 3) + require( + groupOrThrow("middle")?.sampleStyles()?.find { it.color != null }?.color == EnumChatFormatting.RED + ) + groupOrThrow("middle") }!! Pattern.compile("(?c)").findStyledMatcher(middlePartExtracted) { - require(group("whole")?.sampleStyleAtStart()?.color == EnumChatFormatting.RED) + require(groupOrThrow("whole")?.sampleStyleAtStart()?.color == EnumChatFormatting.RED) } } -- cgit