From fc478774143a73aa1470e6348d75896231fa21ca Mon Sep 17 00:00:00 2001 From: Rime <81419447+Emirlol@users.noreply.github.com> Date: Thu, 27 Feb 2025 23:48:55 +0300 Subject: Chat rule location config overhaul (#1138) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Chat rule location config overhaul * Fix incorrect logic in ItemTickList * Boolean → boolean * Update location name * Remove locations list * Revamp widgets in `ChatRuleConfigScreen` * Complete codec to decode both string and enumset * Take negated locations into account * Fix exclusion parsing and add tests * Clean up codec with Codec::either * Dynamic width calculation Also moves `Ignore Case` button to the next row, with the location config button. * Remove stale javadoc * Small code cleanup * Remove `UNKNOWN` and `MODERN_FORAGING_ISLAND` from the location selector * Future-proofing * Consider valid locations set of only `Location.UNKNOWN` as empty --------- Co-authored-by: Kevin <92656833+kevinthegreat1@users.noreply.github.com> --- .../skyblocker/skyblock/chat/ChatRuleTest.java | 94 +++++++++++++++------- 1 file changed, 66 insertions(+), 28 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/de/hysky/skyblocker/skyblock/chat/ChatRuleTest.java b/src/test/java/de/hysky/skyblocker/skyblock/chat/ChatRuleTest.java index 81a44ff0..1c5004fc 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/chat/ChatRuleTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/chat/ChatRuleTest.java @@ -1,35 +1,73 @@ package de.hysky.skyblocker.skyblock.chat; +import com.mojang.serialization.JsonOps; +import de.hysky.skyblocker.utils.Location; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.util.EnumSet; +import java.util.stream.Stream; + class ChatRuleTest { - @Test - void isMatch() { - ChatRule testRule = new ChatRule(); - //test enabled check - testRule.setFilter("test"); - testRule.setEnabled(false); - Assertions.assertEquals(testRule.isMatch("test"), false); - //test simple filter works - testRule.setEnabled(true); - Assertions.assertEquals(testRule.isMatch("test"), true); - //test partial match works - Assertions.assertEquals(testRule.isMatch("test extra"), false); - testRule.setPartialMatch(true); - Assertions.assertEquals(testRule.isMatch("test extra"), true); - //test ignore case works - Assertions.assertEquals(testRule.isMatch("TEST"), true); - testRule.setIgnoreCase(false); - Assertions.assertEquals(testRule.isMatch("TEST"), false); - - //test regex - testRule = new ChatRule(); - testRule.setRegex(true); - testRule.setFilter("[0-9]+"); - Assertions.assertEquals(testRule.isMatch("1234567"), true); - Assertions.assertEquals(testRule.isMatch("1234567 test"), false); - - } -} \ No newline at end of file + @Test + void isMatch() { + ChatRule testRule = new ChatRule(); + //test enabled check + testRule.setFilter("test"); + testRule.setEnabled(false); + Assertions.assertFalse(testRule.isMatch("test")); + //test simple filter works + testRule.setEnabled(true); + Assertions.assertTrue(testRule.isMatch("test")); + //test partial match works + Assertions.assertFalse(testRule.isMatch("test extra")); + testRule.setPartialMatch(true); + Assertions.assertTrue(testRule.isMatch("test extra")); + //test ignore case works + Assertions.assertTrue(testRule.isMatch("TEST")); + testRule.setIgnoreCase(false); + Assertions.assertFalse(testRule.isMatch("TEST")); + + //test regex + testRule = new ChatRule(); + testRule.setRegex(true); + testRule.setFilter("[0-9]+"); + Assertions.assertTrue(testRule.isMatch("1234567")); + Assertions.assertFalse(testRule.isMatch("1234567 test")); + } + + @Test + void codecParseLegacy() { + // Testing to see if the string/enum set decoding codec works properly + // Encoding is left to the actual enum set codec, and that's beyond the scope of this test. + Assertions.assertEquals( + EnumSet.of(Location.DWARVEN_MINES, Location.WINTER_ISLAND, Location.THE_PARK), + ChatRule.LOCATION_FIXING_CODEC.parse(JsonOps.INSTANCE, JsonOps.INSTANCE.createString("Dwarven Mines, Jerry's Workshop, The Park")).getOrThrow() + ); + } + + @Test + void codecParseLegacyExclusion() { + Assertions.assertEquals( + EnumSet.complementOf(EnumSet.of(Location.WINTER_ISLAND, Location.DEEP_CAVERNS)), + ChatRule.LOCATION_FIXING_CODEC.parse(JsonOps.INSTANCE, JsonOps.INSTANCE.createString("!Jerry's Workshop, !Deep Caverns")).getOrThrow() + ); + + Assertions.assertEquals( + EnumSet.complementOf(EnumSet.of(Location.DWARVEN_MINES)), + ChatRule.LOCATION_FIXING_CODEC.parse(JsonOps.INSTANCE, JsonOps.INSTANCE.createString("!Dwarven Mines, Jerry's Workshop, The Park")).getOrThrow() + ); + } + + @Test + void codecParseEnumSet() { + Assertions.assertEquals( + EnumSet.of(Location.DWARVEN_MINES, Location.WINTER_ISLAND, Location.THE_PARK), + ChatRule.LOCATION_FIXING_CODEC.parse(JsonOps.INSTANCE, JsonOps.INSTANCE.createList(Stream.of(Location.DWARVEN_MINES, Location.WINTER_ISLAND, Location.THE_PARK) + .map(Location::asString) + .map(JsonOps.INSTANCE::createString) + )).getOrThrow() + ); + } +} -- cgit