vimamsa 0.1.27 → 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.
- checksums.yaml +4 -4
- data/README.md +139 -89
- data/custom_example.rb +18 -6
- data/doc/TODO.md +327 -110
- data/doc/action_names_plan.md +442 -0
- data/doc/bundling_plan.md +2 -1
- data/doc/delta_syntax_plan.md +293 -0
- data/doc/demo_recording_plan.md +288 -0
- data/doc/design_goals.md +27 -0
- data/doc/intro_page_plan.md +266 -0
- data/doc/key_bindings_report_plan.md +45 -0
- data/doc/line_tree_plan.md +89 -0
- data/doc/missing_vim_bindings.md +34 -44
- data/doc/modules_settings_plan.md +1 -1
- data/doc/registries_plan.md +202 -0
- data/doc/startup_speed_plan.md +97 -0
- data/doc/treap_visualizer.html +585 -0
- data/doc/vim_compatibility_plan.md +186 -31
- data/doc/vimlike_vim_conflicts.md +236 -228
- data/doc/vm_snapshots_plan.md +4 -4
- data/doc/wysiwyg_plan.md +231 -0
- data/exe/run_tests.rb +8 -1
- data/exe/vimamsa +49 -6
- data/help/intro.txt +30 -0
- data/help/vim_intro.txt +31 -0
- data/img/demo.gif +0 -0
- data/img/demo.mp4 +0 -0
- data/lang/hyperplaintext.lang +1 -1
- data/lib/vimamsa/ack.rb +2 -0
- data/lib/vimamsa/actions.rb +381 -36
- data/lib/vimamsa/bookmarks.rb +8 -8
- data/lib/vimamsa/buffer.rb +83 -37
- data/lib/vimamsa/buffer_changetext.rb +58 -36
- data/lib/vimamsa/buffer_list.rb +2 -2
- data/lib/vimamsa/buffer_manager.rb +6 -6
- data/lib/vimamsa/cli_help.rb +75 -0
- data/lib/vimamsa/clipboard.rb +6 -3
- data/lib/vimamsa/conf.rb +9 -0
- data/lib/vimamsa/crash_handler.rb +2 -2
- data/lib/vimamsa/debug.rb +2 -2
- data/lib/vimamsa/demo_player.rb +458 -0
- data/lib/vimamsa/demo_recorder.rb +277 -0
- data/lib/vimamsa/diff_buffer.rb +1 -1
- data/lib/vimamsa/dot_repeat.rb +104 -0
- data/lib/vimamsa/easy_jump.rb +54 -3
- data/lib/vimamsa/editor.rb +89 -46
- data/lib/vimamsa/file_history.rb +1 -1
- data/lib/vimamsa/file_manager.rb +23 -23
- data/lib/vimamsa/form_input.rb +388 -0
- data/lib/vimamsa/gui.rb +83 -13
- data/lib/vimamsa/gui_command_line.rb +44 -5
- data/lib/vimamsa/gui_form_generator.rb +17 -6
- data/lib/vimamsa/gui_key_hint.rb +165 -0
- data/lib/vimamsa/gui_keylog_panel.rb +164 -2
- data/lib/vimamsa/gui_menu.rb +69 -50
- data/lib/vimamsa/gui_select_window.rb +77 -43
- data/lib/vimamsa/gui_settings.rb +9 -5
- data/lib/vimamsa/gui_sourceview.rb +15 -81
- data/lib/vimamsa/gui_theme.rb +11 -2
- data/lib/vimamsa/hook.rb +2 -0
- data/lib/vimamsa/intro_page.rb +368 -0
- data/lib/vimamsa/key_actions.rb +315 -225
- data/lib/vimamsa/key_binding_tree.rb +228 -61
- data/lib/vimamsa/key_bindings_notepad.rb +18 -16
- data/lib/vimamsa/key_bindings_report.rb +290 -67
- data/lib/vimamsa/key_bindings_vim.rb +47 -297
- data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
- data/lib/vimamsa/key_names.rb +80 -0
- data/lib/vimamsa/line_tree.rb +367 -0
- data/lib/vimamsa/macro.rb +20 -3
- data/lib/vimamsa/rbvma.rb +15 -0
- data/lib/vimamsa/registers.rb +125 -0
- data/lib/vimamsa/run_ruby.rb +64 -0
- data/lib/vimamsa/search_replace.rb +4 -4
- data/lib/vimamsa/string_util.rb +17 -3
- data/lib/vimamsa/tests.rb +8 -8
- data/lib/vimamsa/text_objects.rb +11 -54
- data/lib/vimamsa/text_transforms.rb +4 -0
- data/lib/vimamsa/tmp_user_dir.rb +39 -0
- data/lib/vimamsa/user_dirs.rb +83 -0
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa/vim_core.rb +355 -0
- data/lib/vimamsa/vim_operators.rb +365 -0
- data/modules/calculator/calculator.rb +5 -5
- data/modules/color_highlight/color_highlight.rb +3 -3
- data/modules/dictation/dictation.rb +32 -32
- data/modules/ollama/ollama.rb +5 -5
- data/modules/terminal/terminal.rb +5 -5
- data/modules/tts/tts.rb +10 -10
- data/run_e2e_vm.sh +3 -3
- data/run_tests_vm.rb +138 -0
- data/scripts/demo/demo_easyjump_steps.txt +60 -0
- data/scripts/demo/demo_files_steps.txt +52 -0
- data/scripts/demo/demo_steps.txt +9 -1
- data/scripts/demo/notes.txt +6 -0
- data/scripts/demo/record_demo.rb +60 -81
- data/scripts/demo/report.rb +7 -0
- data/scripts/demo/shapes.rb +1 -0
- data/scripts/demo/square/shapes.rb +29 -0
- data/scripts/demo/square/steps.txt +185 -0
- data/scripts/lib/perf_startup.rb +138 -0
- data/scripts/lib/script_helpers.rb +53 -0
- data/scripts/perf_compare.rb +34 -0
- data/scripts/profile_startup.rb +72 -0
- data/tests/test_action_ids.rb +232 -0
- data/tests/test_auto_format.rb +2 -2
- data/tests/test_autocomplete.rb +1 -1
- data/tests/test_basic_editing.rb +18 -18
- data/tests/test_bookmarks.rb +6 -6
- data/tests/test_bracket_match.rb +3 -0
- data/tests/test_cli_help.rb +64 -0
- data/tests/test_color_highlight.rb +2 -2
- data/tests/test_command_line.rb +1 -1
- data/tests/test_context_menu_file.rb +18 -0
- data/tests/test_copy_paste.rb +33 -33
- data/tests/test_custom_two_phase.rb +1 -1
- data/tests/test_demo_player.rb +301 -0
- data/tests/test_demo_recorder.rb +202 -0
- data/tests/test_dictation.rb +16 -16
- data/tests/test_dot_repeat.rb +88 -0
- data/tests/test_easy_jump.rb +93 -0
- data/tests/test_extract_file_links.rb +3 -3
- data/tests/test_file_panel.rb +2 -2
- data/tests/test_flash.rb +1 -1
- data/tests/test_fold.rb +1 -1
- data/tests/test_form_input.rb +203 -0
- data/tests/test_func_panel.rb +2 -2
- data/tests/test_gtk_sync.rb +7 -7
- data/tests/test_intro_page.rb +437 -0
- data/tests/test_key_categories.rb +163 -0
- data/tests/test_keylog_panel.rb +163 -3
- data/tests/test_line_ends.rb +51 -0
- data/tests/test_line_tree.rb +86 -0
- data/tests/test_lsp_clangd.rb +2 -2
- data/tests/test_macro.rb +2 -2
- data/tests/test_module_interface.rb +9 -9
- data/tests/test_notepad_bindings.rb +5 -5
- data/tests/test_perf_startup.rb +28 -0
- data/tests/test_random_edit.rb +27 -27
- data/tests/test_registers.rb +122 -0
- data/tests/test_run_ruby.rb +77 -0
- data/tests/test_startup_file.rb +1 -1
- data/tests/test_text_objects.rb +1 -1
- data/tests/test_text_transforms.rb +12 -0
- data/tests/test_tmp_user_dir.rb +79 -0
- data/tests/test_tts.rb +10 -10
- data/tests/test_undo.rb +34 -34
- data/tests/test_user_dirs.rb +122 -0
- data/tests/test_vim_bindings.rb +107 -6
- data/tests/test_vim_conflicts.rb +41 -4
- data/tests/test_vim_operators.rb +116 -0
- data/tests/test_window_layout.rb +83 -0
- data/vimamsa.gemspec +1 -1
- data/vm_guest_run.sh +22 -2
- metadata +58 -3
- data/run_tests_vm.sh +0 -130
data/tests/test_keylog_panel.rb
CHANGED
|
@@ -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
|
|
9
|
+
act "panel.keylog.toggle"
|
|
10
10
|
panel.clear
|
|
11
11
|
yield
|
|
12
12
|
ensure
|
|
13
|
-
act
|
|
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
|
|
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
|
data/tests/test_lsp_clangd.rb
CHANGED
|
@@ -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,
|
|
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
|
|
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"
|
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
|
|
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 [
|
|
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?(
|
|
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?(
|
|
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?(
|
|
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?(
|
|
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?(
|
|
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?(
|
|
70
|
-
assert vma.gui.menu.module_action?(
|
|
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?(
|
|
73
|
-
assert !vma.gui.menu.module_action?(
|
|
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
|
|
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"][
|
|
51
|
-
assert_eq "ctrl-h", vma.kbd.act_bindings["I"][
|
|
52
|
-
assert_eq "ctrl-q", vma.kbd.act_bindings["I"][
|
|
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
|
|
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
|
data/tests/test_random_edit.rb
CHANGED
|
@@ -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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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(
|
|
73
|
+
when 11 then act_fast("move.random")
|
|
74
74
|
end
|
|
75
75
|
rescue => e
|
|
76
76
|
errors << "iter #{iteration}: #{e.class}: #{e.message}"
|
|
@@ -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
|