Software / code / prosody
Annotate
spec/util_jsonpointer_spec.lua @ 13762:81856814d74f 13.0
util.argparse: Fix bug (regression?) in argument parsing with --foo=bar
After recent changes, '--foo bar' was working, but '--foo=bar' was not. The
test had a typo (?) (bar != baz) and because util.argparse is not strict by
default, the typo was not caught.
The typo caused the code to take a different path, and bypassed the buggy
handling of --foo=bar options.
I've preserved the existing test (typo and all!) because it's still an
interesting test, and ensures no unintended behaviour changes compared to the
old code.
However I've added a new variant of the test, with strict mode enabled and the
typo fixed. This test failed due to the bug, and this commit introduces a fix.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 11 Mar 2025 18:27:36 +0000 |
| parent | 12777:4d5549de27e6 |
| rev | line source |
|---|---|
| 12495 | 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() | |
|
12777
4d5549de27e6
util.jsonpointer: Improve tests
Kim Alvefur <zash@zash.se>
parents:
12495
diff
changeset
|
24 assert.is_nil(jp.resolve("string", "/string")) |
| 12495 | 25 assert.same(example, jp.resolve(example, "")); |
| 26 assert.same({ "bar", "baz" }, jp.resolve(example, "/foo")); | |
| 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 | 29 assert.same(0, jp.resolve(example, "/")); |
| 30 assert.same(1, jp.resolve(example, "/a~1b")); | |
| 31 assert.same(2, jp.resolve(example, "/c%d")); | |
| 32 assert.same(3, jp.resolve(example, "/e^f")); | |
| 33 assert.same(4, jp.resolve(example, "/g|h")); | |
| 34 assert.same(5, jp.resolve(example, "/i\\j")); | |
| 35 assert.same(6, jp.resolve(example, "/k\"l")); | |
| 36 assert.same(7, jp.resolve(example, "/ ")); | |
| 37 assert.same(8, jp.resolve(example, "/m~0n")); | |
| 38 end) | |
| 39 end) | |
| 40 end) |