vimamsa 0.1.27 → 0.1.29

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 (167) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/appimage.yml +17 -10
  3. data/Dockerfile +2 -2
  4. data/README.md +162 -90
  5. data/custom_example.rb +33 -15
  6. data/doc/TODO.md +334 -110
  7. data/doc/action_names_plan.md +442 -0
  8. data/doc/bundling_plan.md +2 -1
  9. data/doc/delta_syntax_plan.md +293 -0
  10. data/doc/demo_recording_plan.md +288 -0
  11. data/doc/design_goals.md +27 -0
  12. data/doc/intro_page_plan.md +266 -0
  13. data/doc/key_bindings_report_plan.md +45 -0
  14. data/doc/line_tree_plan.md +89 -0
  15. data/doc/missing_vim_bindings.md +34 -44
  16. data/doc/modules_settings_plan.md +1 -1
  17. data/doc/registries_plan.md +202 -0
  18. data/doc/startup_speed_plan.md +97 -0
  19. data/doc/test_commands.md +232 -0
  20. data/doc/treap_visualizer.html +585 -0
  21. data/doc/vim_compatibility_plan.md +186 -31
  22. data/doc/vimlike_vim_conflicts.md +236 -228
  23. data/doc/vm_snapshots_plan.md +4 -4
  24. data/doc/wysiwyg_plan.md +231 -0
  25. data/docker_cmd.sh +1 -1
  26. data/exe/run_tests.rb +85 -3
  27. data/exe/vimamsa +49 -6
  28. data/help/intro.txt +30 -0
  29. data/help/vim_intro.txt +31 -0
  30. data/img/demo.gif +0 -0
  31. data/img/demo.mp4 +0 -0
  32. data/lang/hyperplaintext.lang +1 -1
  33. data/lib/vimamsa/ack.rb +2 -0
  34. data/lib/vimamsa/actions.rb +381 -36
  35. data/lib/vimamsa/bookmarks.rb +8 -8
  36. data/lib/vimamsa/buffer.rb +84 -38
  37. data/lib/vimamsa/buffer_changetext.rb +58 -36
  38. data/lib/vimamsa/buffer_list.rb +2 -2
  39. data/lib/vimamsa/buffer_manager.rb +6 -6
  40. data/lib/vimamsa/cli_help.rb +75 -0
  41. data/lib/vimamsa/clipboard.rb +6 -3
  42. data/lib/vimamsa/conf.rb +9 -0
  43. data/lib/vimamsa/crash_handler.rb +2 -2
  44. data/lib/vimamsa/debug.rb +2 -2
  45. data/lib/vimamsa/demo_player.rb +494 -0
  46. data/lib/vimamsa/demo_recorder.rb +277 -0
  47. data/lib/vimamsa/diff_buffer.rb +1 -1
  48. data/lib/vimamsa/dot_repeat.rb +104 -0
  49. data/lib/vimamsa/easy_jump.rb +54 -3
  50. data/lib/vimamsa/editor.rb +136 -65
  51. data/lib/vimamsa/file_history.rb +1 -1
  52. data/lib/vimamsa/file_manager.rb +23 -23
  53. data/lib/vimamsa/form_input.rb +388 -0
  54. data/lib/vimamsa/gui.rb +89 -13
  55. data/lib/vimamsa/gui_command_line.rb +44 -5
  56. data/lib/vimamsa/gui_form_generator.rb +17 -6
  57. data/lib/vimamsa/gui_func_panel.rb +1 -1
  58. data/lib/vimamsa/gui_key_hint.rb +165 -0
  59. data/lib/vimamsa/gui_keylog_panel.rb +164 -2
  60. data/lib/vimamsa/gui_menu.rb +69 -50
  61. data/lib/vimamsa/gui_select_window.rb +77 -43
  62. data/lib/vimamsa/gui_settings.rb +9 -5
  63. data/lib/vimamsa/gui_sourceview.rb +28 -81
  64. data/lib/vimamsa/gui_theme.rb +11 -2
  65. data/lib/vimamsa/hook.rb +2 -0
  66. data/lib/vimamsa/intro_page.rb +367 -0
  67. data/lib/vimamsa/key_actions.rb +315 -225
  68. data/lib/vimamsa/key_binding_tree.rb +228 -61
  69. data/lib/vimamsa/key_bindings_notepad.rb +18 -16
  70. data/lib/vimamsa/key_bindings_report.rb +290 -67
  71. data/lib/vimamsa/key_bindings_vim.rb +43 -297
  72. data/lib/vimamsa/key_bindings_vim_core.rb +356 -0
  73. data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
  74. data/lib/vimamsa/key_names.rb +80 -0
  75. data/lib/vimamsa/langservp.rb +62 -7
  76. data/lib/vimamsa/line_tree.rb +367 -0
  77. data/lib/vimamsa/macro.rb +20 -3
  78. data/lib/vimamsa/rbvma.rb +15 -0
  79. data/lib/vimamsa/registers.rb +125 -0
  80. data/lib/vimamsa/run_ruby.rb +64 -0
  81. data/lib/vimamsa/search_replace.rb +4 -4
  82. data/lib/vimamsa/string_util.rb +17 -3
  83. data/lib/vimamsa/tests.rb +8 -8
  84. data/lib/vimamsa/text_objects.rb +11 -54
  85. data/lib/vimamsa/text_transforms.rb +4 -0
  86. data/lib/vimamsa/tmp_user_dir.rb +39 -0
  87. data/lib/vimamsa/user_dirs.rb +83 -0
  88. data/lib/vimamsa/version.rb +1 -1
  89. data/lib/vimamsa/vim_operators.rb +365 -0
  90. data/modules/calculator/calculator.rb +5 -5
  91. data/modules/color_highlight/color_highlight.rb +3 -3
  92. data/modules/dictation/dictation.rb +32 -32
  93. data/modules/ollama/ollama.rb +5 -5
  94. data/modules/terminal/terminal.rb +5 -5
  95. data/modules/tts/tts.rb +10 -10
  96. data/run_e2e_vm.sh +3 -3
  97. data/run_tests_vm.rb +163 -0
  98. data/scripts/appimage/AppRun +7 -0
  99. data/scripts/appimage/build_in_container.sh +11 -1
  100. data/scripts/appimage/smoke_test.sh +1 -1
  101. data/scripts/demo/demo_easyjump_steps.txt +60 -0
  102. data/scripts/demo/demo_files_steps.txt +52 -0
  103. data/scripts/demo/demo_steps.txt +9 -1
  104. data/scripts/demo/notes.txt +6 -0
  105. data/scripts/demo/record_demo.rb +60 -81
  106. data/scripts/demo/report.rb +7 -0
  107. data/scripts/demo/shapes.rb +1 -0
  108. data/scripts/demo/square/shapes.rb +29 -0
  109. data/scripts/demo/square/steps.txt +185 -0
  110. data/scripts/lib/perf_startup.rb +138 -0
  111. data/scripts/lib/script_helpers.rb +53 -0
  112. data/scripts/perf_compare.rb +34 -0
  113. data/scripts/profile_startup.rb +72 -0
  114. data/tests/test_action_ids.rb +232 -0
  115. data/tests/test_auto_format.rb +2 -2
  116. data/tests/test_autocomplete.rb +1 -1
  117. data/tests/test_basic_editing.rb +18 -18
  118. data/tests/test_bookmarks.rb +6 -6
  119. data/tests/test_bracket_match.rb +3 -0
  120. data/tests/test_cli_help.rb +64 -0
  121. data/tests/test_color_highlight.rb +2 -2
  122. data/tests/test_command_line.rb +1 -1
  123. data/tests/test_context_menu_file.rb +18 -0
  124. data/tests/test_copy_paste.rb +33 -33
  125. data/tests/test_custom_two_phase.rb +1 -1
  126. data/tests/test_demo_player.rb +355 -0
  127. data/tests/test_demo_recorder.rb +202 -0
  128. data/tests/test_dictation.rb +16 -16
  129. data/tests/test_dot_repeat.rb +88 -0
  130. data/tests/test_easy_jump.rb +93 -0
  131. data/tests/test_extract_file_links.rb +3 -3
  132. data/tests/test_file_panel.rb +2 -2
  133. data/tests/test_flash.rb +1 -1
  134. data/tests/test_fold.rb +1 -1
  135. data/tests/test_form_input.rb +203 -0
  136. data/tests/test_func_panel.rb +2 -2
  137. data/tests/test_gtk_sync.rb +7 -7
  138. data/tests/test_intro_page.rb +437 -0
  139. data/tests/test_key_categories.rb +163 -0
  140. data/tests/test_keylog_panel.rb +163 -3
  141. data/tests/test_line_ends.rb +51 -0
  142. data/tests/test_line_tree.rb +86 -0
  143. data/tests/test_lsp_clangd.rb +2 -2
  144. data/tests/test_lsp_root.rb +43 -0
  145. data/tests/test_macro.rb +2 -2
  146. data/tests/test_module_interface.rb +9 -9
  147. data/tests/test_notepad_bindings.rb +5 -5
  148. data/tests/test_perf_startup.rb +28 -0
  149. data/tests/test_random_edit.rb +27 -27
  150. data/tests/test_registers.rb +131 -0
  151. data/tests/test_run_ruby.rb +77 -0
  152. data/tests/test_startup_file.rb +45 -4
  153. data/tests/test_text_objects.rb +1 -1
  154. data/tests/test_text_transforms.rb +12 -0
  155. data/tests/test_tmp_user_dir.rb +79 -0
  156. data/tests/test_tts.rb +10 -10
  157. data/tests/test_undo.rb +34 -34
  158. data/tests/test_user_dirs.rb +122 -0
  159. data/tests/test_vim_bindings.rb +107 -6
  160. data/tests/test_vim_conflicts.rb +41 -4
  161. data/tests/test_vim_operators.rb +116 -0
  162. data/tests/test_window_layout.rb +83 -0
  163. data/vimamsa.gemspec +1 -1
  164. data/vm_guest_run.sh +75 -28
  165. metadata +60 -4
  166. data/run_tests.rb +0 -89
  167. data/run_tests_vm.sh +0 -130
@@ -6,11 +6,11 @@ class TestKeylogPanel < VmaTest
6
6
  # Show the panel, run the block with a clean log, always hide again so
7
7
  # later tests (and other test files) start with logging off.
8
8
  def with_panel
9
- act :toggle_keylog_panel
9
+ act "panel.keylog.toggle"
10
10
  panel.clear
11
11
  yield
12
12
  ensure
13
- act :toggle_keylog_panel
13
+ act "panel.keylog.toggle"
14
14
  end
15
15
 
16
16
  def test_chord_and_action_logged
@@ -18,7 +18,7 @@ class TestKeylogPanel < VmaTest
18
18
  keys("g g")
19
19
  e = panel.entries.last
20
20
  assert_eq :action, e[:kind]
21
- assert_eq :jump_start_of_buffer, e[:action]
21
+ assert_eq "move.buf.start", e[:action]
22
22
  assert e[:chord].include?("g g"), "chord was #{e[:chord].inspect}"
23
23
  assert e[:chord].include?("[COMMAND]"), "chord was #{e[:chord].inspect}"
24
24
  end
@@ -82,6 +82,7 @@ class TestKeylogPanel < VmaTest
82
82
  # First show uses the default width, and long entries (even without
83
83
  # spaces) don't widen it
84
84
  def test_width_fixed_on_first_show
85
+ skip "no layout on the Broadway backend" if ENV["VMA_HEADLESS"] == "broadway"
85
86
  gui = vma.gui
86
87
  old = gui.instance_variable_get(:@keylog_width)
87
88
  gui.instance_variable_set(:@keylog_width, nil)
@@ -98,4 +99,163 @@ class TestKeylogPanel < VmaTest
98
99
  ensure
99
100
  gui.instance_variable_set(:@keylog_width, old)
100
101
  end
102
+ def drain_for(secs)
103
+ t = Time.now
104
+ while Time.now - t < secs
105
+ drain_idle
106
+ sleep 0.01
107
+ end
108
+ end
109
+
110
+ # The bubble next to the cursor (gui_key_hint.rb) shows the key and the
111
+ # action, without the mode badge, near the cursor's line
112
+ def test_hint_near_cursor
113
+ act 'buf.insert_txt("one\ntwo\nthree\nfour\n")'
114
+ keys "g g"
115
+ with_panel do
116
+ keys "j j"
117
+ drain_for(0.1)
118
+ h = panel.hint
119
+ assert h.visible?, "hint not shown"
120
+ assert h.markup.include?("<b>j</b>"), "hint was #{h.markup.inspect}"
121
+ assert !h.markup.include?("[COMMAND]"), "hint has the mode: #{h.markup.inspect}"
122
+ _x, y = vma.gui.view.pos_to_coord(vma.buf.pos)
123
+ top = h.widget.margin_top
124
+ assert (top - y).abs < 100, "hint at y #{top}, cursor at y #{y}"
125
+ assert h.widget.can_target? == false, "the hint takes mouse input"
126
+ end
127
+ end
128
+
129
+ # The bubble starts with the mode after the action: v shows VISUAL
130
+ def test_hint_shows_mode
131
+ with_panel do
132
+ keys "j"
133
+ drain_for(0.05)
134
+ assert panel.hint.markup.include?("COMMAND"), panel.hint.markup
135
+ keys "v"
136
+ drain_for(0.05)
137
+ assert panel.hint.markup.include?("VISUAL"), panel.hint.markup
138
+ # the badge's own CSS classes, as the status badge: same theme colors
139
+ ml = panel.hint.mode_label
140
+ assert ml.has_css_class?("mode-badge") && ml.has_css_class?("mode-visual"), ml.css_classes.inspect
141
+ assert !ml.has_css_class?("mode-command"), ml.css_classes.inspect
142
+ keys "esc"
143
+ keys "i"
144
+ drain_for(0.05)
145
+ assert panel.hint.markup.include?("INSERT"), panel.hint.markup
146
+ keys "esc"
147
+ end
148
+ end
149
+
150
+ # cnf.key_hint.y_offset px below the cursor's row, starting right of the
151
+ # text of the row it covers
152
+ def test_hint_below_row_by_offset
153
+ act 'buf.insert_txt("one\nsecond line here\nthree\nfour\n")'
154
+ keys "g g"
155
+ old = cnf.key_hint.y_offset!
156
+ with_panel do
157
+ [4, 20].each { |off|
158
+ cnf.key_hint.y_offset = off
159
+ keys "j k"
160
+ drain_for(0.1)
161
+ v = vma.gui.view
162
+ x, y = v.pos_to_coord(vma.buf.pos)
163
+ line_h = v.get_iter_location(v.buffer.get_iter_at(offset: vma.buf.pos)).height
164
+ w = panel.hint.widget
165
+ assert_eq y + line_h + off, w.margin_top, "offset #{off}"
166
+ xe, _ = v.pos_to_coord(vma.buf.line_ends[1]) # end of "second line here"
167
+ assert w.margin_start > xe, "hint at x #{w.margin_start} covers row 2 (ends at x #{xe})"
168
+ }
169
+ end
170
+ ensure
171
+ cnf.key_hint.y_offset = old
172
+ end
173
+
174
+ # A long bubble on a long line stays inside the editor (it used to be
175
+ # placed by the width of the previous, shorter text)
176
+ def test_hint_fits_in_view
177
+ with_panel do
178
+ keys "i"
179
+ keys ("a b c d e f g h " * 6).strip
180
+ drain_for(0.1)
181
+ w = panel.hint.widget
182
+ ov = vma.gui.active_window[:overlay]
183
+ right = w.measure(:horizontal, -1)[1] - w.margin_end # measure counts margin_start
184
+ assert right <= ov.width + 1, "hint ends at x #{right}, editor is #{ov.width} wide"
185
+ keys "esc"
186
+ end
187
+ end
188
+
189
+ # A buffer switch by a key doesn't cover the hint: the new scrolled window
190
+ # is the overlay's main child, drawn below the hint (gui.rb
191
+ # set_current_buffer)
192
+ def test_hint_stays_above_after_buffer_switch
193
+ create_new_buffer("first buffer\n", "hint_a")
194
+ create_new_buffer("second buffer\n", "hint_b")
195
+ with_panel do
196
+ keys "tab"
197
+ drain_for(0.1)
198
+ assert_eq "first buffer\n", vma.buf.to_s, "tab didn't switch buffers"
199
+ ov = vma.gui.active_window[:overlay]
200
+ sw = vma.gui.active_window[:sw]
201
+ w = panel.hint.widget
202
+ assert w.visible?, "hint not shown"
203
+ assert_eq ov, w.parent
204
+ assert_eq sw, ov.child, "scrolled window not the overlay's main child"
205
+ kids = []
206
+ c = ov.first_child
207
+ while c
208
+ kids << c
209
+ c = c.next_sibling
210
+ end
211
+ assert kids.index(w) > kids.index(sw), "hint drawn below the text: #{kids.map { |k| k.class }.inspect}"
212
+ end
213
+ end
214
+
215
+ def test_hint_typed_text_and_pending
216
+ with_panel do
217
+ keys "g"
218
+ assert panel.hint.markup.include?("<b>g</b> …"), panel.hint.markup
219
+ keys "esc i a b c"
220
+ assert panel.hint.markup.include?("typed"), panel.hint.markup
221
+ assert panel.hint.markup.include?("abc"), panel.hint.markup
222
+ keys "esc"
223
+ end
224
+ end
225
+
226
+ def test_hint_fades_and_hides_with_panel
227
+ with_panel do
228
+ keys "j"
229
+ assert panel.hint.visible?
230
+ drain_for(KeyHint::SHOW_SECS + KeyHint::FADE_SECS + 0.4)
231
+ assert !panel.hint.visible?, "hint didn't fade out"
232
+ keys "k"
233
+ assert panel.hint.visible?
234
+ end
235
+ assert !panel.hint.visible?, "hint still shown with the panel hidden"
236
+ end
237
+ # Easy jump reads its label keys itself; they are logged as one row
238
+ def test_easy_jump_label_logged
239
+ act 'buf.insert_txt("one\ntwo\nthree\nfour\n")'
240
+ keys "g g"
241
+ vma.buf.view.handle_deltas
242
+ with_panel do
243
+ 20.times { drain_idle; sleep 0.02 } # laid out: easy jump labels only what's visible
244
+ keys "s"
245
+ ej = EasyJump.class_variable_get(:@@cur)
246
+ marks = ej.instance_variable_get(:@easy_jump_wsmarks)
247
+ seq = ej.instance_variable_get(:@jump_sequence)
248
+ n = marks.index(vma.buf.line_ends[1] + 1) # the start of line 3
249
+ assert n, "no label for line 3: marks #{marks.first(10).inspect}"
250
+ label = seq[n].downcase
251
+ keys label.chars.join(" ")
252
+ e = panel.entries.last
253
+ assert_eq :jump, e[:kind]
254
+ assert_eq label, e[:text]
255
+ assert_eq :jumped, e[:state]
256
+ assert_eq 3, e[:line]
257
+ assert_eq 1, panel.entries.count { |x| x[:kind] == :jump }, "one row per label"
258
+ assert panel.hint.markup.include?(label), panel.hint.markup
259
+ end
260
+ end
101
261
  end
@@ -0,0 +1,51 @@
1
+ require "benchmark"
2
+
3
+ # scan_indexes / line ends on non-ASCII text (scan_indexes used to be O(n^2)
4
+ # there), and get_line_end (used to scan all line ends).
5
+ class TestLineEnds < VmaTest
6
+ # The old implementation, kept as the reference.
7
+ def ref_scan_indexes(txt, regex)
8
+ txt.enum_for(:scan, regex).map { Regexp.last_match.begin(0) }
9
+ end
10
+
11
+ def test_scan_indexes_matches_reference_on_utf8
12
+ txt = "äö foo\nbär baz\n\n€ x\ty\nlast"
13
+ [/\n/, /\S/, /(?<=[^\p{Word}])\p{Word}|\Z/, /(?<=\p{Word})[^\p{Word}]/, /\n[ \t]*\n/, /z/].each do |re|
14
+ assert_eq ref_scan_indexes(txt, re), scan_indexes(txt, re), "regex #{re.inspect}"
15
+ end
16
+ end
17
+
18
+ def test_scan_indexes_ascii_unchanged
19
+ txt = "foo bar\nbaz\n"
20
+ assert_eq ref_scan_indexes(txt, /\n/), scan_indexes(txt, /\n/)
21
+ end
22
+
23
+ def test_line_ends_of_utf8_buffer
24
+ act 'buf.insert_txt("äb\nc€d\n\nlast")'
25
+ b = vma.buf
26
+ assert_eq ref_scan_indexes(b.to_s, /\n/), b.line_ends.to_a
27
+ assert_eq 2, b.get_line_end(0)
28
+ assert_eq 6, b.get_line_end(3)
29
+ assert_eq 7, b.get_line_end(6)
30
+ end
31
+
32
+ def test_get_line_end_matches_select
33
+ act 'buf.insert_txt("a\nbb\n\nccc\nd")'
34
+ b = vma.buf
35
+ (0...b.size).each do |pos|
36
+ assert_eq b.line_ends.to_a.select { |x| x > pos }.min, b.get_line_end(pos), "pos #{pos}"
37
+ end
38
+ end
39
+
40
+ # 3 MB with one non-ASCII character: the old code took seconds (13 s at
41
+ # 5.5 MB), the new one well under 0.1 s. The bound is loose for slow
42
+ # machines (the test VM once took 1.0 s).
43
+ def test_scan_indexes_utf8_is_not_quadratic
44
+ txt = "ä" + ("the quick brown fox jumps over the lazy dog 0123456789\n" * 55_000)
45
+ res = nil
46
+ t = Benchmark.realtime { res = scan_indexes(txt, /\n/) }
47
+ assert_eq 55_000, res.size
48
+ assert_eq txt.size - 1, res.last
49
+ assert t < 2.0, "scan_indexes took #{t.round(2)} s for 3 MB of UTF-8"
50
+ end
51
+ end
@@ -0,0 +1,86 @@
1
+ require "benchmark"
2
+
3
+ # LineTree: the treap that holds a buffer's line ends (lib/vimamsa/line_tree.rb,
4
+ # doc/line_tree_plan.md).
5
+ class TestLineTree < VmaTest
6
+ def newline_positions(s)
7
+ out = []
8
+ s.each_char.with_index { |c, i| out << i if c == "\n" }
9
+ out
10
+ end
11
+
12
+ def test_from_string
13
+ assert_eq [], LineTree.from_string("").to_a
14
+ assert_eq [2], LineTree.from_string("ab\n").to_a
15
+ assert_eq [2, 3], LineTree.from_string("ab\n\ncd").to_a
16
+ t = LineTree.from_string("ab\n\ncd")
17
+ assert_eq 2, t.size
18
+ assert_eq 6, t.total
19
+ assert_eq [2, 1], t.line_at(5)
20
+ assert_eq [2, 2], t.line_at(6) # the end belongs to the last line
21
+ end
22
+
23
+ # Random inserts and deletes, including non-ASCII text and newlines, compared
24
+ # with the newline positions of a String after every step.
25
+ def test_random_edits_match_string
26
+ rng = Random.new(7)
27
+ alpha = ["a", "b", "ä", "€", "\n", "\n", "xy", "\n\n", "q\nr", "ö\nä\n"]
28
+ 40.times do
29
+ s = Array.new(rng.rand(0..20)) { alpha.sample(random: rng) }.join
30
+ t = LineTree.from_string(s)
31
+ 40.times do
32
+ if rng.rand < 0.55 || s.empty?
33
+ pos = rng.rand(0..s.size)
34
+ txt = Array.new(rng.rand(1..4)) { alpha.sample(random: rng) }.join
35
+ s.insert(pos, txt)
36
+ t.insert(pos, txt)
37
+ else
38
+ pos = rng.rand(0...s.size)
39
+ removed = s.slice!(pos, rng.rand(1..[6, s.size - pos].min))
40
+ t.delete(pos, removed)
41
+ end
42
+ ref = newline_positions(s)
43
+ assert_eq ref, t.to_a, "after edits, text #{s.inspect}"
44
+ assert t.check!
45
+ assert_eq s.size, t.total
46
+ end
47
+ end
48
+ end
49
+
50
+ def test_array_interface_matches_array
51
+ s = "ab\n\nc€d\nx\n\nlast"
52
+ ref = newline_positions(s)
53
+ t = LineTree.from_string(s)
54
+ assert_eq ref.size, t.size
55
+ (-ref.size - 1..ref.size).each { |i| assert_eq ref[i], t[i], "[#{i}]" }
56
+ (0..s.size + 1).each do |p|
57
+ assert_eq ref.bsearch_index { |x| x >= p }, t.bsearch_index { |x| x >= p }, "bsearch_index #{p}"
58
+ assert_eq ref.bsearch { |x| x > p }, t.bsearch { |x| x > p }, "bsearch #{p}"
59
+ end
60
+ end
61
+
62
+ def test_buffer_edits_keep_line_ends
63
+ act 'buf.insert_txt("one\ntwo\nthree\n")'
64
+ keys "g g d d"
65
+ keys "p"
66
+ act 'buf.insert_txt("x\ny")'
67
+ b = vma.buf
68
+ assert_eq newline_positions(b.to_s), b.line_ends.to_a
69
+ act "undo.last"
70
+ act "undo.last"
71
+ b = vma.buf
72
+ assert_eq newline_positions(b.to_s), b.line_ends.to_a
73
+ end
74
+
75
+ # The old Array took about 6 ms per edit at 100k lines (it shifted every later
76
+ # entry); the tree needs microseconds. The bound is loose for slow machines.
77
+ def test_edit_cost_does_not_grow_with_lines
78
+ t = LineTree.from_string("the quick brown fox jumps over the lazy dog 0123456789\n" * 100_000)
79
+ mid = t.total / 2
80
+ sec = Benchmark.realtime { 1000.times { |k| t.insert(mid + k, "x") } }
81
+ assert sec < 0.5, "1000 inserts took #{sec.round(3)} s"
82
+ sec = Benchmark.realtime { 200.times { t.insert(mid, "ab\ncd\n") } }
83
+ assert sec < 0.5, "200 newline inserts took #{sec.round(3)} s"
84
+ assert_eq 100_400, t.size
85
+ end
86
+ end
@@ -230,7 +230,7 @@ class TestLspClangd < VmaTest
230
230
 
231
231
  # The pnnfast.c case: a header in another dir, no compile flags -> clangd
232
232
  # drops declarations using its types, so definition lookup finds nothing.
233
- # After adding compile_flags.txt, :lsp_restart (new clangd, buffers
233
+ # After adding compile_flags.txt, "lsp.restart" (new clangd, buffers
234
234
  # reattached) makes it work, and the old clangd process exits.
235
235
  def test_restart_picks_up_compile_flags
236
236
  with_clangd do |_b, _lsp, _path, dir|
@@ -255,7 +255,7 @@ class TestLspClangd < VmaTest
255
255
 
256
256
  File.write(File.join(dir, "compile_flags.txt"), "-Iinc\n")
257
257
  old_pid = old.pid
258
- act :lsp_restart
258
+ act "lsp.restart"
259
259
  assert cb.lsp && !cb.lsp.equal?(old), "buffer not reattached to a new server"
260
260
  d = retry_until { cb.lsp.get_definition(cpath, *call) }
261
261
  assert d, "no definition after restart"
@@ -0,0 +1,43 @@
1
+ require "tmpdir"
2
+
3
+ # LangSrv.project_root: the folder an LSP server runs in (its working
4
+ # directory and rootUri). ruby-lsp indexes its whole workspace, and used to
5
+ # get the editor's current directory, often the home directory.
6
+ class TestLspRoot < VmaTest
7
+ REPO = File.expand_path("..", __dir__)
8
+
9
+ def setup_lsp
10
+ require "vimamsa/langservp"
11
+ end
12
+
13
+ def test_nearest_project_marker
14
+ setup_lsp
15
+ assert_eq REPO, LangSrv.project_root(File.join(REPO, "lib/vimamsa/editor.rb"))
16
+ Dir.mktmpdir { |d|
17
+ FileUtils.mkdir_p("#{d}/proj/src/deep")
18
+ File.write("#{d}/proj/Gemfile", "")
19
+ assert_eq "#{d}/proj", LangSrv.project_root("#{d}/proj/src/deep/x.rb")
20
+ }
21
+ end
22
+
23
+ # No marker up to the home directory (or /): the file's own folder
24
+ def test_without_marker_the_files_folder
25
+ setup_lsp
26
+ Dir.mktmpdir { |d|
27
+ FileUtils.mkdir_p("#{d}/a/b")
28
+ root = LangSrv.project_root("#{d}/a/b/x.rb")
29
+ assert_eq "#{d}/a/b", root
30
+ }
31
+ end
32
+
33
+ # Never the home directory: a file directly in ~ gets an empty folder
34
+ def test_never_home
35
+ setup_lsp
36
+ home = File.expand_path("~")
37
+ r = LangSrv.project_root(File.join(home, "notes.rb"))
38
+ assert r != home, "home directory as the project root"
39
+ assert File.directory?(r)
40
+ assert_eq [], Dir.children(r)
41
+ assert_eq nil, LangSrv.project_root(nil)
42
+ end
43
+ end
data/tests/test_macro.rb CHANGED
@@ -10,7 +10,7 @@ class TestMacro < VmaTest
10
10
  # Fill the buffer with +n+ copies of +line+, cursor at the start.
11
11
  def set_lines(line, n)
12
12
  act "buf.insert_txt(#{([line] * n).join("\n").inspect})"
13
- act :jump_to_start_of_buffer
13
+ act "move.buf.start"
14
14
  end
15
15
 
16
16
  def recorded(slot)
@@ -132,6 +132,6 @@ class TestMacro < VmaTest
132
132
  keys "q b @ a j q"
133
133
  assert_buf "bc\nabc\nabc\n"
134
134
  assert_pos 2, 0
135
- assert_eq [:forward_line], recorded("b")
135
+ assert_eq ["move.line.next"], recorded("b")
136
136
  end
137
137
  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
 
@@ -32,7 +32,7 @@ class TestNotepadBindings < VmaTest
32
32
 
33
33
  def test_delete_forward
34
34
  act 'buf.insert_txt("abc")'
35
- act :jump_to_start_of_buffer
35
+ act "move.buf.start"
36
36
  keys "delete"
37
37
  assert_buf "bc\n"
38
38
  end
@@ -47,11 +47,11 @@ class TestNotepadBindings < VmaTest
47
47
 
48
48
  def test_rebound_dispatch
49
49
  # Assert rebinds without invoking GUI dialogs / quit
50
- assert_eq "ctrl-f", vma.kbd.act_bindings["I"][:find_in_buffer]
51
- assert_eq "ctrl-h", vma.kbd.act_bindings["I"][:gui_search_replace]
52
- assert_eq "ctrl-q", vma.kbd.act_bindings["I"][: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
53
  keys "ctrl-n" # safe to execute: creates a new buffer
54
- assert_eq :buf_new, vma.kbd.cur_action
54
+ assert_eq "buf.new", vma.kbd.cur_action
55
55
  assert_mode :insert
56
56
  end
57
57
 
@@ -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
@@ -10,32 +10,32 @@ class TestRandomEdit < VmaTest
10
10
 
11
11
  # Safe actions: no file dialogs, no eval, no close/save operations.
12
12
  SAFE_ACTIONS = [
13
- :e_move_forward_char,
14
- :e_move_backward_char,
15
- :move_next_line,
16
- :move_prev_line,
17
- :jump_to_start_of_buffer,
18
- :jump_to_end_of_buffer,
19
- :jump_end_of_line,
20
- :jump_beginning_of_line,
21
- :jump_next_word_end,
22
- :jump_prev_word_start,
23
- :jump_next_word_start,
24
- :delete_char_forward,
25
- :insert_backspace,
26
- :delete_to_word_end,
27
- :delete_to_next_word_start,
28
- :delete_to_line_start,
29
- :undo,
30
- :redo,
31
- :copy_cur_line,
32
- :paste_after_cursor,
33
- :paste_before_cursor,
34
- :insert_new_line,
35
- :page_down,
36
- :page_up,
37
- :center_on_current_line,
38
- :gui_refresh_cursor,
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
39
  ].freeze
40
40
 
41
41
  RANDOM_TEXTS = [
@@ -70,7 +70,7 @@ class TestRandomEdit < VmaTest
70
70
  when 8 then act_fast("vma.kbd.set_mode(:insert)")
71
71
  when 9 then act_fast("vma.kbd.set_mode(:command)")
72
72
  when 10 then act_fast("buf.start_selection; vma.kbd.set_mode(:visual)")
73
- when 11 then act_fast(:jump_to_random)
73
+ when 11 then act_fast("move.random")
74
74
  end
75
75
  rescue => e
76
76
  errors << "iter #{iteration}: #{e.class}: #{e.message}"