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