| 546 | } |
| 547 | |
| 548 | static void advanced(void) |
| 549 | { |
| 550 | { |
| 551 | struct json *j = json_parse(cmd, "[ 'lightning', 24, 'tok', 543 ]"); |
| 552 | |
| 553 | struct json_escape *label; |
| 554 | u64 *msat; |
| 555 | u64 *msat_opt1, *msat_opt2; |
| 556 | const jsmntok_t *tok; |
| 557 | |
| 558 | assert(param(cmd, j->buffer, j->toks, |
| 559 | p_req("description", param_label, &label), |
| 560 | p_req("msat", param_u64, &msat), |
| 561 | p_req("tok", param_tok, &tok), |
| 562 | p_opt("msat_opt1", param_u64, &msat_opt1), |
| 563 | p_opt("msat_opt2", param_u64, &msat_opt2), |
| 564 | NULL)); |
| 565 | assert(label != NULL); |
| 566 | assert(streq(label->s, "lightning")); |
| 567 | assert(*msat == 24); |
| 568 | assert(tok); |
| 569 | assert(msat_opt1); |
| 570 | assert(*msat_opt1 == 543); |
| 571 | assert(msat_opt2 == NULL); |
| 572 | } |
| 573 | { |
| 574 | struct json *j = json_parse(cmd, "[ 3, 'foo' ]"); |
| 575 | struct json_escape *label, *foo; |
| 576 | assert(param(cmd, j->buffer, j->toks, |
| 577 | p_req("label", param_label, &label), |
| 578 | p_opt("foo", param_label, &foo), |
| 579 | NULL)); |
| 580 | assert(streq(label->s, "3")); |
| 581 | assert(streq(foo->s, "foo")); |
| 582 | } |
| 583 | { |
| 584 | u64 *msat; |
| 585 | u64 *msat2; |
| 586 | struct json *j = json_parse(cmd, "[ 3 ]"); |
| 587 | assert(param(cmd, j->buffer, j->toks, |
| 588 | p_opt_def("msat", param_u64, &msat, 23), |
| 589 | p_opt_def("msat2", param_u64, &msat2, 53), |
| 590 | NULL)); |
| 591 | assert(*msat == 3); |
| 592 | assert(msat2); |
| 593 | assert(*msat2 == 53); |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | static void advanced_fail(void) |
| 598 | { |
no test coverage detected