-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnormalizer_test.go
148 lines (138 loc) · 3.3 KB
/
normalizer_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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package addy
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNormalizeAddress1(t *testing.T) {
var tests = []struct {
name string
input string
options []option
expOutput string
expCount int
}{
{
name: "1 match",
input: "42 wallaby way",
expOutput: "42 WALLABY WAY",
expCount: 1,
},
{
name: "2 matches, replacements",
input: "401 North Coast Highway",
expOutput: "401 N COAST HWY",
expCount: 2,
},
{
name: "1 match, replacement; remove spaces",
input: " 1465 c street ",
expOutput: "1465 C ST",
expCount: 1,
},
{
name: "1 match, replacement; lowercased",
input: "976 Cherry Lane",
options: []option{OptionLowerCase},
expOutput: "976 cherry ln",
expCount: 1,
},
{
name: "2 matches, replacements; titlecased",
input: "23 n columbus circle",
options: []option{OptionTitleCase},
expOutput: "23 N Columbus Cir",
expCount: 2,
},
{
name: "1 match, replacement; uppercase",
input: "8400 south charles",
options: []option{OptionUpperCase},
expOutput: "8400 S CHARLES",
expCount: 1,
},
{
name: "2 matches, replacements; preserve titlecase",
input: "101 South Broadway Avenue",
options: []option{OptionPreserveCase},
expOutput: "101 S Broadway Ave",
expCount: 2,
},
{
name: "1 match, replacement; preserve lowercase",
input: "1465 c street",
options: []option{OptionPreserveCase},
expOutput: "1465 c st",
expCount: 1,
},
{
name: "1 match, replacement; preserve uppercase",
input: "904 LIBERTY PLACE",
options: []option{OptionPreserveCase},
expOutput: "904 LIBERTY PL",
expCount: 1,
},
{
name: "3 matches, replacements; preserve multicase",
input: "84 east Martin luther KIng BouLevard ROAD",
options: []option{OptionPreserveCase},
expOutput: "84 e Martin luther KIng Blvd RD",
expCount: 3,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
output, count := NormalizeAddress1(tt.input, tt.options...)
assert.Equal(t, tt.expOutput, output)
assert.Equal(t, tt.expCount, count)
})
}
}
func TestNormalizeAddress2(t *testing.T) {
var tests = []struct {
name string
input string
options []option
expOutput string
expCount int
}{
{
name: "1 match",
input: "unit 10",
expOutput: "UNIT 10",
expCount: 1,
},
{
name: "2 matches, replacement",
input: "p.o. box 44",
expOutput: "PO BOX 44",
expCount: 2,
},
{
name: "1 match, replacement; remove spaces",
input: " 32nd floor ",
expOutput: "32ND FL",
expCount: 1,
},
{
name: "2 matches, replacement; PO not cased",
input: "p.o. box 98",
options: []option{OptionTitleCase},
expOutput: "PO Box 98",
expCount: 2,
},
{
name: "2 matches, replacement; PO cased",
input: "P.O. BOX 44",
options: []option{OptionLowerCase, OptionExcludePOCasing},
expOutput: "po box 44",
expCount: 2,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
output, count := NormalizeAddress2(tt.input, tt.options...)
assert.Equal(t, tt.expOutput, output)
assert.Equal(t, tt.expCount, count)
})
}
}