From cd31d31309cf51db224dedd75df52a1b6e109e64 Mon Sep 17 00:00:00 2001 From: Kaleb Elwert Date: Mon, 9 Jan 2017 17:06:15 -0800 Subject: [PATCH 1/7] Start moving to a common set of test cases --- .gitmodules | 3 + README.md | 5 ++ parser.go | 11 ++++ parser_test.go | 157 ++++++++++++++++++++++++++++++++++++++++++++----- testcases | 1 + 5 files changed, 161 insertions(+), 16 deletions(-) create mode 100644 .gitmodules create mode 160000 testcases diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..8c73f7c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "testcases"] + path = testcases + url = https://github.com/DanielOaks/irc-parser-tests/ diff --git a/README.md b/README.md index bcb9d9d..c905cc3 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,11 @@ As a result of this, there are multiple import locations. tagged as stable * `github.com/go-irc/irc` should be used to develop against the master branch +## Development + +In order to run the tests, make sure all submodules are up to date. If you are +just using this library, these are not needed. + ## Example ```go diff --git a/parser.go b/parser.go index 80c5568..8a3cbc6 100644 --- a/parser.go +++ b/parser.go @@ -305,6 +305,12 @@ func ParseMessage(line string) (*Message, error) { c.Command = strings.ToUpper(c.Params[0]) c.Params = c.Params[1:] + // If there are no params, set it to nil, to make writing tests and other + // things simpler. + if len(c.Params) == 0 { + c.Params = nil + } + return c, nil } @@ -354,6 +360,11 @@ func (m *Message) Copy() *Message { // Copy the Params slice newMessage.Params = append(make([]string, 0, len(m.Params)), m.Params...) + // Similar to parsing, if Params is empty, set it to nil + if len(newMessage.Params) == 0 { + newMessage.Params = nil + } + return newMessage } diff --git a/parser_test.go b/parser_test.go index 0bdc2d4..6c603f3 100644 --- a/parser_test.go +++ b/parser_test.go @@ -1,9 +1,14 @@ package irc import ( + "io/ioutil" + "strings" "testing" + yaml "gopkg.in/yaml.v2" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var messageTests = []struct { @@ -43,7 +48,6 @@ var messageTests = []struct { { // Basic prefix test Prefix: "server.kevlar.net", Cmd: "PING", - Params: []string{}, Name: "server.kevlar.net", @@ -146,8 +150,7 @@ var messageTests = []struct { "tag": "value", }, - Params: []string{}, - Cmd: "A", + Cmd: "A", Expect: "@tag=value A\n", }, @@ -156,8 +159,7 @@ var messageTests = []struct { "tag": "\n", }, - Params: []string{}, - Cmd: "A", + Cmd: "A", Expect: "@tag=\\n A\n", }, @@ -166,8 +168,7 @@ var messageTests = []struct { "tag": "\\", }, - Params: []string{}, - Cmd: "A", + Cmd: "A", Expect: "@tag=\\ A\n", ExpectIn: []string{"@tag=\\\\ A\n"}, @@ -177,8 +178,7 @@ var messageTests = []struct { "tag": ";", }, - Params: []string{}, - Cmd: "A", + Cmd: "A", Expect: "@tag=\\: A\n", }, @@ -187,8 +187,7 @@ var messageTests = []struct { "tag": "", }, - Params: []string{}, - Cmd: "A", + Cmd: "A", Expect: "@tag A\n", }, @@ -197,8 +196,7 @@ var messageTests = []struct { "tag": "\\&", }, - Params: []string{}, - Cmd: "A", + Cmd: "A", Expect: "@tag=\\& A\n", ExpectIn: []string{"@tag=\\\\& A\n"}, @@ -209,8 +207,7 @@ var messageTests = []struct { "tag2": "asd", }, - Params: []string{}, - Cmd: "A", + Cmd: "A", Expect: "@tag=x;tag2=asd A\n", ExpectIn: []string{"@tag=x;tag2=asd A\n", "@tag2=asd;tag=x A\n"}, @@ -220,7 +217,6 @@ var messageTests = []struct { "tag": "; \\\r\n", }, - Params: []string{}, Cmd: "A", Expect: "@tag=\\:\\s\\\\\\r\\n A\n", }, @@ -443,3 +439,132 @@ func TestMessageTags(t *testing.T) { assert.EqualValues(t, test.Tags, m.Tags, "%d. Tags don't match", i) } } + +type MsgSplitTests struct { + Tests []struct { + Input string + Atoms struct { + Source *string + Verb string + Params []string + Tags map[string]interface{} + } + } +} + +func TestMsgSplit(t *testing.T) { + data, err := ioutil.ReadFile("./testcases/tests/msg-split.yaml") + require.NoError(t, err) + + var splitTests MsgSplitTests + err = yaml.Unmarshal(data, &splitTests) + require.NoError(t, err) + + for _, test := range splitTests.Tests { + msg, err := ParseMessage(test.Input) + assert.NoError(t, err, "Failed to parse: %s (%s)", test.Input, err) + + assert.Equal(t, + strings.ToUpper(test.Atoms.Verb), msg.Command, + "Wrong command for input: %s", test.Input, + ) + assert.Equal(t, + test.Atoms.Params, msg.Params, + "Wrong params for input: %s", test.Input, + ) + + if test.Atoms.Source != nil { + assert.Equal(t, *test.Atoms.Source, msg.Prefix.String()) + } + + assert.Equal(t, + len(test.Atoms.Tags), len(msg.Tags), + "Wrong number of tags", + ) + + for k, v := range test.Atoms.Tags { + if v == nil { + assert.EqualValues(t, "", msg.Tags[k], "Tag differs") + } else { + assert.EqualValues(t, v, msg.Tags[k], "Tag differs") + } + } + } +} + +type MsgJoinTests struct { + Tests []struct { + Atoms struct { + Source string + Verb string + Params []string + Tags map[string]interface{} + } + Matches []string + } +} + +func TestMsgJoin(t *testing.T) { + data, err := ioutil.ReadFile("./testcases/tests/msg-join.yaml") + require.NoError(t, err) + + var splitTests MsgJoinTests + err = yaml.Unmarshal(data, &splitTests) + require.NoError(t, err) + + for _, test := range splitTests.Tests { + msg := &Message{ + Prefix: ParsePrefix(test.Atoms.Source), + Command: test.Atoms.Verb, + Params: test.Atoms.Params, + Tags: make(map[string]TagValue), + } + + for k, v := range test.Atoms.Tags { + if v == nil { + msg.Tags[k] = TagValue("") + } else { + msg.Tags[k] = TagValue(v.(string)) + } + } + + assert.Contains(t, test.Matches, msg.String()) + } +} + +type UserhostSplitTests struct { + Tests []struct { + Source string + Atoms struct { + Nick string + User string + Host string + } + } +} + +func TestUserhostSplit(t *testing.T) { + data, err := ioutil.ReadFile("./testcases/tests/userhost-split.yaml") + require.NoError(t, err) + + var userhostTests UserhostSplitTests + err = yaml.Unmarshal(data, &userhostTests) + require.NoError(t, err) + + for _, test := range userhostTests.Tests { + prefix := ParsePrefix(test.Source) + + assert.Equal(t, + test.Atoms.Nick, prefix.Name, + "Name did not match for input: %q", test.Source, + ) + assert.Equal(t, + test.Atoms.User, prefix.User, + "User did not match for input: %q", test.Source, + ) + assert.Equal(t, + test.Atoms.Host, prefix.Host, + "Host did not match for input: %q", test.Source, + ) + } +} diff --git a/testcases b/testcases new file mode 160000 index 0000000..e1a2ee1 --- /dev/null +++ b/testcases @@ -0,0 +1 @@ +Subproject commit e1a2ee15a29f90e66ff943c98b95b27acdedf406 From 6b3c88ff9c77fa5be6de218ce042c88d9c1d8065 Mon Sep 17 00:00:00 2001 From: Kaleb Elwert Date: Tue, 10 Jan 2017 03:08:04 -0800 Subject: [PATCH 2/7] Remove go files from the subrepo when testing in travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index cd867a3..494bd20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,8 @@ before_install: # Linting deps - go get github.com/alecthomas/gometalinter - gometalinter --install + # Remove the go file from the test cases dir as it fails linting + - rm ./testcases/*.go script: - gometalinter --fast ./... -D gas From f336c4f1077dc1153fd4aafe4b2119c10ff8244c Mon Sep 17 00:00:00 2001 From: Kaleb Elwert Date: Tue, 10 Jan 2017 03:10:36 -0800 Subject: [PATCH 3/7] gofmt -s --- client_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client_test.go b/client_test.go index bf49db8..8a32fa6 100644 --- a/client_test.go +++ b/client_test.go @@ -120,7 +120,7 @@ func TestClientHandler(t *testing.T) { }) assert.EqualValues(t, []*Message{ - &Message{ + { Tags: Tags{}, Prefix: &Prefix{}, Command: "001", @@ -133,7 +133,7 @@ func TestClientHandler(t *testing.T) { err = c.Run() assert.Equal(t, io.EOF, err) assert.EqualValues(t, []*Message{ - &Message{ + { Tags: Tags{}, Prefix: &Prefix{Name: "world"}, Command: "CTCP", @@ -147,7 +147,7 @@ func TestClientHandler(t *testing.T) { err = c.Run() assert.Equal(t, io.EOF, err) assert.EqualValues(t, []*Message{ - &Message{ + { Tags: Tags{}, Prefix: &Prefix{Name: "world"}, Command: "PRIVMSG", From b8a7e43b025b43b333f5f46fee90b2196d5d6b04 Mon Sep 17 00:00:00 2001 From: Kaleb Elwert Date: Tue, 10 Jan 2017 04:14:23 -0800 Subject: [PATCH 4/7] Remove my previous test cases --- parser_test.go | 462 +++++++++---------------------------------------- 1 file changed, 77 insertions(+), 385 deletions(-) diff --git a/parser_test.go b/parser_test.go index 6c603f3..54c0251 100644 --- a/parser_test.go +++ b/parser_test.go @@ -5,440 +5,124 @@ import ( "strings" "testing" - yaml "gopkg.in/yaml.v2" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + yaml "gopkg.in/yaml.v2" ) -var messageTests = []struct { - // Message parsing - Prefix, Cmd string - Params []string - - // Tag parsing - Tags Tags - - // Prefix parsing - Name, User, Host string - - // Total output - Expect string - ExpectIn []string - Err error - - // FromChannel - FromChan bool -}{ - { // Empty message should error - Err: ErrZeroLengthMessage, - }, - { // Make sure we've got a command - Expect: ":asd :", - Err: ErrMissingCommand, - }, - { // Need data after tags - Expect: "@A", - Err: ErrMissingDataAfterTags, - }, - { // Need data after prefix - Expect: ":A", - Err: ErrMissingDataAfterPrefix, - }, - { // Basic prefix test - Prefix: "server.kevlar.net", - Cmd: "PING", - - Name: "server.kevlar.net", - - Expect: ":server.kevlar.net PING\n", - }, - { // Trailing argument test - Prefix: "server.kevlar.net", - Cmd: "NOTICE", - Params: []string{"user", "*** This is a test"}, - - Name: "server.kevlar.net", - - Expect: ":server.kevlar.net NOTICE user :*** This is a test\n", - }, - { // Full prefix test - Prefix: "belakA!belakB@a.host.com", - Cmd: "PRIVMSG", - Params: []string{"#somewhere", "*** This is a test"}, - - Name: "belakA", - User: "belakB", - Host: "a.host.com", - - Expect: ":belakA!belakB@a.host.com PRIVMSG #somewhere :*** This is a test\n", - FromChan: true, - }, - { // Test : in the middle of a param - Prefix: "freenode", - Cmd: "005", - Params: []string{"starkbot", "CHANLIMIT=#:120", "MORE", "are supported by this server"}, - - Name: "freenode", - - Expect: ":freenode 005 starkbot CHANLIMIT=#:120 MORE :are supported by this server\n", - }, - { // Test FromChannel on a different channel prefix - Prefix: "belakA!belakB@a.host.com", - Cmd: "PRIVMSG", - Params: []string{"&somewhere", "*** This is a test"}, - - Name: "belakA", - User: "belakB", - Host: "a.host.com", - - Expect: ":belakA!belakB@a.host.com PRIVMSG &somewhere :*** This is a test\n", - FromChan: true, - }, - { // Test FromChannel on a single user - Prefix: "belakA!belakB@a.host.com", - Cmd: "PRIVMSG", - Params: []string{"belak", "*** This is a test"}, - - Name: "belakA", - User: "belakB", - Host: "a.host.com", - - Expect: ":belakA!belakB@a.host.com PRIVMSG belak :*** This is a test\n", - }, - { // Simple message - Cmd: "B", - Params: []string{"C"}, - Expect: "B C\n", - }, - { // Simple message with tags - Prefix: "A@B", - Cmd: "C", - Params: []string{"D"}, - - Name: "A", - Host: "B", - - Expect: ":A@B C D\n", - }, - { // Simple message with prefix - Prefix: "A", - Cmd: "B", - Params: []string{"C"}, - - Name: "A", - - Expect: ":A B C\n", - }, - { // Message with prefix and multiple params - Prefix: "A", - Cmd: "B", - Params: []string{"C", "D"}, - - Name: "A", - - Expect: ":A B C D\n", - }, - { // Message with empty trailing - Cmd: "A", - Params: []string{""}, - - Expect: "A :\n", - }, - { // Test basic tag parsing - Tags: Tags{ - "tag": "value", - }, - - Cmd: "A", - - Expect: "@tag=value A\n", - }, - { // Escaped \n in tag - Tags: Tags{ - "tag": "\n", - }, - - Cmd: "A", - - Expect: "@tag=\\n A\n", - }, - { // Escaped \ in tag - Tags: Tags{ - "tag": "\\", - }, - - Cmd: "A", - - Expect: "@tag=\\ A\n", - ExpectIn: []string{"@tag=\\\\ A\n"}, - }, - { // Escaped ; in tag - Tags: Tags{ - "tag": ";", - }, - - Cmd: "A", - - Expect: "@tag=\\: A\n", - }, - { // Empty tag - Tags: Tags{ - "tag": "", - }, - - Cmd: "A", - - Expect: "@tag A\n", - }, - { // Escaped & in tag - Tags: Tags{ - "tag": "\\&", - }, - - Cmd: "A", +func TestMustParseMessage(t *testing.T) { + t.Parallel() - Expect: "@tag=\\& A\n", - ExpectIn: []string{"@tag=\\\\& A\n"}, - }, - { // Multiple simple tags - Tags: Tags{ - "tag": "x", - "tag2": "asd", + var messageTests = []struct { + Input string + Err error + }{ + { + Input: "", + Err: ErrZeroLengthMessage, }, - - Cmd: "A", - - Expect: "@tag=x;tag2=asd A\n", - ExpectIn: []string{"@tag=x;tag2=asd A\n", "@tag2=asd;tag=x A\n"}, - }, - { // Complicated escaped tag - Tags: Tags{ - "tag": "; \\\r\n", + { + Input: "@asdf", + Err: ErrMissingDataAfterTags, }, - - Cmd: "A", - Expect: "@tag=\\:\\s\\\\\\r\\n A\n", - }, - { // Tags example from the spec - Tags: Tags{ - "aaa": "bbb", - "ccc": "", - "example.com/ddd": "eee", + { + Input: ":asdf", + Err: ErrMissingDataAfterPrefix, }, - - Name: "nick", - User: "ident", - Host: "host.com", - - Prefix: "nick!ident@host.com", - Cmd: "PRIVMSG", - Params: []string{"me", "Hello"}, - - Expect: "@aaa=bbb;ccc;example.com/ddd=eee :nick!ident@host.com PRIVMSG me :Hello\n", - ExpectIn: []string{ - "@aaa=bbb;ccc;example.com/ddd=eee :nick!ident@host.com PRIVMSG me Hello\n", - "@aaa=bbb;example.com/ddd=eee;ccc :nick!ident@host.com PRIVMSG me Hello\n", - "@ccc;aaa=bbb;example.com/ddd=eee :nick!ident@host.com PRIVMSG me Hello\n", - "@ccc;example.com/ddd=eee;aaa=bbb :nick!ident@host.com PRIVMSG me Hello\n", - "@example.com/ddd=eee;aaa=bbb;ccc :nick!ident@host.com PRIVMSG me Hello\n", - "@example.com/ddd=eee;ccc;aaa=bbb :nick!ident@host.com PRIVMSG me Hello\n", + { + Input: " :", + Err: ErrMissingCommand, }, - }, - { // = in tag - Tags: Tags{ - "a": "a=a", + { + Input: "PING :asdf", }, - - Name: "nick", - User: "ident", - Host: "host.com", - - Prefix: "nick!ident@host.com", - Cmd: "PRIVMSG", - Params: []string{"me", "Hello"}, - - Expect: "@a=a=a :nick!ident@host.com PRIVMSG me :Hello\n", - ExpectIn: []string{"@a=a=a :nick!ident@host.com PRIVMSG me Hello\n"}, - }, -} - -func TestMustParseMessage(t *testing.T) { - t.Parallel() + } for i, test := range messageTests { + m, err := ParseMessage(test.Input) + assert.Equal(t, test.Err, err, "%d. Error didn't match expected", i) + if test.Err != nil { assert.Panics(t, func() { - MustParseMessage(test.Expect) + MustParseMessage(test.Input) }, "%d. Didn't get expected panic", i) + + assert.Nil(t, m, "%d. Didn't get nil message", i) } else { assert.NotPanics(t, func() { - MustParseMessage(test.Expect) + MustParseMessage(test.Input) }, "%d. Got unexpected panic", i) - } - } -} - -func TestParseMessage(t *testing.T) { - t.Parallel() - for i, test := range messageTests { - m, err := ParseMessage(test.Expect) - if test.Err != nil { - assert.Equal(t, test.Err, err, "%d. Didn't get correct error for invalid message.", i) - } else { - assert.NotNil(t, m, "%d. Got nil for valid message.", i) + assert.NotNil(t, m, "%d. Got nil message", i) } - - if m == nil { - continue - } - - assert.Equal(t, test.Cmd, m.Command, "%d. Command doesn't match.", i) - assert.EqualValues(t, test.Params, m.Params, "%d. Params don't match.", i) - } -} - -func BenchmarkParseMessage(b *testing.B) { - for i := 0; i < b.N; i++ { - ParseMessage(messageTests[i%len(messageTests)].Prefix) - } -} - -func TestParsePrefix(t *testing.T) { - t.Parallel() - - for i, test := range messageTests { - pi := ParsePrefix(test.Prefix) - if pi == nil { - t.Errorf("%d. Got nil for valid identity", i) - continue - } - - assert.EqualValues(t, &Prefix{ - Name: test.Name, - User: test.User, - Host: test.Host, - }, pi, "%d. Identity did not match", i) - } -} - -func BenchmarkParsePrefix(b *testing.B) { - for i := 0; i < b.N; i++ { - ParsePrefix(messageTests[i%len(messageTests)].Expect) } } func TestMessageTrailing(t *testing.T) { t.Parallel() - for i, test := range messageTests { - if test.Err != nil { - continue - } + m := MustParseMessage("PING :helloworld") + assert.Equal(t, "helloworld", m.Trailing()) - m, _ := ParseMessage(test.Expect) - tr := m.Trailing() - if len(test.Params) < 1 { - assert.Equal(t, "", tr, "%d. Expected empty trailing", i) - } else { - assert.Equal(t, test.Params[len(test.Params)-1], tr, "%d. Expected matching traling", i) - } - } + m = MustParseMessage("PING") + assert.Equal(t, "", m.Trailing()) } func TestMessageFromChan(t *testing.T) { t.Parallel() - for i, test := range messageTests { - if test.Err != nil { - continue - } + m := MustParseMessage("PRIVMSG #test-msg :hello world") + assert.True(t, m.FromChannel(), "Wrong FromChannel value") - m, _ := ParseMessage(test.Expect) - assert.Equal(t, test.FromChan, m.FromChannel(), "%d. Wrong FromChannel value", i) - } + m = MustParseMessage("PRIVMSG bot :hello world") + assert.False(t, m.FromChannel(), "Wrong FromChannel value") + + m = MustParseMessage("PING") + assert.False(t, m.FromChannel(), "Wrong FromChannel value") } func TestMessageCopy(t *testing.T) { t.Parallel() - for i, test := range messageTests { - if test.Err != nil { - continue - } - - m, _ := ParseMessage(test.Expect) + m := MustParseMessage("@tag=val :user@host PING :helloworld") - c := m.Copy() - assert.EqualValues(t, m, c, "%d. Copied values are not equal", i) - - if len(m.Tags) > 0 { - c = m.Copy() - for k := range c.Tags { - c.Tags[k] += "junk" - } + // Ensure copied messages are equal + c := m.Copy() + assert.EqualValues(t, m, c, "Copied values are not equal") - assert.False(t, assert.ObjectsAreEqualValues(m, c), "%d. Copied with modified tags should not match", i) - } + // Ensure messages with modified tags don't match + c = m.Copy() + for k := range c.Tags { + c.Tags[k] += "junk" + } + assert.False(t, assert.ObjectsAreEqualValues(m, c), "Copied with modified tags should not match") - c = m.Copy() - c.Prefix.Name += "junk" - assert.False(t, assert.ObjectsAreEqualValues(m, c), "%d. Copied with modified identity should not match", i) + // Ensure messages with modified prefix don't match + c = m.Copy() + c.Prefix.Name += "junk" + assert.False(t, assert.ObjectsAreEqualValues(m, c), "Copied with modified identity should not match") - c = m.Copy() - c.Params = append(c.Params, "junk") - assert.False(t, assert.ObjectsAreEqualValues(m, c), "%d. Copied with additional params should not match", i) - } + // Ensure messages with modified params don't match + c = m.Copy() + c.Params = append(c.Params, "junk") + assert.False(t, assert.ObjectsAreEqualValues(m, c), "Copied with additional params should not match") // The message itself doesn't matter, we just need to make sure we // don't error if the user does something crazy and makes Params // nil. - m, _ := ParseMessage("PING :hello world") + m = MustParseMessage("PING :hello world") m.Prefix = nil - c := m.Copy() - + c = m.Copy() assert.EqualValues(t, m, c, "nil prefix copy failed") -} - -func TestMessageString(t *testing.T) { - t.Parallel() - - for i, test := range messageTests { - if test.Err != nil { - continue - } - m, _ := ParseMessage(test.Expect) - if test.ExpectIn != nil { - assert.Contains(t, test.ExpectIn, m.String()+"\n", "%d. Message Stringification failed", i) - } else { - assert.Equal(t, test.Expect, m.String()+"\n", "%d. Message Stringification failed", i) - } - } + // Ensure an empty Params is copied as nil + m = MustParseMessage("PING") + m.Params = []string{} + c = m.Copy() + assert.Nil(t, c.Params, "Expected nil for empty params") } -func TestMessageTags(t *testing.T) { - t.Parallel() - - for i, test := range messageTests { - if test.Err != nil || test.Tags == nil { - continue - } - - m, _ := ParseMessage(test.Expect) - assert.EqualValues(t, test.Tags, m.Tags, "%d. Tag parsing failed", i) - - // Ensure we have all the tags we expected. - for k, v := range test.Tags { - tag, ok := m.GetTag(k) - assert.True(t, ok, "%d. Missing tag %q", i, k) - assert.EqualValues(t, v, tag, "%d. Wrong tag value", i) - } - - assert.EqualValues(t, test.Tags, m.Tags, "%d. Tags don't match", i) - } -} +// Everything beyond here comes from the testcases repo type MsgSplitTests struct { Tests []struct { @@ -453,6 +137,8 @@ type MsgSplitTests struct { } func TestMsgSplit(t *testing.T) { + t.Parallel() + data, err := ioutil.ReadFile("./testcases/tests/msg-split.yaml") require.NoError(t, err) @@ -483,10 +169,12 @@ func TestMsgSplit(t *testing.T) { ) for k, v := range test.Atoms.Tags { + tag, ok := msg.GetTag(k) + assert.True(t, ok, "Missing tag") if v == nil { - assert.EqualValues(t, "", msg.Tags[k], "Tag differs") + assert.EqualValues(t, "", tag, "Tag differs") } else { - assert.EqualValues(t, v, msg.Tags[k], "Tag differs") + assert.EqualValues(t, v, tag, "Tag differs") } } } @@ -505,6 +193,8 @@ type MsgJoinTests struct { } func TestMsgJoin(t *testing.T) { + t.Parallel() + data, err := ioutil.ReadFile("./testcases/tests/msg-join.yaml") require.NoError(t, err) @@ -544,6 +234,8 @@ type UserhostSplitTests struct { } func TestUserhostSplit(t *testing.T) { + t.Parallel() + data, err := ioutil.ReadFile("./testcases/tests/userhost-split.yaml") require.NoError(t, err) From 98f7ad8dc125be6db26f70f99805a19468568dfd Mon Sep 17 00:00:00 2001 From: Kaleb Elwert Date: Tue, 10 Jan 2017 04:20:54 -0800 Subject: [PATCH 5/7] Update tag parsing from feedback --- parser.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/parser.go b/parser.go index 8a3cbc6..8ec439d 100644 --- a/parser.go +++ b/parser.go @@ -59,15 +59,16 @@ func ParseTagValue(v string) TagValue { if c == '\\' { c2, _, err := input.ReadRune() + + // If we got a backslash then the end of the tag value, we should + // just ignore the backslash. if err != nil { - ret.WriteRune(c) break } if replacement, ok := tagDecodeSlashMap[c2]; ok { ret.WriteRune(replacement) } else { - ret.WriteRune(c) ret.WriteRune(c2) } } else { From e8fe94ecc56ebf29650974f76303beb2192f5755 Mon Sep 17 00:00:00 2001 From: Kaleb Elwert Date: Tue, 10 Jan 2017 10:33:55 -0800 Subject: [PATCH 6/7] Change submodule url --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 8c73f7c..8ed3899 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "testcases"] path = testcases - url = https://github.com/DanielOaks/irc-parser-tests/ + url = https://github.com/go-irc/irc-parser-tests/ From b1d4625bdbbe80bebd74ea54793b8af17fe4899a Mon Sep 17 00:00:00 2001 From: Kaleb Elwert Date: Tue, 10 Jan 2017 10:43:53 -0800 Subject: [PATCH 7/7] Update parser tests to include tag value edge cases --- testcases | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testcases b/testcases index e1a2ee1..cb0cf57 160000 --- a/testcases +++ b/testcases @@ -1 +1 @@ -Subproject commit e1a2ee15a29f90e66ff943c98b95b27acdedf406 +Subproject commit cb0cf5737a8ba01feff4e3423d87fb356258f361