Debian Codegraph @

tests/test_regex.py

raw symbols SCIP
1 import pytermgui as ptg
2 from pytermgui.regex import has_open_sequence, real_length, strip_ansi, strip_markup
3
4
5 def test_strip_ansi():
6 assert strip_ansi(ptg.tim.parse("[141 @61]This is a test")) == "This is a test"
7
8
9 def test_real_length():
10 assert real_length(ptg.tim.parse("[!rainbow]Test string")) == len("Test string")
11
12
13 def test_strip_markup():
14 assert strip_markup("[141 @61 !upper]This is a test") == "This is a test"
15
16
17 def test_has_open_sequence():
18 assert not has_open_sequence(ptg.tim.parse("[141]Hello!"))
19
20 assert has_open_sequence("\x1b[1")
21 assert not has_open_sequence("\x1b[1m")
22 assert not has_open_sequence("\x1b[1mHello")
23
24 assert has_open_sequence("\x1b]")
25 assert not has_open_sequence("\x1b]1\x1b\\")
26 assert not has_open_sequence("\x1b]30;2ST\x1b\\Hello")
27
28 assert has_open_sequence("\x1b_G")
29 assert has_open_sequence("\x1b_GthisstringcanHaveanycharacters")
30 assert not has_open_sequence("\x1b_GthisstringcanHaveanycharacters\x1b\\")
31
32 assert has_open_sequence("\x1b[Something\x1b\\")
33 assert has_open_sequence("\x1b]SomethingmH")
34 assert has_open_sequence("\x1b_GSomethingmH")
35
36 assert not has_open_sequence(
37 ptg.tim.parse("[141]Hello[/fg bold italic]There[@61 inverse]Text")
38 )
39
40 assert has_open_sequence("\x1b[38;5;141hello I aM Missing a lowercase M\x1b[1m")