From d8e291de8845e1e205247a0d218c3a45f48f60b2 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 20 Dec 2024 00:18:11 +0100 Subject: [PATCH 1/5] added unit tests for replace roman --- .../features/misc/ReplaceRomanNumerals.kt | 2 + .../skyhanni/test/ReplaceRomanNumeralsTest.kt | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/test/java/at/hannibal2/skyhanni/test/ReplaceRomanNumeralsTest.kt diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt index be1fcd7994de..448fe1eada66 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt @@ -104,4 +104,6 @@ object ReplaceRomanNumerals { private fun String.removeFormatting() = removeColor().replace(",", "") private fun isEnabled() = LorenzUtils.inSkyBlock && SkyHanniMod.feature.misc.replaceRomanNumerals + + fun replaceRomanNumerals(string: String): String = string.transformLine() } diff --git a/src/test/java/at/hannibal2/skyhanni/test/ReplaceRomanNumeralsTest.kt b/src/test/java/at/hannibal2/skyhanni/test/ReplaceRomanNumeralsTest.kt new file mode 100644 index 000000000000..c645bc306b86 --- /dev/null +++ b/src/test/java/at/hannibal2/skyhanni/test/ReplaceRomanNumeralsTest.kt @@ -0,0 +1,44 @@ +package at.hannibal2.skyhanni.test + +import at.hannibal2.skyhanni.features.misc.ReplaceRomanNumerals +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test + +class ReplaceRomanNumeralsTest { + + @Test + fun testTransformLine() { + // Simple case with no Roman numerals + Assertions.assertEquals("hello", "hello".transformLine()) + + // I should never be converted + Assertions.assertEquals("I", "I".transformLine()) + + // Single Roman numeral should be converted + Assertions.assertEquals("5", "V".transformLine()) + + // Multiple Roman numerals separated by spaces + Assertions.assertEquals("5 10 world", "V X world".transformLine()) + + // Roman numeral next to punctuation + Assertions.assertEquals("5!", "V!".transformLine()) + Assertions.assertEquals("hello 14 you?", "hello XIV you?".transformLine()) + + // Mixed with color codes + Assertions.assertEquals("§c5!", "§cV!".transformLine()) + Assertions.assertEquals("hello 2 is this 5 you?", "hello II is this V you?".transformLine()) + + // If invalid Roman numeral sequences are left unchanged + // Assuming "IIII" is invalid, it remains as is + Assertions.assertEquals("IIII", "IIII".transformLine()) + + // Check sequences with punctuation and color codes interspersed + Assertions.assertEquals("§d5 world", "§dV world".transformLine()) + Assertions.assertEquals("hello 10 and then 1 more", "hello X and then I more".transformLine()) + + // Mixed complexity + Assertions.assertEquals("Today 2023 was great!", "Today MMXXIII was great!".transformLine()) + } + + fun String.transformLine(): String = ReplaceRomanNumerals.replaceRomanNumerals(this) +} From c8f7299c41b66bd4c693ecd7f8c240ffa23b99ea Mon Sep 17 00:00:00 2001 From: calwolfson Date: Sun, 22 Dec 2024 11:42:43 -0500 Subject: [PATCH 2/5] add to baseline --- versions/1.8.9/detekt/baseline.xml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/versions/1.8.9/detekt/baseline.xml b/versions/1.8.9/detekt/baseline.xml index c9ef245f4622..8d13272f0827 100644 --- a/versions/1.8.9/detekt/baseline.xml +++ b/versions/1.8.9/detekt/baseline.xml @@ -56,6 +56,7 @@ MemberNameEqualsClassName:FirstMinionTier.kt$FirstMinionTier$fun firstMinionTier( otherItems: Map<NEUInternalName, Int>, minions: MutableMap<String, NEUInternalName>, tierOneMinions: MutableList<NEUInternalName>, tierOneMinionsDone: MutableSet<NEUInternalName>, ) MemberNameEqualsClassName:LastServers.kt$LastServers$private val lastServers = mutableMapOf<String, SimpleTimeMark>() MemberNameEqualsClassName:PestSpawn.kt$PestSpawn$private fun pestSpawn(amount: Int, plotNames: List<String>, unknownAmount: Boolean) + MemberNameEqualsClassName:ReplaceRomanNumerals.kt$ReplaceRomanNumerals$fun replaceRomanNumerals(string: String): String MemberNameEqualsClassName:Shimmy.kt$Shimmy.Companion$private fun shimmy(source: Any?, fieldName: String): Any? MemberNameEqualsClassName:TestBingo.kt$TestBingo$var testBingo = false MemberNameEqualsClassName:Text.kt$Text$fun text(text: String, init: IChatComponent.() -> Unit = {}) @@ -73,7 +74,6 @@ NoNameShadowing:Renderable.kt$Renderable.Companion.<no name provided>$posY NoNameShadowing:Renderable.kt$Renderable.Companion.<no name provided>${ it.value?.contains(textInput.textBox, ignoreCase = true) ?: true } NoNameShadowing:RenderableUtils.kt$RenderableUtils${ it != null } - NoNameShadowing:ReplaceRomanNumerals.kt$ReplaceRomanNumerals${ it.isValidRomanNumeral() && it.removeFormatting().romanToDecimal() != 2000 } NoNameShadowing:RepoManager.kt$RepoManager${ unsuccessfulConstants.add(it) } NoNameShadowing:RepoPatternManager.kt$RepoPatternManager${ it == '.' } NoNameShadowing:Shimmy.kt$Shimmy.Companion$source @@ -233,10 +233,6 @@ RepoPatternRegexTest:ScoreboardPattern.kt$ScoreboardPattern$by dungeonSb.pattern( "keys", "Keys: §.■ §.[✗✓] §.■ §a.x", ) RepoPatternRegexTest:ScoreboardPattern.kt$ScoreboardPattern$by dungeonSb.pattern( "teammates", "(?:§.)*(?<classAbbv>\\[\\w]) (?:§.)*(?<username>\\w{2,16}) (?:(?:§.)*(?<classLevel>\\[Lvl?(?<level>[\\w,.]+)?]?)|(?:§.)*(?<health>[\\w,.]+)(?:§.)*.?)", ) RepoPatternRegexTest:ShowMotesNpcSellPrice.kt$ShowMotesNpcSellPrice$by RepoPattern.pattern( "rift.everywhere.burger", ".*(?:§\\w)+You have (?:§\\w)+(?<amount>\\d) Grubber Stacks.*" ) - RepoPatternRegexTest:SkillAPI.kt$SkillAPI$by patternGroup.pattern( "skill", "\\+(?<gained>[\\d.,]+) (?<skillName>\\w+) \\((?<current>[\\d.,]+)/(?<needed>[\\d.,]+)\\)", ) - RepoPatternRegexTest:SkillAPI.kt$SkillAPI$by patternGroup.pattern( "skill.multiplier", "\\+(?<gained>[\\d.,]+) (?<skillName>.+) \\((?<current>[\\d.,]+)/(?<needed>[\\d,.]+[kmb])\\)", ) - RepoPatternRegexTest:SkillAPI.kt$SkillAPI$by patternGroup.pattern( "skill.percent", "\\+(?<gained>[\\d.,]+) (?<skillName>.+) \\((?<progress>[\\d.]+)%\\)", ) - RepoPatternRegexTest:SkillAPI.kt$SkillAPI$by patternGroup.pattern( "skill.tab", " (?<type>\\w+)(?: (?<level>\\d+))?: §r§a(?<progress>[0-9.]+)%", ) RepoPatternRegexTest:SkillAPI.kt$SkillAPI$by patternGroup.pattern( "skill.tab.max", " (?<type>\\w+) (?<level>\\d+): §r§c§lMAX", ) RepoPatternRegexTest:SkillAPI.kt$SkillAPI$by patternGroup.pattern( "skill.tab.nopercent", " §r§a(?<type>\\w+)(?: (?<level>\\d+))?: §r§e(?<current>[0-9,.]+)§r§6/§r§e(?<needed>[0-9kmb]+)", ) RepoPatternRegexTest:SkillExperience.kt$SkillExperience$by patternGroup.pattern( "actionbar", ".*§3\\+.* (?<skill>.*) \\((?<overflow>.*)/(?<needed>.*)\\).*" ) @@ -417,7 +413,6 @@ UnsafeCallOnNullableType:SoopyGuessBurrow.kt$SoopyGuessBurrow$lastParticlePoint2?.distance(particlePoint!!)!! UnsafeCallOnNullableType:SoopyGuessBurrow.kt$SoopyGuessBurrow$particlePoint!! UnsafeCallOnNullableType:SoopyGuessBurrow.kt$SoopyGuessBurrow$particlePoint?.let { it - lastParticlePoint2!! }!! - UnsafeCallOnNullableType:SummoningSoulsName.kt$SummoningSoulsName$mobsName.getOrNull(nearestMob)!! UnsafeCallOnNullableType:SuperpairsClicksAlert.kt$SuperpairsClicksAlert$match.groups[1]!! UnsafeCallOnNullableType:TiaRelayWaypoints.kt$TiaRelayWaypoints$waypointName!! UnsafeCallOnNullableType:Translator.kt$Translator$messageContentRegex.find(message)!! From a21f9671320780dd4a28cd6e87e41cf8fcec57a8 Mon Sep 17 00:00:00 2001 From: calwolfson Date: Sun, 22 Dec 2024 11:53:28 -0500 Subject: [PATCH 3/5] separate test cases --- .../skyhanni/test/ReplaceRomanNumeralsTest.kt | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/test/java/at/hannibal2/skyhanni/test/ReplaceRomanNumeralsTest.kt b/src/test/java/at/hannibal2/skyhanni/test/ReplaceRomanNumeralsTest.kt index c645bc306b86..3803ed2e187f 100644 --- a/src/test/java/at/hannibal2/skyhanni/test/ReplaceRomanNumeralsTest.kt +++ b/src/test/java/at/hannibal2/skyhanni/test/ReplaceRomanNumeralsTest.kt @@ -7,38 +7,52 @@ import org.junit.jupiter.api.Test class ReplaceRomanNumeralsTest { @Test - fun testTransformLine() { - // Simple case with no Roman numerals + fun `Regular words shouldn't be modified`() { Assertions.assertEquals("hello", "hello".transformLine()) + } - // I should never be converted + @Test + fun `'I' should never be converted`() { Assertions.assertEquals("I", "I".transformLine()) + } - // Single Roman numeral should be converted + @Test + fun `Single Roman numeral should be converted`() { Assertions.assertEquals("5", "V".transformLine()) + } - // Multiple Roman numerals separated by spaces + @Test + fun `Multiple Roman numerals separated by spaces should be converted`() { Assertions.assertEquals("5 10 world", "V X world".transformLine()) + } - // Roman numeral next to punctuation + @Test + fun `Roman numeral next to punctuation should be converted`() { Assertions.assertEquals("5!", "V!".transformLine()) Assertions.assertEquals("hello 14 you?", "hello XIV you?".transformLine()) + } - // Mixed with color codes + @Test + fun `Mixed with color codes should be converted`() { Assertions.assertEquals("§c5!", "§cV!".transformLine()) Assertions.assertEquals("hello 2 is this 5 you?", "hello II is this V you?".transformLine()) + } - // If invalid Roman numeral sequences are left unchanged - // Assuming "IIII" is invalid, it remains as is + @Test + fun `Invalid Roman numeral sequences are left unchanged`() { Assertions.assertEquals("IIII", "IIII".transformLine()) + } - // Check sequences with punctuation and color codes interspersed + @Test + fun `Sequences with punctuation and color codes interspersed should be converted`() { Assertions.assertEquals("§d5 world", "§dV world".transformLine()) Assertions.assertEquals("hello 10 and then 1 more", "hello X and then I more".transformLine()) + } - // Mixed complexity + @Test + fun `Mixed complexity should be converted`() { Assertions.assertEquals("Today 2023 was great!", "Today MMXXIII was great!".transformLine()) } - fun String.transformLine(): String = ReplaceRomanNumerals.replaceRomanNumerals(this) + private fun String.transformLine(): String = ReplaceRomanNumerals.replaceRomanNumerals(this) } From 654d30a396ec5568485f48c26bf5d27988de0eeb Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Wed, 25 Dec 2024 03:42:40 +0100 Subject: [PATCH 4/5] fix merge conflict --- .../hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt | 4 ++-- .../at/hannibal2/skyhanni/test/ReplaceRomanNumeralsTest.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt index 8f59492a758f..9b9d28765b50 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt @@ -96,8 +96,8 @@ object ReplaceRomanNumerals { if (allowedPatterns.matches(this)) replace() else this } - fun replaceLine(line: String): String { - if (!isEnabled()) return line + fun replaceLine(line: String, checkIfEnabled: Boolean = true): String { + if (checkIfEnabled && !isEnabled()) return line return cachedStrings.getOrPut(line) { line.replace() diff --git a/src/test/java/at/hannibal2/skyhanni/test/ReplaceRomanNumeralsTest.kt b/src/test/java/at/hannibal2/skyhanni/test/ReplaceRomanNumeralsTest.kt index 3803ed2e187f..4ff530f67de1 100644 --- a/src/test/java/at/hannibal2/skyhanni/test/ReplaceRomanNumeralsTest.kt +++ b/src/test/java/at/hannibal2/skyhanni/test/ReplaceRomanNumeralsTest.kt @@ -54,5 +54,5 @@ class ReplaceRomanNumeralsTest { Assertions.assertEquals("Today 2023 was great!", "Today MMXXIII was great!".transformLine()) } - private fun String.transformLine(): String = ReplaceRomanNumerals.replaceRomanNumerals(this) + private fun String.transformLine(): String = ReplaceRomanNumerals.replaceLine(this, checkIfEnabled = false) } From 8576b0e8ce4449a31ce509052ae544a70f96fe3e Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Wed, 25 Dec 2024 03:57:04 +0100 Subject: [PATCH 5/5] code cleanup --- .../skyhanni/features/misc/ReplaceRomanNumerals.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt index 9b9d28765b50..469637e8c9b0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt @@ -46,7 +46,7 @@ object ReplaceRomanNumerals { "§o§a✔ §.* (?[IVXLCDM]+)§r", "§5§o§7Purchase §a.* (?[IVXLCDM]+) §7.*", "§5§o(?:§7)§.(?[IVXLCDM]+).*", - ".*Heart of the Mountain (?[IVXLCDM]+) ?.*" + ".*Heart of the Mountain (?[IVXLCDM]+) ?.*", ) /** @@ -104,9 +104,12 @@ object ReplaceRomanNumerals { } } - private fun String.replace() = splitRegex.findAll(this).map { it.value }.joinToString("") { - it.takeIf { it.isValidRomanNumeral() && it.removeFormatting().romanToDecimal() != 2000 }?.coloredRomanToDecimal() ?: it - } + private fun String.replace() = splitRegex + .findAll(this) + .map { it.value } + .joinToString("") { part -> + part.takeIf { it.isValidRomanNumeral() }?.coloredRomanToDecimal() ?: part + } private fun String.removeFormatting() = removeColor().replace(",", "")