From a9cb991a2d48746fbf6e466bd47175de92465b54 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Fri, 30 Jun 2023 18:07:11 +0200 Subject: [PATCH] Tests for RegexSet --- .../pgpainless/wot/dijkstra/RegexSetTest.kt | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/RegexSetTest.kt 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