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,41 @@
1
+ # Regression tests for the mode badge (e.g. COMMAND) shown in the status area.
2
+ #
3
+ # Bug: the badge stayed blank on startup because show_state_trail was only ever
4
+ # called from key handling — so the mode was not displayed until the first
5
+ # keypress. Editor#start now calls set_state_to_root + show_state_trail after
6
+ # init to paint it immediately.
7
+ class TestModeBadge < VmaTest
8
+
9
+ def badge_text
10
+ vma.gui.statnfo.text
11
+ end
12
+
13
+ # Force a re-render regardless of the last painted value (update_mode_badge
14
+ # skips the update when the text is unchanged).
15
+ def render_badge
16
+ vma.gui.instance_variable_set(:@last_badge_text, nil)
17
+ vma.kbd.set_state_to_root
18
+ vma.kbd.show_state_trail
19
+ end
20
+
21
+ # The exact sequence Editor#start runs must paint a non-blank badge, even
22
+ # starting from the pre-fix state where the label is empty.
23
+ def test_startup_sequence_paints_badge
24
+ vma.kbd.set_mode(:command)
25
+ vma.gui.statnfo.text = "" # simulate the blank pre-fix state
26
+ render_badge
27
+ assert !badge_text.empty?, "mode badge should be painted, was blank"
28
+ assert_eq "COMMAND", badge_text
29
+ end
30
+
31
+ # Badge reflects the active mode.
32
+ def test_badge_reflects_mode
33
+ vma.kbd.set_mode(:insert)
34
+ render_badge
35
+ assert_eq "INSERT", badge_text
36
+
37
+ vma.kbd.set_mode(:command)
38
+ render_badge
39
+ assert_eq "COMMAND", badge_text
40
+ end
41
+ end
@@ -1,7 +1,7 @@
1
1
  class TestModuleInterface < VmaTest
2
2
  # Ensure the calculator is inactive before each test that needs a clean slate.
3
3
  def ensure_disabled
4
- if vma.actions.include?(:insert_calculator)
4
+ if vma.actions.include?("calculator.insert")
5
5
  calculator_disable if respond_to?(:calculator_disable, true)
6
6
  end
7
7
  end
@@ -27,7 +27,7 @@ class TestModuleInterface < VmaTest
27
27
  ensure_disabled
28
28
  load_calculator
29
29
  calculator_init
30
- assert vma.actions.include?(:insert_calculator), "action not registered after init"
30
+ assert vma.actions.include?("calculator.insert"), "action not registered after init"
31
31
  ensure
32
32
  calculator_disable
33
33
  end
@@ -36,7 +36,7 @@ class TestModuleInterface < VmaTest
36
36
  ensure_disabled
37
37
  load_calculator
38
38
  calculator_init
39
- assert vma.gui.menu.module_action?(:insert_calculator), "menu item missing after init"
39
+ assert vma.gui.menu.module_action?("calculator.insert"), "menu item missing after init"
40
40
  ensure
41
41
  calculator_disable
42
42
  end
@@ -48,7 +48,7 @@ class TestModuleInterface < VmaTest
48
48
  load_calculator
49
49
  calculator_init
50
50
  calculator_disable
51
- assert !vma.actions.include?(:insert_calculator), "action still registered after disable"
51
+ assert !vma.actions.include?("calculator.insert"), "action still registered after disable"
52
52
  end
53
53
 
54
54
  def test_disable_removes_menu_item
@@ -56,7 +56,7 @@ class TestModuleInterface < VmaTest
56
56
  load_calculator
57
57
  calculator_init
58
58
  calculator_disable
59
- assert !vma.gui.menu.module_action?(:insert_calculator), "menu item still present after disable"
59
+ assert !vma.gui.menu.module_action?("calculator.insert"), "menu item still present after disable"
60
60
  end
61
61
 
62
62
  # --- cycle ---
@@ -66,11 +66,11 @@ class TestModuleInterface < VmaTest
66
66
  load_calculator
67
67
  3.times do |i|
68
68
  calculator_init
69
- assert vma.actions.include?(:insert_calculator), "action missing after init (cycle #{i})"
70
- assert vma.gui.menu.module_action?(:insert_calculator), "menu missing after init (cycle #{i})"
69
+ assert vma.actions.include?("calculator.insert"), "action missing after init (cycle #{i})"
70
+ assert vma.gui.menu.module_action?("calculator.insert"), "menu missing after init (cycle #{i})"
71
71
  calculator_disable
72
- assert !vma.actions.include?(:insert_calculator), "action present after disable (cycle #{i})"
73
- assert !vma.gui.menu.module_action?(:insert_calculator), "menu present after disable (cycle #{i})"
72
+ assert !vma.actions.include?("calculator.insert"), "action present after disable (cycle #{i})"
73
+ assert !vma.gui.menu.module_action?("calculator.insert"), "menu present after disable (cycle #{i})"
74
74
  end
75
75
  end
76
76
 
@@ -0,0 +1,67 @@
1
+ # Tests for the notepad keybinding scheme.
2
+ #
3
+ # Run separately: ruby exe/run_tests.rb notepad_bindings
4
+ # Excluded from the default suite (see exe/run_tests.rb): loading the
5
+ # notepad scheme permanently rebinds keys in the shared test process.
6
+ load "vimamsa/key_bindings_notepad.rb" # vimlike already required; applies overrides
7
+
8
+ class TestNotepadBindings < VmaTest
9
+ def test_typing_inserts_in_default_mode
10
+ keys "h i"
11
+ assert_mode :insert
12
+ assert_buf "hi\n"
13
+ end
14
+
15
+ def test_esc_clears_selection_stays_insert
16
+ act 'buf.insert_txt("abc")'
17
+ keys "shift-left shift-left"
18
+ assert vma.buf.selection_active?, "shift-left should select"
19
+ keys "esc"
20
+ assert_mode :insert
21
+ assert !vma.buf.selection_active?, "esc should clear selection"
22
+ end
23
+
24
+ def test_ctrl_a_selects_all
25
+ act 'buf.insert_txt("hello world")'
26
+ keys "ctrl-a"
27
+ assert vma.buf.selection_active?, "ctrl-a should activate selection"
28
+ r = vma.buf.get_visual_mode_range
29
+ assert_eq 0, r.begin
30
+ assert_eq vma.buf.size - 1, r.end
31
+ end
32
+
33
+ def test_delete_forward
34
+ act 'buf.insert_txt("abc")'
35
+ act "move.buf.start"
36
+ keys "delete"
37
+ assert_buf "bc\n"
38
+ end
39
+
40
+ def test_home_end_keys
41
+ act 'buf.insert_txt("hello")'
42
+ keys "home"
43
+ assert_pos 0, 0
44
+ keys "end"
45
+ assert_eq 5, vma.buf.pos
46
+ end
47
+
48
+ def test_rebound_dispatch
49
+ # Assert rebinds without invoking GUI dialogs / quit
50
+ assert_eq "ctrl-f", vma.kbd.act_bindings["I"]["search.buf"]
51
+ assert_eq "ctrl-h", vma.kbd.act_bindings["I"]["search.replace"]
52
+ assert_eq "ctrl-q", vma.kbd.act_bindings["I"]["app.quit"]
53
+ keys "ctrl-n" # safe to execute: creates a new buffer
54
+ assert_eq "buf.new", vma.kbd.cur_action
55
+ assert_mode :insert
56
+ end
57
+
58
+ private
59
+
60
+ # Framework default sets :command mode; the notepad scheme is
61
+ # insert-mode based, so make that explicit for each test.
62
+ def _setup_test
63
+ create_new_buffer("\n", "test", true)
64
+ vma.kbd.set_mode(:insert) rescue nil
65
+ drain_idle
66
+ end
67
+ end
@@ -0,0 +1,28 @@
1
+ # Startup time compared with an earlier commit (scripts/lib/perf_startup.rb).
2
+ # Not in the default suite (about a minute): run it by name, e.g.
3
+ # ./run_tests_vm.rb perf_startup # vs the previous commit
4
+ # ./run_tests_vm.rb perf_startup ref=HEAD~10 runs=7
5
+ # Without ref=: the previous commit, or the current one when lib/, exe/ or
6
+ # ext/ have uncommitted changes. Fails when the fastest startup grew by more
7
+ # than 25% and more than 0.3 s.
8
+ require_relative "../scripts/lib/perf_startup"
9
+
10
+ class TestPerfStartup < VmaTest
11
+ REPO = File.expand_path("..", __dir__)
12
+
13
+ def test_startup_not_much_slower
14
+ skip "needs a display" unless ENV["DISPLAY"] || ENV["WAYLAND_DISPLAY"]
15
+ skip "not a git checkout" unless File.exist?(File.join(REPO, ".git"))
16
+ ref = $vma_test_ref || PerfStartup.default_ref(REPO)
17
+ runs = $vma_test_runs || 5
18
+ puts " startup time: current vs #{ref}, #{runs} runs each"
19
+ times = PerfStartup.compare(REPO, ref, runs: runs, file: File.join(REPO, "README.md"))
20
+ cur, old = times["current"].min, times[ref].min
21
+ pct = (cur - old) / old * 100
22
+ puts format(" fastest: current %.2f s, %s %.2f s (%+.0f%%)", cur, ref, old, pct)
23
+ puts format(" median: current %.2f s, %s %.2f s", PerfStartup.median(times["current"]), ref, PerfStartup.median(times[ref]))
24
+ assert !PerfStartup.slower?(cur, old),
25
+ format("startup is %.2f s (%+.0f%%) slower than at %s: %s vs %s", cur - old, pct, ref,
26
+ times["current"].map { |t| t.round(2) }.inspect, times[ref].map { |t| t.round(2) }.inspect)
27
+ end
28
+ end
@@ -0,0 +1,51 @@
1
+ # PopupFormGenerator serializes modal popups: only one shows at a time, the
2
+ # rest queue and appear as each closes. This prevents two modal dialogs (e.g.
3
+ # the session-restore dialog and a startup file's autosave dialog at startup)
4
+ # from grabbing input simultaneously and getting stuck.
5
+
6
+ class TestPopupQueue < VmaTest
7
+ def popup_params
8
+ { "inputs" => { "ok" => { :label => "OK", :type => :button } }, :callback => proc {} }
9
+ end
10
+
11
+ def test_second_popup_queues_until_first_closes
12
+ PopupFormGenerator.reset_popup_queue
13
+
14
+ p1 = PopupFormGenerator.new(popup_params)
15
+ p1.run
16
+ assert(PopupFormGenerator.popup_active?, "first popup should be active")
17
+ assert_eq(0, PopupFormGenerator.popup_queue_size)
18
+
19
+ # Second popup requested while the first is open -> queued, not shown.
20
+ p2 = PopupFormGenerator.new(popup_params)
21
+ p2.run
22
+ assert(PopupFormGenerator.popup_active?, "first popup still active")
23
+ assert_eq(1, PopupFormGenerator.popup_queue_size, "second popup should be queued")
24
+
25
+ # Close the first -> the queued popup is presented.
26
+ p1.close
27
+ drain_idle
28
+ assert(PopupFormGenerator.popup_active?, "queued popup should now be active")
29
+ assert_eq(0, PopupFormGenerator.popup_queue_size, "queue should be drained")
30
+
31
+ # Close the second -> nothing left active.
32
+ p2.close
33
+ drain_idle
34
+ assert(!PopupFormGenerator.popup_active?, "no popup should remain active")
35
+ ensure
36
+ PopupFormGenerator.reset_popup_queue
37
+ end
38
+
39
+ def test_single_popup_shows_immediately
40
+ PopupFormGenerator.reset_popup_queue
41
+ p1 = PopupFormGenerator.new(popup_params)
42
+ p1.run
43
+ assert(PopupFormGenerator.popup_active?)
44
+ assert_eq(0, PopupFormGenerator.popup_queue_size)
45
+ p1.close
46
+ drain_idle
47
+ assert(!PopupFormGenerator.popup_active?)
48
+ ensure
49
+ PopupFormGenerator.reset_popup_queue
50
+ end
51
+ end
@@ -0,0 +1,109 @@
1
+ # Random edit stress test — NOT part of the normal test suite.
2
+ # Run explicitly: vimamsa --test tests/test_random_edit.rb
3
+ #
4
+ # Executes editor actions at random for 30 seconds and fails if any
5
+ # action raises an unhandled exception (i.e. the editor crashes).
6
+
7
+ class TestRandomEdit < VmaTest
8
+
9
+ DURATION = 300 # seconds — override with duration=N on the command line
10
+
11
+ # Safe actions: no file dialogs, no eval, no close/save operations.
12
+ SAFE_ACTIONS = [
13
+ "move.char.next",
14
+ "move.char.prev",
15
+ "move.line.next",
16
+ "move.line.prev",
17
+ "move.buf.start",
18
+ "move.buf.end",
19
+ "move.line.end",
20
+ "move.line.start",
21
+ "move.word.end",
22
+ "move.word.prev",
23
+ "move.word.next",
24
+ "edit.delete.char",
25
+ "edit.backspace",
26
+ "edit.delete.word.end",
27
+ "edit.delete.word.next",
28
+ "edit.delete.line.start",
29
+ "undo.last",
30
+ "undo.redo",
31
+ "edit.line.copy",
32
+ "edit.paste.after",
33
+ "edit.paste.before",
34
+ "edit.newline",
35
+ "move.page.next",
36
+ "move.page.prev",
37
+ "view.center",
38
+ "view.cursor.refresh",
39
+ ].freeze
40
+
41
+ RANDOM_TEXTS = [
42
+ "hello world",
43
+ "foo bar baz",
44
+ "test 123",
45
+ "abc def ghi",
46
+ " indented ",
47
+ "line\nbreak",
48
+ "x",
49
+ "longer text with spaces and stuff",
50
+ ].freeze
51
+
52
+ MODES = [:insert, :command, :visual].freeze
53
+
54
+ def test_random_editing_stress
55
+ duration = $vma_test_duration || DURATION
56
+ start_time = Time.now
57
+ iteration = 0
58
+ errors = []
59
+
60
+ # Seed the buffer with some content to work with
61
+ act 'buf.insert_txt("alpha\nbeta\ngamma\ndelta\nepsilon\nzeta\neta\n")'
62
+
63
+ while Time.now - start_time < duration
64
+ iteration += 1
65
+
66
+ begin
67
+ case rand(12)
68
+ when 0..5 then act_fast(SAFE_ACTIONS.sample)
69
+ when 6..7 then act_fast("buf.insert_txt(#{RANDOM_TEXTS.sample.inspect})")
70
+ when 8 then act_fast("vma.kbd.set_mode(:insert)")
71
+ when 9 then act_fast("vma.kbd.set_mode(:command)")
72
+ when 10 then act_fast("buf.start_selection; vma.kbd.set_mode(:visual)")
73
+ when 11 then act_fast("move.random")
74
+ end
75
+ rescue => e
76
+ errors << "iter #{iteration}: #{e.class}: #{e.message}"
77
+ end
78
+
79
+ if (iteration % 20).zero?
80
+ drain_idle
81
+ # Flush pending deltas to GTK before comparing — handle_deltas is not
82
+ # called by act_fast or drain_idle, so the GTK buffer lags otherwise.
83
+ vma.buf.view.handle_deltas
84
+
85
+ # Verify GTK and Ruby buffers are in sync
86
+ gtk_text = vma.buf.view.buffer.text
87
+ ruby_text = vma.buf.to_s
88
+ unless gtk_text == ruby_text
89
+ errors << "iter #{iteration}: GTK/Ruby buffer mismatch " \
90
+ "(gtk #{gtk_text.bytesize}B != ruby #{ruby_text.bytesize}B)"
91
+ end
92
+ end
93
+ end
94
+
95
+ # Restore a clean state
96
+ act("vma.kbd.set_mode(:command)") rescue nil
97
+ drain_idle
98
+
99
+ elapsed = (Time.now - start_time).round(1)
100
+ puts " Random edit stress: #{iteration} actions in #{elapsed}s"
101
+
102
+ unless errors.empty?
103
+ sample = errors.first(5).join("\n ")
104
+ raise VmaTestFailure,
105
+ "#{errors.size} error(s) during random editing:\n #{sample}"
106
+ end
107
+ end
108
+
109
+ end
@@ -0,0 +1,122 @@
1
+ # Vim registers (registers.rb, doc/vim_compatibility_plan.md step 4)
2
+ class TestRegisters < VmaTest
3
+ # Put synchronously from the editor's copy (as in test_copy_paste): the
4
+ # system clipboard is read asynchronously and may belong to another program
5
+ def sync_paste
6
+ vma.macro.instance_variable_set(:@running_macro, true)
7
+ yield
8
+ ensure
9
+ vma.macro.instance_variable_set(:@running_macro, false)
10
+ end
11
+
12
+ def setup_text(s, pos = 0)
13
+ buf.set_content(s)
14
+ buf.set_pos(pos)
15
+ vma.kbd.set_mode(:command)
16
+ end
17
+
18
+ def test_linewise_put_in_another_buffer
19
+ setup_text("one\ntwo\n")
20
+ keys("y y")
21
+ create_new_buffer("a\nb\n", "regtest", true)
22
+ buf.set_pos(0)
23
+ sync_paste { keys("p") }
24
+ assert_buf "a\none\nb\n"
25
+ vma.buffers.close_buffer(buf.id)
26
+ end
27
+
28
+ def test_named_register
29
+ setup_text("one\ntwo\n")
30
+ keys('" a y y j')
31
+ assert_eq ["one\n", true], vma.registers["a"].to_a
32
+ keys('" a p')
33
+ assert_buf "one\ntwo\none\n"
34
+ end
35
+
36
+ def test_append_to_named_register
37
+ setup_text("one two\nthree\n")
38
+ keys('" a y y')
39
+ keys('j " A y y')
40
+ assert_eq ["one two\nthree\n", true], vma.registers["a"].to_a
41
+ vma.registers.store("x", reg: "b")
42
+ vma.registers.store("y", reg: "B")
43
+ assert_eq ["xy", false], vma.registers["b"].to_a
44
+ end
45
+
46
+ def test_numbered_and_small_delete
47
+ setup_text("1\n2\n3\nfoo bar\n")
48
+ keys("d d d d")
49
+ assert_eq "2\n", vma.registers["1"].text
50
+ assert_eq "1\n", vma.registers["2"].text
51
+ keys("j d w") # a delete within one line goes to "-, not "1
52
+ assert_eq "foo ", vma.registers["-"].text
53
+ assert_eq "2\n", vma.registers["1"].text
54
+ end
55
+
56
+ def test_yank_register_survives_deletes
57
+ setup_text("keep\ngone\n")
58
+ keys("y y j d d")
59
+ assert_eq "keep\n", vma.registers["0"].text
60
+ assert_eq "gone\n", vma.registers['"'].text
61
+ keys('" 0 P')
62
+ assert_buf "keep\nkeep\n"
63
+ end
64
+
65
+ def test_black_hole
66
+ setup_text("keep\ngone\n")
67
+ keys("y y j")
68
+ keys('" _ d d')
69
+ assert_buf "keep\n"
70
+ assert_eq "keep\n", vma.registers['"'].text
71
+ assert_eq "keep\n", vma.clipboard.get
72
+ end
73
+
74
+ # "x applies to the next command only; a count may come between
75
+ def test_pending_register_is_used_once
76
+ setup_text("a\nb\nc\n")
77
+ keys('" q j y y')
78
+ assert vma.registers["q"].nil?, "register used by a later command"
79
+ keys('" w 2 y y')
80
+ assert_eq "b\nc\n", vma.registers["w"].text
81
+ end
82
+
83
+ # A case change replaces the text but isn't a delete
84
+ def test_case_change_keeps_clipboard
85
+ setup_text("abc def\n")
86
+ keys("y y g U w")
87
+ assert_buf "ABC def\n"
88
+ assert_eq "abc def\n", vma.registers['"'].text
89
+ end
90
+
91
+ def test_put_empty_register
92
+ setup_text("abc\n")
93
+ keys('" z p')
94
+ assert_buf "abc\n"
95
+ end
96
+
97
+ def test_insert_register
98
+ setup_text("abc\n")
99
+ vma.registers.store("XY", reg: "k")
100
+ keys("i")
101
+ act("a.edit.insert.register!('k')")
102
+ keys("esc")
103
+ assert_buf "XYabc\n"
104
+ end
105
+
106
+ def test_operator_and_text_object_registers
107
+ setup_text("foo bar\n")
108
+ keys('" e c w') # vimlike has no c: the shared operator layer
109
+ keys("esc")
110
+ assert_eq ["foo", false], vma.registers["e"].to_a
111
+ setup_text("(x y)\n", 1)
112
+ keys('" f d i (')
113
+ assert_eq "x y", vma.registers["f"].text
114
+ end
115
+
116
+ def test_show_registers
117
+ vma.registers.store("hello\n", linewise: true, reg: "h")
118
+ show_registers
119
+ assert buf.to_s.include?("\"h l hello^J"), buf.to_s
120
+ vma.buffers.close_buffer(buf.id)
121
+ end
122
+ end
@@ -0,0 +1,127 @@
1
+ require "tempfile"
2
+
3
+ # Reloading a file that was changed by an external program (buf.revert) must
4
+ # keep the cursor, the view and the edit positions on the same text.
5
+ class TestRevert < VmaTest
6
+
7
+ def open_temp(contents)
8
+ @tmp = Tempfile.new(["revert_test", ".txt"])
9
+ @tmp.write(contents)
10
+ @tmp.flush
11
+ open_new_file(File.expand_path(@tmp.path))
12
+ drain_idle
13
+ end
14
+
15
+ def write_external(contents)
16
+ File.write(@tmp.path, contents)
17
+ end
18
+
19
+ def revert
20
+ act "buf.revert"
21
+ drain_idle
22
+ end
23
+
24
+ def teardown_tmp
25
+ return if @tmp.nil?
26
+ @tmp.close
27
+ @tmp.unlink
28
+ @tmp = nil
29
+ end
30
+
31
+ def edit_pos_history
32
+ vma.buf.instance_variable_get(:@edit_pos_history)
33
+ end
34
+
35
+ def test_cursor_follows_lines_inserted_above
36
+ open_temp("aaa\nbbb\nccc\n")
37
+ act "buf.set_line_and_column_pos(2, 1)"
38
+ write_external("new1\nnew2\naaa\nbbb\nccc\n")
39
+ revert
40
+ assert_buf "new1\nnew2\naaa\nbbb\nccc\n"
41
+ assert_pos(4, 1)
42
+ ensure
43
+ teardown_tmp
44
+ end
45
+
46
+ def test_cursor_follows_edit_on_same_line
47
+ open_temp("foo bar baz\n")
48
+ act "buf.set_pos(8)" # on "baz"
49
+ write_external("foo XXXXX bar baz\n")
50
+ revert
51
+ assert_pos(0, 14)
52
+ assert_eq "baz", vma.buf.to_s[vma.buf.pos, 3]
53
+ ensure
54
+ teardown_tmp
55
+ end
56
+
57
+ def test_cursor_on_deleted_line
58
+ open_temp("aaa\nbbb\nccc\n")
59
+ act "buf.set_line_and_column_pos(1, 2)"
60
+ write_external("aaa\nccc\n")
61
+ revert
62
+ assert_buf "aaa\nccc\n"
63
+ assert_pos(1, 0)
64
+ ensure
65
+ teardown_tmp
66
+ end
67
+
68
+ def test_edit_positions_kept_and_shifted
69
+ open_temp("aaa\nbbb\nccc\n")
70
+ act "buf.set_line_and_column_pos(2, 0)"
71
+ keys("i x esc")
72
+ act "buf.save"
73
+ drain_idle
74
+ hist = edit_pos_history.dup
75
+ assert_eq [8], hist
76
+ write_external("top\n" + File.read(@tmp.path) + "end\n")
77
+ revert
78
+ # Shifted by the inserted line, and the external edits are not recorded
79
+ assert_eq [12], edit_pos_history
80
+ assert !vma.buf.unsaved_changes?, "buffer should match disk after reload"
81
+ ensure
82
+ teardown_tmp
83
+ end
84
+
85
+ def test_reload_is_one_undo_step
86
+ open_temp("aaa\nbbb\n")
87
+ write_external("x\naaa\ny\nbbb\nz\n")
88
+ revert
89
+ assert_buf "x\naaa\ny\nbbb\nz\n"
90
+ act "buf.undo"
91
+ assert_buf "aaa\nbbb\n"
92
+ ensure
93
+ teardown_tmp
94
+ end
95
+
96
+ def test_view_top_line_kept
97
+ lines = (0...300).map { |i| "line #{i}\n" }
98
+ open_temp(lines.join)
99
+ view = vma.buf.view
100
+ act "buf.set_line_and_column_pos(103, 0)"
101
+ view.scroll_to_top_pos(vma.buf.to_s.index("line 100\n"))
102
+ drain_idle
103
+ top = view.top_visible_pos
104
+ skip("view has no layout (headless?)") if top.nil? || vma.buf.to_s[top, 9] != "line 100\n"
105
+ nvis = view.visible_line_count
106
+ skip("window too small to show the cursor below the top line") if nvis.nil? || nvis < 10
107
+ write_external((0...10).map { |i| "added #{i}\n" }.join + lines.join)
108
+ revert
109
+ top = view.top_visible_pos
110
+ assert_eq "line 100\n", vma.buf.to_s[top, 9]
111
+ assert_pos(113, 0)
112
+ ensure
113
+ teardown_tmp
114
+ end
115
+
116
+ # Folded buffers can't be diffed against disk; the cursor is kept by line.
117
+ def test_folded_buffer_keeps_line
118
+ open_temp("a\nb\nc\n{{{\nx\n}}}\n")
119
+ act "buf.set_line_and_column_pos(2, 0)"
120
+ write_external("a\nb\nc\n{{{\nx\ny\n}}}\nd\n")
121
+ revert
122
+ assert_eq "a\nb\nc\n{{{\nx\ny\n}}}\nd\n", vma.buf.content_for_disk
123
+ assert_pos(2, 0)
124
+ ensure
125
+ teardown_tmp
126
+ end
127
+ end
@@ -0,0 +1,77 @@
1
+ # buf.run.ruby (run_ruby.rb): the file run with Ruby in a separate process,
2
+ # its output (stdout and stderr in order) in a buffer
3
+ require "tmpdir"
4
+
5
+ class TestRunRuby < VmaTest
6
+ def outputs
7
+ vma.buffers.list.select { |b| b.instance_variable_get(:@ruby_output_of) }
8
+ end
9
+
10
+ # Runs b and returns the output buffer
11
+ def run_and_wait(b)
12
+ before = outputs.map(&:id)
13
+ act "buf.run.ruby"
14
+ t = Time.now
15
+ o = nil
16
+ until (o = outputs.find { |x| !before.include?(x.id) }) || Time.now - t > 20
17
+ drain_idle
18
+ sleep 0.02
19
+ end
20
+ assert o, "no output buffer"
21
+ o
22
+ end
23
+
24
+ def test_runs_file_and_shows_output
25
+ Dir.mktmpdir("vma-run") { |d|
26
+ f = File.join(d, "hello.rb")
27
+ File.write(f, "puts 1 + 1\n$stderr.puts 'to stderr'\nputs File.basename(__FILE__)\n")
28
+ b = open_new_file(f)
29
+ o = run_and_wait(b)
30
+ assert o.to_s.start_with?("# ruby #{f} (exit 0,"), o.to_s.lines.first
31
+ assert o.to_s.include?("2\nto stderr\nhello.rb\n"), o.to_s
32
+ assert vma.buf.equal?(o)
33
+ vma.buffers.close_buffer(o.id)
34
+ vma.buffers.close_buffer(b.id)
35
+ }
36
+ end
37
+
38
+ # Unsaved changes are saved first; a second run replaces the output
39
+ def test_saves_first_and_replaces_output
40
+ Dir.mktmpdir("vma-run") { |d|
41
+ f = File.join(d, "edit.rb")
42
+ File.write(f, "puts :old\n")
43
+ b = open_new_file(f)
44
+ o1 = run_and_wait(b)
45
+ vma.buffers.set_current_buffer_by_id(b.id)
46
+ b.set_pos(0)
47
+ keys "d d"
48
+ keys "i p u t s space : n e w esc"
49
+ o2 = run_and_wait(b)
50
+ assert_eq "puts :new\n", File.read(f), "not saved before running"
51
+ assert o2.to_s.include?("new\n"), o2.to_s
52
+ assert vma.buffers.list.none? { |x| x.equal?(o1) }, "old output buffer still open"
53
+ assert_eq 1, outputs.size
54
+ vma.buffers.close_buffer(o2.id)
55
+ vma.buffers.close_buffer(b.id)
56
+ }
57
+ end
58
+
59
+ # An error: the exit status and the message with its file:line
60
+ def test_error_and_buffer_without_file
61
+ b = create_new_buffer("puts :before\nraise 'boom'\n", "runtest")
62
+ o = run_and_wait(b)
63
+ assert o.to_s.lines.first.include?("exit 1"), o.to_s.lines.first
64
+ assert o.to_s.include?("before\n"), o.to_s
65
+ assert o.to_s =~ /vimamsa-run.*\.rb:2:in .*boom/, o.to_s
66
+ vma.buffers.close_buffer(o.id)
67
+ end
68
+
69
+ # The action search lists id and description in columns of their own
70
+ def test_action_search_columns
71
+ rows = vma.actions.search_actions_update_callback("bufrunruby")
72
+ row = rows.find { |_k, id, _d| id == "buf.run.ruby" }
73
+ assert row, rows.first(3).inspect
74
+ assert_eq 3, row.size
75
+ assert row[2].start_with?("Run the file as Ruby"), row.inspect
76
+ end
77
+ end