Skip to content

Commit

Permalink
Start moving to a common set of test cases (#49)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
belak authored Jan 11, 2017
1 parent 762af81 commit ed3c9a9
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 377 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "testcases"]
path = testcases
url = https://github.com/go-irc/irc-parser-tests/
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestClientHandler(t *testing.T) {
})

assert.EqualValues(t, []*Message{
&Message{
{
Tags: Tags{},
Prefix: &Prefix{},
Command: "001",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
16 changes: 14 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -305,6 +306,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
}

Expand Down Expand Up @@ -354,6 +361,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
}

Expand Down
Loading

0 comments on commit ed3c9a9

Please sign in to comment.