-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathparser_test.go
42 lines (35 loc) · 924 Bytes
/
parser_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
p "github.com/mpapi/failmail/parse"
"testing"
)
type ParserTestCase struct {
Verify func(*p.Node) bool
Input string
}
func failed(node *p.Node) bool {
return node == nil
}
func ok(node *p.Node) bool {
return node != nil
}
var parserTests = []ParserTestCase{
ParserTestCase{ok, "HELO example.com\r\n"},
ParserTestCase{ok, "HELO [10.130.27.199]\r\n"},
ParserTestCase{failed, "HELO\r\n"},
ParserTestCase{ok, "VRFY user\r\n"},
ParserTestCase{ok, "AUTH PLAIN dGVzdA==\r\n"},
ParserTestCase{failed, "AUTH badtype dGVzdA==\r\n"},
ParserTestCase{failed, "AUTH PLAIN notb64*=\r\n"},
ParserTestCase{ok, "AUTH PLAIN\r\n"},
ParserTestCase{failed, "AUTH PLAIN \r\n"},
}
func TestSMTPParser(t *testing.T) {
parser := SMTPParser()
for _, test := range parserTests {
result := parser(test.Input)
if !test.Verify(result) {
t.Errorf("unexpected parse result for %s", test.Input)
}
}
}