From b7db411671b6366a4dbb3b9eda769c89e91bd21c Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Thu, 20 Oct 2022 23:37:46 -0700 Subject: [PATCH] json array --- src/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 50f76b3..cc0c351 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,11 +101,10 @@ mod tests { } fn json_array() -> impl JsonParser<'static, JsonValue> { - let val = whitespace() - .ignore_then(json_value()) - .then_ignore(whitespace()); + let val = json_value().delimited(whitespace(), whitespace()); repeated(val) + .separated_by(literal(","), false) .delimited(literal_char('['), literal_char(']')) .map(JsonValue::Array) } @@ -120,9 +119,9 @@ mod tests { json_string().parse(r#""yolo swagg""#).unwrap(), (JsonValue::Str("yolo swagg".into()), "") ); - //TODO not correct! + assert!(json_array().parse(r#"[ 4, 9, "ara",]"#).is_err()); assert_eq!( - json_array().parse(r#"[ 4 9 "foo" ]"#).unwrap(), + json_array().parse(r#"[ 4, 9, "foo" ]"#).unwrap(), ( JsonValue::Array(vec![ JsonValue::Num(4.),