forked from joshfraser/PHP-Name-Parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples.php
283 lines (277 loc) · 16.3 KB
/
examples.php
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<?php
require_once('parser.php');
// examples & a poor mans test suite
// intentionally shows examples that fail
$names = array(
"Mr Anthony R Von Fange III" => array("salutation" => "Mr.",
"fname" => "Anthony",
"initials" => "R",
"lname" => "Von Fange",
"suffix" => "III"),
"J. B. Hunt" => array("salutation" => "",
"fname" => "J.",
"initials" => "B.",
"lname" => "Hunt",
"suffix" => ""),
"J.B. Hunt" => array("salutation" => "",
"fname" => "J.B.",
"initials" => "",
"lname" => "Hunt",
"suffix" => ""),
"Edward Senior III" => array("salutation" => "",
"fname" => "Edward",
"initials" => "",
"lname" => "Senior",
"suffix" => "III"),
"Edward Dale Senior II" => array("salutation" => "",
"fname" => "Edward Dale",
"initials" => "",
"lname" => "Senior",
"suffix" => "II"),
"Dale Edward Jones Senior" => array("salutation" => "",
"fname" => "Dale Edward",
"initials" => "",
"lname" => "Jones",
"suffix" => "Senior"),
"Edward Senior II" => array("salutation" => "",
"fname" => "Edward",
"initials" => "",
"lname" => "Senior",
"suffix" => "II"),
"Dale Edward Senior II, PhD" => array("salutation" => "",
"fname" => "Dale Edward",
"initials" => "",
"lname" => "Senior",
"suffix" => "II, PhD"),
"Jason Rodriguez Sr." => array("salutation" => "",
"fname" => "Jason",
"initials" => "",
"lname" => "Rodriguez",
"suffix" => "Sr"),
"Jason Senior" => array("salutation" => "",
"fname" => "Jason",
"initials" => "",
"lname" => "Senior",
"suffix" => ""),
"Bill Junior" => array("salutation" => "",
"fname" => "Bill",
"initials" => "",
"lname" => "Junior",
"suffix" => ""),
"Sara Ann Fraser" => array("salutation" => "",
"fname" => "Sara Ann",
"initials" => "",
"lname" => "Fraser",
"suffix" => ""),
"Adam" => array("salutation" => "",
"fname" => "Adam",
"initials" => "",
"lname" => "",
"suffix" => ""),
"OLD MACDONALD" => array("salutation" => "",
"fname" => "Old",
"initials" => "",
"lname" => "Macdonald",
"suffix" => ""),
"Old MacDonald" => array("salutation" => "",
"fname" => "Old",
"initials" => "",
"lname" => "MacDonald",
"suffix" => ""),
"Old McDonald" => array("salutation" => "",
"fname" => "Old",
"initials" => "",
"lname" => "McDonald",
"suffix" => ""),
"Old Mc Donald" => array("salutation" => "",
"fname" => "Old Mc",
"initials" => "",
"lname" => "Donald",
"suffix" => ""),
"Old Mac Donald" => array("salutation" => "",
"fname" => "Old Mac",
"initials" => "",
"lname" => "Donald",
"suffix" => ""),
"James van Allen" => array("salutation" => "",
"fname" => "James",
"initials" => "",
"lname" => "Van Allen",
"suffix" => ""),
"Jimmy (Bubba) Smith" => array("nickname" => "Bubba",
"salutation" => "",
"fname" => "Jimmy",
"initials" => "",
"lname" => "Smith",
"suffix" => ""),
"Miss Jennifer Shrader Lawrence" => array("salutation" => "Ms.",
"fname" => "Jennifer Shrader",
"initials" => "",
"lname" => "Lawrence",
"suffix" => ""),
"Jonathan Smith, MD" => array("salutation" => "",
"fname" => "Jonathan",
"initials" => "",
"lname" => "Smith",
"suffix" => "MD"),
"Dr. Jonathan Smith" => array("salutation" => "Dr.",
"fname" => "Jonathan",
"initials" => "",
"lname" => "Smith",
"suffix" => ""),
"Jonathan Smith IV, PhD" => array("salutation" => "",
"fname" => "Jonathan",
"initials" => "",
"lname" => "Smith",
"suffix" => "IV, PhD"),
"Miss Jamie P. Harrowitz" => array("salutation" => "Ms.",
"fname" => "Jamie",
"initials" => "P.",
"lname" => "Harrowitz",
"suffix" => ""),
"Mr John Doe" => array("salutation" => "Mr.",
"fname" => "John",
"initials" => "",
"lname" => "Doe",
"suffix" => ""),
"Rev. Dr John Doe" => array("salutation" => "Rev. Dr.",
"fname" => "John",
"initials" => "",
"lname" => "Doe",
"suffix" => ""),
"Anthony Von Fange III" => array("salutation" => "",
"fname" => "Anthony",
"initials" => "",
"lname" => "Von Fange",
"suffix" => "III"),
"Anthony Von Fange III, PhD" => array("salutation" => "",
"fname" => "Anthony",
"initials" => "",
"lname" => "Von Fange",
"suffix" => "III, PhD"),
"Smarty Pants Phd" => array("salutation" => "",
"fname" => "Smarty",
"initials" => "",
"lname" => "Pants",
"suffix" => "PhD"),
"Mark Peter Williams" => array("salutation" => "",
"fname" => "Mark Peter",
"initials" => "",
"lname" => "Williams",
"suffix" => ""),
"Mark P Williams" => array("salutation" => "",
"fname" => "Mark",
"initials" => "P",
"lname" => "Williams",
"suffix" => ""),
"Mark P. Williams" => array("salutation" => "",
"fname" => "Mark",
"initials" => "P.",
"lname" => "Williams",
"suffix" => ""),
"M Peter Williams" => array("salutation" => "",
"fname" => "Peter",
"initials" => "M",
"lname" => "Williams",
"suffix" => ""),
"M. Peter Williams" => array("salutation" => "",
"fname" => "Peter",
"initials" => "M.",
"lname" => "Williams",
"suffix" => ""),
"M. P. Williams" => array("salutation" => "",
"fname" => "M.",
"initials" => "P.",
"lname" => "Williams",
"suffix" => ""),
"The Rev. Mark Williams" => array("salutation" => "Rev.",
"fname" => "Mark",
"initials" => "",
"lname" => "Williams",
"suffix" => ""),
"Mister Mark Williams" => array("salutation" => "Mr.",
"fname" => "Mark",
"initials" => "",
"lname" => "Williams",
"suffix" => ""),
// fails. format not yet supported
"Fraser, Joshua" => array("salutation" => "",
"fname" => "Joshua",
"initials" => "",
"lname" => "Fraser",
"suffix" => ""),
// fails. both initials should be capitalized
"JB Hunt" => array("salutation" => "",
"fname" => "JB",
"initials" => "",
"lname" => "Hunt",
"suffix" => ""),
// fails. doesn't handle multiple words inside parenthesis
"Jimmy (Bubba Junior) Smith" => array("nickname" => "Bubba Junior",
"salutation" => "",
"fname" => "Jimmy",
"initials" => "",
"lname" => "Smith",
"suffix" => ""),
// fails. should normalize the PhD suffix
"Anthony Von Fange III, PHD" => array("salutation" => "",
"fname" => "Anthony",
"initials" => "",
"lname" => "Von Fange",
"suffix" => "III, PhD"),
// fails. should treat "Silly" as the nickname or remove altogether
"Not So Smarty Pants, Silly" => array("nickname" => "Silly",
"salutation" => "",
"fname" => "Not So Smarty",
"initials" => "",
"lname" => "Pants",
"suffix" => ""),
"Rev Al Sharpton" => array("salutation" => "Rev.",
"fname" => "Al",
"initials" => "",
"lname" => "Sharpton",
"suffix" => ""),
"Dr Ty P. Bennington iIi" => array("salutation" => "Dr.",
"fname" => "Ty",
"initials" => "P.",
"lname" => "Bennington",
"suffix" => "III"),
);
$parser = new FullNameParser();
$headers = array("salutation","fname","initials","lname","suffix","nickname");
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PHP Name Parser | Unit Tests</title>
<link rel="stylesheet" href="./tests/style.css" type="text/css" media="all">
</head>
<body>
<div class="wrapper">
<table class="unit-tests">
<thead>
<tr>
<th>Full Name</th>
<?php foreach ($headers as $col): ?>
<th><?= ucfirst($col); ?></th>
<?php endforeach; ?>
<th>Passed</th>
</tr>
</thead>
<tbody>
<?php foreach ($names as $name => $expected_values): $split_name = $parser->parse_name($name); $passed = ($split_name === $expected_values); ?>
<tr class="<?= ($passed) ? 'pass' : 'fail'; ?>">
<td><?= $name; ?></td>
<?php foreach ($headers as $col): ?>
<td><?= (isset($split_name[$col])) ? $split_name[$col] : ''; ?></td>
<?php endforeach; ?>
<td><?= ($passed) ? 'PASS' : 'FAIL'; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</body>
</html>