Skip to content

Commit

Permalink
Merge pull request #111 from gempir/pajlada/fix-tests
Browse files Browse the repository at this point in the history
Actually run tests, and fix the ones that were broken.
Also test for the error case reported in #110
  • Loading branch information
pajlada committed Nov 13, 2019
2 parents 29ec318 + 6f3888a commit 1ea7808
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 92 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: go
sudo: false
go:
- 1.10.x
- 1.11.x
- 1.12.x
- 1.13.x
before_install:
- go get github.com/mattn/goveralls
- go get github.com/prometheus/client_golang/prometheus
Expand Down
2 changes: 1 addition & 1 deletion cmd/pingpong/pingpong.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"log"
"strings"

twitch "github.com/gempir/go-twitch-irc"
twitch "github.com/gempir/go-twitch-irc/v2"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func assertStringSlicesEqual(t *testing.T, expected, actual []string) {
}

if len(actual) != len(expected) {
t.Errorf("actual slice was not the same length as expected slice")
t.Errorf("actual slice(%#v)(%d) was not the same length as expected slice(%#v)(%d)", actual, len(actual), expected, len(expected))
}

for i, v := range actual {
Expand Down
19 changes: 11 additions & 8 deletions irc.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,20 @@ func parseIRCTags(rawTags string) map[string]string {
return tags
}

var escapeCharacters = map[string]string{
"\\s": " ",
"\\n": "",
"\\r": "",
"\\:": ";",
"\\\\": "\\",
var tagEscapeCharacters = []struct {
from string
to string
}{
{`\s`, ` `},
{`\n`, ``},
{`\r`, ``},
{`\:`, `;`},
{`\\`, `\`},
}

func parseIRCTagValue(rawValue string) string {
for char, value := range escapeCharacters {
rawValue = strings.Replace(rawValue, char, value, -1)
for _, escape := range tagEscapeCharacters {
rawValue = strings.Replace(rawValue, escape.from, escape.to, -1)
}

rawValue = strings.TrimSuffix(rawValue, "\\")
Expand Down
18 changes: 9 additions & 9 deletions irc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

type ircTest struct {
input string
expected ircMessage
Input string
Expected ircMessage
}

func ircTests() ([]*ircTest, error) {
Expand Down Expand Up @@ -37,18 +37,18 @@ func TestCanParseIRCMessage(t *testing.T) {
}

for _, test := range tests {
actual, err := parseIRCMessage(test.input)
actual, err := parseIRCMessage(test.Input)
if err != nil {
t.Error(err)
continue
}

assertStringMapsEqual(t, test.expected.Tags, actual.Tags)
assertStringsEqual(t, test.expected.Source.Nickname, actual.Source.Nickname)
assertStringsEqual(t, test.expected.Source.Username, actual.Source.Username)
assertStringsEqual(t, test.expected.Source.Host, actual.Source.Host)
assertStringsEqual(t, test.expected.Command, actual.Command)
assertStringSlicesEqual(t, test.expected.Params, actual.Params)
assertStringMapsEqual(t, test.Expected.Tags, actual.Tags)
assertStringsEqual(t, test.Expected.Source.Nickname, actual.Source.Nickname)
assertStringsEqual(t, test.Expected.Source.Username, actual.Source.Username)
assertStringsEqual(t, test.Expected.Source.Host, actual.Source.Host)
assertStringsEqual(t, test.Expected.Command, actual.Command)
assertStringSlicesEqual(t, test.Expected.Params, actual.Params)
}
}

Expand Down
Loading

0 comments on commit 1ea7808

Please sign in to comment.