Skip to content

Commit 8d44650

Browse files
committed
(test) add test for valuable
Signed-off-by: Ning Sun <[email protected]>
1 parent c6df4ef commit 8d44650

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

valuable/src/json.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@ impl Valuable for Json {
88
Json::Array(ref array) => array.as_value(),
99
Json::Bool(ref value) => value.as_value(),
1010
Json::Number(ref num) => {
11-
// TODO: check correctness for this
1211
if num.is_f64() {
1312
Value::F64(num.as_f64().unwrap())
1413
} else if num.is_i64() {
1514
Value::I64(num.as_i64().unwrap())
16-
} else if num.is_u64() {
17-
Value::U64(num.as_u64().unwrap())
1815
} else {
1916
unreachable!()
2017
}
@@ -30,13 +27,10 @@ impl Valuable for Json {
3027
Json::Array(ref array) => array.visit(visit),
3128
Json::Bool(ref value) => value.visit(visit),
3229
Json::Number(ref num) => {
33-
// TODO: check correctness for this
3430
if num.is_f64() {
3531
num.as_f64().unwrap().visit(visit)
3632
} else if num.is_i64() {
3733
num.as_i64().unwrap().visit(visit)
38-
} else if num.is_u64() {
39-
num.as_u64().unwrap().visit(visit)
4034
} else {
4135
unreachable!()
4236
}
@@ -66,3 +60,19 @@ impl Mappable for Map<String, Json> {
6660
(len, Some(len))
6761
}
6862
}
63+
64+
#[cfg(test)]
65+
mod test {
66+
use crate::{Valuable, Value};
67+
use serde_json::json;
68+
69+
#[test]
70+
fn test_json() {
71+
let j = json!({"a": 100, "b": 1.0, "c": -1});
72+
let jv = j.as_value();
73+
74+
assert!(matches!(jv, Value::Mappable(_)));
75+
76+
assert!(matches!(json!(100).as_value(), Value::I64(_)));
77+
}
78+
}

0 commit comments

Comments
 (0)