Fix a bug incorrectly abbreviating road names, found in Bristol

This commit is contained in:
Dustin Carlino 2022-07-19 10:38:22 +02:00
parent aed6795234
commit 83600f0e26

View File

@ -170,12 +170,12 @@ fn simplify_patterns() -> Vec<(Regex, String)> {
] {
// Only replace directions at the start or end of the string
replace.push((
Regex::new(&format!("^{}", long)).unwrap(),
short.to_string(),
Regex::new(&format!("^{long} ")).unwrap(),
format!("{short} "),
));
replace.push((
Regex::new(&format!("{}$", long)).unwrap(),
short.to_string(),
Regex::new(&format!(" {long}$")).unwrap(),
format!(" {short}"),
));
}
@ -209,6 +209,7 @@ mod tests {
for (input, want) in [
("Northeast Northgate Way", "NE Northgate Way"),
("South 42nd Street", "S 42nd St"),
("Northcote Road", "Northcote Road"),
] {
let got = simplify_name(input.to_string()).unwrap();
if got != want {