Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: content/renderer/android/address_detector_unittest.cc

Issue 10456007: [Android] Split the address parser from AddressDetector for WebView use. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: transforming AddressParser into a namespace. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/android/address_detector.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/renderer/android/address_detector.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 using content::AddressDetector;
13
14 class AddressDetectorTest : public testing::Test {
15 public:
16 AddressDetectorTest() {}
17
18 void TokenizeWords(const string16& content,
19 AddressDetector::WordList* words) const {
20 AddressDetector::String16Tokenizer tokenizer(content.begin(),
21 content.end(), kWhitespaceUTF16);
22 while (tokenizer.GetNext()) {
23 words->push_back(AddressDetector::Word(tokenizer.token_begin(),
24 tokenizer.token_end()));
25 }
26 }
27
28 std::string GetHouseNumber(const std::string& content) const {
29 string16 content_16 = UTF8ToUTF16(content);
30 string16 result;
31
32 AddressDetector::HouseNumberParser parser;
33 AddressDetector::Word word;
34 if (parser.Parse(content_16.begin(), content_16.end(), &word))
35 result = string16(word.begin, word.end);
36 return UTF16ToUTF8(result);
37 }
38
39 bool ContainsHouseNumber(const std::string& content) const {
40 return !GetHouseNumber(content).empty();
41 }
42
43 bool GetState(const std::string& state, size_t* state_index) const {
44 string16 state_16 = UTF8ToUTF16(state);
45 AddressDetector::String16Tokenizer tokenizer(state_16.begin(),
46 state_16.end(),
47 kWhitespaceUTF16);
48 if (!tokenizer.GetNext())
49 return false;
50
51 size_t state_last_word;
52 AddressDetector::WordList words;
53 words.push_back(AddressDetector::Word(tokenizer.token_begin(),
54 tokenizer.token_end()));
55 return AddressDetector::FindStateStartingInWord(
56 &words, 0, &state_last_word, &tokenizer, state_index);
57 }
58
59 bool IsState(const std::string& state) const {
60 size_t state_index;
61 return GetState(state, &state_index);
62 }
63
64 bool IsZipValid(const std::string& zip, const std::string& state) const {
65 size_t state_index;
66 EXPECT_TRUE(GetState(state, &state_index));
67
68 string16 zip_16 = UTF8ToUTF16(zip);
69 AddressDetector::WordList words;
70 TokenizeWords(zip_16, &words);
71 EXPECT_TRUE(words.size() == 1);
72 return AddressDetector::IsZipValid(words.front(), state_index);
73 }
74
75 bool IsLocationName(const std::string& street) const {
76 string16 street_16 = UTF8ToUTF16(street);
77 AddressDetector::WordList words;
78 TokenizeWords(street_16, &words);
79 EXPECT_TRUE(words.size() == 1);
80 return AddressDetector::IsValidLocationName(words.front());
81 }
82
83 std::string FindAddress(const std::string& content) const {
84 string16 content_16 = UTF8ToUTF16(content);
85 string16 result_16;
86 size_t start, end;
87 AddressDetector detector;
88 std::string content_text;
89 if (detector.FindContent(content_16.begin(), content_16.end(),
90 &start, &end, &content_text))
91 result_16 = content_16.substr(start, end - start);
92 return UTF16ToUTF8(result_16);
93 }
94
95 bool ContainsAddress(const std::string& content) const {
96 return !FindAddress(content).empty();
97 }
98
99 bool IsAddress(const std::string& content) const {
100 return FindAddress(content) == content;
101 }
102
103 private:
104 DISALLOW_COPY_AND_ASSIGN(AddressDetectorTest);
105 };
106
107 TEST_F(AddressDetectorTest, HouseNumber) {
108 // Tests cases with valid home numbers.
109 EXPECT_EQ(GetHouseNumber("4 my house"), "4");
110 EXPECT_EQ(GetHouseNumber("Something 4 my house"), "4");
111 EXPECT_EQ(GetHouseNumber("4"), "4");
112 EXPECT_EQ(GetHouseNumber(" 4,5"), "4");
113 EXPECT_EQ(GetHouseNumber("one"), "one");
114 EXPECT_EQ(GetHouseNumber("Number One somewhere"), "One");
115 EXPECT_EQ(GetHouseNumber("Testing \n4\n"), "4");
116 EXPECT_EQ(GetHouseNumber("Foo 1ST"), "1ST");
117 EXPECT_EQ(GetHouseNumber("Bar 2nd"), "2nd");
118 EXPECT_EQ(GetHouseNumber("Blah 3rd"), "3rd");
119 EXPECT_EQ(GetHouseNumber("4th"), "4th");
120 EXPECT_EQ(GetHouseNumber("Blah 11th"), "11th");
121 EXPECT_EQ(GetHouseNumber("Blah 12th meh"), "12th");
122 EXPECT_EQ(GetHouseNumber("Blah 13th moo"), "13th");
123 EXPECT_EQ(GetHouseNumber("211st"), "211st");
124 EXPECT_EQ(GetHouseNumber("1A"), "1A");
125 EXPECT_EQ(GetHouseNumber("number:35"), "35");
126 EXPECT_EQ(GetHouseNumber("five digits at most: 12345"), "12345");
127 EXPECT_EQ(GetHouseNumber("'123'"), "123");
128 EXPECT_EQ(GetHouseNumber("\"123\""), "123");
129 EXPECT_EQ(GetHouseNumber("\"123, something\""), "123");
130 EXPECT_EQ(GetHouseNumber("Testing 12-34"), "12-34");
131 EXPECT_EQ(GetHouseNumber("Testing 12-34c,d"), "12-34c");
132 EXPECT_EQ(GetHouseNumber("住所は:76 Buckingham Palace Roadです"), "76");
133
134 // Tests cases without valid home numbers.
135 EXPECT_FALSE(ContainsHouseNumber("0th"));
136 EXPECT_FALSE(ContainsHouseNumber("25st"));
137 EXPECT_FALSE(ContainsHouseNumber("111th"));
138 EXPECT_FALSE(ContainsHouseNumber("011th"));
139 EXPECT_FALSE(ContainsHouseNumber("27AZ"));
140 EXPECT_FALSE(ContainsHouseNumber("22ºC"));
141 EXPECT_FALSE(ContainsHouseNumber("3.141592"));
142 EXPECT_FALSE(ContainsHouseNumber("more than five digits: 123456"));
143 EXPECT_FALSE(ContainsHouseNumber("kjhdfkajsdhf98uf93h"));
144 EXPECT_FALSE(ContainsHouseNumber("これはテストです。"));
145 EXPECT_FALSE(ContainsHouseNumber("Number On"));
146 EXPECT_FALSE(ContainsHouseNumber("2: foo"));
147 EXPECT_FALSE(ContainsHouseNumber("12-"));
148 EXPECT_FALSE(ContainsHouseNumber("\n\"' \t, "));
149 EXPECT_FALSE(ContainsHouseNumber(""));
150 }
151
152 TEST_F(AddressDetectorTest, FindState) {
153 // The complete set of state codes and names is tested together with their
154 // returned state indices in the zip code test.
155 EXPECT_TRUE(IsState("CALIFORNIA"));
156 EXPECT_TRUE(IsState("ca"));
157
158 EXPECT_FALSE(IsState("californi"));
159 EXPECT_FALSE(IsState("northern mariana"));
160 EXPECT_FALSE(IsState("northern mariana island"));
161 EXPECT_FALSE(IsState("zz"));
162 }
163
164 TEST_F(AddressDetectorTest, ZipCode) {
165 EXPECT_TRUE(IsZipValid("90000", "CA"));
166 EXPECT_TRUE(IsZipValid("01234", "MA"));
167 EXPECT_TRUE(IsZipValid("99999-9999", "Alaska"));
168
169 EXPECT_FALSE(IsZipValid("999999999", "Alaska"));
170 EXPECT_FALSE(IsZipValid("9999-99999", "Alaska"));
171 EXPECT_FALSE(IsZipValid("999999999-", "Alaska"));
172 EXPECT_FALSE(IsZipValid("99999-999a", "Alaska"));
173 EXPECT_FALSE(IsZipValid("99999--9999", "Alaska"));
174 EXPECT_FALSE(IsZipValid("90000o", "CA"));
175 EXPECT_FALSE(IsZipValid("01234", "CA"));
176 EXPECT_FALSE(IsZipValid("01234-", "MA"));
177
178 // Test the state index against the zip range table.
179 EXPECT_TRUE(IsZipValid("99000", "AK"));
180 EXPECT_TRUE(IsZipValid("99000", "Alaska"));
181 EXPECT_TRUE(IsZipValid("35000", "AL"));
182 EXPECT_TRUE(IsZipValid("36000", "Alabama"));
183 EXPECT_TRUE(IsZipValid("71000", "AR"));
184 EXPECT_TRUE(IsZipValid("72000", "Arkansas"));
185 EXPECT_TRUE(IsZipValid("96000", "AS"));
186 EXPECT_TRUE(IsZipValid("96000", "American Samoa"));
187 EXPECT_TRUE(IsZipValid("85000", "AZ"));
188 EXPECT_TRUE(IsZipValid("86000", "Arizona"));
189 EXPECT_TRUE(IsZipValid("90000", "CA"));
190 EXPECT_TRUE(IsZipValid("96000", "California"));
191 EXPECT_TRUE(IsZipValid("80000", "CO"));
192 EXPECT_TRUE(IsZipValid("81000", "Colorado"));
193 EXPECT_TRUE(IsZipValid("06000", "CT"));
194 EXPECT_TRUE(IsZipValid("06000", "Connecticut"));
195 EXPECT_TRUE(IsZipValid("20000", "DC"));
196 EXPECT_TRUE(IsZipValid("20000", "District of Columbia"));
197 EXPECT_TRUE(IsZipValid("19000", "DE"));
198 EXPECT_TRUE(IsZipValid("19000", "Delaware"));
199 EXPECT_TRUE(IsZipValid("32000", "FL"));
200 EXPECT_TRUE(IsZipValid("34000", "Florida"));
201 EXPECT_TRUE(IsZipValid("96000", "FM"));
202 EXPECT_TRUE(IsZipValid("96000", "Federated States of Micronesia"));
203 EXPECT_TRUE(IsZipValid("30000", "GA"));
204 EXPECT_TRUE(IsZipValid("31000", "Georgia"));
205 EXPECT_TRUE(IsZipValid("96000", "GU"));
206 EXPECT_TRUE(IsZipValid("96000", "Guam"));
207 EXPECT_TRUE(IsZipValid("96000", "HI"));
208 EXPECT_TRUE(IsZipValid("96000", "Hawaii"));
209 EXPECT_TRUE(IsZipValid("50000", "IA"));
210 EXPECT_TRUE(IsZipValid("52000", "Iowa"));
211 EXPECT_TRUE(IsZipValid("83000", "ID"));
212 EXPECT_TRUE(IsZipValid("83000", "Idaho"));
213 EXPECT_TRUE(IsZipValid("60000", "IL"));
214 EXPECT_TRUE(IsZipValid("62000", "Illinois"));
215 EXPECT_TRUE(IsZipValid("46000", "IN"));
216 EXPECT_TRUE(IsZipValid("47000", "Indiana"));
217 EXPECT_TRUE(IsZipValid("66000", "KS"));
218 EXPECT_TRUE(IsZipValid("67000", "Kansas"));
219 EXPECT_TRUE(IsZipValid("40000", "KY"));
220 EXPECT_TRUE(IsZipValid("42000", "Kentucky"));
221 EXPECT_TRUE(IsZipValid("70000", "LA"));
222 EXPECT_TRUE(IsZipValid("71000", "Louisiana"));
223 EXPECT_TRUE(IsZipValid("01000", "MA"));
224 EXPECT_TRUE(IsZipValid("02000", "Massachusetts"));
225 EXPECT_TRUE(IsZipValid("20000", "MD"));
226 EXPECT_TRUE(IsZipValid("21000", "Maryland"));
227 EXPECT_TRUE(IsZipValid("03000", "ME"));
228 EXPECT_TRUE(IsZipValid("04000", "Maine"));
229 EXPECT_TRUE(IsZipValid("96000", "MH"));
230 EXPECT_TRUE(IsZipValid("96000", "Marshall Islands"));
231 EXPECT_TRUE(IsZipValid("48000", "MI"));
232 EXPECT_TRUE(IsZipValid("49000", "Michigan"));
233 EXPECT_TRUE(IsZipValid("55000", "MN"));
234 EXPECT_TRUE(IsZipValid("56000", "Minnesota"));
235 EXPECT_TRUE(IsZipValid("63000", "MO"));
236 EXPECT_TRUE(IsZipValid("65000", "Missouri"));
237 EXPECT_TRUE(IsZipValid("96000", "MP"));
238 EXPECT_TRUE(IsZipValid("96000", "Northern Mariana Islands"));
239 EXPECT_TRUE(IsZipValid("38000", "MS"));
240 EXPECT_TRUE(IsZipValid("39000", "Mississippi"));
241 EXPECT_TRUE(IsZipValid("55000", "MT"));
242 EXPECT_TRUE(IsZipValid("56000", "Montana"));
243 EXPECT_TRUE(IsZipValid("27000", "NC"));
244 EXPECT_TRUE(IsZipValid("28000", "North Carolina"));
245 EXPECT_TRUE(IsZipValid("58000", "ND"));
246 EXPECT_TRUE(IsZipValid("58000", "North Dakota"));
247 EXPECT_TRUE(IsZipValid("68000", "NE"));
248 EXPECT_TRUE(IsZipValid("69000", "Nebraska"));
249 EXPECT_TRUE(IsZipValid("03000", "NH"));
250 EXPECT_TRUE(IsZipValid("04000", "New Hampshire"));
251 EXPECT_TRUE(IsZipValid("07000", "NJ"));
252 EXPECT_TRUE(IsZipValid("08000", "New Jersey"));
253 EXPECT_TRUE(IsZipValid("87000", "NM"));
254 EXPECT_TRUE(IsZipValid("88000", "New Mexico"));
255 EXPECT_TRUE(IsZipValid("88000", "NV"));
256 EXPECT_TRUE(IsZipValid("89000", "Nevada"));
257 EXPECT_TRUE(IsZipValid("10000", "NY"));
258 EXPECT_TRUE(IsZipValid("14000", "New York"));
259 EXPECT_TRUE(IsZipValid("43000", "OH"));
260 EXPECT_TRUE(IsZipValid("45000", "Ohio"));
261 EXPECT_TRUE(IsZipValid("73000", "OK"));
262 EXPECT_TRUE(IsZipValid("74000", "Oklahoma"));
263 EXPECT_TRUE(IsZipValid("97000", "OR"));
264 EXPECT_TRUE(IsZipValid("97000", "Oregon"));
265 EXPECT_TRUE(IsZipValid("15000", "PA"));
266 EXPECT_TRUE(IsZipValid("19000", "Pennsylvania"));
267 EXPECT_TRUE(IsZipValid("06000", "PR"));
268 EXPECT_TRUE(IsZipValid("06000", "Puerto Rico"));
269 EXPECT_TRUE(IsZipValid("96000", "PW"));
270 EXPECT_TRUE(IsZipValid("96000", "Palau"));
271 EXPECT_TRUE(IsZipValid("02000", "RI"));
272 EXPECT_TRUE(IsZipValid("02000", "Rhode Island"));
273 EXPECT_TRUE(IsZipValid("29000", "SC"));
274 EXPECT_TRUE(IsZipValid("29000", "South Carolina"));
275 EXPECT_TRUE(IsZipValid("57000", "SD"));
276 EXPECT_TRUE(IsZipValid("57000", "South Dakota"));
277 EXPECT_TRUE(IsZipValid("37000", "TN"));
278 EXPECT_TRUE(IsZipValid("38000", "Tennessee"));
279 EXPECT_TRUE(IsZipValid("75000", "TX"));
280 EXPECT_TRUE(IsZipValid("79000", "Texas"));
281 EXPECT_TRUE(IsZipValid("84000", "UT"));
282 EXPECT_TRUE(IsZipValid("84000", "Utah"));
283 EXPECT_TRUE(IsZipValid("22000", "VA"));
284 EXPECT_TRUE(IsZipValid("24000", "Virginia"));
285 EXPECT_TRUE(IsZipValid("06000", "VI"));
286 EXPECT_TRUE(IsZipValid("09000", "Virgin Islands"));
287 EXPECT_TRUE(IsZipValid("05000", "VT"));
288 EXPECT_TRUE(IsZipValid("05000", "Vermont"));
289 EXPECT_TRUE(IsZipValid("98000", "WA"));
290 EXPECT_TRUE(IsZipValid("99000", "Washington"));
291 EXPECT_TRUE(IsZipValid("53000", "WI"));
292 EXPECT_TRUE(IsZipValid("54000", "Wisconsin"));
293 EXPECT_TRUE(IsZipValid("24000", "WV"));
294 EXPECT_TRUE(IsZipValid("26000", "West Virginia"));
295 EXPECT_TRUE(IsZipValid("82000", "WY"));
296 EXPECT_TRUE(IsZipValid("83000", "Wyoming"));
297 }
298
299 TEST_F(AddressDetectorTest, LocationName) {
300 EXPECT_FALSE(IsLocationName("str-eet"));
301 EXPECT_FALSE(IsLocationName("somewhere"));
302
303 // Test all supported street names and expected plural cases.
304 EXPECT_TRUE(IsLocationName("alley"));
305 EXPECT_TRUE(IsLocationName("annex"));
306 EXPECT_TRUE(IsLocationName("arcade"));
307 EXPECT_TRUE(IsLocationName("ave."));
308 EXPECT_TRUE(IsLocationName("avenue"));
309 EXPECT_TRUE(IsLocationName("alameda"));
310 EXPECT_TRUE(IsLocationName("bayou"));
311 EXPECT_TRUE(IsLocationName("beach"));
312 EXPECT_TRUE(IsLocationName("bend"));
313 EXPECT_TRUE(IsLocationName("bluff"));
314 EXPECT_TRUE(IsLocationName("bluffs"));
315 EXPECT_TRUE(IsLocationName("bottom"));
316 EXPECT_TRUE(IsLocationName("boulevard"));
317 EXPECT_TRUE(IsLocationName("branch"));
318 EXPECT_TRUE(IsLocationName("bridge"));
319 EXPECT_TRUE(IsLocationName("brook"));
320 EXPECT_TRUE(IsLocationName("brooks"));
321 EXPECT_TRUE(IsLocationName("burg"));
322 EXPECT_TRUE(IsLocationName("burgs"));
323 EXPECT_TRUE(IsLocationName("bypass"));
324 EXPECT_TRUE(IsLocationName("broadway"));
325 EXPECT_TRUE(IsLocationName("camino"));
326 EXPECT_TRUE(IsLocationName("camp"));
327 EXPECT_TRUE(IsLocationName("canyon"));
328 EXPECT_TRUE(IsLocationName("cape"));
329 EXPECT_TRUE(IsLocationName("causeway"));
330 EXPECT_TRUE(IsLocationName("center"));
331 EXPECT_TRUE(IsLocationName("centers"));
332 EXPECT_TRUE(IsLocationName("circle"));
333 EXPECT_TRUE(IsLocationName("circles"));
334 EXPECT_TRUE(IsLocationName("cliff"));
335 EXPECT_TRUE(IsLocationName("cliffs"));
336 EXPECT_TRUE(IsLocationName("club"));
337 EXPECT_TRUE(IsLocationName("common"));
338 EXPECT_TRUE(IsLocationName("corner"));
339 EXPECT_TRUE(IsLocationName("corners"));
340 EXPECT_TRUE(IsLocationName("course"));
341 EXPECT_TRUE(IsLocationName("court"));
342 EXPECT_TRUE(IsLocationName("courts"));
343 EXPECT_TRUE(IsLocationName("cove"));
344 EXPECT_TRUE(IsLocationName("coves"));
345 EXPECT_TRUE(IsLocationName("creek"));
346 EXPECT_TRUE(IsLocationName("crescent"));
347 EXPECT_TRUE(IsLocationName("crest"));
348 EXPECT_TRUE(IsLocationName("crossing"));
349 EXPECT_TRUE(IsLocationName("crossroad"));
350 EXPECT_TRUE(IsLocationName("curve"));
351 EXPECT_TRUE(IsLocationName("circulo"));
352 EXPECT_TRUE(IsLocationName("dale"));
353 EXPECT_TRUE(IsLocationName("dam"));
354 EXPECT_TRUE(IsLocationName("divide"));
355 EXPECT_TRUE(IsLocationName("drive"));
356 EXPECT_TRUE(IsLocationName("drives"));
357 EXPECT_TRUE(IsLocationName("estate"));
358 EXPECT_TRUE(IsLocationName("estates"));
359 EXPECT_TRUE(IsLocationName("expressway"));
360 EXPECT_TRUE(IsLocationName("extension"));
361 EXPECT_TRUE(IsLocationName("extensions"));
362 EXPECT_TRUE(IsLocationName("fall"));
363 EXPECT_TRUE(IsLocationName("falls"));
364 EXPECT_TRUE(IsLocationName("ferry"));
365 EXPECT_TRUE(IsLocationName("field"));
366 EXPECT_TRUE(IsLocationName("fields"));
367 EXPECT_TRUE(IsLocationName("flat"));
368 EXPECT_TRUE(IsLocationName("flats"));
369 EXPECT_TRUE(IsLocationName("ford"));
370 EXPECT_TRUE(IsLocationName("fords"));
371 EXPECT_TRUE(IsLocationName("forest"));
372 EXPECT_TRUE(IsLocationName("forge"));
373 EXPECT_TRUE(IsLocationName("forges"));
374 EXPECT_TRUE(IsLocationName("fork"));
375 EXPECT_TRUE(IsLocationName("forks"));
376 EXPECT_TRUE(IsLocationName("fort"));
377 EXPECT_TRUE(IsLocationName("freeway"));
378 EXPECT_TRUE(IsLocationName("garden"));
379 EXPECT_TRUE(IsLocationName("gardens"));
380 EXPECT_TRUE(IsLocationName("gateway"));
381 EXPECT_TRUE(IsLocationName("glen"));
382 EXPECT_TRUE(IsLocationName("glens"));
383 EXPECT_TRUE(IsLocationName("green"));
384 EXPECT_TRUE(IsLocationName("greens"));
385 EXPECT_TRUE(IsLocationName("grove"));
386 EXPECT_TRUE(IsLocationName("groves"));
387 EXPECT_TRUE(IsLocationName("harbor"));
388 EXPECT_TRUE(IsLocationName("harbors"));
389 EXPECT_TRUE(IsLocationName("haven"));
390 EXPECT_TRUE(IsLocationName("heights"));
391 EXPECT_TRUE(IsLocationName("highway"));
392 EXPECT_TRUE(IsLocationName("hill"));
393 EXPECT_TRUE(IsLocationName("hills"));
394 EXPECT_TRUE(IsLocationName("hollow"));
395 EXPECT_TRUE(IsLocationName("inlet"));
396 EXPECT_TRUE(IsLocationName("island"));
397 EXPECT_TRUE(IsLocationName("islands"));
398 EXPECT_TRUE(IsLocationName("isle"));
399 EXPECT_TRUE(IsLocationName("junction"));
400 EXPECT_TRUE(IsLocationName("junctions"));
401 EXPECT_TRUE(IsLocationName("key"));
402 EXPECT_TRUE(IsLocationName("keys"));
403 EXPECT_TRUE(IsLocationName("knoll"));
404 EXPECT_TRUE(IsLocationName("knolls"));
405 EXPECT_TRUE(IsLocationName("lake"));
406 EXPECT_TRUE(IsLocationName("lakes"));
407 EXPECT_TRUE(IsLocationName("land"));
408 EXPECT_TRUE(IsLocationName("landing"));
409 EXPECT_TRUE(IsLocationName("lane"));
410 EXPECT_TRUE(IsLocationName("light"));
411 EXPECT_TRUE(IsLocationName("lights"));
412 EXPECT_TRUE(IsLocationName("loaf"));
413 EXPECT_TRUE(IsLocationName("lock"));
414 EXPECT_TRUE(IsLocationName("locks"));
415 EXPECT_TRUE(IsLocationName("lodge"));
416 EXPECT_TRUE(IsLocationName("loop"));
417 EXPECT_TRUE(IsLocationName("mall"));
418 EXPECT_TRUE(IsLocationName("manor"));
419 EXPECT_TRUE(IsLocationName("manors"));
420 EXPECT_TRUE(IsLocationName("meadow"));
421 EXPECT_TRUE(IsLocationName("meadows"));
422 EXPECT_TRUE(IsLocationName("mews"));
423 EXPECT_TRUE(IsLocationName("mill"));
424 EXPECT_TRUE(IsLocationName("mills"));
425 EXPECT_TRUE(IsLocationName("mission"));
426 EXPECT_TRUE(IsLocationName("motorway"));
427 EXPECT_TRUE(IsLocationName("mount"));
428 EXPECT_TRUE(IsLocationName("mountain"));
429 EXPECT_TRUE(IsLocationName("mountains"));
430 EXPECT_TRUE(IsLocationName("neck"));
431 EXPECT_TRUE(IsLocationName("orchard"));
432 EXPECT_TRUE(IsLocationName("oval"));
433 EXPECT_TRUE(IsLocationName("overpass"));
434 EXPECT_TRUE(IsLocationName("park"));
435 EXPECT_TRUE(IsLocationName("parks"));
436 EXPECT_TRUE(IsLocationName("parkway"));
437 EXPECT_TRUE(IsLocationName("parkways"));
438 EXPECT_TRUE(IsLocationName("pass"));
439 EXPECT_TRUE(IsLocationName("passage"));
440 EXPECT_TRUE(IsLocationName("path"));
441 EXPECT_TRUE(IsLocationName("pike"));
442 EXPECT_TRUE(IsLocationName("pine"));
443 EXPECT_TRUE(IsLocationName("pines"));
444 EXPECT_TRUE(IsLocationName("plain"));
445 EXPECT_TRUE(IsLocationName("plains"));
446 EXPECT_TRUE(IsLocationName("plaza"));
447 EXPECT_TRUE(IsLocationName("point"));
448 EXPECT_TRUE(IsLocationName("points"));
449 EXPECT_TRUE(IsLocationName("port"));
450 EXPECT_TRUE(IsLocationName("ports"));
451 EXPECT_TRUE(IsLocationName("prairie"));
452 EXPECT_TRUE(IsLocationName("privada"));
453 EXPECT_TRUE(IsLocationName("radial"));
454 EXPECT_TRUE(IsLocationName("ramp"));
455 EXPECT_TRUE(IsLocationName("ranch"));
456 EXPECT_TRUE(IsLocationName("rapid"));
457 EXPECT_TRUE(IsLocationName("rapids"));
458 EXPECT_TRUE(IsLocationName("rest"));
459 EXPECT_TRUE(IsLocationName("ridge"));
460 EXPECT_TRUE(IsLocationName("ridges"));
461 EXPECT_TRUE(IsLocationName("river"));
462 EXPECT_TRUE(IsLocationName("road"));
463 EXPECT_TRUE(IsLocationName("roads"));
464 EXPECT_TRUE(IsLocationName("route"));
465 EXPECT_TRUE(IsLocationName("row"));
466 EXPECT_TRUE(IsLocationName("rue"));
467 EXPECT_TRUE(IsLocationName("run"));
468 EXPECT_TRUE(IsLocationName("shoal"));
469 EXPECT_TRUE(IsLocationName("shoals"));
470 EXPECT_TRUE(IsLocationName("shore"));
471 EXPECT_TRUE(IsLocationName("shores"));
472 EXPECT_TRUE(IsLocationName("skyway"));
473 EXPECT_TRUE(IsLocationName("spring"));
474 EXPECT_TRUE(IsLocationName("springs"));
475 EXPECT_TRUE(IsLocationName("spur"));
476 EXPECT_TRUE(IsLocationName("spurs"));
477 EXPECT_TRUE(IsLocationName("square"));
478 EXPECT_TRUE(IsLocationName("squares"));
479 EXPECT_TRUE(IsLocationName("station"));
480 EXPECT_TRUE(IsLocationName("stravenue"));
481 EXPECT_TRUE(IsLocationName("stream"));
482 EXPECT_TRUE(IsLocationName("st."));
483 EXPECT_TRUE(IsLocationName("street"));
484 EXPECT_TRUE(IsLocationName("streets"));
485 EXPECT_TRUE(IsLocationName("summit"));
486 EXPECT_TRUE(IsLocationName("speedway"));
487 EXPECT_TRUE(IsLocationName("terrace"));
488 EXPECT_TRUE(IsLocationName("throughway"));
489 EXPECT_TRUE(IsLocationName("trace"));
490 EXPECT_TRUE(IsLocationName("track"));
491 EXPECT_TRUE(IsLocationName("trafficway"));
492 EXPECT_TRUE(IsLocationName("trail"));
493 EXPECT_TRUE(IsLocationName("tunnel"));
494 EXPECT_TRUE(IsLocationName("turnpike"));
495 EXPECT_TRUE(IsLocationName("underpass"));
496 EXPECT_TRUE(IsLocationName("union"));
497 EXPECT_TRUE(IsLocationName("unions"));
498 EXPECT_TRUE(IsLocationName("valley"));
499 EXPECT_TRUE(IsLocationName("valleys"));
500 EXPECT_TRUE(IsLocationName("viaduct"));
501 EXPECT_TRUE(IsLocationName("view"));
502 EXPECT_TRUE(IsLocationName("views"));
503 EXPECT_TRUE(IsLocationName("village"));
504 EXPECT_TRUE(IsLocationName("villages"));
505 EXPECT_TRUE(IsLocationName("ville"));
506 EXPECT_TRUE(IsLocationName("vista"));
507 EXPECT_TRUE(IsLocationName("walk"));
508 EXPECT_TRUE(IsLocationName("walks"));
509 EXPECT_TRUE(IsLocationName("wall"));
510 EXPECT_TRUE(IsLocationName("way"));
511 EXPECT_TRUE(IsLocationName("ways"));
512 EXPECT_TRUE(IsLocationName("well"));
513 EXPECT_TRUE(IsLocationName("wells"));
514 EXPECT_TRUE(IsLocationName("xing"));
515 EXPECT_TRUE(IsLocationName("xrd"));
516 }
517
518 TEST_F(AddressDetectorTest, NumberPrefixCases) {
519 EXPECT_EQ(FindAddress("Cafe 21\n750 Fifth Ave. San Diego, California 92101"),
520 "750 Fifth Ave. San Diego, California 92101");
521 EXPECT_EQ(FindAddress(
522 "Century City 15\n 10250 Santa Monica Boulevard Los Angeles, CA 90067"),
523 "10250 Santa Monica Boulevard Los Angeles, CA 90067");
524 EXPECT_EQ(FindAddress("123 45\n67 My Street, Somewhere, NY 10000"),
525 "67 My Street, Somewhere, NY 10000");
526 EXPECT_TRUE(IsAddress("123 4th Avenue, Somewhere in NY 10000"));
527 }
528
529 TEST_F(AddressDetectorTest, FullAddress) {
530 // Test US Google corporate addresses. Expects a full string match.
531 EXPECT_TRUE(IsAddress("1600 Amphitheatre Parkway Mountain View, CA 94043"));
532 EXPECT_TRUE(IsAddress("201 S. Division St. Suite 500 Ann Arbor, MI 48104"));
533 EXPECT_TRUE(ContainsAddress(
534 "Millennium at Midtown 10 10th Street NE Suite 600 Atlanta, GA 30309"));
535 EXPECT_TRUE(IsAddress(
536 "9606 North MoPac Expressway Suite 400 Austin, TX 78759"));
537 EXPECT_TRUE(IsAddress("2590 Pearl Street Suite 100 Boulder, CO 80302"));
538 EXPECT_TRUE(IsAddress("5 Cambridge Center, Floors 3-6 Cambridge, MA 02142"));
539 EXPECT_TRUE(IsAddress("410 Market St Suite 415 Chapel Hill, NC 27516"));
540 EXPECT_TRUE(IsAddress("20 West Kinzie St. Chicago, IL 60654"));
541 EXPECT_TRUE(IsAddress("114 Willits Street Birmingham, MI 48009"));
542 EXPECT_TRUE(IsAddress("19540 Jamboree Road 2nd Floor Irvine, CA 92612"));
543 EXPECT_TRUE(IsAddress("747 6th Street South, Kirkland, WA 98033"));
544 EXPECT_TRUE(IsAddress("301 S. Blount St. Suite 301 Madison, WI 53703"));
545 EXPECT_TRUE(IsAddress("76 Ninth Avenue 4th Floor New York, NY 10011"));
546 EXPECT_TRUE(ContainsAddress(
547 "Chelsea Markset Space, 75 Ninth Avenue 2nd and 4th Floors New York, \
548 NY 10011"));
549 EXPECT_TRUE(IsAddress("6425 Penn Ave. Suite 700 Pittsburgh, PA 15206"));
550 EXPECT_TRUE(IsAddress("1818 Library Street Suite 400 Reston, VA 20190"));
551 EXPECT_TRUE(IsAddress("345 Spear Street Floors 2-4 San Francisco, CA 94105"));
552 EXPECT_TRUE(IsAddress("604 Arizona Avenue Santa Monica, CA 90401"));
553 EXPECT_TRUE(IsAddress("651 N. 34th St. Seattle, WA 98103"));
554 EXPECT_TRUE(IsAddress(
555 "1101 New York Avenue, N.W. Second Floor Washington, DC 20005"));
556
557 // Other tests.
558 EXPECT_TRUE(IsAddress("57th Street and Lake Shore Drive\nChicago, IL 60637"));
559 EXPECT_TRUE(IsAddress("308 Congress Street Boston, MA 02210"));
560 EXPECT_TRUE(ContainsAddress(
561 "Central Park West at 79th Street, New York, NY, 10024-5192"));
562 EXPECT_TRUE(ContainsAddress(
563 "Lincoln Park | 100 34th Avenue • San Francisco, CA 94121 | 41575036"));
564
565 EXPECT_EQ(FindAddress("Lorem ipsum dolor sit amet, consectetur adipisicing " \
566 "elit, sed do 1600 Amphitheatre Parkway Mountain View, CA 94043 " \
567 "eiusmod tempor incididunt ut labore et dolore magna aliqua."),
568 "1600 Amphitheatre Parkway Mountain View, CA 94043");
569
570 EXPECT_EQ(FindAddress("2590 Pearl Street Suite 100 Boulder, CO 80302 6425 " \
571 "Penn Ave. Suite 700 Pittsburgh, PA 15206"),
572 "2590 Pearl Street Suite 100 Boulder, CO 80302");
573
574 EXPECT_TRUE(ContainsAddress(
575 "住所は 1600 Amphitheatre Parkway Mountain View, CA 94043 です。"));
576
577 EXPECT_FALSE(ContainsAddress("1 st. too-short, CA 90000"));
578 EXPECT_TRUE(ContainsAddress("1 st. long enough, CA 90000"));
579
580 EXPECT_TRUE(ContainsAddress("1 st. some city in al 35000"));
581 EXPECT_FALSE(ContainsAddress("1 book st Aquinas et al 35000"));
582
583 EXPECT_FALSE(ContainsAddress("1 this comes too late: street, CA 90000"));
584 EXPECT_TRUE(ContainsAddress("1 this is ok: street, CA 90000"));
585
586 EXPECT_FALSE(ContainsAddress(
587 "1 street I love verbosity, so I'm writing an address with too many " \
588 "words CA 90000"));
589 EXPECT_TRUE(ContainsAddress("1 street 2 3 4 5 6 7 8 9 10 11 12, CA 90000"));
590
591 EXPECT_TRUE(IsAddress("79th Street 1st Floor New York City, NY 10024-5192"));
592
593 EXPECT_FALSE(ContainsAddress("123 Fake Street, Springfield, Springfield"));
594 EXPECT_FALSE(ContainsAddress("999 Street Avenue, City, ZZ 98765"));
595 EXPECT_FALSE(ContainsAddress("76 Here be dragons, CA 94043"));
596 EXPECT_FALSE(ContainsAddress("1 This, has, too* many, lines, to, be* valid"));
597 EXPECT_FALSE(ContainsAddress(
598 "1 Supercalifragilisticexpialidocious is too long, CA 90000"));
599 EXPECT_FALSE(ContainsAddress(""));
600 }
OLDNEW
« no previous file with comments | « content/renderer/android/address_detector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698