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:/ |
| 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 |
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 | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 66 | call assert_equal("\n--- Signs ---\nSigns for [NULL]:\n line=3 id=41 name=Sign1\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 | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 107 | " After undefining the sign, we should no longer be able to place it. |
| 108 | sign undefine Sign1 |
| 109 | sign undefine Sign2 |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 110 | sign undefine Sign3 |
| 111 | call assert_fails("exe 'sign place 41 line=3 name=Sign1 buffer=' . bufnr('%')", 'E155:') |
| 112 | endfunc |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 113 | |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 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) |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 133 | endfunc |
| 134 | |
| 135 | func Test_sign_completion() |
| 136 | sign define Sign1 text=x |
| 137 | sign define Sign2 text=y |
| 138 | |
| 139 | call feedkeys(":sign \<C-A>\<C-B>\"\<CR>", 'tx') |
| 140 | call assert_equal('"sign define jump list place undefine unplace', @:) |
| 141 | |
| 142 | call feedkeys(":sign define Sign \<C-A>\<C-B>\"\<CR>", 'tx') |
| 143 | call assert_equal('"sign define Sign icon= linehl= text= texthl=', @:) |
| 144 | |
| 145 | call feedkeys(":sign define Sign linehl=Spell\<C-A>\<C-B>\"\<CR>", 'tx') |
| 146 | call assert_equal('"sign define Sign linehl=SpellBad SpellCap SpellLocal SpellRare', @:) |
| 147 | |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 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', @:) |
| 150 | |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 151 | call feedkeys(":sign undefine \<C-A>\<C-B>\"\<CR>", 'tx') |
| 152 | call assert_equal('"sign undefine Sign1 Sign2', @:) |
| 153 | |
| 154 | call feedkeys(":sign place 1 \<C-A>\<C-B>\"\<CR>", 'tx') |
| 155 | call assert_equal('"sign place 1 buffer= file= line= name=', @:) |
| 156 | |
| 157 | call feedkeys(":sign place 1 name=\<C-A>\<C-B>\"\<CR>", 'tx') |
| 158 | call assert_equal('"sign place 1 name=Sign1 Sign2', @:) |
| 159 | |
| 160 | call feedkeys(":sign unplace 1 \<C-A>\<C-B>\"\<CR>", 'tx') |
| 161 | call assert_equal('"sign unplace 1 buffer= file=', @:) |
| 162 | |
| 163 | call feedkeys(":sign list \<C-A>\<C-B>\"\<CR>", 'tx') |
| 164 | call assert_equal('"sign list Sign1 Sign2', @:) |
| 165 | |
| 166 | call feedkeys(":sign jump 1 \<C-A>\<C-B>\"\<CR>", 'tx') |
| 167 | call assert_equal('"sign jump 1 buffer= file=', @:) |
| 168 | |
| 169 | sign undefine Sign1 |
| 170 | sign undefine Sign2 |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 171 | endfunc |
| 172 | |
| 173 | func Test_sign_invalid_commands() |
| 174 | call assert_fails('sign', 'E471:') |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 175 | call assert_fails('sign jump', 'E471:') |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 176 | call assert_fails('sign xxx', 'E160:') |
| 177 | call assert_fails('sign define', 'E156:') |
Bram Moolenaar | 446a973 | 2016-08-10 21:36:23 +0200 | [diff] [blame] | 178 | call assert_fails('sign define Sign1 xxx', 'E475:') |
Bram Moolenaar | 09de175 | 2016-08-08 22:26:48 +0200 | [diff] [blame] | 179 | call assert_fails('sign undefine', 'E156:') |
| 180 | call assert_fails('sign list xxx', 'E155:') |
| 181 | call assert_fails('sign place 1 buffer=', 'E158:') |
| 182 | call assert_fails('sign define Sign2 text=', 'E239:') |
| 183 | endfunc |
Bram Moolenaar | bfd096d | 2016-08-17 22:29:09 +0200 | [diff] [blame] | 184 | |
| 185 | func Test_sign_delete_buffer() |
| 186 | new |
| 187 | sign define Sign text=x |
| 188 | let bufnr = bufnr('%') |
| 189 | new |
| 190 | exe 'bd ' . bufnr |
| 191 | exe 'sign place 61 line=3 name=Sign buffer=' . bufnr |
| 192 | call assert_fails('sign jump 61 buffer=' . bufnr, 'E934:') |
| 193 | sign unplace 61 |
| 194 | sign undefine Sign |
| 195 | endfunc |