Annotate

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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12495
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 describe("util.jsonpointer", function()
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local json, jp;
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 setup(function()
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 json = require "util.json";
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 jp = require "util.jsonpointer";
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 end)
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 describe("resolve()", function()
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local example;
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 setup(function()
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 example = json.decode([[{
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 "foo": ["bar", "baz"],
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 "": 0,
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 "a/b": 1,
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 "c%d": 2,
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 "e^f": 3,
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 "g|h": 4,
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 "i\\j": 5,
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 "k\"l": 6,
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 " ": 7,
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 "m~n": 8
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 }]])
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 end)
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 it("works", function()
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 assert.same(example, jp.resolve(example, ""));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 assert.same({ "bar", "baz" }, jp.resolve(example, "/foo"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 assert.same("bar", jp.resolve(example, "/foo/0"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 assert.same(0, jp.resolve(example, "/"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 assert.same(1, jp.resolve(example, "/a~1b"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 assert.same(2, jp.resolve(example, "/c%d"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 assert.same(3, jp.resolve(example, "/e^f"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 assert.same(4, jp.resolve(example, "/g|h"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 assert.same(5, jp.resolve(example, "/i\\j"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 assert.same(6, jp.resolve(example, "/k\"l"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 assert.same(7, jp.resolve(example, "/ "));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 assert.same(8, jp.resolve(example, "/m~0n"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 end)
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 end)
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 end)