File: test_expand_tabs.py

package info (click to toggle)
textual 2.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,084 kB
  • sloc: python: 85,423; lisp: 1,669; makefile: 101
file content (32 lines) | stat: -rw-r--r-- 1,046 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pytest

from textual.expand_tabs import expand_tabs_inline, get_tab_widths


@pytest.mark.parametrize(
    "line, expanded_line",
    [
        (" b ar ", " b ar "),
        ("\tbar", "    bar"),
        ("\tbar\t", "    bar "),
        ("\tr\t", "    r   "),
        ("1\tbar", "1   bar"),
        ("12\tbar", "12  bar"),
        ("123\tbar", "123 bar"),
        ("1234\tbar", "1234    bar"),
        ("💩\tbar", "💩  bar"),
        ("💩💩\tbar", "💩💩    bar"),
        ("💩💩💩\tbar", "💩💩💩  bar"),
        ("F💩\tbar", "F💩 bar"),
        ("F💩O\tbar", "F💩O    bar"),
    ],
)
def test_expand_tabs_inline(line, expanded_line):
    assert expand_tabs_inline(line) == expanded_line


def test_get_tab_widths():
    assert get_tab_widths("\tbar") == [("", 4), ("bar", 0)]
    assert get_tab_widths("\tbar\t") == [("", 4), ("bar", 1)]
    assert get_tab_widths("\tfoo\t\t") == [("", 4), ("foo", 1), ("", 4)]
    assert get_tab_widths("\t木foo\t木\t\t") == [("", 4), ("木foo", 3), ("木", 2), ("", 4)]