Mercurial > vim
annotate src/testdir/test_scriptnames.vim @ 32732:257ab4ee8e4a v9.0.1686
patch 9.0.1686: undotree() only works for the current buffer
Commit: https://github.com/vim/vim/commit/5fee11114975b7405b7ccd3ee8758e54bf559760
Author: Devin J. Pohly <djpohly@gmail.com>
Date: Sun Apr 23 20:26:59 2023 -0500
patch 9.0.1686: undotree() only works for the current buffer
Problem: undotree() only works for the current buffer
Solution: Add an optional "buffer number" parameter to undotree(). If
omitted, use the current buffer for backwards compatibility.
closes: #4001
closes: #12292
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Co-authored-by: Devin J. Pohly <djpohly@gmail.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 11 Aug 2023 23:00:05 +0200 |
parents | 730eebd56f48 |
children |
rev | line source |
---|---|
15085
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 |
29810
761631155a90
patch 9.0.0244: cannot easily get the list of sourced scripts
Bram Moolenaar <Bram@vim.org>
parents:
27209
diff
changeset
|
2 " Test for the :scriptnames command |
15085
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 func Test_scriptnames() |
30769
ae10b91ac6b3
patch 9.0.0719: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
4 call writefile(['let did_load_script = 123'], 'Xscripting', 'D') |
15085
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 source Xscripting |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 call assert_equal(123, g:did_load_script) |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 let scripts = split(execute('scriptnames'), "\n") |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 let last = scripts[-1] |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 call assert_match('\<Xscripting\>', last) |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 let lastnr = substitute(last, '\D*\(\d\+\):.*', '\1', '') |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 exe 'script ' . lastnr |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 call assert_equal('Xscripting', expand('%:t')) |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 call assert_fails('script ' . (lastnr + 1), 'E474:') |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 call assert_fails('script 0', 'E939:') |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 new |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 call setline(1, 'nothing') |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 call assert_fails('script ' . lastnr, 'E37:') |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 exe 'script! ' . lastnr |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 call assert_equal('Xscripting', expand('%:t')) |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 bwipe |
27209
fa09602eae48
patch 8.2.4133: output of ":scriptnames" goes into the message history
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
25 |
fa09602eae48
patch 8.2.4133: output of ":scriptnames" goes into the message history
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
26 let msgs = execute('messages') |
fa09602eae48
patch 8.2.4133: output of ":scriptnames" goes into the message history
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
27 scriptnames |
fa09602eae48
patch 8.2.4133: output of ":scriptnames" goes into the message history
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
28 call assert_equal(msgs, execute('messages')) |
15085
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 endfunc |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
15085
diff
changeset
|
30 |
29810
761631155a90
patch 9.0.0244: cannot easily get the list of sourced scripts
Bram Moolenaar <Bram@vim.org>
parents:
27209
diff
changeset
|
31 " Test for the getscriptinfo() function |
761631155a90
patch 9.0.0244: cannot easily get the list of sourced scripts
Bram Moolenaar <Bram@vim.org>
parents:
27209
diff
changeset
|
32 func Test_getscriptinfo() |
29861
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
33 let lines =<< trim END |
29930
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
34 scriptversion 3 |
29861
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
35 let g:loaded_script_id = expand("<SID>") |
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
36 let s:XscriptVar = [1, #{v: 2}] |
29930
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
37 func s:XgetScriptVar() |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
38 return s:XscriptVar |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
39 endfunc |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
40 func s:Xscript_legacy_func1() |
29861
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
41 endfunc |
29930
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
42 def s:Xscript_def_func1() |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
43 enddef |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
44 func Xscript_legacy_func2() |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
45 endfunc |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
46 def Xscript_def_func2() |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
47 enddef |
29861
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
48 END |
30769
ae10b91ac6b3
patch 9.0.0719: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
49 call writefile(lines, 'X22script91', 'D') |
29861
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
50 source X22script91 |
29810
761631155a90
patch 9.0.0244: cannot easily get the list of sourced scripts
Bram Moolenaar <Bram@vim.org>
parents:
27209
diff
changeset
|
51 let l = getscriptinfo() |
29861
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
52 call assert_match('X22script91$', l[-1].name) |
29810
761631155a90
patch 9.0.0244: cannot easily get the list of sourced scripts
Bram Moolenaar <Bram@vim.org>
parents:
27209
diff
changeset
|
53 call assert_equal(g:loaded_script_id, $"<SNR>{l[-1].sid}_") |
29930
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
54 call assert_equal(3, l[-1].version) |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
55 call assert_equal(0, has_key(l[-1], 'variables')) |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
56 call assert_equal(0, has_key(l[-1], 'functions')) |
29861
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
57 |
29930
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
58 " Get script information using script name |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
59 let l = getscriptinfo(#{name: '22script91'}) |
29861
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
60 call assert_equal(1, len(l)) |
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
61 call assert_match('22script91$', l[0].name) |
29930
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
62 let sid = l[0].sid |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
63 |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
64 " Get script information using script-ID |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
65 let l = getscriptinfo({'sid': sid}) |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
66 call assert_equal(#{XscriptVar: [1, {'v': 2}]}, l[0].variables) |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
67 let funcs = ['Xscript_legacy_func2', |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
68 \ $"<SNR>{sid}_Xscript_legacy_func1", |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
69 \ $"<SNR>{sid}_Xscript_def_func1", |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
70 \ 'Xscript_def_func2', |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
71 \ $"<SNR>{sid}_XgetScriptVar"] |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
72 for f in funcs |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
73 call assert_true(index(l[0].functions, f) != -1) |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
74 endfor |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
75 |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
76 " Verify that a script-local variable cannot be modified using the dict |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
77 " returned by getscriptinfo() |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
78 let l[0].variables.XscriptVar = ['n'] |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
79 let funcname = $"<SNR>{sid}_XgetScriptVar" |
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
80 call assert_equal([1, {'v': 2}], call(funcname, [])) |
29861
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
81 |
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
82 let l = getscriptinfo({'name': 'foobar'}) |
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
83 call assert_equal(0, len(l)) |
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
84 let l = getscriptinfo({'name': ''}) |
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
85 call assert_true(len(l) > 1) |
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
86 |
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
87 call assert_fails("echo getscriptinfo({'name': []})", 'E730:') |
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
88 call assert_fails("echo getscriptinfo({'name': '\\@'})", 'E866:') |
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
89 let l = getscriptinfo({'name': test_null_string()}) |
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
90 call assert_true(len(l) > 1) |
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
91 call assert_fails("echo getscriptinfo('foobar')", 'E1206:') |
8dca33bca038
patch 9.0.0269: getscriptinfo() does not include the version
Bram Moolenaar <Bram@vim.org>
parents:
29810
diff
changeset
|
92 |
29930
cd573d7bc30d
patch 9.0.0303: it is not easy to get information about a script
Bram Moolenaar <Bram@vim.org>
parents:
29861
diff
changeset
|
93 call assert_fails("echo getscriptinfo({'sid': []})", 'E745:') |
32200
730eebd56f48
patch 9.0.1431: getscriptinfo() loops even when specific SID is given
Bram Moolenaar <Bram@vim.org>
parents:
30769
diff
changeset
|
94 call assert_fails("echo getscriptinfo({'sid': {}})", 'E728:') |
730eebd56f48
patch 9.0.1431: getscriptinfo() loops even when specific SID is given
Bram Moolenaar <Bram@vim.org>
parents:
30769
diff
changeset
|
95 call assert_fails("echo getscriptinfo({'sid': 0})", 'E475:') |
730eebd56f48
patch 9.0.1431: getscriptinfo() loops even when specific SID is given
Bram Moolenaar <Bram@vim.org>
parents:
30769
diff
changeset
|
96 call assert_fails("echo getscriptinfo({'sid': -1})", 'E475:') |
730eebd56f48
patch 9.0.1431: getscriptinfo() loops even when specific SID is given
Bram Moolenaar <Bram@vim.org>
parents:
30769
diff
changeset
|
97 call assert_fails("echo getscriptinfo({'sid': -999})", 'E475:') |
730eebd56f48
patch 9.0.1431: getscriptinfo() loops even when specific SID is given
Bram Moolenaar <Bram@vim.org>
parents:
30769
diff
changeset
|
98 |
730eebd56f48
patch 9.0.1431: getscriptinfo() loops even when specific SID is given
Bram Moolenaar <Bram@vim.org>
parents:
30769
diff
changeset
|
99 echo getscriptinfo({'sid': '1'}) |
730eebd56f48
patch 9.0.1431: getscriptinfo() loops even when specific SID is given
Bram Moolenaar <Bram@vim.org>
parents:
30769
diff
changeset
|
100 call assert_fails("vim9cmd echo getscriptinfo({'sid': '1'})", 'E1030:') |
730eebd56f48
patch 9.0.1431: getscriptinfo() loops even when specific SID is given
Bram Moolenaar <Bram@vim.org>
parents:
30769
diff
changeset
|
101 |
730eebd56f48
patch 9.0.1431: getscriptinfo() loops even when specific SID is given
Bram Moolenaar <Bram@vim.org>
parents:
30769
diff
changeset
|
102 let max_sid = max(map(getscriptinfo(), { k, v -> v.sid })) |
730eebd56f48
patch 9.0.1431: getscriptinfo() loops even when specific SID is given
Bram Moolenaar <Bram@vim.org>
parents:
30769
diff
changeset
|
103 call assert_equal([], getscriptinfo({'sid': max_sid + 1})) |
29810
761631155a90
patch 9.0.0244: cannot easily get the list of sourced scripts
Bram Moolenaar <Bram@vim.org>
parents:
27209
diff
changeset
|
104 endfunc |
761631155a90
patch 9.0.0244: cannot easily get the list of sourced scripts
Bram Moolenaar <Bram@vim.org>
parents:
27209
diff
changeset
|
105 |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
15085
diff
changeset
|
106 " vim: shiftwidth=2 sts=2 expandtab |