blob: 2d8ee6186791bc0c558b9e44c34a3d7688f342f1 [file] [log] [blame]
Bram Moolenaar07dc18f2018-11-30 22:48:32 +01001
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01002" Test for the :scriptnames command
Bram Moolenaar07dc18f2018-11-30 22:48:32 +01003func 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 Moolenaar840f1622022-01-18 13:34:05 +000026
27 let msgs = execute('messages')
28 scriptnames
29 call assert_equal(msgs, execute('messages'))
Bram Moolenaar07dc18f2018-11-30 22:48:32 +010030endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020031
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +010032" Test for the getscriptinfo() function
33func Test_getscriptinfo()
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +010034 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 Lakshmananf768c3d2022-08-22 13:15:13 +010042 let l = getscriptinfo()
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +010043 call assert_match('X22script91$', l[-1].name)
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +010044 call assert_equal(g:loaded_script_id, $"<SNR>{l[-1].sid}_")
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +010045
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 Lakshmananf768c3d2022-08-22 13:15:13 +010062endfunc
63
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020064" vim: shiftwidth=2 sts=2 expandtab