Skip to content

Commit

Permalink
fix: allow negative floats
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKreil committed Jul 22, 2024
1 parent 5b5f81a commit 0881893
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion versatiles_geometry/src/geo/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl GeoValue {

pub fn parse_str(value: &str) -> Self {
lazy_static! {
static ref REG_DOUBLE: Regex = RegexBuilder::new(r"^\d*\.\d+$").build().unwrap();
static ref REG_DOUBLE: Regex = RegexBuilder::new(r"^\-?\d*\.\d+$").build().unwrap();
static ref REG_INT: Regex = RegexBuilder::new(r"^\-\d+$").build().unwrap();
static ref REG_UINT: Regex = RegexBuilder::new(r"^\d+$").build().unwrap();
}
Expand Down Expand Up @@ -290,4 +290,17 @@ mod tests {
assert_ne!(GeoValue::from(1u64), GeoValue::from(2u64));
assert_ne!(GeoValue::from(false), GeoValue::from(true));
}

#[test]
fn test_parse_str() {
assert_eq!(GeoValue::parse_str("true"), GeoValue::Bool(true));
assert_eq!(GeoValue::parse_str("false"), GeoValue::Bool(false));
assert_eq!(GeoValue::parse_str("3.14"), GeoValue::Double(3.14));
assert_eq!(GeoValue::parse_str("-3.14"), GeoValue::Double(-3.14));
assert_eq!(GeoValue::parse_str("-42"), GeoValue::Int(-42));
assert_eq!(GeoValue::parse_str("42"), GeoValue::UInt(42));
assert_eq!(GeoValue::parse_str("hello"), GeoValue::from("hello"));
assert_eq!(GeoValue::parse_str("123abc"), GeoValue::from("123abc"));
assert_eq!(GeoValue::parse_str(""), GeoValue::from(""));
}
}

0 comments on commit 0881893

Please sign in to comment.