parent
ffc195e49a
commit
481c8434d9
@ -0,0 +1,43 @@ |
||||
# latlon |
||||
|
||||
Parse geographic coordinates from string. |
||||
|
||||
A wide range of commonly used formats is supported. |
||||
See the unit tests for a complete reference. |
||||
|
||||
If a format you need is missing, please submit a merge request (including unit tests). |
||||
|
||||
## Usage |
||||
|
||||
```rust |
||||
// parse a coord |
||||
let coord : geo::Point = latlon::parse("N 50°5.30385', E 14°26.94732'").unwrap(); |
||||
|
||||
// individual lat/lng parsing |
||||
let lat : f64 = latlon::parse_lat("N 50°5.30385'").unwrap(); |
||||
let lng : f64 = latlon::parse_lng("E 14°26.94732'").unwrap(); |
||||
``` |
||||
|
||||
## Supported formats |
||||
|
||||
Example of supported formats: |
||||
|
||||
- `40° 26′ 46″ N 79° 58′ 56″ W` |
||||
- `N 40° 26′ 46″ W 79° 58′ 56″` |
||||
- `40° 26.767' N 79° 58.933' W` |
||||
- `40° 26′ 46″ 79° 58′ 56″`, `40° 26′ 46″, 79° 58′ 56″`, ... |
||||
- `N 40° 26.767' W 79° 58.933'` |
||||
- `40° 26.767' 79° 58.933'`, `40° 26.767', 79° 58.933'`, ... |
||||
- `N 40.446° W 79.982°` |
||||
- `40.446° N 79.982° W` |
||||
- `40.446° 79.982°`, `40.446,79.982`, etc. |
||||
|
||||
## Parser rules |
||||
- All formats support negative degrees (preceded by a minus sign). Positive latitude is North, positive longitude is East. |
||||
- Whitespace is optional and ignored, except for formats that would become unparsable. |
||||
- Degree, minute and second symbols can be omitted. |
||||
- Comma (`,`) may be used as an alternate decimal separator. |
||||
- Unicode quotes (`’`, `”`) may be used in place of apostrophe and double quote (`'`, `"`) |
||||
for minutes and seconds. |
||||
- The two coordinates can be separated by comma (`,`), semicolon (`;`), whitespace (` `), or nothing |
||||
at all, if not ambiguous. |
@ -0,0 +1,27 @@ |
||||
use std::fmt; |
||||
use std::fmt::{Display, Formatter}; |
||||
use std::num::ParseFloatError; |
||||
|
||||
#[derive(Debug)] |
||||
pub(crate) struct ParseErrorInternal; |
||||
|
||||
impl From<ParseFloatError> for ParseErrorInternal { |
||||
fn from(_: ParseFloatError) -> Self { |
||||
ParseErrorInternal |
||||
} |
||||
} |
||||
|
||||
impl Display for ParseErrorInternal { |
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
||||
f.write_str("Parse error") |
||||
} |
||||
} |
||||
|
||||
#[derive(Debug)] |
||||
pub struct GeoParseError<T: AsRef<str> + Display>(pub T); |
||||
|
||||
impl<T: AsRef<str> + Display> Display for GeoParseError<T> { |
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
||||
write!(f, "Error parsing coordinates from {}", self.0) |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,303 @@ |
||||
use crate::{parse, parse_lat, parse_lng}; |
||||
use geo_types::Point; |
||||
|
||||
#[test] |
||||
fn dms_ns_dms_ew() { |
||||
let reference = Point::new(-79.98222222222222, 40.44611111111111); |
||||
|
||||
assert_eq!(reference, parse(r#"40° 26′ 46″ N 79° 58′ 56″ W"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse(r#"40° 26’ 46″ N 79° 58’ 56″ W"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse(r#"40° 26′ 46″ N, 79° 58′ 56″ W"#).unwrap(), "comma"); |
||||
assert_eq!(reference, parse(r#"40° 26′ 46″ N; 79° 58′ 56″ W"#).unwrap(), "semi"); |
||||
assert_eq!(reference, parse(r#"40° 26′ 46″ N,79° 58′ 56″ W"#).unwrap(), "comma2"); |
||||
assert_eq!(reference, parse(r#"40° 26′ 46″ N;79° 58′ 56″ W"#).unwrap(), "semi2"); |
||||
assert_eq!(reference, parse(r#"40° 26′ 46″ N ,79° 58′ 56″ W"#).unwrap(), "comma2"); |
||||
assert_eq!(reference, parse(r#"40° 26′ 46″ N ;79° 58′ 56″ W"#).unwrap(), "semi2"); |
||||
assert_eq!(reference, parse(r#"40°26′46″N79°58′56″W"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse(r#"40°26′46N79°58′56W"#).unwrap(), "compact, no sec mark"); |
||||
assert_eq!(reference, parse(r#"40 26 46 N 79 58 56 W"#).unwrap(), "no symbols"); |
||||
assert_eq!(reference, parse(r#"-40 26 46 S -79 58 56 E"#).unwrap(), "inverted"); |
||||
} |
||||
|
||||
#[test] |
||||
fn ns_dms_ew_dms() { |
||||
let reference = Point::new(-79.98222222222222, 40.44611111111111); |
||||
|
||||
assert_eq!(reference, parse(r#"N 40° 26′ 46″ W 79° 58′ 56″"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse(r#"N 40° 26’ 46″ W 79° 58’ 56″"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse(r#"N 40° 26′ 46″, W 79° 58′ 56″"#).unwrap(), "comma"); |
||||
assert_eq!(reference, parse(r#"N 40° 26′ 46″; W 79° 58′ 56″"#).unwrap(), "semi"); |
||||
assert_eq!(reference, parse(r#"N 40° 26′ 46″,W 79° 58′ 56″"#).unwrap(), "comma2"); |
||||
assert_eq!(reference, parse(r#"N 40° 26′ 46″;W 79° 58′ 56″"#).unwrap(), "semi2"); |
||||
assert_eq!(reference, parse(r#"N 40° 26′ 46″ , W 79° 58′ 56″"#).unwrap(), "comma3"); |
||||
assert_eq!(reference, parse(r#"N 40° 26′ 46″ ; W 79° 58′ 56″"#).unwrap(), "semi3"); |
||||
assert_eq!(reference, parse(r#"N40°26′46″W79°58′56″"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse(r#"N40°26′46W79°58′56"#).unwrap(), "compact, no sec mark"); |
||||
assert_eq!(reference, parse(r#"N 40 26 46 W 79 58 56"#).unwrap(), "no symbols"); |
||||
assert_eq!(reference, parse(r#"S -40 26 46 E -79 58 56"#).unwrap(), "inverted"); |
||||
} |
||||
|
||||
#[test] |
||||
fn dms_dms() { |
||||
let reference = Point::new(79.98222222222222, 40.44611111111111); |
||||
|
||||
assert_eq!(reference, parse(r#"40° 26′ 46″ 79° 58′ 56″"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse(r#"40° 26’ 46″ 79° 58’ 56″"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse(r#"40° 26′ 46″, 79° 58′ 56″"#).unwrap(), "comma"); |
||||
assert_eq!(reference, parse(r#"40° 26′ 46″; 79° 58′ 56″"#).unwrap(), "semi"); |
||||
assert_eq!(reference, parse(r#"40° 26′ 46″,79° 58′ 56″"#).unwrap(), "comma2"); |
||||
assert_eq!(reference, parse(r#"40° 26′ 46″;79° 58′ 56″"#).unwrap(), "semi2"); |
||||
assert_eq!(reference, parse(r#"40° 26′ 46″ , 79° 58′ 56″"#).unwrap(), "comma3"); |
||||
assert_eq!(reference, parse(r#"40° 26′ 46″ ; 79° 58′ 56″"#).unwrap(), "semi3"); |
||||
assert_eq!(reference, parse(r#"40°26′46″79°58′56″"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse(r#"40 26 46 79 58 56"#).unwrap(), "no symbols"); |
||||
} |
||||
|
||||
#[test] |
||||
fn dm_ns_dm_ew() { |
||||
let reference = Point::new(-79.98221666666667, 40.44055); |
||||
|
||||
assert_eq!(reference, parse(r#"40° 26.433′ N 79° 58.933′ W"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse(r#"40° 26,433′ N 79° 58,933′ W"#).unwrap(), "comma dec"); |
||||
assert_eq!(reference, parse(r#"40° 26.433’ N 79° 58.933’ W"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse(r#"40° 26.433′ N, 79° 58.933′ W"#).unwrap(), "comma"); |
||||
assert_eq!(reference, parse(r#"40° 26,433′ N, 79° 58,933′ W"#).unwrap(), "comma dec and comma sep"); |
||||
assert_eq!(reference, parse(r#"40° 26.433′ N; 79° 58.933′ W"#).unwrap(), "semi"); |
||||
assert_eq!(reference, parse(r#"40° 26.433′ N, 79° 58.933′ W"#).unwrap(), "comma2"); |
||||
assert_eq!(reference, parse(r#"40° 26.433′ N; 79° 58.933′ W"#).unwrap(), "semi2"); |
||||
assert_eq!(reference, parse(r#"40° 26.433 N,79° 58.933′ W"#).unwrap(), "comma3"); |
||||
assert_eq!(reference, parse(r#"40° 26.433 N;79° 58.933′ W"#).unwrap(), "semi3"); |
||||
assert_eq!(reference, parse(r#"40° 26.433′N , 79° 58.933′ W"#).unwrap(), "comma4"); |
||||
assert_eq!(reference, parse(r#"40° 26.433′N ; 79° 58.933′ W"#).unwrap(), "semi4"); |
||||
assert_eq!(reference, parse(r#"40°26.433′N79°58.933′W"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse(r#"40°26.433N79°58.933W"#).unwrap(), "compact, no min mark"); |
||||
assert_eq!(reference, parse(r#"40 26.433 N 79 58.933 W"#).unwrap(), "no symbols"); |
||||
assert_eq!(reference, parse(r#"-40 26.433 S -79 58.933 E"#).unwrap(), "inverted"); |
||||
} |
||||
|
||||
#[test] |
||||
fn ns_dm_ew_dm() { |
||||
let reference = Point::new(-79.98221666666667, 40.44055); |
||||
|
||||
assert_eq!(reference, parse(r#"N 40° 26.433′ W 79° 58.933′"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse(r#"N 40° 26.433’ W 79° 58.933’"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse(r#"N 40° 26,433′ W 79° 58,933′"#).unwrap(), "comma dec"); |
||||
assert_eq!(reference, parse(r#"N 40° 26.433′, W 79° 58.933′"#).unwrap(), "comma"); |
||||
assert_eq!(reference, parse(r#"N 40° 26,433′, W 79° 58,933′"#).unwrap(), "comma dec and comma sep"); |
||||
assert_eq!(reference, parse(r#"N 40° 26.433′; W 79° 58.933′"#).unwrap(), "semi"); |
||||
assert_eq!(reference, parse(r#"N 40° 26.433′, W 79° 58.933′"#).unwrap(), "comma2"); |
||||
assert_eq!(reference, parse(r#"N 40° 26.433′; W 79° 58.933′"#).unwrap(), "semi2"); |
||||
assert_eq!(reference, parse(r#"N 40° 26.433 ,W 79° 58.933′"#).unwrap(), "comma3"); |
||||
assert_eq!(reference, parse(r#"N 40° 26.433 ;W 79° 58.933′"#).unwrap(), "semi3"); |
||||
assert_eq!(reference, parse(r#"N 40° 26.433′ , W 79° 58.933′"#).unwrap(), "comma4"); |
||||
assert_eq!(reference, parse(r#"N 40° 26.433′ ; W 79° 58.933′"#).unwrap(), "semi4"); |
||||
assert_eq!(reference, parse(r#"N40°26.433′W79°58.933′"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse(r#"N40°26.433W79°58.933"#).unwrap(), "compact, no min mark"); |
||||
assert_eq!(reference, parse(r#"N40 26.433W79 58.933"#).unwrap(), "no symbols"); |
||||
assert_eq!(reference, parse(r#"S -40 26.433 E -79 58.933"#).unwrap(), "inverted"); |
||||
} |
||||
|
||||
#[test] |
||||
fn dm_dm() { |
||||
let reference = Point::new(79.98221666666667, 40.44055); |
||||
|
||||
assert_eq!(reference, parse(r#"40° 26.433′ 79° 58.933′"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse(r#"40° 26.433’ 79° 58.933’"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse(r#"40° 26,433′ 79° 58,933′"#).unwrap(), "comma dec"); |
||||
assert_eq!(reference, parse(r#"40° 26.433′, 79° 58.933′"#).unwrap(), "comma"); |
||||
assert_eq!(reference, parse(r#"40° 26,433′, 79° 58,933′"#).unwrap(), "comma dec and comma sep"); |
||||
assert_eq!(reference, parse(r#"40° 26.433′; 79° 58.933′"#).unwrap(), "semi"); |
||||
assert_eq!(reference, parse(r#"40° 26.433′, 79° 58.933′"#).unwrap(), "comma2"); |
||||
assert_eq!(reference, parse(r#"40° 26.433′; 79° 58.933′"#).unwrap(), "semi2"); |
||||
assert_eq!(reference, parse(r#"40° 26.433 ,79° 58.933′"#).unwrap(), "comma3"); |
||||
assert_eq!(reference, parse(r#"40° 26.433 ;79° 58.933′"#).unwrap(), "semi3"); |
||||
assert_eq!(reference, parse(r#"40° 26.433′ , 79° 58.933′"#).unwrap(), "comma4"); |
||||
assert_eq!(reference, parse(r#"40° 26.433′ ; 79° 58.933′"#).unwrap(), "semi4"); |
||||
assert_eq!(reference, parse(r#"40°26.433′79°58.933′"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse(r#"40 26.433 79 58.933"#).unwrap(), "no symbols"); |
||||
} |
||||
|
||||
#[test] |
||||
fn d_ns_d_ew() { |
||||
let reference = Point::new(-79.9822, 40.44055); |
||||
|
||||
assert_eq!(reference, parse(r#"40.44055° N 79.9822° W"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse(r#"40,44055° N 79,9822° W"#).unwrap(), "comma dec"); |
||||
assert_eq!(reference, parse(r#"40.44055 N 79.9822 W"#).unwrap(), "no deg"); |
||||
assert_eq!(reference, parse(r#"40.44055° N, 79.9822° W"#).unwrap(), "comma"); |
||||
assert_eq!(reference, parse(r#"40,44055° N, 79,9822° W"#).unwrap(), "comma comma"); |
||||
assert_eq!(reference, parse(r#"40.44055° N; 79.9822° W"#).unwrap(), "semi"); |
||||
assert_eq!(reference, parse(r#"40.44055° N,79.9822° W"#).unwrap(), "comma2"); |
||||
assert_eq!(reference, parse(r#"40.44055° N;79.9822° W"#).unwrap(), "semi2"); |
||||
assert_eq!(reference, parse(r#"40.44055° N ,79.9822° W"#).unwrap(), "comma3"); |
||||
assert_eq!(reference, parse(r#"40.44055° N ;79.9822° W"#).unwrap(), "semi3"); |
||||
assert_eq!(reference, parse(r#"40.44055N79.9822W"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse(r#"-40.44055° S -79.9822° E"#).unwrap(), "inverted"); |
||||
} |
||||
|
||||
#[test] |
||||
fn d_d() { |
||||
let reference = Point::new(79.9822, 40.44055); |
||||
|
||||
assert_eq!(reference, parse(r#"40.44055° 79.9822°"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse(r#"40,44055° 79,9822°"#).unwrap(), "comma dec"); |
||||
assert_eq!(reference, parse(r#"40.44055 79.9822"#).unwrap(), "no deg"); |
||||
assert_eq!(reference, parse(r#"40.44055°, 79.9822°"#).unwrap(), "comma"); |
||||
assert_eq!(reference, parse(r#"40,44055°, 79,9822°"#).unwrap(), "comma comma"); |
||||
assert_eq!(reference, parse(r#"40.44055°; 79.9822°"#).unwrap(), "semi"); |
||||
assert_eq!(reference, parse(r#"40.44055°,79.9822°"#).unwrap(), "comma2"); |
||||
assert_eq!(reference, parse(r#"40.44055°;79.9822°"#).unwrap(), "semi2"); |
||||
assert_eq!(reference, parse(r#"40.44055° ,79.9822°"#).unwrap(), "comma3"); |
||||
assert_eq!(reference, parse(r#"40.44055° ;79.9822°"#).unwrap(), "semi3"); |
||||
} |
||||
|
||||
|
||||
// ------ lat / lng separate ------
|
||||
|
||||
#[test] |
||||
fn dms_nsew() { |
||||
let reference = 40.44611111111111; |
||||
|
||||
assert_eq!(reference, parse_lat(r#"40° 26′ 46″ N"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse_lat(r#"40° 26’ 46″ N"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse_lat(r#"40°26′46″N"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse_lat(r#"40°26′46N"#).unwrap(), "compact, no sec mark"); |
||||
assert_eq!(reference, parse_lat(r#"40 26 46 N"#).unwrap(), "no symbols"); |
||||
assert_eq!(reference, parse_lat(r#"-40 26 46 S"#).unwrap(), "inverted"); |
||||
|
||||
assert_eq!(reference, parse_lng(r#"40° 26′ 46″ E"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse_lng(r#"40° 26’ 46″ E"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse_lng(r#"40°26′46″E"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse_lng(r#"40°26′46E"#).unwrap(), "compact, no sec mark"); |
||||
assert_eq!(reference, parse_lng(r#"40 26 46 E"#).unwrap(), "no symbols"); |
||||
assert_eq!(reference, parse_lng(r#"-40 26 46 W"#).unwrap(), "inverted"); |
||||
} |
||||
|
||||
#[test] |
||||
fn nsew_dms() { |
||||
let reference = 40.44611111111111; |
||||
|
||||
assert_eq!(reference, parse_lat(r#"N 40° 26′ 46″"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse_lat(r#"N 40° 26’ 46″"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse_lat(r#"N40°26′46"#).unwrap(), "compact, no sec mark"); |
||||
assert_eq!(reference, parse_lat(r#"N 40 26 46"#).unwrap(), "no symbols"); |
||||
assert_eq!(reference, parse_lat(r#"S -40 26 46"#).unwrap(), "inverted"); |
||||
|
||||
assert_eq!(reference, parse_lng(r#"E 40° 26′ 46″"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse_lng(r#"E 40° 26’ 46″"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse_lng(r#"E40°26′46"#).unwrap(), "compact, no sec mark"); |
||||
assert_eq!(reference, parse_lng(r#"E 40 26 46"#).unwrap(), "no symbols"); |
||||
assert_eq!(reference, parse_lng(r#"W -40 26 46"#).unwrap(), "inverted"); |
||||
} |
||||
|
||||
#[test] |
||||
fn dms() { |
||||
let reference = 40.44611111111111; |
||||
let ref_neg = -reference; |
||||
|
||||
assert_eq!(reference, parse_lat(r#"40° 26′ 46″"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse_lat(r#"40° 26’ 46″"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse_lat(r#"40°26′46″"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse_lat(r#"40 26 46"#).unwrap(), "no symbols"); |
||||
assert_eq!(ref_neg, parse_lat(r#"-40° 26′ 46″"#).unwrap(), "neg"); |
||||
|
||||
assert_eq!(reference, parse_lng(r#"40° 26′ 46″"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse_lng(r#"40° 26’ 46″"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse_lng(r#"40°26′46″"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse_lng(r#"40 26 46"#).unwrap(), "no symbols"); |
||||
assert_eq!(ref_neg, parse_lng(r#"-40° 26′ 46″"#).unwrap(), "neg"); |
||||
} |
||||
|
||||
#[test] |
||||
fn dm_nsew() { |
||||
let reference = 40.44055; |
||||
|
||||
assert_eq!(reference, parse_lat(r#"40° 26.433′ N"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse_lat(r#"40° 26,433′ N"#).unwrap(), "comma dec"); |
||||
assert_eq!(reference, parse_lat(r#"40° 26.433’ N"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse_lat(r#"40°26.433′N"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse_lat(r#"40°26.433N"#).unwrap(), "compact, no min mark"); |
||||
assert_eq!(reference, parse_lat(r#"40 26.433 N"#).unwrap(), "no symbols"); |
||||
assert_eq!(reference, parse_lat(r#"-40 26.433 S"#).unwrap(), "inverted"); |
||||
|
||||
assert_eq!(reference, parse_lng(r#"40° 26.433′ E"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse_lng(r#"40° 26,433′ E"#).unwrap(), "comma dec"); |
||||
assert_eq!(reference, parse_lng(r#"40° 26.433’ E"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse_lng(r#"40°26.433′E"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse_lng(r#"40°26.433E"#).unwrap(), "compact, no min mark"); |
||||
assert_eq!(reference, parse_lng(r#"40 26.433 E"#).unwrap(), "no symbols"); |
||||
assert_eq!(reference, parse_lng(r#"-40 26.433 W"#).unwrap(), "inverted"); |
||||
} |
||||
|
||||
#[test] |
||||
fn nsew_dm() { |
||||
let reference = 40.44055; |
||||
|
||||
assert_eq!(reference, parse_lat(r#"N 40° 26.433′"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse_lat(r#"N 40° 26.433’"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse_lat(r#"N 40° 26,433′"#).unwrap(), "comma dec"); |
||||
assert_eq!(reference, parse_lat(r#"N40°26.433′"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse_lat(r#"N40°26.433"#).unwrap(), "compact, no min mark"); |
||||
assert_eq!(reference, parse_lat(r#"N40 26.433"#).unwrap(), "no symbols"); |
||||
assert_eq!(reference, parse_lat(r#"S -40 26.433"#).unwrap(), "inverted"); |
||||
|
||||
assert_eq!(reference, parse_lng(r#"E 40° 26.433′"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse_lng(r#"E 40° 26.433’"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse_lng(r#"E 40° 26,433′"#).unwrap(), "comma dec"); |
||||
assert_eq!(reference, parse_lng(r#"E40°26.433′"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse_lng(r#"E40°26.433"#).unwrap(), "compact, no min mark"); |
||||
assert_eq!(reference, parse_lng(r#"E40 26.433"#).unwrap(), "no symbols"); |
||||
assert_eq!(reference, parse_lng(r#"W -40 26.433"#).unwrap(), "inverted"); |
||||
} |
||||
|
||||
#[test] |
||||
fn dm() { |
||||
let reference = 40.44055; |
||||
let ref_neg = -reference; |
||||
|
||||
assert_eq!(reference, parse_lat(r#"40° 26.433′"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse_lat(r#"40° 26.433’"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse_lat(r#"40° 26,433′"#).unwrap(), "comma dec"); |
||||
assert_eq!(reference, parse_lat(r#"40°26.433′"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse_lat(r#"40 26.433"#).unwrap(), "no symbols"); |
||||
assert_eq!(ref_neg, parse_lat(r#"-40° 26.433′"#).unwrap(), "neg"); |
||||
|
||||
assert_eq!(reference, parse_lng(r#"40° 26.433′"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse_lng(r#"40° 26.433’"#).unwrap(), "fancy apos"); |
||||
assert_eq!(reference, parse_lng(r#"40° 26,433′"#).unwrap(), "comma dec"); |
||||
assert_eq!(reference, parse_lng(r#"40°26.433′"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse_lng(r#"40 26.433"#).unwrap(), "no symbols"); |
||||
assert_eq!(ref_neg, parse_lng(r#"-40° 26.433′"#).unwrap(), "neg"); |
||||
} |
||||
|
||||
#[test] |
||||
fn d_nsew() { |
||||
let reference = 40.44055; |
||||
assert_eq!(reference, parse_lat(r#"40.44055° N"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse_lat(r#"40,44055° N"#).unwrap(), "comma dec"); |
||||
assert_eq!(reference, parse_lat(r#"40.44055 N"#).unwrap(), "no deg"); |
||||
assert_eq!(reference, parse_lat(r#"40.44055N"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse_lat(r#"-40.44055° S"#).unwrap(), "inverted"); |
||||
|
||||
assert_eq!(reference, parse_lng(r#"40.44055° E"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse_lng(r#"40,44055° E"#).unwrap(), "comma dec"); |
||||
assert_eq!(reference, parse_lng(r#"40.44055 E"#).unwrap(), "no deg"); |
||||
assert_eq!(reference, parse_lng(r#"40.44055E"#).unwrap(), "compact"); |
||||
assert_eq!(reference, parse_lng(r#"-40.44055° W"#).unwrap(), "inverted"); |
||||
} |
||||
|
||||
#[test] |
||||
fn d() { |
||||
let reference = 40.44055; |
||||
let ref_neg = -reference; |
||||
|
||||
assert_eq!(reference, parse_lat(r#"40.44055°"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse_lat(r#"40,44055°"#).unwrap(), "comma dec"); |
||||
assert_eq!(reference, parse_lat(r#"40.44055"#).unwrap(), "no deg"); |
||||
assert_eq!(ref_neg, parse_lat(r#"-40.44055"#).unwrap(), "no deg"); |
||||
|
||||
assert_eq!(reference, parse_lng(r#"40.44055°"#).unwrap(), "normal"); |
||||
assert_eq!(reference, parse_lng(r#"40,44055°"#).unwrap(), "comma dec"); |
||||
assert_eq!(reference, parse_lng(r#"40.44055"#).unwrap(), "no deg"); |
||||
assert_eq!(ref_neg, parse_lng(r#"-40.44055"#).unwrap(), "no deg"); |
||||
} |
Loading…
Reference in new issue