more tests passing

This commit is contained in:
Brandon Thomas committed 2021-04-29 02:01:53 -04:00
1 parent 39e2b74499
commit 879fce4ef1
1 file changed
+17 -2
+17 -2
View File
@@ -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<LatLong> {
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,
})));
}
}