More test parameterization

This commit is contained in:
Greg Shuflin 2023-02-26 04:41:03 -08:00
parent 638139b7da
commit 5526ce7bd1

View File

@ -187,26 +187,23 @@ fn parse_json_primitives() {
);
}
#[test]
fn parse_json_array() {
assert!(json_array().parse(r#"[ 4, 9, "ara",]"#).is_err());
assert_eq!(
json_array().parse("[[],[]]").unwrap().0,
JsonValue::Array(vec![JsonValue::Array(vec![]), JsonValue::Array(vec![])])
);
assert_eq!(
json_array().parse(r#"[ 4, 9, "foo" ]"#).unwrap(),
(
#[rstest]
#[case(r#"[ 4, 9, "ara",]"#)]
fn parse_json_array_err(#[case] input: &str) {
assert!(json_array().parse(input).is_err());
}
#[rstest]
#[case("[[],[]]", (JsonValue::Array(vec![JsonValue::Array(vec![]), JsonValue::Array(vec![])]), ""))]
#[case(r#"[ 4, 9, "foo" ]"#, (
JsonValue::Array(vec![
JsonValue::Num(4.),
JsonValue::Num(9.0),
JsonValue::Str("foo".to_string())
]),
""
)
);
assert_eq!(
json_array().parse(r#"[8,null,[],5],{}"#).unwrap(),
))]
#[case(r#"[8,null,[],5],{}"#,
(
JsonValue::Array(vec![
JsonValue::Num(8.),
@ -215,9 +212,9 @@ fn parse_json_array() {
JsonValue::Num(5.),
]),
",{}"
)
);
assert_eq!(json_value().parse("true"), Ok((JsonValue::Bool(true), "")));
))]
fn parse_json_array(#[case] input: &str, #[case] expected: (JsonValue, &str)) {
assert_eq!(json_array().parse(input).unwrap(), expected);
}
#[test]