diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-04-15 21:27:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-15 21:27:30 +0800 |
commit | 2e2101cf7b0e4a70f5670d9d1317860a47bb8385 (patch) | |
tree | dadcd914c45ee440bb85e63e889d9e2723182fdb /test | |
parent | eb151a9730f0000ff46e0b3467e29bb9f02ae362 (diff) | |
parent | 9770dcf96d77d734e2b88fc693c0f4fa0a17ef74 (diff) | |
download | rneovim-2e2101cf7b0e4a70f5670d9d1317860a47bb8385.tar.gz rneovim-2e2101cf7b0e4a70f5670d9d1317860a47bb8385.tar.bz2 rneovim-2e2101cf7b0e4a70f5670d9d1317860a47bb8385.zip |
Merge pull request #23107 from zeertzjq/vim-9.0.0269
vim-patch:9.0.{0269,0303,1431}: more getscriptinfo() features
Diffstat (limited to 'test')
-rw-r--r-- | test/old/testdir/test_scriptnames.vim | 76 |
1 files changed, 72 insertions, 4 deletions
diff --git a/test/old/testdir/test_scriptnames.vim b/test/old/testdir/test_scriptnames.vim index 06ae305ab7..69e5e526fd 100644 --- a/test/old/testdir/test_scriptnames.vim +++ b/test/old/testdir/test_scriptnames.vim @@ -31,12 +31,80 @@ endfunc " Test for the getscriptinfo() function func Test_getscriptinfo() - call writefile(['let loaded_script_id = expand("<SID>")'], 'Xscript') - source Xscript + 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') + source X22script91 let l = getscriptinfo() - call assert_match('Xscript$', l[-1].name) + call assert_match('X22script91$', l[-1].name) call assert_equal(g:loaded_script_id, $"<SNR>{l[-1].sid}_") - call delete('Xscript') + " call assert_equal(3, l[-1].version) + call assert_equal(1, 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': v:_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})) + + call delete('X22script91') endfunc " vim: shiftwidth=2 sts=2 expandtab |