• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

biojppm / rapidyaml / 18058224053

27 Sep 2025 09:47AM UTC coverage: 97.35% (+0.04%) from 97.312%
18058224053

Pull #536

github

web-flow
Merge f0cd8f7b3 into 9a044c88b
Pull Request #536: Int handler

959 of 990 new or added lines in 15 files covered. (96.87%)

7 existing lines in 2 files now uncovered.

13007 of 13361 relevant lines covered (97.35%)

765169.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.47
/src_extra/c4/yml/extra/event_handler_ints_utils.cpp
1
#ifndef _C4_YML_EXTRA_EVENT_HANDLER_INTS_UTILS_HPP_
2
#include "c4/yml/extra/event_handler_ints_utils.hpp"
3
#endif
4

5
#ifndef _C4_YML_EXTRA_SCALAR_HPP_
6
#include "c4/yml/extra/scalar.hpp"
7
#endif
8

9
C4_SUPPRESS_WARNING_GCC_WITH_PUSH("-Wold-style-cast")
10
// NOLINTBEGIN(hicpp-signed-bitwise)
11

12
namespace c4 {
13
namespace yml {
14
namespace extra {
15

16
void print_events_ints(csubstr parsed_yaml, csubstr arena, ievt::DataType const* evts, ievt::DataType evts_sz)
13,880✔
17
{
18
    char buf[200];
19
    for(ievt::DataType evtpos = 0, evtnumber = 0;
13,880✔
20
        evtpos < evts_sz;
214,340✔
21
        ++evtnumber,
200,460✔
22
            evtpos += ((evts[evtpos] & ievt::WSTR) ? 3 : 1))
200,460✔
23
    {
24
        ievt::DataType evt = evts[evtpos];
200,460✔
25
        {
26
            csubstr str = ievt::mkstring(evt, buf);
200,460✔
27
            printf("[%d][%d] %.*s(0x%x)", evtnumber, evtpos, (int)str.len, str.str, evt);
200,460✔
28
        }
29
        if (evt & ievt::WSTR)
200,460✔
30
        {
31
            bool in_arena = evt & ievt::AREN;
84,932✔
32
            csubstr region = !in_arena ? parsed_yaml : arena;
84,932✔
33
            bool safe = (evts[evtpos + 1] >= 0)
169,864✔
34
                && (evts[evtpos + 2] >= 0)
84,932✔
35
                && (evts[evtpos + 1] <= (int)region.len)
84,932✔
36
                && ((evts[evtpos + 1] + evts[evtpos + 2]) <= (int)region.len);
169,864✔
37
            const char *str = safe ? (region.str + evts[evtpos + 1]) : "ERR!!!";
84,932✔
38
            int len = safe ? evts[evtpos + 2] : 6;
84,932✔
39
            printf(": %d [%d]~~~%.*s~~~", evts[evtpos+1], evts[evtpos+2], len, str);
84,932✔
40
            if(in_arena)
84,932✔
41
                printf(" (arenasz=%zu)", arena.len);
512✔
42
            else
43
                printf(" (srcsz=%zu)", parsed_yaml.len);
84,420✔
44
        }
45
        printf("\n");
200,460✔
46
    }
47
}
13,880✔
48

49
size_t emit_events_test_suite_from_ints(csubstr parsed_yaml,
63,664✔
50
                                        csubstr arena,
51
                                        ievt::DataType const* evts_ints,
52
                                        ievt::DataType evts_ints_sz,
53
                                        substr evts_test_suite)
54
{
55
    auto getstr = [&](ievt::DataType i){
411,200✔
56
        bool in_arena = evts_ints[i] & ievt::AREN;
411,200✔
57
        csubstr region = !in_arena ? parsed_yaml : arena;
411,200✔
58
        return region.sub((size_t)evts_ints[i+1], (size_t)evts_ints[i+2]);
822,400✔
59
    };
63,664✔
60
    size_t sz = 0;
63,664✔
61
    auto append = [&](csubstr s){
2,244,000✔
62
        size_t next = sz + s.len;
2,244,000✔
63
        if (s.len && (next <= evts_test_suite.len && evts_test_suite.len))
2,244,000✔
64
            memcpy(evts_test_suite.str + sz, s.str, s.len);
1,121,992✔
65
        sz = next;
2,244,000✔
66
    };
2,307,664✔
67
    bool has_tag = false;
63,664✔
68
    csubstr tag;
63,664✔
69
    auto maybe_append_tag = [&]{
454,112✔
70
        if(has_tag)
454,112✔
71
        {
72
            if(tag.begins_with('<'))
39,632✔
73
            {
NEW
74
                append(" ");
×
NEW
75
                append(tag);
×
76
            }
77
            else if(tag.begins_with("!<"))
39,632✔
78
            {
79
                append(" ");
560✔
80
                append(tag.sub(1));
1,120✔
81
            }
82
            else if(tag.begins_with('!'))
39,072✔
83
            {
84
                append(" <");
37,552✔
85
                append(tag);
37,552✔
86
                append(">");
37,552✔
87
            }
88
            else
89
            {
90
                append(" <!");
1,520✔
91
                append(tag);
1,520✔
92
                append(">");
1,520✔
93
            }
94
        }
95
        has_tag = false;
454,112✔
96
    };
517,776✔
97
    bool has_anchor = false;
63,664✔
98
    csubstr anchor;
63,664✔
99
    auto maybe_append_anchor = [&]{
454,112✔
100
        if(has_anchor)
454,112✔
101
        {
102
            append(" &");
39,408✔
103
            append(anchor);
39,408✔
104
        }
105
        has_anchor = false;
454,112✔
106
    };
517,776✔
107
    auto append_cont = [&](csubstr evt, csubstr style){
128,032✔
108
        append(evt);
128,032✔
109
        if(style.len)
128,032✔
110
        {
111
            append(" ");
34,912✔
112
            append(style);
34,912✔
113
        }
114
        maybe_append_anchor();
128,032✔
115
        maybe_append_tag();
128,032✔
116
        append("\n");
128,032✔
117
    };
191,696✔
118
    auto append_val = [&](csubstr evt, csubstr val){
326,080✔
119
        append("=VAL");
326,080✔
120
        maybe_append_anchor();
326,080✔
121
        maybe_append_tag();
326,080✔
122
        append(" ");
326,080✔
123
        append(evt);
326,080✔
124
        substr buf = sz <= evts_test_suite.len ? evts_test_suite.sub(sz) : evts_test_suite.last(0);
489,120✔
125
        sz += escape_scalar(buf, val);
326,080✔
126
        append("\n");
326,080✔
127
    };
326,080✔
128
    for(ievt::DataType i = 0; i < evts_ints_sz; )
1,001,296✔
129
    {
130
        ievt::DataType evt = evts_ints[i];
937,632✔
131
        if(evt & ievt::SCLR)
937,632✔
132
        {
133
            csubstr s = getstr(i);
326,080✔
134
            if(evt & ievt::SQUO)
326,080✔
135
                append_val("'", s);
6,256✔
136
            else if(evt & ievt::DQUO)
319,824✔
137
                append_val("\"", s);
15,344✔
138
            else if(evt & ievt::LITL)
304,480✔
139
                append_val("|", s);
9,456✔
140
            else if(evt & ievt::FOLD)
295,024✔
141
                append_val(">", s);
5,648✔
142
            else //if(evt & ievt::PLAI)
143
                append_val(":", s);
289,376✔
144
        }
145
        else if(evt & ievt::BSEQ)
611,552✔
146
        {
147
            if(evt & ievt::FLOW)
42,016✔
148
                append_cont("+SEQ", "[]");
15,584✔
149
            else
150
                append_cont("+SEQ", "");
26,432✔
151
        }
152
        else if(evt & ievt::ESEQ)
569,536✔
153
        {
154
            append("-SEQ\n");
42,016✔
155
        }
156
        else if(evt & ievt::BMAP)
527,520✔
157
        {
158
            if(evt & ievt::FLOW)
86,016✔
159
                append_cont("+MAP", "{}");
19,328✔
160
            else
161
                append_cont("+MAP", "");
66,688✔
162
        }
163
        else if(evt & ievt::EMAP)
441,504✔
164
        {
165
            append("-MAP\n");
86,016✔
166
        }
167
        else if(evt & ievt::ALIA)
355,488✔
168
        {
169
            append("=ALI *");
6,080✔
170
            append(getstr(i));
6,080✔
171
            append("\n");
6,080✔
172
        }
173
        else if(evt & ievt::TAG_)
349,408✔
174
        {
175
            has_tag = true;
39,632✔
176
            tag = getstr(i);
39,632✔
177
        }
178
        else if(evt & ievt::ANCH)
309,776✔
179
        {
180
            has_anchor = true;
39,408✔
181
            anchor = getstr(i);
39,408✔
182
        }
183
        else if(evt & ievt::BDOC)
270,368✔
184
        {
185
            if(evt & ievt::EXPL)
71,520✔
186
                append("+DOC ---\n");
22,144✔
187
            else
188
                append("+DOC\n");
49,376✔
189
        }
190
        else if(evt & ievt::EDOC)
198,848✔
191
        {
192
            if(evt & ievt::EXPL)
71,520✔
193
                append("-DOC ...\n");
5,264✔
194
            else
195
                append("-DOC\n");
66,256✔
196
        }
197
        else if(evt & ievt::BSTR)
127,328✔
198
        {
199
             append("+STR\n");
63,664✔
200
        }
201
        else if(evt & ievt::ESTR)
63,664✔
202
        {
203
            append("-STR\n");
63,664✔
204
        }
205

206
        i += (evt & ievt::WSTR) ? 3 : 1;
937,632✔
207
    }
208
    return sz;
63,664✔
209
}
210

211
} // namespace extra
212
} // namespace yml
213
} // namespace c4
214

215
// NOLINTEND(hicpp-signed-bitwise)
216
C4_SUPPRESS_WARNING_GCC_POP
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc