vimamsa 0.1.26 → 0.1.27

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 (170) 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 +62 -16
  6. data/custom_example.rb +43 -13
  7. data/doc/TODO.md +461 -0
  8. data/doc/bundling_plan.md +569 -0
  9. data/doc/key_bindings_report_plan.md +168 -0
  10. data/doc/missing_vim_bindings.md +71 -0
  11. data/doc/modules_settings_plan.md +433 -0
  12. data/doc/refactor_dedup_plan.md +117 -0
  13. data/doc/unused_code_plan.md +120 -0
  14. data/doc/vim_compatibility_plan.md +296 -0
  15. data/doc/vimlike_vim_conflicts.md +254 -0
  16. data/doc/vm_snapshots_plan.md +146 -0
  17. data/exe/run_tests.rb +117 -3
  18. data/exe/vimamsa +24 -4
  19. data/fonts/OFL-Oxanium.txt +93 -0
  20. data/fonts/Oxanium[wght].ttf +0 -0
  21. data/icon.png +0 -0
  22. data/img/demo.gif +0 -0
  23. data/lang/hyperplaintext.lang +6 -0
  24. data/lib/vimamsa/ack.rb +11 -1
  25. data/lib/vimamsa/actions.rb +4 -1
  26. data/lib/vimamsa/appimage_env.rb +35 -0
  27. data/lib/vimamsa/audio.rb +2 -5
  28. data/lib/vimamsa/bookmarks.rb +302 -0
  29. data/lib/vimamsa/buffer.rb +593 -82
  30. data/lib/vimamsa/buffer_changetext.rb +102 -42
  31. data/lib/vimamsa/buffer_cursor.rb +7 -0
  32. data/lib/vimamsa/buffer_list.rb +4 -0
  33. data/lib/vimamsa/buffer_manager.rb +4 -1
  34. data/lib/vimamsa/bundled_fonts.rb +32 -0
  35. data/lib/vimamsa/clipboard.rb +3 -0
  36. data/lib/vimamsa/conf.rb +59 -3
  37. data/lib/vimamsa/constants.rb +3 -0
  38. data/lib/vimamsa/crash_handler.rb +149 -0
  39. data/lib/vimamsa/debug.rb +4 -1
  40. data/lib/vimamsa/desktop_install.rb +96 -0
  41. data/lib/vimamsa/diff_buffer.rb +39 -10
  42. data/lib/vimamsa/easy_jump.rb +3 -0
  43. data/lib/vimamsa/editor.rb +263 -57
  44. data/lib/vimamsa/encrypt.rb +78 -29
  45. data/lib/vimamsa/file_finder.rb +4 -19
  46. data/lib/vimamsa/file_history.rb +3 -0
  47. data/lib/vimamsa/file_manager.rb +30 -15
  48. data/lib/vimamsa/fold.rb +226 -0
  49. data/lib/vimamsa/gui.rb +520 -106
  50. data/lib/vimamsa/gui_command_line.rb +208 -0
  51. data/lib/vimamsa/gui_dialog.rb +94 -42
  52. data/lib/vimamsa/gui_file_panel.rb +356 -25
  53. data/lib/vimamsa/gui_form_generator.rb +59 -35
  54. data/lib/vimamsa/gui_func_panel.rb +67 -22
  55. data/lib/vimamsa/gui_image.rb +3 -0
  56. data/lib/vimamsa/gui_keylog_panel.rb +246 -0
  57. data/lib/vimamsa/gui_menu.rb +23 -11
  58. data/lib/vimamsa/gui_select_window.rb +19 -48
  59. data/lib/vimamsa/gui_settings.rb +78 -37
  60. data/lib/vimamsa/gui_sourceview.rb +273 -19
  61. data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
  62. data/lib/vimamsa/gui_text.rb +63 -2
  63. data/lib/vimamsa/gui_theme.rb +606 -0
  64. data/lib/vimamsa/hook.rb +3 -0
  65. data/lib/vimamsa/hyper_plain_text.rb +3 -0
  66. data/lib/vimamsa/key_actions.rb +112 -13
  67. data/lib/vimamsa/key_binding_tree.rb +242 -215
  68. data/lib/vimamsa/key_bindings_notepad.rb +43 -0
  69. data/lib/vimamsa/key_bindings_report.rb +261 -0
  70. data/lib/vimamsa/key_bindings_vim.rb +354 -0
  71. data/lib/vimamsa/key_bindings_vimlike.rb +65 -9
  72. data/lib/vimamsa/langservp.rb +271 -54
  73. data/lib/vimamsa/macro.rb +3 -0
  74. data/lib/vimamsa/main.rb +14 -8
  75. data/lib/vimamsa/rbvma.rb +26 -1
  76. data/lib/vimamsa/search.rb +3 -0
  77. data/lib/vimamsa/search_replace.rb +11 -10
  78. data/lib/vimamsa/string_util.rb +120 -40
  79. data/lib/vimamsa/terminal.rb +3 -0
  80. data/lib/vimamsa/test_framework.rb +28 -2
  81. data/lib/vimamsa/tests.rb +3 -0
  82. data/lib/vimamsa/text_objects.rb +353 -0
  83. data/lib/vimamsa/text_transforms.rb +14 -0
  84. data/lib/vimamsa/util.rb +46 -7
  85. data/lib/vimamsa/version.rb +1 -1
  86. data/lib/vimamsa.rb +0 -1
  87. data/modules/color_highlight/color_highlight.rb +118 -0
  88. data/modules/color_highlight/color_highlight_info.rb +3 -0
  89. data/modules/dictation/dictation.rb +1054 -0
  90. data/modules/dictation/dictation_info.rb +3 -0
  91. data/modules/dictation/whisper_worker.py +273 -0
  92. data/modules/ollama/ollama.rb +107 -0
  93. data/modules/ollama/ollama_info.rb +3 -0
  94. data/modules/tts/tts.rb +119 -0
  95. data/modules/tts/tts_info.rb +3 -0
  96. data/run_e2e_vm.sh +28 -0
  97. data/run_tests_vm.sh +130 -0
  98. data/scripts/appimage/AppRun +54 -0
  99. data/scripts/appimage/Dockerfile +18 -0
  100. data/scripts/appimage/build.sh +19 -0
  101. data/scripts/appimage/build_in_container.sh +192 -0
  102. data/scripts/appimage/smoke_test.sh +27 -0
  103. data/scripts/demo/demo_steps.txt +59 -0
  104. data/scripts/demo/record_demo.rb +177 -0
  105. data/scripts/demo/shapes.rb +28 -0
  106. data/styles/134272-molokai.xml +3 -0
  107. data/styles/molokai_cyber.xml +48 -0
  108. data/styles/molokai_edit.xml +1 -0
  109. data/tests/support/virtual_keyboard.rb +254 -0
  110. data/tests/support/virtual_mic.rb +67 -0
  111. data/tests/test_ack.rb +22 -0
  112. data/tests/test_auto_format.rb +122 -0
  113. data/tests/test_autocomplete.rb +211 -0
  114. data/tests/test_autosave.rb +145 -0
  115. data/tests/test_basic_editing.rb +33 -3
  116. data/tests/test_bookmarks.rb +206 -0
  117. data/tests/test_bracket_match.rb +85 -0
  118. data/tests/test_bundling.rb +92 -0
  119. data/tests/test_color_highlight.rb +92 -0
  120. data/tests/test_command_line.rb +79 -0
  121. data/tests/test_command_line_file.rb +27 -0
  122. data/tests/test_context_menu_file.rb +129 -0
  123. data/tests/test_copy_paste.rb +80 -0
  124. data/tests/test_crash_handler.rb +39 -0
  125. data/tests/test_custom_two_phase.rb +92 -0
  126. data/tests/test_dialog_callback_errors.rb +44 -0
  127. data/tests/test_dictation.rb +294 -0
  128. data/tests/test_diff_buffer_name.rb +51 -0
  129. data/tests/test_double_click.rb +41 -0
  130. data/tests/test_drag_selection.rb +125 -0
  131. data/tests/test_e2e_cmdline.rb +116 -0
  132. data/tests/test_e2e_dictation.rb +98 -0
  133. data/tests/test_e2e_replace_char.rb +58 -0
  134. data/tests/test_extract_file_links.rb +55 -0
  135. data/tests/test_file_format.rb +217 -0
  136. data/tests/test_file_manager.rb +72 -0
  137. data/tests/test_file_panel.rb +269 -0
  138. data/tests/test_flash.rb +78 -0
  139. data/tests/test_fold.rb +111 -0
  140. data/tests/test_font_refresh.rb +56 -0
  141. data/tests/test_func_panel.rb +68 -0
  142. data/tests/test_grep_apply.rb +46 -0
  143. data/tests/test_gtk_sync.rb +126 -0
  144. data/tests/test_hpt_highlight_visible.rb +75 -0
  145. data/tests/test_hpt_link_highlight.rb +82 -0
  146. data/tests/test_jump_to_file.rb +41 -0
  147. data/tests/test_key_bindings.rb +208 -0
  148. data/tests/test_keylog_panel.rb +101 -0
  149. data/tests/test_lsp_clangd.rb +281 -0
  150. data/tests/test_lsp_jump.rb +87 -0
  151. data/tests/test_lsp_position_encoding.rb +49 -0
  152. data/tests/test_lsp_symbols.rb +68 -0
  153. data/tests/test_macro.rb +137 -0
  154. data/tests/test_markdown_highlight.rb +57 -0
  155. data/tests/test_mode_badge.rb +41 -0
  156. data/tests/test_notepad_bindings.rb +67 -0
  157. data/tests/test_popup_queue.rb +51 -0
  158. data/tests/test_random_edit.rb +109 -0
  159. data/tests/test_revert.rb +127 -0
  160. data/tests/test_startup_file.rb +58 -0
  161. data/tests/test_status_area.rb +50 -0
  162. data/tests/test_text_objects.rb +163 -0
  163. data/tests/test_text_transforms.rb +329 -0
  164. data/tests/test_tts.rb +68 -0
  165. data/tests/test_vim_bindings.rb +252 -0
  166. data/tests/test_vim_conflicts.rb +63 -0
  167. data/tests/test_window_layout.rb +219 -0
  168. data/vimamsa.gemspec +3 -1
  169. data/vm_guest_run.sh +109 -0
  170. metadata +112 -10
@@ -0,0 +1,329 @@
1
+ # Covers the visual-selection transform envelope (transform_selection,
2
+ # convert_selected_text, style_transform) and the line-style helper
3
+ # (set_line_style) after they were refactored onto the shared
4
+ # transform_visual_selection / apply_style_markers helpers.
5
+
6
+ class TestTextTransforms < VmaTest
7
+ # Select the whole first word ("hello") in visual mode.
8
+ def select_first_word
9
+ keys("i h e l l o esc")
10
+ act("buf.set_pos(0)")
11
+ keys("v")
12
+ act("buf.set_pos(4)") # extend selection over "hello"
13
+ end
14
+
15
+ def test_upcase
16
+ select_first_word
17
+ act("buf.transform_selection(:upcase)")
18
+ assert_buf("HELLO\n")
19
+ assert_mode(:command)
20
+ end
21
+
22
+ def test_swapcase
23
+ keys("i H e L l O esc")
24
+ act("buf.set_pos(0)")
25
+ keys("v")
26
+ act("buf.set_pos(4)")
27
+ act("buf.transform_selection(:swapcase)")
28
+ assert_buf("hElLo\n")
29
+ end
30
+
31
+ def test_reverse
32
+ select_first_word
33
+ act("buf.transform_selection(:reverse)")
34
+ assert_buf("olleh\n")
35
+ end
36
+
37
+ def test_no_op_when_not_visual
38
+ keys("i h e l l o esc")
39
+ # Not in visual mode: transform_selection must be a no-op.
40
+ act("buf.transform_selection(:upcase)")
41
+ assert_buf("hello\n")
42
+ end
43
+
44
+ # vim-style case operators in the default (vimlike) keymap
45
+ def test_case_operator_word
46
+ keys("i f o o space b a r esc")
47
+ act("buf.set_pos(0)")
48
+ keys("g U w")
49
+ assert_buf("FOO bar\n")
50
+ assert_pos(0, 0)
51
+ keys("w g ~ w")
52
+ assert_buf("FOO BAR\n")
53
+ keys("g u w")
54
+ assert_buf("FOO bar\n")
55
+ end
56
+
57
+ def test_case_operator_line
58
+ keys("i f o o space b a r esc")
59
+ keys("g U U")
60
+ assert_buf("FOO BAR\n")
61
+ assert_pos(0, 0)
62
+ keys("g u u")
63
+ assert_buf("foo bar\n")
64
+ keys("g ~ ~")
65
+ assert_buf("FOO BAR\n")
66
+ end
67
+
68
+ def test_toggle_case_char
69
+ keys("i a B c esc")
70
+ act("buf.set_pos(0)")
71
+ keys("~ ~")
72
+ assert_buf("Abc\n")
73
+ assert_pos(0, 2)
74
+ end
75
+
76
+ def test_visual_case_keys
77
+ select_first_word
78
+ keys("U")
79
+ assert_buf("HELLO\n")
80
+ act("buf.set_pos(0)")
81
+ keys("v")
82
+ act("buf.set_pos(4)")
83
+ keys("~")
84
+ assert_buf("hello\n")
85
+ end
86
+
87
+ def test_style_bold
88
+ select_first_word
89
+ act("buf.style_transform(:bold)")
90
+ assert_buf("⦁hello⦁\n")
91
+ end
92
+
93
+ def test_style_italic
94
+ select_first_word
95
+ act("buf.style_transform(:italic)")
96
+ assert_buf("╱hello╱\n")
97
+ end
98
+
99
+ def test_style_clear
100
+ keys("i ❙ h i ❙ esc")
101
+ act("buf.set_pos(0)")
102
+ keys("v")
103
+ act("buf.set_pos(3)")
104
+ act("buf.style_transform(:clear)")
105
+ assert_buf("hi\n")
106
+ end
107
+
108
+ def test_line_style_title
109
+ keys("i h e l l o esc")
110
+ act("buf.set_line_style(:title)")
111
+ assert_buf("❙hello❙\n")
112
+ end
113
+
114
+ def test_line_style_italic_then_clear
115
+ keys("i h e l l o esc")
116
+ act("buf.set_line_style(:italic)")
117
+ assert_buf("╱hello╱\n")
118
+ act("buf.set_line_style(:clear)")
119
+ assert_buf("hello\n")
120
+ end
121
+
122
+ def test_line_style_h2_then_clear
123
+ keys("i h e l l o esc")
124
+ act("buf.set_line_style(:h2)")
125
+ assert_buf("◼◼ hello\n")
126
+ act("buf.set_line_style(:clear)")
127
+ assert_buf("hello\n")
128
+ end
129
+
130
+ # Content is set via set_content to avoid auto-indent altering the setup.
131
+
132
+ def test_indent_selection_spaces
133
+ act("cnf.tab.to_spaces_default = true")
134
+ act("cnf.tab.width = 2")
135
+ act('buf.set_content("x\naa\nbb\n")')
136
+ act("buf.set_pos(2)") # start of "aa" line
137
+ keys("v")
138
+ act("buf.set_pos(6)") # into the "bb" line
139
+ act("buf.indent_selection")
140
+ assert_buf("x\n aa\n bb\n")
141
+ end
142
+
143
+ def test_unindent_selection
144
+ act("cnf.tab.to_spaces_default = true")
145
+ act("cnf.tab.width = 2")
146
+ act('buf.set_content("x\n aa\n bb\n")')
147
+ act("buf.set_pos(2)") # start of " aa" line
148
+ keys("v")
149
+ act("buf.set_pos(9)") # into the " bb" line
150
+ act("buf.unindent_selection")
151
+ assert_buf("x\naa\nbb\n")
152
+ end
153
+
154
+ def test_indent_selection_first_line
155
+ act("cnf.tab.to_spaces_default = true")
156
+ act("cnf.tab.width = 2")
157
+ act('buf.set_content("aa\nbb\ncc\n")')
158
+ act("buf.set_pos(1)")
159
+ keys("v")
160
+ act("buf.set_pos(4)") # into the "bb" line
161
+ act("buf.indent_selection")
162
+ assert_buf(" aa\n bb\ncc\n")
163
+ end
164
+
165
+ def test_comment_selection_first_line
166
+ act('buf.set_content("aa\nbb\ncc\n")')
167
+ act("buf.set_pos(1)")
168
+ keys("v")
169
+ act("buf.set_pos(4)") # into the "bb" line
170
+ act("buf.comment_selection")
171
+ assert_buf("// aa\n// bb\ncc\n")
172
+ end
173
+
174
+ def test_indent_selection_last_line
175
+ act("cnf.tab.to_spaces_default = true")
176
+ act("cnf.tab.width = 2")
177
+ act('buf.set_content("aa\nbb\n")')
178
+ act("buf.set_pos(3)")
179
+ keys("v")
180
+ act("buf.set_pos(4)")
181
+ act("buf.indent_selection")
182
+ assert_buf("aa\n bb\n")
183
+ end
184
+
185
+ def test_remove_indent_selection
186
+ act('buf.set_content("x\n aa\n\t\t bb\n \n cc\n dd\n")')
187
+ act("buf.set_pos(5)") # inside the indentation of "aa"
188
+ keys("v")
189
+ act("buf.set_pos(23)") # into the " cc" line
190
+ keys("g i")
191
+ assert_buf("x\naa\nbb\n\ncc\n dd\n")
192
+ assert_mode(:visual)
193
+ assert_eq(buf.get_current_selection, "aa\nbb\n\nc")
194
+ end
195
+
196
+ def test_remove_indent_selection_partial_first_line
197
+ # The whole indent goes, also when the selection starts after it
198
+ act('buf.set_content(" aa bb\n cc\n")')
199
+ act("buf.set_pos(7)")
200
+ keys("v")
201
+ act("buf.set_pos(15)")
202
+ keys("g i")
203
+ assert_buf("aa bb\ncc\n")
204
+ end
205
+
206
+ def test_remove_indent_selection_single_line
207
+ act('buf.set_content(" aa\n bb\n")')
208
+ act("buf.set_pos(3)")
209
+ keys("v")
210
+ keys("g i")
211
+ assert_buf("aa\n bb\n")
212
+ end
213
+
214
+ # g I removes only the smallest indent among the selected non-blank lines,
215
+ # keeping relative indentation; lines outside the selection are untouched.
216
+ def test_remove_common_indent_selection
217
+ act('buf.set_content("x\n aa\n bb\n \n cc\n dd\n")')
218
+ act("buf.set_pos(2)") # "aa" line
219
+ keys("v")
220
+ act("buf.set_pos(23)") # into the "cc" line
221
+ keys("g I")
222
+ assert_buf("x\naa\n bb\n\ncc\n dd\n")
223
+ assert_mode(:visual)
224
+ end
225
+
226
+ def test_remove_common_indent_tabs
227
+ act('buf.set_content("\t\taa\n\tbb\n")')
228
+ act("buf.set_pos(0)")
229
+ keys("v")
230
+ act("buf.set_pos(5)")
231
+ keys("g I")
232
+ assert_buf("\taa\nbb\n")
233
+ end
234
+
235
+ def test_remove_common_indent_noop_when_some_line_unindented
236
+ act('buf.set_content(" aa\nbb\n")')
237
+ act("buf.set_pos(0)")
238
+ keys("v")
239
+ act("buf.set_pos(6)")
240
+ keys("g I")
241
+ assert_buf(" aa\nbb\n")
242
+ end
243
+
244
+ def test_remove_common_indent_current_line
245
+ act('buf.set_content("x\n aa\n")')
246
+ act("buf.set_pos(5)")
247
+ keys("g I")
248
+ assert_buf("x\naa\n")
249
+ end
250
+
251
+ # Outside visual mode g i works on the current line only; the cursor keeps
252
+ # its character.
253
+ def test_remove_indent_current_line
254
+ act('buf.set_content(" aa\n \t bb cc\n dd\n")')
255
+ act("buf.set_pos(9)") # the "c" of "cc"
256
+ keys("g i")
257
+ assert_buf(" aa\nbb cc\n dd\n")
258
+ assert_mode(:command)
259
+ assert_eq(6, buf.pos)
260
+ end
261
+
262
+ def test_remove_indent_current_line_cursor_in_indent
263
+ act('buf.set_content("x\n aa\n")')
264
+ act("buf.set_pos(3)") # inside the indentation
265
+ keys("g i")
266
+ assert_buf("x\naa\n")
267
+ assert_eq(2, buf.pos)
268
+ end
269
+
270
+ def test_remove_indent_current_line_last_and_unindented
271
+ act('buf.set_content("aa\n bb\n")')
272
+ act("buf.set_pos(1)")
273
+ keys("g i") # no indent: unchanged
274
+ assert_buf("aa\n bb\n")
275
+ act("buf.set_pos(5)")
276
+ keys("g i") # last line
277
+ assert_buf("aa\nbb\n")
278
+ end
279
+
280
+ def test_converter_on_selection
281
+ keys("i b space a space c esc")
282
+ act("buf.set_pos(0)")
283
+ keys("v")
284
+ act("buf.set_pos(4)")
285
+ act("buf.convert_selected_text(:sortwords)")
286
+ assert_buf("a b c\n")
287
+ assert_mode(:command)
288
+ end
289
+
290
+ # Not in visual mode: converter runs on the current line only
291
+ def test_converter_on_current_line
292
+ act("buf.insert_txt(\"x\\nb a c\\ny\")")
293
+ act("buf.set_pos(3)")
294
+ act("buf.convert_selected_text(:sortwords)")
295
+ assert_buf("x\na b c\ny\n")
296
+ end
297
+
298
+ # Converter result ending in a newline doesn't add a blank line
299
+ def test_converter_on_current_line_trailing_newline
300
+ act("buf.insert_txt(\"x\\n a \\ny\")")
301
+ act("buf.set_pos(3)")
302
+ act("buf.convert_selected_text(:joinlines)")
303
+ assert_buf("x\na\ny\n")
304
+ end
305
+
306
+ def test_converter_on_empty_line
307
+ act("buf.insert_txt(\"x\\n\\ny\")")
308
+ act("buf.set_pos(2)")
309
+ act("buf.convert_selected_text(:sortwords)")
310
+ assert_buf("x\n\ny\n")
311
+ end
312
+
313
+ def test_remove_extra_spaces_current_line
314
+ act("buf.insert_txt(\"x y\\n a b\\tc \\nz w\")")
315
+ act("buf.set_pos(6)")
316
+ keys("g w")
317
+ assert_buf("x y\n a b c\nz w\n")
318
+ end
319
+
320
+ def test_remove_extra_spaces_selection
321
+ act("buf.insert_txt(\"a b\\nc d \\ne f\")")
322
+ act("buf.set_pos(0)")
323
+ keys("v")
324
+ act("buf.set_pos(11)") # through the trailing spaces of line 2
325
+ keys("g w")
326
+ assert_buf("a b\nc d\ne f\n")
327
+ assert_mode(:command)
328
+ end
329
+ end
data/tests/test_tts.rb ADDED
@@ -0,0 +1,68 @@
1
+ class TestTts < VmaTest
2
+ def load_tts
3
+ load ppath("modules/tts/tts_info.rb")
4
+ load ppath("modules/tts/tts.rb")
5
+ end
6
+
7
+ def ensure_disabled
8
+ tts_disable if vma.actions.include?(:tts_speak_selection)
9
+ end
10
+
11
+ # --- _info ---
12
+
13
+ def test_info_structure
14
+ load ppath("modules/tts/tts_info.rb")
15
+ info = tts_info
16
+ assert info[:name].is_a?(String) && !info[:name].empty?, "name should be a non-empty String"
17
+ assert_eq true, info[:no_restart], "tts should be no_restart"
18
+ end
19
+
20
+ # --- init / disable contract ---
21
+
22
+ def test_init_registers_actions_and_menu
23
+ ensure_disabled
24
+ load_tts
25
+ tts_init
26
+ assert vma.actions.include?(:tts_speak_selection), "speak action not registered"
27
+ assert vma.actions.include?(:tts_stop), "stop action not registered"
28
+ assert vma.gui.menu.module_action?(:tts_speak_selection), "speak menu item missing"
29
+ assert vma.gui.menu.module_action?(:tts_stop), "stop menu item missing"
30
+ ensure
31
+ tts_disable
32
+ end
33
+
34
+ def test_disable_unregisters
35
+ ensure_disabled
36
+ load_tts
37
+ tts_init
38
+ tts_disable
39
+ assert !vma.actions.include?(:tts_speak_selection), "speak action still registered"
40
+ assert !vma.actions.include?(:tts_stop), "stop action still registered"
41
+ assert !vma.gui.menu.module_action?(:tts_speak_selection), "speak menu still present"
42
+ end
43
+
44
+ def test_init_disable_cycle
45
+ ensure_disabled
46
+ load_tts
47
+ 3.times do |i|
48
+ tts_init
49
+ assert vma.actions.include?(:tts_speak_selection), "speak missing after init (cycle #{i})"
50
+ tts_disable
51
+ assert !vma.actions.include?(:tts_speak_selection), "speak present after disable (cycle #{i})"
52
+ end
53
+ end
54
+
55
+ # --- detect_rate ---
56
+
57
+ def test_detect_rate
58
+ load_tts
59
+ dir = Dir.mktmpdir("vma_tts_test")
60
+ File.write(File.join(dir, "myvoice.onnx.json"),
61
+ JSON.generate({ "audio" => { "sample_rate" => 16000 } }))
62
+ rate = VmaTts.new.send(:detect_rate, dir, "myvoice")
63
+ assert_eq 16000, rate, "sample rate not read from voice json"
64
+ assert_eq nil, VmaTts.new.send(:detect_rate, dir, "missing"), "missing voice should be nil"
65
+ ensure
66
+ FileUtils.remove_entry(dir) if dir && File.exist?(dir)
67
+ end
68
+ end
@@ -0,0 +1,252 @@
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
+ def test_join
90
+ assert_matches_vim("aa\nbb\n", "J")
91
+ end
92
+
93
+ def test_yank_paste
94
+ assert_matches_vim("aa\nbb\n", "yyp")
95
+ assert_matches_vim("aa\nbb\n", "Yp")
96
+ end
97
+
98
+ def test_open_lines
99
+ assert_matches_vim("aa\nbb\n", "ofoo\e")
100
+ assert_matches_vim("aa\nbb\n", "Obar\e")
101
+ end
102
+
103
+ def test_insert_variants
104
+ assert_matches_vim("world\n", "ihi \e")
105
+ assert_matches_vim(" hi\n", "A!\e")
106
+ assert_matches_vim(" hi\n", "I>\e")
107
+ end
108
+
109
+ def test_first_non_blank
110
+ assert_matches_vim(" abc\n", "$^ix\e")
111
+ end
112
+
113
+ def test_motions_with_insert_probe
114
+ assert_matches_vim("a\nb\nc\nd\ne\n", "3jix\e")
115
+ assert_matches_vim("abcdef\n", "fdix\e")
116
+ assert_matches_vim("a\nb\nc\n", "Gdd")
117
+ assert_matches_vim("a\nb\nc\n", "Gggdd")
118
+ end
119
+
120
+ def test_undo_after_dd
121
+ assert_matches_vim("aa\nbb\n", "ddu")
122
+ end
123
+
124
+ # ── structural tests (approximations / GUI-dependent; no oracle) ──────────
125
+
126
+ def test_leader_namespace_gone
127
+ before = vma.buf.to_s
128
+ keys ", b" # vimlike: start_buf_manager; must be inert now
129
+ assert_mode :command
130
+ assert_buf before
131
+ end
132
+
133
+ def test_non_vim_chords_gone
134
+ n = bufs.list.size
135
+ keys "ctrl-w" # vimlike: close_current_buffer
136
+ assert_eq n, bufs.list.size
137
+ keys "i ctrl-w" # vimlike: close_current_buffer from insert
138
+ assert_eq n, bufs.list.size
139
+ assert_mode :insert
140
+ keys "esc"
141
+ end
142
+
143
+ def test_insert_ctrl_c_acts_as_esc
144
+ keys "i"
145
+ assert_mode :insert
146
+ keys "ctrl-c"
147
+ assert_mode :command
148
+ end
149
+
150
+ def test_insert_ctrl_h_is_backspace
151
+ keys "i a b ctrl-h"
152
+ assert_buf "a\n"
153
+ keys "esc"
154
+ end
155
+
156
+ def test_zz_dispatch
157
+ keys "z z"
158
+ assert_eq :center_on_current_line, vma.kbd.cur_action
159
+ end
160
+
161
+ def test_ctrl_o_binding
162
+ assert_eq "ctrl-o", vma.kbd.act_bindings["C"][:jump_to_last_edit]
163
+ end
164
+
165
+ def test_backtick_jumps_to_mark
166
+ act 'buf.insert_txt("one\ntwo\nthree\n")'
167
+ act :jump_to_start_of_buffer
168
+ keys "j m a G ` a"
169
+ assert_eq 1, vma.buf.lpos
170
+ end
171
+
172
+ def test_ctrl_a_increments
173
+ act 'buf.insert_txt("a 41 b")'
174
+ act :jump_to_start_of_buffer
175
+ keys "w ctrl-a"
176
+ assert_buf "a 42 b\n"
177
+ end
178
+
179
+ def test_visual_case_ops
180
+ act 'buf.insert_txt("abc def")'
181
+ act :jump_to_start_of_buffer
182
+ keys "v e U"
183
+ assert_buf "ABC def\n"
184
+ end
185
+
186
+ private
187
+
188
+ def _setup_test
189
+ create_new_buffer("\n", "test", true)
190
+ vma.kbd.set_mode(:command) rescue nil
191
+ drain_idle
192
+ end
193
+
194
+ # vim-style key string -> vimamsa keys() tokens
195
+ def vim_tokens(s)
196
+ s.chars.map { |ch|
197
+ case ch
198
+ when "\e" then "esc"
199
+ when " " then "space"
200
+ when "\r", "\n" then "enter"
201
+ else ch
202
+ end
203
+ }.join(" ")
204
+ end
205
+
206
+ # Run `normal! nkeys` in real vim on initial; returns resulting text,
207
+ # nil if no vim available. Array-args system(): raw "\e" bytes are fine.
208
+ def vim_oracle(initial, nkeys)
209
+ return nil unless NVIM
210
+ f = Tempfile.new(["vma_vim_oracle", ".txt"])
211
+ begin
212
+ f.write(initial)
213
+ f.flush
214
+ # Plain vim has no --headless: use silent ex mode, which starts on the
215
+ # last line, so jump to line 1 first.
216
+ mode = NVIM == "nvim" ? ["--headless"] : ["-E", "-s", "-c", "1"]
217
+ ok = system(NVIM, *mode, "-u", "NONE", "-i", "NONE", "-n",
218
+ "-c", "set noautoindent nosmartindent",
219
+ "-c", "normal! #{nkeys}",
220
+ "-c", "wq!", f.path,
221
+ out: File::NULL, err: File::NULL)
222
+ raise VmaTestFailure, "oracle #{NVIM} failed for #{nkeys.inspect}" unless ok
223
+ IO.read(f.path)
224
+ ensure
225
+ f.close
226
+ f.unlink
227
+ end
228
+ end
229
+
230
+ def assert_matches_vim(initial, seq)
231
+ raise VmaTestFailure, "initial must end with \\n" unless initial.end_with?("\n")
232
+ create_new_buffer(initial, "vimoracle", true)
233
+ vma.kbd.set_mode(:command) rescue nil
234
+ vma.buf.set_pos(0) # cursor at line 1 col 1, like vim
235
+ drain_idle
236
+ # Force the synchronous internal-clipboard paste path (as in test_copy_paste)
237
+ vma.macro.instance_variable_set(:@running_macro, true)
238
+ begin
239
+ keys vim_tokens(seq)
240
+ ensure
241
+ vma.macro.instance_variable_set(:@running_macro, false)
242
+ end
243
+ expected = vim_oracle(initial, seq)
244
+ if expected.nil?
245
+ puts " SKIP oracle (no nvim/vim in PATH)"
246
+ return
247
+ end
248
+ assert_eq expected, vma.buf.to_s,
249
+ "vim mismatch for #{seq.inspect} on #{initial.inspect}\n" \
250
+ " vim: #{expected.inspect}\n vimamsa: #{vma.buf.to_s.inspect}"
251
+ end
252
+ end