tests for json

This commit is contained in:
Greg Shuflin 2022-10-17 01:42:42 -07:00
parent 32508b25f5
commit 26f813ee16

View File

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