Coverage for tests / unit / parsers / base_parser / test_strip_ansi.py: 100%
22 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Tests for strip_ansi_codes function."""
3from __future__ import annotations
5from assertpy import assert_that
7from lintro.parsers.base_parser import strip_ansi_codes
10def test_strip_ansi_codes_with_color() -> None:
11 """Remove ANSI color codes from text."""
12 text = "\x1b[31mError\x1b[0m: message"
13 result = strip_ansi_codes(text)
14 assert_that(result).is_equal_to("Error: message")
17def test_strip_ansi_codes_plain_text() -> None:
18 """Return plain text unchanged."""
19 text = "plain text without codes"
20 result = strip_ansi_codes(text)
21 assert_that(result).is_equal_to(text)
24def test_strip_ansi_codes_multiple_codes() -> None:
25 """Remove multiple ANSI codes from text."""
26 text = "\x1b[1m\x1b[31mBold Red\x1b[0m normal \x1b[32mgreen\x1b[0m"
27 result = strip_ansi_codes(text)
28 assert_that(result).is_equal_to("Bold Red normal green")
31def test_strip_ansi_codes_empty_string() -> None:
32 """Handle empty string input."""
33 result = strip_ansi_codes("")
34 assert_that(result).is_equal_to("")
37def test_strip_ansi_codes_complex_sequences() -> None:
38 """Remove complex ANSI sequences with multiple parameters."""
39 text = "\x1b[38;5;196mComplex color\x1b[0m"
40 result = strip_ansi_codes(text)
41 assert_that(result).is_equal_to("Complex color")