Browse Source

hid: port IRC tests from liberty, fix tag parsing

master
Přemysl Janouch 1 year ago
parent
commit
f32e2f1483
Signed by: Přemysl Janouch <p@janouch.name> GPG Key ID: A0420B94F92B9493
2 changed files with 30 additions and 1 deletions
  1. 1
    1
      hid/main.go
  2. 29
    0
      hid/main_test.go

+ 1
- 1
hid/main.go View File

@@ -420,7 +420,7 @@ func ircFnmatch(pattern string, s string) bool {
}

var reMsg = regexp.MustCompile(
`^(@[^ ]* +)?(?::([^! ]*)(?:!([^@]*)@([^ ]*))? +)?([^ ]+)(.*)?$`)
`^(?:@([^ ]*) +)?(?::([^! ]*)(?:!([^@]*)@([^ ]*))? +)?([^ ]+)(.*)?$`)
var reArgs = regexp.MustCompile(`:.*| [^: ][^ ]*`)

type message struct {

+ 29
- 0
hid/main_test.go View File

@@ -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.
}

Loading…
Cancel
Save