Annotate

spec/util_jsonpointer_spec.lua @ 12559:865631ebb9f2

util.hashes: Refactor hash functions to use OpenSSL EVP methods (fix #1698) MD5() is deprecated, but EVP_md5() is not. Functions in macros like this make it awkward to apply static analysis and code formatting.
author Kim Alvefur <zash@zash.se>
date Thu, 10 Sep 2020 21:58:23 +0200
parent 12495:5bf9056dca2c
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)