Comparison

spec/util_jsonpointer_spec.lua @ 12495:5bf9056dca2c 0.12

util.jsonpointer: Add basic tests Example values from RFC 6901
author Kim Alvefur <zash@zash.se>
date Sun, 08 May 2022 18:03:44 +0200
child 12777:4d5549de27e6
comparison
equal deleted inserted replaced
12491:dc0c20753d6c 12495:5bf9056dca2c
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)