forked from kodemartin/rustpostal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpand.rs
82 lines (76 loc) · 2.19 KB
/
expand.rs
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
extern crate rustpostal;
use rustpostal::error::RuntimeError;
use rustpostal::expand;
use rustpostal::LibModules;
const TEST_CASES: &[(&str, &str, &str)] = &[
("123 Main St. #2f", "123 main street number 2f", "en"),
("120 E 96th St", "120 east 96 street", "en"),
("120 E Ninety-sixth St", "120 east 96 street", "en"),
(
"4998 Vanderbilt Dr, Columbus, OH 43213",
"4998 vanderbilt drive columbus ohio 43213",
"en",
),
(
"Nineteen oh one W El Segundo Blvd",
"1901 west el segundo boulevard",
"en",
),
("S St. NW", "s street northwest", "en"),
(
"Quatre vingt douze Ave des Champs-Élysées",
"92 avenue des champs-elysees",
"fr",
),
(
"Quatre vingt douze Ave des Champs-Élysées",
"92 avenue des champs elysees",
"fr",
),
(
"Quatre vingt douze Ave des Champs-Élysées",
"92 avenue des champselysees",
"fr",
),
("Marktstrasse", "markt strasse", "de"),
("Hoofdstraat", "hoofdstraat", "nl"),
("มงแตร", "มงแตร", "th"),
];
fn expansion_contains_phrase(address: &str, phrase: &str) -> bool {
let expansion = expand::expand_address(address).unwrap();
for expanded in &expansion {
if expanded == phrase {
return true;
}
}
false
}
fn expansion_contains_phrase_with_options(address: &str, phrase: &str, lang: &str) -> bool {
let expansion = expand::expand_address_with_options(address, Some(vec![lang].iter())).unwrap();
for expanded in &expansion {
if expanded == phrase {
return true;
}
}
false
}
#[test]
fn expand() -> Result<(), RuntimeError> {
let postal_module = LibModules::Expand;
postal_module.setup()?;
for (address, phrase, _) in TEST_CASES {
assert!(expansion_contains_phrase(address, phrase));
}
Ok(())
}
#[test]
fn expand_with_options() -> Result<(), RuntimeError> {
let postal_module = LibModules::Expand;
postal_module.setup()?;
for (address, phrase, lang) in TEST_CASES {
assert!(expansion_contains_phrase_with_options(
address, phrase, lang
));
}
Ok(())
}