mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
common: add tests that json_scan can omit an entire object member.
We can, but I had a typo and thought we couldn't! Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
8738d78c86
commit
7c26f140d8
1 changed files with 25 additions and 0 deletions
|
@ -219,5 +219,30 @@ int main(int argc, char *argv[])
|
|||
JSON_SCAN(json_to_number, &u32val)));
|
||||
assert(u32val == 4);
|
||||
|
||||
/* You can have optional whole objects */
|
||||
u32val = -1U;
|
||||
/* Missing */
|
||||
assert(!json_scan(tmpctx, buf, toks, "{5?:{deeper:%}}",
|
||||
JSON_SCAN(json_to_number, &u32val)));
|
||||
assert(u32val == -1U);
|
||||
/* Missing */
|
||||
assert(!json_scan(tmpctx, buf, toks, "{3?:{not?:%}}",
|
||||
JSON_SCAN(json_to_number, &u32val)));
|
||||
assert(u32val == -1U);
|
||||
/* Present */
|
||||
assert(!json_scan(tmpctx, buf, toks, "{3?:{three:{deeper:%}}}",
|
||||
JSON_SCAN(json_to_number, &u32val)));
|
||||
assert(u32val == 17);
|
||||
/* Missing inside optional */
|
||||
err = json_scan(tmpctx, buf, toks, "{3?:{not:%}",
|
||||
JSON_SCAN(json_to_number, &u32val));
|
||||
assert(streq(err, "Parsing '{3?:{not:': object does not have member not"));
|
||||
|
||||
|
||||
buf = tal_strdup(tmpctx, "{\"1\":\"one\", \"2\":\"two\", \"3\":{\"three\": {\"deeper\": 17}}, \"arr\": [{\"1\": \"arrone\"}, 2, [3, 4]]}");
|
||||
toks = json_parse_simple(tmpctx, buf, strlen(buf));
|
||||
assert(toks);
|
||||
assert(toks->size == 4);
|
||||
|
||||
common_shutdown();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue