Rewrite Value::lookup to not require an allocation

This commit is contained in:
Erick Tryzelaar
2015-05-18 22:19:30 -07:00
parent 5fe85128c2
commit 50cac7f985
2 changed files with 19 additions and 4 deletions
+9
View File
@@ -1066,6 +1066,15 @@ fn test_missing_fmt_renamed_field() {
assert_eq!(value, Foo { x: Some(5) });
}
#[test]
fn test_find_path() {
let obj: Value = json::from_str(r#"{"x": {"a": 1}, "y": 2}"#).unwrap();
assert!(obj.find_path(&["x", "a"]).unwrap() == &Value::U64(1));
assert!(obj.find_path(&["y"]).unwrap() == &Value::U64(2));
assert!(obj.find_path(&["z"]).is_none());
}
#[test]
fn test_lookup() {
let obj: Value = json::from_str(r#"{"x": {"a": 1}, "y": 2}"#).unwrap();