@@ -20,6 +20,7 @@ import (
20
20
21
21
"github.com/DanielOaks/girc-go/ircmatch"
22
22
"github.com/DanielOaks/girc-go/ircmsg"
23
+ "github.com/DanielOaks/girc-go/ircutils"
23
24
"github.com/docopt/docopt-go"
24
25
)
25
26
@@ -58,6 +59,18 @@ type MaskMatchTests struct {
58
59
}
59
60
}
60
61
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
+
61
74
func main () {
62
75
version := "irc-parser-tests 0.1.0"
63
76
usage := `irc-parser-tests Go script.
@@ -78,6 +91,9 @@ Options:
78
91
// msg-split tests
79
92
fmt .Println ("Running split tests" )
80
93
94
+ passed = 0
95
+ failed = 0
96
+
81
97
data , err := ioutil .ReadFile ("tests/msg-split.yaml" )
82
98
if err != nil {
83
99
log .Fatal ("Could not open test file msg-split.yaml:" , err .Error ())
@@ -90,9 +106,6 @@ Options:
90
106
log .Fatal ("Could not unmarshal msg-split.yaml test file:" , err .Error ())
91
107
}
92
108
93
- passed = 0
94
- failed = 0
95
-
96
109
for _ , test := range msgSplitTests .Tests {
97
110
msg , err := ircmsg .ParseLine (test .Input )
98
111
@@ -222,9 +235,6 @@ Options:
222
235
log .Fatal ("Could not unmarshal msg-join.yaml test file:" , err .Error ())
223
236
}
224
237
225
- passed = 0
226
- failed = 0
227
-
228
238
for _ , test := range msgJoinTests .Tests {
229
239
var tags * map [string ]ircmsg.TagValue
230
240
if test .Atoms .Tags != nil {
@@ -283,9 +293,6 @@ Options:
283
293
log .Fatal ("Could not unmarshal mask-match.yaml test file:" , err .Error ())
284
294
}
285
295
286
- passed = 0
287
- failed = 0
288
-
289
296
for _ , test := range maskMatchTests .Tests {
290
297
mask := ircmatch .MakeMatch (test .Mask )
291
298
@@ -312,5 +319,51 @@ Options:
312
319
313
320
fmt .Println (" * Passed tests:" , passed )
314
321
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 )
315
368
}
316
369
}
0 commit comments