-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
postcode_test.go
71 lines (68 loc) · 1.39 KB
/
postcode_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
package postcode
import (
"testing"
)
func TestValidate(t *testing.T) {
testCases := []struct {
description string
input string
expected error
}{
{
description: "Paris, France",
input: " 75008 ",
expected: nil,
},
{
description: "Brussels, Belgium",
input: " 1000 ",
expected: nil,
},
{
description: "Utrecht, The Netherlands",
input: " 3511 ax ",
expected: nil,
},
{
description: "Utrecht, The Netherlands, Alt",
input: " 3511AX ",
expected: nil,
},
{
description: "Hannover, Germany",
input: " 30179 ",
expected: nil,
},
{
description: "Vilnius, Lithuania",
input: "LT-00200",
expected: nil,
},
{
description: "Empty postal code",
input: "",
expected: ErrEmpty,
},
{
description: "Short postal code",
input: "A",
expected: ErrShort,
},
{
description: "Inexistent country code",
input: "TY 1234",
expected: ErrInvalidCountry,
},
{
description: "Inexistent postal code format",
input: "11111111111",
expected: ErrInvalidFormat,
},
}
for _, testCase := range testCases {
t.Logf("Validating `%s` (%s)", testCase.input, testCase.description)
if err := Validate(testCase.input); err != testCase.expected {
t.Errorf("expected: %v; got: %v", testCase.expected, err)
}
}
}