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

tired-labs / tiredize / 22530199229

28 Feb 2026 09:42PM UTC coverage: 90.826% (-3.8%) from 94.577%
22530199229

push

github

sludgework
Incorporating peer review feedback

Fix tautological assertion in test_document_load_twice_replaces_state,
strengthen test_line_col_offset_beyond_length to verify exact clamped
values, differentiate test_image_reference_dead_lookbehind input from
test_image_reference_preceded_by_bracket, and correct issue file
description for closing fence with extra backticks.

4 of 4 new or added lines in 2 files covered. (100.0%)

142 existing lines in 7 files now uncovered.

3594 of 3957 relevant lines covered (90.83%)

1.82 hits per line

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

85.71
/tests/markdown/types/test_codeinline.py
1
# Standard library
2
from __future__ import annotations
2✔
3

4
# Third-party
5
import pytest
2✔
6

7
# Local
8
from tiredize.core_types import Position
2✔
9
from tiredize.markdown.types.code import CodeInline
2✔
10

11
md_section = """# Markdown Test Section - Lorem Ipsum
2✔
12

13
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean dapibus auctor
14
mattis. Donec eu posuere ex. Morbi faucibus, diam vitae interdum viverra, diam
15
nulla tempor tellus, non maximus nulla elit eget arcu. Nam quam turpis, finibus
16
non velit vel, pellentesque mattis magna. Nunc tempus ultricies pharetra.
17
Mauris rutrum vel purus eu facilisis. Proin laoreet facilisis libero ac
18
ultricies. Quisque lectus tellus, maximus nec tellus ut, vestibulum faucibus
19
nulla. Pellentesque vel ante egestas, aliquet neque a, egestas mauris. Quisque
20
vulputate metus imperdiet, rhoncus odio eu, dapibus justo. Fusce porta magna in
21
efficitur tincidunt. Vestibulum efficitur ex porttitor neque suscipit pulvinar.
22
Nulla mauris libero, semper in ultricies eu, interdum eget justo.
23

24
Line 15, Offset 00
25
{}
26

27
Donec quis erat non diam sollicitudin faucibus quis quis arcu. In posuere vel
28
dolor vitae aliquet. Maecenas ultrices dignissim orci, id aliquet arcu
29
malesuada eu. Quisque congue ex ac dictum faucibus. Curabitur mollis leo et
30
enim pretium rhoncus. Etiam at lorem vel diam viverra malesuada vel ut erat.
31
Mauris vehicula condimentum consequat. Phasellus fermentum rhoncus enim nec
32
volutpat.
33

34
Line 25, Offset 00
35
{}
36

37
Nulla facilisi. Vestibulum ut turpis ut ipsum euismod varius. Integer et
38
egestas leo. Etiam et porttitor turpis, et dignissim diam. Suspendisse nec
39
maximus ipsum, eget convallis lorem. Donec consequat blandit nisi at porttitor.
40
Vivamus dictum ante a odio varius fringilla. Donec scelerisque nisi dolor, at
41
volutpat nibh aliquam in. Maecenas vestibulum nulla a efficitur vestibulum.
42
Nulla vulputate pulvinar diam, non sollicitudin leo. Suspendisse id porta orci,
43
a fringilla ex. In hac habitasse platea dictumst.
44

45
Line 36, Offset 00
46
{}
47

48
Cras venenatis semper justo, eget feugiat turpis mollis non. Suspendisse risus
49
lacus, pulvinar ut ipsum nec, pharetra blandit leo. Vivamus ullamcorper magna
50
sit amet dolor dapibus porta. Pellentesque habitant morbi tristique senectus et
51
netus et malesuada fames ac turpis egestas. Aenean eget mollis nulla. Donec
52
risus ex, malesuada fermentum sem in, molestie viverra sem. Ut odio massa,
53
luctus egestas maximus non, venenatis id justo. Suspendisse eleifend est id
54
arcu porta tempus.
55

56
Line 47, Offset 00
57
{}
58

59
Curabitur id nulla sit amet felis porta tempus. Morbi placerat malesuada dolor,
60
pulvinar tempor enim laoreet eget. Nullam consequat, magna ac dapibus bibendum,
61
magna enim aliquet turpis, vitae facilisis sapien velit sed odio. Duis eu
62
condimentum lorem. Maecenas quam magna, condimentum ac ultrices sit amet,
63
pellentesque et metus. Donec placerat et sem ut auctor. Suspendisse molestie,
64
quam ac pretium varius, libero enim placerat dolor, eget sagittis urna sapien
65
eu tortor.
66

67
Line 58, Offset 00
68
{}"""
69

70

71
def test_no_codeinline():
2✔
72
    md_test = md_section
2✔
73
    matches = CodeInline.extract(md_test)
2✔
74
    assert len(matches) == 0
2✔
75

76

77
def test_single_codeinline_normal():
2✔
78
    actual_code = 'tiredize --help'
2✔
79
    actual_string = f"`{actual_code}`"
2✔
80
    actual_line = f"You can run {actual_string} to see available options."
2✔
81

82
    exp_code = actual_code
2✔
83
    exp_string = actual_string
2✔
84
    exp_position = Position(offset=1781, length=len(exp_string))
2✔
85

86
    md_text = md_section.format("", "", actual_line, "", "")
2✔
87

88
    matches = CodeInline.extract(md_text)
2✔
89
    assert len(matches) == 1
2✔
90
    assert matches[0] == CodeInline(
2✔
91
        code=exp_code,
92
        position=exp_position,
93
        string=exp_string
94
    )
95

96

97
def test_five_codeinlines_repeated():
2✔
98
    actual_code = 'tiredize --help'
2✔
99
    actual_string = f"`{actual_code}`"
2✔
100
    actual_line = f"You can run {actual_string} to see available options."
2✔
101

102
    exp_code = actual_code
2✔
103
    exp_string = actual_string
2✔
104

105
    md_text = md_section.format(
2✔
106
        actual_line,
107
        actual_line,
108
        actual_line,
109
        actual_line,
110
        actual_line
111
    )
112

113
    positions = [
2✔
114
        Position(offset=837, length=len(exp_string)),
115
        Position(offset=1302, length=len(exp_string)),
116
        Position(offset=1891, length=len(exp_string)),
117
        Position(offset=2451, length=len(exp_string)),
118
        Position(offset=3003, length=len(exp_string))
119
    ]
120

121
    matches = CodeInline.extract(md_text)
2✔
122
    assert len(matches) == 5
2✔
123
    for i, match in enumerate(matches):
2✔
124
        assert match == CodeInline(
2✔
125
            code=exp_code,
126
            position=positions[i],
127
            string=exp_string
128
        )
129

130

131
# ===================================================================
132
#  Sanitize method
133
# ===================================================================
134

135

136
def test_codeinline_sanitize_preserves_length():
2✔
137
    text = "Run `tiredize --help` to see options."
2✔
138
    sanitized = CodeInline.sanitize(text)
2✔
139
    assert len(sanitized) == len(text)
2✔
140
    assert "tiredize" not in sanitized
2✔
141

142

143
def test_codeinline_sanitize_no_inline_code():
2✔
144
    text = "No inline code here."
2✔
145
    sanitized = CodeInline.sanitize(text)
2✔
146
    assert sanitized == text
2✔
147

148

149
def test_codeinline_sanitize_idempotent():
2✔
150
    text = "Use `cmd` and `flag` options."
2✔
151
    first = CodeInline.sanitize(text)
2✔
152
    second = CodeInline.sanitize(first)
2✔
153
    assert first == second
2✔
154
    assert len(second) == len(text)
2✔
155

156

157
# ===================================================================
158
#  Edge cases
159
# ===================================================================
160

161

162
def test_codeinline_multiple_on_same_line():
2✔
163
    text = "Use `foo` or `bar` or `baz` commands."
2✔
164
    matches = CodeInline.extract(text)
2✔
165
    assert len(matches) == 3
2✔
166
    assert matches[0].code == "foo"
2✔
167
    assert matches[1].code == "bar"
2✔
168
    assert matches[2].code == "baz"
2✔
169

170

171
def test_codeinline_base_offset():
2✔
172
    text = "`code`"
2✔
173
    matches = CodeInline.extract(text, base_offset=25)
2✔
174
    assert len(matches) == 1
2✔
175
    assert matches[0].position.offset == 25
2✔
176

177

178
# ===================================================================
179
#  Syntax variant tests (GFM spec compliance)
180
# ===================================================================
181

182

183
@pytest.mark.skip(
2✔
184
    reason="gfm-parity: double-backtick inline code not supported"
185
)
186
def test_codeinline_double_backtick():
2✔
187
    """GFM supports `` code `` for inline code with preserved spaces."""
UNCOV
188
    text = "`` code ``"
×
UNCOV
189
    matches = CodeInline.extract(text)
×
UNCOV
190
    assert len(matches) == 1
×
UNCOV
191
    assert matches[0].code == " code "
×
192

193

194
@pytest.mark.skip(reason="gfm-parity: multiline inline code not supported")
2✔
195
def test_codeinline_multiline():
2✔
196
    """GFM allows inline code to span lines."""
UNCOV
197
    text = "`first line\nsecond line`"
×
UNCOV
198
    matches = CodeInline.extract(text)
×
UNCOV
199
    assert len(matches) == 1
×
UNCOV
200
    assert matches[0].code == "first line\nsecond line"
×
201

202

203
# ===================================================================
204
#  Boundary and degenerate inputs
205
# ===================================================================
206

207

208
def test_codeinline_extract_empty_string():
2✔
209
    assert CodeInline.extract("") == []
2✔
210

211

212
def test_codeinline_extract_single_char():
2✔
213
    assert CodeInline.extract("`") == []
2✔
214

215

216
def test_codeinline_empty_backticks():
2✔
217
    """`` (empty inline code) not matched -- [^\\n`]+ requires content."""
218
    assert CodeInline.extract("``") == []
2✔
219

220

221
# ===================================================================
222
#  State mutation
223
# ===================================================================
224

225

226
def test_codeinline_extract_does_not_mutate_input():
2✔
227
    text = "Use `cmd` here."
2✔
228
    original = text
2✔
229
    CodeInline.extract(text)
2✔
230
    assert text == original
2✔
231

232

233
# ===================================================================
234
#  Unicode
235
# ===================================================================
236

237

238
def test_codeinline_unicode_content():
2✔
239
    text = "`café = True`"
2✔
240
    matches = CodeInline.extract(text)
2✔
241
    assert len(matches) == 1
2✔
242
    assert matches[0].code == "café = True"
2✔
243

244

245
def test_codeinline_sanitize_unicode_preserves_length():
2✔
246
    text = "Use `日本語` in code."
2✔
247
    sanitized = CodeInline.sanitize(text)
2✔
248
    assert len(sanitized) == len(text)
2✔
249

250

251
# ===================================================================
252
#  Additional syntax variant tests
253
# ===================================================================
254

255

256
@pytest.mark.skip(
2✔
257
    reason="gfm-parity: triple-backtick inline code not supported"
258
)
259
def test_codeinline_triple_backtick():
2✔
260
    """GFM supports ``` code ``` for inline code."""
UNCOV
261
    text = "``` code ```"
×
UNCOV
262
    matches = CodeInline.extract(text)
×
UNCOV
263
    assert len(matches) == 1
×
UNCOV
264
    assert matches[0].code == " code "
×
265

266

267
@pytest.mark.skip(
2✔
268
    reason=(
269
        "gfm-parity: inline code containing "
270
        "backtick via multi-backtick wrapper not supported"
271
    )
272
)
273
def test_codeinline_containing_backtick():
2✔
274
    """GFM allows `` foo`bar `` to include a backtick in content."""
UNCOV
275
    text = "`` foo`bar ``"
×
UNCOV
276
    matches = CodeInline.extract(text)
×
UNCOV
277
    assert len(matches) == 1
×
UNCOV
278
    assert matches[0].code == "foo`bar"
×
279

280

281
# ===================================================================
282
#  Cross-cutting: CRLF line endings
283
# ===================================================================
284

285

286
# ===================================================================
287
#  Cross-cutting: escaped characters
288
# ===================================================================
289

290

291
def test_codeinline_escaped_backtick():
2✔
292
    r"""Backslash-escaped backticks are not handled by the regex.
293
    \`text\` is still matched as inline code because [^\n`]+
294
    treats \ as a regular character."""
295
    text = r"Use \`not code\` here."
2✔
296
    matches = CodeInline.extract(text)
2✔
297
    # The regex matches `not code\` (backslash before closing
298
    # backtick is captured as content)
299
    assert len(matches) == 1
2✔
300

301

302
def test_codeinline_crlf_in_content():
2✔
303
    """CodeInline regex excludes \\n but not \\r.
304
    A \\r character would be captured in the code field."""
305
    text = "`code\rmore`"
2✔
306
    matches = CodeInline.extract(text)
2✔
307
    # The regex [^\\n`]+ does not exclude \\r, so it matches
308
    assert len(matches) == 1
2✔
309
    assert "\r" in matches[0].code  # documents actual behavior
2✔
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