2014-10-27 19:01:22 +00:00
|
|
|
import pytest
|
2021-03-26 11:42:03 +00:00
|
|
|
from poezio.windows import Input, HistoryInput, MessageInput
|
|
|
|
from poezio import config
|
|
|
|
|
2014-10-27 19:01:22 +00:00
|
|
|
|
2021-03-26 11:42:03 +00:00
|
|
|
class ConfigShim:
|
2014-10-27 19:01:22 +00:00
|
|
|
def get(self, *args, **kwargs):
|
|
|
|
return ''
|
|
|
|
|
2021-03-26 11:42:03 +00:00
|
|
|
def getbool(self, *args, **kwargs):
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2014-10-27 19:01:22 +00:00
|
|
|
config.config = ConfigShim()
|
|
|
|
|
|
|
|
|
2018-12-15 14:19:27 +00:00
|
|
|
class SubInput(Input):
|
2021-03-26 11:42:03 +00:00
|
|
|
|
2018-12-15 14:19:27 +00:00
|
|
|
def rewrite_text(self, *args, **kwargs):
|
|
|
|
return None
|
|
|
|
|
2021-03-26 11:42:03 +00:00
|
|
|
|
2014-10-27 19:01:22 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def input():
|
2021-03-26 11:42:03 +00:00
|
|
|
from poezio.windows import base_wins
|
|
|
|
base_wins.TAB_WIN = True # The value is not relevant
|
2018-12-15 14:19:27 +00:00
|
|
|
return SubInput()
|
2014-10-27 19:01:22 +00:00
|
|
|
|
2021-03-26 11:42:03 +00:00
|
|
|
|
2014-10-27 19:01:22 +00:00
|
|
|
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):
|
2021-03-26 11:42:03 +00:00
|
|
|
assert input.is_empty()
|
2014-10-27 19:01:22 +00:00
|
|
|
input.do_command('a')
|
2021-03-26 11:42:03 +00:00
|
|
|
assert not input.is_empty()
|
2014-10-27 19:01:22 +00:00
|
|
|
|
|
|
|
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'
|
|
|
|
|