| 482 | } |
| 483 | |
| 484 | static void advanced(void) |
| 485 | { |
| 486 | { |
| 487 | struct json *j = json_parse(cmd, "[ 'lightning', 24, 'tok', 543 ]"); |
| 488 | |
| 489 | struct json_escape *label; |
| 490 | u64 *msat; |
| 491 | u64 *msat_opt1, *msat_opt2; |
| 492 | const jsmntok_t *tok; |
| 493 | |
| 494 | assert(param(cmd, j->buffer, j->toks, |
| 495 | p_req("description", param_label, &label), |
| 496 | p_req("msat", param_u64, &msat), |
| 497 | p_req("tok", param_tok, &tok), |
| 498 | p_opt("msat_opt1", param_u64, &msat_opt1), |
| 499 | p_opt("msat_opt2", param_u64, &msat_opt2), |
| 500 | NULL)); |
| 501 | assert(label != NULL); |
| 502 | assert(streq(label->s, "lightning")); |
| 503 | assert(*msat == 24); |
| 504 | assert(tok); |
| 505 | assert(msat_opt1); |
| 506 | assert(*msat_opt1 == 543); |
| 507 | assert(msat_opt2 == NULL); |
| 508 | } |
| 509 | { |
| 510 | struct json *j = json_parse(cmd, "[ 3, 'foo' ]"); |
| 511 | struct json_escape *label, *foo; |
| 512 | assert(param(cmd, j->buffer, j->toks, |
| 513 | p_req("label", param_label, &label), |
| 514 | p_opt("foo", param_label, &foo), |
| 515 | NULL)); |
| 516 | assert(streq(label->s, "3")); |
| 517 | assert(streq(foo->s, "foo")); |
| 518 | } |
| 519 | { |
| 520 | u64 *msat; |
| 521 | u64 *msat2; |
| 522 | struct json *j = json_parse(cmd, "[ 3 ]"); |
| 523 | assert(param(cmd, j->buffer, j->toks, |
| 524 | p_opt_def("msat", param_u64, &msat, 23), |
| 525 | p_opt_def("msat2", param_u64, &msat2, 53), |
| 526 | NULL)); |
| 527 | assert(*msat == 3); |
| 528 | assert(msat2); |
| 529 | assert(*msat2 == 53); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | static void advanced_fail(void) |
| 534 | { |
no test coverage detected