From 26f813ee1640141ec8ceebc2b9aa362122832cea Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Mon, 17 Oct 2022 01:42:42 -0700 Subject: [PATCH] tests for json --- src/lib.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0fd4ed5..16489f1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,18 +76,26 @@ mod tests { literal("-") .optional() .then(json_number_inner) - .map(|(maybe_sign, val)| { + .map(|(maybe_sign, mut val)| { if maybe_sign.is_some() { - val * -1.0 - } else { - val + val *= -1.0; } + JsonValue::Num(val) }); - assert_eq!(json_number.parse("-383").unwrap().0, -383f64); - assert_eq!(json_number.parse("-.383").unwrap().0, -0.383); - assert_eq!(json_number.parse(".383").unwrap().0, 0.383); - assert_eq!(json_number.parse("-1.383").unwrap().0, -1.383); + assert_eq!( + json_number.parse("-383").unwrap().0, + JsonValue::Num(-383f64) + ); + assert_eq!( + json_number.parse("-.383").unwrap().0, + JsonValue::Num(-0.383) + ); + assert_eq!(json_number.parse(".383").unwrap().0, JsonValue::Num(0.383)); + assert_eq!( + json_number.parse("-1.383").unwrap().0, + JsonValue::Num(-1.383) + ); let json_string = seq(( literal_char('"'), @@ -96,7 +104,7 @@ mod tests { )) .map(|(_, s, _)| JsonValue::Str(s.to_string())); - let json_value = choice((json_null, json_bool, json_string)); + let json_value = choice((json_null, json_bool, json_number, json_string)); assert_eq!(json_value.parse("true"), Ok((JsonValue::Bool(true), ""))); }