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
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# buf.run.ruby (run_ruby.rb): the file run with Ruby in a separate process,
|
|
2
|
+
# its output (stdout and stderr in order) in a buffer
|
|
3
|
+
require "tmpdir"
|
|
4
|
+
|
|
5
|
+
class TestRunRuby < VmaTest
|
|
6
|
+
def outputs
|
|
7
|
+
vma.buffers.list.select { |b| b.instance_variable_get(:@ruby_output_of) }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# Runs b and returns the output buffer
|
|
11
|
+
def run_and_wait(b)
|
|
12
|
+
before = outputs.map(&:id)
|
|
13
|
+
act "buf.run.ruby"
|
|
14
|
+
t = Time.now
|
|
15
|
+
o = nil
|
|
16
|
+
until (o = outputs.find { |x| !before.include?(x.id) }) || Time.now - t > 20
|
|
17
|
+
drain_idle
|
|
18
|
+
sleep 0.02
|
|
19
|
+
end
|
|
20
|
+
assert o, "no output buffer"
|
|
21
|
+
o
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_runs_file_and_shows_output
|
|
25
|
+
Dir.mktmpdir("vma-run") { |d|
|
|
26
|
+
f = File.join(d, "hello.rb")
|
|
27
|
+
File.write(f, "puts 1 + 1\n$stderr.puts 'to stderr'\nputs File.basename(__FILE__)\n")
|
|
28
|
+
b = open_new_file(f)
|
|
29
|
+
o = run_and_wait(b)
|
|
30
|
+
assert o.to_s.start_with?("# ruby #{f} (exit 0,"), o.to_s.lines.first
|
|
31
|
+
assert o.to_s.include?("2\nto stderr\nhello.rb\n"), o.to_s
|
|
32
|
+
assert vma.buf.equal?(o)
|
|
33
|
+
vma.buffers.close_buffer(o.id)
|
|
34
|
+
vma.buffers.close_buffer(b.id)
|
|
35
|
+
}
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Unsaved changes are saved first; a second run replaces the output
|
|
39
|
+
def test_saves_first_and_replaces_output
|
|
40
|
+
Dir.mktmpdir("vma-run") { |d|
|
|
41
|
+
f = File.join(d, "edit.rb")
|
|
42
|
+
File.write(f, "puts :old\n")
|
|
43
|
+
b = open_new_file(f)
|
|
44
|
+
o1 = run_and_wait(b)
|
|
45
|
+
vma.buffers.set_current_buffer_by_id(b.id)
|
|
46
|
+
b.set_pos(0)
|
|
47
|
+
keys "d d"
|
|
48
|
+
keys "i p u t s space : n e w esc"
|
|
49
|
+
o2 = run_and_wait(b)
|
|
50
|
+
assert_eq "puts :new\n", File.read(f), "not saved before running"
|
|
51
|
+
assert o2.to_s.include?("new\n"), o2.to_s
|
|
52
|
+
assert vma.buffers.list.none? { |x| x.equal?(o1) }, "old output buffer still open"
|
|
53
|
+
assert_eq 1, outputs.size
|
|
54
|
+
vma.buffers.close_buffer(o2.id)
|
|
55
|
+
vma.buffers.close_buffer(b.id)
|
|
56
|
+
}
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# An error: the exit status and the message with its file:line
|
|
60
|
+
def test_error_and_buffer_without_file
|
|
61
|
+
b = create_new_buffer("puts :before\nraise 'boom'\n", "runtest")
|
|
62
|
+
o = run_and_wait(b)
|
|
63
|
+
assert o.to_s.lines.first.include?("exit 1"), o.to_s.lines.first
|
|
64
|
+
assert o.to_s.include?("before\n"), o.to_s
|
|
65
|
+
assert o.to_s =~ /vimamsa-run.*\.rb:2:in .*boom/, o.to_s
|
|
66
|
+
vma.buffers.close_buffer(o.id)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# The action search lists id and description in columns of their own
|
|
70
|
+
def test_action_search_columns
|
|
71
|
+
rows = vma.actions.search_actions_update_callback("bufrunruby")
|
|
72
|
+
row = rows.find { |_k, id, _d| id == "buf.run.ruby" }
|
|
73
|
+
assert row, rows.first(3).inspect
|
|
74
|
+
assert_eq 3, row.size
|
|
75
|
+
assert row[2].start_with?("Run the file as Ruby"), row.inspect
|
|
76
|
+
end
|
|
77
|
+
end
|
data/tests/test_startup_file.rb
CHANGED
|
@@ -11,7 +11,7 @@ class TestStartupFile < VmaTest
|
|
|
11
11
|
File.write(startup, "startup\n")
|
|
12
12
|
File.write(a, "a\n")
|
|
13
13
|
File.write(b, "b\n")
|
|
14
|
-
session =
|
|
14
|
+
session = get_data_path("session.txt")
|
|
15
15
|
File.write(session, "#{a}\n#{b}\n")
|
|
16
16
|
|
|
17
17
|
open_new_file(startup)
|
data/tests/test_text_objects.rb
CHANGED
|
@@ -109,7 +109,7 @@ class TestTextObjects < VmaTest
|
|
|
109
109
|
def test_yank_paragraph_is_linewise
|
|
110
110
|
run_case("p1\np|1b\n\np2", "yip")
|
|
111
111
|
assert_eq "p1\np1b\n", vma.clipboard.get
|
|
112
|
-
assert vma.
|
|
112
|
+
assert vma.registers['"'].linewise, "yip should yank whole lines"
|
|
113
113
|
end
|
|
114
114
|
|
|
115
115
|
def test_delete_puts_text_in_clipboard
|
|
@@ -326,4 +326,16 @@ class TestTextTransforms < VmaTest
|
|
|
326
326
|
assert_buf("a b\nc d\ne f\n")
|
|
327
327
|
assert_mode(:command)
|
|
328
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
|
+
|
|
329
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
|
data/tests/test_tts.rb
CHANGED
|
@@ -5,7 +5,7 @@ class TestTts < VmaTest
|
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
def ensure_disabled
|
|
8
|
-
tts_disable if vma.actions.include?(
|
|
8
|
+
tts_disable if vma.actions.include?("tts.speak_selection")
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
# --- _info ---
|
|
@@ -23,10 +23,10 @@ class TestTts < VmaTest
|
|
|
23
23
|
ensure_disabled
|
|
24
24
|
load_tts
|
|
25
25
|
tts_init
|
|
26
|
-
assert vma.actions.include?(
|
|
27
|
-
assert vma.actions.include?(
|
|
28
|
-
assert vma.gui.menu.module_action?(
|
|
29
|
-
assert vma.gui.menu.module_action?(
|
|
26
|
+
assert vma.actions.include?("tts.speak_selection"), "speak action not registered"
|
|
27
|
+
assert vma.actions.include?("tts.stop"), "stop action not registered"
|
|
28
|
+
assert vma.gui.menu.module_action?("tts.speak_selection"), "speak menu item missing"
|
|
29
|
+
assert vma.gui.menu.module_action?("tts.stop"), "stop menu item missing"
|
|
30
30
|
ensure
|
|
31
31
|
tts_disable
|
|
32
32
|
end
|
|
@@ -36,9 +36,9 @@ class TestTts < VmaTest
|
|
|
36
36
|
load_tts
|
|
37
37
|
tts_init
|
|
38
38
|
tts_disable
|
|
39
|
-
assert !vma.actions.include?(
|
|
40
|
-
assert !vma.actions.include?(
|
|
41
|
-
assert !vma.gui.menu.module_action?(
|
|
39
|
+
assert !vma.actions.include?("tts.speak_selection"), "speak action still registered"
|
|
40
|
+
assert !vma.actions.include?("tts.stop"), "stop action still registered"
|
|
41
|
+
assert !vma.gui.menu.module_action?("tts.speak_selection"), "speak menu still present"
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def test_init_disable_cycle
|
|
@@ -46,9 +46,9 @@ class TestTts < VmaTest
|
|
|
46
46
|
load_tts
|
|
47
47
|
3.times do |i|
|
|
48
48
|
tts_init
|
|
49
|
-
assert vma.actions.include?(
|
|
49
|
+
assert vma.actions.include?("tts.speak_selection"), "speak missing after init (cycle #{i})"
|
|
50
50
|
tts_disable
|
|
51
|
-
assert !vma.actions.include?(
|
|
51
|
+
assert !vma.actions.include?("tts.speak_selection"), "speak present after disable (cycle #{i})"
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
data/tests/test_undo.rb
CHANGED
|
@@ -4,47 +4,47 @@ class TestUndo < VmaTest
|
|
|
4
4
|
|
|
5
5
|
def test_undo_restores_empty_buffer
|
|
6
6
|
act 'buf.insert_txt("hello")'
|
|
7
|
-
act
|
|
7
|
+
act "undo.last"
|
|
8
8
|
assert_buf "\n"
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def test_undo_on_empty_buffer_is_noop
|
|
12
|
-
act
|
|
12
|
+
act "undo.last"
|
|
13
13
|
assert_buf "\n"
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def test_redo_after_undo
|
|
17
17
|
act 'buf.insert_txt("hello")'
|
|
18
|
-
act
|
|
19
|
-
act
|
|
18
|
+
act "undo.last"
|
|
19
|
+
act "undo.redo"
|
|
20
20
|
assert_buf "hello\n"
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def test_redo_on_empty_stack_is_noop
|
|
24
|
-
act
|
|
25
|
-
act
|
|
24
|
+
act "undo.last"
|
|
25
|
+
act "undo.redo"
|
|
26
26
|
assert_buf "\n"
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def test_new_edit_clears_redo_stack
|
|
30
30
|
act 'buf.insert_txt("hello")'
|
|
31
|
-
act
|
|
31
|
+
act "undo.last"
|
|
32
32
|
assert_buf "\n"
|
|
33
33
|
act 'buf.insert_txt("world")'
|
|
34
34
|
# redo stack was cleared — redo should be a no-op
|
|
35
|
-
act
|
|
35
|
+
act "undo.redo"
|
|
36
36
|
assert_buf "world\n"
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def test_undo_delete_char
|
|
40
40
|
act 'buf.insert_txt("abcde")'
|
|
41
|
-
act
|
|
41
|
+
act "move.buf.start"
|
|
42
42
|
vma.buf.new_undo_group
|
|
43
|
-
act
|
|
44
|
-
act
|
|
43
|
+
act "edit.delete.char"
|
|
44
|
+
act "edit.delete.char"
|
|
45
45
|
vma.buf.new_undo_group
|
|
46
46
|
assert_buf "cde\n"
|
|
47
|
-
act
|
|
47
|
+
act "undo.last"
|
|
48
48
|
assert_buf "abcde\n"
|
|
49
49
|
end
|
|
50
50
|
|
|
@@ -52,11 +52,11 @@ class TestUndo < VmaTest
|
|
|
52
52
|
act 'buf.insert_txt("first\n")'
|
|
53
53
|
act 'buf.insert_txt("second")'
|
|
54
54
|
vma.buf.new_undo_group
|
|
55
|
-
act
|
|
56
|
-
act
|
|
55
|
+
act "move.buf.start"
|
|
56
|
+
act "edit.delete.line"
|
|
57
57
|
vma.buf.new_undo_group
|
|
58
58
|
assert_buf "second\n"
|
|
59
|
-
act
|
|
59
|
+
act "undo.last"
|
|
60
60
|
assert_buf "first\nsecond\n"
|
|
61
61
|
end
|
|
62
62
|
|
|
@@ -66,13 +66,13 @@ class TestUndo < VmaTest
|
|
|
66
66
|
act 'buf.insert_txt(" second")'
|
|
67
67
|
assert_buf "first second\n"
|
|
68
68
|
|
|
69
|
-
act
|
|
69
|
+
act "undo.last"
|
|
70
70
|
assert_buf "first\n"
|
|
71
|
-
act
|
|
71
|
+
act "undo.redo"
|
|
72
72
|
assert_buf "first second\n"
|
|
73
|
-
act
|
|
73
|
+
act "undo.last"
|
|
74
74
|
assert_buf "first\n"
|
|
75
|
-
act
|
|
75
|
+
act "undo.last"
|
|
76
76
|
assert_buf "\n"
|
|
77
77
|
end
|
|
78
78
|
|
|
@@ -87,11 +87,11 @@ class TestUndo < VmaTest
|
|
|
87
87
|
vma.buf.new_undo_group
|
|
88
88
|
assert_buf "aaabbbccc\n"
|
|
89
89
|
|
|
90
|
-
act
|
|
90
|
+
act "undo.last"
|
|
91
91
|
assert_buf "aaabbb\n"
|
|
92
|
-
act
|
|
92
|
+
act "undo.last"
|
|
93
93
|
assert_buf "aaa\n"
|
|
94
|
-
act
|
|
94
|
+
act "undo.last"
|
|
95
95
|
assert_buf "\n"
|
|
96
96
|
end
|
|
97
97
|
|
|
@@ -103,9 +103,9 @@ class TestUndo < VmaTest
|
|
|
103
103
|
keys "i space w o r l d esc"
|
|
104
104
|
assert_buf "hello world\n"
|
|
105
105
|
|
|
106
|
-
act
|
|
106
|
+
act "undo.last"
|
|
107
107
|
assert_buf "hello\n" # second insert session (" world") undone
|
|
108
|
-
act
|
|
108
|
+
act "undo.last"
|
|
109
109
|
assert_buf "\n" # first insert session ("hello") undone
|
|
110
110
|
end
|
|
111
111
|
|
|
@@ -121,7 +121,7 @@ class TestUndo < VmaTest
|
|
|
121
121
|
drain_idle
|
|
122
122
|
assert_buf "line1\nline2\nline3\n"
|
|
123
123
|
|
|
124
|
-
act
|
|
124
|
+
act "undo.last"
|
|
125
125
|
assert_buf "\n"
|
|
126
126
|
end
|
|
127
127
|
|
|
@@ -133,9 +133,9 @@ class TestUndo < VmaTest
|
|
|
133
133
|
drain_idle
|
|
134
134
|
assert_buf "abcdef\n"
|
|
135
135
|
|
|
136
|
-
act
|
|
136
|
+
act "undo.last"
|
|
137
137
|
assert_buf "abc\n"
|
|
138
|
-
act
|
|
138
|
+
act "undo.last"
|
|
139
139
|
assert_buf "\n"
|
|
140
140
|
end
|
|
141
141
|
|
|
@@ -147,9 +147,9 @@ class TestUndo < VmaTest
|
|
|
147
147
|
drain_idle
|
|
148
148
|
assert_buf "base appended\n"
|
|
149
149
|
|
|
150
|
-
act
|
|
150
|
+
act "undo.last"
|
|
151
151
|
assert_buf "base\n"
|
|
152
|
-
act
|
|
152
|
+
act "undo.last"
|
|
153
153
|
assert_buf "\n"
|
|
154
154
|
end
|
|
155
155
|
|
|
@@ -165,9 +165,9 @@ class TestUndo < VmaTest
|
|
|
165
165
|
drain_idle
|
|
166
166
|
assert_buf "foofoo\n"
|
|
167
167
|
|
|
168
|
-
act
|
|
168
|
+
act "undo.last" # undo the macro run
|
|
169
169
|
assert_buf "foo\n"
|
|
170
|
-
act
|
|
170
|
+
act "undo.last" # undo the recording-time insertion
|
|
171
171
|
assert_buf "\n"
|
|
172
172
|
end
|
|
173
173
|
|
|
@@ -176,9 +176,9 @@ class TestUndo < VmaTest
|
|
|
176
176
|
drain_idle
|
|
177
177
|
assert_buf "hello\n"
|
|
178
178
|
|
|
179
|
-
act
|
|
179
|
+
act "undo.last"
|
|
180
180
|
assert_buf "\n"
|
|
181
|
-
act
|
|
181
|
+
act "undo.redo"
|
|
182
182
|
assert_buf "hello\n"
|
|
183
183
|
end
|
|
184
184
|
|
|
@@ -194,7 +194,7 @@ class TestUndo < VmaTest
|
|
|
194
194
|
drain_idle
|
|
195
195
|
assert_buf " world\n"
|
|
196
196
|
|
|
197
|
-
act
|
|
197
|
+
act "undo.last"
|
|
198
198
|
assert_buf "hello world\n"
|
|
199
199
|
end
|
|
200
200
|
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Config dir and data dir (user_dirs.rb): the XDG defaults, --user-dir
|
|
2
|
+
# keeping both in one dir, which files go where, and the one-time move of
|
|
3
|
+
# the files of older versions
|
|
4
|
+
require "tmpdir"
|
|
5
|
+
|
|
6
|
+
class TestUserDirs < VmaTest
|
|
7
|
+
REPO = File.expand_path("..", __dir__)
|
|
8
|
+
|
|
9
|
+
def with_env(vars)
|
|
10
|
+
old = vars.keys.to_h { |k| [k, ENV[k]] }
|
|
11
|
+
vars.each { |k, v| ENV[k] = v }
|
|
12
|
+
yield
|
|
13
|
+
ensure
|
|
14
|
+
old.each { |k, v| ENV[k] = v }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_xdg_defaults
|
|
18
|
+
with_env("XDG_CONFIG_HOME" => nil, "XDG_DATA_HOME" => nil) {
|
|
19
|
+
assert_eq File.expand_path("~/.config/vimamsa"), UserDirs.default_config_dir
|
|
20
|
+
assert_eq File.expand_path("~/.local/share/vimamsa"), UserDirs.default_data_dir
|
|
21
|
+
assert_eq File.expand_path("~/.local/share/vimamsa"), UserDirs.data_dir_for("~/.config/vimamsa")
|
|
22
|
+
}
|
|
23
|
+
with_env("XDG_CONFIG_HOME" => "/tmp/xc", "XDG_DATA_HOME" => "/tmp/xd") {
|
|
24
|
+
assert_eq "/tmp/xc/vimamsa", UserDirs.default_config_dir
|
|
25
|
+
assert_eq "/tmp/xd/vimamsa", UserDirs.data_dir_for("/tmp/xc/vimamsa")
|
|
26
|
+
}
|
|
27
|
+
# --user-dir: data in the same dir
|
|
28
|
+
assert_eq "/tmp/somedir", UserDirs.data_dir_for("/tmp/somedir")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# The test run uses its own user dir, and data goes there too
|
|
32
|
+
def test_test_run_isolated
|
|
33
|
+
assert !UserDirs.default_config_dir?(vma_user_dir)
|
|
34
|
+
assert_eq File.expand_path(vma_user_dir), File.expand_path(vma_data_dir)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# With separate dirs, generated files go to the data dir and the user's
|
|
38
|
+
# files to the config dir
|
|
39
|
+
def test_files_go_to_their_dirs
|
|
40
|
+
Dir.mktmpdir { |d|
|
|
41
|
+
old = $vma_data_dir
|
|
42
|
+
$vma_data_dir = d
|
|
43
|
+
begin
|
|
44
|
+
vma.marshal_save("file_index", [])
|
|
45
|
+
assert File.exist?(File.join(d, "file_index")), "file_index not in the data dir"
|
|
46
|
+
assert_eq File.join(d, "file_history"), vma.var_file_path("file_history")
|
|
47
|
+
assert_eq get_dot_path("bookmarks"), vma.var_file_path("bookmarks")
|
|
48
|
+
assert_eq get_dot_path("named_macros"), vma.var_file_path("named_macros")
|
|
49
|
+
vma.save_session
|
|
50
|
+
assert File.exist?(File.join(d, "session.txt")), "session not in the data dir"
|
|
51
|
+
assert_eq File.join(d, "crash"), Vimamsa::CrashHandler.crash_dir
|
|
52
|
+
f = File.join(d, "afile.txt")
|
|
53
|
+
File.write(f, "x\n")
|
|
54
|
+
jump_to_file(f)
|
|
55
|
+
b = vma.buf
|
|
56
|
+
assert_eq f, b.fname
|
|
57
|
+
b.backup # written on a thread
|
|
58
|
+
t = Time.now
|
|
59
|
+
sleep 0.02 while Dir[File.join(d, "backup", "*afile.txt_*")].empty? && Time.now - t < 2
|
|
60
|
+
assert Dir[File.join(d, "backup", "*afile.txt_*")].any?, "backup not in the data dir"
|
|
61
|
+
vma.buffers.close_buffer(b.id)
|
|
62
|
+
ensure
|
|
63
|
+
$vma_data_dir = old
|
|
64
|
+
end
|
|
65
|
+
}
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# No code uses fixed paths (~/.vimamsa, ~/.config/vimamsa): they would
|
|
69
|
+
# skip --user-dir, and the tests would touch the real user's files.
|
|
70
|
+
# user_dirs.rb names the old places, to move their files.
|
|
71
|
+
def test_no_fixed_user_paths
|
|
72
|
+
files = Dir[File.join(REPO, "{lib,modules}/**/*.rb")] + [File.join(REPO, "exe/vimamsa")]
|
|
73
|
+
files -= [File.join(REPO, "lib/vimamsa/user_dirs.rb")]
|
|
74
|
+
bad = files.flat_map { |f|
|
|
75
|
+
File.readlines(f).each_with_index.map { |l, i|
|
|
76
|
+
next if l.strip.start_with?("#")
|
|
77
|
+
"#{f.sub(REPO + "/", "")}:#{i + 1}: #{l.strip}" if l =~ %r{["']~/\.(vimamsa|config/vimamsa|config/\.vimamsa)}
|
|
78
|
+
}.compact
|
|
79
|
+
}
|
|
80
|
+
assert bad.empty?, "fixed user paths:\n#{bad.join("\n")}"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_migrate
|
|
84
|
+
Dir.mktmpdir { |t|
|
|
85
|
+
conf, data = File.join(t, "conf"), File.join(t, "data")
|
|
86
|
+
legacy, lmacro = File.join(t, "legacy"), File.join(t, "lmacro")
|
|
87
|
+
w = ->(path, txt = "x") { FileUtils.mkdir_p(File.dirname(path)); File.write(path, txt) }
|
|
88
|
+
w.(File.join(conf, "session.txt"), "s")
|
|
89
|
+
w.(File.join(conf, "file_history"))
|
|
90
|
+
w.(File.join(conf, "bookmarks"))
|
|
91
|
+
w.(File.join(conf, "settings.rb"))
|
|
92
|
+
w.(File.join(conf, "backup", "a_1"))
|
|
93
|
+
w.(File.join(conf, "crash", "stderr.log"), "old log")
|
|
94
|
+
FileUtils.mkdir_p(File.join(conf, "listen"))
|
|
95
|
+
w.(File.join(data, "crash", "stderr.log"), "new log") # written at start, before the move
|
|
96
|
+
w.(File.join(legacy, "cmd_history.txt"), ":e x")
|
|
97
|
+
w.(File.join(legacy, "backup", "c_1"))
|
|
98
|
+
w.(File.join(legacy, "backup", "a_1"), "older a")
|
|
99
|
+
w.(File.join(legacy, "file_history"), "older")
|
|
100
|
+
w.(File.join(lmacro, "macro_q.rb"), "macro")
|
|
101
|
+
moved = UserDirs.migrate(config_dir: conf, data_dir: data, legacy_dir: legacy, legacy_macro_dir: lmacro)
|
|
102
|
+
%w[session.txt file_history cmd_history.txt backup/a_1 backup/c_1].each { |n|
|
|
103
|
+
assert File.exist?(File.join(data, n)), "#{n} not moved"
|
|
104
|
+
}
|
|
105
|
+
assert_eq "s", File.read(File.join(data, "session.txt"))
|
|
106
|
+
assert_eq "x", File.read(File.join(data, "backup", "a_1")), "the config dir's backup wins"
|
|
107
|
+
assert_eq "older a", File.read(File.join(legacy, "backup", "a_1")), "a file in both places left as it was"
|
|
108
|
+
assert_eq "new log", File.read(File.join(data, "crash", "stderr.log"))
|
|
109
|
+
assert File.exist?(File.join(conf, "crash", "stderr.log")), "the old log is kept"
|
|
110
|
+
assert File.exist?(File.join(legacy, "file_history")), "older copies in ~/.vimamsa stay"
|
|
111
|
+
assert File.exist?(File.join(conf, "settings.rb")) && File.exist?(File.join(conf, "bookmarks")), "config files moved"
|
|
112
|
+
assert File.exist?(File.join(conf, "macro_q.rb")), "saved macro not moved to the config dir"
|
|
113
|
+
assert !File.exist?(File.join(conf, "listen")), "empty old listen dir left"
|
|
114
|
+
assert !File.exist?(File.join(conf, "session.txt"))
|
|
115
|
+
assert moved.include?([File.join(conf, "session.txt"), File.join(data, "session.txt")])
|
|
116
|
+
# once: a second run moves nothing
|
|
117
|
+
assert_eq [], UserDirs.migrate(config_dir: conf, data_dir: data, legacy_dir: legacy, legacy_macro_dir: lmacro)
|
|
118
|
+
# one dir (--user-dir): nothing moves
|
|
119
|
+
assert_eq [], UserDirs.migrate(config_dir: conf, data_dir: conf, legacy_dir: legacy, legacy_macro_dir: lmacro)
|
|
120
|
+
}
|
|
121
|
+
end
|
|
122
|
+
end
|