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,116 @@
|
|
|
1
|
+
require_relative "support/virtual_keyboard"
|
|
2
|
+
|
|
3
|
+
# True end-to-end test of the ":" command line: a uinput virtual keyboard types
|
|
4
|
+
# real key events (kernel -> compositor -> this GTK window), verifying that
|
|
5
|
+
# focus enters the command line entry — via the @entry_has_focus bypass in the
|
|
6
|
+
# window key controller — and that a shell command executes into a new buffer.
|
|
7
|
+
#
|
|
8
|
+
# Skips when /dev/uinput is not writable, xmodmap is missing, or the editor
|
|
9
|
+
# window is not the focused window (never type into someone else's window).
|
|
10
|
+
class TestE2eCmdline < VmaTest
|
|
11
|
+
def test_colon_focuses_cmdline_and_executes_shell_command
|
|
12
|
+
with_vkb do |kb|
|
|
13
|
+
assert_mode :command
|
|
14
|
+
orig_buf_id = vma.buf.id
|
|
15
|
+
orig_text = vma.buf.to_s
|
|
16
|
+
|
|
17
|
+
kb.type(":")
|
|
18
|
+
assert wait_until(3) { stack.visible_child_name == "cmdline" },
|
|
19
|
+
"':' key opens the command line"
|
|
20
|
+
assert focus_inside?(vma.gui.cmd_line.entry),
|
|
21
|
+
"keyboard focus is inside the command line entry"
|
|
22
|
+
|
|
23
|
+
kb.type("!ls")
|
|
24
|
+
assert wait_until(3) { vma.gui.cmd_line.entry.text == "!ls" },
|
|
25
|
+
"typed keys land in the entry (entry has #{vma.gui.cmd_line.entry.text.inspect})"
|
|
26
|
+
assert_eq orig_text, vma.buf.to_s, "editor buffer untouched while typing in the command line"
|
|
27
|
+
|
|
28
|
+
kb.tap_keysym("Return")
|
|
29
|
+
ok = wait_until(5) {
|
|
30
|
+
vma.buf.id != orig_buf_id &&
|
|
31
|
+
Dir.children(Dir.pwd).any? { |f| vma.buf.to_s.include?(f) }
|
|
32
|
+
}
|
|
33
|
+
assert ok, "!ls output opened in a new buffer (current buffer starts: #{vma.buf.to_s[0, 80].inspect})"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_escape_closes_and_returns_focus_to_editor
|
|
38
|
+
with_vkb do |kb|
|
|
39
|
+
assert_mode :command
|
|
40
|
+
kb.type(":")
|
|
41
|
+
assert wait_until(3) { stack.visible_child_name == "cmdline" },
|
|
42
|
+
"':' key opens the command line"
|
|
43
|
+
|
|
44
|
+
kb.tap_keysym("Escape")
|
|
45
|
+
assert wait_until(3) { stack.visible_child_name != "cmdline" },
|
|
46
|
+
"Escape closes the command line"
|
|
47
|
+
assert !focus_inside?(vma.gui.cmd_line.entry), "focus left the entry"
|
|
48
|
+
|
|
49
|
+
# Keys must reach the editor again: 'i' should enter insert mode
|
|
50
|
+
kb.type("i")
|
|
51
|
+
assert wait_until(3) { vma.kbd.get_mode == :insert }, "editor receives keys again after Escape"
|
|
52
|
+
keys("esc")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
# Guard preconditions, open/close the uinput device around the block.
|
|
59
|
+
def with_vkb
|
|
60
|
+
# uinput events go to the real seat's focused window. Only type when this
|
|
61
|
+
# app is itself on the real Wayland session — never on a headless backend
|
|
62
|
+
# (Broadway/Xvfb), where the keystrokes would land in some other program.
|
|
63
|
+
# gtype.name: ruby-gnome has no named Ruby class for some backends.
|
|
64
|
+
backend = Gdk::Display.default&.gtype&.name.to_s
|
|
65
|
+
if !backend.include?("Wayland")
|
|
66
|
+
skip "not on a real Wayland seat (#{backend})"
|
|
67
|
+
end
|
|
68
|
+
skip "no writable /dev/uinput" if !VirtualKeyboard.available?
|
|
69
|
+
skip "xmodmap not available" if !KeyTyper.available?
|
|
70
|
+
vkb = nil
|
|
71
|
+
vma.gui.window.present
|
|
72
|
+
# Wayland won't let a non-interactively launched window steal focus. In the
|
|
73
|
+
# semi-interactive VM mode (VMA_E2E_INTERACTIVE), wait longer and prompt for a
|
|
74
|
+
# single click; a real user click legitimately focuses the window, after which
|
|
75
|
+
# every following test in the run finds it already active (no more clicks).
|
|
76
|
+
focus_wait = ENV["VMA_E2E_INTERACTIVE"] ? 90 : 3
|
|
77
|
+
if ENV["VMA_E2E_INTERACTIVE"] && !vma.gui.window.active?
|
|
78
|
+
puts "\n>>> [E2E] Click the vimamsa window in the VM to give it focus " \
|
|
79
|
+
"(waiting up to #{focus_wait}s)…"
|
|
80
|
+
$stdout.flush
|
|
81
|
+
end
|
|
82
|
+
if !wait_until(focus_wait) { vma.gui.window.active? }
|
|
83
|
+
skip "editor window is not focused; typing would go to another window"
|
|
84
|
+
end
|
|
85
|
+
vkb = VirtualKeyboard.new.open
|
|
86
|
+
yield KeyTyper.new(vkb)
|
|
87
|
+
ensure
|
|
88
|
+
vkb&.close
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Poll cond while letting the GTK main loop process the incoming key events.
|
|
92
|
+
def wait_until(timeout)
|
|
93
|
+
t0 = Time.now
|
|
94
|
+
loop do
|
|
95
|
+
drain_idle
|
|
96
|
+
return true if yield
|
|
97
|
+
return false if Time.now - t0 > timeout
|
|
98
|
+
sleep 0.05
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def stack
|
|
103
|
+
vma.gui.instance_variable_get(:@minibuf_stack)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# True if the window's focus widget is `widget` or one of its descendants
|
|
107
|
+
# (Gtk::Entry keeps focus on an internal GtkText child).
|
|
108
|
+
def focus_inside?(widget)
|
|
109
|
+
f = vma.gui.window.focus_widget
|
|
110
|
+
while f
|
|
111
|
+
return true if f == widget
|
|
112
|
+
f = f.parent
|
|
113
|
+
end
|
|
114
|
+
false
|
|
115
|
+
end
|
|
116
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
require_relative "support/virtual_mic"
|
|
2
|
+
|
|
3
|
+
# End-to-end dictation test driven by a virtual microphone (see
|
|
4
|
+
# support/virtual_mic.rb): a synthesized phrase is fed into the real dictation
|
|
5
|
+
# recorder pipeline, transcribed by the Whisper worker, and asserted to land in
|
|
6
|
+
# the buffer.
|
|
7
|
+
#
|
|
8
|
+
# SKIPPED BY DEFAULT. It is slow (loads a Whisper model) and needs a speech
|
|
9
|
+
# synth tool + faster-whisper, so it only runs when opted in:
|
|
10
|
+
#
|
|
11
|
+
# VMA_E2E_DICTATION=1 ruby exe/run_tests.rb e2e_dictation
|
|
12
|
+
#
|
|
13
|
+
# The first run also downloads the tiny Whisper model (~75 MB); allow time.
|
|
14
|
+
class TestE2eDictation < VmaTest
|
|
15
|
+
PHRASE = "the quick brown fox jumps over the lazy dog"
|
|
16
|
+
# Any one of these words appearing in the transcript proves ASR worked. Kept
|
|
17
|
+
# loose on purpose — Whisper output is not deterministic word-for-word.
|
|
18
|
+
EXPECT = %w[quick brown fox jumps lazy dog].freeze
|
|
19
|
+
TIMEOUT = 180 # seconds: model load + CPU transcription of a short clip
|
|
20
|
+
|
|
21
|
+
def test_dictation_transcribes_virtual_mic
|
|
22
|
+
reason = VirtualMic.unmet_requirement
|
|
23
|
+
skip reason if reason
|
|
24
|
+
ensure_dictation_loaded or return skip("dictation module unavailable")
|
|
25
|
+
|
|
26
|
+
mic = VirtualMic.new(PHRASE).open
|
|
27
|
+
with_dictation_config(mic.gst_source) do
|
|
28
|
+
buf.set_pos(buf.size - 1)
|
|
29
|
+
before = buf.to_s
|
|
30
|
+
|
|
31
|
+
s = dictation_session
|
|
32
|
+
# Respawn the worker so it picks up the fast test model config.
|
|
33
|
+
$vma_dictation_worker&.stop
|
|
34
|
+
|
|
35
|
+
unless s.start(nil)
|
|
36
|
+
skip "recorder failed to start (GStreamer source? no audio libs?)"
|
|
37
|
+
end
|
|
38
|
+
# `start` began playing the fixture via filesrc; let it feed a moment, then
|
|
39
|
+
# finalize (add_newline:false keeps the assertion to just the transcript).
|
|
40
|
+
sleep 1.5
|
|
41
|
+
s.stop(add_newline: false)
|
|
42
|
+
|
|
43
|
+
got = wait_until(TIMEOUT) { buf.to_s != before }
|
|
44
|
+
assert got, "no transcript was inserted within #{TIMEOUT}s (Whisper worker failed?)"
|
|
45
|
+
|
|
46
|
+
transcript = buf.to_s.sub(before.chomp, "").strip
|
|
47
|
+
words = transcript.downcase.gsub(/[^a-z ]/, " ").split
|
|
48
|
+
assert (EXPECT & words).any?,
|
|
49
|
+
"transcript #{transcript.inspect} contained none of #{EXPECT.inspect}"
|
|
50
|
+
end
|
|
51
|
+
ensure
|
|
52
|
+
$vma_dictation_worker&.stop
|
|
53
|
+
mic&.close
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
# Load the dictation module if the suite ran without it enabled, so the test
|
|
59
|
+
# is self-sufficient when opted in. Returns true if usable.
|
|
60
|
+
def ensure_dictation_loaded
|
|
61
|
+
# Module-level defs (dictation_session etc.) load as *private* methods on
|
|
62
|
+
# Object, so include private methods in the check.
|
|
63
|
+
return true if respond_to?(:dictation_session, true)
|
|
64
|
+
df = ppath("modules/dictation/dictation.rb")
|
|
65
|
+
return false unless File.exist?(df)
|
|
66
|
+
load df
|
|
67
|
+
respond_to?(:dictation_session, true)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Point dictation at the virtual mic and a fast CPU model, disable the live
|
|
71
|
+
# preliminary passes (so only the final transcript lands), run the block, then
|
|
72
|
+
# restore every key we touched.
|
|
73
|
+
def with_dictation_config(source)
|
|
74
|
+
keys = %i[source model device compute_type chunk_secs normalize]
|
|
75
|
+
saved = keys.to_h { |k| [k, cnf.dictation.public_send("#{k}!")] }
|
|
76
|
+
cnf.dictation.source = source
|
|
77
|
+
cnf.dictation.model = "tiny.en"
|
|
78
|
+
cnf.dictation.device = "cpu"
|
|
79
|
+
cnf.dictation.compute_type = "int8"
|
|
80
|
+
cnf.dictation.chunk_secs = 999 # suppress preliminary chunk transcriptions
|
|
81
|
+
cnf.dictation.normalize = false # skip ffmpeg loudnorm on the final pass
|
|
82
|
+
yield
|
|
83
|
+
ensure
|
|
84
|
+
saved&.each { |k, v| cnf.dictation.public_send("#{k}=", v) }
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Poll `cond` while pumping the GTK main loop (the finalize insert arrives via
|
|
88
|
+
# GLib::Idle from the worker thread).
|
|
89
|
+
def wait_until(timeout)
|
|
90
|
+
t0 = Time.now
|
|
91
|
+
loop do
|
|
92
|
+
drain_idle
|
|
93
|
+
return true if yield
|
|
94
|
+
return false if Time.now - t0 > timeout
|
|
95
|
+
sleep 0.1
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require_relative "support/virtual_keyboard"
|
|
2
|
+
|
|
3
|
+
# True end-to-end test of the "r" (replace character) command with a *non-ASCII*
|
|
4
|
+
# replacement typed via AltGr: a uinput virtual keyboard emits real key events
|
|
5
|
+
# (kernel -> compositor -> IM -> this GTK window), so the "ä" arrives the same
|
|
6
|
+
# way it does for a user on an English (international, AltGr dead keys) layout,
|
|
7
|
+
# where AltGr-q produces "ä" (keysym adiaeresis).
|
|
8
|
+
#
|
|
9
|
+
# Sequence: type a random line, "g g" to the start of the buffer, then "r" +
|
|
10
|
+
# AltGr-q — the first character must become "ä".
|
|
11
|
+
#
|
|
12
|
+
# Skips when /dev/uinput is not writable, xmodmap is missing, the editor window
|
|
13
|
+
# is not the focused window, or the active layout has no "ä" key.
|
|
14
|
+
class TestE2eReplaceChar < VmaTest
|
|
15
|
+
include VkbTest
|
|
16
|
+
|
|
17
|
+
CHAR = "ä" # AltGr-q on us(altgr-intl); typed by keysym, so layout-independent
|
|
18
|
+
|
|
19
|
+
def test_replace_first_char_with_altgr_umlaut
|
|
20
|
+
with_vkb do |kb|
|
|
21
|
+
skip "layout cannot type #{CHAR.inspect} (no adiaeresis key)" if !kb.can_type?(CHAR)
|
|
22
|
+
assert_mode :command
|
|
23
|
+
|
|
24
|
+
text = random_line
|
|
25
|
+
expected = CHAR + text[1..] + "\n"
|
|
26
|
+
|
|
27
|
+
# Enter one line of random text.
|
|
28
|
+
kb.type("i")
|
|
29
|
+
assert wait_until(3) { vma.kbd.get_mode == :insert }, "'i' enters insert mode"
|
|
30
|
+
kb.type(text)
|
|
31
|
+
assert wait_until(5) { vma.buf.to_s == text + "\n" },
|
|
32
|
+
"typed line landed in the buffer (buffer is #{vma.buf.to_s.inspect})"
|
|
33
|
+
kb.tap_keysym("Escape")
|
|
34
|
+
assert wait_until(3) { vma.kbd.get_mode == :command }, "Escape returns to command mode"
|
|
35
|
+
|
|
36
|
+
# Go to the beginning of the buffer.
|
|
37
|
+
kb.type("gg")
|
|
38
|
+
assert wait_until(3) { vma.buf.pos == 0 },
|
|
39
|
+
"'g g' moved to the start of the buffer (pos is #{vma.buf.pos})"
|
|
40
|
+
|
|
41
|
+
# "r" then AltGr-q: replace the first character with "ä".
|
|
42
|
+
kb.type("r")
|
|
43
|
+
kb.tap_keysym(Gdk::Keyval.to_name(CHAR.ord)) # adiaeresis == AltGr-q
|
|
44
|
+
assert wait_until(3) { vma.buf.to_s == expected },
|
|
45
|
+
"first character replaced by #{CHAR.inspect}\n" \
|
|
46
|
+
" expected: #{expected.inspect}\n actual: #{vma.buf.to_s.inspect}"
|
|
47
|
+
assert_mode :command
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
# A line of random lowercase words. Kept to unshifted ASCII so typing it does
|
|
54
|
+
# not depend on the layout; the first character is what "r" will replace.
|
|
55
|
+
def random_line
|
|
56
|
+
4.times.map { (3 + rand(5)).times.map { ("a".."z").to_a.sample }.join }.join(" ")
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Easy jump (s): labels at line and word starts; typing one jumps there
|
|
2
|
+
# (easy_jump.rb)
|
|
3
|
+
class TestEasyJump < VmaTest
|
|
4
|
+
TEXT = "first line here\nsecond line\nthird one\nfourth\n"
|
|
5
|
+
|
|
6
|
+
def setup_buf
|
|
7
|
+
act "buf.insert_txt(#{TEXT.inspect})"
|
|
8
|
+
keys "g g"
|
|
9
|
+
vma.buf.view.handle_deltas
|
|
10
|
+
20.times { drain_idle; sleep 0.02 } # laid out: labels only what's visible
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def ej
|
|
14
|
+
EasyJump.class_variable_get(:@@cur)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# The label of the start of line l (0-based)
|
|
18
|
+
def label_index(l)
|
|
19
|
+
ls = l == 0 ? 0 : vma.buf.line_ends[l - 1] + 1
|
|
20
|
+
ej.instance_variable_get(:@easy_jump_wsmarks).index(ls)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def seq(i)
|
|
24
|
+
ej.instance_variable_get(:@jump_sequence)[i]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# A failed test must not leave easy jump waiting for keys
|
|
28
|
+
def teardown_ej
|
|
29
|
+
vma.kbd.remove_keyhandling_override
|
|
30
|
+
vma.gui.clear_overlay
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def drain_for(secs)
|
|
34
|
+
t = Time.now
|
|
35
|
+
while Time.now - t < secs
|
|
36
|
+
drain_idle
|
|
37
|
+
sleep 0.01
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# After the first key, the matching labels show it bright and bold, the
|
|
42
|
+
# others are dimmed
|
|
43
|
+
def test_typed_key_highlighted
|
|
44
|
+
setup_buf
|
|
45
|
+
keys "s"
|
|
46
|
+
i = label_index(2)
|
|
47
|
+
s = seq(i)
|
|
48
|
+
keys s[0].downcase
|
|
49
|
+
# (a label set with markup returns the markup as its text)
|
|
50
|
+
assert_eq ej.label_markup(s, 1), ej.labels[i].label
|
|
51
|
+
assert ej.labels[i].label.include?("foreground='#{EasyJump::TYPED_FG}' weight='heavy'>#{s[0]}<"), ej.labels[i].label
|
|
52
|
+
other = ej.labels.each_index.find { |k| !seq(k).to_s.start_with?(s[0]) }
|
|
53
|
+
assert other, "no label that doesn't match #{s[0]}"
|
|
54
|
+
assert_eq ej.label_markup(seq(other), 0, dim: true), ej.labels[other].label
|
|
55
|
+
assert ej.labels[other].label.include?("alpha="), ej.labels[other].label
|
|
56
|
+
keys s[1].downcase
|
|
57
|
+
assert_eq vma.buf.line_ends[1] + 1, vma.buf.pos
|
|
58
|
+
ensure
|
|
59
|
+
teardown_ej
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# The chosen label stays a moment after the others are gone
|
|
63
|
+
def test_chosen_label_stays_briefly
|
|
64
|
+
setup_buf
|
|
65
|
+
keys "s"
|
|
66
|
+
i = label_index(1)
|
|
67
|
+
s = seq(i)
|
|
68
|
+
labels = ej.labels
|
|
69
|
+
keys s.downcase.chars.join(" ")
|
|
70
|
+
chosen = labels[i]
|
|
71
|
+
assert chosen.parent, "chosen label removed at once"
|
|
72
|
+
assert labels.each_with_index.all? { |l, k| k == i || l.parent.nil? }, "other labels still shown"
|
|
73
|
+
da = chosen.parent
|
|
74
|
+
drain_for(EasyJump::CHOSEN_SECS + 0.25)
|
|
75
|
+
assert da.parent.nil?, "chosen label still shown after #{EasyJump::CHOSEN_SECS} s"
|
|
76
|
+
ensure
|
|
77
|
+
teardown_ej
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# cnf.easy_jump.glow (off by default: slower without a GPU)
|
|
81
|
+
def test_labels_with_glow
|
|
82
|
+
old = cnf.easy_jump.glow?
|
|
83
|
+
cnf.easy_jump.glow = true
|
|
84
|
+
setup_buf
|
|
85
|
+
keys "s"
|
|
86
|
+
assert ej.labels.size > 0
|
|
87
|
+
assert ej.labels.all? { |l| l.has_css_class?("overlay-label") }
|
|
88
|
+
keys "esc"
|
|
89
|
+
ensure
|
|
90
|
+
teardown_ej
|
|
91
|
+
cnf.easy_jump.glow = old
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require "tmpdir"
|
|
2
|
+
|
|
3
|
+
# "file.links" lists the existing files named in the current file in a
|
|
4
|
+
# new buffer, one absolute path per line.
|
|
5
|
+
class TestExtractFileLinks < VmaTest
|
|
6
|
+
def with_dir
|
|
7
|
+
Dir.mktmpdir do |dir|
|
|
8
|
+
File.write("#{dir}/a.pdf", "x")
|
|
9
|
+
FileUtils.mkdir_p("#{dir}/sub")
|
|
10
|
+
File.write("#{dir}/sub/b.txt", "x")
|
|
11
|
+
File.write("#{dir}/notes.txt", "x")
|
|
12
|
+
# Real image: opening a buffer with ⟦img:...⟧ renders it
|
|
13
|
+
GdkPixbuf::Pixbuf.new(colorspace: :rgb, has_alpha: false, bits_per_sample: 8,
|
|
14
|
+
width: 1, height: 1).save("#{dir}/img.png", "png")
|
|
15
|
+
yield dir
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def open_with(dir, text)
|
|
20
|
+
path = "#{dir}/main.txt"
|
|
21
|
+
File.write(path, text)
|
|
22
|
+
b = open_new_file(path)
|
|
23
|
+
drain_idle
|
|
24
|
+
b
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_extracts_existing_files_in_order
|
|
28
|
+
with_dir do |dir|
|
|
29
|
+
text = "See (a.pdf), sub/b.txt and missing.pdf.\n" \
|
|
30
|
+
"Again a.pdf; link ⟦notes⟧ image ⟦img:img.png⟧ dir sub/ url https://x.org/a.pdf\n" \
|
|
31
|
+
"abs #{dir}/sub/b.txt plain words only\n"
|
|
32
|
+
b = open_with(dir, text)
|
|
33
|
+
begin
|
|
34
|
+
act "file.links"
|
|
35
|
+
assert_eq "#{dir}/a.pdf\n#{dir}/sub/b.txt\n#{dir}/notes.txt\n#{dir}/img.png\n", vma.buf.to_s
|
|
36
|
+
assert vma.buf.fname.nil?, "result should be an unsaved buffer"
|
|
37
|
+
vma.buffers.close_buffer(vma.buf.id)
|
|
38
|
+
ensure
|
|
39
|
+
vma.buffers.close_buffer(b.id)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_no_links_creates_no_buffer
|
|
45
|
+
with_dir do |dir|
|
|
46
|
+
b = open_with(dir, "nothing here, missing.pdf\n")
|
|
47
|
+
begin
|
|
48
|
+
act "file.links"
|
|
49
|
+
assert_eq b.id, vma.buf.id
|
|
50
|
+
ensure
|
|
51
|
+
vma.buffers.close_buffer(b.id)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
require "tmpdir"
|
|
2
|
+
|
|
3
|
+
# Files that are not UTF-8 / \n (e.g. Latin-1 with CRLF) open converted to
|
|
4
|
+
# UTF-8 + \n; the first save asks whether to keep the original format.
|
|
5
|
+
class TestFileFormat < VmaTest
|
|
6
|
+
LATIN1_CRLF = "/* caf\xE9 */\r\nint x;\r\n".b
|
|
7
|
+
|
|
8
|
+
def with_file(bytes, name = "f.c")
|
|
9
|
+
Dir.mktmpdir do |dir|
|
|
10
|
+
path = File.join(dir, name)
|
|
11
|
+
File.binwrite(path, bytes)
|
|
12
|
+
b = nil
|
|
13
|
+
begin
|
|
14
|
+
b = open_new_file(path)
|
|
15
|
+
drain_idle
|
|
16
|
+
yield b, path
|
|
17
|
+
ensure
|
|
18
|
+
PopupFormGenerator.reset_popup_queue
|
|
19
|
+
vma.buffers.close_buffer(b.id) if b
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Press button `id` in the active popup.
|
|
25
|
+
def answer_popup(id)
|
|
26
|
+
popup = PopupFormGenerator.class_variable_get(:@@popup_active)
|
|
27
|
+
assert popup, "no popup shown"
|
|
28
|
+
popup.instance_variable_get(:@ret)[id] = "submit"
|
|
29
|
+
popup.submit
|
|
30
|
+
drain_idle
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Saving writes from a thread (truncate, then write): wait until the file
|
|
34
|
+
# has new, non-empty content.
|
|
35
|
+
def wait_for_write(path, old)
|
|
36
|
+
data = nil
|
|
37
|
+
50.times do
|
|
38
|
+
data = File.binread(path)
|
|
39
|
+
break if data != old && !data.empty?
|
|
40
|
+
sleep 0.05
|
|
41
|
+
end
|
|
42
|
+
data
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_latin1_crlf_file_opens_as_utf8
|
|
46
|
+
with_file(LATIN1_CRLF) do |b, path|
|
|
47
|
+
assert b, "file did not open"
|
|
48
|
+
assert_eq "/* café */\nint x;\n", b.to_s
|
|
49
|
+
assert_eq Encoding::UTF_8, b.to_s.encoding
|
|
50
|
+
assert_eq "ISO-8859-1 with CRLF line endings", b.file_format_desc
|
|
51
|
+
assert file_is_text_file(path)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_save_keep_original_format
|
|
56
|
+
with_file(LATIN1_CRLF) do |b, path|
|
|
57
|
+
b.insert_txt_at("int y;\n", b.line_range(1, 1).begin) # before "int x;"
|
|
58
|
+
b.save
|
|
59
|
+
assert PopupFormGenerator.popup_active?, "first save should ask"
|
|
60
|
+
assert_eq LATIN1_CRLF, File.binread(path) # nothing written yet
|
|
61
|
+
answer_popup("keep_btn")
|
|
62
|
+
data = wait_for_write(path, LATIN1_CRLF)
|
|
63
|
+
assert_eq "/* caf\xE9 */\r\nint y;\r\nint x;\r\n".b, data
|
|
64
|
+
|
|
65
|
+
# second save does not ask again
|
|
66
|
+
b.insert_txt_at("z", 0)
|
|
67
|
+
b.save
|
|
68
|
+
assert !PopupFormGenerator.popup_active?, "asked twice"
|
|
69
|
+
assert_eq "z/* caf\xE9 */\r\n".b, wait_for_write(path, data)[0, 13]
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_save_convert_to_utf8
|
|
74
|
+
with_file(LATIN1_CRLF) do |b, path|
|
|
75
|
+
b.save
|
|
76
|
+
answer_popup("convert_btn")
|
|
77
|
+
assert_eq "/* café */\nint x;\n".b, wait_for_write(path, LATIN1_CRLF)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# A character Latin-1 cannot hold: saved as UTF-8 (CRLF kept), with a message.
|
|
82
|
+
def test_keep_falls_back_to_utf8_for_unencodable_text
|
|
83
|
+
with_file(LATIN1_CRLF) do |b, path|
|
|
84
|
+
b.insert_txt_at("€", 0)
|
|
85
|
+
b.save
|
|
86
|
+
answer_popup("keep_btn")
|
|
87
|
+
assert_eq "€/* café */\r\nint x;\r\n".b, wait_for_write(path, LATIN1_CRLF)
|
|
88
|
+
msgs = $vmag.instance_variable_get(:@minibuf_messages)
|
|
89
|
+
assert msgs.first(3).any? { |m| m.include?("Cannot save f.c as ISO-8859-1") }, msgs.first(3).inspect
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_utf8_lf_file_saves_without_asking
|
|
94
|
+
with_file("int ä;\n") do |b, path|
|
|
95
|
+
assert_eq nil, b.file_format_desc
|
|
96
|
+
b.insert_txt_at("x", 0)
|
|
97
|
+
b.save
|
|
98
|
+
assert !PopupFormGenerator.popup_active?
|
|
99
|
+
assert_eq "xint ä;\n".b, wait_for_write(path, "int ä;\n".b)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# `vimamsa <file>` with an instance running drops the path into the listen
|
|
104
|
+
# dir; non-UTF-8 files used to be ignored there without a message.
|
|
105
|
+
def test_file_from_command_line_opens
|
|
106
|
+
Dir.mktmpdir do |dir|
|
|
107
|
+
path = File.join(dir, "pnn.c")
|
|
108
|
+
File.binwrite(path, LATIN1_CRLF)
|
|
109
|
+
drop = File.join(dir, "vmarun-test")
|
|
110
|
+
File.write(drop, path)
|
|
111
|
+
vma.open_file_listener([drop])
|
|
112
|
+
drain_idle
|
|
113
|
+
b = vma.buffers.list.find { |x| x.fname == path }
|
|
114
|
+
assert b, "file from listen dir was not opened"
|
|
115
|
+
assert_eq "/* café */\nint x;\n", b.to_s
|
|
116
|
+
vma.buffers.close_buffer(b.id)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# Settings > Behavior: cnf.file_format.on_save = "keep" / "convert" saves
|
|
121
|
+
# without asking.
|
|
122
|
+
def with_on_save(value)
|
|
123
|
+
old = cnf.file_format.on_save!
|
|
124
|
+
cnf.file_format.on_save = value
|
|
125
|
+
yield
|
|
126
|
+
ensure
|
|
127
|
+
cnf.file_format.on_save = old
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def test_setting_keep_saves_original_without_asking
|
|
131
|
+
with_on_save("keep") do
|
|
132
|
+
with_file(LATIN1_CRLF) do |b, path|
|
|
133
|
+
b.insert_txt_at("z", 0)
|
|
134
|
+
b.save
|
|
135
|
+
assert !PopupFormGenerator.popup_active?, "should not ask"
|
|
136
|
+
assert_eq "z/* caf\xE9 */\r\nint x;\r\n".b, wait_for_write(path, LATIN1_CRLF)
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def test_setting_convert_saves_utf8_without_asking
|
|
142
|
+
with_on_save("convert") do
|
|
143
|
+
with_file(LATIN1_CRLF) do |b, path|
|
|
144
|
+
b.save
|
|
145
|
+
assert !PopupFormGenerator.popup_active?, "should not ask"
|
|
146
|
+
assert_eq "/* café */\nint x;\n".b, wait_for_write(path, LATIN1_CRLF)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# An answer given in the dialog wins over a later change of the setting.
|
|
152
|
+
def test_answer_overrides_setting
|
|
153
|
+
with_file(LATIN1_CRLF) do |b, path|
|
|
154
|
+
b.save
|
|
155
|
+
answer_popup("convert_btn")
|
|
156
|
+
data = wait_for_write(path, LATIN1_CRLF)
|
|
157
|
+
with_on_save("keep") do
|
|
158
|
+
b.insert_txt_at("z", 0)
|
|
159
|
+
b.save
|
|
160
|
+
assert_eq "z/* café */\n".b, wait_for_write(path, data)[0, 13]
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def test_setting_in_settings_dialog
|
|
166
|
+
s = SETTINGS_DEFS.flat_map { |g| g[:settings] }.find { |x| x[:key] == [:file_format, :on_save] }
|
|
167
|
+
assert s, "file_format.on_save missing from the settings dialog"
|
|
168
|
+
assert_eq ["ask", "keep", "convert"], s[:options]
|
|
169
|
+
assert_eq "ask", cnf.file_format.on_save!
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# git diff of a Latin-1 + CRLF file: shown as UTF-8 with \n, no error.
|
|
173
|
+
def test_git_diff_of_latin1_file
|
|
174
|
+
skip("git not installed") unless system("which git >/dev/null 2>&1")
|
|
175
|
+
Dir.mktmpdir do |dir|
|
|
176
|
+
path = File.join(dir, "f.c")
|
|
177
|
+
File.binwrite(path, LATIN1_CRLF)
|
|
178
|
+
system("git", "-C", dir, "init", "-q")
|
|
179
|
+
system("git", "-C", dir, "add", "f.c")
|
|
180
|
+
system("git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", "init")
|
|
181
|
+
File.binwrite(path, "/* caf\xE9 */\r\nint y;\r\n".b)
|
|
182
|
+
b = open_new_file(path)
|
|
183
|
+
begin
|
|
184
|
+
git_diff_buffer
|
|
185
|
+
d = vma.buf
|
|
186
|
+
assert !d.equal?(b), "no diff buffer"
|
|
187
|
+
assert_eq Encoding::UTF_8, d.to_s.encoding
|
|
188
|
+
assert d.to_s.valid_encoding?
|
|
189
|
+
assert d.to_s.include?(" /* café */\n"), d.to_s
|
|
190
|
+
assert d.to_s.include?("-int x;\n+int y;\n"), d.to_s
|
|
191
|
+
assert !d.to_s.include?("\r")
|
|
192
|
+
vma.buffers.close_buffer(d.id)
|
|
193
|
+
ensure
|
|
194
|
+
vma.buffers.close_buffer(b.id)
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# Diff of unsaved changes: the buffer (UTF-8 + \n) is compared with the file
|
|
200
|
+
# as loaded, so only the edited line differs, not every line.
|
|
201
|
+
def test_diff_unsaved_of_latin1_file
|
|
202
|
+
with_file("/* caf\xE9 */\r\nint x;\r\nint z;\r\n".b) do |b, path|
|
|
203
|
+
b.insert_txt_at("q", b.line_range(2, 1).begin) # "qint z;"
|
|
204
|
+
diff_buffer
|
|
205
|
+
d = vma.buf
|
|
206
|
+
changed = d.to_s.lines.select { |l| l =~ /^[-+][^-+]/ }
|
|
207
|
+
assert_eq ["-int z;\n", "+qint z;\n"], changed
|
|
208
|
+
assert d.to_s.start_with?("--- #{path}\n+++ #{path}\n"), d.to_s.lines.first(2).inspect
|
|
209
|
+
# enter on the changed line jumps back to the file
|
|
210
|
+
d.set_pos(d.to_s.index("+qint"))
|
|
211
|
+
diff_buffer_jump_to_source
|
|
212
|
+
assert vma.buf.equal?(b), "did not jump to the file"
|
|
213
|
+
assert_eq 2, b.lpos
|
|
214
|
+
vma.buffers.close_buffer(d.id)
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|