Skip to content

Commit

Permalink
emacs: fix comments, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
askalt committed Jul 18, 2023
1 parent 07f7b1e commit 71d32d2
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 8 deletions.
16 changes: 8 additions & 8 deletions emacs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,33 @@ Editing
*/

var emacsKeyBindings = []KeyBind{
// Go to the End of the line
// Go to the End of the command.
{
Key: ControlE,
Fn: GoCmdEnd,
},
// Go to the beginning of the line
// Go to the beginning of the command.
{
Key: ControlA,
Fn: GoCmdBeginning,
},
// Cut the Line after the cursor
// Cut the command after the cursor.
{
Key: ControlK,
Fn: func(buf *Buffer) {
x := []rune(buf.Document().TextAfterCursor())
buf.Delete(len(x))
},
},
// Cut/delete the Line before the cursor
// Cut the command before the cursor.
{
Key: ControlU,
Fn: func(buf *Buffer) {
x := []rune(buf.Document().TextBeforeCursor())
buf.DeleteBeforeCursor(len(x))
},
},
// Delete character under the cursor
// Delete character under the cursor.
{
Key: ControlD,
Fn: func(buf *Buffer) {
Expand All @@ -74,19 +74,19 @@ var emacsKeyBindings = []KeyBind{
}
},
},
// Backspace
// Backspace.
{
Key: ControlH,
Fn: func(buf *Buffer) {
buf.DeleteBeforeCursor(1)
},
},
// Right allow: Forward one character
// Right allow: Forward one character.
{
Key: ControlF,
Fn: GoRightChar,
},
// Left allow: Backward one character
// Left allow: Backward one character.
{
Key: ControlB,
Fn: GoLeftChar,
Expand Down
71 changes: 71 additions & 0 deletions test/integration/prompt/pipelines/completion_revsearch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
- cmd: [a]
pane: |
prompt_app> a
abc
aad
aba
aart
apple
- cmd: [b]
pane: |
prompt_app> ab
abc
aba
- cmd: [Tab, Tab]
pane: |
prompt_app> aba
abc
aba
- cmd: [Enter]
pane: |
prompt_app> aba
cmd: aba
prompt_app>
- cmd: [C-r, q]
pane: |
prompt_app> aba
cmd: aba
(failed reverse-i-search)`q':
- cmd: [Left, C-l]
pane: |
prompt_app>
- cmd: [C-r, a]
pane: |
(reverse-i-search)`a':aba
- cmd: [Enter]
pane: |
prompt_app> aba
cmd: aba
prompt_app>
- cmd: ["if some then\nprint(один)", Enter]

- cmd: ["if some then\nprint(три)\nelse\nprint(четыре)", Enter, C-l]
pane: |
prompt_app>
- cmd: [C-r, pri]
pane: |
(reverse-i-search)`pri':if some then
print(три)
else
print(четыре)
- cmd: [C-r]
pane: |
(reverse-i-search)`pri':if some then
print(один)
- cmd: [Enter]
pane: |
prompt_app> if some then
print(один)
cmd: if some then
print(один)
prompt_app>
50 changes: 50 additions & 0 deletions test/integration/prompt/pipelines/erase_manipulations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
- cmd: |
hello
world
а также
мир!
pane: |
prompt_app> hello
world
а также
мир!
- cmd: [C-w]
pane: |
prompt_app> hello
world
а также
cursor: [4, 3]

- cmd: [M-b, M-b, C-k]
pane: |
prompt_app> hello
world
- cmd: |
дополнительные
много
строчек, да!
- cmd: [M-b, C-u]
pane: |
prompt_app> да!
- cmd: [C-d, C-d]
pane: |
prompt_app> !
- cmd: |
снова
много строчек
а б в г д е
- cmd: [C-w, C-w, C-w, C-w, C-w]
pane: |
prompt_app> снова
много строчек
а !
- cmd: [C-k, C-w, C-w, C-w, C-w, C-w, C-w, C-w, C-w] # too many
pane: |
prompt_app>
27 changes: 27 additions & 0 deletions test/integration/prompt/test_prompt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import os

import pytest
import yaml

DEFAULT_KEYS = {
"Left": "Left",
Expand Down Expand Up @@ -363,3 +366,27 @@ def test_go_left_right_word(prompt, keys):
for cmd, cursor in zip(cmds, cursors):
prompt.send_keys(cmd)
assert prompt.get_cursor() == cursor


@pytest.mark.parametrize("keys", [DEFAULT_KEYS, EMACS_KEYS])
@pytest.mark.parametrize("pipeline_file", [
"completion_revsearch.yml",
"erase_manipulations.yml"
])
def test_pipeline(prompt, pipeline_file, keys):
test_files_path = os.path.relpath(
os.path.join(os.path.dirname(__file__), "pipelines"))
with open(os.path.join(test_files_path, pipeline_file)) as pipeline_data:
pipeline = yaml.safe_load(pipeline_data)
for step in pipeline:
cmd = step["cmd"]
for i in range(len(cmd)):
if cmd[i] in keys:
cmd[i] = keys[cmd[i]]
prompt.send_keys(cmd)
if "cursor" in step:
x, y = step["cursor"]
assert prompt.get_cursor() == (x, y)
if "pane" in step:
assert prompt.dump_workspace() == step["pane"].strip()

0 comments on commit 71d32d2

Please sign in to comment.