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,145 @@
1
+ require "tmpdir"
2
+ require "fileutils"
3
+
4
+ # Covers Buffer#check_autosave_load's decision to prompt vs. silently drop an
5
+ # autosave file (.<name>_vma_autosave) when a file is opened:
6
+ # - autosave identical to the file -> deleted, no prompt
7
+ # - autosave older than the file (stale) -> deleted, no prompt (the fix)
8
+ # - autosave newer than the file -> kept, prompt shown
9
+ #
10
+ # The prompt is a GTK popup; for the "newer" case we stub PopupFormGenerator#run
11
+ # so the test neither blocks nor leaves a window behind, and record whether it
12
+ # would have been shown.
13
+
14
+ class TestAutosave < VmaTest
15
+ # Build a buffer backed by a real temp file, plus an autosave file next to it.
16
+ # Returns [buffer, file_path, autosave_path]. Caller sets mtimes as needed.
17
+ def make_backed_buffer(file_content, autosave_content)
18
+ dir = Dir.mktmpdir("vma_autosave_test")
19
+ @tmpdirs << dir
20
+ path = File.join(dir, "note.txt")
21
+ File.write(path, file_content)
22
+ b = create_new_buffer(file_content, "test", true)
23
+ b.set_filename(path)
24
+ apath = b.autosave_path
25
+ File.write(apath, autosave_content)
26
+ [b, path, apath]
27
+ end
28
+
29
+ def set_older(apath, path)
30
+ now = Time.now
31
+ File.utime(now - 100, now - 100, apath) # autosave older
32
+ File.utime(now, now, path) # file newer
33
+ end
34
+
35
+ def set_newer(apath, path)
36
+ now = Time.now
37
+ File.utime(now, now, apath) # autosave newer
38
+ File.utime(now - 100, now - 100, path) # file older
39
+ end
40
+
41
+ # Run block with PopupFormGenerator#run stubbed out; returns true if a popup
42
+ # would have been shown.
43
+ def popup_shown_during
44
+ $vma_test_popup_shown = false
45
+ orig = PopupFormGenerator.instance_method(:run)
46
+ PopupFormGenerator.send(:define_method, :run) { |*_a| $vma_test_popup_shown = true; self }
47
+ yield
48
+ $vma_test_popup_shown
49
+ ensure
50
+ PopupFormGenerator.send(:define_method, :run, orig)
51
+ end
52
+
53
+ def setup_dirs
54
+ @tmpdirs ||= []
55
+ end
56
+
57
+ def cleanup_dirs
58
+ (@tmpdirs || []).each { |d| FileUtils.remove_entry(d, true) }
59
+ @tmpdirs = []
60
+ end
61
+
62
+ def test_stale_autosave_deleted_silently
63
+ setup_dirs
64
+ b, path, apath = make_backed_buffer("current on disk\n", "stale autosave contents\n")
65
+ set_older(apath, path)
66
+ shown = popup_shown_during { b.check_autosave_load }
67
+ assert(!File.exist?(apath), "stale autosave should be deleted")
68
+ assert(!shown, "no prompt should be shown for a stale autosave")
69
+ ensure
70
+ cleanup_dirs
71
+ end
72
+
73
+ def test_identical_autosave_deleted_silently
74
+ setup_dirs
75
+ b, path, apath = make_backed_buffer("hello world\n", "hello world\n")
76
+ # mtimes irrelevant here; identical content is dropped regardless.
77
+ set_newer(apath, path)
78
+ shown = popup_shown_during { b.check_autosave_load }
79
+ assert(!File.exist?(apath), "autosave identical to file should be deleted")
80
+ assert(!shown, "no prompt should be shown when autosave equals the file")
81
+ ensure
82
+ cleanup_dirs
83
+ end
84
+
85
+ def test_newer_autosave_kept_and_prompts
86
+ setup_dirs
87
+ b, path, apath = make_backed_buffer("saved version\n", "newer unsaved edits\n")
88
+ set_newer(apath, path)
89
+ shown = popup_shown_during { b.check_autosave_load }
90
+ assert(File.exist?(apath), "a newer autosave must not be deleted")
91
+ assert(shown, "a newer, differing autosave should prompt")
92
+ ensure
93
+ cleanup_dirs
94
+ end
95
+
96
+ # ── Deferred check for session-restored buffers ──────────────────────────
97
+ # Session restore loads buffers without running check_autosave_load; the
98
+ # check is deferred (needs_autosave_check) until the buffer is first entered
99
+ # via set_current_buffer.
100
+
101
+ # Enter another buffer, then switch (back) to `b` — the "enter buffer" path.
102
+ def enter_buffer(b)
103
+ create_new_buffer("\n", "decoy", true) # move current buffer away from b
104
+ vma.buffers.set_current_buffer_by_id(b.id)
105
+ end
106
+
107
+ def test_restored_newer_autosave_prompts_on_enter
108
+ setup_dirs
109
+ b, path, apath = make_backed_buffer("saved version\n", "newer unsaved edits\n")
110
+ set_newer(apath, path)
111
+ b.needs_autosave_check = true
112
+ shown = popup_shown_during { enter_buffer(b) }
113
+ assert(shown, "restored buffer should prompt when first entered")
114
+ assert(File.exist?(apath), "newer autosave must be kept")
115
+ assert(!b.needs_autosave_check, "pending flag should be cleared after entering")
116
+ ensure
117
+ cleanup_dirs
118
+ end
119
+
120
+ def test_restored_stale_autosave_deleted_on_enter
121
+ setup_dirs
122
+ b, path, apath = make_backed_buffer("current on disk\n", "stale autosave\n")
123
+ set_older(apath, path)
124
+ b.needs_autosave_check = true
125
+ shown = popup_shown_during { enter_buffer(b) }
126
+ assert(!shown, "stale autosave should not prompt on enter")
127
+ assert(!File.exist?(apath), "stale autosave should be deleted on enter")
128
+ assert(!b.needs_autosave_check, "pending flag should be cleared after entering")
129
+ ensure
130
+ cleanup_dirs
131
+ end
132
+
133
+ def test_unflagged_buffer_not_checked_on_enter
134
+ setup_dirs
135
+ # No needs_autosave_check flag (a normal, non-restored buffer): entering it
136
+ # must not run the autosave check, even with a newer differing autosave.
137
+ b, path, apath = make_backed_buffer("saved version\n", "newer unsaved edits\n")
138
+ set_newer(apath, path)
139
+ shown = popup_shown_during { enter_buffer(b) }
140
+ assert(!shown, "unflagged buffer must not prompt on enter")
141
+ assert(File.exist?(apath), "unflagged buffer must not touch the autosave")
142
+ ensure
143
+ cleanup_dirs
144
+ end
145
+ end
@@ -1,5 +1,4 @@
1
1
  class TestBasicEditing < VmaTest
2
-
3
2
  def test_insert_text
4
3
  act 'buf.insert_txt("hello")'
5
4
  assert_buf "hello\n"
@@ -7,9 +6,9 @@ class TestBasicEditing < VmaTest
7
6
 
8
7
  def test_delete_char_forward
9
8
  act 'buf.insert_txt("abcde")'
10
- act :jump_to_start_of_buffer
11
- act :delete_char_forward
12
- act :delete_char_forward
9
+ act "move.buf.start"
10
+ act "edit.delete.char"
11
+ act "edit.delete.char"
13
12
  assert_buf "cde\n"
14
13
  end
15
14
 
@@ -20,12 +19,22 @@ class TestBasicEditing < VmaTest
20
19
  assert_buf "abc\n"
21
20
  end
22
21
 
22
+ def test_select_all_action
23
+ act 'buf.insert_txt("hello\nworld")'
24
+ act "sel.all"
25
+ assert vma.buf.selection_active?, "select_all should activate selection"
26
+ assert_eq 0, vma.buf.get_visual_mode_range.begin
27
+ assert_eq vma.buf.size - 1, vma.buf.get_visual_mode_range.end
28
+ act "sel.copy"
29
+ assert_eq "hello\nworld\n", vma.clipboard.get
30
+ end
31
+
23
32
  def test_undo_redo
24
33
  act 'buf.insert_txt("hello")'
25
34
  assert_buf "hello\n"
26
- act :undo
35
+ act "undo.last"
27
36
  assert_buf "\n"
28
- act :redo
37
+ act "undo.redo"
29
38
  assert_buf "hello\n"
30
39
  end
31
40
 
@@ -38,34 +47,32 @@ class TestBasicEditing < VmaTest
38
47
 
39
48
  def test_jump_start_end
40
49
  act 'buf.insert_txt("hello")'
41
- act :jump_to_start_of_buffer
50
+ act "move.buf.start"
42
51
  assert_pos 0, 0
43
- act :jump_to_end_of_buffer
52
+ act "move.buf.end"
44
53
  assert_pos 0, 5
45
54
  end
46
55
 
47
56
  def test_copy_paste
48
57
  #Note: Buffer contains a single "\n" by default
49
58
  act 'buf.insert_txt("hello\n")'
50
- act :jump_to_start_of_buffer
51
- act :copy_cur_line
52
- act :jump_to_end_of_buffer
53
- act :paste_after_cursor
59
+ act "move.buf.start"
60
+ act "edit.line.copy"
61
+ act "move.buf.end"
62
+ act "edit.paste.after"
54
63
  assert_buf "hello\n\nhello\n"
55
64
  end
56
65
 
57
66
  def test_delete_line
58
67
  act 'buf.insert_txt("first\n")'
59
68
  act 'buf.insert_txt("second")'
60
- act :jump_to_start_of_buffer
61
- act :delete_line
69
+ act "move.buf.start"
70
+ act "edit.delete.line"
62
71
  assert_buf "second\n"
63
72
  end
64
-
65
73
  end
66
74
 
67
75
  class TestKeySequences < VmaTest
68
-
69
76
  def test_insert_mode_via_keys
70
77
  # 'i' enters insert mode in command mode
71
78
  keys "i"
@@ -82,5 +89,28 @@ class TestKeySequences < VmaTest
82
89
  assert_buf "hello\n"
83
90
  assert_mode :command
84
91
  end
92
+ end
85
93
 
94
+ class TestDeleteFindChar < VmaTest
95
+ def test_df_char
96
+ act 'buf.insert_txt("foo bar baz")'
97
+ act "move.buf.start"
98
+ keys "d f a"
99
+ assert_buf "r baz\n"
100
+ end
101
+
102
+ def test_dF_char
103
+ act 'buf.insert_txt("foo bar baz")'
104
+ act "move.buf.start"
105
+ act "buf.set_pos(10)" # on the final 'z'
106
+ keys "d F a"
107
+ assert_buf "foo bar bz\n"
108
+ end
109
+
110
+ def test_df_not_on_line_is_noop
111
+ act 'buf.insert_txt("foo\nbar")'
112
+ act "move.buf.start"
113
+ keys "d f b"
114
+ assert_buf "foo\nbar\n"
115
+ end
86
116
  end
@@ -0,0 +1,206 @@
1
+ require "tempfile"
2
+
3
+ # Persistent bookmarks (lib/vimamsa/bookmarks.rb): , M to add, , ' to list.
4
+ class TestBookmarks < VmaTest
5
+ SAMPLE = (1..10).collect { |i| "line #{i}\n" }.join # "line 1" .. "line 10"
6
+
7
+ def make_file(contents)
8
+ f = Tempfile.new(["bookmark_target", ".txt"])
9
+ f.write(contents)
10
+ f.flush
11
+ f
12
+ end
13
+
14
+ def cleanup(f)
15
+ path = File.expand_path(f.path)
16
+ vma.bookmarks.list.select { |bm| bm[:fname] == path }.each { |bm| vma.bookmarks.delete(bm) }
17
+ close_file(path)
18
+ f.close
19
+ f.unlink
20
+ end
21
+
22
+ def close_file(path)
23
+ id = vma.buffers.get_buffer_by_filename(path)
24
+ vma.buffers.close_buffer(id) if id
25
+ drain_idle
26
+ end
27
+
28
+ # lpos is 0-based
29
+ def add_at(path, lpos)
30
+ jump_to_file(path, lpos + 1)
31
+ assert_eq lpos, vma.buf.lpos
32
+ act("mark.add")
33
+ bm = vma.bookmarks.list.find { |b| b[:fname] == path && b[:lpos] == lpos }
34
+ assert bm, "bookmark was not added at line #{lpos}"
35
+ bm
36
+ end
37
+
38
+ def test_add_and_jump
39
+ f = make_file(SAMPLE)
40
+ path = File.expand_path(f.path)
41
+ bm = add_at(path, 4)
42
+ assert_eq "line 5", bm[:text]
43
+ assert_eq "line 4", bm[:before]
44
+ assert_eq "line 6", bm[:after]
45
+
46
+ create_new_buffer("\n", "other", true)
47
+ assert vma.bookmarks.jump(bm), "jump failed"
48
+ assert_eq path, vma.buf.fname
49
+ assert_eq 4, vma.buf.lpos
50
+ ensure
51
+ cleanup(f)
52
+ end
53
+
54
+ def test_keys_add_bookmark
55
+ f = make_file(SAMPLE)
56
+ path = File.expand_path(f.path)
57
+ jump_to_file(path, 3)
58
+ keys(", M")
59
+ bm = vma.bookmarks.list.find { |b| b[:fname] == path }
60
+ assert bm, ", M did not add a bookmark"
61
+ assert_eq 2, bm[:lpos]
62
+ ensure
63
+ cleanup(f)
64
+ end
65
+
66
+ def test_same_line_replaces
67
+ f = make_file(SAMPLE)
68
+ path = File.expand_path(f.path)
69
+ add_at(path, 4)
70
+ add_at(path, 4)
71
+ assert_eq 1, vma.bookmarks.list.count { |b| b[:fname] == path }
72
+ ensure
73
+ cleanup(f)
74
+ end
75
+
76
+ # File changed outside the editor: the line moved, found again by its text
77
+ def test_regexp_recovery_after_external_change
78
+ f = make_file(SAMPLE)
79
+ path = File.expand_path(f.path)
80
+ bm = add_at(path, 4)
81
+ close_file(path)
82
+ File.write(path, "new a\nnew b\nnew c\n" + SAMPLE)
83
+
84
+ assert vma.bookmarks.jump(bm), "jump failed"
85
+ assert_eq 7, vma.buf.lpos
86
+ assert_eq 7, bm[:lpos], "stored line should be updated after jump"
87
+ ensure
88
+ cleanup(f)
89
+ end
90
+
91
+ def test_whitespace_changes_still_match
92
+ f = make_file("a\nfoo(x, y)\nb\n")
93
+ path = File.expand_path(f.path)
94
+ bm = add_at(path, 1)
95
+ close_file(path)
96
+ File.write(path, "z\nz\na\n foo(x, y)\nb\n")
97
+
98
+ vma.bookmarks.jump(bm)
99
+ assert_eq 3, vma.buf.lpos
100
+ ensure
101
+ cleanup(f)
102
+ end
103
+
104
+ # Two identical lines: the one with matching context wins even when the
105
+ # other one is at the stored line number.
106
+ def test_duplicate_lines_use_context
107
+ f = make_file("def a\n x = 1\nend\ndef b\n y = 2\nend\n")
108
+ path = File.expand_path(f.path)
109
+ bm = add_at(path, 5) # "end" after "y = 2"
110
+ close_file(path)
111
+ File.write(path, "def b\n y = 2\nend\ndef a\n x = 1\nend\n")
112
+
113
+ vma.bookmarks.jump(bm)
114
+ assert_eq 2, vma.buf.lpos
115
+ ensure
116
+ cleanup(f)
117
+ end
118
+
119
+ def test_text_deleted_falls_back_to_line_number
120
+ f = make_file(SAMPLE)
121
+ path = File.expand_path(f.path)
122
+ bm = add_at(path, 8)
123
+ close_file(path)
124
+ File.write(path, "a\nb\nc\n")
125
+
126
+ assert vma.bookmarks.jump(bm), "jump failed"
127
+ assert_eq 2, vma.buf.lpos # clamped to last line
128
+ assert_eq "line 9", bm[:text], "stored text must not be overwritten"
129
+ ensure
130
+ cleanup(f)
131
+ end
132
+
133
+ def test_persisted_to_disk
134
+ f = make_file(SAMPLE)
135
+ path = File.expand_path(f.path)
136
+ bm = add_at(path, 2)
137
+ stored = vma.marshal_load("bookmarks", [])
138
+ assert stored.any? { |b| b[:fname] == path && b[:text] == "line 3" }, "bookmark not saved to disk"
139
+
140
+ vma.bookmarks.delete(bm)
141
+ stored = vma.marshal_load("bookmarks", [])
142
+ assert !stored.any? { |b| b[:fname] == path }, "deleted bookmark still on disk"
143
+ ensure
144
+ cleanup(f)
145
+ end
146
+
147
+ # Edits in an open buffer move the bookmark; saving stores the new line.
148
+ def test_tracked_while_open_and_saved
149
+ f = make_file(SAMPLE)
150
+ path = File.expand_path(f.path)
151
+ bm = add_at(path, 4)
152
+ vma.buf.set_pos(0)
153
+ act('buf.insert_txt("new1\nnew2\n")')
154
+ vma.buf.save
155
+ drain_idle
156
+
157
+ assert_eq 6, bm[:lpos]
158
+ assert_eq "line 5", bm[:text]
159
+ assert_eq "line 4", bm[:before]
160
+ assert File.read(path).start_with?("new1\nnew2\n"), "file was not saved"
161
+ ensure
162
+ cleanup(f)
163
+ end
164
+
165
+ def test_list_newest_first_and_select
166
+ f = make_file(SAMPLE)
167
+ path = File.expand_path(f.path)
168
+ b1 = add_at(path, 0)
169
+ b3 = add_at(path, 2)
170
+ b5 = add_at(path, 4)
171
+ b1[:created] = Time.now - 300
172
+ b3[:created] = Time.now - 200
173
+ b5[:created] = Time.now - 100
174
+
175
+ act("mark.list")
176
+ assert_mode :bmark
177
+ list_id = vma.buf.id
178
+ rows = vma.buf.to_s.lines.select { |l| l.include?(tilde_path(path)) }.collect(&:strip)
179
+ assert_eq ["line 5", "line 3", "line 1"], rows.collect { |r| r.split(" ").last }
180
+
181
+ act("bmark.select") # cursor starts on the first (newest) row
182
+ assert_eq path, vma.buf.fname
183
+ assert_eq 4, vma.buf.lpos
184
+ assert vma.buffers.get_buffer_by_id(list_id).nil?, "list buffer should be closed"
185
+ assert_mode vma.kbd.default_mode
186
+ ensure
187
+ cleanup(f)
188
+ end
189
+
190
+ def test_list_delete
191
+ f = make_file(SAMPLE)
192
+ path = File.expand_path(f.path)
193
+ add_at(path, 1)
194
+ bm = add_at(path, 6) # newest -> first row
195
+
196
+ act("mark.list")
197
+ act("bmark.delete")
198
+ assert !vma.bookmarks.list.include?(bm), "bookmark not deleted"
199
+ assert_eq 1, vma.bookmarks.list.count { |b| b[:fname] == path }
200
+ rows = vma.buf.to_s.lines.select { |l| l.include?(tilde_path(path)) }
201
+ assert_eq 1, rows.size
202
+ act("buf.close")
203
+ ensure
204
+ cleanup(f)
205
+ end
206
+ end
@@ -0,0 +1,88 @@
1
+ # With the cursor on a bracket, GtkSourceView highlights its matching bracket
2
+ # (buffer.highlight_matching_brackets, set in gui_create_buffer, styled by the
3
+ # scheme's "bracket-match" style).
4
+ class TestBracketMatch < VmaTest
5
+ TEXT = "foo(bar[1], {a: 2}) x\n"
6
+
7
+ # GtkSourceView updates the bracket highlight from a low-priority main loop
8
+ # source, so give the loop real time rather than a fixed iteration count.
9
+ def wait_main_loop(sec = 0.3)
10
+ t = Time.now
11
+ GLib::MainContext.default.iteration(false) while Time.now - t < sec
12
+ end
13
+
14
+ # Put text in the current buffer, move the cursor to pos and return
15
+ # [matched_offset, state] from the last "bracket-matched" signal, state as
16
+ # :found, :not_found, :out_of_range or :none. nil if no signal came.
17
+ def match_at(pos, text = TEXT)
18
+ # Broadway (--headless without xvfb) draws nothing while no browser is
19
+ # connected, so GtkSourceView never updates the highlight
20
+ skip "no drawing on the Broadway backend" if ENV["VMA_HEADLESS"] == "broadway"
21
+ b = vma.buf
22
+ b.set_content(text)
23
+ drain_idle
24
+ gbuf = b.view.buffer
25
+ # Start from a non-bracket position so moving to pos is a real change
26
+ b.set_pos(text.index(" ") || 0)
27
+ wait_main_loop
28
+ got = nil
29
+ hid = gbuf.signal_connect("bracket-matched") do |_buf, iter, state|
30
+ got = [state.nick.tr("-", "_").to_sym == :found ? iter.offset : nil, state.nick.tr("-", "_").to_sym]
31
+ end
32
+ begin
33
+ b.set_pos(pos)
34
+ wait_main_loop
35
+ ensure
36
+ gbuf.signal_handler_disconnect(hid)
37
+ end
38
+ got
39
+ end
40
+
41
+ # Tags at offset that paint a background (the bracket-match highlight)
42
+ def highlight_tags_at(offset)
43
+ gbuf = vma.buf.view.buffer
44
+ gbuf.get_iter_at(:offset => offset).tags.select { |t| t.background_set? }
45
+ end
46
+
47
+ def test_enabled_on_gtk_buffer
48
+ assert vma.buf.view.buffer.highlight_matching_brackets?, "highlight_matching_brackets is off"
49
+ end
50
+
51
+ def test_scheme_defines_bracket_match_style
52
+ sty = vma.buf.view.buffer.style_scheme
53
+ assert !sty.nil?, "no style scheme"
54
+ assert !sty.get_style("bracket-match").nil?, "scheme #{sty.id} has no bracket-match style"
55
+ end
56
+
57
+ def test_open_paren_matches_close
58
+ assert_eq [TEXT.index(")"), :found], match_at(TEXT.index("("))
59
+ assert !highlight_tags_at(TEXT.index(")")).empty?, "closing ) not highlighted"
60
+ end
61
+
62
+ def test_close_paren_matches_open
63
+ assert_eq [TEXT.index("("), :found], match_at(TEXT.index(")"))
64
+ assert !highlight_tags_at(TEXT.index("(")).empty?, "opening ( not highlighted"
65
+ end
66
+
67
+ def test_square_and_curly
68
+ assert_eq [TEXT.index("]"), :found], match_at(TEXT.index("["))
69
+ assert_eq [TEXT.index("}"), :found], match_at(TEXT.index("{"))
70
+ end
71
+
72
+ def test_nested_matches_outer
73
+ t = "((a)(b)) z\n"
74
+ assert_eq [7, :found], match_at(0, t)
75
+ assert_eq [3, :found], match_at(1, t)
76
+ end
77
+
78
+ def test_unbalanced_is_not_found
79
+ assert_eq [nil, :not_found], match_at(0, "(abc def\n")
80
+ end
81
+
82
+ def test_highlight_cleared_when_cursor_leaves
83
+ assert_eq [TEXT.index(")"), :found], match_at(TEXT.index("("))
84
+ vma.buf.set_pos(TEXT.index("x"))
85
+ wait_main_loop
86
+ assert highlight_tags_at(TEXT.index(")")).empty?, ") still highlighted with cursor away"
87
+ end
88
+ end
@@ -0,0 +1,92 @@
1
+ require "tmpdir"
2
+ require "open3"
3
+
4
+ # Code changes for running from a bundle (doc/bundling_plan.md, "Code changes
5
+ # needed regardless of format").
6
+ class TestBundling < VmaTest
7
+ def with_env(name, val)
8
+ old = ENV[name]
9
+ ENV[name] = val
10
+ yield
11
+ ensure
12
+ ENV[name] = old
13
+ end
14
+
15
+ def test_launcher_runs_gem_binstub_by_default
16
+ with_env("APPIMAGE", nil) {
17
+ assert_eq "vimamsa %F", desktop_exec_command
18
+ assert desktop_entry_contents.include?("\nExec=vimamsa %F\n")
19
+ }
20
+ end
21
+
22
+ def test_launcher_runs_the_appimage
23
+ with_env("APPIMAGE", "/home/u/Apps/Vimamsa-x86_64.AppImage") {
24
+ assert_eq %{"/home/u/Apps/Vimamsa-x86_64.AppImage" %F}, desktop_exec_command
25
+ }
26
+ end
27
+
28
+ def test_launcher_quotes_odd_appimage_paths
29
+ # Spaces stay inside the quotes; " ` $ \ are escaped, % is doubled
30
+ with_env("APPIMAGE", %{/home/u/My Apps/a"b$c%d\\e.AppImage}) {
31
+ assert_eq %{"/home/u/My Apps/a\\\\"b\\\\$c%%d\\\\\\\\e.AppImage" %F}, desktop_exec_command
32
+ }
33
+ end
34
+
35
+ # exe/vimamsa must load lib/ next to itself, not ./lib of the current dir
36
+ def test_exe_load_path_is_relative_to_script
37
+ exe = File.expand_path("../exe/vimamsa", __dir__)
38
+ src = File.read(exe)
39
+ assert !src.include?('File.expand_path("lib")'), "exe/vimamsa uses ./lib of the current directory"
40
+ Dir.mktmpdir { |dir|
41
+ # A decoy lib/vimamsa.rb in the current directory must not be loaded
42
+ Dir.mkdir("#{dir}/lib")
43
+ File.write("#{dir}/lib/vimamsa.rb", "puts 'DECOY'; exit 3\n")
44
+ code = src[/\A.*?\$LOAD_PATH\.unshift\(File\.join\(scriptdir, "ext"\)\)\n/m]
45
+ assert code, "load path lines not found in exe/vimamsa"
46
+ code = code.sub(/^require "ripl\/multi_line"\n/, "")
47
+ script = "#{dir}/probe.rb"
48
+ File.write(script, code.sub("selfpath = __FILE__", "selfpath = #{exe.inspect}") +
49
+ "puts $LOAD_PATH.first(2)\n")
50
+ out, st = Open3.capture2e(RbConfig.ruby, script, chdir: dir)
51
+ assert st.success?, out
52
+ root = File.expand_path("..", __dir__)
53
+ assert_eq ["#{root}/ext", "#{root}/lib"], out.split("\n").last(2)
54
+ }
55
+ end
56
+
57
+ # ── restore_host_env (lib/vimamsa/appimage_env.rb) ──
58
+
59
+ def test_restore_host_env_puts_back_previous_values
60
+ saved = ENV.to_h
61
+ ENV["VMA_APPIMAGE_ENV"] = " VMA_T_SET VMA_T_UNSET"
62
+ ENV["VMA_HOST_VMA_T_SET"] = "host value"
63
+ ENV["VMA_T_SET"] = "bundle value"
64
+ ENV["VMA_T_UNSET"] = "bundle value"
65
+ restore_host_env
66
+ assert_eq "host value", ENV["VMA_T_SET"]
67
+ assert !ENV.key?("VMA_T_UNSET"), "a variable the host didn't have must be removed"
68
+ assert !ENV.key?("VMA_HOST_VMA_T_SET") && !ENV.key?("VMA_APPIMAGE_ENV")
69
+ out = IO.popen(["sh", "-c", "echo \"$VMA_T_SET|${VMA_T_UNSET-unset}\""], &:read)
70
+ assert_eq "host value|unset\n", out
71
+ ensure
72
+ ENV.replace(saved)
73
+ end
74
+
75
+ # Only from the AppImage (AppRun exports APPDIR)
76
+ def test_appimage_children_get_host_environment
77
+ appdir = ENV["APPDIR"]
78
+ skip "not running from the AppImage" if appdir.nil?
79
+ ok = %w[PATH APPDIR APPIMAGE ARGV0 OWD]
80
+ leaked = ENV.reject { |k, v| ok.include?(k) || !v.include?(appdir) }
81
+ assert leaked.empty?, "still pointing into the AppImage: #{leaked.keys.join(", ")}"
82
+ # What the restore must not break: things loaded on first use
83
+ require "vte4"
84
+ assert Vte::Terminal.new
85
+ assert Gst::ElementFactory.make("playbin"), "playbin (bundled GStreamer plugins)"
86
+ png = Dir.glob("#{appdir}/usr/share/icons/hicolor/**/*.png").first || "#{appdir}/vimamsa.png"
87
+ assert GdkPixbuf::Pixbuf.new(file: png)
88
+ # The bundled ruby-lsp still runs (its wrapper drops the user's GEM_HOME)
89
+ out = IO.popen(["ruby-lsp", "--version"], err: [:child, :out], &:read)
90
+ assert out =~ /\d+\.\d+/, "ruby-lsp --version: #{out}"
91
+ end
92
+ end