Mercurial > vim
view src/testdir/test_scriptnames.vim @ 34379:37b4c89ba420 v9.1.0116
patch 9.1.0116: win_split_ins may not check available room
Commit: https://github.com/vim/vim/commit/0fd44a5ad81ade342cb54d8984965bdedd2272c8
Author: Sean Dewar <6256228+seandewar@users.noreply.github.com>
Date: Tue Feb 20 20:28:15 2024 +0100
patch 9.1.0116: win_split_ins may not check available room
Problem: win_split_ins has no check for E36 when moving an existing
window
Solution: check for room and fix the issues in f_win_splitmove()
(Sean Dewar)
win_split_ins has no check for E36 when moving an existing window,
allowing for layouts with many overlapping zero-sized windows to be
created (which may also cause drawing issues with tablines and such).
f_win_splitmove also has some bugs.
So check for room and fix the issues in f_win_splitmove. Handle failure
in the two relevant win_split_ins callers by restoring the original
layout, and factor the common logic into win_splitmove.
Don't check for room when opening an autocommand window, as it's a
temporary window that's rarely interacted with or drawn anyhow, and is
rather important for some autocommands.
Issues fixed in f_win_splitmove:
- Error if splitting is disallowed.
- Fix heap-use-after-frees if autocommands fired from switching to "targetwin"
close "wp" or "oldwin".
- Fix splitting the wrong window if autocommands fired from switching to
"targetwin" switch to a different window.
- Ensure -1 is returned for all errors.
Also handle allocation failure a bit earlier in make_snapshot (callers,
except win_splitmove, don't really care if a snapshot can't be made, so
just ignore the return value).
Note: Test_smoothscroll_in_zero_width_window failed after these changes with
E36, as it was using the previous behaviour to create a zero-width window.
I've fixed the test such that it fails with UBSAN as expected when v9.0.1367 is
reverted (and simplified it too).
related: #14042
Signed-off-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 20 Feb 2024 22:30:04 +0100 |
parents | 730eebd56f48 |
children |
line wrap: on
line source
" Test for the :scriptnames command func Test_scriptnames() call writefile(['let did_load_script = 123'], 'Xscripting', 'D') source Xscripting call assert_equal(123, g:did_load_script) let scripts = split(execute('scriptnames'), "\n") let last = scripts[-1] call assert_match('\<Xscripting\>', last) let lastnr = substitute(last, '\D*\(\d\+\):.*', '\1', '') exe 'script ' . lastnr call assert_equal('Xscripting', expand('%:t')) call assert_fails('script ' . (lastnr + 1), 'E474:') call assert_fails('script 0', 'E939:') new call setline(1, 'nothing') call assert_fails('script ' . lastnr, 'E37:') exe 'script! ' . lastnr call assert_equal('Xscripting', expand('%:t')) bwipe let msgs = execute('messages') scriptnames call assert_equal(msgs, execute('messages')) endfunc " Test for the getscriptinfo() function func Test_getscriptinfo() let lines =<< trim END scriptversion 3 let g:loaded_script_id = expand("<SID>") let s:XscriptVar = [1, #{v: 2}] func s:XgetScriptVar() return s:XscriptVar endfunc func s:Xscript_legacy_func1() endfunc def s:Xscript_def_func1() enddef func Xscript_legacy_func2() endfunc def Xscript_def_func2() enddef END call writefile(lines, 'X22script91', 'D') source X22script91 let l = getscriptinfo() call assert_match('X22script91$', l[-1].name) call assert_equal(g:loaded_script_id, $"<SNR>{l[-1].sid}_") call assert_equal(3, l[-1].version) call assert_equal(0, has_key(l[-1], 'variables')) call assert_equal(0, has_key(l[-1], 'functions')) " Get script information using script name let l = getscriptinfo(#{name: '22script91'}) call assert_equal(1, len(l)) call assert_match('22script91$', l[0].name) let sid = l[0].sid " Get script information using script-ID let l = getscriptinfo({'sid': sid}) call assert_equal(#{XscriptVar: [1, {'v': 2}]}, l[0].variables) let funcs = ['Xscript_legacy_func2', \ $"<SNR>{sid}_Xscript_legacy_func1", \ $"<SNR>{sid}_Xscript_def_func1", \ 'Xscript_def_func2', \ $"<SNR>{sid}_XgetScriptVar"] for f in funcs call assert_true(index(l[0].functions, f) != -1) endfor " Verify that a script-local variable cannot be modified using the dict " returned by getscriptinfo() let l[0].variables.XscriptVar = ['n'] let funcname = $"<SNR>{sid}_XgetScriptVar" call assert_equal([1, {'v': 2}], call(funcname, [])) let l = getscriptinfo({'name': 'foobar'}) call assert_equal(0, len(l)) let l = getscriptinfo({'name': ''}) call assert_true(len(l) > 1) call assert_fails("echo getscriptinfo({'name': []})", 'E730:') call assert_fails("echo getscriptinfo({'name': '\\@'})", 'E866:') let l = getscriptinfo({'name': test_null_string()}) call assert_true(len(l) > 1) call assert_fails("echo getscriptinfo('foobar')", 'E1206:') call assert_fails("echo getscriptinfo({'sid': []})", 'E745:') call assert_fails("echo getscriptinfo({'sid': {}})", 'E728:') call assert_fails("echo getscriptinfo({'sid': 0})", 'E475:') call assert_fails("echo getscriptinfo({'sid': -1})", 'E475:') call assert_fails("echo getscriptinfo({'sid': -999})", 'E475:') echo getscriptinfo({'sid': '1'}) call assert_fails("vim9cmd echo getscriptinfo({'sid': '1'})", 'E1030:') let max_sid = max(map(getscriptinfo(), { k, v -> v.sid })) call assert_equal([], getscriptinfo({'sid': max_sid + 1})) endfunc " vim: shiftwidth=2 sts=2 expandtab