summaryrefslogtreecommitdiff
path: root/test/test_windows.py
blob: 3be961721a17bbc1157c76e11676895374955aa4 (plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import pytest
from poezio.windows import Input, HistoryInput, MessageInput
from poezio import config


class ConfigShim:
    def get(self, *args, **kwargs):
        return ''

    def getbool(self, *args, **kwargs):
        return True


config.config = ConfigShim()


class SubInput(Input):

    def rewrite_text(self, *args, **kwargs):
        return None


@pytest.fixture
def input():
    from poezio.windows import base_wins
    base_wins.TAB_WIN = True  # The value is not relevant
    return SubInput()


class TestInput(object):

    def test_do_command(self, input):

        input.do_command('a')
        assert input.text == 'a'

        for char in 'coucou':
            input.do_command(char)
        assert input.text == 'acoucou'

    def test_empty(self, input):
        assert input.is_empty()
        input.do_command('a')
        assert not input.is_empty()

    def test_key_left(self, input):
        for char in 'this is a line':
            input.do_command(char)
        for i in range(4):
            input.key_left()
        for char in 'long ':
            input.do_command(char)

        assert input.text == 'this is a long line'

    def test_key_right(self, input):
        for char in 'this is a line':
            input.do_command(char)
        for i in range(4):
            input.key_left()
        input.key_right()

        for char in 'iii':
            input.do_command(char)

        assert input.text == 'this is a liiiine'

    def test_key_home(self, input):
        for char in 'this is a line of text':
            input.do_command(char)
        input.do_command('z')
        input.key_home()
        input.do_command('a')

        assert input.text == 'athis is a line of textz'

    def test_key_end(self, input):
        for char in 'this is a line of text':
            input.do_command(char)
        input.key_home()
        input.key_end()
        input.do_command('z')

        assert input.text == 'this is a line of textz'