@@ -31,4 +31,38 @@ public void testPathHashCode() {
31
31
assertEquals (Path .of (".a.b.c" ).hashCode (), Path .of (".a.b.c" ).hashCode ());
32
32
assertNotEquals (Path .of (".a.b.c" ).hashCode (), Path .of (".b.c" ).hashCode ());
33
33
}
34
+
35
+ @ Test
36
+ public void testJsonPointer () {
37
+ assertEquals (Path .ofJsonPointer ("" ), Path .ROOT_PATH );
38
+ assertEquals (Path .ofJsonPointer ("/" ), Path .of (".[\" \" ]" ));
39
+ assertEquals (Path .ofJsonPointer ("//0" ), Path .of (".[\" \" ].[0]" ));
40
+ assertEquals (Path .ofJsonPointer ("//" ), Path .of (".[\" \" ].[\" \" ]" ));
41
+ assertEquals (Path .ofJsonPointer ("// " ), Path .of (".[\" \" ].[\" \" ]" ));
42
+ assertEquals (Path .ofJsonPointer ("/a/b/c" ), Path .of (".[\" a\" ].[\" b\" ].[\" c\" ]" ));
43
+ assertEquals (Path .ofJsonPointer ("/a/0/c" ), Path .of (".[\" a\" ].[0].[\" c\" ]" ));
44
+ assertEquals (Path .ofJsonPointer ("/a/0b/c" ), Path .of (".[\" a\" ].[\" 0b\" ].[\" c\" ]" ));
45
+ assertEquals (Path .ofJsonPointer ("/ab/cd/1010" ), Path .of (".[\" ab\" ].[\" cd\" ].[1010]" ));
46
+ assertEquals (Path .ofJsonPointer ("/a/b/c" ).hashCode (), Path .of (".[\" a\" ].[\" b\" ].[\" c\" ]" ).hashCode ());
47
+
48
+ // escape test
49
+ assertEquals (Path .ofJsonPointer ("/a/~0" ), Path .of (".[\" a\" ].[\" ~\" ]" ));
50
+ assertEquals (Path .ofJsonPointer ("/a/~1" ), Path .of (".[\" a\" ].[\" /\" ]" ));
51
+ assertEquals (Path .ofJsonPointer ("/a/~0/c" ), Path .of (".[\" a\" ].[\" ~\" ].[\" c\" ]" ));
52
+ assertEquals (Path .ofJsonPointer ("/a/~1/c" ), Path .of (".[\" a\" ].[\" /\" ].[\" c\" ]" ));
53
+ assertEquals (Path .ofJsonPointer ("/a/~~/c" ), Path .of (".[\" a\" ].[\" ~~\" ].[\" c\" ]" ));
54
+ assertEquals (Path .ofJsonPointer ("/~/~~~/~" ), Path .of (".[\" ~\" ].[\" ~~~\" ].[\" ~\" ]" ));
55
+ assertEquals (Path .ofJsonPointer ("/~/~~~/~~" ), Path .of (".[\" ~\" ].[\" ~~~\" ].[\" ~~\" ]" ));
56
+ assertEquals (Path .ofJsonPointer ("/~/~~~0/~~" ), Path .of (".[\" ~\" ].[\" ~~~\" ].[\" ~~\" ]" ));
57
+ assertEquals (Path .ofJsonPointer ("/~/'.'/~~" ), Path .of (".[\" ~\" ].[\" '.'\" ].[\" ~~\" ]" ));
58
+
59
+ // json path escape test
60
+ assertEquals (Path .ofJsonPointer ("/\t " ), Path .of (".[\" \t \" ]" ));
61
+ assertEquals (Path .ofJsonPointer ("/\u0074 " ), Path .of (".[\" \u0074 \" ]" ));
62
+ assertEquals (Path .ofJsonPointer ("/'" ), Path .of (".[\" '\" ]" ));
63
+ assertEquals (Path .ofJsonPointer ("/\' " ), Path .of (".[\" \' \" ]" ));
64
+ assertEquals (Path .ofJsonPointer ("/\" " ), Path .of (".[\" \" \" ]" ));
65
+ assertEquals (Path .ofJsonPointer ("/\n " ), Path .of (".[\" \n \" ]" ));
66
+ assertEquals (Path .ofJsonPointer ("/\\ " ), Path .of (".[\" \\ \" ]" ));
67
+ }
34
68
}
0 commit comments