diff options
author | Přemysl Janouch <p@janouch.name> | 2018-08-06 12:09:18 +0200 |
---|---|---|
committer | Přemysl Janouch <p@janouch.name> | 2018-08-06 12:09:18 +0200 |
commit | f32e2f14839e6560409897d9472fd6e3820e2568 (patch) | |
tree | a8fb2955d6e54b3c186fd15bc40fde79777a3a6f /hid | |
parent | 62418ebb543caf0da72e9f3a8ec77bc7b978cfa7 (diff) | |
download | haven-f32e2f14839e6560409897d9472fd6e3820e2568.tar.gz haven-f32e2f14839e6560409897d9472fd6e3820e2568.tar.xz haven-f32e2f14839e6560409897d9472fd6e3820e2568.zip |
hid: port IRC tests from liberty, fix tag parsing
Diffstat (limited to 'hid')
-rw-r--r-- | hid/main.go | 2 | ||||
-rw-r--r-- | hid/main_test.go | 29 |
2 files changed, 30 insertions, 1 deletions
diff --git a/hid/main.go b/hid/main.go index a7bd2e9..c49b2f6 100644 --- a/hid/main.go +++ b/hid/main.go @@ -420,7 +420,7 @@ func ircFnmatch(pattern string, s string) bool { } var reMsg = regexp.MustCompile( - `^(@[^ ]* +)?(?::([^! ]*)(?:!([^@]*)@([^ ]*))? +)?([^ ]+)(.*)?$`) + `^(?:@([^ ]*) +)?(?::([^! ]*)(?:!([^@]*)@([^ ]*))? +)?([^ ]+)(.*)?$`) var reArgs = regexp.MustCompile(`:.*| [^: ][^ ]*`) type message struct { diff --git a/hid/main_test.go b/hid/main_test.go index 90a55f6..4d6ccb3 100644 --- a/hid/main_test.go +++ b/hid/main_test.go @@ -137,3 +137,32 @@ func TestDetectTLS(t *testing.T) { } }) } + +func TestIRC(t *testing.T) { + msg := ircParseMessage( + `@first=a\:\s\r\n\\;2nd :srv hi there :good m8 :how are you?`) + + if !reflect.DeepEqual(msg.tags, map[string]string{ + "first": "a; \r\n\\", + "2nd": "", + }) { + t.Error("tags parsed incorrectly") + } + + if msg.nick != "srv" || msg.user != "" || msg.host != "" { + t.Error("server name parsed incorrectly") + } + if msg.command != "hi" { + t.Error("command name parsed incorrectly") + } + if !reflect.DeepEqual(msg.params, + []string{"there", "good m8 :how are you?"}) { + t.Error("params parsed incorrectly") + } + + if !ircEqual("[fag]^", "{FAG}~") { + t.Error("string case comparison not according to RFC 2812") + } + + // TODO: More tests. +} |