annotate src/testdir/test_expand_func.vim @ 21600:622021f43db1 v8.2.1350

patch 8.2.1350: Vim9: no test for error message when redefining function Commit: https://github.com/vim/vim/commit/b9a2cac3ef293bfdfe80dea6c6d16d02b7af5435 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 1 22:23:20 2020 +0200 patch 8.2.1350: Vim9: no test for error message when redefining function Problem: Vim9: no test for error message when redefining function. Solution: Add a test.
author Bram Moolenaar <Bram@vim.org>
date Sat, 01 Aug 2020 22:30:05 +0200
parents 5daca8504c63
children a607f02fd17a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Tests for expand()
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
21594
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
3 source shared.vim
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
4
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 let s:sfile = expand('<sfile>')
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 let s:slnum = str2nr(expand('<slnum>'))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 let s:sflnum = str2nr(expand('<sflnum>'))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 func s:expand_sfile()
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 return expand('<sfile>')
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 endfunc
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 func s:expand_slnum()
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 return str2nr(expand('<slnum>'))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 endfunc
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 func s:expand_sflnum()
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 return str2nr(expand('<sflnum>'))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 endfunc
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20
21493
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
21 " This test depends on the location in the test file, put it first.
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
22 func Test_expand_sflnum()
21594
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
23 call assert_equal(7, s:sflnum)
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
24 call assert_equal(24, str2nr(expand('<sflnum>')))
21493
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
25
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
26 " Line-continuation
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
27 call assert_equal(
21594
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
28 \ 27,
21493
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
29 \ str2nr(expand('<sflnum>')))
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 " Call in script-local function
21594
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
32 call assert_equal(18, s:expand_sflnum())
21493
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
33
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
34 " Call in command
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
35 command Flnum echo expand('<sflnum>')
21594
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
36 call assert_equal(36, str2nr(trim(execute('Flnum'))))
21493
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
37 delcommand Flnum
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
38 endfunc
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
39
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
40 func Test_expand_sfile_and_stack()
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
41 call assert_match('test_expand_func\.vim$', s:sfile)
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
42 let expected = 'script .*testdir/runtest.vim\[\d\+\]\.\.function RunTheTest\[\d\+\]\.\.Test_expand_sfile_and_stack$'
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
43 call assert_match(expected , expand('<sfile>'))
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
44 call assert_match(expected , expand('<stack>'))
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
45
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
46 " Call in script-local function
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
47 call assert_match('script .*testdir/runtest.vim\[\d\+\]\.\.function RunTheTest\[\d\+\]\.\.Test_expand_sfile_and_stack\[7\]\.\.<SNR>\d\+_expand_sfile$', s:expand_sfile())
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 " Call in command
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 command Sfile echo expand('<sfile>')
21493
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
51 call assert_match('script .*testdir/runtest.vim\[\d\+\]\.\.function RunTheTest\[\d\+\]\.\.Test_expand_sfile_and_stack$', trim(execute('Sfile')))
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 delcommand Sfile
21493
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
53
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
54 " Use <stack> from sourced script.
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
55 let lines =<< trim END
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
56 let g:stack_value = expand('<stack>')
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
57 END
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
58 call writefile(lines, 'Xstack')
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
59 source Xstack
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
60 call assert_match('\<Xstack$', g:stack_value)
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
61 call delete('Xstack')
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 endfunc
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 func Test_expand_slnum()
21594
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
65 call assert_equal(6, s:slnum)
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 call assert_equal(2, str2nr(expand('<slnum>')))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 " Line-continuation
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 call assert_equal(
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 \ 5,
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 \ str2nr(expand('<slnum>')))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 " Call in script-local function
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 call assert_equal(1, s:expand_slnum())
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 " Call in command
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 command Slnum echo expand('<slnum>')
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 call assert_equal(14, str2nr(trim(execute('Slnum'))))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 delcommand Slnum
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 endfunc
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81
16668
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
82 func Test_expand()
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
83 new
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
84 call assert_equal("", expand('%:S'))
17849
73ddc462979d patch 8.1.1921: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
85 call assert_equal('3', '<slnum>'->expand())
16668
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
86 call assert_equal(['4'], expand('<slnum>', v:false, v:true))
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
87 " Don't add any line above this, otherwise <slnum> will change.
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
88 quit
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
89 endfunc
19603
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
90
21594
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
91 func s:sid_test()
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
92 return 'works'
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
93 endfunc
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
94
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
95 func Test_expand_SID()
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
96 let sid = expand('<SID>')
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
97 execute 'let g:sid_result = ' .. sid .. 'sid_test()'
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
98 call assert_equal('works', g:sid_result)
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
99 endfunc
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
100
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
101
19603
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
102 " Test for 'wildignore' with expand()
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
103 func Test_expand_wildignore()
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
104 set wildignore=*.vim
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
105 call assert_equal('', expand('test_expand_func.vim'))
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
106 call assert_equal('', expand('test_expand_func.vim', 0))
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
107 call assert_equal([], expand('test_expand_func.vim', 0, 1))
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
108 call assert_equal('test_expand_func.vim', expand('test_expand_func.vim', 1))
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
109 call assert_equal(['test_expand_func.vim'],
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
110 \ expand('test_expand_func.vim', 1, 1))
19783
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
111 call assert_fails("call expand('*', [])", 'E745:')
19603
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
112 set wildignore&
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
113 endfunc
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
114
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
115 " vim: shiftwidth=2 sts=2 expandtab