diff options
| author | Rime <81419447+Emirlol@users.noreply.github.com> | 2025-02-27 23:48:55 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-28 04:48:55 +0800 |
| commit | fc478774143a73aa1470e6348d75896231fa21ca (patch) | |
| tree | d0f808a784f2eae1d394cf43fa23949ec4fdc61b /src/test/java | |
| parent | 37422acb185653f1d33c606687a97715db1a7264 (diff) | |
| download | Skyblocker-fc478774143a73aa1470e6348d75896231fa21ca.tar.gz Skyblocker-fc478774143a73aa1470e6348d75896231fa21ca.tar.bz2 Skyblocker-fc478774143a73aa1470e6348d75896231fa21ca.zip | |
Chat rule location config overhaul (#1138)
* 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>
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/de/hysky/skyblocker/skyblock/chat/ChatRuleTest.java | 94 |
1 files changed, 66 insertions, 28 deletions
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() + ); + } +} |
