From dfe5c28dd6a50fc88973e95e60bcfd418daa1e90 Mon Sep 17 00:00:00 2001 From: Rime <81419447+Emirlol@users.noreply.github.com> Date: Sat, 13 Jul 2024 02:21:47 +0300 Subject: Fix regex and add tests for the regex --- .../dwarven/CrystalsLocationManagerTest.java | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/test/java') diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java index 5d555742..11331fae 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java @@ -6,7 +6,31 @@ import org.junit.jupiter.api.Test; import de.hysky.skyblocker.utils.Constants; -public class CrystalsLocationManagerTest { +class CrystalsLocationManagerTest { + boolean matches(String text) { + return CrystalsLocationsManager.TEXT_CWORDS_PATTERN.matcher(text).find(); + } + + @Test + void testRegex() { + Assertions.assertTrue(matches("x123 y12 z123")); + Assertions.assertTrue(matches("x123, y12, z123")); + Assertions.assertTrue(matches("Player: 123 12 123")); //This and the ones below fail when specified in the same format as those above, as the regex check assumes that the message is sent somewhere in a message and that it isn't the whole message + Assertions.assertTrue(matches("Player: 123 123 123")); + Assertions.assertTrue(matches("Player: 123, 12, 123")); + Assertions.assertTrue(matches("Player: 123, 123, 123")); + Assertions.assertTrue(matches("Player: 123,12,123")); + Assertions.assertTrue(matches("Player: 123,123,123")); + + Assertions.assertFalse(matches("Player: 123 1234 123")); + Assertions.assertFalse(matches("Player: 1234 12 123")); + Assertions.assertFalse(matches("Player: 123 12 1234")); + Assertions.assertFalse(matches("Player: 12 12 123")); + Assertions.assertFalse(matches("Player: 123 1 123")); + Assertions.assertFalse(matches("Player: 123 12 12")); + Assertions.assertFalse(matches("Player: 12312123")); + Assertions.assertFalse(matches("Player: 123123123")); + } @Test void testLocationInCrystals() { -- cgit