vimamsa 0.1.28 → 0.1.29

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.
@@ -216,6 +216,60 @@ class TestDemoPlayer < VmaTest
216
216
  vma.buffers.close_buffer(p.buf.id) if p&.buf
217
217
  end
218
218
 
219
+ # While it plays, the GUI ignores the user's keys and clicks; paused or
220
+ # stopped, it doesn't
221
+ def test_blocks_input_while_playing
222
+ p = short_player(5, loop: false)
223
+ assert !DemoPlayer.blocks_input?
224
+ p.start
225
+ assert DemoPlayer.blocks_input?, "a playing demo lets user input through"
226
+ p.toggle_pause
227
+ assert !DemoPlayer.blocks_input?, "a paused demo blocks user input"
228
+ p.toggle_pause
229
+ assert DemoPlayer.blocks_input?
230
+ p.stop
231
+ assert !DemoPlayer.blocks_input?, "a stopped demo blocks user input"
232
+ ensure
233
+ p&.stop
234
+ vma.buffers.close_buffer(p.buf.id) if p&.buf
235
+ end
236
+
237
+ # Edited while paused: continuing starts the demo from the beginning, on
238
+ # the file as it was at the start
239
+ def test_edit_while_paused_restarts
240
+ p = short_player(0.2, loop: false)
241
+ p.start
242
+ p.toggle_pause
243
+ keys "i h e l l o esc"
244
+ assert p.buf.to_s.start_with?("hello"), p.buf.to_s[0, 20]
245
+ p.toggle_pause
246
+ assert_eq original, p.buf.to_s
247
+ assert_eq 0, p.buf.pos
248
+ assert_eq 0, p.rounds
249
+ wait_until_done(p, 5)
250
+ assert_eq "Demo finished", p.stop_message
251
+ assert_eq original[1..], p.buf.to_s
252
+ ensure
253
+ p&.stop
254
+ vma.buffers.close_buffer(p.buf.id) if p&.buf
255
+ end
256
+
257
+ # Only the cursor moved while paused: that too starts it again
258
+ def test_cursor_move_while_paused_restarts
259
+ p = short_player(0.2, loop: false)
260
+ p.start
261
+ p.toggle_pause
262
+ keys "j j l"
263
+ assert p.buf.pos > 0
264
+ p.toggle_pause
265
+ assert_eq 0, p.buf.pos
266
+ wait_until_done(p, 5)
267
+ assert_eq original[1..], p.buf.to_s
268
+ ensure
269
+ p&.stop
270
+ vma.buffers.close_buffer(p.buf.id) if p&.buf
271
+ end
272
+
219
273
  # A demo from any steps file (scripts/demo/record_demo.rb): no controls,
220
274
  # on_finish gets the stop message
221
275
  def test_given_demo_without_controls
@@ -0,0 +1,43 @@
1
+ require "tmpdir"
2
+
3
+ # LangSrv.project_root: the folder an LSP server runs in (its working
4
+ # directory and rootUri). ruby-lsp indexes its whole workspace, and used to
5
+ # get the editor's current directory, often the home directory.
6
+ class TestLspRoot < VmaTest
7
+ REPO = File.expand_path("..", __dir__)
8
+
9
+ def setup_lsp
10
+ require "vimamsa/langservp"
11
+ end
12
+
13
+ def test_nearest_project_marker
14
+ setup_lsp
15
+ assert_eq REPO, LangSrv.project_root(File.join(REPO, "lib/vimamsa/editor.rb"))
16
+ Dir.mktmpdir { |d|
17
+ FileUtils.mkdir_p("#{d}/proj/src/deep")
18
+ File.write("#{d}/proj/Gemfile", "")
19
+ assert_eq "#{d}/proj", LangSrv.project_root("#{d}/proj/src/deep/x.rb")
20
+ }
21
+ end
22
+
23
+ # No marker up to the home directory (or /): the file's own folder
24
+ def test_without_marker_the_files_folder
25
+ setup_lsp
26
+ Dir.mktmpdir { |d|
27
+ FileUtils.mkdir_p("#{d}/a/b")
28
+ root = LangSrv.project_root("#{d}/a/b/x.rb")
29
+ assert_eq "#{d}/a/b", root
30
+ }
31
+ end
32
+
33
+ # Never the home directory: a file directly in ~ gets an empty folder
34
+ def test_never_home
35
+ setup_lsp
36
+ home = File.expand_path("~")
37
+ r = LangSrv.project_root(File.join(home, "notes.rb"))
38
+ assert r != home, "home directory as the project root"
39
+ assert File.directory?(r)
40
+ assert_eq [], Dir.children(r)
41
+ assert_eq nil, LangSrv.project_root(nil)
42
+ end
43
+ end
@@ -33,6 +33,15 @@ class TestRegisters < VmaTest
33
33
  assert_buf "one\ntwo\none\n"
34
34
  end
35
35
 
36
+ # vim's i_ctrl-r in the default keymap too (VIM_BINDINGS): Insert mode,
37
+ # ctrl-r and a register name insert that register's text
38
+ def test_insert_register_in_insert_mode
39
+ setup_text("foo bar\n")
40
+ keys('" a y w')
41
+ keys("A space ctrl-r a esc")
42
+ assert_buf("foo bar foo \n")
43
+ end
44
+
36
45
  def test_append_to_named_register
37
46
  setup_text("one two\nthree\n")
38
47
  keys('" a y y')
@@ -3,6 +3,17 @@ require "tmpdir"
3
3
  # cnf.startup_file is the buffer shown on startup even when the previous
4
4
  # session is restored (restoring would otherwise leave its last file current).
5
5
  class TestStartupFile < VmaTest
6
+ # Runs the main loop until the block is true (a session restore opens its
7
+ # files one per main loop turn)
8
+ def wait_until(secs = 10)
9
+ t = Time.now
10
+ until yield || Time.now - t > secs
11
+ drain_idle
12
+ sleep 0.01
13
+ end
14
+ yield
15
+ end
16
+
6
17
  def test_startup_file_stays_current_after_session_restore
7
18
  Dir.mktmpdir do |dir|
8
19
  startup = "#{dir}/startup.txt"
@@ -19,7 +30,7 @@ class TestStartupFile < VmaTest
19
30
  ENV["VIMAMSA_RESTORE_SESSION"] = "1"
20
31
  begin
21
32
  vma.check_session_restore
22
- drain_idle
33
+ assert wait_until { vma.buffers.get_buffer_by_filename(b) && vma.gui.status_indicator(:session_restore).nil? }
23
34
  assert_eq startup, vma.buf.fname
24
35
  assert vma.buffers.get_buffer_by_filename(a), "session file a restored"
25
36
  assert vma.buffers.get_buffer_by_filename(b), "session file b restored"
@@ -43,8 +54,9 @@ class TestStartupFile < VmaTest
43
54
  File.write(a, "a\n")
44
55
  File.write(b, "b\n")
45
56
  begin
46
- vma.restore_session_files([a, b])
47
- drain_idle
57
+ done = false
58
+ vma.restore_session_files([a, b]) { done = true }
59
+ assert wait_until { done }, "restore didn't finish"
48
60
  assert_eq b, vma.buf.fname
49
61
  ensure
50
62
  [b, a].each { |f|
@@ -55,4 +67,33 @@ class TestStartupFile < VmaTest
55
67
  end
56
68
  end
57
69
  end
70
+
71
+ # A session opens one file per main loop turn with its progress in the
72
+ # status bar ("Restoring session: 2/5 c.txt"), gone at the end; a file
73
+ # that can't be opened is skipped
74
+ def test_restore_shows_progress
75
+ Dir.mktmpdir do |dir|
76
+ files = %w[a b c d e].map { |n| f = "#{dir}/#{n}.txt"; File.write(f, "#{n}\n"); f }
77
+ bad = "#{dir}/gone.txt" # deleted after the list was made
78
+ seen = []
79
+ done = false
80
+ begin
81
+ vma.restore_session_files(files[0, 2] + [bad] + files[2..]) { done = true }
82
+ assert_eq "Restoring session: 0/6", vma.gui.status_indicator(:session_restore), "no progress before the first file"
83
+ wait_until { seen << vma.gui.status_indicator(:session_restore); done }
84
+ assert done, "restore didn't finish"
85
+ # some file in between (one main loop drain can open several)
86
+ assert seen.compact.any? { |t| t.match?(%r{\ARestoring session: [1-5]/6 }) }, seen.compact.uniq.inspect
87
+ assert_eq nil, vma.gui.status_indicator(:session_restore), "progress still shown"
88
+ files.each { |f| assert vma.buffers.get_buffer_by_filename(f), "#{f} not restored" }
89
+ ensure
90
+ files.each { |f|
91
+ id = vma.buffers.get_buffer_by_filename(f)
92
+ vma.buffers.close_buffer(id) if id
93
+ }
94
+ drain_idle
95
+ end
96
+ end
97
+ end
98
+
58
99
  end
data/vm_guest_run.sh CHANGED
@@ -9,6 +9,8 @@
9
9
  # VMA_DISPLAY X display of the logged-in desktop session (default :0)
10
10
  # VMA_TEST_ARGS optional args forwarded to exe/run_tests.rb (test filters)
11
11
  # FORCE_PROVISION set to 1 to re-run apt/gem provisioning even if the marker exists
12
+ # VMA_APPIMAGE an AppImage in the guest to test instead of building this tree
13
+ # VMA_APPIMAGE_DEV set to 1: this tree's code on that AppImage's runtime
12
14
  set -euo pipefail
13
15
 
14
16
  SRC_TGZ="$HOME/vimamsa_src.tgz"
@@ -72,33 +74,58 @@ fi
72
74
  sudo_do modprobe uinput 2>/dev/null || true
73
75
  sudo_do chmod 0666 /dev/uinput 2>/dev/null || true
74
76
 
75
- # 3. Build + install the gem. Compiles ext/vmaext and (first run) installs the
76
- # ruby-gnome gems and the external StrIdx C++ gem. Copy the built .so back into
77
- # the tree so `require "vmaext"` resolves when running from source.
78
- echo ">> Building and installing the vimamsa gem"
79
- rm -f vimamsa-0.1.*.gem
80
- gem build vimamsa.gemspec
81
- # NB: no --local — installing the local .gem must be allowed to fetch its runtime
82
- # deps (gtk4, gtksourceview5, StrIdx, language_server-protocol, …) from rubygems.org.
83
- sudo_do gem install vimamsa-0.1.*.gem
84
- # A system `gem install` compiles the extension under Gem.dir/extensions/<platform>/
85
- # <abi>/vimamsa-<ver>/vmaext.so (not under gems/.../ext), so locate it with find.
86
- GEM_DIR="$(ruby -e 'puts Gem.dir')"
87
- so_path="$(find "$GEM_DIR" -name vmaext.so -path '*vimamsa*' 2>/dev/null | head -1)"
88
- [ -z "$so_path" ] && so_path="$(find "$GEM_DIR" -name vmaext.so 2>/dev/null | head -1)"
89
- if [ -z "$so_path" ]; then
90
- echo "!! Could not locate compiled vmaext.so under $GEM_DIR" >&2
91
- exit 2
92
- fi
93
- cp "$so_path" lib/
94
- touch "$MARKER"
77
+ # 3a. VMA_APPIMAGE (run_tests_vm.rb --appimage): test that AppImage instead
78
+ # of a build of this tree. It is unpacked (no FUSE needed) and run by
79
+ # exe/run_tests.rb through VMA_TEST_APP, with this tree's tests.
80
+ # VMA_APPIMAGE_DEV=1: this tree's code on the AppImage's Ruby, gems and
81
+ # libraries (AppRun's VMA_SOURCE; an older AppRun gets it by sed).
82
+ if [ -n "${VMA_APPIMAGE:-}" ]; then
83
+ echo ">> Unpacking the AppImage $VMA_APPIMAGE"
84
+ APPDIR_X="$HOME/vma_appimage"
85
+ rm -rf "$APPDIR_X"
86
+ mkdir -p "$APPDIR_X"
87
+ chmod +x "$VMA_APPIMAGE"
88
+ (cd "$APPDIR_X" && "$VMA_APPIMAGE" --appimage-extract >/dev/null)
89
+ app="$APPDIR_X/squashfs-root/AppRun"
90
+ if [ "${VMA_APPIMAGE_DEV:-}" = "1" ]; then
91
+ echo ">> ... running this tree's code on it (VMA_SOURCE=$DEST)"
92
+ sed 's#^exec "$U/bin/ruby" "$U/bin/vimamsa" "$@"#exec "$U/bin/ruby" "$VMA_SOURCE/exe/vimamsa" "$@"#' \
93
+ "$app" > "$APPDIR_X/AppRun.dev"
94
+ chmod +x "$APPDIR_X/AppRun.dev"
95
+ export APPDIR="$APPDIR_X/squashfs-root" VMA_SOURCE="$DEST"
96
+ app="$APPDIR_X/AppRun.dev"
97
+ fi
98
+ export VMA_TEST_APP="$app"
99
+ else
95
100
 
96
- # The ruby-lsp tests run `bundle exec ruby-lsp`. The synced Gemfile.lock is the
97
- # host's and pins exact versions the guest doesn't have (gem install above picks
98
- # the newest matching ones), so resolve the bundle against the guest's gems,
99
- # installing only what's missing (e.g. the development dependencies).
100
- rm -f Gemfile.lock
101
- bundle check >/dev/null 2>&1 || sudo_do bundle install
101
+ # 3. Build + install the gem. Compiles ext/vmaext and (first run) installs the
102
+ # ruby-gnome gems and the external StrIdx C++ gem. Copy the built .so back into
103
+ # the tree so `require "vmaext"` resolves when running from source.
104
+ echo ">> Building and installing the vimamsa gem"
105
+ rm -f vimamsa-0.1.*.gem
106
+ gem build vimamsa.gemspec
107
+ # NB: no --local — installing the local .gem must be allowed to fetch its runtime
108
+ # deps (gtk4, gtksourceview5, StrIdx, language_server-protocol, …) from rubygems.org.
109
+ sudo_do gem install vimamsa-0.1.*.gem
110
+ # A system `gem install` compiles the extension under Gem.dir/extensions/<platform>/
111
+ # <abi>/vimamsa-<ver>/vmaext.so (not under gems/.../ext), so locate it with find.
112
+ GEM_DIR="$(ruby -e 'puts Gem.dir')"
113
+ so_path="$(find "$GEM_DIR" -name vmaext.so -path '*vimamsa*' 2>/dev/null | head -1)"
114
+ [ -z "$so_path" ] && so_path="$(find "$GEM_DIR" -name vmaext.so 2>/dev/null | head -1)"
115
+ if [ -z "$so_path" ]; then
116
+ echo "!! Could not locate compiled vmaext.so under $GEM_DIR" >&2
117
+ exit 2
118
+ fi
119
+ cp "$so_path" lib/
120
+ touch "$MARKER"
121
+
122
+ # The ruby-lsp tests run `bundle exec ruby-lsp`. The synced Gemfile.lock is the
123
+ # host's and pins exact versions the guest doesn't have (gem install above picks
124
+ # the newest matching ones), so resolve the bundle against the guest's gems,
125
+ # installing only what's missing (e.g. the development dependencies).
126
+ rm -f Gemfile.lock
127
+ bundle check >/dev/null 2>&1 || sudo_do bundle install
128
+ fi
102
129
 
103
130
  # 4. Run the suite on the real desktop (no --headless: the window shows on-screen).
104
131
  export XDG_RUNTIME_DIR="/run/user/$(id -u)"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vimamsa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.28
4
+ version: 0.1.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sami Sieranoja
@@ -269,6 +269,7 @@ files:
269
269
  - doc/refactor_dedup_plan.md
270
270
  - doc/registries_plan.md
271
271
  - doc/startup_speed_plan.md
272
+ - doc/test_commands.md
272
273
  - doc/treap_visualizer.html
273
274
  - doc/unused_code_plan.md
274
275
  - doc/vim_compatibility_plan.md
@@ -346,6 +347,7 @@ files:
346
347
  - lib/vimamsa/key_bindings_notepad.rb
347
348
  - lib/vimamsa/key_bindings_report.rb
348
349
  - lib/vimamsa/key_bindings_vim.rb
350
+ - lib/vimamsa/key_bindings_vim_core.rb
349
351
  - lib/vimamsa/key_bindings_vimlike.rb
350
352
  - lib/vimamsa/key_names.rb
351
353
  - lib/vimamsa/langservp.rb
@@ -367,7 +369,6 @@ files:
367
369
  - lib/vimamsa/user_dirs.rb
368
370
  - lib/vimamsa/util.rb
369
371
  - lib/vimamsa/version.rb
370
- - lib/vimamsa/vim_core.rb
371
372
  - lib/vimamsa/vim_operators.rb
372
373
  - modules/calculator/calculator.rb
373
374
  - modules/calculator/calculator_info.rb
@@ -383,7 +384,6 @@ files:
383
384
  - modules/tts/tts.rb
384
385
  - modules/tts/tts_info.rb
385
386
  - run_e2e_vm.sh
386
- - run_tests.rb
387
387
  - run_tests_vm.rb
388
388
  - scripts/appimage/AppRun
389
389
  - scripts/appimage/Dockerfile
@@ -463,6 +463,7 @@ files:
463
463
  - tests/test_lsp_clangd.rb
464
464
  - tests/test_lsp_jump.rb
465
465
  - tests/test_lsp_position_encoding.rb
466
+ - tests/test_lsp_root.rb
466
467
  - tests/test_lsp_symbols.rb
467
468
  - tests/test_macro.rb
468
469
  - tests/test_markdown_highlight.rb
data/run_tests.rb DELETED
@@ -1,89 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $stdout.sync = true
3
- $stderr.sync = true
4
- # run_tests.rb — Discover and run all vimamsa tests, write a report.
5
- #
6
- # Usage:
7
- # ruby run_tests.rb [REPORT_FILE] default report: test_report.txt
8
- #
9
- # For headless / CI use:
10
- # xvfb-run ruby run_tests.rb
11
-
12
- require "open3"
13
-
14
- SCRIPT_DIR = File.expand_path("..", __FILE__)
15
- REPORT = File.expand_path(ARGV.first || "test_report.txt", SCRIPT_DIR)
16
-
17
- # ── Discover test files ───────────────────────────────────────────────────────
18
- test_files = Dir.glob(File.join(SCRIPT_DIR, "tests", "test_*.rb")).sort
19
-
20
- if test_files.empty?
21
- warn "ERROR: No test files found in tests/"
22
- exit 1
23
- end
24
-
25
- # ── Guard: need a display ─────────────────────────────────────────────────────
26
- unless ENV["DISPLAY"] || ENV["WAYLAND_DISPLAY"]
27
- xvfb = `which xvfb-run 2>/dev/null`.strip
28
- if xvfb.empty?
29
- warn "ERROR: No display found (DISPLAY/WAYLAND_DISPLAY unset) and xvfb-run not available."
30
- warn " Install xvfb or run from a desktop session."
31
- exit 1
32
- end
33
- puts "No display detected — re-running under xvfb-run."
34
- exec("xvfb-run", "-a", RbConfig.ruby, __FILE__, *ARGV)
35
- end
36
-
37
- # ── Print header ──────────────────────────────────────────────────────────────
38
- puts "=== Vimamsa test runner ==="
39
- puts "Running #{test_files.size} test file(s):"
40
- test_files.each { |f| puts " #{File.basename(f)}" }
41
- puts ""
42
-
43
- # ── Run tests ─────────────────────────────────────────────────────────────────
44
- # All files loaded in a single vimamsa session (one GTK startup).
45
- # stdout → streamed live and captured for the report
46
- # stderr → suppressed (GTK/GLib noise)
47
- cmd = [RbConfig.ruby, "exe/run_tests.rb", "--test", *test_files]
48
- raw = ""
49
- IO.popen([*cmd, err: File::NULL], chdir: SCRIPT_DIR) do |io|
50
- io.each_line do |line|
51
- print line
52
- raw << line
53
- end
54
- end
55
- puts ""
56
-
57
- # ── Parse summary ─────────────────────────────────────────────────────────────
58
- summary_line = raw.lines.grep(/^Results:/).last.to_s
59
- passed = summary_line[/(\d+) passed/, 1].to_i
60
- failed = summary_line[/(\d+) failed/, 1].to_i
61
- errors = raw.lines.count { |l| l.match?(/^\s+ERROR\s/) }
62
-
63
- timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
64
-
65
- # ── Write report ──────────────────────────────────────────────────────────────
66
- File.open(REPORT, "w") do |f|
67
- f.puts "Vimamsa Test Report — #{timestamp}"
68
- f.puts "=" * 52
69
- f.puts ""
70
- f.puts "Test files (#{test_files.size}):"
71
- test_files.each { |tf| f.puts " #{File.basename(tf)}" }
72
- f.puts ""
73
- f.puts "-" * 52
74
- f.puts raw
75
- f.puts "-" * 52
76
- f.puts ""
77
- f.puts "Summary"
78
- f.puts "-" * 52
79
- f.puts " Passed : #{passed}"
80
- f.puts " Failed : #{failed}"
81
- f.puts " Errors : #{errors}"
82
- f.puts "\n ALL TESTS PASSED" if failed + errors == 0
83
- f.puts ""
84
- end
85
-
86
- puts "Report written to: #{REPORT}"
87
- puts " Passed: #{passed} Failed: #{failed} Errors: #{errors}"
88
-
89
- exit(failed + errors == 0 ? 0 : 1)