MCPcopy Create free account
hub / github.com/chanced/jsonptr / resolve_json

Function resolve_json

src/resolve.rs:604–714  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

602 #[test]
603 #[cfg(feature = "json")]
604 fn resolve_json() {
605 use serde_json::json;
606
607 let data = &json!({
608 "array": ["bar", "baz"],
609 "object": {
610 "object": {"baz": {"qux": "quux"}},
611 "strings": ["zero", "one", "two"],
612 "nothing": null,
613 "bool": true,
614 "objects": [{"field": "zero"}, {"field": "one"}, {"field": "two"}]
615 },
616 "": 0,
617 "a/b": 1,
618 "c%d": 2,
619 "e^f": 3,
620 "g|h": 4,
621 "i\\j": 5,
622 "k\"l": 6,
623 " ": 7,
624 "m~n": 8
625 });
626 // let data = &data;
627
628 Test::all([
629 // 0
630 Test {
631 ptr: "",
632 data,
633 expected: Ok(data),
634 },
635 // 1
636 Test {
637 ptr: "/array",
638 data,
639 expected: Ok(data.get("array").unwrap()), // ["bar", "baz"]
640 },
641 // 2
642 Test {
643 ptr: "/array/0",
644 data,
645 expected: Ok(data.get("array").unwrap().get(0).unwrap()), // "bar"
646 },
647 // 3
648 Test {
649 ptr: "/a~1b",
650 data,
651 expected: Ok(data.get("a/b").unwrap()), // 1
652 },
653 // 4
654 Test {
655 ptr: "/c%d",
656 data,
657 expected: Ok(data.get("c%d").unwrap()), // 2
658 },
659 // 5
660 Test {
661 ptr: "/e^f",

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected