From 879fce4ef136cd7e41b1a0673b1afbaa70fcb69e Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Thu, 29 Apr 2021 02:01:53 -0400 Subject: [PATCH] more tests passing --- .../coordinate_and_geocode_handler.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/handlers/coordinate_and_geocode_handler.rs b/src/handlers/coordinate_and_geocode_handler.rs index 638cfbe0e2..c4b8d69226 100644 --- a/src/handlers/coordinate_and_geocode_handler.rs +++ b/src/handlers/coordinate_and_geocode_handler.rs @@ -34,10 +34,10 @@ pub struct LatLong { /// * "34.0659° N, 84.6769° W" /// * "33.753746, -84.386330" pub fn parse_lat_long(input: &str) -> Option { - const NUMERAL : &'static str = r"(\-?\d+\.?\d*)\s*([NSEW])?"; + const NUMERAL : &'static str = r"(\-?\d+\.?\d*)\s*°?\s*([NSEW])?"; lazy_static! { static ref COORDINATE_REGEX: Regex = - Regex::new(&format!(r"^({})\s*,\s*({})$", NUMERAL, NUMERAL)).expect("Regex should work"); + Regex::new(&format!(r"^({})\s*,?\s*({})$", NUMERAL, NUMERAL)).expect("Regex should work"); } println!("{}", input); @@ -151,4 +151,19 @@ mod tests { longitude: 456.0, }))); } + + #[test] + fn parse_lat_long_directions_degrees() { + expect!(parse_lat_long("34.0659° N, 84.6769° W")).to( + be_eq(Some(LatLong { + latitude: 34.0659, + longitude: -84.6769, + }))); + + expect!(parse_lat_long("123°S, 777° E")).to( + be_eq(Some(LatLong { + latitude: -123.0, + longitude: 777.0, + }))); + } }