From 5526ce7bd17beda52047fbc3442e23e0174b79a7 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 26 Feb 2023 04:41:03 -0800 Subject: [PATCH] More test parameterization --- tests/json_parser.rs | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/tests/json_parser.rs b/tests/json_parser.rs index a5fe16a..2b515d5 100644 --- a/tests/json_parser.rs +++ b/tests/json_parser.rs @@ -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]