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.
- checksums.yaml +4 -4
- data/.github/workflows/appimage.yml +93 -0
- data/.gitignore +4 -1
- data/Dockerfile +7 -4
- data/README.md +195 -99
- data/custom_example.rb +59 -17
- data/doc/TODO.md +678 -0
- data/doc/action_names_plan.md +442 -0
- data/doc/bundling_plan.md +570 -0
- 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 +213 -0
- data/doc/line_tree_plan.md +89 -0
- data/doc/missing_vim_bindings.md +61 -0
- data/doc/modules_settings_plan.md +433 -0
- data/doc/refactor_dedup_plan.md +117 -0
- data/doc/registries_plan.md +202 -0
- data/doc/startup_speed_plan.md +97 -0
- data/doc/treap_visualizer.html +585 -0
- data/doc/unused_code_plan.md +120 -0
- data/doc/vim_compatibility_plan.md +451 -0
- data/doc/vimlike_vim_conflicts.md +262 -0
- data/doc/vm_snapshots_plan.md +146 -0
- data/doc/wysiwyg_plan.md +231 -0
- data/exe/run_tests.rb +124 -3
- data/exe/vimamsa +68 -5
- data/fonts/OFL-Oxanium.txt +93 -0
- data/fonts/Oxanium[wght].ttf +0 -0
- data/help/intro.txt +30 -0
- data/help/vim_intro.txt +31 -0
- data/icon.png +0 -0
- data/img/demo.gif +0 -0
- data/img/demo.mp4 +0 -0
- data/lang/hyperplaintext.lang +7 -1
- data/lib/vimamsa/ack.rb +13 -1
- data/lib/vimamsa/actions.rb +385 -37
- data/lib/vimamsa/appimage_env.rb +35 -0
- data/lib/vimamsa/audio.rb +2 -5
- data/lib/vimamsa/bookmarks.rb +302 -0
- data/lib/vimamsa/buffer.rb +675 -118
- data/lib/vimamsa/buffer_changetext.rb +150 -68
- data/lib/vimamsa/buffer_cursor.rb +7 -0
- data/lib/vimamsa/buffer_list.rb +6 -2
- data/lib/vimamsa/buffer_manager.rb +10 -7
- data/lib/vimamsa/bundled_fonts.rb +32 -0
- data/lib/vimamsa/cli_help.rb +75 -0
- data/lib/vimamsa/clipboard.rb +9 -3
- data/lib/vimamsa/conf.rb +68 -3
- data/lib/vimamsa/constants.rb +3 -0
- data/lib/vimamsa/crash_handler.rb +149 -0
- data/lib/vimamsa/debug.rb +6 -3
- data/lib/vimamsa/demo_player.rb +458 -0
- data/lib/vimamsa/demo_recorder.rb +277 -0
- data/lib/vimamsa/desktop_install.rb +96 -0
- data/lib/vimamsa/diff_buffer.rb +40 -11
- data/lib/vimamsa/dot_repeat.rb +104 -0
- data/lib/vimamsa/easy_jump.rb +57 -3
- data/lib/vimamsa/editor.rb +327 -78
- data/lib/vimamsa/encrypt.rb +78 -29
- data/lib/vimamsa/file_finder.rb +4 -19
- data/lib/vimamsa/file_history.rb +4 -1
- data/lib/vimamsa/file_manager.rb +46 -31
- data/lib/vimamsa/fold.rb +226 -0
- data/lib/vimamsa/form_input.rb +388 -0
- data/lib/vimamsa/gui.rb +603 -119
- data/lib/vimamsa/gui_command_line.rb +247 -0
- data/lib/vimamsa/gui_dialog.rb +94 -42
- data/lib/vimamsa/gui_file_panel.rb +356 -25
- data/lib/vimamsa/gui_form_generator.rb +75 -40
- data/lib/vimamsa/gui_func_panel.rb +67 -22
- data/lib/vimamsa/gui_image.rb +3 -0
- data/lib/vimamsa/gui_key_hint.rb +165 -0
- data/lib/vimamsa/gui_keylog_panel.rb +408 -0
- data/lib/vimamsa/gui_menu.rb +84 -53
- data/lib/vimamsa/gui_select_window.rb +80 -75
- data/lib/vimamsa/gui_settings.rb +86 -41
- data/lib/vimamsa/gui_sourceview.rb +280 -92
- data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
- data/lib/vimamsa/gui_text.rb +63 -2
- data/lib/vimamsa/gui_theme.rb +615 -0
- data/lib/vimamsa/hook.rb +5 -0
- data/lib/vimamsa/hyper_plain_text.rb +3 -0
- data/lib/vimamsa/intro_page.rb +368 -0
- data/lib/vimamsa/key_actions.rb +382 -193
- data/lib/vimamsa/key_binding_tree.rb +467 -273
- data/lib/vimamsa/key_bindings_notepad.rb +45 -0
- data/lib/vimamsa/key_bindings_report.rb +484 -0
- data/lib/vimamsa/key_bindings_vim.rb +104 -0
- data/lib/vimamsa/key_bindings_vimlike.rb +353 -289
- data/lib/vimamsa/key_names.rb +80 -0
- data/lib/vimamsa/langservp.rb +271 -54
- data/lib/vimamsa/line_tree.rb +367 -0
- data/lib/vimamsa/macro.rb +23 -3
- data/lib/vimamsa/main.rb +14 -8
- data/lib/vimamsa/rbvma.rb +41 -1
- data/lib/vimamsa/registers.rb +125 -0
- data/lib/vimamsa/run_ruby.rb +64 -0
- data/lib/vimamsa/search.rb +3 -0
- data/lib/vimamsa/search_replace.rb +15 -14
- data/lib/vimamsa/string_util.rb +134 -40
- data/lib/vimamsa/terminal.rb +3 -0
- data/lib/vimamsa/test_framework.rb +28 -2
- data/lib/vimamsa/tests.rb +11 -8
- data/lib/vimamsa/text_objects.rb +310 -0
- data/lib/vimamsa/text_transforms.rb +18 -0
- data/lib/vimamsa/tmp_user_dir.rb +39 -0
- data/lib/vimamsa/user_dirs.rb +83 -0
- data/lib/vimamsa/util.rb +46 -7
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa/vim_core.rb +355 -0
- data/lib/vimamsa/vim_operators.rb +365 -0
- data/lib/vimamsa.rb +0 -1
- data/modules/calculator/calculator.rb +5 -5
- data/modules/color_highlight/color_highlight.rb +118 -0
- data/modules/color_highlight/color_highlight_info.rb +3 -0
- data/modules/dictation/dictation.rb +1054 -0
- data/modules/dictation/dictation_info.rb +3 -0
- data/modules/dictation/whisper_worker.py +273 -0
- data/modules/ollama/ollama.rb +107 -0
- data/modules/ollama/ollama_info.rb +3 -0
- data/modules/terminal/terminal.rb +5 -5
- data/modules/tts/tts.rb +119 -0
- data/modules/tts/tts_info.rb +3 -0
- data/run_e2e_vm.sh +28 -0
- data/run_tests_vm.rb +138 -0
- data/scripts/appimage/AppRun +54 -0
- data/scripts/appimage/Dockerfile +18 -0
- data/scripts/appimage/build.sh +19 -0
- data/scripts/appimage/build_in_container.sh +192 -0
- data/scripts/appimage/smoke_test.sh +27 -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 +67 -0
- data/scripts/demo/notes.txt +6 -0
- data/scripts/demo/record_demo.rb +156 -0
- data/scripts/demo/report.rb +7 -0
- data/scripts/demo/shapes.rb +29 -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/styles/134272-molokai.xml +3 -0
- data/styles/molokai_cyber.xml +48 -0
- data/styles/molokai_edit.xml +1 -0
- data/tests/support/virtual_keyboard.rb +254 -0
- data/tests/support/virtual_mic.rb +67 -0
- data/tests/test_ack.rb +22 -0
- data/tests/test_action_ids.rb +232 -0
- data/tests/test_auto_format.rb +122 -0
- data/tests/test_autocomplete.rb +211 -0
- data/tests/test_autosave.rb +145 -0
- data/tests/test_basic_editing.rb +46 -16
- data/tests/test_bookmarks.rb +206 -0
- data/tests/test_bracket_match.rb +88 -0
- data/tests/test_bundling.rb +92 -0
- data/tests/test_cli_help.rb +64 -0
- data/tests/test_color_highlight.rb +92 -0
- data/tests/test_command_line.rb +79 -0
- data/tests/test_command_line_file.rb +27 -0
- data/tests/test_context_menu_file.rb +147 -0
- data/tests/test_copy_paste.rb +106 -26
- data/tests/test_crash_handler.rb +39 -0
- data/tests/test_custom_two_phase.rb +92 -0
- data/tests/test_demo_player.rb +301 -0
- data/tests/test_demo_recorder.rb +202 -0
- data/tests/test_dialog_callback_errors.rb +44 -0
- data/tests/test_dictation.rb +294 -0
- data/tests/test_diff_buffer_name.rb +51 -0
- data/tests/test_dot_repeat.rb +88 -0
- data/tests/test_double_click.rb +41 -0
- data/tests/test_drag_selection.rb +125 -0
- data/tests/test_e2e_cmdline.rb +116 -0
- data/tests/test_e2e_dictation.rb +98 -0
- data/tests/test_e2e_replace_char.rb +58 -0
- data/tests/test_easy_jump.rb +93 -0
- data/tests/test_extract_file_links.rb +55 -0
- data/tests/test_file_format.rb +217 -0
- data/tests/test_file_manager.rb +72 -0
- data/tests/test_file_panel.rb +269 -0
- data/tests/test_flash.rb +78 -0
- data/tests/test_fold.rb +111 -0
- data/tests/test_font_refresh.rb +56 -0
- data/tests/test_form_input.rb +203 -0
- data/tests/test_func_panel.rb +68 -0
- data/tests/test_grep_apply.rb +46 -0
- data/tests/test_gtk_sync.rb +126 -0
- data/tests/test_hpt_highlight_visible.rb +75 -0
- data/tests/test_hpt_link_highlight.rb +82 -0
- data/tests/test_intro_page.rb +437 -0
- data/tests/test_jump_to_file.rb +41 -0
- data/tests/test_key_bindings.rb +208 -0
- data/tests/test_key_categories.rb +163 -0
- data/tests/test_keylog_panel.rb +261 -0
- data/tests/test_line_ends.rb +51 -0
- data/tests/test_line_tree.rb +86 -0
- data/tests/test_lsp_clangd.rb +281 -0
- data/tests/test_lsp_jump.rb +87 -0
- data/tests/test_lsp_position_encoding.rb +49 -0
- data/tests/test_lsp_symbols.rb +68 -0
- data/tests/test_macro.rb +137 -0
- data/tests/test_markdown_highlight.rb +57 -0
- data/tests/test_mode_badge.rb +41 -0
- data/tests/test_module_interface.rb +9 -9
- data/tests/test_notepad_bindings.rb +67 -0
- data/tests/test_perf_startup.rb +28 -0
- data/tests/test_popup_queue.rb +51 -0
- data/tests/test_random_edit.rb +109 -0
- data/tests/test_registers.rb +122 -0
- data/tests/test_revert.rb +127 -0
- data/tests/test_run_ruby.rb +77 -0
- data/tests/test_startup_file.rb +58 -0
- data/tests/test_status_area.rb +50 -0
- data/tests/test_text_objects.rb +163 -0
- data/tests/test_text_transforms.rb +341 -0
- data/tests/test_tmp_user_dir.rb +79 -0
- data/tests/test_tts.rb +68 -0
- data/tests/test_undo.rb +34 -34
- data/tests/test_user_dirs.rb +122 -0
- data/tests/test_vim_bindings.rb +353 -0
- data/tests/test_vim_conflicts.rb +100 -0
- data/tests/test_vim_operators.rb +116 -0
- data/tests/test_window_layout.rb +302 -0
- data/vimamsa.gemspec +3 -1
- data/vm_guest_run.sh +129 -0
- metadata +167 -10
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
require "tmpdir"
|
|
2
|
+
require "rbconfig"
|
|
3
|
+
|
|
4
|
+
# custom.rb is loaded in two phases (see call_custom_after_init in editor.rb):
|
|
5
|
+
# the body of the file runs before Grep.init/FileManager.init/module loading, so
|
|
6
|
+
# that its cnf.* settings are visible to them, and hook_custom_after_init runs
|
|
7
|
+
# after everything is loaded, so it can bind keys for the modes they registered.
|
|
8
|
+
#
|
|
9
|
+
# That ordering can only be observed while an editor starts up, so this test
|
|
10
|
+
# boots a second editor process with VMA_USER_DIR pointing at a generated config
|
|
11
|
+
# and lets a probe test inside that process check the resulting binding tree.
|
|
12
|
+
class TestCustomTwoPhase < VmaTest
|
|
13
|
+
CUSTOM_RB = <<~'RUBY'
|
|
14
|
+
# Phase 1: must be visible to FileManager.init, which registers the
|
|
15
|
+
# experimental fexp bindings ("fexp d d" etc.) only when this is set.
|
|
16
|
+
cnf.fexp.experimental = true
|
|
17
|
+
|
|
18
|
+
# Phase 2: the fexp mode does not exist while the body of this file runs.
|
|
19
|
+
def hook_custom_after_init
|
|
20
|
+
reg_act(:_zz_probe_archive, proc { }, "probe")
|
|
21
|
+
bindkey "fexp , x", :_zz_probe_archive
|
|
22
|
+
end
|
|
23
|
+
RUBY
|
|
24
|
+
|
|
25
|
+
PROBE_RB = <<~'RUBY'
|
|
26
|
+
class TestZzTwoPhaseProbe < VmaTest
|
|
27
|
+
def test_hook_custom_after_init_bound_to_fexp
|
|
28
|
+
assert_eq ["fexp , x"], paths_of(:_zz_probe_archive),
|
|
29
|
+
"hook_custom_after_init should bind to the fexp mode, not leak elsewhere"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_phase1_settings_reached_module_init
|
|
33
|
+
assert_eq ["fexp d d"], paths_of("fexp.cut_file"),
|
|
34
|
+
"cnf.fexp.experimental from the body of custom.rb should reach FileManager.init"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def paths_of(action)
|
|
38
|
+
found = []
|
|
39
|
+
walk = lambda { |state, path|
|
|
40
|
+
state.children.each { |c|
|
|
41
|
+
p2 = path + [c.key_name]
|
|
42
|
+
found << p2.join(" ") if c.action == action
|
|
43
|
+
walk.call(c, p2)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
vma.kbd.root.children.each { |mode| walk.call(mode, [mode.key_name]) }
|
|
47
|
+
found
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
RUBY
|
|
51
|
+
|
|
52
|
+
def test_custom_rb_phases_run_in_order
|
|
53
|
+
# Set in the child so a copy of this test file there can never recurse.
|
|
54
|
+
skip "nested editor run" if ENV["VMA_TEST_CHILD"]
|
|
55
|
+
|
|
56
|
+
Dir.mktmpdir("vimamsa-two-phase-") do |dir|
|
|
57
|
+
File.write(File.join(dir, "custom.rb"), CUSTOM_RB)
|
|
58
|
+
probe = File.join(dir, "test_zz_two_phase_probe.rb")
|
|
59
|
+
File.write(probe, PROBE_RB)
|
|
60
|
+
|
|
61
|
+
args = [File.expand_path("exe/run_tests.rb", vma_root), probe]
|
|
62
|
+
# Reuse this run's display when it is already headless; open the child on
|
|
63
|
+
# its own invisible display when we are on the real desktop, so it cannot
|
|
64
|
+
# steal focus from e2e tests.
|
|
65
|
+
backend = Gdk::Display.default&.gtype&.name.to_s
|
|
66
|
+
args << "--headless" if backend.include?("Wayland")
|
|
67
|
+
|
|
68
|
+
env = { "VMA_USER_DIR" => dir, "VMA_TEST_CHILD" => "1" }
|
|
69
|
+
out_r, out_w = IO.pipe
|
|
70
|
+
pid = begin
|
|
71
|
+
Process.spawn(env, RbConfig.ruby, *args, chdir: vma_root,
|
|
72
|
+
out: out_w, err: out_w)
|
|
73
|
+
rescue SystemCallError => e
|
|
74
|
+
out_r.close
|
|
75
|
+
out_w.close
|
|
76
|
+
skip "could not start child editor: #{e}"
|
|
77
|
+
end
|
|
78
|
+
out_w.close
|
|
79
|
+
output = out_r.read
|
|
80
|
+
out_r.close
|
|
81
|
+
_, status = Process.waitpid2(pid)
|
|
82
|
+
|
|
83
|
+
assert status.success?, "child editor run failed:\n#{output}"
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
def vma_root
|
|
90
|
+
File.expand_path("..", File.dirname(__FILE__))
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# Help ▸ Play demo: the README demo steps played inside the editor
|
|
2
|
+
# (demo_player.rb, scripts/demo/demo_steps.txt)
|
|
3
|
+
class TestDemoPlayer < VmaTest
|
|
4
|
+
SHAPES = File.join(DemoPlayer::DIR, "shapes.rb")
|
|
5
|
+
|
|
6
|
+
def wait_until_done(player, secs = 60)
|
|
7
|
+
wait_for(secs) { !player.running? }
|
|
8
|
+
assert !player.running?, "demo still running after #{secs} s"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Runs the main loop until the block is true or secs pass; the block's value
|
|
12
|
+
def wait_for(secs)
|
|
13
|
+
t = Time.now
|
|
14
|
+
until (ok = yield) || Time.now - t > secs
|
|
15
|
+
drain_idle
|
|
16
|
+
sleep 0.005
|
|
17
|
+
end
|
|
18
|
+
ok
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Runs the main loop for secs
|
|
22
|
+
def idle_for(secs)
|
|
23
|
+
wait_for(secs) { false }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# A short demo: after a wait, x deletes the first character of the file;
|
|
27
|
+
# then the closing wait, if any
|
|
28
|
+
def short_player(wait, closing = nil, **opts)
|
|
29
|
+
steps = [["wait", wait.to_s], ["keys", "x"]]
|
|
30
|
+
steps << ["wait", closing.to_s] if closing
|
|
31
|
+
# on the easy jump demo's file (scripts/demo/shapes.rb, as original)
|
|
32
|
+
DemoPlayer.new(:easyjump, speed: 1, steps: steps, **opts)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def original
|
|
36
|
+
File.read(SHAPES)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_steps_parse
|
|
40
|
+
steps = DemoPlayer.parse(File.read(DemoPlayer::STEPS))
|
|
41
|
+
assert steps.any? { |c, a| c == "keys" && a.include?("@JUMP_LABEL@") }
|
|
42
|
+
assert steps.any? { |c, _| c == "target" }, "no target line for the easy jump"
|
|
43
|
+
assert steps.any? { |c, a| c == "type" && a.start_with?("puts ") }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# The basic demo (square/steps.txt), fast: it plays to the end and turns
|
|
47
|
+
# Circle into a Square class with a width (search and replace in a form,
|
|
48
|
+
# the action search, easy jumps), back in Command mode
|
|
49
|
+
# (Not faster: at 50x an easy jump can come before the view has scrolled
|
|
50
|
+
# to its target, which then has no label.)
|
|
51
|
+
def test_plays_whole_demo
|
|
52
|
+
# its action searches find the same action whatever else is registered
|
|
53
|
+
assert_eq "sel.convert.remove_empty_lines", vma.actions.search_actions_update_callback("sel.convert.remempty")[0][1]
|
|
54
|
+
assert_eq "sel.convert.eval", vma.actions.search_actions_update_callback("sel.convert.eval")[0][1]
|
|
55
|
+
p = DemoPlayer.new(speed: 3, loop: false)
|
|
56
|
+
p.start
|
|
57
|
+
wait_until_done(p, 300)
|
|
58
|
+
assert_eq "Demo finished", p.stop_message
|
|
59
|
+
t = p.buf.to_s
|
|
60
|
+
assert t.include?("class Square < Shape"), t
|
|
61
|
+
assert t.include?("@width**2"), t
|
|
62
|
+
# the action search ran the eval converter on the whole file
|
|
63
|
+
assert t.end_with?("[3.141592653589793, 1]\n\n") || t.include?("[3.141592653589793, 1]"), t
|
|
64
|
+
assert_mode :command
|
|
65
|
+
ensure
|
|
66
|
+
vma.buffers.close_buffer(p.buf.id) if p&.buf
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# The easy jump demo moves Shape#to_s above area, with v + easy jump to
|
|
70
|
+
# select it, x and P
|
|
71
|
+
def test_easyjump_demo_moves_to_s
|
|
72
|
+
p = DemoPlayer.new(:easyjump, speed: 50, loop: false)
|
|
73
|
+
p.start
|
|
74
|
+
wait_until_done(p)
|
|
75
|
+
l = original.lines
|
|
76
|
+
want = l[0..4] + ["\n"] + l[10..12] + ["\n"] + l[6..8] + l[13..]
|
|
77
|
+
assert_eq want.join, p.buf.to_s
|
|
78
|
+
assert_mode :command
|
|
79
|
+
ensure
|
|
80
|
+
vma.buffers.close_buffer(p.buf.id) if p&.buf
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# The file switching demo: tab, browse mode h / l and the file explorer
|
|
84
|
+
# visit every file and end on shapes.rb, unchanged, at the top
|
|
85
|
+
def test_files_demo_switches_files
|
|
86
|
+
p = DemoPlayer.new(:files, speed: 20, loop: false)
|
|
87
|
+
p.start
|
|
88
|
+
seen = []
|
|
89
|
+
t = Time.now
|
|
90
|
+
while p.running? && Time.now - t < 60
|
|
91
|
+
seen << File.basename(vma.buf.fname.to_s)
|
|
92
|
+
drain_idle
|
|
93
|
+
sleep 0.005
|
|
94
|
+
end
|
|
95
|
+
assert !p.running?, "demo still running"
|
|
96
|
+
order = seen.chunk_while { |a, b| a == b }.map(&:first)
|
|
97
|
+
assert_eq "Demo finished", p.stop_message, "#{p.stop_message}; buffers in order: #{order.inspect}, log: #{vma.gui.keylog_panel.entries.last(4).map { |e| e[:chord] || e[:text] }.inspect}"
|
|
98
|
+
# "": the file explorer's buffer
|
|
99
|
+
assert_eq ["", "notes.txt", "report.rb", "shapes.rb"], seen.uniq.sort
|
|
100
|
+
assert_eq "shapes.rb", File.basename(vma.buf.fname.to_s)
|
|
101
|
+
assert_eq File.read(SHAPES), vma.buf.to_s
|
|
102
|
+
assert_eq 0, vma.buf.pos
|
|
103
|
+
assert vma.buffers.list.none? { |b| b.module.is_a?(FileManager) rescue false }, "file explorer still open"
|
|
104
|
+
ensure
|
|
105
|
+
p&.bufs&.each { |b| vma.buffers.close_buffer(b.id) }
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def test_easyjump_steps_parse
|
|
109
|
+
steps = DemoPlayer.parse(File.read(DemoPlayer::DEMOS[:easyjump][:steps]))
|
|
110
|
+
assert steps.count { |c, a| c == "keys" && a.include?("@JUMP_LABEL@") } >= 5
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Another demo from the menu stops the playing one and starts; the same
|
|
114
|
+
# one again stops it
|
|
115
|
+
def test_toggle_switches_demo
|
|
116
|
+
DemoPlayer.toggle(:basic)
|
|
117
|
+
a = DemoPlayer.current
|
|
118
|
+
DemoPlayer.toggle(:easyjump)
|
|
119
|
+
b = DemoPlayer.current
|
|
120
|
+
assert !a.running?
|
|
121
|
+
assert b.running?
|
|
122
|
+
assert_eq :easyjump, b.name
|
|
123
|
+
DemoPlayer.toggle(:easyjump)
|
|
124
|
+
assert !b.running?
|
|
125
|
+
drain_idle
|
|
126
|
+
ensure
|
|
127
|
+
[a, b].compact.each { |x| x.stop; vma.buffers.close_buffer(x.buf.id) if x.buf }
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# The key log's close button stops the demo and hides the panel
|
|
131
|
+
def test_close_button_stops_demo
|
|
132
|
+
p = short_player(5)
|
|
133
|
+
p.start
|
|
134
|
+
panel = vma.gui.keylog_panel
|
|
135
|
+
assert panel.active?, "key log not shown by the demo"
|
|
136
|
+
panel.close_btn.signal_emit("clicked")
|
|
137
|
+
drain_idle
|
|
138
|
+
assert !p.running?, "demo still running"
|
|
139
|
+
assert !panel.active?, "key log still shown"
|
|
140
|
+
ensure
|
|
141
|
+
p&.stop
|
|
142
|
+
vma.buffers.close_buffer(p.buf.id) if p&.buf
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# The easy jump label is looked up for the target line in this window (a
|
|
146
|
+
# line near the top: the test window may not show line 16 the demo uses)
|
|
147
|
+
def test_jump_label_reaches_target
|
|
148
|
+
p = DemoPlayer.new
|
|
149
|
+
b = create_new_buffer(File.read(SHAPES), "demotest", true)
|
|
150
|
+
p.instance_variable_set(:@buf, b)
|
|
151
|
+
p.instance_variable_set(:@target, " def area")
|
|
152
|
+
b.set_pos(0)
|
|
153
|
+
# Let the new view get laid out: easy jump labels only what's visible
|
|
154
|
+
20.times { drain_idle; sleep 0.02 }
|
|
155
|
+
keys("s")
|
|
156
|
+
ej = EasyJump.class_variable_get(:@@cur)
|
|
157
|
+
label = p.send(:jump_label)
|
|
158
|
+
marks = ej.instance_variable_get(:@easy_jump_wsmarks)
|
|
159
|
+
assert label != ["esc"], "no label: target line start #{b.index(" def area")}, marks #{marks.first(30).inspect}, visible #{get_visible_area.inspect}, cur buf #{vma.buf.equal?(b)}"
|
|
160
|
+
label.each { |c| p.send(:press, c) }
|
|
161
|
+
assert_eq b.index(" def area"), b.pos
|
|
162
|
+
ensure
|
|
163
|
+
vma.buffers.close_buffer(b.id) if b
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# At the end the file goes back to how it was and the demo plays again
|
|
167
|
+
def test_loops_until_stopped
|
|
168
|
+
p = short_player(0.3, 0.3)
|
|
169
|
+
p.start
|
|
170
|
+
assert wait_for(5) { p.buf.to_s == original[1..] }, "the first round didn't delete a char"
|
|
171
|
+
assert wait_for(5) { p.rounds >= 1 }, "no second round"
|
|
172
|
+
assert p.running?
|
|
173
|
+
assert_eq original, p.buf.to_s
|
|
174
|
+
assert wait_for(5) { p.buf.to_s == original[1..] }, "the second round didn't play"
|
|
175
|
+
p.stop
|
|
176
|
+
assert !p.running?
|
|
177
|
+
ensure
|
|
178
|
+
p&.stop
|
|
179
|
+
vma.buffers.close_buffer(p.buf.id) if p&.buf
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# The key log starts empty, without the keys typed before the demo
|
|
183
|
+
def test_key_log_cleared_at_start
|
|
184
|
+
act "panel.keylog.toggle"
|
|
185
|
+
keys "j k"
|
|
186
|
+
assert vma.gui.keylog_panel.entries.size > 0
|
|
187
|
+
p = short_player(5, loop: false)
|
|
188
|
+
p.start
|
|
189
|
+
assert_eq [], vma.gui.keylog_panel.entries
|
|
190
|
+
ensure
|
|
191
|
+
p&.stop
|
|
192
|
+
vma.buffers.close_buffer(p.buf.id) if p&.buf
|
|
193
|
+
act "panel.keylog.toggle" if vma.gui.keylog_panel.active?
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Paused, the step waits; continued, it runs. The button label follows.
|
|
197
|
+
def test_pause_and_continue
|
|
198
|
+
p = short_player(0.2, loop: false)
|
|
199
|
+
panel = vma.gui.keylog_panel
|
|
200
|
+
p.start
|
|
201
|
+
assert panel.demo_bar.visible?
|
|
202
|
+
assert_eq "Pause", panel.demo_pause_btn.label
|
|
203
|
+
p.toggle_pause
|
|
204
|
+
assert p.paused?
|
|
205
|
+
assert_eq "Continue", panel.demo_pause_btn.label
|
|
206
|
+
idle_for(0.6)
|
|
207
|
+
assert_eq original, p.buf.to_s, "a paused demo went on"
|
|
208
|
+
p.toggle_pause
|
|
209
|
+
assert !p.paused?
|
|
210
|
+
assert_eq "Pause", panel.demo_pause_btn.label
|
|
211
|
+
wait_until_done(p, 5)
|
|
212
|
+
assert_eq original[1..], p.buf.to_s
|
|
213
|
+
assert !panel.demo_bar.visible?, "demo controls still shown after the end"
|
|
214
|
+
ensure
|
|
215
|
+
p&.stop
|
|
216
|
+
vma.buffers.close_buffer(p.buf.id) if p&.buf
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
# A demo from any steps file (scripts/demo/record_demo.rb): no controls,
|
|
220
|
+
# on_finish gets the stop message
|
|
221
|
+
def test_given_demo_without_controls
|
|
222
|
+
got = nil
|
|
223
|
+
demo = { steps: DemoPlayer::DEMOS[:easyjump][:steps], files: ["shapes.rb"], src: DemoPlayer::DIR }
|
|
224
|
+
p = DemoPlayer.new(:recording, demo: demo, steps: [["wait", "0.1"], ["keys", "x"]], speed: 1, loop: false,
|
|
225
|
+
controls: false, on_finish: proc { |m| got = m })
|
|
226
|
+
p.start
|
|
227
|
+
assert !vma.gui.keylog_panel.demo_bar.visible?, "controls shown"
|
|
228
|
+
wait_until_done(p, 5)
|
|
229
|
+
assert_eq "Demo finished", got
|
|
230
|
+
assert_eq original[1..], p.buf.to_s
|
|
231
|
+
ensure
|
|
232
|
+
vma.buffers.close_buffer(p.buf.id) if p&.buf
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
# An easy jump target outside the window (a demo recorded in a bigger
|
|
236
|
+
# one): the cursor still ends on it
|
|
237
|
+
def test_jump_target_not_shown
|
|
238
|
+
Dir.mktmpdir("vma-demo-src") { |src|
|
|
239
|
+
File.write(File.join(src, "long.txt"), (1..300).map { |i| "line #{i} some words here\n" }.join)
|
|
240
|
+
steps = [["wait", "0.1"], ["keys", "s"], ["target", "line 200 col 6"], ["keys", "@JUMP_LABEL@"], ["keys", "x"]]
|
|
241
|
+
p = DemoPlayer.new(:recording, demo: { steps: nil, files: ["long.txt"], src: src }, steps: steps,
|
|
242
|
+
speed: 1, loop: false, controls: false)
|
|
243
|
+
p.start
|
|
244
|
+
wait_until_done(p, 10)
|
|
245
|
+
assert_eq "Demo finished", p.stop_message
|
|
246
|
+
l = p.buf.lines[199]
|
|
247
|
+
assert_eq "line 00 some words here\n", l, "x not at line 200 col 6"
|
|
248
|
+
assert_mode :command
|
|
249
|
+
}
|
|
250
|
+
ensure
|
|
251
|
+
vma.buffers.close_buffer(p.buf.id) if p&.buf
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def test_speed_steps
|
|
255
|
+
p = DemoPlayer.new
|
|
256
|
+
r = p.rate
|
|
257
|
+
assert DemoPlayer::RATES.include?(r), "default rate #{r} not in RATES"
|
|
258
|
+
p.faster
|
|
259
|
+
assert_eq DemoPlayer::RATES[DemoPlayer::RATES.index(r) + 1], p.rate
|
|
260
|
+
8.times { p.faster }
|
|
261
|
+
assert_eq DemoPlayer::RATES.last, p.rate
|
|
262
|
+
20.times { p.slower }
|
|
263
|
+
assert_eq DemoPlayer::RATES.first, p.rate
|
|
264
|
+
assert_eq "0.25×", DemoPlayer.rate_label(0.25)
|
|
265
|
+
assert_eq "2×", DemoPlayer.rate_label(2)
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
# Speed divides the waits: a 2 s wait at 4× takes 0.5 s, a 0.2 s wait at
|
|
269
|
+
# 0.25× takes 0.8 s (the bounds are loose for slow machines)
|
|
270
|
+
def test_speed_changes_waits
|
|
271
|
+
p = short_player(2, loop: false)
|
|
272
|
+
p.set_rate(4)
|
|
273
|
+
p.start
|
|
274
|
+
assert_eq "4×", vma.gui.keylog_panel.demo_speed_lbl.label
|
|
275
|
+
assert wait_for(1.5) { !p.running? }, "a 2 s wait at 4× took over 1.5 s"
|
|
276
|
+
vma.buffers.close_buffer(p.buf.id)
|
|
277
|
+
|
|
278
|
+
p = short_player(0.2, loop: false)
|
|
279
|
+
p.set_rate(0.25)
|
|
280
|
+
p.start
|
|
281
|
+
idle_for(0.4)
|
|
282
|
+
assert p.running?, "a 0.2 s wait at 0.25× took under 0.4 s"
|
|
283
|
+
wait_until_done(p, 5)
|
|
284
|
+
ensure
|
|
285
|
+
p&.stop
|
|
286
|
+
vma.buffers.close_buffer(p.buf.id) if p&.buf
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
def test_toggle_stops
|
|
290
|
+
DemoPlayer.toggle
|
|
291
|
+
p = DemoPlayer.current
|
|
292
|
+
assert p.running?
|
|
293
|
+
assert vma.gui.keylog_panel.demo_bar.visible?
|
|
294
|
+
DemoPlayer.toggle
|
|
295
|
+
assert !p.running?
|
|
296
|
+
assert !vma.gui.keylog_panel.demo_bar.visible?
|
|
297
|
+
drain_idle
|
|
298
|
+
ensure
|
|
299
|
+
vma.buffers.close_buffer(p.buf.id) if p&.buf
|
|
300
|
+
end
|
|
301
|
+
end
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# Recording demos (demo_recorder.rb, doc/demo_recording_plan.md part 2):
|
|
2
|
+
# keys into steps, and a recorded demo played back (DemoPlayer user demos)
|
|
3
|
+
class TestDemoRecorder < VmaTest
|
|
4
|
+
K = DemoRecorder::Key
|
|
5
|
+
|
|
6
|
+
def lines(keys, end_line: 0)
|
|
7
|
+
DemoRecorder.steps(keys, end_line: end_line).lines.map(&:chomp).reject { |l| l.start_with?("#") }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def wait_until(secs = 60)
|
|
11
|
+
t = Time.now
|
|
12
|
+
until yield || Time.now - t > secs
|
|
13
|
+
drain_idle
|
|
14
|
+
sleep 0.005
|
|
15
|
+
end
|
|
16
|
+
yield
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# delay from the typical gap, wait for a pause, type for Insert-mode typing
|
|
20
|
+
def test_steps_from_keys
|
|
21
|
+
ins = "a.edit.insert.char!('%s')"
|
|
22
|
+
keys = [
|
|
23
|
+
K.new(t: 0.0, key: "j", mode: :command, action: "move.line.next"),
|
|
24
|
+
K.new(t: 0.4, key: "j", mode: :command, action: "move.line.next"),
|
|
25
|
+
K.new(t: 3.0, key: "i", mode: :command, action: "mode.insert"),
|
|
26
|
+
K.new(t: 3.4, key: "h", mode: :insert, action: ins % "h"),
|
|
27
|
+
K.new(t: 3.8, key: "i", mode: :insert, action: ins % "i"),
|
|
28
|
+
K.new(t: 4.2, key: "esc", mode: :insert, action: "mode.prev"),
|
|
29
|
+
]
|
|
30
|
+
assert_eq ["delay 0.4", "wait 1", "keys j j", "wait 2.2", "keys i", "type hi", "keys esc"], lines(keys)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_long_pause_capped
|
|
34
|
+
keys = [K.new(t: 0.0, key: "j", mode: :command, action: "x"), K.new(t: 30.0, key: "k", mode: :command, action: "x")]
|
|
35
|
+
assert lines(keys).include?("wait 3"), lines(keys).inspect
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Leading spaces of typed text go in a keys line ("type " would lose them)
|
|
39
|
+
def test_typed_leading_space
|
|
40
|
+
keys = [" ", "a"].each_with_index.map { |c, i|
|
|
41
|
+
K.new(t: i * 0.3, key: c == " " ? "space" : c, mode: :insert, action: c == " " ? "edit.insert.space" : "a.edit.insert.char!('a')")
|
|
42
|
+
}
|
|
43
|
+
assert_eq ["keys space", "type a"], lines(keys).last(2)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# An easy jump's label keys become the target line and @JUMP_LABEL@
|
|
47
|
+
def test_easy_jump_label
|
|
48
|
+
keys = [
|
|
49
|
+
K.new(t: 0.0, key: "s", mode: :command, action: "jump.easy", line: 0),
|
|
50
|
+
K.new(t: 0.4, key: "a", mode: :command, action: nil, line: 0, read: true),
|
|
51
|
+
K.new(t: 0.8, key: "b", mode: :command, action: nil, line: 0, read: true),
|
|
52
|
+
K.new(t: 1.2, key: "d", mode: :command, action: nil, line: 7, col: 12),
|
|
53
|
+
K.new(t: 1.4, key: "d", mode: :command, action: "edit.delete.line", line: 7),
|
|
54
|
+
]
|
|
55
|
+
l = lines(keys)
|
|
56
|
+
i = l.index("keys s")
|
|
57
|
+
assert i, l.inspect
|
|
58
|
+
# the d of d d has no action, but isn't a label key
|
|
59
|
+
assert_eq ["target line 8 col 13", "keys @JUMP_LABEL@", "keys d d"], l[i + 1, 3]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# ctrl alone is a key ("ctrl!"), ctrl held for ctrl-r is not
|
|
63
|
+
def test_bare_modifier
|
|
64
|
+
r = DemoRecorder.new
|
|
65
|
+
r.instance_variable_set(:@recording, true)
|
|
66
|
+
r.instance_variable_set(:@t0, 0)
|
|
67
|
+
r.key_input("ctrl", :key_press)
|
|
68
|
+
r.key_input("ctrl!", :key_release)
|
|
69
|
+
r.key_input("ctrl", :key_press)
|
|
70
|
+
r.key_input("ctrl-r", :key_press)
|
|
71
|
+
r.key_input("j", :key_press)
|
|
72
|
+
r.key_input("j!", :key_release)
|
|
73
|
+
assert_eq ["ctrl", "ctrl-r", "j"], r.keys.map(&:key)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Record real keys (an edit and , r r with typing in the form), name it in
|
|
77
|
+
# the save form, play it back: the same text
|
|
78
|
+
def test_record_save_and_play_back
|
|
79
|
+
b = create_new_buffer("one two one\nline two\n", "rectest")
|
|
80
|
+
rec = DemoRecorder.new
|
|
81
|
+
DemoRecorder.current = rec
|
|
82
|
+
rec.start
|
|
83
|
+
keys "j d d"
|
|
84
|
+
keys ", r r o n e tab 1 enter"
|
|
85
|
+
want = b.to_s.dup
|
|
86
|
+
assert_eq "1 two 1\n", want
|
|
87
|
+
rec.stop
|
|
88
|
+
assert FormInput.current, "no name form"
|
|
89
|
+
keys "ctrl-a r t enter"
|
|
90
|
+
dir = File.join(DemoPlayer.user_demos_dir, "rt")
|
|
91
|
+
assert File.exist?(File.join(dir, "steps.txt")), "not saved"
|
|
92
|
+
steps = File.read(File.join(dir, "steps.txt"))
|
|
93
|
+
assert steps.include?("type one"), steps
|
|
94
|
+
assert_eq "one two one\nline two\n", File.read(File.join(dir, "demo.txt")), "start file"
|
|
95
|
+
assert_eq :user_rt, DemoRecorder.last_saved
|
|
96
|
+
assert DemoPlayer.demos.key?(:user_rt)
|
|
97
|
+
assert vma.actions.include?("help.demo.user.rt")
|
|
98
|
+
|
|
99
|
+
p = DemoPlayer.new(:user_rt, speed: 50, loop: false)
|
|
100
|
+
p.start
|
|
101
|
+
assert wait_until { !p.running? }, "demo still running"
|
|
102
|
+
assert_eq "Demo finished", p.stop_message, steps
|
|
103
|
+
assert_eq want, p.buf.to_s, steps
|
|
104
|
+
ensure
|
|
105
|
+
DemoRecorder.current = nil
|
|
106
|
+
FormInput.current&.cancel
|
|
107
|
+
drain_idle
|
|
108
|
+
p&.bufs&.each { |x| vma.buffers.close_buffer(x.id) }
|
|
109
|
+
FileUtils.rm_rf(DemoPlayer.user_demos_dir)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# An easy jump to a word inside a line (s + a label), then d w: all keys
|
|
113
|
+
# play back, at the same character (the d, which has no action, used to be
|
|
114
|
+
# taken for a label key)
|
|
115
|
+
def test_record_dd_then_easy_jump
|
|
116
|
+
text = (1..12).map { |i| "line number #{i} with words\n" }.join
|
|
117
|
+
b = create_new_buffer(text, "rectest")
|
|
118
|
+
# easy jump labels only what is shown: wait until the view is laid out
|
|
119
|
+
assert wait_until(10) { (a = get_visible_area) && a[1] - a[0] > 100 }, "view not laid out: #{get_visible_area.inspect}"
|
|
120
|
+
rec = DemoRecorder.new
|
|
121
|
+
DemoRecorder.current = rec
|
|
122
|
+
rec.start
|
|
123
|
+
keys "s"
|
|
124
|
+
ej = EasyJump.class_variable_get(:@@cur)
|
|
125
|
+
# a labelled word inside line 6, not its start
|
|
126
|
+
ls = b.index("line number 6")
|
|
127
|
+
marks = ej.instance_variable_get(:@easy_jump_wsmarks)
|
|
128
|
+
target = marks.select { |m| m > ls && m < b.index("\n", ls) }.min
|
|
129
|
+
assert target, "no labelled word inside line 6: #{marks.sort.inspect}"
|
|
130
|
+
n = marks.index(target)
|
|
131
|
+
label = ej.instance_variable_get(:@jump_sequence)[n].downcase.chars
|
|
132
|
+
keys label.join(" ")
|
|
133
|
+
assert_eq target, b.pos, "jump"
|
|
134
|
+
keys "d w"
|
|
135
|
+
keys "x"
|
|
136
|
+
want = b.to_s.dup
|
|
137
|
+
rec.stop(save: false)
|
|
138
|
+
steps = rec.steps_text(file: "demo.txt")
|
|
139
|
+
assert steps.include?("keys d w"), steps
|
|
140
|
+
col = target - ls + 1
|
|
141
|
+
assert steps.include?("target line 6 col #{col}"), steps
|
|
142
|
+
rec.save("ddjump")
|
|
143
|
+
p = DemoPlayer.new(:user_ddjump, speed: 50, loop: false)
|
|
144
|
+
p.start
|
|
145
|
+
assert wait_until { !p.running? }, "demo still running"
|
|
146
|
+
assert_eq want, p.buf.to_s, steps
|
|
147
|
+
ensure
|
|
148
|
+
vma.kbd.remove_keyhandling_override # easy jump left reading keys
|
|
149
|
+
vma.gui.clear_overlay rescue nil
|
|
150
|
+
vma.kbd.set_mode(:command)
|
|
151
|
+
DemoRecorder.current = nil
|
|
152
|
+
p&.bufs&.each { |x| vma.buffers.close_buffer(x.id) }
|
|
153
|
+
FileUtils.rm_rf(DemoPlayer.user_demos_dir)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# The action search (a list window): select lines, , , s, type a fuzzy
|
|
157
|
+
# name, enter. It is recorded (form mode) and plays back.
|
|
158
|
+
def test_record_action_search
|
|
159
|
+
b = create_new_buffer("a\n\nb\n\nc\n", "rectest")
|
|
160
|
+
rec = DemoRecorder.new
|
|
161
|
+
DemoRecorder.current = rec
|
|
162
|
+
rec.start
|
|
163
|
+
keys "v j j j"
|
|
164
|
+
keys ", , s"
|
|
165
|
+
assert FormInput.current, "action search not in form mode"
|
|
166
|
+
keys "r e m e m p t y l i n e s"
|
|
167
|
+
keys "enter"
|
|
168
|
+
assert FormInput.current.nil?, "action search still open"
|
|
169
|
+
want = b.to_s.dup
|
|
170
|
+
assert_eq "a\nb\nc\n", want
|
|
171
|
+
rec.stop(save: false)
|
|
172
|
+
steps = rec.steps_text(file: "demo.txt")
|
|
173
|
+
assert steps.include?("type rememptylines"), steps
|
|
174
|
+
assert steps.include?("keys enter"), steps
|
|
175
|
+
rec.save("search")
|
|
176
|
+
p = DemoPlayer.new(:user_search, speed: 50, loop: false)
|
|
177
|
+
p.start
|
|
178
|
+
assert wait_until { !p.running? }, "demo still running"
|
|
179
|
+
assert_eq want, p.buf.to_s, steps
|
|
180
|
+
ensure
|
|
181
|
+
FormInput.current&.cancel
|
|
182
|
+
vma.kbd.set_mode(:command)
|
|
183
|
+
DemoRecorder.current = nil
|
|
184
|
+
p&.bufs&.each { |x| vma.buffers.close_buffer(x.id) }
|
|
185
|
+
FileUtils.rm_rf(DemoPlayer.user_demos_dir)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# The stop command's own keys aren't in the demo
|
|
189
|
+
def test_stop_keys_dropped
|
|
190
|
+
rec = DemoRecorder.new
|
|
191
|
+
DemoRecorder.current = rec
|
|
192
|
+
rec.start
|
|
193
|
+
keys "j"
|
|
194
|
+
rec.key_input(",", :key_press)
|
|
195
|
+
rec.key_input("x", :key_press)
|
|
196
|
+
rec.key_action("help.demo.record")
|
|
197
|
+
rec.stop(save: false)
|
|
198
|
+
assert_eq ["j"], rec.keys.map(&:key)
|
|
199
|
+
ensure
|
|
200
|
+
DemoRecorder.current = nil
|
|
201
|
+
end
|
|
202
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# An exception raised by a dialog callback must not escape to GTK: ruby-gnome
|
|
2
|
+
# calls exit for exceptions leaving a signal handler, quitting the editor.
|
|
3
|
+
class TestDialogCallbackErrors < VmaTest
|
|
4
|
+
def test_run_dialog_callback_returns_nil_and_reports
|
|
5
|
+
r = run_dialog_callback("test cb") { raise ArgumentError, "boom" }
|
|
6
|
+
assert_eq nil, r
|
|
7
|
+
assert $vmag.instance_variable_get(:@minibuf_messages).first.include?("ERROR in test cb: boom")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_run_dialog_callback_returns_block_value
|
|
11
|
+
assert_eq 42, run_dialog_callback { 42 }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_run_dialog_callback_does_not_swallow_exit
|
|
15
|
+
raised = false
|
|
16
|
+
begin
|
|
17
|
+
run_dialog_callback { exit }
|
|
18
|
+
rescue SystemExit
|
|
19
|
+
raised = true
|
|
20
|
+
end
|
|
21
|
+
assert raised, "SystemExit must propagate"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_form_submit_with_raising_callback_closes_popup
|
|
25
|
+
PopupFormGenerator.reset_popup_queue
|
|
26
|
+
params = { "inputs" => { "q" => { :label => "Q", :type => :entry } },
|
|
27
|
+
:callback => proc { |_| raise "form boom" } }
|
|
28
|
+
p1 = PopupFormGenerator.new(params)
|
|
29
|
+
p1.run
|
|
30
|
+
drain_idle
|
|
31
|
+
p1.submit
|
|
32
|
+
drain_idle
|
|
33
|
+
assert !PopupFormGenerator.popup_active?, "popup should close even though callback raised"
|
|
34
|
+
ensure
|
|
35
|
+
PopupFormGenerator.reset_popup_queue
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_key_controller_submit_raising_is_caught
|
|
39
|
+
entry = Gtk::Entry.new
|
|
40
|
+
press = on_submit_escape(entry, submit: proc { raise "submit boom" })
|
|
41
|
+
handled = press.signal_emit("key-pressed", Gdk::Keyval::KEY_Return, 0, 0)
|
|
42
|
+
assert_eq true, handled
|
|
43
|
+
end
|
|
44
|
+
end
|