Print uncovered gaps in text with adjacent-mention context. Returns True if any uncovered text was found.
(boltpath: str, bolt_num: int, si: int,
text: str, linemap: List[int],
section_records: List[CovRecord])
| 172 | |
| 173 | |
| 174 | def show_gaps(boltpath: str, bolt_num: int, si: int, |
| 175 | text: str, linemap: List[int], |
| 176 | section_records: List[CovRecord]) -> bool: |
| 177 | """Print uncovered gaps in text with adjacent-mention context. |
| 178 | |
| 179 | Returns True if any uncovered text was found. |
| 180 | """ |
| 181 | content_start = section_content_start(text) |
| 182 | |
| 183 | # Build merged intervals to find gaps, but keep raw records for adjacency. |
| 184 | merged = merge_intervals([(r[1], r[2]) for r in section_records]) |
| 185 | |
| 186 | # Walk the merged intervals and find gaps. |
| 187 | any_gap = False |
| 188 | pos = content_start |
| 189 | for m_start, m_end in merged: |
| 190 | if m_start > pos: |
| 191 | gap_text = text[pos:m_start].strip() |
| 192 | if not gap_text: |
| 193 | pos = max(pos, m_end) |
| 194 | continue |
| 195 | |
| 196 | any_gap = True |
| 197 | bolt_lineno = linemap[pos] if pos < len(linemap) else 1 |
| 198 | |
| 199 | before = adjacent_before(section_records, pos) |
| 200 | after = adjacent_after(section_records, m_start) |
| 201 | |
| 202 | for r in before: |
| 203 | print("{}:{}:{}".format(r[3], r[4], snippet(text, r[1], r[2], tail=True))) |
| 204 | print("{}:{}:{}".format(boltpath, bolt_lineno, gap_text[:120])) |
| 205 | for r in after: |
| 206 | print("{}:{}:{}".format(r[3], r[4], snippet(text, r[1], r[2], tail=False))) |
| 207 | |
| 208 | pos = max(pos, m_end) |
| 209 | |
| 210 | # Tail gap after last interval. |
| 211 | if pos < len(text): |
| 212 | gap_text = text[pos:].strip() |
| 213 | if gap_text: |
| 214 | any_gap = True |
| 215 | bolt_lineno = linemap[pos] if pos < len(linemap) else 1 |
| 216 | before = adjacent_before(section_records, pos) |
| 217 | |
| 218 | for r in before: |
| 219 | print("{}:{}:{}".format(r[3], r[4], snippet(text, r[1], r[2], tail=True))) |
| 220 | print("{}:{}:{}".format(boltpath, bolt_lineno, gap_text[:120])) |
| 221 | |
| 222 | return any_gap |
| 223 | |
| 224 | |
| 225 | def main() -> None: |
no test coverage detected