Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ace0d6c

Browse files
committedNov 28, 2016
Rename mask-split to userhost-split
1 parent 0fbb4e2 commit ace0d6c

File tree

3 files changed

+65
-12
lines changed

3 files changed

+65
-12
lines changed
 

‎test.go

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/DanielOaks/girc-go/ircmatch"
2222
"github.com/DanielOaks/girc-go/ircmsg"
23+
"github.com/DanielOaks/girc-go/ircutils"
2324
"github.com/docopt/docopt-go"
2425
)
2526

@@ -58,6 +59,18 @@ type MaskMatchTests struct {
5859
}
5960
}
6061

62+
// MaskSplitTests holds the test cases for IRC userhost splitting.
63+
type MaskSplitTests struct {
64+
Tests []struct {
65+
Source string
66+
Atoms struct {
67+
Nick string
68+
User string
69+
Host string
70+
}
71+
}
72+
}
73+
6174
func main() {
6275
version := "irc-parser-tests 0.1.0"
6376
usage := `irc-parser-tests Go script.
@@ -78,6 +91,9 @@ Options:
7891
// msg-split tests
7992
fmt.Println("Running split tests")
8093

94+
passed = 0
95+
failed = 0
96+
8197
data, err := ioutil.ReadFile("tests/msg-split.yaml")
8298
if err != nil {
8399
log.Fatal("Could not open test file msg-split.yaml:", err.Error())
@@ -90,9 +106,6 @@ Options:
90106
log.Fatal("Could not unmarshal msg-split.yaml test file:", err.Error())
91107
}
92108

93-
passed = 0
94-
failed = 0
95-
96109
for _, test := range msgSplitTests.Tests {
97110
msg, err := ircmsg.ParseLine(test.Input)
98111

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

225-
passed = 0
226-
failed = 0
227-
228238
for _, test := range msgJoinTests.Tests {
229239
var tags *map[string]ircmsg.TagValue
230240
if test.Atoms.Tags != nil {
@@ -283,9 +293,6 @@ Options:
283293
log.Fatal("Could not unmarshal mask-match.yaml test file:", err.Error())
284294
}
285295

286-
passed = 0
287-
failed = 0
288-
289296
for _, test := range maskMatchTests.Tests {
290297
mask := ircmatch.MakeMatch(test.Mask)
291298

@@ -312,5 +319,51 @@ Options:
312319

313320
fmt.Println(" * Passed tests:", passed)
314321
fmt.Println(" * Failed tests:", failed)
322+
323+
// mask splitting tests
324+
fmt.Println("Running userhost splitting tests")
325+
326+
passed = 0
327+
failed = 0
328+
329+
data, err = ioutil.ReadFile("tests/userhost-split.yaml")
330+
if err != nil {
331+
log.Fatal("Could not open test file userhost-split.yaml:", err.Error())
332+
}
333+
334+
var maskSplitTests *MaskSplitTests
335+
336+
err = yaml.Unmarshal(data, &maskSplitTests)
337+
if err != nil {
338+
log.Fatal("Could not unmarshal userhost-split.yaml test file:", err.Error())
339+
}
340+
341+
for _, test := range maskSplitTests.Tests {
342+
uh := ircutils.ParseUserhost(test.Source)
343+
344+
var testfailed bool
345+
346+
if uh.Nick != test.Atoms.Nick {
347+
fmt.Println(fmt.Sprintf("Expected nick from userhost [%s] to match test [%s] but it was [%s].", test.Source, test.Atoms.Nick, uh.Nick))
348+
testfailed = true
349+
}
350+
if uh.User != test.Atoms.User {
351+
fmt.Println(fmt.Sprintf("Expected user from userhost [%s] to match test [%s] but it was [%s].", test.Source, test.Atoms.User, uh.User))
352+
testfailed = true
353+
}
354+
if uh.Host != test.Atoms.Host {
355+
fmt.Println(fmt.Sprintf("Expected host from userhost [%s] to match test [%s] but it was [%s].", test.Source, test.Atoms.Host, uh.Host))
356+
testfailed = true
357+
}
358+
359+
if testfailed {
360+
failed++
361+
} else {
362+
passed++
363+
}
364+
}
365+
366+
fmt.Println(" * Passed tests:", passed)
367+
fmt.Println(" * Failed tests:", failed)
315368
}
316369
}

‎test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121

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

126126
failed_tests = 0
127127
passed_tests = 0

‎tests/mask-split.yaml renamed to ‎tests/userhost-split.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# IRC parser tests
2-
# splitting nickmasks into atoms
2+
# splitting userhosts into atoms
33

44
# Written in 2015 by Daniel Oaks <daniel@danieloaks.net>
55
#
@@ -12,7 +12,7 @@
1212
# <http://creativecommons.org/publicdomain/zero/1.0/>.
1313

1414
tests:
15-
# source is the mask directly
15+
# source is the usthost
1616

1717
# the atoms dict has the keys:
1818
# * nick: nick string

0 commit comments

Comments
 (0)
Please sign in to comment.