Changeset

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
parents 12491:dc0c20753d6c
children 12496:87c3d45208ef
files spec/util_jsonpointer_spec.lua
diffstat 1 files changed, 38 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spec/util_jsonpointer_spec.lua	Sun May 08 18:03:44 2022 +0200
@@ -0,0 +1,38 @@
+describe("util.jsonpointer", function()
+	local json, jp;
+	setup(function()
+		json = require "util.json";
+		jp = require "util.jsonpointer";
+	end)
+	describe("resolve()", function()
+		local example;
+		setup(function()
+			example = json.decode([[{
+				"foo": ["bar", "baz"],
+				"": 0,
+				"a/b": 1,
+				"c%d": 2,
+				"e^f": 3,
+				"g|h": 4,
+				"i\\j": 5,
+				"k\"l": 6,
+				" ": 7,
+				"m~n": 8
+		 }]])
+		end)
+		it("works", function()
+			assert.same(example, jp.resolve(example, ""));
+			assert.same({ "bar", "baz" }, jp.resolve(example, "/foo"));
+			assert.same("bar", jp.resolve(example, "/foo/0"));
+			assert.same(0, jp.resolve(example, "/"));
+			assert.same(1, jp.resolve(example, "/a~1b"));
+			assert.same(2, jp.resolve(example, "/c%d"));
+			assert.same(3, jp.resolve(example, "/e^f"));
+			assert.same(4, jp.resolve(example, "/g|h"));
+			assert.same(5, jp.resolve(example, "/i\\j"));
+			assert.same(6, jp.resolve(example, "/k\"l"));
+			assert.same(7, jp.resolve(example, "/ "));
+			assert.same(8, jp.resolve(example, "/m~0n"));
+		end)
+	end)
+end)