Skip to content

Commit ed3c9a9

Browse files
authored
Start moving to a common set of test cases (#49)
* Start moving to a common set of test cases * Remove go files from the subrepo when testing in travis * gofmt -s * Remove my previous test cases * Update tag parsing from feedback * Change submodule url * Update parser tests to include tag value edge cases
1 parent 762af81 commit ed3c9a9

File tree

7 files changed

+217
-377
lines changed

7 files changed

+217
-377
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "testcases"]
2+
path = testcases
3+
url = https://github.com/go-irc/irc-parser-tests/

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ before_install:
99
# Linting deps
1010
- go get github.com/alecthomas/gometalinter
1111
- gometalinter --install
12+
# Remove the go file from the test cases dir as it fails linting
13+
- rm ./testcases/*.go
1214

1315
script:
1416
- gometalinter --fast ./... -D gas

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ As a result of this, there are multiple import locations.
3333
tagged as stable
3434
* `github.com/go-irc/irc` should be used to develop against the master branch
3535

36+
## Development
37+
38+
In order to run the tests, make sure all submodules are up to date. If you are
39+
just using this library, these are not needed.
40+
3641
## Example
3742

3843
```go

client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func TestClientHandler(t *testing.T) {
120120
})
121121

122122
assert.EqualValues(t, []*Message{
123-
&Message{
123+
{
124124
Tags: Tags{},
125125
Prefix: &Prefix{},
126126
Command: "001",
@@ -133,7 +133,7 @@ func TestClientHandler(t *testing.T) {
133133
err = c.Run()
134134
assert.Equal(t, io.EOF, err)
135135
assert.EqualValues(t, []*Message{
136-
&Message{
136+
{
137137
Tags: Tags{},
138138
Prefix: &Prefix{Name: "world"},
139139
Command: "CTCP",
@@ -147,7 +147,7 @@ func TestClientHandler(t *testing.T) {
147147
err = c.Run()
148148
assert.Equal(t, io.EOF, err)
149149
assert.EqualValues(t, []*Message{
150-
&Message{
150+
{
151151
Tags: Tags{},
152152
Prefix: &Prefix{Name: "world"},
153153
Command: "PRIVMSG",

parser.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,16 @@ func ParseTagValue(v string) TagValue {
5959

6060
if c == '\\' {
6161
c2, _, err := input.ReadRune()
62+
63+
// If we got a backslash then the end of the tag value, we should
64+
// just ignore the backslash.
6265
if err != nil {
63-
ret.WriteRune(c)
6466
break
6567
}
6668

6769
if replacement, ok := tagDecodeSlashMap[c2]; ok {
6870
ret.WriteRune(replacement)
6971
} else {
70-
ret.WriteRune(c)
7172
ret.WriteRune(c2)
7273
}
7374
} else {
@@ -305,6 +306,12 @@ func ParseMessage(line string) (*Message, error) {
305306
c.Command = strings.ToUpper(c.Params[0])
306307
c.Params = c.Params[1:]
307308

309+
// If there are no params, set it to nil, to make writing tests and other
310+
// things simpler.
311+
if len(c.Params) == 0 {
312+
c.Params = nil
313+
}
314+
308315
return c, nil
309316
}
310317

@@ -354,6 +361,11 @@ func (m *Message) Copy() *Message {
354361
// Copy the Params slice
355362
newMessage.Params = append(make([]string, 0, len(m.Params)), m.Params...)
356363

364+
// Similar to parsing, if Params is empty, set it to nil
365+
if len(newMessage.Params) == 0 {
366+
newMessage.Params = nil
367+
}
368+
357369
return newMessage
358370
}
359371

0 commit comments

Comments
 (0)