Mercurial > vim
comparison src/testdir/test_signs.vim @ 9838:66f1cf5dd385 v7.4.2194
commit https://github.com/vim/vim/commit/446a973ce3ce4988607292c0e6345db788f12c7b
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Aug 10 21:36:23 2016 +0200
patch 7.4.2194
Problem: Sign tests don't cover enough.
Solution: Add more test cases. (Dominique Pelle)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 10 Aug 2016 21:45:05 +0200 |
parents | 74990ddf0813 |
children | 5a667a3a3743 |
comparison
equal
deleted
inserted
replaced
9837:372c1b42edb3 | 9838:66f1cf5dd385 |
---|---|
6 | 6 |
7 func Test_sign() | 7 func Test_sign() |
8 new | 8 new |
9 call setline(1, ['a', 'b', 'c', 'd']) | 9 call setline(1, ['a', 'b', 'c', 'd']) |
10 | 10 |
11 " Define some signs. | |
12 " We can specify icons even if not all versions of vim support icons as | |
13 " icon is ignored when not supported. "(not supported)" is shown after | |
14 " the icon name when listing signs. | |
11 sign define Sign1 text=x | 15 sign define Sign1 text=x |
12 sign define Sign2 text=y | 16 try |
17 sign define Sign2 text=xy texthl=Title linehl=Error icon=../../pixmaps/stock_vim_find_help.png | |
18 catch /E255:/ | |
19 " ignore error: E255: Couldn't read in sign data! | |
20 " This error can happen when running in gui. | |
21 " Some gui like Motif do not support the png icon format. | |
22 endtry | |
13 | 23 |
14 " Test listing signs. | 24 " Test listing signs. |
15 let a=execute('sign list') | 25 let a=execute('sign list') |
16 call assert_equal("\nsign Sign1 text=x \nsign Sign2 text=y ", a) | 26 call assert_match("^\nsign Sign1 text=x \nsign Sign2 icon=../../pixmaps/stock_vim_find_help.png .*text=xy linehl=Error texthl=Title$", a) |
17 | 27 |
18 let a=execute('sign list Sign1') | 28 let a=execute('sign list Sign1') |
19 call assert_equal("\nsign Sign1 text=x ", a) | 29 call assert_equal("\nsign Sign1 text=x ", a) |
20 | 30 |
21 " Place the sign at line 3,then check that we can jump to it. | 31 " Split the window to the bottom to verify sign jump will stay in the current window |
22 exe 'sign place 42 line=3 name=Sign1 buffer=' . bufnr('') | 32 " if the buffer is displayed there. |
33 let bn = bufnr('%') | |
34 let wn = winnr() | |
35 exe 'sign place 41 line=3 name=Sign1 buffer=' . bn | |
23 1 | 36 1 |
24 exe 'sign jump 42 buffer=' . bufnr('') | 37 bot split |
38 exe 'sign jump 41 buffer=' . bufnr('%') | |
39 call assert_equal('c', getline('.')) | |
40 call assert_equal(3, winnr()) | |
41 call assert_equal(bn, bufnr('%')) | |
42 call assert_notequal(wn, winnr()) | |
43 | |
44 " Create a new buffer and check that ":sign jump" switches to the old buffer. | |
45 1 | |
46 new foo | |
47 call assert_notequal(bn, bufnr('%')) | |
48 exe 'sign jump 41 buffer=' . bn | |
49 call assert_equal(bn, bufnr('%')) | |
25 call assert_equal('c', getline('.')) | 50 call assert_equal('c', getline('.')) |
26 | 51 |
27 " Can't change sign. | 52 " Redraw to make sure that screen redraw with sign gets exercised, |
28 call assert_fails("exe 'sign place 43 name=Sign1 buffer=' . bufnr('')", 'E885:') | 53 " with and without 'rightleft'. |
54 if has('rightleft') | |
55 set rightleft | |
56 redraw | |
57 set norightleft | |
58 endif | |
59 redraw | |
29 | 60 |
61 " Check that we can't change sign. | |
62 call assert_fails("exe 'sign place 40 name=Sign1 buffer=' . bufnr('%')", 'E885:') | |
63 | |
64 " Check placed signs | |
30 let a=execute('sign place') | 65 let a=execute('sign place') |
31 call assert_equal("\n--- Signs ---\nSigns for [NULL]:\n line=3 id=42 name=Sign1\n", a) | 66 call assert_equal("\n--- Signs ---\nSigns for [NULL]:\n line=3 id=41 name=Sign1\n", a) |
32 | 67 |
33 " Unplace the sign and try jumping to it again should now fail. | 68 " Unplace the sign and try jumping to it again should fail. |
34 sign unplace 42 | 69 sign unplace 41 |
35 1 | 70 1 |
36 call assert_fails("exe 'sign jump 42 buffer=' . bufnr('')", 'E157:') | 71 call assert_fails("exe 'sign jump 41 buffer=' . bufnr('%')", 'E157:') |
37 call assert_equal('a', getline('.')) | 72 call assert_equal('a', getline('.')) |
38 | 73 |
39 " Unplace sign on current line. | 74 " Unplace sign on current line. |
40 exe 'sign place 43 line=4 name=Sign2 buffer=' . bufnr('') | 75 exe 'sign place 42 line=4 name=Sign2 buffer=' . bufnr('%') |
41 4 | 76 4 |
42 sign unplace | 77 sign unplace |
43 let a=execute('sign place') | 78 let a=execute('sign place') |
44 call assert_equal("\n--- Signs ---\n", a) | 79 call assert_equal("\n--- Signs ---\n", a) |
45 | 80 |
46 " Try again to unplace sign on current line, it should fail this time. | 81 " Try again to unplace sign on current line, it should fail this time. |
47 call assert_fails('sign unplace', 'E159:') | 82 call assert_fails('sign unplace', 'E159:') |
48 | 83 |
49 " Unplace all signs. | 84 " Unplace all signs. |
50 exe 'sign place 42 line=3 name=Sign1 buffer=' . bufnr('') | 85 exe 'sign place 41 line=3 name=Sign1 buffer=' . bufnr('%') |
51 sign unplace * | 86 sign unplace * |
52 let a=execute('sign place') | 87 let a=execute('sign place') |
53 call assert_equal("\n--- Signs ---\n", a) | 88 call assert_equal("\n--- Signs ---\n", a) |
54 | 89 |
90 " Check :jump with file=... | |
91 edit foo | |
92 call setline(1, ['A', 'B', 'C', 'D']) | |
93 | |
94 try | |
95 sign define Sign3 text=y texthl=DoesNotExist linehl=DoesNotExist icon=doesnotexist.xpm | |
96 catch /E255:/ | |
97 " ignore error: E255: it can happens for guis. | |
98 endtry | |
99 | |
100 let fn = expand('%:p') | |
101 exe 'sign place 43 line=2 name=Sign3 file=' . fn | |
102 edit bar | |
103 call assert_notequal(fn, expand('%:p')) | |
104 exe 'sign jump 43 file=' . fn | |
105 call assert_equal('B', getline('.')) | |
106 | |
55 " After undefining the sign, we should no longer be able to place it. | 107 " After undefining the sign, we should no longer be able to place it. |
56 sign undefine Sign1 | 108 sign undefine Sign1 |
57 sign undefine Sign2 | 109 sign undefine Sign2 |
58 call assert_fails("exe 'sign place 42 line=3 name=Sign1 buffer=' . bufnr('')", 'E155:') | 110 sign undefine Sign3 |
111 call assert_fails("exe 'sign place 41 line=3 name=Sign1 buffer=' . bufnr('%')", 'E155:') | |
112 endfunc | |
59 | 113 |
114 " Undefining placed sign is not recommended. | |
115 " Quoting :help sign | |
116 " | |
117 " :sign undefine {name} | |
118 " Deletes a previously defined sign. If signs with this {name} | |
119 " are still placed this will cause trouble. | |
120 func Test_sign_undefine_still_placed() | |
121 new foobar | |
122 sign define Sign text=x | |
123 exe 'sign place 41 line=1 name=Sign buffer=' . bufnr('%') | |
124 sign undefine Sign | |
125 | |
126 " Listing placed sign should show that sign is deleted. | |
127 let a=execute('sign place') | |
128 call assert_equal("\n--- Signs ---\nSigns for foobar:\n line=1 id=41 name=[Deleted]\n", a) | |
129 | |
130 sign unplace 41 | |
131 let a=execute('sign place') | |
132 call assert_equal("\n--- Signs ---\n", a) | |
60 endfunc | 133 endfunc |
61 | 134 |
62 func Test_sign_completion() | 135 func Test_sign_completion() |
63 sign define Sign1 text=x | 136 sign define Sign1 text=x |
64 sign define Sign2 text=y | 137 sign define Sign2 text=y |
69 call feedkeys(":sign define Sign \<C-A>\<C-B>\"\<CR>", 'tx') | 142 call feedkeys(":sign define Sign \<C-A>\<C-B>\"\<CR>", 'tx') |
70 call assert_equal('"sign define Sign icon= linehl= text= texthl=', @:) | 143 call assert_equal('"sign define Sign icon= linehl= text= texthl=', @:) |
71 | 144 |
72 call feedkeys(":sign define Sign linehl=Spell\<C-A>\<C-B>\"\<CR>", 'tx') | 145 call feedkeys(":sign define Sign linehl=Spell\<C-A>\<C-B>\"\<CR>", 'tx') |
73 call assert_equal('"sign define Sign linehl=SpellBad SpellCap SpellLocal SpellRare', @:) | 146 call assert_equal('"sign define Sign linehl=SpellBad SpellCap SpellLocal SpellRare', @:) |
147 | |
148 call feedkeys(":sign define Sign icon=../../pixmaps/tb_p\<C-A>\<C-B>\"\<CR>", 'tx') | |
149 call assert_equal('"sign define Sign icon=../../pixmaps/tb_paste.xpm ../../pixmaps/tb_print.xpm', @:) | |
74 | 150 |
75 call feedkeys(":sign undefine \<C-A>\<C-B>\"\<CR>", 'tx') | 151 call feedkeys(":sign undefine \<C-A>\<C-B>\"\<CR>", 'tx') |
76 call assert_equal('"sign undefine Sign1 Sign2', @:) | 152 call assert_equal('"sign undefine Sign1 Sign2', @:) |
77 | 153 |
78 call feedkeys(":sign place 1 \<C-A>\<C-B>\"\<CR>", 'tx') | 154 call feedkeys(":sign place 1 \<C-A>\<C-B>\"\<CR>", 'tx') |
90 call feedkeys(":sign jump 1 \<C-A>\<C-B>\"\<CR>", 'tx') | 166 call feedkeys(":sign jump 1 \<C-A>\<C-B>\"\<CR>", 'tx') |
91 call assert_equal('"sign jump 1 buffer= file=', @:) | 167 call assert_equal('"sign jump 1 buffer= file=', @:) |
92 | 168 |
93 sign undefine Sign1 | 169 sign undefine Sign1 |
94 sign undefine Sign2 | 170 sign undefine Sign2 |
95 | |
96 endfunc | 171 endfunc |
97 | 172 |
98 func Test_sign_invalid_commands() | 173 func Test_sign_invalid_commands() |
99 call assert_fails('sign', 'E471:') | 174 call assert_fails('sign', 'E471:') |
175 call assert_fails('sign jump', 'E471:') | |
100 call assert_fails('sign xxx', 'E160:') | 176 call assert_fails('sign xxx', 'E160:') |
101 call assert_fails('sign define', 'E156:') | 177 call assert_fails('sign define', 'E156:') |
178 call assert_fails('sign define Sign1 xxx', 'E475:') | |
102 call assert_fails('sign undefine', 'E156:') | 179 call assert_fails('sign undefine', 'E156:') |
103 call assert_fails('sign list xxx', 'E155:') | 180 call assert_fails('sign list xxx', 'E155:') |
104 call assert_fails('sign place 1 buffer=', 'E158:') | 181 call assert_fails('sign place 1 buffer=', 'E158:') |
105 call assert_fails('sign define Sign2 text=', 'E239:') | 182 call assert_fails('sign define Sign2 text=', 'E239:') |
106 endfunc | 183 endfunc |