forked from andar/go_nibbler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnibbler_test.go
More file actions
100 lines (94 loc) · 5.01 KB
/
nibbler_test.go
File metadata and controls
100 lines (94 loc) · 5.01 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package go_nibbler
import (
"strings"
"testing"
)
type example struct {
Input string
Valid bool
Address string
}
var validExamples = []example{
example{"hi@style--plus.com", true, "hi@style--plus.com"},
example{"test@domain---with-multiple-hyphens.com", true, "test@domain---with-multiple-hyphens.com"},
example{"hoot@hoot-hoot.com", true, "hoot@hoot-hoot.com"},
example{"woo/+@blah.com", true, "woo/+@blah.com"},
example{"üñîçøðé@üñîçøðéı.com", true, "üñîçøðé@üñîçøðéı.com"},
example{"johndoe@example.co.uk", true, "johndoe@example.co.uk"},
example{"niceandsimple@example.com", true, "niceandsimple@example.com"},
example{"very.common@example.com", true, "very.common@example.com"},
example{"a.little.lengthy.but.fine@dept.example.com", true, "a.little.lengthy.but.fine@dept.example.com"},
example{"disposable.style.email.with+symbol@example.com", true, "disposable.style.email.with+symbol@example.com"},
example{"other.email-with-dash@example.com", true, "other.email-with-dash@example.com"},
example{`"much.more unusual"@example.com`, true, `"much.more unusual"@example.com`},
example{`"very.unusual.@.unusual.com"@example.com`, true, `"very.unusual.@.unusual.com"@example.com`},
example{`"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com`, true, `"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com`},
example{"postbox@com", true, "postbox@com"},
example{"admin@mailserver1", true, "admin@mailserver1"},
example{"!#$%&'*+-/=?^_`{}|~@example.org", true, "!#$%&'*+-/=?^_`{}|~@example.org"},
example{`"()<>[]:,;@\\\"!#$%&'*+-/=?^_` + "`{}| ~.a\"@example.org", true, `"()<>[]:,;@\\\"!#$%&'*+-/=?^_` + "`{}| ~.a\"@example.org"},
example{`" "@example.org`, true, `" "@example.org`},
example{`abc."defghi".xyz@example.com`, true, `abc."defghi".xyz@example.com`},
example{`"two..dot"@example.com`, true, `"two..dot"@example.com`},
example{`"test."@example.com`, true, `"test."@example.com`},
example{"_somename@example.com", true, "_somename@example.com"},
example{"customer/department=shipping@example.com", true, "customer/department=shipping@example.com"},
example{"!def!xyz.c%abc+@example.com", true, "!def!xyz.c%abc+@example.com"},
example{"1234567890.0987654321@EXAMPLE.WHATEVER.ABC.123.CAT", true, "1234567890.0987654321@EXAMPLE.WHATEVER.ABC.123.CAT"},
example{"relay.mil%john.smith@EXAMPLE-WHATEVER.ARPA", true, "relay.mil%john.smith@EXAMPLE-WHATEVER.ARPA"},
example{"joe@123.45.67.89", true, "joe@123.45.67.89"},
example{"joe@2001:0db8::1428:57ab", true, "joe@2001:0db8::1428:57ab"},
example{`"first".second@employs.allowable.trick`, true, `"first".second@employs.allowable.trick`},
example{`""@the-void.example.com`, true, `""@the-void.example.com`},
}
var invalidExamples = []example{
example{"woo", false, "woo"},
example{"\"Bob\" <bobthebuilder@dlc.com>", false, "\"Bob\""},
example{"[j\\k]l@example.com", false, ""},
example{" johndoe@example.com", false, ""},
example{"johndoe@example.com ", false, "johndoe@example.com"},
example{"Abc.example.com", false, "Abc.example.com"},
example{"A@b@c@example.com", false, "A@b"},
example{`a"b(c)d,e:f;g<h>i[j\\k]l@example.com`, false, `a`},
example{`just"not"right@example.com`, false, `just`},
example{`this is"not\\allowed@example.com`, false, `this`},
example{`this\\ still\\"not\\\\allowed@example.com`, false, `this`},
example{`abc"defghi"xyz@example.com`, false, `abc`},
example{"invalid@", false, "invalid"},
example{"john@example...com", false, "john@example."},
example{"test@.com", false, "test@"},
example{"test@-.com", false, "test@"},
example{"test@-example.com", false, "test@"}, // Dash at start of domain
example{"test@example.com-", false, "test@example.com"}, // Dash at end of domain
example{".invalid@example.com", false, ""},
example{"invalid.@example.com", false, "invalid."},
example{"@example.com", false, ""},
example{"hello world@example.com", false, "hello"},
example{"bird@test example.com", false, "bird@test"},
example{`\$A12345@example.com`, false, ""},
example{`"quote@example.com`, false, `"quote@example.com`},
example{`quote\"@example.com`, false, `quote`},
example{"two..dot@example.com", false, "two."},
example{"user@???", false, "user@"},
example{"user@example-.com", false, "user@example-"},
example{"user@test.-example.com", false, "user@test."},
example{"test@example.com.", false, "test@example.com"},
example{"test@[example.com]", false, "test@"},
example{strings.Repeat("a", 255), false, strings.Repeat("a", 254)},
}
func TestValidEmail(t *testing.T) {
for _, e := range validExamples {
valid, address := ParseEmail(e.Input)
if valid != e.Valid || address != e.Address {
t.Errorf("Failed for \"%s\": wanted {%t, %s}, got {%t, %s}", e.Input, e.Valid, e.Address, valid, address)
}
}
}
func TestInvalidEmail(t *testing.T) {
for _, e := range invalidExamples {
valid, address := ParseEmail(e.Input)
if valid != e.Valid || address != e.Address {
t.Errorf("Failed for \"%s\": wanted {%t, %s}, got {%t, %s}", e.Input, e.Valid, e.Address, valid, address)
}
}
}