-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaddress_test.go
76 lines (71 loc) · 1.81 KB
/
address_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package emlparser
import (
"reflect"
"testing"
)
// We use examples from RFC5322 as our test suite.
type parseAddressTest struct {
addrStr string
addrRes Address
}
var parseAddressTests = []parseAddressTest{
parseAddressTest{
`"Joe Q. Public" <[email protected]>`,
MailboxAddr{`"Joe Q. Public"`, `john.q.public`, `example.com`},
},
parseAddressTest{
`Mary Smith <[email protected]>`,
MailboxAddr{`Mary Smith`, `mary`, `x.test`},
},
parseAddressTest{
MailboxAddr{``, `jdoe`, `example.org`},
},
parseAddressTest{
`Who? <[email protected]>`,
MailboxAddr{`Who?`, `one`, `y.test`},
},
parseAddressTest{
`<[email protected]>`,
MailboxAddr{``, `boss`, `nil.test`},
},
parseAddressTest{
`"Giant; \"Big\" Box" <[email protected]>`,
MailboxAddr{`"Giant; \"Big\" Box"`, `sysservices`, `example.net`},
},
parseAddressTest{
`Pete <[email protected]>`,
MailboxAddr{`Pete`, `pete`, `silly.example`},
},
parseAddressTest{
GroupAddr{
`A Group`,
[]MailboxAddr{
MailboxAddr{`Ed Jones`, `c`, `a.test`},
MailboxAddr{``, `joe`, `where.test`},
MailboxAddr{`John`, `jdoe`, `one.test`},
},
},
},
parseAddressTest{
`Undisclosed recipients:;`,
GroupAddr{`Undisclosed recipients`, []MailboxAddr{}},
},
parseAddressTest{
`Undisclosed recipients: ;`,
GroupAddr{`Undisclosed recipients`, []MailboxAddr{}},
},
}
func TestParseAddress(t *testing.T) {
for _, pt := range parseAddressTests {
address, err := ParseAddress([]byte(pt.addrStr))
if err != nil {
t.Errorf("ParseAddress returned error for %#V", pt.addrStr)
} else if !reflect.DeepEqual(address, pt.addrRes) {
t.Errorf(
"ParseAddress: incorrect result for %#V: gave %#V; expected %#V",
pt.addrStr, address, pt.addrRes)
}
}
}