12495
|
1 describe("util.jsonpointer", function()
|
|
2 local json, jp;
|
|
3 setup(function()
|
|
4 json = require "util.json";
|
|
5 jp = require "util.jsonpointer";
|
|
6 end)
|
|
7 describe("resolve()", function()
|
|
8 local example;
|
|
9 setup(function()
|
|
10 example = json.decode([[{
|
|
11 "foo": ["bar", "baz"],
|
|
12 "": 0,
|
|
13 "a/b": 1,
|
|
14 "c%d": 2,
|
|
15 "e^f": 3,
|
|
16 "g|h": 4,
|
|
17 "i\\j": 5,
|
|
18 "k\"l": 6,
|
|
19 " ": 7,
|
|
20 "m~n": 8
|
|
21 }]])
|
|
22 end)
|
|
23 it("works", function()
|
|
24 assert.same(example, jp.resolve(example, ""));
|
|
25 assert.same({ "bar", "baz" }, jp.resolve(example, "/foo"));
|
|
26 assert.same("bar", jp.resolve(example, "/foo/0"));
|
|
27 assert.same(0, jp.resolve(example, "/"));
|
|
28 assert.same(1, jp.resolve(example, "/a~1b"));
|
|
29 assert.same(2, jp.resolve(example, "/c%d"));
|
|
30 assert.same(3, jp.resolve(example, "/e^f"));
|
|
31 assert.same(4, jp.resolve(example, "/g|h"));
|
|
32 assert.same(5, jp.resolve(example, "/i\\j"));
|
|
33 assert.same(6, jp.resolve(example, "/k\"l"));
|
|
34 assert.same(7, jp.resolve(example, "/ "));
|
|
35 assert.same(8, jp.resolve(example, "/m~0n"));
|
|
36 end)
|
|
37 end)
|
|
38 end)
|