diff --git a/wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/RegexSetTest.kt b/wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/RegexSetTest.kt new file mode 100644 index 00000000..9e31cff4 --- /dev/null +++ b/wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/RegexSetTest.kt @@ -0,0 +1,38 @@ +package org.pgpainless.wot.dijkstra + +import org.junit.jupiter.api.Test +import org.pgpainless.wot.dijkstra.sq.RegexSet +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +class RegexSetTest { + + private val exampleComRegex = "<[^>]+[@.]example\\.com>\$" + private val pgpainlessOrgRegex = "<[^>]+[@.]pgpainless\\.org>\$" + + @Test + fun testWildcard() { + val wildcard = RegexSet.wildcard() + assertTrue { wildcard.matches("Alice ") } + assertTrue { wildcard.matches("Bob ") } + } + + @Test + fun testDomainRegex() { + val exampleCom = RegexSet.fromExpression(exampleComRegex) + assertTrue { exampleCom.matches("Bob ") } + assertTrue { exampleCom.matches("") } + assertFalse { exampleCom.matches("Spoofed ") } + assertFalse { exampleCom.matches("Alice ") } + } + + @Test + fun testMultipleDomainRegex() { + val multi = RegexSet.fromExpressionList(listOf(exampleComRegex, pgpainlessOrgRegex)) + assertTrue { multi.matches("Bob ") } + assertTrue { multi.matches("Alice ") } + assertTrue { multi.matches("") } + assertFalse { multi.matches("Alice") } + assertFalse { multi.matches("") } + } +} \ No newline at end of file