Skip to content

Commit e046917

Browse files
committed
emacs: fix comments, add tests
1 parent 8289fd9 commit e046917

File tree

5 files changed

+157
-9
lines changed

5 files changed

+157
-9
lines changed

emacs.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,33 @@ Editing
3939
*/
4040

4141
var emacsKeyBindings = []KeyBind{
42-
// Go to the End of the line
42+
// Go to the End of the command.
4343
{
4444
Key: ControlE,
4545
Fn: GoCmdEnd,
4646
},
47-
// Go to the beginning of the line
47+
// Go to the beginning of the command.
4848
{
4949
Key: ControlA,
5050
Fn: GoCmdBeginning,
5151
},
52-
// Cut the Line after the cursor
52+
// Cut the command after the cursor.
5353
{
5454
Key: ControlK,
5555
Fn: func(buf *Buffer) {
5656
x := []rune(buf.Document().TextAfterCursor())
5757
buf.Delete(len(x))
5858
},
5959
},
60-
// Cut/delete the Line before the cursor
60+
// Cut the command before the cursor.
6161
{
6262
Key: ControlU,
6363
Fn: func(buf *Buffer) {
6464
x := []rune(buf.Document().TextBeforeCursor())
6565
buf.DeleteBeforeCursor(len(x))
6666
},
6767
},
68-
// Delete character under the cursor
68+
// Delete character under the cursor.
6969
{
7070
Key: ControlD,
7171
Fn: func(buf *Buffer) {
@@ -74,19 +74,19 @@ var emacsKeyBindings = []KeyBind{
7474
}
7575
},
7676
},
77-
// Backspace
77+
// Backspace.
7878
{
7979
Key: ControlH,
8080
Fn: func(buf *Buffer) {
8181
buf.DeleteBeforeCursor(1)
8282
},
8383
},
84-
// Right allow: Forward one character
84+
// Right allow: Forward one character.
8585
{
8686
Key: ControlF,
8787
Fn: GoRightChar,
8888
},
89-
// Left allow: Backward one character
89+
// Left allow: Backward one character.
9090
{
9191
Key: ControlB,
9292
Fn: GoLeftChar,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
- cmd: [a]
2+
pane: |
3+
prompt_app> a
4+
abc
5+
aad
6+
aba
7+
aart
8+
apple
9+
- cmd: [b]
10+
pane: |
11+
prompt_app> ab
12+
abc
13+
aba
14+
15+
- cmd: [Tab, Tab]
16+
pane: |
17+
prompt_app> aba
18+
abc
19+
aba
20+
21+
- cmd: [Enter]
22+
pane: |
23+
prompt_app> aba
24+
cmd: aba
25+
prompt_app>
26+
27+
- cmd: [C-r, q]
28+
pane: |
29+
prompt_app> aba
30+
cmd: aba
31+
(failed reverse-i-search)`q':
32+
33+
- cmd: [Left, C-l]
34+
pane: |
35+
prompt_app>
36+
37+
- cmd: [C-r, a]
38+
pane: |
39+
(reverse-i-search)`a':aba
40+
41+
- cmd: [Enter]
42+
pane: |
43+
prompt_app> aba
44+
cmd: aba
45+
prompt_app>
46+
47+
- cmd: ["if some then\nprint(один)", Enter]
48+
49+
- cmd: ["if some then\nprint(три)\nelse\nprint(четыре)", Enter, C-l]
50+
pane: |
51+
prompt_app>
52+
53+
- cmd: [C-r, pri]
54+
pane: |
55+
(reverse-i-search)`pri':if some then
56+
print(три)
57+
else
58+
print(четыре)
59+
60+
- cmd: [C-r]
61+
pane: |
62+
(reverse-i-search)`pri':if some then
63+
print(один)
64+
65+
- cmd: [Enter]
66+
pane: |
67+
prompt_app> if some then
68+
print(один)
69+
cmd: if some then
70+
print(один)
71+
prompt_app>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
- cmd: |
2+
hello
3+
world
4+
а также
5+
мир!
6+
pane: |
7+
prompt_app> hello
8+
world
9+
а также
10+
мир!
11+
12+
- cmd: [C-w]
13+
pane: |
14+
prompt_app> hello
15+
world
16+
а также
17+
cursor: [4, 3]
18+
19+
- cmd: [M-b, M-b, C-k]
20+
pane: |
21+
prompt_app> hello
22+
world
23+
24+
- cmd: |
25+
дополнительные
26+
много
27+
строчек, да!
28+
29+
- cmd: [M-b, C-u]
30+
pane: |
31+
prompt_app> да!
32+
33+
- cmd: [C-d, C-d]
34+
pane: |
35+
prompt_app> !
36+
37+
- cmd: |
38+
снова
39+
много строчек
40+
а б в г д е
41+
42+
- cmd: [C-w, C-w, C-w, C-w, C-w]
43+
pane: |
44+
prompt_app> снова
45+
много строчек
46+
а !
47+
48+
- cmd: [C-k, C-w, C-w, C-w, C-w, C-w, C-w, C-w, C-w] # too many
49+
pane: |
50+
prompt_app>

test/integration/prompt/test_prompt.py

+26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import os
2+
13
import pytest
4+
import yaml
25

36
DEFAULT_KEYS = {
47
"Left": "Left",
@@ -363,3 +366,26 @@ def test_go_left_right_word(prompt, keys):
363366
for cmd, cursor in zip(cmds, cursors):
364367
prompt.send_keys(cmd)
365368
assert prompt.get_cursor() == cursor
369+
370+
371+
@pytest.mark.parametrize("keys", [DEFAULT_KEYS, EMACS_KEYS])
372+
@pytest.mark.parametrize("pipeline_file", [
373+
"completion_revsearch.yml",
374+
"erase_manipulations.yml"
375+
])
376+
def test_pipeline(prompt, pipeline_file, keys):
377+
test_files_path = os.path.relpath(
378+
os.path.join(os.path.dirname(__file__), "pipelines"))
379+
with open(os.path.join(test_files_path, pipeline_file)) as pipeline_data:
380+
pipeline = yaml.safe_load(pipeline_data)
381+
for step in pipeline:
382+
cmd = step["cmd"]
383+
for i in range(len(cmd)):
384+
if cmd[i] in keys:
385+
cmd[i] = keys[cmd[i]]
386+
prompt.send_keys(cmd)
387+
if "cursor" in step:
388+
x, y = step["cursor"]
389+
assert prompt.get_cursor() == (x, y)
390+
if "pane" in step:
391+
assert prompt.dump_workspace() == step["pane"].strip()

test/requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pytest==6.2.5
22
flake8==3.8.1
33
flake8-unused-arguments==0.0.6
4-
flake8-isort==4.0.0
4+
flake8-isort==4.0.0
5+
pyyaml==6.0.1

0 commit comments

Comments
 (0)