Skip to content

Commit

Permalink
expect different error
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkirk committed Apr 10, 2023
1 parent b79b6e5 commit 1936b8e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions src/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<GeoJson>().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),
}
}

Expand Down Expand Up @@ -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::<GeoJson>(),
Err(Error::FeatureInvalidIdentifierType(_))
));
match feature_json_str.parse::<GeoJson>().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::<GeoJson>().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),
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/feature_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit 1936b8e

Please sign in to comment.