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,58 @@
|
|
|
1
|
+
require "tmpdir"
|
|
2
|
+
|
|
3
|
+
# cnf.startup_file is the buffer shown on startup even when the previous
|
|
4
|
+
# session is restored (restoring would otherwise leave its last file current).
|
|
5
|
+
class TestStartupFile < VmaTest
|
|
6
|
+
def test_startup_file_stays_current_after_session_restore
|
|
7
|
+
Dir.mktmpdir do |dir|
|
|
8
|
+
startup = "#{dir}/startup.txt"
|
|
9
|
+
a = "#{dir}/a.txt"
|
|
10
|
+
b = "#{dir}/b.txt"
|
|
11
|
+
File.write(startup, "startup\n")
|
|
12
|
+
File.write(a, "a\n")
|
|
13
|
+
File.write(b, "b\n")
|
|
14
|
+
session = get_data_path("session.txt")
|
|
15
|
+
File.write(session, "#{a}\n#{b}\n")
|
|
16
|
+
|
|
17
|
+
open_new_file(startup)
|
|
18
|
+
vma.instance_variable_set(:@startup_fname, startup)
|
|
19
|
+
ENV["VIMAMSA_RESTORE_SESSION"] = "1"
|
|
20
|
+
begin
|
|
21
|
+
vma.check_session_restore
|
|
22
|
+
drain_idle
|
|
23
|
+
assert_eq startup, vma.buf.fname
|
|
24
|
+
assert vma.buffers.get_buffer_by_filename(a), "session file a restored"
|
|
25
|
+
assert vma.buffers.get_buffer_by_filename(b), "session file b restored"
|
|
26
|
+
ensure
|
|
27
|
+
ENV.delete("VIMAMSA_RESTORE_SESSION")
|
|
28
|
+
vma.instance_variable_set(:@startup_fname, nil)
|
|
29
|
+
File.delete(session) if File.exist?(session)
|
|
30
|
+
[b, a, startup].each { |f|
|
|
31
|
+
id = vma.buffers.get_buffer_by_filename(f)
|
|
32
|
+
vma.buffers.close_buffer(id) if id
|
|
33
|
+
}
|
|
34
|
+
drain_idle
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_without_startup_file_last_session_file_is_current
|
|
40
|
+
Dir.mktmpdir do |dir|
|
|
41
|
+
a = "#{dir}/a.txt"
|
|
42
|
+
b = "#{dir}/b.txt"
|
|
43
|
+
File.write(a, "a\n")
|
|
44
|
+
File.write(b, "b\n")
|
|
45
|
+
begin
|
|
46
|
+
vma.restore_session_files([a, b])
|
|
47
|
+
drain_idle
|
|
48
|
+
assert_eq b, vma.buf.fname
|
|
49
|
+
ensure
|
|
50
|
+
[b, a].each { |f|
|
|
51
|
+
id = vma.buffers.get_buffer_by_filename(f)
|
|
52
|
+
vma.buffers.close_buffer(id) if id
|
|
53
|
+
}
|
|
54
|
+
drain_idle
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
class TestStatusArea < VmaTest
|
|
2
|
+
|
|
3
|
+
# ── Mode badge CSS class + text ──────────────────────────────────────────
|
|
4
|
+
|
|
5
|
+
def test_badge_insert_mode
|
|
6
|
+
keys "i"
|
|
7
|
+
assert vma.gui.statnfo.css_classes.include?("mode-insert"), "badge should have mode-insert class"
|
|
8
|
+
assert_eq "INSERT", vma.gui.statnfo.text
|
|
9
|
+
keys "esc"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_badge_command_mode
|
|
13
|
+
keys "i esc"
|
|
14
|
+
assert vma.gui.statnfo.css_classes.include?("mode-command"), "badge should have mode-command class"
|
|
15
|
+
assert !vma.gui.statnfo.css_classes.include?("mode-insert"), "mode-insert class should be removed"
|
|
16
|
+
assert_eq "COMMAND", vma.gui.statnfo.text
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_badge_visual_mode
|
|
20
|
+
keys "v"
|
|
21
|
+
assert vma.gui.statnfo.css_classes.include?("mode-visual"), "badge should have mode-visual class"
|
|
22
|
+
assert_eq "VISUAL", vma.gui.statnfo.text
|
|
23
|
+
keys "esc"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# ── Pending key trail ────────────────────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
def test_keytrail_shows_pending_chord
|
|
29
|
+
keys ","
|
|
30
|
+
assert vma.gui.keytrail.text.include?(","), "keytrail should show pending chord key"
|
|
31
|
+
keys "esc"
|
|
32
|
+
assert_eq "", vma.gui.keytrail.text
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_keytrail_shows_repeat_count
|
|
36
|
+
keys "3"
|
|
37
|
+
assert vma.gui.keytrail.text.include?("3"), "keytrail should show repeat count"
|
|
38
|
+
keys "esc"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# ── Modified marker in subtitle ──────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
def test_modified_marker_appears_on_edit
|
|
44
|
+
act 'buf.insert_txt("hello")'
|
|
45
|
+
act "buf.refresh_title"
|
|
46
|
+
drain_idle
|
|
47
|
+
assert vma.gui.subtitle.text.start_with?("+ "), "subtitle should start with \"+ \" after edit"
|
|
48
|
+
assert !vma.gui.subtitle.label.include?("foreground"), "modified marker should use the theme color"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
require "tmpdir"
|
|
2
|
+
|
|
3
|
+
# Vim text objects (text_objects.rb). Each case: [text with "|" at the
|
|
4
|
+
# cursor, vim keys, expected text, expected cursor offset]. The expected
|
|
5
|
+
# values come from vim 9.1 (vim -Nu NONE); test_cases_match_real_vim checks
|
|
6
|
+
# them again when vim is installed.
|
|
7
|
+
class TestTextObjects < VmaTest
|
|
8
|
+
CASES = [
|
|
9
|
+
["foo b|ar baz", "diw", "foo baz\n", 4],
|
|
10
|
+
["foo b|ar baz", "daw", "foo baz\n", 4],
|
|
11
|
+
["foo b|ar", "daw", "foo\n", 2],
|
|
12
|
+
[" |foo", "daw", " \n", 1],
|
|
13
|
+
["foo | bar", "daw", "foo\n", 2],
|
|
14
|
+
["foo | bar", "diw", "foobar\n", 3],
|
|
15
|
+
["foo.b|ar", "diw", "foo.\n", 3],
|
|
16
|
+
["foo x.b|ar(1) z", "diW", "foo z\n", 4],
|
|
17
|
+
["foo x.b|ar(1) z", "daW", "foo z\n", 4],
|
|
18
|
+
["foo bar |\n", "daw", "foo bar \n", 8],
|
|
19
|
+
["say \"h|i\" now", "di\"", "say \"\" now\n", 5],
|
|
20
|
+
["say \"h|i\" now", "da\"", "say now\n", 4],
|
|
21
|
+
["say \"hi|\"", "da\"", "say\n", 2],
|
|
22
|
+
["\"a\" |x \"b\"", "di\"", "\"a\"\"b\"\n", 3],
|
|
23
|
+
["x |y \"a\" \"b\"", "di\"", "x y \"\" \"b\"\n", 5],
|
|
24
|
+
["a \"q\" |b", "da\"", "a \"q\" b\n", 6],
|
|
25
|
+
["it's |a 'q'", "di'", "it''q'\n", 3],
|
|
26
|
+
["a `c|d` b", "di`", "a `` b\n", 3],
|
|
27
|
+
["say \"|\"", "ci\"Z", "say \"Z\"\n", 5],
|
|
28
|
+
["a(b,|c)d", "di(", "a()d\n", 2],
|
|
29
|
+
["a(b,|c)d", "da(", "ad\n", 1],
|
|
30
|
+
["a(b,|c)d", "dib", "a()d\n", 2],
|
|
31
|
+
["a(b,|c)d", "di)", "a()d\n", 2],
|
|
32
|
+
["a|(b)d", "di(", "a()d\n", 2],
|
|
33
|
+
["x (a) |y (b)", "di(", "x (a) y ()\n", 9],
|
|
34
|
+
["x (a (|b) c)", "2di(", "x ()\n", 3],
|
|
35
|
+
["a [x|y] b", "di[", "a [] b\n", 3],
|
|
36
|
+
["a [x|y] b", "da]", "a b\n", 2],
|
|
37
|
+
["f {\n a|b\n c\n}\nz", "di{", "f {\n}\nz\n", 4],
|
|
38
|
+
["f {\n a|b\n c\n}\nz", "da{", "f \nz\n", 1],
|
|
39
|
+
["f { a|b }\nz", "diB", "f {}\nz\n", 3],
|
|
40
|
+
["x <a|b> y", "di<", "x <> y\n", 3],
|
|
41
|
+
["x\nf(a,\n |b)\nz", "di(", "x\nf()\nz\n", 4],
|
|
42
|
+
["a(|)b", "ci(Z", "a(Z)b\n", 2],
|
|
43
|
+
["f {\n a|b\n}\nz", "ci{Z", "f {\nZ\n}\nz\n", 4],
|
|
44
|
+
["x()|y", "di(", "x()y\n", 3],
|
|
45
|
+
["<a><b>x|y</b></a>", "dit", "<a><b></b></a>\n", 6],
|
|
46
|
+
["<a><b>x|y</b></a>", "dat", "<a></a>\n", 3],
|
|
47
|
+
["<a><b>xy</b>|z</a>", "dit", "<a></a>\n", 3],
|
|
48
|
+
["<a x=\"1\">|<br>q</a>", "dit", "<a x=\"1\"></a>\n", 9],
|
|
49
|
+
["<a><b>x|y</b></a>", "2dit", "<a></a>\n", 3],
|
|
50
|
+
["Hi there. This |is it. And more.", "dis", "Hi there. And more.\n", 10],
|
|
51
|
+
["Hi there. This |is it. And more.", "das", "Hi there. And more.\n", 10],
|
|
52
|
+
["Hi there. This is it. And |more.", "das", "Hi there. This is it.\n", 20],
|
|
53
|
+
["p1\np|1b\n\n\np2", "dip", "\n\np2\n", 0],
|
|
54
|
+
["p1\np|1b\n\n\np2", "dap", "p2\n", 0],
|
|
55
|
+
["p1\n\np2\np|2b", "dap", "p1\n", 0],
|
|
56
|
+
["p1\n|\n\np2", "dip", "p1\np2\n", 3],
|
|
57
|
+
["p1\n|\n\np2", "dap", "p1\n", 0],
|
|
58
|
+
["p1\np|1b\n\np2", "cipZ", "Z\n\np2\n", 0],
|
|
59
|
+
["ab|c d", "gUiw", "ABC d\n", 0],
|
|
60
|
+
["x (a|B) y", "g~i(", "x (Ab) y\n", 3],
|
|
61
|
+
["X 'A|B'", "gua'", "X 'ab'\n", 1],
|
|
62
|
+
["a [x|y] b", "vi[d", "a [] b\n", 3],
|
|
63
|
+
["foo b|ar baz", "vawd", "foo baz\n", 4],
|
|
64
|
+
["p1\np|1b\n\np2", "vipd", "\np2\n", 0],
|
|
65
|
+
["say \"h|i\" now", "va\"d", "say now\n", 4],
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
# Cases that end in Insert mode: the cursor after esc differs from vim's
|
|
69
|
+
# (vim -es stays in Insert mode), so only the text is compared.
|
|
70
|
+
def inserts?(keys)
|
|
71
|
+
keys =~ /^(\d*)c/
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def run_case(text, keys)
|
|
75
|
+
pre, rest = text.split("|", 2)
|
|
76
|
+
s = pre + rest
|
|
77
|
+
s += "\n" unless s.end_with?("\n")
|
|
78
|
+
pos = pre.size
|
|
79
|
+
# vim's Normal mode cursor can't be on the newline of a non-empty line
|
|
80
|
+
pos -= 1 if s[pos] == "\n" && pos > 0 && s[pos - 1] != "\n"
|
|
81
|
+
b = vma.buf
|
|
82
|
+
b.set_content(s)
|
|
83
|
+
b.set_pos(pos)
|
|
84
|
+
vma.kbd.set_mode(:command)
|
|
85
|
+
k = keys.chars
|
|
86
|
+
k << "esc" if inserts?(keys)
|
|
87
|
+
keys(k.join(" "))
|
|
88
|
+
[b.to_s, b.pos]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def test_cases
|
|
92
|
+
fails = []
|
|
93
|
+
CASES.each { |text, keys, want, want_pos|
|
|
94
|
+
got, got_pos = run_case(text, keys)
|
|
95
|
+
ok = got == want && (inserts?(keys) || got_pos == want_pos)
|
|
96
|
+
fails << "#{text.inspect} #{keys}: got #{got.inspect} pos #{got_pos}, vim #{want.inspect} pos #{want_pos}" if !ok
|
|
97
|
+
vma.kbd.set_mode(:command)
|
|
98
|
+
}
|
|
99
|
+
assert fails.empty?, "#{fails.size} of #{CASES.size} cases differ from vim:\n " + fails.join("\n ")
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def test_yank_word
|
|
103
|
+
run_case("x foo|bar y", "yiw")
|
|
104
|
+
assert_eq "foobar", vma.clipboard.get
|
|
105
|
+
assert_eq 2, vma.buf.pos
|
|
106
|
+
assert_buf "x foobar y\n"
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def test_yank_paragraph_is_linewise
|
|
110
|
+
run_case("p1\np|1b\n\np2", "yip")
|
|
111
|
+
assert_eq "p1\np1b\n", vma.clipboard.get
|
|
112
|
+
assert vma.registers['"'].linewise, "yip should yank whole lines"
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def test_delete_puts_text_in_clipboard
|
|
116
|
+
run_case('say "h|i" now', 'di"')
|
|
117
|
+
assert_eq "hi", vma.clipboard.get
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def test_change_enters_insert_mode
|
|
121
|
+
vma.buf.set_content("a(b,c)d\n")
|
|
122
|
+
vma.buf.set_pos(4)
|
|
123
|
+
keys("c i (")
|
|
124
|
+
assert_mode :insert
|
|
125
|
+
assert_buf "a()d\n"
|
|
126
|
+
assert_eq 2, vma.buf.pos
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def test_no_object_changes_nothing
|
|
130
|
+
run_case("plain| text", "di(")
|
|
131
|
+
assert_buf "plain text\n"
|
|
132
|
+
assert_mode :command
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def test_visual_append_bindings_still_work
|
|
136
|
+
# vimlike's Visual "a y" (copy, append to clipboard) shares the "a" prefix
|
|
137
|
+
vma.clipboard.set("old")
|
|
138
|
+
run_case("ab|cd", "v")
|
|
139
|
+
keys("l a y")
|
|
140
|
+
assert_eq "cd\nold", vma.clipboard.get
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def vim_result(text, keys)
|
|
144
|
+
pre, rest = text.split("|", 2)
|
|
145
|
+
Dir.mktmpdir { |d|
|
|
146
|
+
f = "#{d}/f.txt"
|
|
147
|
+
File.write(f, pre + rest + (rest.end_with?("\n") ? "" : "\n"))
|
|
148
|
+
k = keys.gsub("\\", "\\\\\\\\").gsub('"', '\\"')
|
|
149
|
+
system("vim", "-Nu", "NONE", "-i", "NONE", "-es", "-c", "go #{pre.bytesize + 1}",
|
|
150
|
+
"-c", "exe \"norm! #{k}\"",
|
|
151
|
+
"-c", "call writefile([line2byte(line('.'))+col('.')-2], '#{d}/p')", "-c", "wq", f)
|
|
152
|
+
[File.read(f), File.read("#{d}/p").to_i]
|
|
153
|
+
}
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def test_cases_match_real_vim
|
|
157
|
+
skip "vim not installed" unless system("command -v vim >/dev/null 2>&1")
|
|
158
|
+
fails = CASES.reject { |text, keys, want, want_pos|
|
|
159
|
+
vim_result(text, keys) == [want, want_pos]
|
|
160
|
+
}
|
|
161
|
+
assert fails.empty?, "expected values out of date for this vim: #{fails.map { |c| c[0, 2] }.inspect}"
|
|
162
|
+
end
|
|
163
|
+
end
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
# Covers the visual-selection transform envelope (transform_selection,
|
|
2
|
+
# convert_selected_text, style_transform) and the line-style helper
|
|
3
|
+
# (set_line_style) after they were refactored onto the shared
|
|
4
|
+
# transform_visual_selection / apply_style_markers helpers.
|
|
5
|
+
|
|
6
|
+
class TestTextTransforms < VmaTest
|
|
7
|
+
# Select the whole first word ("hello") in visual mode.
|
|
8
|
+
def select_first_word
|
|
9
|
+
keys("i h e l l o esc")
|
|
10
|
+
act("buf.set_pos(0)")
|
|
11
|
+
keys("v")
|
|
12
|
+
act("buf.set_pos(4)") # extend selection over "hello"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_upcase
|
|
16
|
+
select_first_word
|
|
17
|
+
act("buf.transform_selection(:upcase)")
|
|
18
|
+
assert_buf("HELLO\n")
|
|
19
|
+
assert_mode(:command)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_swapcase
|
|
23
|
+
keys("i H e L l O esc")
|
|
24
|
+
act("buf.set_pos(0)")
|
|
25
|
+
keys("v")
|
|
26
|
+
act("buf.set_pos(4)")
|
|
27
|
+
act("buf.transform_selection(:swapcase)")
|
|
28
|
+
assert_buf("hElLo\n")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_reverse
|
|
32
|
+
select_first_word
|
|
33
|
+
act("buf.transform_selection(:reverse)")
|
|
34
|
+
assert_buf("olleh\n")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_no_op_when_not_visual
|
|
38
|
+
keys("i h e l l o esc")
|
|
39
|
+
# Not in visual mode: transform_selection must be a no-op.
|
|
40
|
+
act("buf.transform_selection(:upcase)")
|
|
41
|
+
assert_buf("hello\n")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# vim-style case operators in the default (vimlike) keymap
|
|
45
|
+
def test_case_operator_word
|
|
46
|
+
keys("i f o o space b a r esc")
|
|
47
|
+
act("buf.set_pos(0)")
|
|
48
|
+
keys("g U w")
|
|
49
|
+
assert_buf("FOO bar\n")
|
|
50
|
+
assert_pos(0, 0)
|
|
51
|
+
keys("w g ~ w")
|
|
52
|
+
assert_buf("FOO BAR\n")
|
|
53
|
+
keys("g u w")
|
|
54
|
+
assert_buf("FOO bar\n")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_case_operator_line
|
|
58
|
+
keys("i f o o space b a r esc")
|
|
59
|
+
keys("g U U")
|
|
60
|
+
assert_buf("FOO BAR\n")
|
|
61
|
+
assert_pos(0, 0)
|
|
62
|
+
keys("g u u")
|
|
63
|
+
assert_buf("foo bar\n")
|
|
64
|
+
keys("g ~ ~")
|
|
65
|
+
assert_buf("FOO BAR\n")
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_toggle_case_char
|
|
69
|
+
keys("i a B c esc")
|
|
70
|
+
act("buf.set_pos(0)")
|
|
71
|
+
keys("~ ~")
|
|
72
|
+
assert_buf("Abc\n")
|
|
73
|
+
assert_pos(0, 2)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_visual_case_keys
|
|
77
|
+
select_first_word
|
|
78
|
+
keys("U")
|
|
79
|
+
assert_buf("HELLO\n")
|
|
80
|
+
act("buf.set_pos(0)")
|
|
81
|
+
keys("v")
|
|
82
|
+
act("buf.set_pos(4)")
|
|
83
|
+
keys("~")
|
|
84
|
+
assert_buf("hello\n")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_style_bold
|
|
88
|
+
select_first_word
|
|
89
|
+
act("buf.style_transform(:bold)")
|
|
90
|
+
assert_buf("⦁hello⦁\n")
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_style_italic
|
|
94
|
+
select_first_word
|
|
95
|
+
act("buf.style_transform(:italic)")
|
|
96
|
+
assert_buf("╱hello╱\n")
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def test_style_clear
|
|
100
|
+
keys("i ❙ h i ❙ esc")
|
|
101
|
+
act("buf.set_pos(0)")
|
|
102
|
+
keys("v")
|
|
103
|
+
act("buf.set_pos(3)")
|
|
104
|
+
act("buf.style_transform(:clear)")
|
|
105
|
+
assert_buf("hi\n")
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def test_line_style_title
|
|
109
|
+
keys("i h e l l o esc")
|
|
110
|
+
act("buf.set_line_style(:title)")
|
|
111
|
+
assert_buf("❙hello❙\n")
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def test_line_style_italic_then_clear
|
|
115
|
+
keys("i h e l l o esc")
|
|
116
|
+
act("buf.set_line_style(:italic)")
|
|
117
|
+
assert_buf("╱hello╱\n")
|
|
118
|
+
act("buf.set_line_style(:clear)")
|
|
119
|
+
assert_buf("hello\n")
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def test_line_style_h2_then_clear
|
|
123
|
+
keys("i h e l l o esc")
|
|
124
|
+
act("buf.set_line_style(:h2)")
|
|
125
|
+
assert_buf("◼◼ hello\n")
|
|
126
|
+
act("buf.set_line_style(:clear)")
|
|
127
|
+
assert_buf("hello\n")
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Content is set via set_content to avoid auto-indent altering the setup.
|
|
131
|
+
|
|
132
|
+
def test_indent_selection_spaces
|
|
133
|
+
act("cnf.tab.to_spaces_default = true")
|
|
134
|
+
act("cnf.tab.width = 2")
|
|
135
|
+
act('buf.set_content("x\naa\nbb\n")')
|
|
136
|
+
act("buf.set_pos(2)") # start of "aa" line
|
|
137
|
+
keys("v")
|
|
138
|
+
act("buf.set_pos(6)") # into the "bb" line
|
|
139
|
+
act("buf.indent_selection")
|
|
140
|
+
assert_buf("x\n aa\n bb\n")
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def test_unindent_selection
|
|
144
|
+
act("cnf.tab.to_spaces_default = true")
|
|
145
|
+
act("cnf.tab.width = 2")
|
|
146
|
+
act('buf.set_content("x\n aa\n bb\n")')
|
|
147
|
+
act("buf.set_pos(2)") # start of " aa" line
|
|
148
|
+
keys("v")
|
|
149
|
+
act("buf.set_pos(9)") # into the " bb" line
|
|
150
|
+
act("buf.unindent_selection")
|
|
151
|
+
assert_buf("x\naa\nbb\n")
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def test_indent_selection_first_line
|
|
155
|
+
act("cnf.tab.to_spaces_default = true")
|
|
156
|
+
act("cnf.tab.width = 2")
|
|
157
|
+
act('buf.set_content("aa\nbb\ncc\n")')
|
|
158
|
+
act("buf.set_pos(1)")
|
|
159
|
+
keys("v")
|
|
160
|
+
act("buf.set_pos(4)") # into the "bb" line
|
|
161
|
+
act("buf.indent_selection")
|
|
162
|
+
assert_buf(" aa\n bb\ncc\n")
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def test_comment_selection_first_line
|
|
166
|
+
act('buf.set_content("aa\nbb\ncc\n")')
|
|
167
|
+
act("buf.set_pos(1)")
|
|
168
|
+
keys("v")
|
|
169
|
+
act("buf.set_pos(4)") # into the "bb" line
|
|
170
|
+
act("buf.comment_selection")
|
|
171
|
+
assert_buf("// aa\n// bb\ncc\n")
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def test_indent_selection_last_line
|
|
175
|
+
act("cnf.tab.to_spaces_default = true")
|
|
176
|
+
act("cnf.tab.width = 2")
|
|
177
|
+
act('buf.set_content("aa\nbb\n")')
|
|
178
|
+
act("buf.set_pos(3)")
|
|
179
|
+
keys("v")
|
|
180
|
+
act("buf.set_pos(4)")
|
|
181
|
+
act("buf.indent_selection")
|
|
182
|
+
assert_buf("aa\n bb\n")
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def test_remove_indent_selection
|
|
186
|
+
act('buf.set_content("x\n aa\n\t\t bb\n \n cc\n dd\n")')
|
|
187
|
+
act("buf.set_pos(5)") # inside the indentation of "aa"
|
|
188
|
+
keys("v")
|
|
189
|
+
act("buf.set_pos(23)") # into the " cc" line
|
|
190
|
+
keys("g i")
|
|
191
|
+
assert_buf("x\naa\nbb\n\ncc\n dd\n")
|
|
192
|
+
assert_mode(:visual)
|
|
193
|
+
assert_eq(buf.get_current_selection, "aa\nbb\n\nc")
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def test_remove_indent_selection_partial_first_line
|
|
197
|
+
# The whole indent goes, also when the selection starts after it
|
|
198
|
+
act('buf.set_content(" aa bb\n cc\n")')
|
|
199
|
+
act("buf.set_pos(7)")
|
|
200
|
+
keys("v")
|
|
201
|
+
act("buf.set_pos(15)")
|
|
202
|
+
keys("g i")
|
|
203
|
+
assert_buf("aa bb\ncc\n")
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def test_remove_indent_selection_single_line
|
|
207
|
+
act('buf.set_content(" aa\n bb\n")')
|
|
208
|
+
act("buf.set_pos(3)")
|
|
209
|
+
keys("v")
|
|
210
|
+
keys("g i")
|
|
211
|
+
assert_buf("aa\n bb\n")
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
# g I removes only the smallest indent among the selected non-blank lines,
|
|
215
|
+
# keeping relative indentation; lines outside the selection are untouched.
|
|
216
|
+
def test_remove_common_indent_selection
|
|
217
|
+
act('buf.set_content("x\n aa\n bb\n \n cc\n dd\n")')
|
|
218
|
+
act("buf.set_pos(2)") # "aa" line
|
|
219
|
+
keys("v")
|
|
220
|
+
act("buf.set_pos(23)") # into the "cc" line
|
|
221
|
+
keys("g I")
|
|
222
|
+
assert_buf("x\naa\n bb\n\ncc\n dd\n")
|
|
223
|
+
assert_mode(:visual)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def test_remove_common_indent_tabs
|
|
227
|
+
act('buf.set_content("\t\taa\n\tbb\n")')
|
|
228
|
+
act("buf.set_pos(0)")
|
|
229
|
+
keys("v")
|
|
230
|
+
act("buf.set_pos(5)")
|
|
231
|
+
keys("g I")
|
|
232
|
+
assert_buf("\taa\nbb\n")
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
def test_remove_common_indent_noop_when_some_line_unindented
|
|
236
|
+
act('buf.set_content(" aa\nbb\n")')
|
|
237
|
+
act("buf.set_pos(0)")
|
|
238
|
+
keys("v")
|
|
239
|
+
act("buf.set_pos(6)")
|
|
240
|
+
keys("g I")
|
|
241
|
+
assert_buf(" aa\nbb\n")
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def test_remove_common_indent_current_line
|
|
245
|
+
act('buf.set_content("x\n aa\n")')
|
|
246
|
+
act("buf.set_pos(5)")
|
|
247
|
+
keys("g I")
|
|
248
|
+
assert_buf("x\naa\n")
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
# Outside visual mode g i works on the current line only; the cursor keeps
|
|
252
|
+
# its character.
|
|
253
|
+
def test_remove_indent_current_line
|
|
254
|
+
act('buf.set_content(" aa\n \t bb cc\n dd\n")')
|
|
255
|
+
act("buf.set_pos(9)") # the "c" of "cc"
|
|
256
|
+
keys("g i")
|
|
257
|
+
assert_buf(" aa\nbb cc\n dd\n")
|
|
258
|
+
assert_mode(:command)
|
|
259
|
+
assert_eq(6, buf.pos)
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
def test_remove_indent_current_line_cursor_in_indent
|
|
263
|
+
act('buf.set_content("x\n aa\n")')
|
|
264
|
+
act("buf.set_pos(3)") # inside the indentation
|
|
265
|
+
keys("g i")
|
|
266
|
+
assert_buf("x\naa\n")
|
|
267
|
+
assert_eq(2, buf.pos)
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
def test_remove_indent_current_line_last_and_unindented
|
|
271
|
+
act('buf.set_content("aa\n bb\n")')
|
|
272
|
+
act("buf.set_pos(1)")
|
|
273
|
+
keys("g i") # no indent: unchanged
|
|
274
|
+
assert_buf("aa\n bb\n")
|
|
275
|
+
act("buf.set_pos(5)")
|
|
276
|
+
keys("g i") # last line
|
|
277
|
+
assert_buf("aa\nbb\n")
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
def test_converter_on_selection
|
|
281
|
+
keys("i b space a space c esc")
|
|
282
|
+
act("buf.set_pos(0)")
|
|
283
|
+
keys("v")
|
|
284
|
+
act("buf.set_pos(4)")
|
|
285
|
+
act("buf.convert_selected_text(:sortwords)")
|
|
286
|
+
assert_buf("a b c\n")
|
|
287
|
+
assert_mode(:command)
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
# Not in visual mode: converter runs on the current line only
|
|
291
|
+
def test_converter_on_current_line
|
|
292
|
+
act("buf.insert_txt(\"x\\nb a c\\ny\")")
|
|
293
|
+
act("buf.set_pos(3)")
|
|
294
|
+
act("buf.convert_selected_text(:sortwords)")
|
|
295
|
+
assert_buf("x\na b c\ny\n")
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
# Converter result ending in a newline doesn't add a blank line
|
|
299
|
+
def test_converter_on_current_line_trailing_newline
|
|
300
|
+
act("buf.insert_txt(\"x\\n a \\ny\")")
|
|
301
|
+
act("buf.set_pos(3)")
|
|
302
|
+
act("buf.convert_selected_text(:joinlines)")
|
|
303
|
+
assert_buf("x\na\ny\n")
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
def test_converter_on_empty_line
|
|
307
|
+
act("buf.insert_txt(\"x\\n\\ny\")")
|
|
308
|
+
act("buf.set_pos(2)")
|
|
309
|
+
act("buf.convert_selected_text(:sortwords)")
|
|
310
|
+
assert_buf("x\n\ny\n")
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
def test_remove_extra_spaces_current_line
|
|
314
|
+
act("buf.insert_txt(\"x y\\n a b\\tc \\nz w\")")
|
|
315
|
+
act("buf.set_pos(6)")
|
|
316
|
+
keys("g w")
|
|
317
|
+
assert_buf("x y\n a b c\nz w\n")
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
def test_remove_extra_spaces_selection
|
|
321
|
+
act("buf.insert_txt(\"a b\\nc d \\ne f\")")
|
|
322
|
+
act("buf.set_pos(0)")
|
|
323
|
+
keys("v")
|
|
324
|
+
act("buf.set_pos(11)") # through the trailing spaces of line 2
|
|
325
|
+
keys("g w")
|
|
326
|
+
assert_buf("a b\nc d\ne f\n")
|
|
327
|
+
assert_mode(:command)
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
# sel.convert.remove_empty_lines: empty and blank lines in the selection go,
|
|
331
|
+
# the rest (and the lines outside it) stay
|
|
332
|
+
def test_remove_empty_lines_selection
|
|
333
|
+
act("buf.insert_txt(\"a\\n\\nb\\n \\nc\\n\\nd\")")
|
|
334
|
+
act("buf.set_pos(0)")
|
|
335
|
+
keys("v")
|
|
336
|
+
act("buf.set_pos(10)") # through the line end after c
|
|
337
|
+
act("sel.convert.remove_empty_lines")
|
|
338
|
+
assert_buf("a\nb\nc\n\nd\n")
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# vimamsa --tmp-user-dir: a new user dir in the temp dir, deleted on quit
|
|
2
|
+
# (lib/vimamsa/tmp_user_dir.rb, exe/vimamsa); kill / ctrl-c quit normally
|
|
3
|
+
require "open3"
|
|
4
|
+
require "rbconfig"
|
|
5
|
+
require "tmpdir"
|
|
6
|
+
|
|
7
|
+
class TestTmpUserDir < VmaTest
|
|
8
|
+
EXE = File.expand_path("../exe/vimamsa", __dir__)
|
|
9
|
+
|
|
10
|
+
def test_ours
|
|
11
|
+
d = TmpUserDir.create
|
|
12
|
+
assert TmpUserDir.ours?(d)
|
|
13
|
+
assert File.basename(d).start_with?("vimamsa-user-")
|
|
14
|
+
assert TmpUserDir.delete(d)
|
|
15
|
+
assert !File.exist?(d)
|
|
16
|
+
# never other dirs
|
|
17
|
+
Dir.mktmpdir("other-") { |o|
|
|
18
|
+
assert !TmpUserDir.ours?(o)
|
|
19
|
+
assert !TmpUserDir.delete(o)
|
|
20
|
+
assert File.exist?(o)
|
|
21
|
+
nested = File.join(o, "vimamsa-user-x")
|
|
22
|
+
FileUtils.mkdir_p(nested)
|
|
23
|
+
assert !TmpUserDir.ours?(nested), "not directly in the temp dir"
|
|
24
|
+
}
|
|
25
|
+
assert !TmpUserDir.ours?(nil)
|
|
26
|
+
assert !TmpUserDir.ours?(File.expand_path("~/.config/vimamsa"))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# A real start: the dir is made, the editor comes up in it (the intro page
|
|
30
|
+
# writes settings.rb), and a TERM quits the editor and deletes the dir
|
|
31
|
+
def test_created_and_deleted_on_quit
|
|
32
|
+
skip "needs a display" unless ENV["DISPLAY"] || ENV["WAYLAND_DISPLAY"]
|
|
33
|
+
out = +""
|
|
34
|
+
dir = nil
|
|
35
|
+
Open3.popen2e(RbConfig.ruby, EXE, "--tmp-user-dir") { |_in, oe, th|
|
|
36
|
+
reader = Thread.new { oe.each_line { |l| out << l } rescue nil }
|
|
37
|
+
t = Time.now
|
|
38
|
+
until (dir = out[/Temporary user dir \(deleted on quit\): (\S+)/, 1]) || Time.now - t > 30
|
|
39
|
+
sleep 0.05
|
|
40
|
+
end
|
|
41
|
+
assert dir, "no dir reported: #{out[-500..]}"
|
|
42
|
+
assert TmpUserDir.ours?(dir)
|
|
43
|
+
t = Time.now
|
|
44
|
+
sleep 0.1 until File.exist?(File.join(dir, "settings.rb")) || !th.alive? || Time.now - t > 60
|
|
45
|
+
assert File.exist?(File.join(dir, "custom.rb")), "editor didn't start in #{dir}: #{out[-800..]}"
|
|
46
|
+
assert File.exist?(File.join(dir, "settings.rb")), "intro not shown at start"
|
|
47
|
+
Process.kill("TERM", th.pid)
|
|
48
|
+
t = Time.now
|
|
49
|
+
sleep 0.1 while th.alive? && Time.now - t < 20
|
|
50
|
+
if th.alive?
|
|
51
|
+
Process.kill("KILL", th.pid)
|
|
52
|
+
assert false, "editor didn't quit on TERM"
|
|
53
|
+
end
|
|
54
|
+
reader.join(2)
|
|
55
|
+
}
|
|
56
|
+
assert !File.exist?(dir), "#{dir} not deleted on quit"
|
|
57
|
+
ensure
|
|
58
|
+
TmpUserDir.delete(dir) if dir
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# A dir with a crash report stays (the report would be lost otherwise)
|
|
62
|
+
def test_kept_with_crash_report
|
|
63
|
+
d = TmpUserDir.create
|
|
64
|
+
FileUtils.mkdir_p(File.join(d, "crash"))
|
|
65
|
+
File.write(File.join(d, "crash", "stderr.log"), "log")
|
|
66
|
+
File.write(File.join(d, "crash", "crash_20261121_000000_1.txt"), "report")
|
|
67
|
+
assert !TmpUserDir.delete(d)
|
|
68
|
+
assert File.exist?(File.join(d, "crash", "crash_20261121_000000_1.txt"))
|
|
69
|
+
FileUtils.rm_f(File.join(d, "crash", "crash_20261121_000000_1.txt"))
|
|
70
|
+
assert TmpUserDir.delete(d), "only stderr.log: deleted"
|
|
71
|
+
assert !File.exist?(d)
|
|
72
|
+
ensure
|
|
73
|
+
FileUtils.rm_rf(d) if d && File.exist?(d)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_help_mentions_it
|
|
77
|
+
assert Vimamsa::CLI_USAGE.include?("--tmp-user-dir")
|
|
78
|
+
end
|
|
79
|
+
end
|