Branch Coverage

c/jsonfmt.c
Criterion Covered Total %
branch 162 226 71.6


line true false branch
12 15 2120 if (ctx->pretty >= 0) {
28 727 1210 while (off < len) {
38 17 710 if (utf8) {
39 17 0 if (!ctx->htmlsafe) { SKIPUNTIL(x == 0x7f) }
30 8 if (!ctx->htmlsafe) { SKIPUNTIL(x == 0x7f) }
30 0 if (!ctx->htmlsafe) { SKIPUNTIL(x == 0x7f) }
30 0 if (!ctx->htmlsafe) { SKIPUNTIL(x == 0x7f) }
30 0 if (!ctx->htmlsafe) { SKIPUNTIL(x == 0x7f) }
38 9 if (!ctx->htmlsafe) { SKIPUNTIL(x == 0x7f) }
40 0 0 else { SKIPUNTIL(x == 0x7f || x == '<' || x == '>' || x == '&') }
0 0 else { SKIPUNTIL(x == 0x7f || x == '<' || x == '>' || x == '&') }
0 0 else { SKIPUNTIL(x == 0x7f || x == '<' || x == '>' || x == '&') }
0 0 else { SKIPUNTIL(x == 0x7f || x == '<' || x == '>' || x == '&') }
0 0 else { SKIPUNTIL(x == 0x7f || x == '<' || x == '>' || x == '&') }
0 0 else { SKIPUNTIL(x == 0x7f || x == '<' || x == '>' || x == '&') }
0 0 else { SKIPUNTIL(x == 0x7f || x == '<' || x == '>' || x == '&') }
0 0 else { SKIPUNTIL(x == 0x7f || x == '<' || x == '>' || x == '&') }
42 707 3 if (!ctx->htmlsafe) { SKIPUNTIL(x >= 0x7f) }
4743156 6 if (!ctx->htmlsafe) { SKIPUNTIL(x >= 0x7f) }
4743156 0 if (!ctx->htmlsafe) { SKIPUNTIL(x >= 0x7f) }
4743156 0 if (!ctx->htmlsafe) { SKIPUNTIL(x >= 0x7f) }
4743149 7 if (!ctx->htmlsafe) { SKIPUNTIL(x >= 0x7f) }
4743162 694 if (!ctx->htmlsafe) { SKIPUNTIL(x >= 0x7f) }
43 15 0 else { SKIPUNTIL(x >= 0x7f || x == '<' || x == '>' || x == '&') }
15 0 else { SKIPUNTIL(x >= 0x7f || x == '<' || x == '>' || x == '&') }
15 0 else { SKIPUNTIL(x >= 0x7f || x == '<' || x == '>' || x == '&') }
15 0 else { SKIPUNTIL(x >= 0x7f || x == '<' || x == '>' || x == '&') }
14 1 else { SKIPUNTIL(x >= 0x7f || x == '<' || x == '>' || x == '&') }
13 1 else { SKIPUNTIL(x >= 0x7f || x == '<' || x == '>' || x == '&') }
12 1 else { SKIPUNTIL(x >= 0x7f || x == '<' || x == '>' || x == '&') }
15 0 else { SKIPUNTIL(x >= 0x7f || x == '<' || x == '>' || x == '&') }
49 24 703 if (off < len) { /* early break, which means current byte needs special processing */
59 9 7 if (x < 0x80) {
96 2 4072 if (SvIsUV(val)) { /* Why is this macro not documented? */
101 2015 2057 uv = neg ? -iv : iv;
104 9 4065 if (uv == 0) {
109 4091 4065 while (uv >= 10) {
114 3690 375 if (uv > 0) *(--r) = '0' + (uv % 10);
115 2015 2050 if (neg) *(--r) = '-';
123 552 531 for (i=0; i
124 27 525 if (i) fustr_write_ch(ctx->out, ',');
127 552 0 if (sv) fujson_fmt(aTHX_ ctx, *sv); /* sv will have magic if av is tied, but fujson_fmt() handles that. */
131 524 7 if (i) fujson_fmt_indent(aTHX_ ctx);
140 0 63 char *astr = HePV(a, alen);
141 0 63 char *bstr = HePV(b, blen);
142 0 63 int autf = HeUTF8(a);
143 0 63 int butf = HeUTF8(b);
145 58 5 if (autf == butf) {
147 6 52 return cmp != 0 ? cmp : blen < alen ? -1 : blen == alen ? 0 : 1;
3 3 return cmp != 0 ? cmp : blen < alen ? -1 : blen == alen ? 0 : 1;
150 2 3 : -bytes_cmp_utf8((const U8*)astr, alen, (const U8*)bstr, blen);
155 33 513 if (*hestr) fustr_write_ch(ctx->out, ',');
157 8 538 *hestr = HePV(he, helen);
158 8 538 fujson_fmt_str(aTHX_ ctx, *hestr, helen, HeUTF8(he));
159 8 538 if (ctx->pretty > 0) fustr_write(ctx->out, " : ", 3);
161 8 538 fujson_fmt(aTHX_ ctx, UNLIKELY(SvMAGICAL(hv)) ? hv_iterval(hv, he) : HeVAL(he));
174 9 508 if (ctx->canon && !(SvMAGICAL(hv) && SvTIED_mg((SV*)hv, PERL_MAGIC_tied))) {
0 9 if (ctx->canon && !(SvMAGICAL(hv) && SvTIED_mg((SV*)hv, PERL_MAGIC_tied))) {
0 0 if (ctx->canon && !(SvMAGICAL(hv) && SvTIED_mg((SV*)hv, PERL_MAGIC_tied))) {
0 0 if (ctx->canon && !(SvMAGICAL(hv) && SvTIED_mg((SV*)hv, PERL_MAGIC_tied))) {
176 4 5 if (numkeys < 4) numkeys = 4;
177 0 9 if (SvMAGICAL(hv)) numkeys = 32;
183 36 9 while ((he = hv_iternext(hv))) {
184 0 36 if (i >= numkeys) {
186 0 0 keys = (HE **)SvGROW(keys_sv, numkeys * sizeof(HE*));
0 0 keys = (HE **)SvGROW(keys_sv, numkeys * sizeof(HE*));
192 36 9 while (i--) fujson_fmt_hvkv(aTHX_ ctx, hv, keys[i], &hestr);
193 7 2 FREETMPS;
196 510 508 while ((he = hv_iternext(hv))) fujson_fmt_hvkv(aTHX_ ctx, hv, he, &hestr);
199 513 4 if (hestr) fujson_fmt_indent(aTHX_ ctx);
207 1 7 if (!method) croak("unable to format '%s' object as JSON", HvNAME(SvSTASH(obj)));
1 0 if (!method) croak("unable to format '%s' object as JSON", HvNAME(SvSTASH(obj)));
1 0 if (!method) croak("unable to format '%s' object as JSON", HvNAME(SvSTASH(obj)));
0 1 if (!method) croak("unable to format '%s' object as JSON", HvNAME(SvSTASH(obj)));
0 0 if (!method) croak("unable to format '%s' object as JSON", HvNAME(SvSTASH(obj)));
1 0 if (!method) croak("unable to format '%s' object as JSON", HvNAME(SvSTASH(obj)));
0 1 if (!method) croak("unable to format '%s' object as JSON", HvNAME(SvSTASH(obj)));
212 0 7 PUSHMARK(SP);
213 0 7 XPUSHs(rv);
222 7 0 if (SvROK(TOPs) && SvRV(TOPs) == obj)
1 6 if (SvROK(TOPs) && SvRV(TOPs) == obj)
223 1 0 croak("%s::TO_JSON method returned same object as was passed instead of a new one", HvNAME(SvSTASH(obj)));
1 0 croak("%s::TO_JSON method returned same object as was passed instead of a new one", HvNAME(SvSTASH(obj)));
0 1 croak("%s::TO_JSON method returned same object as was passed instead of a new one", HvNAME(SvSTASH(obj)));
0 0 croak("%s::TO_JSON method returned same object as was passed instead of a new one", HvNAME(SvSTASH(obj)));
1 0 croak("%s::TO_JSON method returned same object as was passed instead of a new one", HvNAME(SvSTASH(obj)));
0 1 croak("%s::TO_JSON method returned same object as was passed instead of a new one", HvNAME(SvSTASH(obj)));
229 6 0 FREETMPS;
237 15 5824 if (r != -1) { /* Must check SvISBOOL() before IOKp & POKp, because it implies both flags */
238 10 5 if (r) fustr_write(ctx->out, "true", 4);
240 665 5159 } else if (SvPOKp(val)) {
242 15 5144 } else if (SvNOKp(val)) { /* Must check before IOKp, because integer conversion might have been lossy */
244 2 13 if (isinfnan(nv)) croak("unable to format floating point NaN or Inf as JSON");
250 4074 1070 } else if (SvIOKp(val)) {
252 1059 11 } else if (SvROK(val)) {
256 1 1058 if (--ctx->depth == 0) croak("max_depth exceeded while formatting JSON");
259 8 1050 if (UNLIKELY(SvOBJECT(rv))) fujson_fmt_obj(aTHX_ ctx, val, rv);
260 517 533 else if (SvTYPE(rv) == SVt_PVHV) fujson_fmt_hv(aTHX_ ctx, (HV *)rv);
261 532 1 else if (SvTYPE(rv) == SVt_PVAV) fujson_fmt_av(aTHX_ ctx, (AV *)rv);
264 10 1 } else if (!SvOK(val)) {
285 2050 4735 while (i < argc) {
288 0 2050 if (i == argc) croak("Odd name/value argument for json_format()");
292 5 2045 if (strcmp(arg, "canonical") == 0) ctx.canon = SvTRUEx(r);
293 1 2044 else if (strcmp(arg, "pretty") == 0) ctx.pretty = SvTRUEx(r) ? 0 : INT_MIN;
1 0 else if (strcmp(arg, "pretty") == 0) ctx.pretty = SvTRUEx(r) ? 0 : INT_MIN;
294 1 2043 else if (strcmp(arg, "html_safe") == 0) ctx.htmlsafe = !!SvTRUEx(r);
295 2041 2 else if (strcmp(arg, "utf8") == 0) encutf8 = SvTRUEx(r);
296 1 1 else if (strcmp(arg, "max_size") == 0) out.maxlen = SvUV(r);
297 1 0 else if (strcmp(arg, "max_depth") == 0) ctx.depth = SvUV(r);
300 4734 1 if (out.maxlen == 0) out.maxlen = 1<<30;
301 4734 1 if (ctx.depth == 0) ctx.depth = 512;
305 1 4726 if (ctx.pretty >= 0) fustr_write_ch(&out, '\n');
307 2686 2041 if (!encutf8) SvUTF8_on(r);