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

tstack / lnav / 17589970077-2502

09 Sep 2025 05:00PM UTC coverage: 65.196% (-5.0%) from 70.225%
17589970077-2502

push

github

tstack
[format] add fields for source file/line

Knowing the source file/line context in a log
message can help find log messages when using
log2src.

56 of 70 new or added lines in 2 files covered. (80.0%)

13954 existing lines in 210 files now uncovered.

45516 of 69814 relevant lines covered (65.2%)

404154.37 hits per line

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

99.02
/src/base/intern_string.tests.cc
1
/**
2
 * Copyright (c) 2021, Timothy Stack
3
 *
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * * Redistributions of source code must retain the above copyright notice, this
10
 * list of conditions and the following disclaimer.
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 * this list of conditions and the following disclaimer in the documentation
13
 * and/or other materials provided with the distribution.
14
 * * Neither the name of Timothy Stack nor the names of its contributors
15
 * may be used to endorse or promote products derived from this software
16
 * without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
29

30
#include <cctype>
31
#include <iostream>
32

33
#include "intern_string.hh"
34

35
#include "config.h"
36
#include "doctest/doctest.h"
37

38
TEST_CASE("string_fragment::startswith")
1✔
39
{
40
    std::string empty;
1✔
41
    auto sf = string_fragment{empty};
1✔
42

43
    CHECK_FALSE(sf.startswith("abc"));
1✔
44
}
1✔
45

46
TEST_CASE("string_fragment::lt")
1✔
47
{
48
    auto sf1 = string_fragment::from_const("abc");
1✔
49
    auto sf2 = string_fragment::from_const("abcdef");
1✔
50

51
    CHECK(sf1 < sf2);
1✔
52
    CHECK_FALSE(sf2 < sf1);
1✔
53
}
1✔
54

55
TEST_CASE("split_lines")
1✔
56
{
57
    std::string in1 = "Hello, World!";
2✔
58
    std::string in2 = "Hello, World!\nGoodbye, World!";
1✔
59

60
    {
61
        auto sf = string_fragment(in1);
1✔
62
        auto split = sf.split_lines();
1✔
63

64
        CHECK(1 == split.size());
1✔
65
        CHECK(in1 == split[0].to_string());
1✔
66
    }
1✔
67

68
    {
69
        auto sf = string_fragment::from_str_range(in1, 7, -1);
1✔
70
        auto split = sf.split_lines();
1✔
71

72
        CHECK(1 == split.size());
1✔
73
        CHECK("World!" == split[0].to_string());
1✔
74
    }
1✔
75

76
    {
77
        auto sf = string_fragment(in2);
1✔
78
        auto split = sf.split_lines();
1✔
79

80
        CHECK(2 == split.size());
1✔
81
        CHECK("Hello, World!\n" == split[0].to_string());
1✔
82
        CHECK("Goodbye, World!" == split[1].to_string());
1✔
83
    }
1✔
84
}
1✔
85

86
TEST_CASE("consume")
1✔
87
{
88
    auto is_eq = string_fragment::tag1{'='};
1✔
89
    auto is_dq = string_fragment::tag1{'"'};
1✔
90
    auto is_colon = string_fragment::tag1{':'};
1✔
91

92
    const char* pair = "foo  =  bar";
1✔
93
    auto sf = string_fragment(pair);
1✔
94

95
    auto split_sf = sf.split_while(isalnum);
1✔
96

97
    CHECK(split_sf.has_value());
1✔
98
    CHECK(split_sf->first.to_string() == "foo");
1✔
99
    CHECK(split_sf->second.to_string() == "  =  bar");
1✔
100

101
    auto value_frag = split_sf->second.skip(isspace).consume(is_eq);
1✔
102

103
    CHECK(value_frag.has_value());
1✔
104
    CHECK(value_frag->to_string() == "  bar");
1✔
105

106
    auto stripped_value_frag = value_frag->consume(isspace);
1✔
107

108
    CHECK(stripped_value_frag.has_value());
1✔
109
    CHECK(stripped_value_frag->to_string() == "bar");
1✔
110

111
    auto no_value = sf.consume(is_colon);
1✔
112
    CHECK(!no_value.has_value());
1✔
113

114
    const char* qs = R"("foo \" bar")";
1✔
115
    auto qs_sf = string_fragment{qs};
1✔
116

117
    auto qs_body = qs_sf.consume(is_dq);
1✔
118
    string_fragment::quoted_string_body qsb;
1✔
119
    auto split_body = qs_body->split_while(qsb);
1✔
120

121
    CHECK(split_body.has_value());
1✔
122
    CHECK(split_body->first.to_string() == "foo \\\" bar");
1✔
123
    CHECK(split_body->second.to_string() == "\"");
1✔
124

125
    auto empty = split_body->second.consume(is_dq);
1✔
126

127
    CHECK(empty.has_value());
1✔
128
    CHECK(empty->empty());
1✔
129
}
1✔
130

131
TEST_CASE("find_left_boundary")
1✔
132
{
133
    std::string in1 = "Hello,\nWorld!\n";
1✔
134

135
    {
136
        auto sf = string_fragment{in1};
1✔
137

138
        auto world_sf = sf.find_left_boundary(
1✔
139
            in1.length() - 3, [](auto ch) { return ch == '\n'; });
7✔
140
        CHECK(world_sf.to_string() == "World!\n");
1✔
141
        auto world_sf2 = sf.find_left_boundary(
1✔
142
            in1.length() - 3, [](auto ch) { return ch == '\n'; }, 2);
13✔
143
        CHECK(world_sf2.to_string() == "Hello,\nWorld!\n");
1✔
144
        auto world_sf3 = sf.find_left_boundary(
1✔
145
            in1.length() - 3, [](auto ch) { return ch == '\n'; }, 3);
13✔
146
        CHECK(world_sf3.to_string() == "Hello,\nWorld!\n");
1✔
147
        auto full_sf
148
            = sf.find_left_boundary(3, [](auto ch) { return ch == '\n'; });
5✔
149
        CHECK(full_sf.to_string() == in1);
1✔
150
    }
151

152
    {
153
        auto sf = string_fragment::from_const("\n    ");
1✔
154
        auto last_line
155
            = sf.find_left_boundary(sf.length(), string_fragment::tag1{'\n'});
1✔
156

157
        CHECK(last_line.to_string() == "    ");
1✔
158
    }
159
}
1✔
160

161
TEST_CASE("find_right_boundary")
1✔
162
{
163
    {
164
        const auto sf = string_fragment::from_const("Hello,\nWorld!\n");
1✔
165

166
        auto world_sf = sf.find_right_boundary(sf.length() - 3,
1✔
UNCOV
167
                                               string_fragment::tag1{'\n'});
×
168
        CHECK(world_sf.to_string() == "Hello,\nWorld!");
1✔
169
        auto hello_sf
170
            = sf.find_right_boundary(3, [](auto ch) { return ch == '\n'; });
5✔
171
        CHECK(hello_sf.to_string() == "Hello,");
1✔
172
        auto hello_sf2
173
            = sf.find_right_boundary(3, string_fragment::tag1{'\n'}, 2);
1✔
174
        CHECK(hello_sf2.to_string() == "Hello,\nWorld!");
1✔
175
    }
176
}
1✔
177

178
TEST_CASE("find_boundaries_around")
1✔
179
{
180
    {
181
        const auto sf = string_fragment::from_const(
1✔
182
            R"(Hello,
183
World!
184
Goodbye,
185
World!)");
186

187
        auto all_sf1
188
            = sf.find_boundaries_around(3, string_fragment::tag1{'\n'});
1✔
189
        CHECK(all_sf1 == "Hello,");
1✔
190
        auto all_sf2
191
            = sf.find_boundaries_around(3, string_fragment::tag1{'\n'}, 2);
1✔
192
        CHECK(all_sf2 == "Hello,\nWorld!");
1✔
193
    }
194
}
1✔
195

196
TEST_CASE("string_fragment::column_width")
1✔
197
{
198
    {
199
        const auto sf = string_fragment::from_const("Key(s)\n");
1✔
200

201
        CHECK(7 == sf.column_width());
1✔
202
    }
203
    {
204
        const auto sf = string_fragment::from_const("\u26a0");
1✔
205

206
        CHECK(1 == sf.column_width());
1✔
207
    }
208
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc