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), ""))); }