use json_pointer::JsonPointer;
use lazy_static::lazy_static;
use serde_json::{json, Value};
lazy_static! {
static ref JSON: Value = json!({
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8,
});
}
macro_rules! rfc_tests {
($($ptr:expr => $json:tt;)*) => {
#[test]
fn rfc_tests() {
$({
let ptr = $ptr.parse::<JsonPointer<_, _>>().unwrap();
assert_eq!(ptr.get(&JSON).unwrap(), &json!($json));
})*
}
}
}
rfc_tests! {
"" => {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8,
};
"/foo" => ["bar", "baz"];
"/foo/0" => "bar";
"/" => 0;
"/a~1b" => 1;
"/c%d" => 2;
"/e^f" => 3;
"/g|h" => 4;
"/i\\j" => 5;
"/k\"l" => 6;
"/ " => 7;
"/m~0n" => 8;
"#" => {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8,
};
"#/foo" => ["bar", "baz"];
"#/foo/0" => "bar";
"#/" => 0;
"#/a~1b" => 1;
"#/c%25d" => 2;
"#/e%5Ef" => 3;
"#/g%7Ch" => 4;
"#/i%5Cj" => 5;
"#/k%22l" => 6;
"#/%20" => 7;
"#/m~0n" => 8;
}