Skip to content

Commit

Permalink
Rename mask-split to userhost-split
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielOaks committed Nov 28, 2016
1 parent 0fbb4e2 commit ace0d6c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 12 deletions.
71 changes: 62 additions & 9 deletions test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/DanielOaks/girc-go/ircmatch"
"github.com/DanielOaks/girc-go/ircmsg"
"github.com/DanielOaks/girc-go/ircutils"
"github.com/docopt/docopt-go"
)

Expand Down Expand Up @@ -58,6 +59,18 @@ type MaskMatchTests struct {
}
}

// MaskSplitTests holds the test cases for IRC userhost splitting.
type MaskSplitTests struct {
Tests []struct {
Source string
Atoms struct {
Nick string
User string
Host string
}
}
}

func main() {
version := "irc-parser-tests 0.1.0"
usage := `irc-parser-tests Go script.
Expand All @@ -78,6 +91,9 @@ Options:
// msg-split tests
fmt.Println("Running split tests")

passed = 0
failed = 0

data, err := ioutil.ReadFile("tests/msg-split.yaml")
if err != nil {
log.Fatal("Could not open test file msg-split.yaml:", err.Error())
Expand All @@ -90,9 +106,6 @@ Options:
log.Fatal("Could not unmarshal msg-split.yaml test file:", err.Error())
}

passed = 0
failed = 0

for _, test := range msgSplitTests.Tests {
msg, err := ircmsg.ParseLine(test.Input)

Expand Down Expand Up @@ -222,9 +235,6 @@ Options:
log.Fatal("Could not unmarshal msg-join.yaml test file:", err.Error())
}

passed = 0
failed = 0

for _, test := range msgJoinTests.Tests {
var tags *map[string]ircmsg.TagValue
if test.Atoms.Tags != nil {
Expand Down Expand Up @@ -283,9 +293,6 @@ Options:
log.Fatal("Could not unmarshal mask-match.yaml test file:", err.Error())
}

passed = 0
failed = 0

for _, test := range maskMatchTests.Tests {
mask := ircmatch.MakeMatch(test.Mask)

Expand All @@ -312,5 +319,51 @@ Options:

fmt.Println(" * Passed tests:", passed)
fmt.Println(" * Failed tests:", failed)

// mask splitting tests
fmt.Println("Running userhost splitting tests")

passed = 0
failed = 0

data, err = ioutil.ReadFile("tests/userhost-split.yaml")
if err != nil {
log.Fatal("Could not open test file userhost-split.yaml:", err.Error())
}

var maskSplitTests *MaskSplitTests

err = yaml.Unmarshal(data, &maskSplitTests)
if err != nil {
log.Fatal("Could not unmarshal userhost-split.yaml test file:", err.Error())
}

for _, test := range maskSplitTests.Tests {
uh := ircutils.ParseUserhost(test.Source)

var testfailed bool

if uh.Nick != test.Atoms.Nick {
fmt.Println(fmt.Sprintf("Expected nick from userhost [%s] to match test [%s] but it was [%s].", test.Source, test.Atoms.Nick, uh.Nick))
testfailed = true
}
if uh.User != test.Atoms.User {
fmt.Println(fmt.Sprintf("Expected user from userhost [%s] to match test [%s] but it was [%s].", test.Source, test.Atoms.User, uh.User))
testfailed = true
}
if uh.Host != test.Atoms.Host {
fmt.Println(fmt.Sprintf("Expected host from userhost [%s] to match test [%s] but it was [%s].", test.Source, test.Atoms.Host, uh.Host))
testfailed = true
}

if testfailed {
failed++
} else {
passed++
}
}

fmt.Println(" * Passed tests:", passed)
fmt.Println(" * Failed tests:", failed)
}
}
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@

# NICKMASK Tests
print('Running nickmask tests')
data = yaml.safe_load(open('tests/mask-split.yaml').read())
data = yaml.safe_load(open('tests/userhost-split.yaml').read())

failed_tests = 0
passed_tests = 0
Expand Down
4 changes: 2 additions & 2 deletions tests/mask-split.yaml → tests/userhost-split.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# IRC parser tests
# splitting nickmasks into atoms
# splitting userhosts into atoms

# Written in 2015 by Daniel Oaks <[email protected]>
#
Expand All @@ -12,7 +12,7 @@
# <http://creativecommons.org/publicdomain/zero/1.0/>.

tests:
# source is the mask directly
# source is the usthost

# the atoms dict has the keys:
# * nick: nick string
Expand Down

0 comments on commit ace0d6c

Please sign in to comment.