tests for json
This commit is contained in:
parent
32508b25f5
commit
26f813ee16
26
src/lib.rs
26
src/lib.rs
@ -76,18 +76,26 @@ mod tests {
|
|||||||
literal("-")
|
literal("-")
|
||||||
.optional()
|
.optional()
|
||||||
.then(json_number_inner)
|
.then(json_number_inner)
|
||||||
.map(|(maybe_sign, val)| {
|
.map(|(maybe_sign, mut val)| {
|
||||||
if maybe_sign.is_some() {
|
if maybe_sign.is_some() {
|
||||||
val * -1.0
|
val *= -1.0;
|
||||||
} else {
|
|
||||||
val
|
|
||||||
}
|
}
|
||||||
|
JsonValue::Num(val)
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(json_number.parse("-383").unwrap().0, -383f64);
|
assert_eq!(
|
||||||
assert_eq!(json_number.parse("-.383").unwrap().0, -0.383);
|
json_number.parse("-383").unwrap().0,
|
||||||
assert_eq!(json_number.parse(".383").unwrap().0, 0.383);
|
JsonValue::Num(-383f64)
|
||||||
assert_eq!(json_number.parse("-1.383").unwrap().0, -1.383);
|
);
|
||||||
|
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((
|
let json_string = seq((
|
||||||
literal_char('"'),
|
literal_char('"'),
|
||||||
@ -96,7 +104,7 @@ mod tests {
|
|||||||
))
|
))
|
||||||
.map(|(_, s, _)| JsonValue::Str(s.to_string()));
|
.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), "")));
|
assert_eq!(json_value.parse("true"), Ok((JsonValue::Bool(true), "")));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user