Annotate

spec/util_jsonpointer_spec.lua @ 13014:06453c564141

util.startup: Add prosody.started promise to easily execute code after startup To avoid a race where server-started fires before the promise function body is run (on next tick), I moved server-started to fire on the next tick, which seems sensible anyway. Errors are logged, I'm not sure if we ought to be doing something more here. I'm sure we'll find out.
author Matthew Wild <mwild1@gmail.com>
date Sat, 01 Apr 2023 11:56:38 +0100
parent 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()
12777
4d5549de27e6 util.jsonpointer: Improve tests
Kim Alvefur <zash@zash.se>
parents: 12495
diff changeset
24 assert.is_nil(jp.resolve("string", "/string"))
12495
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 assert.same(example, jp.resolve(example, ""));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 assert.same({ "bar", "baz" }, jp.resolve(example, "/foo"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 assert.same("bar", jp.resolve(example, "/foo/0"));
12777
4d5549de27e6 util.jsonpointer: Improve tests
Kim Alvefur <zash@zash.se>
parents: 12495
diff changeset
28 assert.same(nil, jp.resolve(example, "/foo/-"));
12495
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 assert.same(0, jp.resolve(example, "/"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 assert.same(1, jp.resolve(example, "/a~1b"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 assert.same(2, jp.resolve(example, "/c%d"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 assert.same(3, jp.resolve(example, "/e^f"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 assert.same(4, jp.resolve(example, "/g|h"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 assert.same(5, jp.resolve(example, "/i\\j"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 assert.same(6, jp.resolve(example, "/k\"l"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 assert.same(7, jp.resolve(example, "/ "));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 assert.same(8, jp.resolve(example, "/m~0n"));
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 end)
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 end)
5bf9056dca2c util.jsonpointer: Add basic tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 end)