vimamsa 0.1.26 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/appimage.yml +93 -0
  3. data/.gitignore +4 -1
  4. data/Dockerfile +7 -4
  5. data/README.md +195 -99
  6. data/custom_example.rb +59 -17
  7. data/doc/TODO.md +678 -0
  8. data/doc/action_names_plan.md +442 -0
  9. data/doc/bundling_plan.md +570 -0
  10. data/doc/delta_syntax_plan.md +293 -0
  11. data/doc/demo_recording_plan.md +288 -0
  12. data/doc/design_goals.md +27 -0
  13. data/doc/intro_page_plan.md +266 -0
  14. data/doc/key_bindings_report_plan.md +213 -0
  15. data/doc/line_tree_plan.md +89 -0
  16. data/doc/missing_vim_bindings.md +61 -0
  17. data/doc/modules_settings_plan.md +433 -0
  18. data/doc/refactor_dedup_plan.md +117 -0
  19. data/doc/registries_plan.md +202 -0
  20. data/doc/startup_speed_plan.md +97 -0
  21. data/doc/treap_visualizer.html +585 -0
  22. data/doc/unused_code_plan.md +120 -0
  23. data/doc/vim_compatibility_plan.md +451 -0
  24. data/doc/vimlike_vim_conflicts.md +262 -0
  25. data/doc/vm_snapshots_plan.md +146 -0
  26. data/doc/wysiwyg_plan.md +231 -0
  27. data/exe/run_tests.rb +124 -3
  28. data/exe/vimamsa +68 -5
  29. data/fonts/OFL-Oxanium.txt +93 -0
  30. data/fonts/Oxanium[wght].ttf +0 -0
  31. data/help/intro.txt +30 -0
  32. data/help/vim_intro.txt +31 -0
  33. data/icon.png +0 -0
  34. data/img/demo.gif +0 -0
  35. data/img/demo.mp4 +0 -0
  36. data/lang/hyperplaintext.lang +7 -1
  37. data/lib/vimamsa/ack.rb +13 -1
  38. data/lib/vimamsa/actions.rb +385 -37
  39. data/lib/vimamsa/appimage_env.rb +35 -0
  40. data/lib/vimamsa/audio.rb +2 -5
  41. data/lib/vimamsa/bookmarks.rb +302 -0
  42. data/lib/vimamsa/buffer.rb +675 -118
  43. data/lib/vimamsa/buffer_changetext.rb +150 -68
  44. data/lib/vimamsa/buffer_cursor.rb +7 -0
  45. data/lib/vimamsa/buffer_list.rb +6 -2
  46. data/lib/vimamsa/buffer_manager.rb +10 -7
  47. data/lib/vimamsa/bundled_fonts.rb +32 -0
  48. data/lib/vimamsa/cli_help.rb +75 -0
  49. data/lib/vimamsa/clipboard.rb +9 -3
  50. data/lib/vimamsa/conf.rb +68 -3
  51. data/lib/vimamsa/constants.rb +3 -0
  52. data/lib/vimamsa/crash_handler.rb +149 -0
  53. data/lib/vimamsa/debug.rb +6 -3
  54. data/lib/vimamsa/demo_player.rb +458 -0
  55. data/lib/vimamsa/demo_recorder.rb +277 -0
  56. data/lib/vimamsa/desktop_install.rb +96 -0
  57. data/lib/vimamsa/diff_buffer.rb +40 -11
  58. data/lib/vimamsa/dot_repeat.rb +104 -0
  59. data/lib/vimamsa/easy_jump.rb +57 -3
  60. data/lib/vimamsa/editor.rb +327 -78
  61. data/lib/vimamsa/encrypt.rb +78 -29
  62. data/lib/vimamsa/file_finder.rb +4 -19
  63. data/lib/vimamsa/file_history.rb +4 -1
  64. data/lib/vimamsa/file_manager.rb +46 -31
  65. data/lib/vimamsa/fold.rb +226 -0
  66. data/lib/vimamsa/form_input.rb +388 -0
  67. data/lib/vimamsa/gui.rb +603 -119
  68. data/lib/vimamsa/gui_command_line.rb +247 -0
  69. data/lib/vimamsa/gui_dialog.rb +94 -42
  70. data/lib/vimamsa/gui_file_panel.rb +356 -25
  71. data/lib/vimamsa/gui_form_generator.rb +75 -40
  72. data/lib/vimamsa/gui_func_panel.rb +67 -22
  73. data/lib/vimamsa/gui_image.rb +3 -0
  74. data/lib/vimamsa/gui_key_hint.rb +165 -0
  75. data/lib/vimamsa/gui_keylog_panel.rb +408 -0
  76. data/lib/vimamsa/gui_menu.rb +84 -53
  77. data/lib/vimamsa/gui_select_window.rb +80 -75
  78. data/lib/vimamsa/gui_settings.rb +86 -41
  79. data/lib/vimamsa/gui_sourceview.rb +280 -92
  80. data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
  81. data/lib/vimamsa/gui_text.rb +63 -2
  82. data/lib/vimamsa/gui_theme.rb +615 -0
  83. data/lib/vimamsa/hook.rb +5 -0
  84. data/lib/vimamsa/hyper_plain_text.rb +3 -0
  85. data/lib/vimamsa/intro_page.rb +368 -0
  86. data/lib/vimamsa/key_actions.rb +382 -193
  87. data/lib/vimamsa/key_binding_tree.rb +467 -273
  88. data/lib/vimamsa/key_bindings_notepad.rb +45 -0
  89. data/lib/vimamsa/key_bindings_report.rb +484 -0
  90. data/lib/vimamsa/key_bindings_vim.rb +104 -0
  91. data/lib/vimamsa/key_bindings_vimlike.rb +353 -289
  92. data/lib/vimamsa/key_names.rb +80 -0
  93. data/lib/vimamsa/langservp.rb +271 -54
  94. data/lib/vimamsa/line_tree.rb +367 -0
  95. data/lib/vimamsa/macro.rb +23 -3
  96. data/lib/vimamsa/main.rb +14 -8
  97. data/lib/vimamsa/rbvma.rb +41 -1
  98. data/lib/vimamsa/registers.rb +125 -0
  99. data/lib/vimamsa/run_ruby.rb +64 -0
  100. data/lib/vimamsa/search.rb +3 -0
  101. data/lib/vimamsa/search_replace.rb +15 -14
  102. data/lib/vimamsa/string_util.rb +134 -40
  103. data/lib/vimamsa/terminal.rb +3 -0
  104. data/lib/vimamsa/test_framework.rb +28 -2
  105. data/lib/vimamsa/tests.rb +11 -8
  106. data/lib/vimamsa/text_objects.rb +310 -0
  107. data/lib/vimamsa/text_transforms.rb +18 -0
  108. data/lib/vimamsa/tmp_user_dir.rb +39 -0
  109. data/lib/vimamsa/user_dirs.rb +83 -0
  110. data/lib/vimamsa/util.rb +46 -7
  111. data/lib/vimamsa/version.rb +1 -1
  112. data/lib/vimamsa/vim_core.rb +355 -0
  113. data/lib/vimamsa/vim_operators.rb +365 -0
  114. data/lib/vimamsa.rb +0 -1
  115. data/modules/calculator/calculator.rb +5 -5
  116. data/modules/color_highlight/color_highlight.rb +118 -0
  117. data/modules/color_highlight/color_highlight_info.rb +3 -0
  118. data/modules/dictation/dictation.rb +1054 -0
  119. data/modules/dictation/dictation_info.rb +3 -0
  120. data/modules/dictation/whisper_worker.py +273 -0
  121. data/modules/ollama/ollama.rb +107 -0
  122. data/modules/ollama/ollama_info.rb +3 -0
  123. data/modules/terminal/terminal.rb +5 -5
  124. data/modules/tts/tts.rb +119 -0
  125. data/modules/tts/tts_info.rb +3 -0
  126. data/run_e2e_vm.sh +28 -0
  127. data/run_tests_vm.rb +138 -0
  128. data/scripts/appimage/AppRun +54 -0
  129. data/scripts/appimage/Dockerfile +18 -0
  130. data/scripts/appimage/build.sh +19 -0
  131. data/scripts/appimage/build_in_container.sh +192 -0
  132. data/scripts/appimage/smoke_test.sh +27 -0
  133. data/scripts/demo/demo_easyjump_steps.txt +60 -0
  134. data/scripts/demo/demo_files_steps.txt +52 -0
  135. data/scripts/demo/demo_steps.txt +67 -0
  136. data/scripts/demo/notes.txt +6 -0
  137. data/scripts/demo/record_demo.rb +156 -0
  138. data/scripts/demo/report.rb +7 -0
  139. data/scripts/demo/shapes.rb +29 -0
  140. data/scripts/demo/square/shapes.rb +29 -0
  141. data/scripts/demo/square/steps.txt +185 -0
  142. data/scripts/lib/perf_startup.rb +138 -0
  143. data/scripts/lib/script_helpers.rb +53 -0
  144. data/scripts/perf_compare.rb +34 -0
  145. data/scripts/profile_startup.rb +72 -0
  146. data/styles/134272-molokai.xml +3 -0
  147. data/styles/molokai_cyber.xml +48 -0
  148. data/styles/molokai_edit.xml +1 -0
  149. data/tests/support/virtual_keyboard.rb +254 -0
  150. data/tests/support/virtual_mic.rb +67 -0
  151. data/tests/test_ack.rb +22 -0
  152. data/tests/test_action_ids.rb +232 -0
  153. data/tests/test_auto_format.rb +122 -0
  154. data/tests/test_autocomplete.rb +211 -0
  155. data/tests/test_autosave.rb +145 -0
  156. data/tests/test_basic_editing.rb +46 -16
  157. data/tests/test_bookmarks.rb +206 -0
  158. data/tests/test_bracket_match.rb +88 -0
  159. data/tests/test_bundling.rb +92 -0
  160. data/tests/test_cli_help.rb +64 -0
  161. data/tests/test_color_highlight.rb +92 -0
  162. data/tests/test_command_line.rb +79 -0
  163. data/tests/test_command_line_file.rb +27 -0
  164. data/tests/test_context_menu_file.rb +147 -0
  165. data/tests/test_copy_paste.rb +106 -26
  166. data/tests/test_crash_handler.rb +39 -0
  167. data/tests/test_custom_two_phase.rb +92 -0
  168. data/tests/test_demo_player.rb +301 -0
  169. data/tests/test_demo_recorder.rb +202 -0
  170. data/tests/test_dialog_callback_errors.rb +44 -0
  171. data/tests/test_dictation.rb +294 -0
  172. data/tests/test_diff_buffer_name.rb +51 -0
  173. data/tests/test_dot_repeat.rb +88 -0
  174. data/tests/test_double_click.rb +41 -0
  175. data/tests/test_drag_selection.rb +125 -0
  176. data/tests/test_e2e_cmdline.rb +116 -0
  177. data/tests/test_e2e_dictation.rb +98 -0
  178. data/tests/test_e2e_replace_char.rb +58 -0
  179. data/tests/test_easy_jump.rb +93 -0
  180. data/tests/test_extract_file_links.rb +55 -0
  181. data/tests/test_file_format.rb +217 -0
  182. data/tests/test_file_manager.rb +72 -0
  183. data/tests/test_file_panel.rb +269 -0
  184. data/tests/test_flash.rb +78 -0
  185. data/tests/test_fold.rb +111 -0
  186. data/tests/test_font_refresh.rb +56 -0
  187. data/tests/test_form_input.rb +203 -0
  188. data/tests/test_func_panel.rb +68 -0
  189. data/tests/test_grep_apply.rb +46 -0
  190. data/tests/test_gtk_sync.rb +126 -0
  191. data/tests/test_hpt_highlight_visible.rb +75 -0
  192. data/tests/test_hpt_link_highlight.rb +82 -0
  193. data/tests/test_intro_page.rb +437 -0
  194. data/tests/test_jump_to_file.rb +41 -0
  195. data/tests/test_key_bindings.rb +208 -0
  196. data/tests/test_key_categories.rb +163 -0
  197. data/tests/test_keylog_panel.rb +261 -0
  198. data/tests/test_line_ends.rb +51 -0
  199. data/tests/test_line_tree.rb +86 -0
  200. data/tests/test_lsp_clangd.rb +281 -0
  201. data/tests/test_lsp_jump.rb +87 -0
  202. data/tests/test_lsp_position_encoding.rb +49 -0
  203. data/tests/test_lsp_symbols.rb +68 -0
  204. data/tests/test_macro.rb +137 -0
  205. data/tests/test_markdown_highlight.rb +57 -0
  206. data/tests/test_mode_badge.rb +41 -0
  207. data/tests/test_module_interface.rb +9 -9
  208. data/tests/test_notepad_bindings.rb +67 -0
  209. data/tests/test_perf_startup.rb +28 -0
  210. data/tests/test_popup_queue.rb +51 -0
  211. data/tests/test_random_edit.rb +109 -0
  212. data/tests/test_registers.rb +122 -0
  213. data/tests/test_revert.rb +127 -0
  214. data/tests/test_run_ruby.rb +77 -0
  215. data/tests/test_startup_file.rb +58 -0
  216. data/tests/test_status_area.rb +50 -0
  217. data/tests/test_text_objects.rb +163 -0
  218. data/tests/test_text_transforms.rb +341 -0
  219. data/tests/test_tmp_user_dir.rb +79 -0
  220. data/tests/test_tts.rb +68 -0
  221. data/tests/test_undo.rb +34 -34
  222. data/tests/test_user_dirs.rb +122 -0
  223. data/tests/test_vim_bindings.rb +353 -0
  224. data/tests/test_vim_conflicts.rb +100 -0
  225. data/tests/test_vim_operators.rb +116 -0
  226. data/tests/test_window_layout.rb +302 -0
  227. data/vimamsa.gemspec +3 -1
  228. data/vm_guest_run.sh +129 -0
  229. metadata +167 -10
@@ -0,0 +1,353 @@
1
+ # Tests for the vim keybinding scheme.
2
+ #
3
+ # Run separately: ruby exe/run_tests.rb vim_bindings
4
+ # Excluded from the default suite (see exe/run_tests.rb): loading the vim
5
+ # scheme permanently rebinds keys in the shared test process.
6
+ #
7
+ # Oracle tests replay each key sequence in real vim (nvim --headless -u NONE)
8
+ # on the same initial text and require an identical resulting buffer.
9
+ load "vimamsa/key_bindings_vim.rb" # replaces the vimlike bindings loaded under --test
10
+
11
+ require "tempfile"
12
+
13
+ # Match the oracle's noautoindent: vimamsa auto-indents "\n" inserts otherwise
14
+ cnf.indent_based_on_last_line = false
15
+
16
+ class TestVimBindings < VmaTest
17
+ NVIM = %w[nvim vim].find { |c| system("which #{c} > /dev/null 2>&1") }
18
+
19
+ # ── oracle tests: same keys into vimamsa and real vim, buffers must match ──
20
+
21
+ def test_x_family
22
+ assert_matches_vim("abc\n", "x")
23
+ assert_matches_vim("a\n\nb\n", "jx") # x on empty line: no-op
24
+ assert_matches_vim("abcd\n", "llX")
25
+ assert_matches_vim("ab\ncd\n", "jX") # X at col 0: no-op
26
+ end
27
+
28
+ def test_dd_and_count
29
+ assert_matches_vim("aa\nbb\ncc\n", "dd")
30
+ assert_matches_vim("a\nb\nc\nd\n", "2dd")
31
+ end
32
+
33
+ def test_delete_motions
34
+ assert_matches_vim("foo bar baz\n", "dw")
35
+ assert_matches_vim("foo bar baz\n", "wdw")
36
+ assert_matches_vim("foo bar baz\n", "de")
37
+ assert_matches_vim("abcdef\n", "lld$")
38
+ end
39
+
40
+ def test_delete_find_char
41
+ assert_matches_vim("foo bar baz\n", "dfa")
42
+ assert_matches_vim("foo bar baz\n", "wdf ")
43
+ assert_matches_vim("foo bar baz\n", "dfz") # to end of line
44
+ assert_matches_vim("foo\nbar\n", "dfb") # char only on next line: no-op
45
+ assert_matches_vim("foo bar baz\n", "$dFa")
46
+ assert_matches_vim("foo bar baz\n", "$dF ")
47
+ assert_matches_vim("foo\nbar\n", "j$dFo") # char only on prev line: no-op
48
+ assert_matches_vim("foo bar\n", "dFf") # at col 0: no-op
49
+ end
50
+
51
+ def test_delete_and_change_to_eol
52
+ assert_matches_vim("abcdef\n", "llD")
53
+ assert_matches_vim("abcdef\n", "llCxy\e")
54
+ end
55
+
56
+ def test_change_line
57
+ assert_matches_vim(" old line\nrest\n", "ccnew\e")
58
+ assert_matches_vim("old\nrest\n", "Snew\e")
59
+ assert_matches_vim("a\n\nb\n", "jccx\e") # cc on empty line: guard path
60
+ end
61
+
62
+ def test_change_word_and_substitute
63
+ assert_matches_vim("foo bar\n", "cwnew\e")
64
+ assert_matches_vim("abc\n", "sX\e")
65
+ end
66
+
67
+ def test_replace_and_case
68
+ assert_matches_vim("abc\n", "rZ")
69
+ assert_matches_vim("aBc\n", "~~")
70
+ end
71
+
72
+ def test_case_operators
73
+ assert_matches_vim("foo bar baz\n", "gUw")
74
+ assert_matches_vim("foo bar baz\n", "llgUw") # mid-word: to word end
75
+ assert_matches_vim("foo.bar baz\n", "gUw") # w stops at punctuation
76
+ assert_matches_vim("foo bar baz\n", "wwlgUw") # last word, no next word
77
+ assert_matches_vim("foo\nbar\n", "llgUw") # does not reach next line
78
+ assert_matches_vim("foo\n\nbar\n", "jgUw") # empty line: no-op
79
+ assert_matches_vim("FOO BAR\n", "wguw")
80
+ assert_matches_vim("aB1c\n", "lg~w")
81
+ assert_matches_vim("foo bar\nbaz\n", "wwgUU")
82
+ assert_matches_vim("FOO Bar\nBAZ\n", "jguu")
83
+ assert_matches_vim("a B\n", "g~~")
84
+ assert_matches_vim("foo\n\nbar\n", "jgUU") # empty line: no-op
85
+ assert_matches_vim("foo bar\n", "wgUwx") # cursor stays at word start
86
+ assert_matches_vim("foo bar\n", "wgUUx") # cursor to line start
87
+ end
88
+
89
+ # The operator + motion layer (vim_operators.rb): every operator with
90
+ # every motion, counts in both places
91
+ def test_operator_counts
92
+ assert_matches_vim("a b c d e f g\n", "d2w")
93
+ assert_matches_vim("a b c d e f g\n", "2dw")
94
+ assert_matches_vim("a b c d e f g\n", "2d2w")
95
+ assert_matches_vim("a\nb\nc\nd\ne\n", "d2j")
96
+ assert_matches_vim("a\nb\nc\nd\ne\n", "3dd")
97
+ assert_matches_vim("a\nb\nc\n", "5dd") # more lines than left: no-op
98
+ assert_matches_vim("a\nb\nc\n", "j2dd")
99
+ end
100
+
101
+ def test_operator_word_motions
102
+ assert_matches_vim("foo.bar baz\n", "dW")
103
+ assert_matches_vim("foo.bar baz\n", "dE")
104
+ assert_matches_vim("foo bar.baz\n", "$dB")
105
+ assert_matches_vim("foo bar baz\n", "wwdb")
106
+ assert_matches_vim("foo bar\nbaz\n", "wdw") # last word: not joined
107
+ assert_matches_vim("foo bar\nbaz qux\n", "wd2w")
108
+ assert_matches_vim("foo\n\nbar\n", "dw")
109
+ assert_matches_vim("foo bar\n", "jdb")
110
+ assert_matches_vim("x\n foo\nbar\n", "jjdb")
111
+ assert_matches_vim("foo bar baz\n", "llcwX\e") # cw inside a word
112
+ assert_matches_vim("foo bar baz\n", "lllcwX\e") # cw on a blank
113
+ assert_matches_vim("a bc d\n", "c2wX\e")
114
+ assert_matches_vim("foo bar\n", "yeP")
115
+ end
116
+
117
+ def test_operator_line_motions
118
+ assert_matches_vim("x\n abc def\n", "jwd0")
119
+ assert_matches_vim("x\n abc def\n", "j$d^")
120
+ assert_matches_vim("abc def\n", "wd$")
121
+ assert_matches_vim("abc\ndef\nghi\n", "d2$")
122
+ assert_matches_vim("abcdef\n", "$dh")
123
+ assert_matches_vim("abcdef\n", "$dl")
124
+ assert_matches_vim("abcdef\n", "d3l")
125
+ end
126
+
127
+ def test_operator_find_till
128
+ assert_matches_vim("foo bar baz\n", "dtb")
129
+ assert_matches_vim("foo bar baz\n", "d2fa")
130
+ assert_matches_vim("foo bar baz\n", "$dTo")
131
+ assert_matches_vim("foo bar baz\n", "$dF ")
132
+ assert_matches_vim("foo bar baz\n", "dt ")
133
+ assert_matches_vim("foo bar baz\n", "cfrX\e")
134
+ assert_matches_vim("foo bar baz\n", "gUfr")
135
+ end
136
+
137
+ def test_operator_linewise_motions
138
+ assert_matches_vim("a\nb\nc\nd\n", "jdk")
139
+ assert_matches_vim("a\nb\nc\nd\n", "jdG")
140
+ assert_matches_vim("a\nb\nc\nd\n", "jjdgg")
141
+ assert_matches_vim("a\nb\nc\nd\n", "d3G")
142
+ assert_matches_vim("a\nb\nc\n", "yjGp")
143
+ assert_matches_vim("a\nb\nc\n", "jcjX\e")
144
+ assert_matches_vim("a\nb\nc\n", "Gdj") # can't move: no-op
145
+ end
146
+
147
+ def test_indent_operators
148
+ assert_matches_vim("a\nb\nc\n", ">>")
149
+ assert_matches_vim("a\nb\nc\n", "3>>")
150
+ assert_matches_vim("a\n\nc\n", ">j")
151
+ assert_matches_vim("a\n\nc\n", ">2j") # empty lines stay empty
152
+ assert_matches_vim("\ta\n\tb\n", "<j")
153
+ assert_matches_vim(" a\nb\n", "<<")
154
+ assert_matches_vim("a b\nc\n", ">w") # > always works on lines
155
+ end
156
+
157
+ def test_operator_text_objects_and_case
158
+ assert_matches_vim("foo (bar baz) x\n", "fbd2w")
159
+ assert_matches_vim("foo (bar baz) x\n", "fb>i(")
160
+ assert_matches_vim("foo bar\nbaz\n", "g~j")
161
+ assert_matches_vim("foo bar\n", "gUiw")
162
+ assert_matches_vim("Foo Bar\n", "gu$")
163
+ assert_matches_vim("foo bar\n", "wgUb")
164
+ end
165
+
166
+ def test_plain_motions_from_the_layer
167
+ assert_matches_vim("foo.bar baz\n", "Wix\e")
168
+ assert_matches_vim("foo.bar baz\n", "Eix\e")
169
+ assert_matches_vim("foo bar.baz\n", "$Bix\e")
170
+ assert_matches_vim("foo bar baz\n", "tzix\e")
171
+ assert_matches_vim("foo bar baz\n", "$Tfix\e")
172
+ assert_matches_vim("abc\n", "$ix\e") # $ on the last character
173
+ end
174
+
175
+ # "." repeats the last change (dot_repeat.rb)
176
+ def test_dot_repeat
177
+ assert_matches_vim("a b c d e\n", "dw.")
178
+ assert_matches_vim("a b c d e\n", "dw2.")
179
+ assert_matches_vim("one two three\n", "cwfoo\ew.")
180
+ assert_matches_vim("ab\n", "ixy\e0.") # (vim's esc also moves left; vimamsa's doesn't)
181
+ assert_matches_vim("abcd\n", "x..")
182
+ assert_matches_vim("1\n2\n3\n4\n", "dd.")
183
+ assert_matches_vim("a\nb\n", ">>j.")
184
+ assert_matches_vim("a\nb\n", "A!\ej.")
185
+ assert_matches_vim("a\nb\n", "ox\ej.")
186
+ assert_matches_vim("foo bar\n", "gUiww.")
187
+ assert_matches_vim("a b c\n", "dwlu.") # undo doesn't replace the change
188
+ end
189
+
190
+ def test_join
191
+ assert_matches_vim("aa\nbb\n", "J")
192
+ end
193
+
194
+ def test_yank_paste
195
+ assert_matches_vim("aa\nbb\n", "yyp")
196
+ assert_matches_vim("aa\nbb\n", "Yp")
197
+ end
198
+
199
+ def test_open_lines
200
+ assert_matches_vim("aa\nbb\n", "ofoo\e")
201
+ assert_matches_vim("aa\nbb\n", "Obar\e")
202
+ end
203
+
204
+ def test_insert_variants
205
+ assert_matches_vim("world\n", "ihi \e")
206
+ assert_matches_vim(" hi\n", "A!\e")
207
+ assert_matches_vim(" hi\n", "I>\e")
208
+ end
209
+
210
+ def test_first_non_blank
211
+ assert_matches_vim(" abc\n", "$^ix\e")
212
+ end
213
+
214
+ def test_motions_with_insert_probe
215
+ assert_matches_vim("a\nb\nc\nd\ne\n", "3jix\e")
216
+ assert_matches_vim("abcdef\n", "fdix\e")
217
+ assert_matches_vim("a\nb\nc\n", "Gdd")
218
+ assert_matches_vim("a\nb\nc\n", "Gggdd")
219
+ end
220
+
221
+ def test_undo_after_dd
222
+ assert_matches_vim("aa\nbb\n", "ddu")
223
+ end
224
+
225
+ # ── structural tests (approximations / GUI-dependent; no oracle) ──────────
226
+
227
+ def test_leader_namespace_gone
228
+ before = vma.buf.to_s
229
+ keys ", b" # vimlike: start_buf_manager; must be inert now
230
+ assert_mode :command
231
+ assert_buf before
232
+ end
233
+
234
+ def test_non_vim_chords_gone
235
+ n = bufs.list.size
236
+ keys "ctrl-w" # vimlike: close_current_buffer
237
+ assert_eq n, bufs.list.size
238
+ keys "i ctrl-w" # vimlike: close_current_buffer from insert
239
+ assert_eq n, bufs.list.size
240
+ assert_mode :insert
241
+ keys "esc"
242
+ end
243
+
244
+ def test_insert_ctrl_c_acts_as_esc
245
+ keys "i"
246
+ assert_mode :insert
247
+ keys "ctrl-c"
248
+ assert_mode :command
249
+ end
250
+
251
+ def test_insert_ctrl_h_is_backspace
252
+ keys "i a b ctrl-h"
253
+ assert_buf "a\n"
254
+ keys "esc"
255
+ end
256
+
257
+ def test_zz_dispatch
258
+ keys "z z"
259
+ assert_eq "view.center", vma.kbd.cur_action
260
+ end
261
+
262
+ def test_ctrl_o_binding
263
+ assert_eq "ctrl-o", vma.kbd.act_bindings["C"]["jump.edit.prev"]
264
+ end
265
+
266
+ def test_backtick_jumps_to_mark
267
+ act 'buf.insert_txt("one\ntwo\nthree\n")'
268
+ act "move.buf.start"
269
+ keys "j m a G ` a"
270
+ assert_eq 1, vma.buf.lpos
271
+ end
272
+
273
+ def test_ctrl_a_increments
274
+ act 'buf.insert_txt("a 41 b")'
275
+ act "move.buf.start"
276
+ keys "w ctrl-a"
277
+ assert_buf "a 42 b\n"
278
+ end
279
+
280
+ def test_visual_case_ops
281
+ act 'buf.insert_txt("abc def")'
282
+ act "move.buf.start"
283
+ keys "v e U"
284
+ assert_buf "ABC def\n"
285
+ end
286
+
287
+ private
288
+
289
+ def _setup_test
290
+ create_new_buffer("\n", "test", true)
291
+ vma.kbd.set_mode(:command) rescue nil
292
+ drain_idle
293
+ end
294
+
295
+ # vim-style key string -> vimamsa keys() tokens
296
+ def vim_tokens(s)
297
+ s.chars.map { |ch|
298
+ case ch
299
+ when "\e" then "esc"
300
+ when " " then "space"
301
+ when "\r", "\n" then "enter"
302
+ else ch
303
+ end
304
+ }.join(" ")
305
+ end
306
+
307
+ # Run `normal! nkeys` in real vim on initial; returns resulting text,
308
+ # nil if no vim available. Array-args system(): raw "\e" bytes are fine.
309
+ def vim_oracle(initial, nkeys)
310
+ return nil unless NVIM
311
+ f = Tempfile.new(["vma_vim_oracle", ".txt"])
312
+ begin
313
+ f.write(initial)
314
+ f.flush
315
+ # Plain vim has no --headless: use silent ex mode, which starts on the
316
+ # last line, so jump to line 1 first.
317
+ mode = NVIM == "nvim" ? ["--headless"] : ["-E", "-s", "-c", "1"]
318
+ ok = system(NVIM, *mode, "-u", "NONE", "-i", "NONE", "-n",
319
+ "-c", "set noautoindent nosmartindent sw=4 ts=4",
320
+ "-c", "normal! #{nkeys}",
321
+ "-c", "wq!", f.path,
322
+ out: File::NULL, err: File::NULL)
323
+ raise VmaTestFailure, "oracle #{NVIM} failed for #{nkeys.inspect}" unless ok
324
+ IO.read(f.path)
325
+ ensure
326
+ f.close
327
+ f.unlink
328
+ end
329
+ end
330
+
331
+ def assert_matches_vim(initial, seq)
332
+ raise VmaTestFailure, "initial must end with \\n" unless initial.end_with?("\n")
333
+ create_new_buffer(initial, "vimoracle", true)
334
+ vma.kbd.set_mode(:command) rescue nil
335
+ vma.buf.set_pos(0) # cursor at line 1 col 1, like vim
336
+ drain_idle
337
+ # Force the synchronous internal-clipboard paste path (as in test_copy_paste)
338
+ vma.macro.instance_variable_set(:@running_macro, true)
339
+ begin
340
+ keys vim_tokens(seq)
341
+ ensure
342
+ vma.macro.instance_variable_set(:@running_macro, false)
343
+ end
344
+ expected = vim_oracle(initial, seq)
345
+ if expected.nil?
346
+ puts " SKIP oracle (no nvim/vim in PATH)"
347
+ return
348
+ end
349
+ assert_eq expected, vma.buf.to_s,
350
+ "vim mismatch for #{seq.inspect} on #{initial.inspect}\n" \
351
+ " vim: #{expected.inspect}\n vimamsa: #{vma.buf.to_s.inspect}"
352
+ end
353
+ end
@@ -0,0 +1,100 @@
1
+ # vim_binding_conflicts (key_bindings_report.rb) and the generated
2
+ # doc/vimlike_vim_conflicts.md. Regenerate the doc with:
3
+ # VMA_UPDATE_DOC=1 ruby exe/run_tests.rb --headless vim_conflicts
4
+ class TestVimConflicts < VmaTest
5
+ DOC = File.expand_path("../doc/vimlike_vim_conflicts.md", __dir__)
6
+
7
+ def rows
8
+ @rows ||= vim_binding_conflicts
9
+ end
10
+
11
+ def row(mode, keys)
12
+ rows.find { |r| r[:mode] == mode && r[:keys].join(" ") == keys }
13
+ end
14
+
15
+ def test_doc_is_up_to_date
16
+ report = vim_binding_conflicts_report(rows)
17
+ if ENV["VMA_UPDATE_DOC"] == "1"
18
+ File.write(DOC, report)
19
+ return
20
+ end
21
+ # The report is tracked in git; skip only if it was deleted locally
22
+ skip "#{DOC} missing (run with VMA_UPDATE_DOC=1)" unless File.exist?(DOC)
23
+ assert File.read(DOC) == report,
24
+ "doc/vimlike_vim_conflicts.md is out of date: rerun with VMA_UPDATE_DOC=1 and commit it"
25
+ end
26
+
27
+ def test_classifies_known_cases
28
+ assert_eq :shared, row("C", "u")[:status] # undo in both
29
+ r = row("C", "s") # vim substitute, vimlike easy_jump
30
+ assert_eq [:conflict, :same_keys], [r[:status], r[:why]]
31
+ r = row("C", "c c") # vimlike has no c operator
32
+ assert_eq :added, r[:status] # so it comes from VIM_BINDINGS
33
+ assert_eq :added, row("C", "d i <char>")[:status] # text objects from the shared templates
34
+ end
35
+
36
+ def test_shorter_and_prefix_conflicts
37
+ kbd = KeyBindingTree.new(actions: ActionList.new)
38
+ kbd.add_mode("C", :command)
39
+ kbd.bindkey("C z", "mode.browse")
40
+ kbd.bindkey("C , x", :foo)
41
+ kbd.bindkey("C q <char>", :rec)
42
+ st = ->(keys) { vim_binding_status(kbd, "C", keys.split, :vim_action) }
43
+ assert_eq [:conflict, :shorter], st.("z z").values_at(:status, :why)
44
+ assert_eq [:conflict, :prefix], st.(",").values_at(:status, :why)
45
+ assert_eq [:conflict, :wildcard], st.("q a").values_at(:status, :why)
46
+ assert_eq :missing, st.("t <char>")[:status]
47
+ end
48
+
49
+ # Everything vimlike could take from the shared table, it took
50
+ def test_nothing_left_missing
51
+ missing = rows.select { |r| r[:status] == :missing }
52
+ assert missing.empty?, missing.map { |r| "#{r[:mode]} #{r[:keys].join(" ")}" }.inspect
53
+ end
54
+
55
+ # The live vimlike tree (the one the tests run with) has the added
56
+ # bindings, and they behave as in vim
57
+ def test_added_bindings_work_in_vimlike
58
+ assert vma.kbd.vim_added.include?(["C", ["c", "w"]]), "c w not added"
59
+ buf.set_content("foo bar baz\n")
60
+ buf.set_pos(4)
61
+ keys("D")
62
+ assert_buf "foo \n"
63
+ assert_mode :command
64
+
65
+ buf.set_content("foo bar\n")
66
+ buf.set_pos(0)
67
+ keys("c w x esc")
68
+ assert_buf "x bar\n"
69
+ assert_mode :command
70
+
71
+ buf.set_content(" foo\nbar\n")
72
+ buf.set_pos(3)
73
+ keys("S y esc")
74
+ assert_buf "y\nbar\n"
75
+ end
76
+
77
+ # Conflicting vim bindings are not loaded: vimlike's own action stays
78
+ def test_vimlike_keeps_its_own_bindings
79
+ st = vim_binding_status(vma.kbd, "C", ["s"], "edit.change.char")
80
+ assert_eq [:conflict, :same_keys], st.values_at(:status, :why)
81
+ assert !vma.kbd.vim_added.include?(["C", ["s"]])
82
+ # Adding C ctrl-f ("move.page.next") doesn't change the key the menu shows
83
+ assert_eq "pagedown", vma.kbd.act_bindings["C"]["move.page.next"]
84
+ end
85
+
86
+ def test_loading_schemes_leaves_editor_alone
87
+ kbd, acts = vma.kbd, vma.actions
88
+ color = cnf.mode.command.cursor.background!
89
+ cnf.mode.command.cursor.background = "#123456"
90
+ begin
91
+ load_scheme_kbd("vim")
92
+ assert vma.kbd.equal?(kbd), "vma.kbd replaced"
93
+ assert vma.actions.equal?(acts), "vma.actions replaced"
94
+ assert_eq "#123456", cnf.mode.command.cursor.background!
95
+ assert vma.actions.include?("help.keys")
96
+ ensure
97
+ cnf.mode.command.cursor.background = color
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,116 @@
1
+ # The operator + motion layer in the vimlike keymap (vim_operators.rb,
2
+ # doc/vim_compatibility_plan.md step 1). Vimlike gets every combination of
3
+ # the shared templates whose keys it doesn't use itself.
4
+ #
5
+ # CASES: [text with "|" at the cursor, vim keys, expected text, expected
6
+ # cursor offset]. The expected values come from vim 9.1 (vim -Nu NONE);
7
+ # test_cases_match_real_vim checks them again when vim is installed. The
8
+ # vim keymap has its own oracle tests in test_vim_bindings.rb.
9
+ require "tmpdir"
10
+
11
+ class TestVimOperators < VmaTest
12
+ CASES = [
13
+ ["foo b|ar baz", "cwX\e", "foo bX baz\n", 5],
14
+ ["foo bar| baz", "cwX\e", "foo barXbaz\n", 7],
15
+ ["one two three four", "d3w", "four\n", 0],
16
+ ["one two three four", "2d2w", "\n", 0],
17
+ ["foo bar", "gUtr", "FOO BAr\n", 0],
18
+ ["a.b c", "dW", "c\n", 0],
19
+ ["a\nb|\nc", ">>", "a\n\tb\nc\n", 3],
20
+ ["a\nb|\nc", ">j", "a\n\tb\n\tc\n", 3],
21
+ ["\ta\n\tb", "<j", "a\nb\n", 0],
22
+ ["a\nb|\nc\nd", "c2jX\e", "a\nX\n", 2],
23
+ ["one two", "wcbX\e", "Xtwo\n", 0],
24
+ ["x (a b) y", "fa>i(", "\tx (a b) y\n", 1],
25
+ ["ab cd", "c$X\e", "X\n", 0],
26
+ ["foo bar", "cOX\e", "X\n", 0], # vimlike's O motion (line end) after an operator
27
+ ]
28
+
29
+ def inserts?(keys)
30
+ keys.include?("\e")
31
+ end
32
+
33
+ def vma_keys(keys)
34
+ keys.chars.map { |ch| { "\e" => "esc", " " => "space" }.fetch(ch, ch) }.join(" ")
35
+ end
36
+
37
+ # [text before the cursor, from the cursor]; no "|" = cursor at the start
38
+ def split_case(text)
39
+ text.include?("|") ? text.split("|", 2) : ["", text]
40
+ end
41
+
42
+ def run_case(text, keys)
43
+ pre, rest = split_case(text)
44
+ s = pre + rest
45
+ s += "\n" unless s.end_with?("\n")
46
+ pos = pre.size
47
+ b = vma.buf
48
+ b.set_content(s)
49
+ b.set_pos(pos)
50
+ vma.kbd.set_mode(:command)
51
+ keys(vma_keys(keys))
52
+ [b.to_s, b.pos]
53
+ end
54
+
55
+ def test_cases
56
+ # > and < indent with a tab, as vim -u NONE (other tests change these)
57
+ saved = [cnf.tab.width!, cnf.tab.to_spaces_default?]
58
+ cnf.tab.width = 4
59
+ cnf.tab.to_spaces_default = false
60
+ fails = []
61
+ CASES.each { |text, keys, want, want_pos|
62
+ got, got_pos = run_case(text, keys)
63
+ ok = got == want && (inserts?(keys) || got_pos == want_pos)
64
+ fails << "#{text.inspect} #{keys.inspect}: got #{got.inspect} pos #{got_pos}, vim #{want.inspect} pos #{want_pos}" if !ok
65
+ vma.kbd.set_mode(:command)
66
+ }
67
+ assert fails.empty?, "#{fails.size} of #{CASES.size} cases differ from vim:\n " + fails.join("\n ")
68
+ ensure
69
+ cnf.tab.width, cnf.tab.to_spaces_default = saved if saved
70
+ end
71
+
72
+ # vimlike's own bindings win over the templates
73
+ def test_vimlike_bindings_kept
74
+ assert_eq "edit.delete.word.end", vma.kbd.find_state_by_path("C d e").action
75
+ assert_eq "op.motion", vma.kbd.find_state_by_path("C c w").action
76
+ end
77
+
78
+ # A motion added after the keymap loaded works with every operator
79
+ def test_key_set_add
80
+ vma.kbd.key_set_add(:motion, "Q" => :line_end)
81
+ vma.buf.set_content("abc def\n")
82
+ vma.buf.set_pos(0)
83
+ keys("g U Q")
84
+ assert_buf "ABC DEF\n"
85
+ ensure
86
+ vma.kbd.key_sets[:motion].delete("Q")
87
+ vma.kbd.bindings.select { |b| b[:args] && b[:keys].last == "Q" }.each { |b|
88
+ unbindkey("#{b[:mode]} #{b[:keys].join(" ")}")
89
+ }
90
+ assert vma.kbd.bindings.none? { |b| b[:args] && b[:keys].last == "Q" }, "Q bindings left"
91
+ end
92
+
93
+ def vim_result(text, keys)
94
+ pre, rest = split_case(text)
95
+ Dir.mktmpdir { |d|
96
+ f = "#{d}/f.txt"
97
+ File.write(f, pre + rest + (rest.end_with?("\n") ? "" : "\n"))
98
+ k = keys.gsub("\\", "\\\\\\\\").gsub('"', '\\"').gsub("\e", "\\<Esc>")
99
+ system("vim", "-Nu", "NONE", "-i", "NONE", "-es", "-c", "go #{pre.bytesize + 1}",
100
+ "-c", "exe \"norm! #{k}\"",
101
+ "-c", "call writefile([line2byte(line('.'))+col('.')-2], '#{d}/p')", "-c", "wq", f)
102
+ [File.read(f), File.read("#{d}/p").to_i]
103
+ }
104
+ end
105
+
106
+ def test_cases_match_real_vim
107
+ skip "vim not installed" unless system("command -v vim >/dev/null 2>&1")
108
+ fails = CASES.reject { |text, keys, want, want_pos|
109
+ next true if keys.include?("O") # vimlike-only motion
110
+ got, got_pos = vim_result(text, keys)
111
+ got == want && (inserts?(keys) || got_pos == want_pos)
112
+ }
113
+ assert fails.empty?, "expected values out of date for this vim: " +
114
+ fails.map { |c| [c[0], c[1], vim_result(c[0], c[1])] }.inspect
115
+ end
116
+ end