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
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
data/tests/test_undo.rb CHANGED
@@ -4,47 +4,47 @@ class TestUndo < VmaTest
4
4
 
5
5
  def test_undo_restores_empty_buffer
6
6
  act 'buf.insert_txt("hello")'
7
- act :undo
7
+ act "undo.last"
8
8
  assert_buf "\n"
9
9
  end
10
10
 
11
11
  def test_undo_on_empty_buffer_is_noop
12
- act :undo
12
+ act "undo.last"
13
13
  assert_buf "\n"
14
14
  end
15
15
 
16
16
  def test_redo_after_undo
17
17
  act 'buf.insert_txt("hello")'
18
- act :undo
19
- act :redo
18
+ act "undo.last"
19
+ act "undo.redo"
20
20
  assert_buf "hello\n"
21
21
  end
22
22
 
23
23
  def test_redo_on_empty_stack_is_noop
24
- act :undo
25
- act :redo
24
+ act "undo.last"
25
+ act "undo.redo"
26
26
  assert_buf "\n"
27
27
  end
28
28
 
29
29
  def test_new_edit_clears_redo_stack
30
30
  act 'buf.insert_txt("hello")'
31
- act :undo
31
+ act "undo.last"
32
32
  assert_buf "\n"
33
33
  act 'buf.insert_txt("world")'
34
34
  # redo stack was cleared — redo should be a no-op
35
- act :redo
35
+ act "undo.redo"
36
36
  assert_buf "world\n"
37
37
  end
38
38
 
39
39
  def test_undo_delete_char
40
40
  act 'buf.insert_txt("abcde")'
41
- act :jump_to_start_of_buffer
41
+ act "move.buf.start"
42
42
  vma.buf.new_undo_group
43
- act :delete_char_forward
44
- act :delete_char_forward
43
+ act "edit.delete.char"
44
+ act "edit.delete.char"
45
45
  vma.buf.new_undo_group
46
46
  assert_buf "cde\n"
47
- act :undo
47
+ act "undo.last"
48
48
  assert_buf "abcde\n"
49
49
  end
50
50
 
@@ -52,11 +52,11 @@ class TestUndo < VmaTest
52
52
  act 'buf.insert_txt("first\n")'
53
53
  act 'buf.insert_txt("second")'
54
54
  vma.buf.new_undo_group
55
- act :jump_to_start_of_buffer
56
- act :delete_line
55
+ act "move.buf.start"
56
+ act "edit.delete.line"
57
57
  vma.buf.new_undo_group
58
58
  assert_buf "second\n"
59
- act :undo
59
+ act "undo.last"
60
60
  assert_buf "first\nsecond\n"
61
61
  end
62
62
 
@@ -66,13 +66,13 @@ class TestUndo < VmaTest
66
66
  act 'buf.insert_txt(" second")'
67
67
  assert_buf "first second\n"
68
68
 
69
- act :undo
69
+ act "undo.last"
70
70
  assert_buf "first\n"
71
- act :redo
71
+ act "undo.redo"
72
72
  assert_buf "first second\n"
73
- act :undo
73
+ act "undo.last"
74
74
  assert_buf "first\n"
75
- act :undo
75
+ act "undo.last"
76
76
  assert_buf "\n"
77
77
  end
78
78
 
@@ -87,11 +87,11 @@ class TestUndo < VmaTest
87
87
  vma.buf.new_undo_group
88
88
  assert_buf "aaabbbccc\n"
89
89
 
90
- act :undo
90
+ act "undo.last"
91
91
  assert_buf "aaabbb\n"
92
- act :undo
92
+ act "undo.last"
93
93
  assert_buf "aaa\n"
94
- act :undo
94
+ act "undo.last"
95
95
  assert_buf "\n"
96
96
  end
97
97
 
@@ -103,9 +103,9 @@ class TestUndo < VmaTest
103
103
  keys "i space w o r l d esc"
104
104
  assert_buf "hello world\n"
105
105
 
106
- act :undo
106
+ act "undo.last"
107
107
  assert_buf "hello\n" # second insert session (" world") undone
108
- act :undo
108
+ act "undo.last"
109
109
  assert_buf "\n" # first insert session ("hello") undone
110
110
  end
111
111
 
@@ -121,7 +121,7 @@ class TestUndo < VmaTest
121
121
  drain_idle
122
122
  assert_buf "line1\nline2\nline3\n"
123
123
 
124
- act :undo
124
+ act "undo.last"
125
125
  assert_buf "\n"
126
126
  end
127
127
 
@@ -133,9 +133,9 @@ class TestUndo < VmaTest
133
133
  drain_idle
134
134
  assert_buf "abcdef\n"
135
135
 
136
- act :undo
136
+ act "undo.last"
137
137
  assert_buf "abc\n"
138
- act :undo
138
+ act "undo.last"
139
139
  assert_buf "\n"
140
140
  end
141
141
 
@@ -147,9 +147,9 @@ class TestUndo < VmaTest
147
147
  drain_idle
148
148
  assert_buf "base appended\n"
149
149
 
150
- act :undo
150
+ act "undo.last"
151
151
  assert_buf "base\n"
152
- act :undo
152
+ act "undo.last"
153
153
  assert_buf "\n"
154
154
  end
155
155
 
@@ -165,9 +165,9 @@ class TestUndo < VmaTest
165
165
  drain_idle
166
166
  assert_buf "foofoo\n"
167
167
 
168
- act :undo # undo the macro run
168
+ act "undo.last" # undo the macro run
169
169
  assert_buf "foo\n"
170
- act :undo # undo the recording-time insertion
170
+ act "undo.last" # undo the recording-time insertion
171
171
  assert_buf "\n"
172
172
  end
173
173
 
@@ -176,9 +176,9 @@ class TestUndo < VmaTest
176
176
  drain_idle
177
177
  assert_buf "hello\n"
178
178
 
179
- act :undo
179
+ act "undo.last"
180
180
  assert_buf "\n"
181
- act :redo
181
+ act "undo.redo"
182
182
  assert_buf "hello\n"
183
183
  end
184
184
 
@@ -194,7 +194,7 @@ class TestUndo < VmaTest
194
194
  drain_idle
195
195
  assert_buf " world\n"
196
196
 
197
- act :undo
197
+ act "undo.last"
198
198
  assert_buf "hello world\n"
199
199
  end
200
200
 
@@ -0,0 +1,122 @@
1
+ # Config dir and data dir (user_dirs.rb): the XDG defaults, --user-dir
2
+ # keeping both in one dir, which files go where, and the one-time move of
3
+ # the files of older versions
4
+ require "tmpdir"
5
+
6
+ class TestUserDirs < VmaTest
7
+ REPO = File.expand_path("..", __dir__)
8
+
9
+ def with_env(vars)
10
+ old = vars.keys.to_h { |k| [k, ENV[k]] }
11
+ vars.each { |k, v| ENV[k] = v }
12
+ yield
13
+ ensure
14
+ old.each { |k, v| ENV[k] = v }
15
+ end
16
+
17
+ def test_xdg_defaults
18
+ with_env("XDG_CONFIG_HOME" => nil, "XDG_DATA_HOME" => nil) {
19
+ assert_eq File.expand_path("~/.config/vimamsa"), UserDirs.default_config_dir
20
+ assert_eq File.expand_path("~/.local/share/vimamsa"), UserDirs.default_data_dir
21
+ assert_eq File.expand_path("~/.local/share/vimamsa"), UserDirs.data_dir_for("~/.config/vimamsa")
22
+ }
23
+ with_env("XDG_CONFIG_HOME" => "/tmp/xc", "XDG_DATA_HOME" => "/tmp/xd") {
24
+ assert_eq "/tmp/xc/vimamsa", UserDirs.default_config_dir
25
+ assert_eq "/tmp/xd/vimamsa", UserDirs.data_dir_for("/tmp/xc/vimamsa")
26
+ }
27
+ # --user-dir: data in the same dir
28
+ assert_eq "/tmp/somedir", UserDirs.data_dir_for("/tmp/somedir")
29
+ end
30
+
31
+ # The test run uses its own user dir, and data goes there too
32
+ def test_test_run_isolated
33
+ assert !UserDirs.default_config_dir?(vma_user_dir)
34
+ assert_eq File.expand_path(vma_user_dir), File.expand_path(vma_data_dir)
35
+ end
36
+
37
+ # With separate dirs, generated files go to the data dir and the user's
38
+ # files to the config dir
39
+ def test_files_go_to_their_dirs
40
+ Dir.mktmpdir { |d|
41
+ old = $vma_data_dir
42
+ $vma_data_dir = d
43
+ begin
44
+ vma.marshal_save("file_index", [])
45
+ assert File.exist?(File.join(d, "file_index")), "file_index not in the data dir"
46
+ assert_eq File.join(d, "file_history"), vma.var_file_path("file_history")
47
+ assert_eq get_dot_path("bookmarks"), vma.var_file_path("bookmarks")
48
+ assert_eq get_dot_path("named_macros"), vma.var_file_path("named_macros")
49
+ vma.save_session
50
+ assert File.exist?(File.join(d, "session.txt")), "session not in the data dir"
51
+ assert_eq File.join(d, "crash"), Vimamsa::CrashHandler.crash_dir
52
+ f = File.join(d, "afile.txt")
53
+ File.write(f, "x\n")
54
+ jump_to_file(f)
55
+ b = vma.buf
56
+ assert_eq f, b.fname
57
+ b.backup # written on a thread
58
+ t = Time.now
59
+ sleep 0.02 while Dir[File.join(d, "backup", "*afile.txt_*")].empty? && Time.now - t < 2
60
+ assert Dir[File.join(d, "backup", "*afile.txt_*")].any?, "backup not in the data dir"
61
+ vma.buffers.close_buffer(b.id)
62
+ ensure
63
+ $vma_data_dir = old
64
+ end
65
+ }
66
+ end
67
+
68
+ # No code uses fixed paths (~/.vimamsa, ~/.config/vimamsa): they would
69
+ # skip --user-dir, and the tests would touch the real user's files.
70
+ # user_dirs.rb names the old places, to move their files.
71
+ def test_no_fixed_user_paths
72
+ files = Dir[File.join(REPO, "{lib,modules}/**/*.rb")] + [File.join(REPO, "exe/vimamsa")]
73
+ files -= [File.join(REPO, "lib/vimamsa/user_dirs.rb")]
74
+ bad = files.flat_map { |f|
75
+ File.readlines(f).each_with_index.map { |l, i|
76
+ next if l.strip.start_with?("#")
77
+ "#{f.sub(REPO + "/", "")}:#{i + 1}: #{l.strip}" if l =~ %r{["']~/\.(vimamsa|config/vimamsa|config/\.vimamsa)}
78
+ }.compact
79
+ }
80
+ assert bad.empty?, "fixed user paths:\n#{bad.join("\n")}"
81
+ end
82
+
83
+ def test_migrate
84
+ Dir.mktmpdir { |t|
85
+ conf, data = File.join(t, "conf"), File.join(t, "data")
86
+ legacy, lmacro = File.join(t, "legacy"), File.join(t, "lmacro")
87
+ w = ->(path, txt = "x") { FileUtils.mkdir_p(File.dirname(path)); File.write(path, txt) }
88
+ w.(File.join(conf, "session.txt"), "s")
89
+ w.(File.join(conf, "file_history"))
90
+ w.(File.join(conf, "bookmarks"))
91
+ w.(File.join(conf, "settings.rb"))
92
+ w.(File.join(conf, "backup", "a_1"))
93
+ w.(File.join(conf, "crash", "stderr.log"), "old log")
94
+ FileUtils.mkdir_p(File.join(conf, "listen"))
95
+ w.(File.join(data, "crash", "stderr.log"), "new log") # written at start, before the move
96
+ w.(File.join(legacy, "cmd_history.txt"), ":e x")
97
+ w.(File.join(legacy, "backup", "c_1"))
98
+ w.(File.join(legacy, "backup", "a_1"), "older a")
99
+ w.(File.join(legacy, "file_history"), "older")
100
+ w.(File.join(lmacro, "macro_q.rb"), "macro")
101
+ moved = UserDirs.migrate(config_dir: conf, data_dir: data, legacy_dir: legacy, legacy_macro_dir: lmacro)
102
+ %w[session.txt file_history cmd_history.txt backup/a_1 backup/c_1].each { |n|
103
+ assert File.exist?(File.join(data, n)), "#{n} not moved"
104
+ }
105
+ assert_eq "s", File.read(File.join(data, "session.txt"))
106
+ assert_eq "x", File.read(File.join(data, "backup", "a_1")), "the config dir's backup wins"
107
+ assert_eq "older a", File.read(File.join(legacy, "backup", "a_1")), "a file in both places left as it was"
108
+ assert_eq "new log", File.read(File.join(data, "crash", "stderr.log"))
109
+ assert File.exist?(File.join(conf, "crash", "stderr.log")), "the old log is kept"
110
+ assert File.exist?(File.join(legacy, "file_history")), "older copies in ~/.vimamsa stay"
111
+ assert File.exist?(File.join(conf, "settings.rb")) && File.exist?(File.join(conf, "bookmarks")), "config files moved"
112
+ assert File.exist?(File.join(conf, "macro_q.rb")), "saved macro not moved to the config dir"
113
+ assert !File.exist?(File.join(conf, "listen")), "empty old listen dir left"
114
+ assert !File.exist?(File.join(conf, "session.txt"))
115
+ assert moved.include?([File.join(conf, "session.txt"), File.join(data, "session.txt")])
116
+ # once: a second run moves nothing
117
+ assert_eq [], UserDirs.migrate(config_dir: conf, data_dir: data, legacy_dir: legacy, legacy_macro_dir: lmacro)
118
+ # one dir (--user-dir): nothing moves
119
+ assert_eq [], UserDirs.migrate(config_dir: conf, data_dir: conf, legacy_dir: legacy, legacy_macro_dir: lmacro)
120
+ }
121
+ end
122
+ end