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