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