Skip to content

Commit 5a29128

Browse files
committed
Check that Shift+Tab cycles back
1 parent d513d17 commit 5a29128

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/Makefile.venv
22
/.venv
33
*.pyc
4+
/.hypothesis

tests/common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(self, *a,
6868
for command in chain(self.STARTUP, startup or ()):
6969
self.execute(command)
7070

71-
def complete(self, text, tabs=1, drop_colors=True):
71+
def complete(self, text, tabs=1, custom_tabs='', drop_colors=True):
7272
'''
7373
Trigger completion after inputting text into interactive bash session
7474
@@ -77,7 +77,7 @@ def complete(self, text, tabs=1, drop_colors=True):
7777
self._clear_current_line()
7878

7979
proc = self.process
80-
proc.send('{}{}'.format(text, '\t' * tabs))
80+
proc.send('{}{}'.format(text, custom_tabs or '\t' * tabs))
8181
proc.expect_exact(text)
8282
proc.send(self.MARKER)
8383
match = proc.expect(re.escape(self.MARKER))

tests/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pexpect
22
pytest
3+
hypothesis

tests/test_tabkey.py

+31
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
'''
44

55

6+
from hypothesis import (
7+
given,
8+
settings,
9+
strategies as st,
10+
)
11+
612
class TestShortcuts:
713

814
def test_tab_cycles(self, bash):
@@ -15,3 +21,28 @@ def test_tab_cycles(self, bash):
1521
assert completion == next_cycle, 'tabs: {}, old: {}, new: {}'.format(
1622
tabs, completion.selected, next_cycle.selected)
1723

24+
@settings(deadline=1000, max_examples=10)
25+
@given(forward = st.integers(min_value=1, max_value=15),
26+
backward = st.integers(min_value=1, max_value=15))
27+
def test_shift_tab(self, bash, log, forward, backward):
28+
'''Shift-Tab cycles back'''
29+
command = 'ls u/s/a'
30+
cycle_length = len(bash.complete(command)) + 1
31+
32+
TAB = '\t'
33+
SHIFT_TAB = '\x1b\x5b\x5a' # use 'showkey -a' on any Linux machine
34+
# to see ASCII codes corresponding to keypresses
35+
36+
tabs_forward = TAB * ((forward - backward) % cycle_length)
37+
if not tabs_forward: # in case we cycle back to the original command
38+
tabs_forward = TAB + SHIFT_TAB
39+
tabs_forward_and_back = TAB * forward + SHIFT_TAB * backward
40+
log.debug(
41+
'[%s/%s] tab sequences: forward=%r, forward and back=%r',
42+
forward,
43+
backward,
44+
tabs_forward,
45+
tabs_forward_and_back
46+
)
47+
assert bash.complete(command, custom_tabs=tabs_forward) == \
48+
bash.complete(command, custom_tabs=tabs_forward_and_back)

0 commit comments

Comments
 (0)