Improved tests

parent 4f781879
......@@ -428,4 +428,45 @@ class ExpressionMatchTest {
assertFalse(invalidRegex.match("network"))
assertFalse(invalidRegex.match("testnetwork"))
}
// Tests imported from https://github.com/ircdocs/parser-tests/blob/master/tests/mask-match.yaml
@Test
fun testDan() {
val mask1 = ExpressionMatch("*@127.0.0.1",
ExpressionMatch.MatchMode.MatchWildcard,
caseSensitive = false)
assertTrue(mask1.match("coolguy!ab@127.0.0.1"))
assertTrue(mask1.match("cooldud3!~bc@127.0.0.1"))
assertFalse(mask1.match("coolguy!ab@127.0.0.5"))
assertFalse(mask1.match("cooldud3!~d@124.0.0.1"))
val mask2 = ExpressionMatch("cool*@*",
ExpressionMatch.MatchMode.MatchWildcard,
caseSensitive = false)
assertTrue(mask2.match("coolguy!ab@127.0.0.1"))
assertTrue(mask2.match("cooldud3!~bc@127.0.0.1"))
assertTrue(mask2.match("cool132!ab@example.com"))
assertFalse(mask2.match("koolguy!ab@127.0.0.5"))
assertFalse(mask2.match("cooodud3!~d@124.0.0.1"))
val mask3 = ExpressionMatch("cool!*@*",
ExpressionMatch.MatchMode.MatchWildcard,
caseSensitive = false)
assertTrue(mask3.match("cool!guyab@127.0.0.1"))
assertTrue(mask3.match("cool!~dudebc@127.0.0.1"))
assertTrue(mask3.match("cool!312ab@example.com"))
assertFalse(mask3.match("coolguy!ab@127.0.0.1"))
assertFalse(mask3.match("cooldud3!~bc@127.0.0.1"))
assertFalse(mask3.match("koolguy!ab@127.0.0.5"))
assertFalse(mask3.match("cooodud3!~d@124.0.0.1"))
// Cause failures in fnmatch/glob based matchers
val mask4 = ExpressionMatch("cool[guy]!*@*",
ExpressionMatch.MatchMode.MatchWildcard,
caseSensitive = false)
assertTrue(mask4.match("cool[guy]!guy@127.0.0.1"))
assertTrue(mask4.match("cool[guy]!a@example.com"))
assertFalse(mask4.match("coolg!ab@127.0.0.1"))
assertFalse(mask4.match("cool[!ac@127.0.1.1"))
}
}
......@@ -25,155 +25,182 @@ import org.junit.Test
class HostmaskHelperTest {
@Test
fun testNormal() {
assertEquals("justJanne",
HostmaskHelper.nick("justJanne!kuschku@lithium.kuschku.de"))
assertEquals("justJanne",
HostmaskHelper.split("justJanne!kuschku@lithium.kuschku.de").first)
assertEquals("kuschku",
HostmaskHelper.user("justJanne!kuschku@lithium.kuschku.de"))
assertEquals("kuschku",
HostmaskHelper.split("justJanne!kuschku@lithium.kuschku.de").second)
assertEquals("lithium.kuschku.de",
HostmaskHelper.host("justJanne!kuschku@lithium.kuschku.de"))
assertEquals("lithium.kuschku.de",
HostmaskHelper.split("justJanne!kuschku@lithium.kuschku.de").third)
assertEquals("justJanne!kuschku@lithium.kuschku.de", HostmaskHelper.build(
"justJanne", "kuschku", "lithium.kuschku.de"
))
runTest(
source = "justJanne!kuschku@lithium.kuschku.de",
nick = "justJanne",
user = "kuschku",
host = "lithium.kuschku.de"
)
assertEquals(
"justJanne!kuschku@lithium.kuschku.de",
HostmaskHelper.build(nick = "justJanne", user = "kuschku", host = "lithium.kuschku.de")
)
}
@Test
fun testUnvalidatedIdent() {
assertEquals("justJanne",
HostmaskHelper.nick("justJanne!~kuschku@lithium.kuschku.de"))
assertEquals("justJanne",
HostmaskHelper.split("justJanne!~kuschku@lithium.kuschku.de").first)
assertEquals("~kuschku",
HostmaskHelper.user("justJanne!~kuschku@lithium.kuschku.de"))
assertEquals("~kuschku",
HostmaskHelper.split("justJanne!~kuschku@lithium.kuschku.de").second)
assertEquals("lithium.kuschku.de",
HostmaskHelper.host("justJanne!~kuschku@lithium.kuschku.de"))
assertEquals("lithium.kuschku.de",
HostmaskHelper.split("justJanne!~kuschku@lithium.kuschku.de").third)
assertEquals("justJanne!~kuschku@lithium.kuschku.de", HostmaskHelper.build(
"justJanne", "~kuschku", "lithium.kuschku.de"
))
runTest(
source = "justJanne!~kuschku@lithium.kuschku.de",
nick = "justJanne",
user = "~kuschku",
host = "lithium.kuschku.de"
)
assertEquals(
"justJanne!~kuschku@lithium.kuschku.de",
HostmaskHelper.build(nick = "justJanne", user = "~kuschku", host = "lithium.kuschku.de")
)
}
@Test
fun testUnicode() {
assertEquals("bärlauch",
HostmaskHelper.nick("bärlauch!maße@flüge.de"))
assertEquals("bärlauch",
HostmaskHelper.split("bärlauch!maße@flüge.de").first)
assertEquals("maße",
HostmaskHelper.user("bärlauch!maße@flüge.de"))
assertEquals("maße",
HostmaskHelper.split("bärlauch!maße@flüge.de").second)
assertEquals("flüge.de",
HostmaskHelper.host("bärlauch!maße@flüge.de"))
assertEquals("flüge.de",
HostmaskHelper.split("bärlauch!maße@flüge.de").third)
assertEquals("bärlauch!maße@flüge.de", HostmaskHelper.build(
"bärlauch", "maße", "flüge.de"
))
runTest(
source = "bärlauch!maße@flüge.de",
nick = "bärlauch",
user = "maße",
host = "flüge.de"
)
assertEquals(
"bärlauch!maße@flüge.de",
HostmaskHelper.build(nick = "bärlauch", user = "maße", host = "flüge.de")
)
}
@Test
fun testServer() {
assertEquals("irc.freenode.org",
HostmaskHelper.nick("irc.freenode.org"))
assertEquals("irc.freenode.org",
HostmaskHelper.split("irc.freenode.org").first)
assertEquals("",
HostmaskHelper.user("irc.freenode.org"))
assertEquals("",
HostmaskHelper.split("irc.freenode.org").second)
assertEquals("",
HostmaskHelper.host("irc.freenode.org"))
assertEquals("",
HostmaskHelper.split("irc.freenode.org").third)
assertEquals("irc.freenode.org", HostmaskHelper.build(
"irc.freenode.org", "", ""
))
runTest(
source = "irc.freenode.org",
nick = "irc.freenode.org",
user = "",
host = ""
)
assertEquals(
"irc.freenode.org",
HostmaskHelper.build(nick = "irc.freenode.org", user = "", host = "")
)
}
@Test
fun testAtNick() {
assertEquals("@nick",
HostmaskHelper.nick("@nick!~ident@example.org"))
assertEquals("@nick",
HostmaskHelper.split("@nick!~ident@example.org").first)
assertEquals("~ident",
HostmaskHelper.user("@nick!~ident@example.org"))
assertEquals("~ident",
HostmaskHelper.split("@nick!~ident@example.org").second)
assertEquals("example.org",
HostmaskHelper.host("@nick!~ident@example.org"))
assertEquals("example.org",
HostmaskHelper.split("@nick!~ident@example.org").third)
assertEquals("@nick!~ident@example.org", HostmaskHelper.build(
"@nick", "~ident", "example.org"
))
runTest(
source = "@nick!~ident@example.org",
nick = "@nick",
user = "~ident",
host = "example.org"
)
assertEquals(
"@nick!~ident@example.org",
HostmaskHelper.build(nick = "@nick", user = "~ident", host = "example.org")
)
}
@Test
fun testReversedDelimiters() {
assertEquals("a",
HostmaskHelper.nick("a@a!"))
assertEquals("a",
HostmaskHelper.split("a@a!").first)
assertEquals("",
HostmaskHelper.user("a@a!"))
assertEquals("",
HostmaskHelper.split("a@a!").second)
assertEquals("a!",
HostmaskHelper.host("a@a!"))
assertEquals("a!",
HostmaskHelper.split("a@a!").third)
assertEquals("a@a!", HostmaskHelper.build(
"a", "", "a!"
))
runTest(
source = "a@a!",
nick = "a",
user = "",
host = "a!"
)
assertEquals(
"a@a!",
HostmaskHelper.build(nick = "a", user = "", host = "a!")
)
}
@Test
fun testDiscord() {
assertEquals("Gin_",
HostmaskHelper.nick("Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord"))
assertEquals("Gin_",
HostmaskHelper.split("Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord").first)
assertEquals("Gin_!♡♅ƸӜƷ♅♡!",
HostmaskHelper.user("Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord"))
assertEquals("Gin_!♡♅ƸӜƷ♅♡!",
HostmaskHelper.split("Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord").second)
assertEquals("discord",
HostmaskHelper.host("Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord"))
assertEquals("discord",
HostmaskHelper.split("Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord").third)
assertEquals("Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord", HostmaskHelper.build(
"Gin_", "Gin_!♡♅ƸӜƷ♅♡!", "discord"
))
runTest(
source = "Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord",
nick = "Gin_",
user = "Gin_!♡♅ƸӜƷ♅♡!",
host = "discord"
)
assertEquals(
"Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord",
HostmaskHelper.build(nick = "Gin_", user = "Gin_!♡♅ƸӜƷ♅♡!", host = "discord")
)
}
@Test
fun testDan() {
runTest(
source = "coolguy!ag@127.0.0.1",
nick = "coolguy",
user = "ag",
host = "127.0.0.1"
)
runTest(
source = "coolguy!~ag@localhost",
nick = "coolguy",
user = "~ag",
host = "localhost"
)
}
@Test
fun testDanMissingAtoms() {
runTest(
source = "!ag@127.0.0.1",
nick = "",
user = "ag",
host = "127.0.0.1"
)
runTest(
source = "coolguy!@127.0.0.1",
nick = "coolguy",
user = "",
host = "127.0.0.1"
)
runTest(
source = "coolguy@127.0.0.1",
nick = "coolguy",
user = "",
host = "127.0.0.1"
)
runTest(
source = "coolguy!ag@",
nick = "coolguy",
user = "ag",
host = ""
)
runTest(
source = "coolguy!ag",
nick = "coolguy",
user = "ag",
host = ""
)
}
@Test
fun testDanWeirdControlCodes() {
runTest(
source = "coolguy!ag@net\u00035w\u0003ork.admin",
nick = "coolguy",
user = "ag",
host = "net\u00035w\u0003ork.admin"
)
runTest(
source = "coolguy!~ag@n\u0002et\u000305w\u000fork.admin",
nick = "coolguy",
user = "~ag",
host = "n\u0002et\u000305w\u000fork.admin"
)
}
private fun runTest(source: String, nick: String, user: String, host: String) {
assertEquals(nick, HostmaskHelper.nick(source))
assertEquals(nick, HostmaskHelper.split(source).first)
assertEquals(user, HostmaskHelper.user(source))
assertEquals(user, HostmaskHelper.split(source).second)
assertEquals(host, HostmaskHelper.host(source))
assertEquals(host, HostmaskHelper.split(source).third)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment