| 324 | } |
| 325 | |
| 326 | int main(int argc, char *argv[]) |
| 327 | { |
| 328 | char **lines, *json = NULL; |
| 329 | int test_count = 0; |
| 330 | |
| 331 | common_setup(argv[0]); |
| 332 | |
| 333 | lines = tal_strsplit(tmpctx, grab_file(tmpctx, tal_fmt(tmpctx, "%s.c", |
| 334 | argv[0])), |
| 335 | "\n", STR_NO_EMPTY); |
| 336 | |
| 337 | for (size_t i = 0; lines[i]; i++) { |
| 338 | const char *l = lines[i]; |
| 339 | if (!strstarts(l, " * ")) |
| 340 | continue; |
| 341 | l += 3; |
| 342 | if (streq(l, "```json")) |
| 343 | json = tal_strdup(tmpctx, ""); |
| 344 | else if (streq(l, "```")) { |
| 345 | jsmn_parser parser; |
| 346 | jsmntok_t toks[500]; |
| 347 | |
| 348 | jsmn_init(&parser); |
| 349 | if (jsmn_parse(&parser, json, strlen(json), |
| 350 | toks, ARRAY_SIZE(toks)) < 0) |
| 351 | abort(); |
| 352 | |
| 353 | switch (test_count) { |
| 354 | case 0: |
| 355 | test_decode(json, toks); |
| 356 | break; |
| 357 | case 1: |
| 358 | test_encode(json, toks); |
| 359 | break; |
| 360 | default: |
| 361 | abort(); |
| 362 | } |
| 363 | test_count++; |
| 364 | json = NULL; |
| 365 | } else if (json) |
| 366 | tal_append_fmt(&json, "%s", l); |
| 367 | } |
| 368 | assert(test_count == 2); |
| 369 | common_shutdown(); |
| 370 | } |
nothing calls this directly
no test coverage detected