vimamsa 0.1.26 → 0.1.27
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 +62 -16
- data/custom_example.rb +43 -13
- data/doc/TODO.md +461 -0
- data/doc/bundling_plan.md +569 -0
- data/doc/key_bindings_report_plan.md +168 -0
- data/doc/missing_vim_bindings.md +71 -0
- data/doc/modules_settings_plan.md +433 -0
- data/doc/refactor_dedup_plan.md +117 -0
- data/doc/unused_code_plan.md +120 -0
- data/doc/vim_compatibility_plan.md +296 -0
- data/doc/vimlike_vim_conflicts.md +254 -0
- data/doc/vm_snapshots_plan.md +146 -0
- data/exe/run_tests.rb +117 -3
- data/exe/vimamsa +24 -4
- data/fonts/OFL-Oxanium.txt +93 -0
- data/fonts/Oxanium[wght].ttf +0 -0
- data/icon.png +0 -0
- data/img/demo.gif +0 -0
- data/lang/hyperplaintext.lang +6 -0
- data/lib/vimamsa/ack.rb +11 -1
- data/lib/vimamsa/actions.rb +4 -1
- 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 +593 -82
- data/lib/vimamsa/buffer_changetext.rb +102 -42
- data/lib/vimamsa/buffer_cursor.rb +7 -0
- data/lib/vimamsa/buffer_list.rb +4 -0
- data/lib/vimamsa/buffer_manager.rb +4 -1
- data/lib/vimamsa/bundled_fonts.rb +32 -0
- data/lib/vimamsa/clipboard.rb +3 -0
- data/lib/vimamsa/conf.rb +59 -3
- data/lib/vimamsa/constants.rb +3 -0
- data/lib/vimamsa/crash_handler.rb +149 -0
- data/lib/vimamsa/debug.rb +4 -1
- data/lib/vimamsa/desktop_install.rb +96 -0
- data/lib/vimamsa/diff_buffer.rb +39 -10
- data/lib/vimamsa/easy_jump.rb +3 -0
- data/lib/vimamsa/editor.rb +263 -57
- data/lib/vimamsa/encrypt.rb +78 -29
- data/lib/vimamsa/file_finder.rb +4 -19
- data/lib/vimamsa/file_history.rb +3 -0
- data/lib/vimamsa/file_manager.rb +30 -15
- data/lib/vimamsa/fold.rb +226 -0
- data/lib/vimamsa/gui.rb +520 -106
- data/lib/vimamsa/gui_command_line.rb +208 -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 +59 -35
- data/lib/vimamsa/gui_func_panel.rb +67 -22
- data/lib/vimamsa/gui_image.rb +3 -0
- data/lib/vimamsa/gui_keylog_panel.rb +246 -0
- data/lib/vimamsa/gui_menu.rb +23 -11
- data/lib/vimamsa/gui_select_window.rb +19 -48
- data/lib/vimamsa/gui_settings.rb +78 -37
- data/lib/vimamsa/gui_sourceview.rb +273 -19
- data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
- data/lib/vimamsa/gui_text.rb +63 -2
- data/lib/vimamsa/gui_theme.rb +606 -0
- data/lib/vimamsa/hook.rb +3 -0
- data/lib/vimamsa/hyper_plain_text.rb +3 -0
- data/lib/vimamsa/key_actions.rb +112 -13
- data/lib/vimamsa/key_binding_tree.rb +242 -215
- data/lib/vimamsa/key_bindings_notepad.rb +43 -0
- data/lib/vimamsa/key_bindings_report.rb +261 -0
- data/lib/vimamsa/key_bindings_vim.rb +354 -0
- data/lib/vimamsa/key_bindings_vimlike.rb +65 -9
- data/lib/vimamsa/langservp.rb +271 -54
- data/lib/vimamsa/macro.rb +3 -0
- data/lib/vimamsa/main.rb +14 -8
- data/lib/vimamsa/rbvma.rb +26 -1
- data/lib/vimamsa/search.rb +3 -0
- data/lib/vimamsa/search_replace.rb +11 -10
- data/lib/vimamsa/string_util.rb +120 -40
- data/lib/vimamsa/terminal.rb +3 -0
- data/lib/vimamsa/test_framework.rb +28 -2
- data/lib/vimamsa/tests.rb +3 -0
- data/lib/vimamsa/text_objects.rb +353 -0
- data/lib/vimamsa/text_transforms.rb +14 -0
- data/lib/vimamsa/util.rb +46 -7
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa.rb +0 -1
- 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/tts/tts.rb +119 -0
- data/modules/tts/tts_info.rb +3 -0
- data/run_e2e_vm.sh +28 -0
- data/run_tests_vm.sh +130 -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_steps.txt +59 -0
- data/scripts/demo/record_demo.rb +177 -0
- data/scripts/demo/shapes.rb +28 -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_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 +33 -3
- data/tests/test_bookmarks.rb +206 -0
- data/tests/test_bracket_match.rb +85 -0
- data/tests/test_bundling.rb +92 -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 +129 -0
- data/tests/test_copy_paste.rb +80 -0
- data/tests/test_crash_handler.rb +39 -0
- data/tests/test_custom_two_phase.rb +92 -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_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_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_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_jump_to_file.rb +41 -0
- data/tests/test_key_bindings.rb +208 -0
- data/tests/test_keylog_panel.rb +101 -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_notepad_bindings.rb +67 -0
- data/tests/test_popup_queue.rb +51 -0
- data/tests/test_random_edit.rb +109 -0
- data/tests/test_revert.rb +127 -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 +329 -0
- data/tests/test_tts.rb +68 -0
- data/tests/test_vim_bindings.rb +252 -0
- data/tests/test_vim_conflicts.rb +63 -0
- data/tests/test_window_layout.rb +219 -0
- data/vimamsa.gemspec +3 -1
- data/vm_guest_run.sh +109 -0
- metadata +112 -10
|
@@ -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,55 @@
|
|
|
1
|
+
require "tmpdir"
|
|
2
|
+
|
|
3
|
+
# :extract_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 :extract_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 :extract_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
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require "tmpdir"
|
|
2
|
+
|
|
3
|
+
class TestFileManager < VmaTest
|
|
4
|
+
def test_sort_mtime_orders_directories_too
|
|
5
|
+
Dir.mktmpdir("vimamsa-fexp-") do |dir|
|
|
6
|
+
older = File.join(dir, "older_dir")
|
|
7
|
+
newer = File.join(dir, "newer_dir")
|
|
8
|
+
afile = File.join(dir, "afile.txt")
|
|
9
|
+
bfile = File.join(dir, "bfile.txt")
|
|
10
|
+
|
|
11
|
+
Dir.mkdir(older)
|
|
12
|
+
sleep 1
|
|
13
|
+
Dir.mkdir(newer)
|
|
14
|
+
File.write(afile, "a")
|
|
15
|
+
sleep 1
|
|
16
|
+
File.write(bfile, "b")
|
|
17
|
+
|
|
18
|
+
fm = Vimamsa::FileManager.new
|
|
19
|
+
fm.dir_to_buf(dir)
|
|
20
|
+
fm.sort_mtime
|
|
21
|
+
|
|
22
|
+
lines = vma.buf.to_s.lines.map(&:chomp)
|
|
23
|
+
dir_lines = lines[3, 2]
|
|
24
|
+
file_lines = lines[6, 2]
|
|
25
|
+
|
|
26
|
+
assert_eq ["newer_dir", "older_dir"], dir_lines, "directories should be sorted by mtime descending"
|
|
27
|
+
assert_eq ["bfile.txt", "afile.txt"], file_lines, "files should remain sorted by mtime descending"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# FileManager.cur used to raise NameError (uninitialized class variable @@cur)
|
|
32
|
+
# when the file selector had never been opened, crashing any action that
|
|
33
|
+
# called it.
|
|
34
|
+
def test_cur_is_nil_before_file_selector_is_opened
|
|
35
|
+
without_current_filemanager {
|
|
36
|
+
assert_eq nil, Vimamsa::FileManager.cur, "cur should be nil, not raise"
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_with_cur_does_not_yield_when_no_file_manager
|
|
41
|
+
without_current_filemanager {
|
|
42
|
+
yielded = false
|
|
43
|
+
ret = Vimamsa::FileManager.with_cur { |fm| yielded = true }
|
|
44
|
+
assert !yielded, "block should not run without an open file selector"
|
|
45
|
+
assert_eq nil, ret
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_with_cur_yields_the_current_file_manager
|
|
50
|
+
fm = Vimamsa::FileManager.new
|
|
51
|
+
prev = Vimamsa::FileManager.cur
|
|
52
|
+
Vimamsa::FileManager.class_variable_set(:@@cur, fm)
|
|
53
|
+
begin
|
|
54
|
+
assert_eq fm, Vimamsa::FileManager.with_cur { |x| x }
|
|
55
|
+
ensure
|
|
56
|
+
Vimamsa::FileManager.class_variable_set(:@@cur, prev)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
private
|
|
61
|
+
|
|
62
|
+
# Run blk with no file selector open (@@cur = nil), restoring it afterwards.
|
|
63
|
+
def without_current_filemanager
|
|
64
|
+
prev = Vimamsa::FileManager.cur
|
|
65
|
+
Vimamsa::FileManager.class_variable_set(:@@cur, nil)
|
|
66
|
+
begin
|
|
67
|
+
yield
|
|
68
|
+
ensure
|
|
69
|
+
Vimamsa::FileManager.class_variable_set(:@@cur, prev)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|