From 1936b8e66aa46d4e9e7e5c76d146906646e3913f Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 10 Apr 2023 14:58:28 -0700 Subject: [PATCH] expect different error --- src/feature.rs | 16 ++++++++-------- src/feature_collection.rs | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/feature.rs b/src/feature.rs index 640ee91..358562f 100644 --- a/src/feature.rs +++ b/src/feature.rs @@ -336,8 +336,8 @@ mod tests { fn feature_json_invalid_geometry() { let geojson_str = r#"{"geometry":3.14,"properties":{},"type":"Feature"}"#; match geojson_str.parse::().unwrap_err() { - Error::FeatureInvalidGeometryValue(_) => (), - _ => unreachable!(), + Error::MalformedJson(e) => assert!(e.to_string().contains("expected a valid GeoJSON Geometry object")), + other => panic!("expecting FeatureInvalidGeometryValue, but got: {:?}", other), } } @@ -396,18 +396,18 @@ mod tests { #[test] fn decode_feature_with_invalid_id_type_object() { let feature_json_str = "{\"geometry\":{\"coordinates\":[1.1,2.1],\"type\":\"Point\"},\"id\":{},\"properties\":{},\"type\":\"Feature\"}"; - assert!(matches!( - feature_json_str.parse::(), - Err(Error::FeatureInvalidIdentifierType(_)) - )); + match feature_json_str.parse::().unwrap_err() { + Error::MalformedJson(e) => assert!(e.to_string().contains("Id")), + other => panic!("expected different error. Got: {:?}", other), + } } #[test] fn decode_feature_with_invalid_id_type_null() { let feature_json_str = "{\"geometry\":{\"coordinates\":[1.1,2.1],\"type\":\"Point\"},\"id\":null,\"properties\":{},\"type\":\"Feature\"}"; match feature_json_str.parse::().unwrap_err() { - Error::FeatureInvalidIdentifierType(_) => {} // pass, - other => panic!("unexpected err: {:?}", other), + Error::MalformedJson(e) => assert!(e.to_string().contains("Id")), + other => panic!("expected different error. Got: {:?}", other), } } diff --git a/src/feature_collection.rs b/src/feature_collection.rs index 5bd28ca..55554fa 100644 --- a/src/feature_collection.rs +++ b/src/feature_collection.rs @@ -342,11 +342,11 @@ mod tests { let actual_failure = FeatureCollection::from_str(&geometry_json).unwrap_err(); match actual_failure { - Error::ExpectedType { actual, expected } => { - assert_eq!(actual, "Geometry"); - assert_eq!(expected, "FeatureCollection"); + Error::MalformedJson(e) => { + assert!(e.to_string().contains("missing field")); + assert!(e.to_string().contains("features")); } - e => panic!("unexpected error: {}", e), - }; + other => panic!("expected other error. Got: {:?}", other) + } } }