{credit?+{credit}:0} - ifset wraps value, ifnotset is "0" */
| 257 | |
| 258 | /* {credit?+{credit}:0} - ifset wraps value, ifnotset is "0" */ |
| 259 | static void test_format_event_ifset(void) |
| 260 | { |
| 261 | struct report_format *f = tal(tmpctx, struct report_format); |
| 262 | struct report_format *ifset = tal(f, struct report_format); |
| 263 | struct income_event *e = tal(tmpctx, struct income_event); |
| 264 | struct bkpr *bkpr = tal(tmpctx, struct bkpr); |
| 265 | char *s; |
| 266 | |
| 267 | /* ifset format: "+{credit}" */ |
| 268 | ifset->fmt = tal_arr(ifset, typeof(*ifset->fmt), 2); |
| 269 | ifset->str = tal_arr(ifset, const char *, 2); |
| 270 | ifset->ifset = tal_arr(ifset, struct report_format *, 2); |
| 271 | ifset->ifnotset = tal_arr(ifset, struct report_format *, 2); |
| 272 | ifset->fmt[0] = NULL; |
| 273 | ifset->str[0] = tal_strdup(ifset, "+"); |
| 274 | ifset->ifset[0] = NULL; |
| 275 | ifset->ifnotset[0] = NULL; |
| 276 | ifset->fmt[1] = report_fmt_credit; |
| 277 | ifset->str[1] = NULL; |
| 278 | ifset->ifset[1] = NULL; |
| 279 | ifset->ifnotset[1] = NULL; |
| 280 | |
| 281 | f->fmt = tal_arr(f, typeof(*f->fmt), 1); |
| 282 | f->str = tal_arr(f, const char *, 1); |
| 283 | f->ifset = tal_arr(f, struct report_format *, 1); |
| 284 | f->ifnotset = tal_arr(f, struct report_format *, 1); |
| 285 | f->fmt[0] = report_fmt_credit; |
| 286 | f->str[0] = NULL; |
| 287 | f->ifset[0] = ifset; |
| 288 | f->ifnotset[0] = make_literal(f, "0"); |
| 289 | |
| 290 | /* Non-zero credit: ifset fires, output "+<amount>" */ |
| 291 | e->credit = AMOUNT_MSAT(100000000); |
| 292 | s = format_event(tmpctx, f, REPORT_FMT_NONE, bkpr, e); |
| 293 | assert(strstr(s, "+")); |
| 294 | |
| 295 | /* Zero credit: ifnotset fires, output "0" */ |
| 296 | e->credit = AMOUNT_MSAT(0); |
| 297 | s = format_event(tmpctx, f, REPORT_FMT_NONE, bkpr, e); |
| 298 | assert(streq(s, "0")); |
| 299 | } |
| 300 | |
| 301 | /* {credit} with no conditionals: zero outputs "0" (ZERO_AMOUNT passthrough) */ |
| 302 | static void test_format_event_zero_amount_no_conditionals(void) |
no test coverage detected