26 lines
686 B
Python
26 lines
686 B
Python
"""Tests for the ANSI stripper."""
|
|
from __future__ import annotations
|
|
|
|
from viandante.ansi import strip_ansi, visible_len
|
|
|
|
|
|
def test_strip_sgr() -> None:
|
|
assert strip_ansi("\x1b[31mhello\x1b[0m") == "hello"
|
|
|
|
|
|
def test_strip_cursor_moves() -> None:
|
|
assert strip_ansi("a\x1b[2Jb\x1b[H") == "ab"
|
|
|
|
|
|
def test_strip_osc() -> None:
|
|
assert strip_ansi("\x1b]0;title\x07rest") == "rest"
|
|
|
|
|
|
def test_strip_keep_tilde() -> None:
|
|
# Tilde-style colour codes (CoCo/MUSH) should NOT be stripped by this module.
|
|
assert "~rhello~n" in strip_ansi("~rhello~n") or strip_ansi("~rhello~n") == "~rhello~n"
|
|
|
|
|
|
def test_visible_len() -> None:
|
|
assert visible_len("\x1b[31mfoo\x1b[0m") == 3
|