From bcc971de15ed540356405f937d640eaffa4a03bb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 15 Apr 2023 19:50:23 +0800 Subject: vim-patch:9.0.0269: getscriptinfo() does not include the version Problem: getscriptinfo() does not include the version. Cannot select entries by script name. Solution: Add the "version" item and the "name" argument. (Yegappan Lakshmanan, closes vim/vim#10962) https://github.com/vim/vim/commit/520f6ef60a59f7b5f3da9199999d13dbe817d3ce Co-authored-by: Yegappan Lakshmanan --- test/old/testdir/test_scriptnames.vim | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'test/old/testdir/test_scriptnames.vim') diff --git a/test/old/testdir/test_scriptnames.vim b/test/old/testdir/test_scriptnames.vim index 06ae305ab7..a04cce3b44 100644 --- a/test/old/testdir/test_scriptnames.vim +++ b/test/old/testdir/test_scriptnames.vim @@ -31,12 +31,34 @@ endfunc " Test for the getscriptinfo() function func Test_getscriptinfo() - call writefile(['let loaded_script_id = expand("")'], 'Xscript') - source Xscript + let lines =<< trim END + let g:loaded_script_id = expand("") + let s:XscriptVar = [1, #{v: 2}] + func s:XscriptFunc() + endfunc + 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, $"{l[-1].sid}_") - call delete('Xscript') + + let l = getscriptinfo({'name': '22script91'}) + call assert_equal(1, len(l)) + call assert_match('22script91$', l[0].name) + + 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 delete('X22script91') endfunc " vim: shiftwidth=2 sts=2 expandtab -- cgit From e9b4f5105100ce2279915bbe1d67d299c294db24 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 15 Apr 2023 19:57:55 +0800 Subject: vim-patch:9.0.0303: it is not easy to get information about a script Problem: It is not easy to get information about a script. Solution: Make getscriptinf() return the version. When selecting a specific script return functions and variables. (Yegappan Lakshmanan, closes vim/vim#10991) https://github.com/vim/vim/commit/2f892d8663498c21296ad6661dac1bb8372cfd10 Co-authored-by: Yegappan Lakshmanan --- test/old/testdir/test_scriptnames.vim | 40 +++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'test/old/testdir/test_scriptnames.vim') diff --git a/test/old/testdir/test_scriptnames.vim b/test/old/testdir/test_scriptnames.vim index a04cce3b44..33b00e2505 100644 --- a/test/old/testdir/test_scriptnames.vim +++ b/test/old/testdir/test_scriptnames.vim @@ -32,20 +32,54 @@ endfunc " Test for the getscriptinfo() function func Test_getscriptinfo() let lines =<< trim END + " scriptversion 3 let g:loaded_script_id = expand("") let s:XscriptVar = [1, #{v: 2}] - func s:XscriptFunc() + 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('X22script91$', l[-1].name) call assert_equal(g:loaded_script_id, $"{l[-1].sid}_") + " 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')) - let l = getscriptinfo({'name': '22script91'}) + " 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', + \ $"{sid}_Xscript_legacy_func1", + "\ $"{sid}_Xscript_def_func1", + "\ 'Xscript_def_func2', + \ $"{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 = $"{sid}_XgetScriptVar" + call assert_equal([1, {'v': 2}], call(funcname, [])) let l = getscriptinfo({'name': 'foobar'}) call assert_equal(0, len(l)) @@ -58,6 +92,8 @@ func Test_getscriptinfo() call assert_true(len(l) > 1) call assert_fails("echo getscriptinfo('foobar')", 'E1206:') + call assert_fails("echo getscriptinfo({'sid': []})", 'E745:') + call delete('X22script91') endfunc -- cgit From c5ec823a14f88a1d5ea1872f39fdabd85af1e81c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 15 Apr 2023 20:47:04 +0800 Subject: vim-patch:9.0.1431: getscriptinfo() loops even when specific SID is given Problem: getscriptinfo() loops even when specific SID is given. Solution: Only loop when needed. Give a clearer error message. (closes vim/vim#12207) https://github.com/vim/vim/commit/2d68b722e3bca7532eb0d83ce773934618f12db5 --- test/old/testdir/test_scriptnames.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/old/testdir/test_scriptnames.vim') diff --git a/test/old/testdir/test_scriptnames.vim b/test/old/testdir/test_scriptnames.vim index 33b00e2505..69e5e526fd 100644 --- a/test/old/testdir/test_scriptnames.vim +++ b/test/old/testdir/test_scriptnames.vim @@ -93,6 +93,16 @@ func Test_getscriptinfo() 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 -- cgit