Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.regex.Pattern;

public class CollectionNotifier extends BaseNotifier implements ChatMessageHandler {
private static final Pattern COLLECTION_LOG_REGEX = Pattern.compile("New item added to your collection log: (?<itemName>[\\w,\\s-.]+)");
public static final Pattern COLLECTION_LOG_REGEX = Pattern.compile("New item added to your collection log: (?<itemName>[\\w,\\s-.'()]+)");

private Matcher lastMatcher;

Expand Down
38 changes: 38 additions & 0 deletions src/test/java/universalDiscord/CollectionNotifierTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package universalDiscord;

import org.junit.Test;
import universalDiscord.notifiers.CollectionNotifier;

import java.util.regex.Matcher;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;


public class CollectionNotifierTest {


@Test
public void testCollectionLogRegex() {
String[] itemNames = {
"Xeric's talisman (inert)",
"Jar of miasma",
"Saradomin's light",
"Craw's bow",
"Thammaron's sceptre",
"Chompy bird hat (ogre yeoman)",
"Robe bottoms of the eye",
"Bucket helm (g)",
"Black d'hide body (g)",
"Tzhaar-ket-om ornament kit",
};

for (String itemName : itemNames) {
String chatLine = "New item added to your collection log: " + itemName;
Matcher matcher = CollectionNotifier.COLLECTION_LOG_REGEX.matcher(chatLine);
boolean finds = matcher.find();
assertTrue(finds);
assertEquals(itemName, matcher.group("itemName"));
}
}
}