Bram Moolenaar | 07dc18f | 2018-11-30 22:48:32 +0100 | [diff] [blame] | 1 | |
Yegappan Lakshmanan | f768c3d | 2022-08-22 13:15:13 +0100 | [diff] [blame] | 2 | " Test for the :scriptnames command |
Bram Moolenaar | 07dc18f | 2018-11-30 22:48:32 +0100 | [diff] [blame] | 3 | func Test_scriptnames() |
| 4 | call writefile(['let did_load_script = 123'], 'Xscripting') |
| 5 | source Xscripting |
| 6 | call assert_equal(123, g:did_load_script) |
| 7 | |
| 8 | let scripts = split(execute('scriptnames'), "\n") |
| 9 | let last = scripts[-1] |
| 10 | call assert_match('\<Xscripting\>', last) |
| 11 | let lastnr = substitute(last, '\D*\(\d\+\):.*', '\1', '') |
| 12 | exe 'script ' . lastnr |
| 13 | call assert_equal('Xscripting', expand('%:t')) |
| 14 | |
| 15 | call assert_fails('script ' . (lastnr + 1), 'E474:') |
| 16 | call assert_fails('script 0', 'E939:') |
| 17 | |
| 18 | new |
| 19 | call setline(1, 'nothing') |
| 20 | call assert_fails('script ' . lastnr, 'E37:') |
| 21 | exe 'script! ' . lastnr |
| 22 | call assert_equal('Xscripting', expand('%:t')) |
| 23 | |
| 24 | bwipe |
| 25 | call delete('Xscripting') |
Bram Moolenaar | 840f162 | 2022-01-18 13:34:05 +0000 | [diff] [blame] | 26 | |
| 27 | let msgs = execute('messages') |
| 28 | scriptnames |
| 29 | call assert_equal(msgs, execute('messages')) |
Bram Moolenaar | 07dc18f | 2018-11-30 22:48:32 +0100 | [diff] [blame] | 30 | endfunc |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 31 | |
Yegappan Lakshmanan | f768c3d | 2022-08-22 13:15:13 +0100 | [diff] [blame] | 32 | " Test for the getscriptinfo() function |
| 33 | func Test_getscriptinfo() |
Yegappan Lakshmanan | 520f6ef | 2022-08-25 17:40:40 +0100 | [diff] [blame] | 34 | let lines =<< trim END |
| 35 | let g:loaded_script_id = expand("<SID>") |
| 36 | let s:XscriptVar = [1, #{v: 2}] |
| 37 | func s:XscriptFunc() |
| 38 | endfunc |
| 39 | END |
| 40 | call writefile(lines, 'X22script91') |
| 41 | source X22script91 |
Yegappan Lakshmanan | f768c3d | 2022-08-22 13:15:13 +0100 | [diff] [blame] | 42 | let l = getscriptinfo() |
Yegappan Lakshmanan | 520f6ef | 2022-08-25 17:40:40 +0100 | [diff] [blame] | 43 | call assert_match('X22script91$', l[-1].name) |
Yegappan Lakshmanan | f768c3d | 2022-08-22 13:15:13 +0100 | [diff] [blame] | 44 | call assert_equal(g:loaded_script_id, $"<SNR>{l[-1].sid}_") |
Yegappan Lakshmanan | 520f6ef | 2022-08-25 17:40:40 +0100 | [diff] [blame] | 45 | |
| 46 | let l = getscriptinfo({'name': '22script91'}) |
| 47 | call assert_equal(1, len(l)) |
| 48 | call assert_match('22script91$', l[0].name) |
| 49 | |
| 50 | let l = getscriptinfo({'name': 'foobar'}) |
| 51 | call assert_equal(0, len(l)) |
| 52 | let l = getscriptinfo({'name': ''}) |
| 53 | call assert_true(len(l) > 1) |
| 54 | |
| 55 | call assert_fails("echo getscriptinfo({'name': []})", 'E730:') |
| 56 | call assert_fails("echo getscriptinfo({'name': '\\@'})", 'E866:') |
| 57 | let l = getscriptinfo({'name': test_null_string()}) |
| 58 | call assert_true(len(l) > 1) |
| 59 | call assert_fails("echo getscriptinfo('foobar')", 'E1206:') |
| 60 | |
| 61 | call delete('X22script91') |
Yegappan Lakshmanan | f768c3d | 2022-08-22 13:15:13 +0100 | [diff] [blame] | 62 | endfunc |
| 63 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 64 | " vim: shiftwidth=2 sts=2 expandtab |