Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 1 | " Test for signs |
| 2 | |
| 3 | if !has('signs') |
| 4 | finish |
| 5 | endif |
| 6 | |
| 7 | func Test_sign() |
| 8 | new |
| 9 | call setline(1, ['a', 'b', 'c', 'd']) |
| 10 | |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 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. |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 15 | sign define Sign1 text=x |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 16 | try |
| 17 | sign define Sign2 text=xy texthl=Title linehl=Error icon=../../pixmaps/stock_vim_find_help.png |
| 18 | catch /E255:/ |
Bram Moolenaar | 162b714 | 2018-12-21 15:17:36 +0100 | [diff] [blame] | 19 | " Ignore error: E255: Couldn't read in sign data! |
| 20 | " This error can happen when running in the GUI. |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 21 | " Some gui like Motif do not support the png icon format. |
| 22 | endtry |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 23 | |
| 24 | " Test listing signs. |
| 25 | let a=execute('sign list') |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 26 | call assert_match("^\nsign Sign1 text=x \nsign Sign2 icon=../../pixmaps/stock_vim_find_help.png .*text=xy linehl=Error texthl=Title$", a) |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 27 | |
| 28 | let a=execute('sign list Sign1') |
| 29 | call assert_equal("\nsign Sign1 text=x ", a) |
| 30 | |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 31 | " Split the window to the bottom to verify sign jump will stay in the current window |
| 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 |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 36 | 1 |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 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('%')) |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 50 | call assert_equal('c', getline('.')) |
| 51 | |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 52 | " Redraw to make sure that screen redraw with sign gets exercised, |
| 53 | " with and without 'rightleft'. |
| 54 | if has('rightleft') |
| 55 | set rightleft |
| 56 | redraw |
| 57 | set norightleft |
| 58 | endif |
| 59 | redraw |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 60 | |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 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 |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 65 | let a=execute('sign place') |
Bram Moolenaar | 162b714 | 2018-12-21 15:17:36 +0100 | [diff] [blame] | 66 | call assert_equal("\n--- Signs ---\nSigns for [NULL]:\n line=3 id=41 name=Sign1 priority=10\n", a) |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 67 | |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 68 | " Unplace the sign and try jumping to it again should fail. |
| 69 | sign unplace 41 |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 70 | 1 |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 71 | call assert_fails("exe 'sign jump 41 buffer=' . bufnr('%')", 'E157:') |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 72 | call assert_equal('a', getline('.')) |
| 73 | |
| 74 | " Unplace sign on current line. |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 75 | exe 'sign place 42 line=4 name=Sign2 buffer=' . bufnr('%') |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 76 | 4 |
| 77 | sign unplace |
| 78 | let a=execute('sign place') |
| 79 | call assert_equal("\n--- Signs ---\n", a) |
| 80 | |
| 81 | " Try again to unplace sign on current line, it should fail this time. |
| 82 | call assert_fails('sign unplace', 'E159:') |
| 83 | |
| 84 | " Unplace all signs. |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 85 | exe 'sign place 41 line=3 name=Sign1 buffer=' . bufnr('%') |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 86 | sign unplace * |
| 87 | let a=execute('sign place') |
| 88 | call assert_equal("\n--- Signs ---\n", a) |
| 89 | |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 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 | |
Bram Moolenaar | 06b056e | 2018-12-14 19:37:08 +0100 | [diff] [blame] | 107 | " can't define a sign with a non-printable character as text |
| 108 | call assert_fails("sign define Sign4 text=\e linehl=Comment", 'E239:') |
| 109 | call assert_fails("sign define Sign4 text=a\e linehl=Comment", 'E239:') |
| 110 | call assert_fails("sign define Sign4 text=\ea linehl=Comment", 'E239:') |
| 111 | |
| 112 | " Only 1 or 2 character text is allowed |
| 113 | call assert_fails("sign define Sign4 text=abc linehl=Comment", 'E239:') |
| 114 | call assert_fails("sign define Sign4 text= linehl=Comment", 'E239:') |
Bram Moolenaar | 162b714 | 2018-12-21 15:17:36 +0100 | [diff] [blame] | 115 | call assert_fails("sign define Sign4 text=\\ ab linehl=Comment", 'E239:') |
Bram Moolenaar | 06b056e | 2018-12-14 19:37:08 +0100 | [diff] [blame] | 116 | |
| 117 | " define sign with whitespace |
| 118 | sign define Sign4 text=\ X linehl=Comment |
| 119 | sign undefine Sign4 |
| 120 | sign define Sign4 linehl=Comment text=\ X |
| 121 | sign undefine Sign4 |
| 122 | |
| 123 | sign define Sign5 text=X\ linehl=Comment |
| 124 | sign undefine Sign5 |
| 125 | sign define Sign5 linehl=Comment text=X\ |
| 126 | sign undefine Sign5 |
| 127 | |
| 128 | " define sign with backslash |
| 129 | sign define Sign4 text=\\\\ linehl=Comment |
| 130 | sign undefine Sign4 |
| 131 | sign define Sign4 text=\\ linehl=Comment |
| 132 | sign undefine Sign4 |
| 133 | |
Bram Moolenaar | 162b714 | 2018-12-21 15:17:36 +0100 | [diff] [blame] | 134 | " Error cases |
| 135 | call assert_fails("exe 'sign place abc line=3 name=Sign1 buffer=' . bufnr('%')", 'E474:') |
| 136 | call assert_fails("exe 'sign unplace abc name=Sign1 buffer=' . bufnr('%')", 'E474:') |
| 137 | call assert_fails("exe 'sign place 1abc line=3 name=Sign1 buffer=' . bufnr('%')", 'E474:') |
| 138 | call assert_fails("exe 'sign unplace 2abc name=Sign1 buffer=' . bufnr('%')", 'E474:') |
| 139 | call assert_fails("sign unplace 2 *", 'E474:') |
| 140 | call assert_fails("exe 'sign place 1 line=3 name=Sign1 buffer=' . bufnr('%') a", 'E488:') |
| 141 | call assert_fails("exe 'sign place name=Sign1 buffer=' . bufnr('%')", 'E474:') |
| 142 | call assert_fails("exe 'sign place line=10 buffer=' . bufnr('%')", 'E474:') |
| 143 | call assert_fails("exe 'sign unplace 2 line=10 buffer=' . bufnr('%')", 'E474:') |
| 144 | call assert_fails("exe 'sign unplace 2 name=Sign1 buffer=' . bufnr('%')", 'E474:') |
| 145 | call assert_fails("exe 'sign place 2 line=3 buffer=' . bufnr('%')", 'E474:') |
| 146 | call assert_fails("sign place 2", 'E474:') |
| 147 | call assert_fails("sign place abc", 'E474:') |
| 148 | call assert_fails("sign place 5 line=3", 'E474:') |
| 149 | call assert_fails("sign place 5 name=Sign1", 'E474:') |
| 150 | call assert_fails("sign place 5 group=g1", 'E474:') |
| 151 | call assert_fails("sign place 5 group=*", 'E474:') |
| 152 | call assert_fails("sign place 5 priority=10", 'E474:') |
| 153 | call assert_fails("sign place 5 line=3 name=Sign1", 'E474:') |
| 154 | call assert_fails("sign place 5 group=g1 line=3 name=Sign1", 'E474:') |
| 155 | |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 156 | " After undefining the sign, we should no longer be able to place it. |
| 157 | sign undefine Sign1 |
| 158 | sign undefine Sign2 |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 159 | sign undefine Sign3 |
| 160 | call assert_fails("exe 'sign place 41 line=3 name=Sign1 buffer=' . bufnr('%')", 'E155:') |
| 161 | endfunc |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 162 | |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 163 | " Undefining placed sign is not recommended. |
| 164 | " Quoting :help sign |
| 165 | " |
| 166 | " :sign undefine {name} |
| 167 | " Deletes a previously defined sign. If signs with this {name} |
| 168 | " are still placed this will cause trouble. |
| 169 | func Test_sign_undefine_still_placed() |
| 170 | new foobar |
| 171 | sign define Sign text=x |
| 172 | exe 'sign place 41 line=1 name=Sign buffer=' . bufnr('%') |
| 173 | sign undefine Sign |
| 174 | |
| 175 | " Listing placed sign should show that sign is deleted. |
| 176 | let a=execute('sign place') |
Bram Moolenaar | 162b714 | 2018-12-21 15:17:36 +0100 | [diff] [blame] | 177 | call assert_equal("\n--- Signs ---\nSigns for foobar:\n line=1 id=41 name=[Deleted] priority=10\n", a) |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 178 | |
| 179 | sign unplace 41 |
| 180 | let a=execute('sign place') |
| 181 | call assert_equal("\n--- Signs ---\n", a) |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 182 | endfunc |
| 183 | |
| 184 | func Test_sign_completion() |
| 185 | sign define Sign1 text=x |
| 186 | sign define Sign2 text=y |
| 187 | |
| 188 | call feedkeys(":sign \<C-A>\<C-B>\"\<CR>", 'tx') |
| 189 | call assert_equal('"sign define jump list place undefine unplace', @:) |
| 190 | |
| 191 | call feedkeys(":sign define Sign \<C-A>\<C-B>\"\<CR>", 'tx') |
| 192 | call assert_equal('"sign define Sign icon= linehl= text= texthl=', @:) |
| 193 | |
| 194 | call feedkeys(":sign define Sign linehl=Spell\<C-A>\<C-B>\"\<CR>", 'tx') |
| 195 | call assert_equal('"sign define Sign linehl=SpellBad SpellCap SpellLocal SpellRare', @:) |
| 196 | |
Bram Moolenaar | 64cefed | 2016-08-29 23:06:28 +0200 | [diff] [blame] | 197 | call writefile(['foo'], 'XsignOne') |
| 198 | call writefile(['bar'], 'XsignTwo') |
| 199 | call feedkeys(":sign define Sign icon=Xsig\<C-A>\<C-B>\"\<CR>", 'tx') |
| 200 | call assert_equal('"sign define Sign icon=XsignOne XsignTwo', @:) |
| 201 | call delete('XsignOne') |
| 202 | call delete('XsignTwo') |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 203 | |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 204 | call feedkeys(":sign undefine \<C-A>\<C-B>\"\<CR>", 'tx') |
| 205 | call assert_equal('"sign undefine Sign1 Sign2', @:) |
| 206 | |
| 207 | call feedkeys(":sign place 1 \<C-A>\<C-B>\"\<CR>", 'tx') |
| 208 | call assert_equal('"sign place 1 buffer= file= line= name=', @:) |
| 209 | |
| 210 | call feedkeys(":sign place 1 name=\<C-A>\<C-B>\"\<CR>", 'tx') |
| 211 | call assert_equal('"sign place 1 name=Sign1 Sign2', @:) |
| 212 | |
| 213 | call feedkeys(":sign unplace 1 \<C-A>\<C-B>\"\<CR>", 'tx') |
| 214 | call assert_equal('"sign unplace 1 buffer= file=', @:) |
| 215 | |
| 216 | call feedkeys(":sign list \<C-A>\<C-B>\"\<CR>", 'tx') |
| 217 | call assert_equal('"sign list Sign1 Sign2', @:) |
| 218 | |
| 219 | call feedkeys(":sign jump 1 \<C-A>\<C-B>\"\<CR>", 'tx') |
| 220 | call assert_equal('"sign jump 1 buffer= file=', @:) |
| 221 | |
| 222 | sign undefine Sign1 |
| 223 | sign undefine Sign2 |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 224 | endfunc |
| 225 | |
| 226 | func Test_sign_invalid_commands() |
Bram Moolenaar | 162b714 | 2018-12-21 15:17:36 +0100 | [diff] [blame] | 227 | sign define Sign1 text=x |
| 228 | |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 229 | call assert_fails('sign', 'E471:') |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 230 | call assert_fails('sign jump', 'E471:') |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 231 | call assert_fails('sign xxx', 'E160:') |
| 232 | call assert_fails('sign define', 'E156:') |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 233 | call assert_fails('sign define Sign1 xxx', 'E475:') |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 234 | call assert_fails('sign undefine', 'E156:') |
| 235 | call assert_fails('sign list xxx', 'E155:') |
Bram Moolenaar | cf1ba35 | 2017-10-27 00:55:04 +0200 | [diff] [blame] | 236 | call assert_fails('sign place 1 buffer=999', 'E158:') |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 237 | call assert_fails('sign define Sign2 text=', 'E239:') |
Bram Moolenaar | 162b714 | 2018-12-21 15:17:36 +0100 | [diff] [blame] | 238 | " Non-numeric identifier for :sign place |
| 239 | call assert_fails("exe 'sign place abc line=3 name=Sign1 buffer=' . bufnr('%')", 'E474:') |
| 240 | " Non-numeric identifier for :sign unplace |
| 241 | call assert_fails("exe 'sign unplace abc name=Sign1 buffer=' . bufnr('%')", 'E474:') |
| 242 | " Number followed by an alphabet as sign identifier for :sign place |
| 243 | call assert_fails("exe 'sign place 1abc line=3 name=Sign1 buffer=' . bufnr('%')", 'E474:') |
| 244 | " Number followed by an alphabet as sign identifier for :sign unplace |
| 245 | call assert_fails("exe 'sign unplace 2abc name=Sign1 buffer=' . bufnr('%')", 'E474:') |
| 246 | " Sign identifier and '*' for :sign unplace |
| 247 | call assert_fails("sign unplace 2 *", 'E474:') |
| 248 | " Trailing characters after buffer number for :sign place |
| 249 | call assert_fails("exe 'sign place 1 line=3 name=Sign1 buffer=' . bufnr('%') . 'xxx'", 'E488:') |
| 250 | " Trailing characters after buffer number for :sign unplace |
| 251 | call assert_fails("exe 'sign unplace 1 buffer=' . bufnr('%') . 'xxx'", 'E488:') |
| 252 | call assert_fails("exe 'sign unplace * buffer=' . bufnr('%') . 'xxx'", 'E488:') |
| 253 | call assert_fails("sign unplace 1 xxx", 'E474:') |
| 254 | call assert_fails("sign unplace * xxx", 'E474:') |
| 255 | call assert_fails("sign unplace xxx", 'E474:') |
| 256 | " Placing a sign without line number |
| 257 | call assert_fails("exe 'sign place name=Sign1 buffer=' . bufnr('%')", 'E474:') |
| 258 | " Placing a sign without sign name |
| 259 | call assert_fails("exe 'sign place line=10 buffer=' . bufnr('%')", 'E474:') |
| 260 | " Unplacing a sign with line number |
| 261 | call assert_fails("exe 'sign unplace 2 line=10 buffer=' . bufnr('%')", 'E474:') |
| 262 | " Unplacing a sign with sign name |
| 263 | call assert_fails("exe 'sign unplace 2 name=Sign1 buffer=' . bufnr('%')", 'E474:') |
| 264 | " Placing a sign without sign name |
| 265 | call assert_fails("exe 'sign place 2 line=3 buffer=' . bufnr('%')", 'E474:') |
| 266 | " Placing a sign with only sign identifier |
| 267 | call assert_fails("sign place 2", 'E474:') |
| 268 | " Placing a sign with only a name |
| 269 | call assert_fails("sign place abc", 'E474:') |
| 270 | " Placing a sign with only line number |
| 271 | call assert_fails("sign place 5 line=3", 'E474:') |
| 272 | " Placing a sign with only sign name |
| 273 | call assert_fails("sign place 5 name=Sign1", 'E474:') |
| 274 | " Placing a sign with only sign group |
| 275 | call assert_fails("sign place 5 group=g1", 'E474:') |
| 276 | call assert_fails("sign place 5 group=*", 'E474:') |
| 277 | " Placing a sign with only sign priority |
| 278 | call assert_fails("sign place 5 priority=10", 'E474:') |
| 279 | " Placing a sign without buffer number or file name |
| 280 | call assert_fails("sign place 5 line=3 name=Sign1", 'E474:') |
| 281 | call assert_fails("sign place 5 group=g1 line=3 name=Sign1", 'E474:') |
| 282 | |
| 283 | sign undefine Sign1 |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 284 | endfunc |
Bram Moolenaar | bfd096d | 2016-08-17 22:29:09 +0200 | [diff] [blame] | 285 | |
| 286 | func Test_sign_delete_buffer() |
| 287 | new |
| 288 | sign define Sign text=x |
| 289 | let bufnr = bufnr('%') |
| 290 | new |
| 291 | exe 'bd ' . bufnr |
| 292 | exe 'sign place 61 line=3 name=Sign buffer=' . bufnr |
| 293 | call assert_fails('sign jump 61 buffer=' . bufnr, 'E934:') |
| 294 | sign unplace 61 |
| 295 | sign undefine Sign |
| 296 | endfunc |
Bram Moolenaar | 162b714 | 2018-12-21 15:17:36 +0100 | [diff] [blame] | 297 | |
| 298 | " Test for VimL functions for managing signs |
| 299 | func Test_sign_funcs() |
| 300 | " Remove all the signs |
| 301 | call sign_unplace('*') |
| 302 | call sign_undefine() |
| 303 | |
| 304 | " Tests for sign_define() |
| 305 | let attr = {'text' : '=>', 'linehl' : 'Search', 'texthl' : 'Error'} |
| 306 | call assert_equal(0, sign_define("sign1", attr)) |
| 307 | call assert_equal([{'name' : 'sign1', 'texthl' : 'Error', |
| 308 | \ 'linehl' : 'Search', 'text' : '=>'}], sign_getdefined()) |
| 309 | |
| 310 | " Define a new sign without attributes and then update it |
| 311 | call sign_define("sign2") |
| 312 | let attr = {'text' : '!!', 'linehl' : 'DiffAdd', 'texthl' : 'DiffChange', |
| 313 | \ 'icon' : 'sign2.ico'} |
| 314 | try |
| 315 | call sign_define("sign2", attr) |
| 316 | catch /E255:/ |
| 317 | " ignore error: E255: Couldn't read in sign data! |
| 318 | " This error can happen when running in gui. |
| 319 | endtry |
| 320 | call assert_equal([{'name' : 'sign2', 'texthl' : 'DiffChange', |
| 321 | \ 'linehl' : 'DiffAdd', 'text' : '!!', 'icon' : 'sign2.ico'}], |
| 322 | \ sign_getdefined("sign2")) |
| 323 | |
| 324 | " Test for a sign name with digits |
| 325 | call assert_equal(0, sign_define(0002, {'linehl' : 'StatusLine'})) |
| 326 | call assert_equal([{'name' : '2', 'linehl' : 'StatusLine'}], |
| 327 | \ sign_getdefined(0002)) |
| 328 | call sign_undefine(0002) |
| 329 | |
| 330 | " Tests for invalid arguments to sign_define() |
| 331 | call assert_fails('call sign_define("sign4", {"text" : "===>"})', 'E239:') |
| 332 | call assert_fails('call sign_define("sign5", {"text" : ""})', 'E239:') |
| 333 | call assert_fails('call sign_define([])', 'E730:') |
| 334 | call assert_fails('call sign_define("sign6", [])', 'E715:') |
| 335 | |
| 336 | " Tests for sign_getdefined() |
| 337 | call assert_equal([], sign_getdefined("none")) |
| 338 | call assert_fails('call sign_getdefined({})', 'E731:') |
| 339 | |
| 340 | " Tests for sign_place() |
| 341 | call writefile(repeat(["Sun is shining"], 30), "Xsign") |
| 342 | edit Xsign |
| 343 | |
| 344 | call assert_equal(10, sign_place(10, '', 'sign1', 'Xsign', |
| 345 | \ {'lnum' : 20})) |
| 346 | call assert_equal([{'bufnr' : bufnr(''), 'signs' : |
| 347 | \ [{'id' : 10, 'group' : '', 'lnum' : 20, 'name' : 'sign1', |
| 348 | \ 'priority' : 10}]}], sign_getplaced('Xsign')) |
| 349 | call assert_equal([{'bufnr' : bufnr(''), 'signs' : |
| 350 | \ [{'id' : 10, 'group' : '', 'lnum' : 20, 'name' : 'sign1', |
| 351 | \ 'priority' : 10}]}], |
| 352 | \ sign_getplaced('Xsign', {'lnum' : 20})) |
| 353 | call assert_equal([{'bufnr' : bufnr(''), 'signs' : |
| 354 | \ [{'id' : 10, 'group' : '', 'lnum' : 20, 'name' : 'sign1', |
| 355 | \ 'priority' : 10}]}], |
| 356 | \ sign_getplaced('Xsign', {'id' : 10})) |
| 357 | |
| 358 | " Tests for invalid arguments to sign_place() |
| 359 | call assert_fails('call sign_place([], "", "mySign", 1)', 'E745:') |
| 360 | call assert_fails('call sign_place(5, "", "mySign", -1)', 'E158:') |
| 361 | call assert_fails('call sign_place(-1, "", "sign1", "Xsign", [])', |
| 362 | \ 'E474:') |
| 363 | call assert_fails('call sign_place(-1, "", "sign1", "Xsign", |
| 364 | \ {"lnum" : 30})', 'E474:') |
| 365 | call assert_fails('call sign_place(10, "", "xsign1x", "Xsign", |
| 366 | \ {"lnum" : 30})', 'E155:') |
| 367 | call assert_fails('call sign_place(10, "", "", "Xsign", |
| 368 | \ {"lnum" : 30})', 'E155:') |
| 369 | call assert_fails('call sign_place(10, "", [], "Xsign", |
| 370 | \ {"lnum" : 30})', 'E730:') |
| 371 | call assert_fails('call sign_place(5, "", "sign1", "abcxyz.xxx", |
| 372 | \ {"lnum" : 10})', 'E158:') |
| 373 | call assert_fails('call sign_place(5, "", "sign1", "", {"lnum" : 10})', |
| 374 | \ 'E158:') |
| 375 | call assert_fails('call sign_place(5, "", "sign1", [], {"lnum" : 10})', |
| 376 | \ 'E158:') |
| 377 | call assert_fails('call sign_place(21, "", "sign1", "Xsign", |
| 378 | \ {"lnum" : -1})', 'E885:') |
| 379 | call assert_fails('call sign_place(22, "", "sign1", "Xsign", |
| 380 | \ {"lnum" : 0})', 'E885:') |
| 381 | call assert_equal(-1, sign_place(1, "*", "sign1", "Xsign", {"lnum" : 10})) |
| 382 | |
| 383 | " Tests for sign_getplaced() |
| 384 | call assert_equal([{'bufnr' : bufnr(''), 'signs' : |
| 385 | \ [{'id' : 10, 'group' : '', 'lnum' : 20, 'name' : 'sign1', |
| 386 | \ 'priority' : 10}]}], |
| 387 | \ sign_getplaced(bufnr('Xsign'))) |
| 388 | call assert_equal([{'bufnr' : bufnr(''), 'signs' : |
| 389 | \ [{'id' : 10, 'group' : '', 'lnum' : 20, 'name' : 'sign1', |
| 390 | \ 'priority' : 10}]}], |
| 391 | \ sign_getplaced()) |
| 392 | call assert_fails("call sign_getplaced('dummy.sign')", 'E158:') |
| 393 | call assert_fails('call sign_getplaced("")', 'E158:') |
| 394 | call assert_fails('call sign_getplaced(-1)', 'E158:') |
| 395 | call assert_fails('call sign_getplaced("Xsign", [])', 'E715:') |
| 396 | call assert_equal([{'bufnr' : bufnr(''), 'signs' : []}], |
| 397 | \ sign_getplaced('Xsign', {'lnum' : 1000000})) |
| 398 | call assert_fails("call sign_getplaced('Xsign', {'lnum' : []})", |
| 399 | \ 'E745:') |
| 400 | call assert_equal([{'bufnr' : bufnr(''), 'signs' : []}], |
| 401 | \ sign_getplaced('Xsign', {'id' : 44})) |
| 402 | call assert_fails("call sign_getplaced('Xsign', {'id' : []})", |
| 403 | \ 'E745:') |
| 404 | |
| 405 | " Tests for sign_unplace() |
| 406 | call sign_place(20, '', 'sign2', 'Xsign', {"lnum" : 30}) |
| 407 | call assert_equal(0, sign_unplace('', |
| 408 | \ {'id' : 20, 'buffer' : 'Xsign'})) |
| 409 | call assert_equal(-1, sign_unplace('', |
| 410 | \ {'id' : 30, 'buffer' : 'Xsign'})) |
| 411 | call sign_place(20, '', 'sign2', 'Xsign', {"lnum" : 30}) |
| 412 | call assert_fails("call sign_unplace('', |
| 413 | \ {'id' : 20, 'buffer' : 'buffer.c'})", 'E158:') |
| 414 | call assert_fails("call sign_unplace('', |
| 415 | \ {'id' : 20, 'buffer' : ''})", 'E158:') |
| 416 | call assert_fails("call sign_unplace('', |
| 417 | \ {'id' : 20, 'buffer' : 200})", 'E158:') |
| 418 | call assert_fails("call sign_unplace('', 'mySign')", 'E715:') |
| 419 | |
| 420 | " Tests for sign_undefine() |
| 421 | call assert_equal(0, sign_undefine("sign1")) |
| 422 | call assert_equal([], sign_getdefined("sign1")) |
| 423 | call assert_fails('call sign_undefine("none")', 'E155:') |
| 424 | call assert_fails('call sign_undefine([])', 'E730:') |
| 425 | |
| 426 | call delete("Xsign") |
| 427 | call sign_unplace('*') |
| 428 | call sign_undefine() |
| 429 | enew | only |
| 430 | endfunc |
| 431 | |
| 432 | " Tests for sign groups |
| 433 | func Test_sign_group() |
| 434 | enew | only |
| 435 | " Remove all the signs |
| 436 | call sign_unplace('*') |
| 437 | call sign_undefine() |
| 438 | |
| 439 | call writefile(repeat(["Sun is shining"], 30), "Xsign") |
| 440 | |
| 441 | let attr = {'text' : '=>', 'linehl' : 'Search', 'texthl' : 'Error'} |
| 442 | call assert_equal(0, sign_define("sign1", attr)) |
| 443 | |
| 444 | edit Xsign |
| 445 | let bnum = bufnr('%') |
| 446 | let fname = fnamemodify('Xsign', ':p') |
| 447 | |
| 448 | " Error case |
| 449 | call assert_fails("call sign_place(5, [], 'sign1', 'Xsign', |
| 450 | \ {'lnum' : 30})", 'E730:') |
| 451 | |
| 452 | " place three signs with the same identifier. One in the global group and |
| 453 | " others in the named groups |
| 454 | call assert_equal(5, sign_place(5, '', 'sign1', 'Xsign', |
| 455 | \ {'lnum' : 10})) |
| 456 | call assert_equal(5, sign_place(5, 'g1', 'sign1', bnum, {'lnum' : 20})) |
| 457 | call assert_equal(5, sign_place(5, 'g2', 'sign1', bnum, {'lnum' : 30})) |
| 458 | |
| 459 | " Test for sign_getplaced() with group |
| 460 | let s = sign_getplaced('Xsign') |
| 461 | call assert_equal(1, len(s[0].signs)) |
| 462 | call assert_equal(s[0].signs[0].group, '') |
| 463 | let s = sign_getplaced(bnum, {'group' : 'g2'}) |
| 464 | call assert_equal('g2', s[0].signs[0].group) |
| 465 | let s = sign_getplaced(bnum, {'group' : 'g3'}) |
| 466 | call assert_equal([], s[0].signs) |
| 467 | let s = sign_getplaced(bnum, {'group' : '*'}) |
| 468 | call assert_equal([{'id' : 5, 'group' : '', 'name' : 'sign1', 'lnum' : 10, |
| 469 | \ 'priority' : 10}, |
| 470 | \ {'id' : 5, 'group' : 'g1', 'name' : 'sign1', 'lnum' : 20, |
| 471 | \ 'priority' : 10}, |
| 472 | \ {'id' : 5, 'group' : 'g2', 'name' : 'sign1', 'lnum' : 30, |
| 473 | \ 'priority' : 10}], |
| 474 | \ s[0].signs) |
| 475 | |
| 476 | " Test for sign_getplaced() with id |
| 477 | let s = sign_getplaced(bnum, {'id' : 5}) |
| 478 | call assert_equal([{'id' : 5, 'group' : '', 'name' : 'sign1', 'lnum' : 10, |
| 479 | \ 'priority' : 10}], |
| 480 | \ s[0].signs) |
| 481 | let s = sign_getplaced(bnum, {'id' : 5, 'group' : 'g2'}) |
| 482 | call assert_equal( |
| 483 | \ [{'id' : 5, 'name' : 'sign1', 'lnum' : 30, 'group' : 'g2', |
| 484 | \ 'priority' : 10}], |
| 485 | \ s[0].signs) |
| 486 | let s = sign_getplaced(bnum, {'id' : 5, 'group' : '*'}) |
| 487 | call assert_equal([{'id' : 5, 'group' : '', 'name' : 'sign1', 'lnum' : 10, |
| 488 | \ 'priority' : 10}, |
| 489 | \ {'id' : 5, 'group' : 'g1', 'name' : 'sign1', 'lnum' : 20, |
| 490 | \ 'priority' : 10}, |
| 491 | \ {'id' : 5, 'group' : 'g2', 'name' : 'sign1', 'lnum' : 30, |
| 492 | \ 'priority' : 10}], |
| 493 | \ s[0].signs) |
| 494 | let s = sign_getplaced(bnum, {'id' : 5, 'group' : 'g3'}) |
| 495 | call assert_equal([], s[0].signs) |
| 496 | |
| 497 | " Test for sign_getplaced() with lnum |
| 498 | let s = sign_getplaced(bnum, {'lnum' : 20}) |
| 499 | call assert_equal([], s[0].signs) |
| 500 | let s = sign_getplaced(bnum, {'lnum' : 20, 'group' : 'g1'}) |
| 501 | call assert_equal( |
| 502 | \ [{'id' : 5, 'name' : 'sign1', 'lnum' : 20, 'group' : 'g1', |
| 503 | \ 'priority' : 10}], |
| 504 | \ s[0].signs) |
| 505 | let s = sign_getplaced(bnum, {'lnum' : 30, 'group' : '*'}) |
| 506 | call assert_equal( |
| 507 | \ [{'id' : 5, 'name' : 'sign1', 'lnum' : 30, 'group' : 'g2', |
| 508 | \ 'priority' : 10}], |
| 509 | \ s[0].signs) |
| 510 | let s = sign_getplaced(bnum, {'lnum' : 40, 'group' : '*'}) |
| 511 | call assert_equal([], s[0].signs) |
| 512 | |
| 513 | " Error case |
| 514 | call assert_fails("call sign_getplaced(bnum, {'group' : []})", |
| 515 | \ 'E730:') |
| 516 | |
| 517 | " Clear the sign in global group |
| 518 | call sign_unplace('', {'id' : 5, 'buffer' : bnum}) |
| 519 | let s = sign_getplaced(bnum, {'group' : '*'}) |
| 520 | call assert_equal([ |
| 521 | \ {'id' : 5, 'name' : 'sign1', 'lnum' : 20, 'group' : 'g1', |
| 522 | \ 'priority' : 10}, |
| 523 | \ {'id' : 5, 'name' : 'sign1', 'lnum' : 30, 'group' : 'g2', |
| 524 | \ 'priority' : 10}], |
| 525 | \ s[0].signs) |
| 526 | |
| 527 | " Clear the sign in one of the groups |
| 528 | call sign_unplace('g1', {'buffer' : 'Xsign'}) |
| 529 | let s = sign_getplaced(bnum, {'group' : '*'}) |
| 530 | call assert_equal([ |
| 531 | \ {'id' : 5, 'name' : 'sign1', 'lnum' : 30, 'group' : 'g2', |
| 532 | \ 'priority' : 10}], |
| 533 | \ s[0].signs) |
| 534 | |
| 535 | " Clear all the signs from the buffer |
| 536 | call sign_unplace('*', {'buffer' : bnum}) |
| 537 | call assert_equal([], sign_getplaced(bnum, {'group' : '*'})[0].signs) |
| 538 | |
| 539 | " Clear sign across groups using an identifier |
| 540 | call sign_place(25, '', 'sign1', bnum, {'lnum' : 10}) |
| 541 | call sign_place(25, 'g1', 'sign1', bnum, {'lnum' : 11}) |
| 542 | call sign_place(25, 'g2', 'sign1', bnum, {'lnum' : 12}) |
| 543 | call assert_equal(0, sign_unplace('*', {'id' : 25})) |
| 544 | call assert_equal([], sign_getplaced(bnum, {'group' : '*'})[0].signs) |
| 545 | |
| 546 | " Error case |
| 547 | call assert_fails("call sign_unplace([])", 'E474:') |
| 548 | |
| 549 | " Place a sign in the global group and try to delete it using a group |
| 550 | call assert_equal(5, sign_place(5, '', 'sign1', bnum, {'lnum' : 10})) |
| 551 | call assert_equal(-1, sign_unplace('g1', {'id' : 5})) |
| 552 | |
| 553 | " Place signs in multiple groups and delete all the signs in one of the |
| 554 | " group |
| 555 | call assert_equal(5, sign_place(5, '', 'sign1', bnum, {'lnum' : 10})) |
| 556 | call assert_equal(6, sign_place(6, '', 'sign1', bnum, {'lnum' : 11})) |
| 557 | call assert_equal(5, sign_place(5, 'g1', 'sign1', bnum, {'lnum' : 10})) |
| 558 | call assert_equal(5, sign_place(5, 'g2', 'sign1', bnum, {'lnum' : 10})) |
| 559 | call assert_equal(6, sign_place(6, 'g1', 'sign1', bnum, {'lnum' : 11})) |
| 560 | call assert_equal(6, sign_place(6, 'g2', 'sign1', bnum, {'lnum' : 11})) |
| 561 | call assert_equal(0, sign_unplace('g1')) |
| 562 | let s = sign_getplaced(bnum, {'group' : 'g1'}) |
| 563 | call assert_equal([], s[0].signs) |
| 564 | let s = sign_getplaced(bnum) |
| 565 | call assert_equal(2, len(s[0].signs)) |
| 566 | let s = sign_getplaced(bnum, {'group' : 'g2'}) |
| 567 | call assert_equal('g2', s[0].signs[0].group) |
| 568 | call assert_equal(0, sign_unplace('', {'id' : 5})) |
| 569 | call assert_equal(0, sign_unplace('', {'id' : 6})) |
| 570 | let s = sign_getplaced(bnum, {'group' : 'g2'}) |
| 571 | call assert_equal('g2', s[0].signs[0].group) |
| 572 | call assert_equal(0, sign_unplace('', {'buffer' : bnum})) |
| 573 | |
| 574 | call sign_unplace('*') |
| 575 | |
| 576 | " Test for :sign command and groups |
| 577 | exe 'sign place 5 line=10 name=sign1 file=' . fname |
| 578 | exe 'sign place 5 group=g1 line=10 name=sign1 file=' . fname |
| 579 | exe 'sign place 5 group=g2 line=10 name=sign1 file=' . fname |
| 580 | |
| 581 | " Test for :sign place group={group} file={fname} |
| 582 | let a = execute('sign place file=' . fname) |
| 583 | call assert_equal("\n--- Signs ---\nSigns for Xsign:\n line=10 id=5 name=sign1 priority=10\n", a) |
| 584 | |
| 585 | let a = execute('sign place group=g2 file=' . fname) |
| 586 | call assert_equal("\n--- Signs ---\nSigns for Xsign:\n line=10 id=5 group=g2 name=sign1 priority=10\n", a) |
| 587 | |
| 588 | let a = execute('sign place group=* file=' . fname) |
| 589 | call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . |
| 590 | \ " line=10 id=5 group=g2 name=sign1 priority=10\n" . |
| 591 | \ " line=10 id=5 group=g1 name=sign1 priority=10\n" . |
| 592 | \ " line=10 id=5 name=sign1 priority=10\n", a) |
| 593 | |
| 594 | let a = execute('sign place group=xyz file=' . fname) |
| 595 | call assert_equal("\n--- Signs ---\nSigns for Xsign:\n", a) |
| 596 | |
| 597 | call sign_unplace('*') |
| 598 | |
| 599 | " Test for :sign place group={group} buffer={nr} |
| 600 | let bnum = bufnr('Xsign') |
| 601 | exe 'sign place 5 line=10 name=sign1 buffer=' . bnum |
| 602 | exe 'sign place 5 group=g1 line=11 name=sign1 buffer=' . bnum |
| 603 | exe 'sign place 5 group=g2 line=12 name=sign1 buffer=' . bnum |
| 604 | |
| 605 | let a = execute('sign place buffer=' . bnum) |
| 606 | call assert_equal("\n--- Signs ---\nSigns for Xsign:\n line=10 id=5 name=sign1 priority=10\n", a) |
| 607 | |
| 608 | let a = execute('sign place group=g2 buffer=' . bnum) |
| 609 | call assert_equal("\n--- Signs ---\nSigns for Xsign:\n line=12 id=5 group=g2 name=sign1 priority=10\n", a) |
| 610 | |
| 611 | let a = execute('sign place group=* buffer=' . bnum) |
| 612 | call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . |
| 613 | \ " line=10 id=5 name=sign1 priority=10\n" . |
| 614 | \ " line=11 id=5 group=g1 name=sign1 priority=10\n" . |
| 615 | \ " line=12 id=5 group=g2 name=sign1 priority=10\n", a) |
| 616 | |
| 617 | let a = execute('sign place group=xyz buffer=' . bnum) |
| 618 | call assert_equal("\n--- Signs ---\nSigns for Xsign:\n", a) |
| 619 | |
| 620 | let a = execute('sign place group=*') |
| 621 | call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . |
| 622 | \ " line=10 id=5 name=sign1 priority=10\n" . |
| 623 | \ " line=11 id=5 group=g1 name=sign1 priority=10\n" . |
| 624 | \ " line=12 id=5 group=g2 name=sign1 priority=10\n", a) |
| 625 | |
| 626 | " Test for :sign unplace |
| 627 | exe 'sign unplace 5 group=g2 file=' . fname |
| 628 | call assert_equal([], sign_getplaced(bnum, {'group' : 'g2'})[0].signs) |
| 629 | |
| 630 | exe 'sign unplace 5 group=g1 buffer=' . bnum |
| 631 | call assert_equal([], sign_getplaced(bnum, {'group' : 'g1'})[0].signs) |
| 632 | |
| 633 | exe 'sign unplace 5 group=xy file=' . fname |
| 634 | call assert_equal(1, len(sign_getplaced(bnum, {'group' : '*'})[0].signs)) |
| 635 | |
| 636 | " Test for removing all the signs. Place the signs again for this test |
| 637 | exe 'sign place 5 group=g1 line=11 name=sign1 file=' . fname |
| 638 | exe 'sign place 5 group=g2 line=12 name=sign1 file=' . fname |
| 639 | exe 'sign place 6 line=20 name=sign1 file=' . fname |
| 640 | exe 'sign place 6 group=g1 line=21 name=sign1 file=' . fname |
| 641 | exe 'sign place 6 group=g2 line=22 name=sign1 file=' . fname |
| 642 | exe 'sign unplace 5 group=* file=' . fname |
| 643 | let a = execute('sign place group=*') |
| 644 | call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . |
| 645 | \ " line=20 id=6 name=sign1 priority=10\n" . |
| 646 | \ " line=21 id=6 group=g1 name=sign1 priority=10\n" . |
| 647 | \ " line=22 id=6 group=g2 name=sign1 priority=10\n", a) |
| 648 | |
| 649 | " Remove all the signs from the global group |
| 650 | exe 'sign unplace * file=' . fname |
| 651 | let a = execute('sign place group=*') |
| 652 | call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . |
| 653 | \ " line=21 id=6 group=g1 name=sign1 priority=10\n" . |
| 654 | \ " line=22 id=6 group=g2 name=sign1 priority=10\n", a) |
| 655 | |
| 656 | " Remove all the signs from a particular group |
| 657 | exe 'sign place 5 line=10 name=sign1 file=' . fname |
| 658 | exe 'sign place 5 group=g1 line=11 name=sign1 file=' . fname |
| 659 | exe 'sign place 5 group=g2 line=12 name=sign1 file=' . fname |
| 660 | exe 'sign unplace * group=g1 file=' . fname |
| 661 | let a = execute('sign place group=*') |
| 662 | call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . |
| 663 | \ " line=10 id=5 name=sign1 priority=10\n" . |
| 664 | \ " line=12 id=5 group=g2 name=sign1 priority=10\n" . |
| 665 | \ " line=22 id=6 group=g2 name=sign1 priority=10\n", a) |
| 666 | |
| 667 | " Remove all the signs from all the groups in a file |
| 668 | exe 'sign place 5 group=g1 line=11 name=sign1 file=' . fname |
| 669 | exe 'sign place 6 line=20 name=sign1 file=' . fname |
| 670 | exe 'sign place 6 group=g1 line=21 name=sign1 file=' . fname |
| 671 | exe 'sign unplace * group=* file=' . fname |
| 672 | let a = execute('sign place group=*') |
| 673 | call assert_equal("\n--- Signs ---\n", a) |
| 674 | |
| 675 | " Remove a particular sign id in a group from all the files |
| 676 | exe 'sign place 5 group=g1 line=11 name=sign1 file=' . fname |
| 677 | sign unplace 5 group=g1 |
| 678 | let a = execute('sign place group=*') |
| 679 | call assert_equal("\n--- Signs ---\n", a) |
| 680 | |
| 681 | " Remove a particular sign id in all the groups from all the files |
| 682 | exe 'sign place 5 line=10 name=sign1 file=' . fname |
| 683 | exe 'sign place 5 group=g1 line=11 name=sign1 file=' . fname |
| 684 | exe 'sign place 5 group=g2 line=12 name=sign1 file=' . fname |
| 685 | exe 'sign place 6 line=20 name=sign1 file=' . fname |
| 686 | exe 'sign place 6 group=g1 line=21 name=sign1 file=' . fname |
| 687 | exe 'sign place 6 group=g2 line=22 name=sign1 file=' . fname |
| 688 | sign unplace 5 group=* |
| 689 | let a = execute('sign place group=*') |
| 690 | call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . |
| 691 | \ " line=20 id=6 name=sign1 priority=10\n" . |
| 692 | \ " line=21 id=6 group=g1 name=sign1 priority=10\n" . |
| 693 | \ " line=22 id=6 group=g2 name=sign1 priority=10\n", a) |
| 694 | |
| 695 | " Remove all the signs from all the groups in all the files |
| 696 | exe 'sign place 5 line=10 name=sign1 file=' . fname |
| 697 | exe 'sign place 5 group=g1 line=11 name=sign1 file=' . fname |
| 698 | sign unplace * group=* |
| 699 | let a = execute('sign place group=*') |
| 700 | call assert_equal("\n--- Signs ---\n", a) |
| 701 | |
| 702 | " Error cases |
| 703 | call assert_fails("exe 'sign place 3 group= name=sign1 buffer=' . bnum", 'E474:') |
| 704 | |
| 705 | call delete("Xsign") |
| 706 | call sign_unplace('*') |
| 707 | call sign_undefine() |
| 708 | enew | only |
| 709 | endfunc |
| 710 | |
| 711 | " Tests for auto-generating the sign identifier |
| 712 | func Test_sign_id_autogen() |
| 713 | enew | only |
| 714 | call sign_unplace('*') |
| 715 | call sign_undefine() |
| 716 | |
| 717 | let attr = {'text' : '=>', 'linehl' : 'Search', 'texthl' : 'Error'} |
| 718 | call assert_equal(0, sign_define("sign1", attr)) |
| 719 | |
| 720 | call writefile(repeat(["Sun is shining"], 30), "Xsign") |
| 721 | edit Xsign |
| 722 | |
| 723 | call assert_equal(1, sign_place(0, '', 'sign1', 'Xsign', |
| 724 | \ {'lnum' : 10})) |
| 725 | call assert_equal(2, sign_place(2, '', 'sign1', 'Xsign', |
| 726 | \ {'lnum' : 12})) |
| 727 | call assert_equal(3, sign_place(0, '', 'sign1', 'Xsign', |
| 728 | \ {'lnum' : 14})) |
| 729 | call sign_unplace('', {'buffer' : 'Xsign', 'id' : 2}) |
| 730 | call assert_equal(2, sign_place(0, '', 'sign1', 'Xsign', |
| 731 | \ {'lnum' : 12})) |
| 732 | |
| 733 | call assert_equal(1, sign_place(0, 'g1', 'sign1', 'Xsign', |
| 734 | \ {'lnum' : 11})) |
| 735 | call assert_equal(0, sign_unplace('g1', {'id' : 1})) |
| 736 | call assert_equal(10, |
| 737 | \ sign_getplaced('Xsign', {'id' : 1})[0].signs[0].lnum) |
| 738 | |
| 739 | call delete("Xsign") |
| 740 | call sign_unplace('*') |
| 741 | call sign_undefine() |
| 742 | enew | only |
| 743 | endfunc |
| 744 | |
| 745 | " Test for sign priority |
| 746 | func Test_sign_priority() |
| 747 | enew | only |
| 748 | call sign_unplace('*') |
| 749 | call sign_undefine() |
| 750 | |
| 751 | let attr = {'text' : '=>', 'linehl' : 'Search', 'texthl' : 'Search'} |
| 752 | call sign_define("sign1", attr) |
| 753 | call sign_define("sign2", attr) |
| 754 | call sign_define("sign3", attr) |
| 755 | |
| 756 | " Place three signs with different priority in the same line |
| 757 | call writefile(repeat(["Sun is shining"], 30), "Xsign") |
| 758 | edit Xsign |
| 759 | let fname = fnamemodify('Xsign', ':p') |
| 760 | |
| 761 | call sign_place(1, 'g1', 'sign1', 'Xsign', |
| 762 | \ {'lnum' : 11, 'priority' : 50}) |
| 763 | call sign_place(2, 'g2', 'sign2', 'Xsign', |
| 764 | \ {'lnum' : 11, 'priority' : 100}) |
| 765 | call sign_place(3, '', 'sign3', 'Xsign', {'lnum' : 11}) |
| 766 | let s = sign_getplaced('Xsign', {'group' : '*'}) |
| 767 | call assert_equal([ |
| 768 | \ {'id' : 2, 'name' : 'sign2', 'lnum' : 11, 'group' : 'g2', |
| 769 | \ 'priority' : 100}, |
| 770 | \ {'id' : 1, 'name' : 'sign1', 'lnum' : 11, 'group' : 'g1', |
| 771 | \ 'priority' : 50}, |
| 772 | \ {'id' : 3, 'name' : 'sign3', 'lnum' : 11, 'group' : '', |
| 773 | \ 'priority' : 10}], |
| 774 | \ s[0].signs) |
| 775 | |
| 776 | " Error case |
| 777 | call assert_fails("call sign_place(1, 'g1', 'sign1', 'Xsign', |
| 778 | \ [])", 'E715:') |
| 779 | call sign_unplace('*') |
| 780 | |
| 781 | " Tests for the :sign place command with priority |
| 782 | sign place 5 line=10 name=sign1 priority=30 file=Xsign |
| 783 | sign place 5 group=g1 line=10 name=sign1 priority=20 file=Xsign |
| 784 | sign place 5 group=g2 line=10 name=sign1 priority=25 file=Xsign |
| 785 | let a = execute('sign place group=*') |
| 786 | call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . |
| 787 | \ " line=10 id=5 name=sign1 priority=30\n" . |
| 788 | \ " line=10 id=5 group=g2 name=sign1 priority=25\n" . |
| 789 | \ " line=10 id=5 group=g1 name=sign1 priority=20\n", a) |
| 790 | |
| 791 | " Test for :sign place group={group} |
| 792 | let a = execute('sign place group=g1') |
| 793 | call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . |
| 794 | \ " line=10 id=5 group=g1 name=sign1 priority=20\n", a) |
| 795 | |
| 796 | call sign_unplace('*') |
| 797 | call sign_undefine() |
| 798 | enew | only |
| 799 | call delete("Xsign") |
| 800 | endfunc |
| 801 | |
| 802 | " Tests for memory allocation failures in sign functions |
| 803 | func Test_sign_memfailures() |
| 804 | call writefile(repeat(["Sun is shining"], 30), "Xsign") |
| 805 | edit Xsign |
| 806 | |
| 807 | call test_alloc_fail(GetAllocId('sign_getdefined'), 0, 0) |
| 808 | call assert_fails('call sign_getdefined("sign1")', 'E342:') |
| 809 | call test_alloc_fail(GetAllocId('sign_getplaced'), 0, 0) |
| 810 | call assert_fails('call sign_getplaced("Xsign")', 'E342:') |
| 811 | call test_alloc_fail(GetAllocId('sign_define_by_name'), 0, 0) |
| 812 | let attr = {'text' : '=>', 'linehl' : 'Search', 'texthl' : 'Error'} |
| 813 | call assert_fails('call sign_define("sign1", attr)', 'E342:') |
| 814 | |
| 815 | let attr = {'text' : '=>', 'linehl' : 'Search', 'texthl' : 'Error'} |
| 816 | call sign_define("sign1", attr) |
| 817 | call test_alloc_fail(GetAllocId('sign_getlist'), 0, 0) |
| 818 | call assert_fails('call sign_getdefined("sign1")', 'E342:') |
| 819 | |
| 820 | call sign_place(3, 'g1', 'sign1', 'Xsign', {'lnum' : 10}) |
| 821 | call test_alloc_fail(GetAllocId('sign_getplaced_dict'), 0, 0) |
| 822 | call assert_fails('call sign_getplaced("Xsign")', 'E342:') |
| 823 | call test_alloc_fail(GetAllocId('sign_getplaced_list'), 0, 0) |
| 824 | call assert_fails('call sign_getplaced("Xsign")', 'E342:') |
| 825 | |
| 826 | call test_alloc_fail(GetAllocId('insert_sign'), 0, 0) |
| 827 | call assert_fails('call sign_place(4, "g1", "sign1", "Xsign", {"lnum" : 11})', |
| 828 | \ 'E342:') |
| 829 | |
| 830 | call test_alloc_fail(GetAllocId('sign_getinfo'), 0, 0) |
| 831 | call assert_fails('call getbufinfo()', 'E342:') |
| 832 | call sign_place(4, 'g1', 'sign1', 'Xsign', {'lnum' : 11}) |
| 833 | call test_alloc_fail(GetAllocId('sign_getinfo'), 0, 0) |
| 834 | call assert_fails('let binfo=getbufinfo("Xsign")', 'E342:') |
| 835 | call assert_equal([{'lnum': 11, 'id': 4, 'name': 'sign1', |
| 836 | \ 'priority': 10, 'group': 'g1'}], binfo[0].signs) |
| 837 | |
| 838 | call sign_unplace('*') |
| 839 | call sign_undefine() |
| 840 | enew | only |
| 841 | call delete("Xsign") |
| 842 | endfunc |