diff options
author | mathieui <mathieui@mathieui.net> | 2019-09-29 12:51:05 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2020-05-09 19:46:17 +0200 |
commit | 076314fc21aa6cfb64412cedbcda1ab40c6adaae (patch) | |
tree | 2acda1ed40e0efeb7aa73dad7d43b760ce27f462 | |
parent | 5bc510eafa5d3e9c735687f0b8c9d446159fffca (diff) | |
download | poezio-076314fc21aa6cfb64412cedbcda1ab40c6adaae.tar.gz poezio-076314fc21aa6cfb64412cedbcda1ab40c6adaae.tar.bz2 poezio-076314fc21aa6cfb64412cedbcda1ab40c6adaae.tar.xz poezio-076314fc21aa6cfb64412cedbcda1ab40c6adaae.zip |
Add tests for ui-related funcs
-rw-r--r-- | test/test_ui/test_funcs.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/test_ui/test_funcs.py b/test/test_ui/test_funcs.py new file mode 100644 index 00000000..0e61549c --- /dev/null +++ b/test/test_ui/test_funcs.py @@ -0,0 +1,46 @@ +from poezio.ui.funcs import ( + find_first_format_char, + parse_attrs, + truncate_nick, +) + + +def test_find_char_not_present(): + assert find_first_format_char("toto") == -1 + + +def test_find_char(): + assert find_first_format_char('a \x1A 1') == 2 + + +def test_truncate_nick(): + assert truncate_nick("toto") == "toto" + + +def test_truncate_nick_wrong_size(): + assert truncate_nick("toto", -10) == "t…" + + +def test_truncate_nick_too_long(): + nick = "012345678901234567" + assert truncate_nick(nick) == nick[:10] + "…" + + +def test_truncate_nick_no_nick(): + assert truncate_nick('') == '' + + +def test_parse_attrs(): + text = "\x19o\x19u\x19b\x19i\x191}\x19o\x194}" + assert parse_attrs(text) == ['4}'] + + +def test_parse_attrs_broken_char(): + text = "coucou\x19" + assert parse_attrs(text) == [] + + +def test_parse_attrs_previous(): + text = "coucou" + previous = ['u'] + assert parse_attrs(text, previous=previous) == previous |