Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 1 | " Test for the search command |
| 2 | |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 3 | source shared.vim |
Bram Moolenaar | 9d34d90 | 2018-04-27 22:18:12 +0200 | [diff] [blame] | 4 | source screendump.vim |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 5 | source check.vim |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 6 | |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 7 | func Test_search_cmdline() |
| 8 | if !exists('+incsearch') |
| 9 | return |
| 10 | endif |
| 11 | " need to disable char_avail, |
| 12 | " so that expansion of commandline works |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 13 | call test_override("char_avail", 1) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 14 | new |
| 15 | call setline(1, [' 1', ' 2 these', ' 3 the', ' 4 their', ' 5 there', ' 6 their', ' 7 the', ' 8 them', ' 9 these', ' 10 foobar']) |
| 16 | " Test 1 |
| 17 | " CTRL-N / CTRL-P skips through the previous search history |
| 18 | set noincsearch |
| 19 | :1 |
| 20 | call feedkeys("/foobar\<cr>", 'tx') |
| 21 | call feedkeys("/the\<cr>",'tx') |
| 22 | call assert_equal('the', @/) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 23 | call feedkeys("/thes\<C-P>\<C-P>\<cr>",'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 24 | call assert_equal('foobar', @/) |
| 25 | |
| 26 | " Test 2 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 27 | " Ctrl-G goes from one match to the next |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 28 | " until the end of the buffer |
| 29 | set incsearch nowrapscan |
| 30 | :1 |
| 31 | " first match |
| 32 | call feedkeys("/the\<cr>", 'tx') |
| 33 | call assert_equal(' 2 these', getline('.')) |
| 34 | :1 |
| 35 | " second match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 36 | call feedkeys("/the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 37 | call assert_equal(' 3 the', getline('.')) |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 38 | call assert_equal([0, 0, 0, 0], getpos('"')) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 39 | :1 |
| 40 | " third match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 41 | call feedkeys("/the".repeat("\<C-G>", 2)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 42 | call assert_equal(' 4 their', getline('.')) |
| 43 | :1 |
| 44 | " fourth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 45 | call feedkeys("/the".repeat("\<C-G>", 3)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 46 | call assert_equal(' 5 there', getline('.')) |
| 47 | :1 |
| 48 | " fifth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 49 | call feedkeys("/the".repeat("\<C-G>", 4)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 50 | call assert_equal(' 6 their', getline('.')) |
| 51 | :1 |
| 52 | " sixth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 53 | call feedkeys("/the".repeat("\<C-G>", 5)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 54 | call assert_equal(' 7 the', getline('.')) |
| 55 | :1 |
| 56 | " seventh match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 57 | call feedkeys("/the".repeat("\<C-G>", 6)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 58 | call assert_equal(' 8 them', getline('.')) |
| 59 | :1 |
| 60 | " eigth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 61 | call feedkeys("/the".repeat("\<C-G>", 7)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 62 | call assert_equal(' 9 these', getline('.')) |
| 63 | :1 |
| 64 | " no further match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 65 | call feedkeys("/the".repeat("\<C-G>", 8)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 66 | call assert_equal(' 9 these', getline('.')) |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 67 | call assert_equal([0, 0, 0, 0], getpos('"')) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 68 | |
| 69 | " Test 3 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 70 | " Ctrl-G goes from one match to the next |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 71 | " and continues back at the top |
| 72 | set incsearch wrapscan |
| 73 | :1 |
| 74 | " first match |
| 75 | call feedkeys("/the\<cr>", 'tx') |
| 76 | call assert_equal(' 2 these', getline('.')) |
| 77 | :1 |
| 78 | " second match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 79 | call feedkeys("/the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 80 | call assert_equal(' 3 the', getline('.')) |
| 81 | :1 |
| 82 | " third match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 83 | call feedkeys("/the".repeat("\<C-G>", 2)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 84 | call assert_equal(' 4 their', getline('.')) |
| 85 | :1 |
| 86 | " fourth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 87 | call feedkeys("/the".repeat("\<C-G>", 3)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 88 | call assert_equal(' 5 there', getline('.')) |
| 89 | :1 |
| 90 | " fifth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 91 | call feedkeys("/the".repeat("\<C-G>", 4)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 92 | call assert_equal(' 6 their', getline('.')) |
| 93 | :1 |
| 94 | " sixth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 95 | call feedkeys("/the".repeat("\<C-G>", 5)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 96 | call assert_equal(' 7 the', getline('.')) |
| 97 | :1 |
| 98 | " seventh match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 99 | call feedkeys("/the".repeat("\<C-G>", 6)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 100 | call assert_equal(' 8 them', getline('.')) |
| 101 | :1 |
| 102 | " eigth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 103 | call feedkeys("/the".repeat("\<C-G>", 7)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 104 | call assert_equal(' 9 these', getline('.')) |
| 105 | :1 |
| 106 | " back at first match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 107 | call feedkeys("/the".repeat("\<C-G>", 8)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 108 | call assert_equal(' 2 these', getline('.')) |
| 109 | |
| 110 | " Test 4 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 111 | " CTRL-T goes to the previous match |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 112 | set incsearch nowrapscan |
| 113 | $ |
| 114 | " first match |
| 115 | call feedkeys("?the\<cr>", 'tx') |
| 116 | call assert_equal(' 9 these', getline('.')) |
| 117 | $ |
| 118 | " first match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 119 | call feedkeys("?the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 120 | call assert_equal(' 9 these', getline('.')) |
| 121 | $ |
| 122 | " second match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 123 | call feedkeys("?the".repeat("\<C-T>", 1)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 124 | call assert_equal(' 8 them', getline('.')) |
| 125 | $ |
| 126 | " last match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 127 | call feedkeys("?the".repeat("\<C-T>", 7)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 128 | call assert_equal(' 2 these', getline('.')) |
| 129 | $ |
| 130 | " last match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 131 | call feedkeys("?the".repeat("\<C-T>", 8)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 132 | call assert_equal(' 2 these', getline('.')) |
| 133 | |
| 134 | " Test 5 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 135 | " CTRL-T goes to the previous match |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 136 | set incsearch wrapscan |
| 137 | $ |
| 138 | " first match |
| 139 | call feedkeys("?the\<cr>", 'tx') |
| 140 | call assert_equal(' 9 these', getline('.')) |
| 141 | $ |
| 142 | " first match at the top |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 143 | call feedkeys("?the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 144 | call assert_equal(' 2 these', getline('.')) |
| 145 | $ |
| 146 | " second match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 147 | call feedkeys("?the".repeat("\<C-T>", 1)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 148 | call assert_equal(' 8 them', getline('.')) |
| 149 | $ |
| 150 | " last match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 151 | call feedkeys("?the".repeat("\<C-T>", 7)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 152 | call assert_equal(' 2 these', getline('.')) |
| 153 | $ |
| 154 | " back at the bottom of the buffer |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 155 | call feedkeys("?the".repeat("\<C-T>", 8)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 156 | call assert_equal(' 9 these', getline('.')) |
| 157 | |
| 158 | " Test 6 |
| 159 | " CTRL-L adds to the search pattern |
| 160 | set incsearch wrapscan |
| 161 | 1 |
| 162 | " first match |
| 163 | call feedkeys("/the\<c-l>\<cr>", 'tx') |
| 164 | call assert_equal(' 2 these', getline('.')) |
| 165 | 1 |
| 166 | " go to next match of 'thes' |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 167 | call feedkeys("/the\<c-l>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 168 | call assert_equal(' 9 these', getline('.')) |
| 169 | 1 |
| 170 | " wrap around |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 171 | call feedkeys("/the\<c-l>\<C-G>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 172 | call assert_equal(' 2 these', getline('.')) |
| 173 | 1 |
| 174 | " wrap around |
| 175 | set nowrapscan |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 176 | call feedkeys("/the\<c-l>\<C-G>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 177 | call assert_equal(' 9 these', getline('.')) |
| 178 | |
| 179 | " Test 7 |
| 180 | " <bs> remove from match, but stay at current match |
| 181 | set incsearch wrapscan |
| 182 | 1 |
| 183 | " first match |
| 184 | call feedkeys("/thei\<cr>", 'tx') |
| 185 | call assert_equal(' 4 their', getline('.')) |
| 186 | 1 |
| 187 | " delete one char, add another |
| 188 | call feedkeys("/thei\<bs>s\<cr>", 'tx') |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 189 | call assert_equal(' 2 these', getline('.')) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 190 | 1 |
| 191 | " delete one char, add another, go to previous match, add one char |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 192 | call feedkeys("/thei\<bs>s\<bs>\<C-T>\<c-l>\<cr>", 'tx') |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 193 | call assert_equal(' 9 these', getline('.')) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 194 | 1 |
| 195 | " delete all chars, start from the beginning again |
| 196 | call feedkeys("/them". repeat("\<bs>",4).'the\>'."\<cr>", 'tx') |
| 197 | call assert_equal(' 3 the', getline('.')) |
| 198 | |
| 199 | " clean up |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 200 | call test_override("char_avail", 0) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 201 | bw! |
| 202 | endfunc |
| 203 | |
| 204 | func Test_search_cmdline2() |
| 205 | if !exists('+incsearch') |
| 206 | return |
| 207 | endif |
| 208 | " need to disable char_avail, |
| 209 | " so that expansion of commandline works |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 210 | call test_override("char_avail", 1) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 211 | new |
| 212 | call setline(1, [' 1', ' 2 these', ' 3 the theother']) |
| 213 | " Test 1 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 214 | " Ctrl-T goes correctly back and forth |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 215 | set incsearch |
| 216 | 1 |
| 217 | " first match |
| 218 | call feedkeys("/the\<cr>", 'tx') |
| 219 | call assert_equal(' 2 these', getline('.')) |
| 220 | 1 |
| 221 | " go to next match (on next line) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 222 | call feedkeys("/the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 223 | call assert_equal(' 3 the theother', getline('.')) |
| 224 | 1 |
| 225 | " go to next match (still on line 3) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 226 | call feedkeys("/the\<C-G>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 227 | call assert_equal(' 3 the theother', getline('.')) |
| 228 | 1 |
| 229 | " go to next match (still on line 3) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 230 | call feedkeys("/the\<C-G>\<C-G>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 231 | call assert_equal(' 3 the theother', getline('.')) |
| 232 | 1 |
| 233 | " go to previous match (on line 3) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 234 | call feedkeys("/the\<C-G>\<C-G>\<C-G>\<C-T>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 235 | call assert_equal(' 3 the theother', getline('.')) |
| 236 | 1 |
| 237 | " go to previous match (on line 3) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 238 | call feedkeys("/the\<C-G>\<C-G>\<C-G>\<C-T>\<C-T>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 239 | call assert_equal(' 3 the theother', getline('.')) |
| 240 | 1 |
| 241 | " go to previous match (on line 2) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 242 | call feedkeys("/the\<C-G>\<C-G>\<C-G>\<C-T>\<C-T>\<C-T>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 243 | call assert_equal(' 2 these', getline('.')) |
Bram Moolenaar | 69a5b86 | 2019-07-16 21:38:51 +0200 | [diff] [blame] | 244 | 1 |
| 245 | " go to previous match (on line 2) |
| 246 | call feedkeys("/the\<C-G>\<C-R>\<C-W>\<cr>", 'tx') |
| 247 | call assert_equal('theother', @/) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 248 | |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 249 | " Test 2: keep the view, |
| 250 | " after deleting a character from the search cmd |
| 251 | call setline(1, [' 1', ' 2 these', ' 3 the', ' 4 their', ' 5 there', ' 6 their', ' 7 the', ' 8 them', ' 9 these', ' 10 foobar']) |
| 252 | resize 5 |
| 253 | 1 |
| 254 | call feedkeys("/foo\<bs>\<cr>", 'tx') |
| 255 | redraw |
| 256 | call assert_equal({'lnum': 10, 'leftcol': 0, 'col': 4, 'topfill': 0, 'topline': 6, 'coladd': 0, 'skipcol': 0, 'curswant': 4}, winsaveview()) |
| 257 | |
| 258 | " remove all history entries |
Bram Moolenaar | 69a5b86 | 2019-07-16 21:38:51 +0200 | [diff] [blame] | 259 | for i in range(11) |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 260 | call histdel('/') |
| 261 | endfor |
| 262 | |
| 263 | " Test 3: reset the view, |
| 264 | " after deleting all characters from the search cmd |
| 265 | norm! 1gg0 |
| 266 | " unfortunately, neither "/foo\<c-w>\<cr>", nor "/foo\<bs>\<bs>\<bs>\<cr>", |
| 267 | " nor "/foo\<c-u>\<cr>" works to delete the commandline. |
| 268 | " In that case Vim should return "E35 no previous regular expression", |
| 269 | " but it looks like Vim still sees /foo and therefore the test fails. |
Bram Moolenaar | 1bc353b | 2019-09-01 14:45:28 +0200 | [diff] [blame] | 270 | " Therefore, disabling this test |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 271 | "call assert_fails(feedkeys("/foo\<c-w>\<cr>", 'tx'), 'E35') |
| 272 | "call assert_equal({'lnum': 1, 'leftcol': 0, 'col': 0, 'topfill': 0, 'topline': 1, 'coladd': 0, 'skipcol': 0, 'curswant': 0}, winsaveview()) |
| 273 | |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 274 | " clean up |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 275 | set noincsearch |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 276 | call test_override("char_avail", 0) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 277 | bw! |
| 278 | endfunc |
Bram Moolenaar | ea683da | 2016-09-09 21:41:34 +0200 | [diff] [blame] | 279 | |
| 280 | func Test_use_sub_pat() |
| 281 | split |
| 282 | let @/ = '' |
| 283 | func X() |
| 284 | s/^/a/ |
| 285 | / |
| 286 | endfunc |
| 287 | call X() |
| 288 | bwipe! |
| 289 | endfunc |
Bram Moolenaar | 6e450a5 | 2017-01-06 20:03:58 +0100 | [diff] [blame] | 290 | |
| 291 | func Test_searchpair() |
| 292 | new |
| 293 | call setline(1, ['other code here', '', '[', '" cursor here', ']']) |
| 294 | 4 |
Bram Moolenaar | 3dddb09 | 2018-06-24 19:01:59 +0200 | [diff] [blame] | 295 | let a = searchpair('\[','',']','bW') |
Bram Moolenaar | 6e450a5 | 2017-01-06 20:03:58 +0100 | [diff] [blame] | 296 | call assert_equal(3, a) |
| 297 | set nomagic |
| 298 | 4 |
Bram Moolenaar | 3dddb09 | 2018-06-24 19:01:59 +0200 | [diff] [blame] | 299 | let a = searchpair('\[','',']','bW') |
Bram Moolenaar | 6e450a5 | 2017-01-06 20:03:58 +0100 | [diff] [blame] | 300 | call assert_equal(3, a) |
| 301 | set magic |
| 302 | q! |
| 303 | endfunc |
| 304 | |
Bram Moolenaar | 3dddb09 | 2018-06-24 19:01:59 +0200 | [diff] [blame] | 305 | func Test_searchpair_errors() |
| 306 | call assert_fails("call searchpair([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: using List as a String') |
| 307 | call assert_fails("call searchpair('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: using Funcref as a String') |
| 308 | call assert_fails("call searchpair('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: using Dictionary as a String') |
| 309 | call assert_fails("call searchpair('start', 'middle', 'end', 'flags', 'skip', 99, 100)", 'E475: Invalid argument: flags') |
| 310 | call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 0, 99, 100)", 'E475: Invalid argument: 0') |
| 311 | call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', -99, 100)", 'E475: Invalid argument: -99') |
| 312 | call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', 99, -100)", 'E475: Invalid argument: -100') |
| 313 | endfunc |
| 314 | |
Bram Moolenaar | 4857048 | 2017-10-30 21:48:41 +0100 | [diff] [blame] | 315 | func Test_searchpair_skip() |
| 316 | func Zero() |
| 317 | return 0 |
| 318 | endfunc |
| 319 | func Partial(x) |
| 320 | return a:x |
| 321 | endfunc |
| 322 | new |
| 323 | call setline(1, ['{', 'foo', 'foo', 'foo', '}']) |
| 324 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', '')) |
| 325 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', '0')) |
| 326 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', {-> 0})) |
| 327 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Zero'))) |
| 328 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Partial', [0]))) |
Bram Moolenaar | 4857048 | 2017-10-30 21:48:41 +0100 | [diff] [blame] | 329 | bw! |
| 330 | endfunc |
| 331 | |
Bram Moolenaar | a43ebe9 | 2018-07-14 17:25:01 +0200 | [diff] [blame] | 332 | func Test_searchpair_leak() |
| 333 | new |
| 334 | call setline(1, 'if one else another endif') |
| 335 | |
| 336 | " The error in the skip expression caused memory to leak. |
| 337 | call assert_fails("call searchpair('\\<if\\>', '\\<else\\>', '\\<endif\\>', '', '\"foo\" 2')", 'E15:') |
| 338 | |
| 339 | bwipe! |
| 340 | endfunc |
| 341 | |
Bram Moolenaar | 66727e1 | 2017-03-01 22:17:05 +0100 | [diff] [blame] | 342 | func Test_searchc() |
| 343 | " These commands used to cause memory overflow in searchc(). |
| 344 | new |
| 345 | norm ixx |
| 346 | exe "norm 0t\u93cf" |
| 347 | bw! |
| 348 | endfunc |
Bram Moolenaar | a693d05 | 2017-06-29 22:23:06 +0200 | [diff] [blame] | 349 | |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 350 | func Cmdline3_prep() |
| 351 | " need to disable char_avail, |
| 352 | " so that expansion of commandline works |
| 353 | call test_override("char_avail", 1) |
| 354 | new |
| 355 | call setline(1, [' 1', ' 2 the~e', ' 3 the theother']) |
| 356 | set incsearch |
| 357 | endfunc |
| 358 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 359 | func Incsearch_cleanup() |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 360 | set noincsearch |
| 361 | call test_override("char_avail", 0) |
| 362 | bw! |
| 363 | endfunc |
| 364 | |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 365 | func Test_search_cmdline3() |
| 366 | if !exists('+incsearch') |
| 367 | return |
| 368 | endif |
| 369 | call Cmdline3_prep() |
| 370 | 1 |
| 371 | " first match |
| 372 | call feedkeys("/the\<c-l>\<cr>", 'tx') |
| 373 | call assert_equal(' 2 the~e', getline('.')) |
| 374 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 375 | call Incsearch_cleanup() |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 376 | endfunc |
| 377 | |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 378 | func Test_search_cmdline3s() |
| 379 | if !exists('+incsearch') |
| 380 | return |
| 381 | endif |
| 382 | call Cmdline3_prep() |
| 383 | 1 |
| 384 | call feedkeys(":%s/the\<c-l>/xxx\<cr>", 'tx') |
| 385 | call assert_equal(' 2 xxxe', getline('.')) |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 386 | undo |
| 387 | call feedkeys(":%subs/the\<c-l>/xxx\<cr>", 'tx') |
| 388 | call assert_equal(' 2 xxxe', getline('.')) |
| 389 | undo |
| 390 | call feedkeys(":%substitute/the\<c-l>/xxx\<cr>", 'tx') |
| 391 | call assert_equal(' 2 xxxe', getline('.')) |
Bram Moolenaar | 167ae42 | 2018-08-14 21:32:21 +0200 | [diff] [blame] | 392 | undo |
| 393 | call feedkeys(":%smagic/the.e/xxx\<cr>", 'tx') |
| 394 | call assert_equal(' 2 xxx', getline('.')) |
| 395 | undo |
| 396 | call assert_fails(":%snomagic/the.e/xxx\<cr>", 'E486') |
| 397 | " |
| 398 | call feedkeys(":%snomagic/the\\.e/xxx\<cr>", 'tx') |
| 399 | call assert_equal(' 2 xxx', getline('.')) |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 400 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 401 | call Incsearch_cleanup() |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 402 | endfunc |
| 403 | |
| 404 | func Test_search_cmdline3g() |
| 405 | if !exists('+incsearch') |
| 406 | return |
| 407 | endif |
| 408 | call Cmdline3_prep() |
| 409 | 1 |
| 410 | call feedkeys(":g/the\<c-l>/d\<cr>", 'tx') |
| 411 | call assert_equal(' 3 the theother', getline(2)) |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 412 | undo |
| 413 | call feedkeys(":global/the\<c-l>/d\<cr>", 'tx') |
| 414 | call assert_equal(' 3 the theother', getline(2)) |
Bram Moolenaar | def7b1d | 2018-08-13 22:54:35 +0200 | [diff] [blame] | 415 | undo |
| 416 | call feedkeys(":g!/the\<c-l>/d\<cr>", 'tx') |
| 417 | call assert_equal(1, line('$')) |
| 418 | call assert_equal(' 2 the~e', getline(1)) |
| 419 | undo |
| 420 | call feedkeys(":global!/the\<c-l>/d\<cr>", 'tx') |
| 421 | call assert_equal(1, line('$')) |
| 422 | call assert_equal(' 2 the~e', getline(1)) |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 423 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 424 | call Incsearch_cleanup() |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 425 | endfunc |
| 426 | |
| 427 | func Test_search_cmdline3v() |
| 428 | if !exists('+incsearch') |
| 429 | return |
| 430 | endif |
| 431 | call Cmdline3_prep() |
| 432 | 1 |
| 433 | call feedkeys(":v/the\<c-l>/d\<cr>", 'tx') |
| 434 | call assert_equal(1, line('$')) |
| 435 | call assert_equal(' 2 the~e', getline(1)) |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 436 | undo |
| 437 | call feedkeys(":vglobal/the\<c-l>/d\<cr>", 'tx') |
| 438 | call assert_equal(1, line('$')) |
| 439 | call assert_equal(' 2 the~e', getline(1)) |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 440 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 441 | call Incsearch_cleanup() |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 442 | endfunc |
| 443 | |
Bram Moolenaar | da5116d | 2017-07-01 23:11:17 +0200 | [diff] [blame] | 444 | func Test_search_cmdline4() |
| 445 | if !exists('+incsearch') |
| 446 | return |
| 447 | endif |
| 448 | " need to disable char_avail, |
| 449 | " so that expansion of commandline works |
| 450 | call test_override("char_avail", 1) |
| 451 | new |
| 452 | call setline(1, [' 1 the first', ' 2 the second', ' 3 the third']) |
| 453 | set incsearch |
| 454 | $ |
| 455 | call feedkeys("?the\<c-g>\<cr>", 'tx') |
| 456 | call assert_equal(' 3 the third', getline('.')) |
| 457 | $ |
| 458 | call feedkeys("?the\<c-g>\<c-g>\<cr>", 'tx') |
| 459 | call assert_equal(' 1 the first', getline('.')) |
| 460 | $ |
| 461 | call feedkeys("?the\<c-g>\<c-g>\<c-g>\<cr>", 'tx') |
| 462 | call assert_equal(' 2 the second', getline('.')) |
| 463 | $ |
| 464 | call feedkeys("?the\<c-t>\<cr>", 'tx') |
| 465 | call assert_equal(' 1 the first', getline('.')) |
| 466 | $ |
| 467 | call feedkeys("?the\<c-t>\<c-t>\<cr>", 'tx') |
| 468 | call assert_equal(' 3 the third', getline('.')) |
| 469 | $ |
| 470 | call feedkeys("?the\<c-t>\<c-t>\<c-t>\<cr>", 'tx') |
| 471 | call assert_equal(' 2 the second', getline('.')) |
| 472 | " clean up |
| 473 | set noincsearch |
| 474 | call test_override("char_avail", 0) |
| 475 | bw! |
| 476 | endfunc |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 477 | |
Bram Moolenaar | f8e8c06 | 2017-10-22 14:44:17 +0200 | [diff] [blame] | 478 | func Test_search_cmdline5() |
| 479 | if !exists('+incsearch') |
| 480 | return |
| 481 | endif |
| 482 | " Do not call test_override("char_avail", 1) so that <C-g> and <C-t> work |
| 483 | " regardless char_avail. |
| 484 | new |
Bram Moolenaar | 69a5b86 | 2019-07-16 21:38:51 +0200 | [diff] [blame] | 485 | call setline(1, [' 1 the first', ' 2 the second', ' 3 the third', '']) |
Bram Moolenaar | f8e8c06 | 2017-10-22 14:44:17 +0200 | [diff] [blame] | 486 | set incsearch |
| 487 | 1 |
| 488 | call feedkeys("/the\<c-g>\<c-g>\<cr>", 'tx') |
| 489 | call assert_equal(' 3 the third', getline('.')) |
| 490 | $ |
| 491 | call feedkeys("?the\<c-t>\<c-t>\<c-t>\<cr>", 'tx') |
Bram Moolenaar | 69a5b86 | 2019-07-16 21:38:51 +0200 | [diff] [blame] | 492 | call assert_equal(' 1 the first', getline('.')) |
Bram Moolenaar | f8e8c06 | 2017-10-22 14:44:17 +0200 | [diff] [blame] | 493 | " clean up |
| 494 | set noincsearch |
| 495 | bw! |
| 496 | endfunc |
| 497 | |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 498 | func Test_search_cmdline6() |
| 499 | " Test that consecutive matches |
| 500 | " are caught by <c-g>/<c-t> |
| 501 | if !exists('+incsearch') |
| 502 | return |
| 503 | endif |
| 504 | " need to disable char_avail, |
| 505 | " so that expansion of commandline works |
| 506 | call test_override("char_avail", 1) |
| 507 | new |
| 508 | call setline(1, [' bbvimb', '']) |
| 509 | set incsearch |
| 510 | " first match |
| 511 | norm! gg0 |
| 512 | call feedkeys("/b\<cr>", 'tx') |
| 513 | call assert_equal([0,1,2,0], getpos('.')) |
| 514 | " second match |
| 515 | norm! gg0 |
| 516 | call feedkeys("/b\<c-g>\<cr>", 'tx') |
| 517 | call assert_equal([0,1,3,0], getpos('.')) |
| 518 | " third match |
| 519 | norm! gg0 |
| 520 | call feedkeys("/b\<c-g>\<c-g>\<cr>", 'tx') |
| 521 | call assert_equal([0,1,7,0], getpos('.')) |
| 522 | " first match again |
| 523 | norm! gg0 |
| 524 | call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx') |
| 525 | call assert_equal([0,1,2,0], getpos('.')) |
| 526 | set nowrapscan |
| 527 | " last match |
| 528 | norm! gg0 |
| 529 | call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx') |
| 530 | call assert_equal([0,1,7,0], getpos('.')) |
| 531 | " clean up |
| 532 | set wrapscan&vim |
| 533 | set noincsearch |
| 534 | call test_override("char_avail", 0) |
| 535 | bw! |
| 536 | endfunc |
| 537 | |
| 538 | func Test_search_cmdline7() |
| 539 | " Test that an pressing <c-g> in an empty command line |
| 540 | " does not move the cursor |
| 541 | if !exists('+incsearch') |
| 542 | return |
| 543 | endif |
| 544 | " need to disable char_avail, |
| 545 | " so that expansion of commandline works |
| 546 | call test_override("char_avail", 1) |
| 547 | new |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 548 | let @/ = 'b' |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 549 | call setline(1, [' bbvimb', '']) |
| 550 | set incsearch |
| 551 | " first match |
| 552 | norm! gg0 |
| 553 | " moves to next match of previous search pattern, just like /<cr> |
| 554 | call feedkeys("/\<c-g>\<cr>", 'tx') |
| 555 | call assert_equal([0,1,2,0], getpos('.')) |
| 556 | " moves to next match of previous search pattern, just like /<cr> |
| 557 | call feedkeys("/\<cr>", 'tx') |
| 558 | call assert_equal([0,1,3,0], getpos('.')) |
| 559 | " moves to next match of previous search pattern, just like /<cr> |
| 560 | call feedkeys("/\<c-t>\<cr>", 'tx') |
| 561 | call assert_equal([0,1,7,0], getpos('.')) |
Bram Moolenaar | d048009 | 2017-11-16 22:20:39 +0100 | [diff] [blame] | 562 | |
| 563 | " using an offset uses the last search pattern |
| 564 | call cursor(1, 1) |
| 565 | call setline(1, ['1 bbvimb', ' 2 bbvimb']) |
| 566 | let @/ = 'b' |
| 567 | call feedkeys("//e\<c-g>\<cr>", 'tx') |
| 568 | call assert_equal('1 bbvimb', getline('.')) |
| 569 | call assert_equal(4, col('.')) |
| 570 | |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 571 | set noincsearch |
| 572 | call test_override("char_avail", 0) |
| 573 | bw! |
| 574 | endfunc |
| 575 | |
| 576 | func Test_search_cmdline8() |
| 577 | " Highlighting is cleared in all windows |
| 578 | " since hls applies to all windows |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 579 | CheckOption incsearch |
| 580 | CheckFeature terminal |
| 581 | CheckNotGui |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 582 | if has("win32") |
| 583 | throw "Skipped: Bug with sending <ESC> to terminal window not fixed yet" |
| 584 | endif |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 585 | |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 586 | let h = winheight(0) |
| 587 | if h < 3 |
| 588 | return |
| 589 | endif |
| 590 | " Prepare buffer text |
| 591 | let lines = ['abb vim vim vi', 'vimvivim'] |
| 592 | call writefile(lines, 'Xsearch.txt') |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 593 | let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3}) |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 594 | |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 595 | call WaitForAssert({-> assert_equal(lines, [term_getline(buf, 1), term_getline(buf, 2)])}) |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 596 | |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 597 | call term_sendkeys(buf, ":set incsearch hlsearch\<cr>") |
| 598 | call term_sendkeys(buf, ":14vsp\<cr>") |
| 599 | call term_sendkeys(buf, "/vim\<cr>") |
| 600 | call term_sendkeys(buf, "/b\<esc>") |
| 601 | call term_sendkeys(buf, "gg0") |
| 602 | call term_wait(buf, 500) |
| 603 | let screen_line = term_scrape(buf, 1) |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 604 | let [a0,a1,a2,a3] = [screen_line[3].attr, screen_line[4].attr, |
| 605 | \ screen_line[18].attr, screen_line[19].attr] |
| 606 | call assert_notequal(a0, a1) |
| 607 | call assert_notequal(a0, a3) |
| 608 | call assert_notequal(a1, a2) |
| 609 | call assert_equal(a0, a2) |
| 610 | call assert_equal(a1, a3) |
| 611 | " clean up |
| 612 | call delete('Xsearch.txt') |
| 613 | |
| 614 | bwipe! |
| 615 | endfunc |
| 616 | |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 617 | " Tests for regexp with various magic settings |
| 618 | func Test_search_regexp() |
| 619 | enew! |
| 620 | |
| 621 | put ='1 a aa abb abbccc' |
| 622 | exe 'normal! /a*b\{2}c\+/e' . "\<CR>" |
| 623 | call assert_equal([0, 2, 17, 0], getpos('.')) |
| 624 | |
| 625 | put ='2 d dd dee deefff' |
| 626 | exe 'normal! /\Md\*e\{2}f\+/e' . "\<CR>" |
| 627 | call assert_equal([0, 3, 17, 0], getpos('.')) |
| 628 | |
| 629 | set nomagic |
| 630 | put ='3 g gg ghh ghhiii' |
| 631 | exe 'normal! /g\*h\{2}i\+/e' . "\<CR>" |
| 632 | call assert_equal([0, 4, 17, 0], getpos('.')) |
| 633 | |
| 634 | put ='4 j jj jkk jkklll' |
| 635 | exe 'normal! /\mj*k\{2}l\+/e' . "\<CR>" |
| 636 | call assert_equal([0, 5, 17, 0], getpos('.')) |
| 637 | |
| 638 | put ='5 m mm mnn mnnooo' |
| 639 | exe 'normal! /\vm*n{2}o+/e' . "\<CR>" |
| 640 | call assert_equal([0, 6, 17, 0], getpos('.')) |
| 641 | |
| 642 | put ='6 x ^aa$ x' |
| 643 | exe 'normal! /\V^aa$' . "\<CR>" |
| 644 | call assert_equal([0, 7, 5, 0], getpos('.')) |
| 645 | |
| 646 | set magic |
| 647 | put ='7 (a)(b) abbaa' |
| 648 | exe 'normal! /\v(a)(b)\2\1\1/e' . "\<CR>" |
| 649 | call assert_equal([0, 8, 14, 0], getpos('.')) |
| 650 | |
| 651 | put ='8 axx [ab]xx' |
| 652 | exe 'normal! /\V[ab]\(\[xy]\)\1' . "\<CR>" |
| 653 | call assert_equal([0, 9, 7, 0], getpos('.')) |
| 654 | |
| 655 | set undolevels=100 |
| 656 | put ='9 foobar' |
| 657 | put ='' |
| 658 | exe "normal! a\<C-G>u\<Esc>" |
| 659 | normal G |
| 660 | exe 'normal! dv?bar?' . "\<CR>" |
| 661 | call assert_equal('9 foo', getline('.')) |
| 662 | call assert_equal([0, 10, 5, 0], getpos('.')) |
| 663 | call assert_equal(10, line('$')) |
| 664 | normal u |
| 665 | call assert_equal('9 foobar', getline('.')) |
| 666 | call assert_equal([0, 10, 6, 0], getpos('.')) |
| 667 | call assert_equal(11, line('$')) |
| 668 | |
| 669 | set undolevels& |
| 670 | enew! |
| 671 | endfunc |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 672 | |
| 673 | func Test_search_cmdline_incsearch_highlight() |
| 674 | if !exists('+incsearch') |
| 675 | return |
| 676 | endif |
| 677 | set incsearch hlsearch |
| 678 | " need to disable char_avail, |
| 679 | " so that expansion of commandline works |
| 680 | call test_override("char_avail", 1) |
| 681 | new |
| 682 | call setline(1, ['aaa 1 the first', ' 2 the second', ' 3 the third']) |
| 683 | |
| 684 | 1 |
| 685 | call feedkeys("/second\<cr>", 'tx') |
| 686 | call assert_equal('second', @/) |
| 687 | call assert_equal(' 2 the second', getline('.')) |
| 688 | |
| 689 | " Canceling search won't change @/ |
| 690 | 1 |
| 691 | let @/ = 'last pattern' |
| 692 | call feedkeys("/third\<C-c>", 'tx') |
| 693 | call assert_equal('last pattern', @/) |
| 694 | call feedkeys("/third\<Esc>", 'tx') |
| 695 | call assert_equal('last pattern', @/) |
| 696 | call feedkeys("/3\<bs>\<bs>", 'tx') |
| 697 | call assert_equal('last pattern', @/) |
| 698 | call feedkeys("/third\<c-g>\<c-t>\<Esc>", 'tx') |
| 699 | call assert_equal('last pattern', @/) |
| 700 | |
| 701 | " clean up |
| 702 | set noincsearch nohlsearch |
| 703 | bw! |
| 704 | endfunc |
| 705 | |
| 706 | func Test_search_cmdline_incsearch_highlight_attr() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 707 | CheckOption incsearch |
| 708 | CheckFeature terminal |
| 709 | CheckNotGui |
| 710 | |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 711 | let h = winheight(0) |
| 712 | if h < 3 |
| 713 | return |
| 714 | endif |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 715 | |
| 716 | " Prepare buffer text |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 717 | let lines = ['abb vim vim vi', 'vimvivim'] |
| 718 | call writefile(lines, 'Xsearch.txt') |
| 719 | let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3}) |
| 720 | |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 721 | call WaitForAssert({-> assert_equal(lines, [term_getline(buf, 1), term_getline(buf, 2)])}) |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 722 | " wait for vim to complete initialization |
| 723 | call term_wait(buf) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 724 | |
| 725 | " Get attr of normal(a0), incsearch(a1), hlsearch(a2) highlight |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 726 | call term_sendkeys(buf, ":set incsearch hlsearch\<cr>") |
| 727 | call term_sendkeys(buf, '/b') |
| 728 | call term_wait(buf, 200) |
| 729 | let screen_line1 = term_scrape(buf, 1) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 730 | call assert_true(len(screen_line1) > 2) |
| 731 | " a0: attr_normal |
| 732 | let a0 = screen_line1[0].attr |
| 733 | " a1: attr_incsearch |
| 734 | let a1 = screen_line1[1].attr |
| 735 | " a2: attr_hlsearch |
| 736 | let a2 = screen_line1[2].attr |
| 737 | call assert_notequal(a0, a1) |
| 738 | call assert_notequal(a0, a2) |
| 739 | call assert_notequal(a1, a2) |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 740 | call term_sendkeys(buf, "\<cr>gg0") |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 741 | |
| 742 | " Test incremental highlight search |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 743 | call term_sendkeys(buf, "/vim") |
| 744 | call term_wait(buf, 200) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 745 | " Buffer: |
| 746 | " abb vim vim vi |
| 747 | " vimvivim |
| 748 | " Search: /vim |
| 749 | let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a2,a2,a2,a0,a0,a0] |
| 750 | let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 751 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 752 | call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 753 | |
| 754 | " Test <C-g> |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 755 | call term_sendkeys(buf, "\<C-g>\<C-g>") |
| 756 | call term_wait(buf, 200) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 757 | let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] |
| 758 | let attr_line2 = [a1,a1,a1,a0,a0,a2,a2,a2] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 759 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 760 | call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 761 | |
| 762 | " Test <C-t> |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 763 | call term_sendkeys(buf, "\<C-t>") |
| 764 | call term_wait(buf, 200) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 765 | let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a1,a1,a1,a0,a0,a0] |
| 766 | let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 767 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 768 | call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 769 | |
| 770 | " Type Enter and a1(incsearch highlight) should become a2(hlsearch highlight) |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 771 | call term_sendkeys(buf, "\<cr>") |
| 772 | call term_wait(buf, 200) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 773 | let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] |
| 774 | let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 775 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 776 | call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 777 | |
| 778 | " Test nohlsearch. a2(hlsearch highlight) should become a0(normal highlight) |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 779 | call term_sendkeys(buf, ":1\<cr>") |
| 780 | call term_sendkeys(buf, ":set nohlsearch\<cr>") |
| 781 | call term_sendkeys(buf, "/vim") |
| 782 | call term_wait(buf, 200) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 783 | let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a0,a0,a0,a0,a0,a0] |
| 784 | let attr_line2 = [a0,a0,a0,a0,a0,a0,a0,a0] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 785 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 786 | call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 787 | call delete('Xsearch.txt') |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 788 | |
Bram Moolenaar | b94340c | 2017-11-02 16:16:31 +0100 | [diff] [blame] | 789 | call delete('Xsearch.txt') |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 790 | bwipe! |
| 791 | endfunc |
Bram Moolenaar | f45938c | 2017-11-02 15:59:57 +0100 | [diff] [blame] | 792 | |
Bram Moolenaar | 548e598 | 2018-12-26 21:45:00 +0100 | [diff] [blame] | 793 | func Test_incsearch_cmdline_modifier() |
| 794 | if !exists('+incsearch') |
| 795 | return |
| 796 | endif |
| 797 | call test_override("char_avail", 1) |
| 798 | new |
| 799 | call setline(1, ['foo']) |
| 800 | set incsearch |
| 801 | " Test that error E14 does not occur in parsing command modifier. |
| 802 | call feedkeys("V:tab", 'tx') |
| 803 | |
| 804 | call Incsearch_cleanup() |
| 805 | endfunc |
| 806 | |
Bram Moolenaar | 9d34d90 | 2018-04-27 22:18:12 +0200 | [diff] [blame] | 807 | func Test_incsearch_scrolling() |
| 808 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 809 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 9d34d90 | 2018-04-27 22:18:12 +0200 | [diff] [blame] | 810 | endif |
| 811 | call assert_equal(0, &scrolloff) |
| 812 | call writefile([ |
| 813 | \ 'let dots = repeat(".", 120)', |
| 814 | \ 'set incsearch cmdheight=2 scrolloff=0', |
| 815 | \ 'call setline(1, [dots, dots, dots, "", "target", dots, dots])', |
| 816 | \ 'normal gg', |
| 817 | \ 'redraw', |
| 818 | \ ], 'Xscript') |
| 819 | let buf = RunVimInTerminal('-S Xscript', {'rows': 9, 'cols': 70}) |
| 820 | " Need to send one key at a time to force a redraw |
| 821 | call term_sendkeys(buf, '/') |
| 822 | sleep 100m |
| 823 | call term_sendkeys(buf, 't') |
| 824 | sleep 100m |
| 825 | call term_sendkeys(buf, 'a') |
| 826 | sleep 100m |
| 827 | call term_sendkeys(buf, 'r') |
| 828 | sleep 100m |
| 829 | call term_sendkeys(buf, 'g') |
| 830 | call VerifyScreenDump(buf, 'Test_incsearch_scrolling_01', {}) |
| 831 | |
| 832 | call term_sendkeys(buf, "\<Esc>") |
| 833 | call StopVimInTerminal(buf) |
| 834 | call delete('Xscript') |
| 835 | endfunc |
| 836 | |
Bram Moolenaar | 4edfe2d | 2018-08-23 20:55:45 +0200 | [diff] [blame] | 837 | func Test_incsearch_search_dump() |
| 838 | if !exists('+incsearch') |
| 839 | return |
| 840 | endif |
| 841 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 842 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 4edfe2d | 2018-08-23 20:55:45 +0200 | [diff] [blame] | 843 | endif |
| 844 | call writefile([ |
| 845 | \ 'set incsearch hlsearch scrolloff=0', |
| 846 | \ 'for n in range(1, 8)', |
| 847 | \ ' call setline(n, "foo " . n)', |
| 848 | \ 'endfor', |
| 849 | \ '3', |
| 850 | \ ], 'Xis_search_script') |
| 851 | let buf = RunVimInTerminal('-S Xis_search_script', {'rows': 9, 'cols': 70}) |
| 852 | " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by |
| 853 | " the 'ambiwidth' check. |
| 854 | sleep 100m |
| 855 | |
| 856 | " Need to send one key at a time to force a redraw. |
| 857 | call term_sendkeys(buf, '/fo') |
Bram Moolenaar | 4edfe2d | 2018-08-23 20:55:45 +0200 | [diff] [blame] | 858 | call VerifyScreenDump(buf, 'Test_incsearch_search_01', {}) |
| 859 | call term_sendkeys(buf, "\<Esc>") |
| 860 | sleep 100m |
| 861 | |
| 862 | call term_sendkeys(buf, '/\v') |
Bram Moolenaar | 4edfe2d | 2018-08-23 20:55:45 +0200 | [diff] [blame] | 863 | call VerifyScreenDump(buf, 'Test_incsearch_search_02', {}) |
| 864 | call term_sendkeys(buf, "\<Esc>") |
| 865 | |
| 866 | call StopVimInTerminal(buf) |
| 867 | call delete('Xis_search_script') |
| 868 | endfunc |
| 869 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 870 | func Test_incsearch_substitute() |
| 871 | if !exists('+incsearch') |
| 872 | return |
| 873 | endif |
| 874 | call test_override("char_avail", 1) |
| 875 | new |
| 876 | set incsearch |
| 877 | for n in range(1, 10) |
| 878 | call setline(n, 'foo ' . n) |
| 879 | endfor |
| 880 | 4 |
| 881 | call feedkeys(":.,.+2s/foo\<BS>o\<BS>o/xxx\<cr>", 'tx') |
| 882 | call assert_equal('foo 3', getline(3)) |
| 883 | call assert_equal('xxx 4', getline(4)) |
| 884 | call assert_equal('xxx 5', getline(5)) |
| 885 | call assert_equal('xxx 6', getline(6)) |
| 886 | call assert_equal('foo 7', getline(7)) |
| 887 | |
| 888 | call Incsearch_cleanup() |
| 889 | endfunc |
| 890 | |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 891 | " Similar to Test_incsearch_substitute() but with a screendump halfway. |
| 892 | func Test_incsearch_substitute_dump() |
| 893 | if !exists('+incsearch') |
| 894 | return |
| 895 | endif |
| 896 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 897 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 898 | endif |
| 899 | call writefile([ |
| 900 | \ 'set incsearch hlsearch scrolloff=0', |
| 901 | \ 'for n in range(1, 10)', |
| 902 | \ ' call setline(n, "foo " . n)', |
| 903 | \ 'endfor', |
Bram Moolenaar | 2f6a346 | 2018-08-14 18:16:52 +0200 | [diff] [blame] | 904 | \ 'call setline(11, "bar 11")', |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 905 | \ '3', |
| 906 | \ ], 'Xis_subst_script') |
| 907 | let buf = RunVimInTerminal('-S Xis_subst_script', {'rows': 9, 'cols': 70}) |
| 908 | " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by |
| 909 | " the 'ambiwidth' check. |
| 910 | sleep 100m |
| 911 | |
| 912 | " Need to send one key at a time to force a redraw. |
Bram Moolenaar | c7f08b7 | 2018-08-12 17:39:14 +0200 | [diff] [blame] | 913 | " Select three lines at the cursor with typed pattern. |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 914 | call term_sendkeys(buf, ':.,.+2s/') |
| 915 | sleep 100m |
| 916 | call term_sendkeys(buf, 'f') |
| 917 | sleep 100m |
| 918 | call term_sendkeys(buf, 'o') |
| 919 | sleep 100m |
| 920 | call term_sendkeys(buf, 'o') |
| 921 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_01', {}) |
Bram Moolenaar | c7f08b7 | 2018-08-12 17:39:14 +0200 | [diff] [blame] | 922 | call term_sendkeys(buf, "\<Esc>") |
| 923 | |
| 924 | " Select three lines at the cursor using previous pattern. |
| 925 | call term_sendkeys(buf, "/foo\<CR>") |
| 926 | sleep 100m |
| 927 | call term_sendkeys(buf, ':.,.+2s//') |
Bram Moolenaar | c7f08b7 | 2018-08-12 17:39:14 +0200 | [diff] [blame] | 928 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_02', {}) |
| 929 | |
| 930 | " Deleting last slash should remove the match. |
| 931 | call term_sendkeys(buf, "\<BS>") |
Bram Moolenaar | c7f08b7 | 2018-08-12 17:39:14 +0200 | [diff] [blame] | 932 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_03', {}) |
Bram Moolenaar | 60d0871 | 2018-08-12 21:53:15 +0200 | [diff] [blame] | 933 | call term_sendkeys(buf, "\<Esc>") |
| 934 | |
| 935 | " Reverse range is accepted |
| 936 | call term_sendkeys(buf, ':5,2s/foo') |
Bram Moolenaar | 60d0871 | 2018-08-12 21:53:15 +0200 | [diff] [blame] | 937 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_04', {}) |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 938 | call term_sendkeys(buf, "\<Esc>") |
Bram Moolenaar | 2b926fc | 2018-08-13 11:07:57 +0200 | [diff] [blame] | 939 | |
| 940 | " White space after the command is skipped |
| 941 | call term_sendkeys(buf, ':2,3sub /fo') |
Bram Moolenaar | 2b926fc | 2018-08-13 11:07:57 +0200 | [diff] [blame] | 942 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_05', {}) |
| 943 | call term_sendkeys(buf, "\<Esc>") |
| 944 | |
Bram Moolenaar | 33c4dbb | 2018-08-14 16:06:16 +0200 | [diff] [blame] | 945 | " Command modifiers are skipped |
| 946 | call term_sendkeys(buf, ':above below browse botr confirm keepmar keepalt keeppat keepjum filter xxx hide lockm leftabove noau noswap rightbel sandbox silent silent! $tab top unsil vert verbose 4,5s/fo.') |
Bram Moolenaar | 33c4dbb | 2018-08-14 16:06:16 +0200 | [diff] [blame] | 947 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_06', {}) |
| 948 | call term_sendkeys(buf, "\<Esc>") |
| 949 | |
Bram Moolenaar | 2f6a346 | 2018-08-14 18:16:52 +0200 | [diff] [blame] | 950 | " Cursorline highlighting at match |
| 951 | call term_sendkeys(buf, ":set cursorline\<CR>") |
| 952 | call term_sendkeys(buf, 'G9G') |
| 953 | call term_sendkeys(buf, ':9,11s/bar') |
Bram Moolenaar | 2f6a346 | 2018-08-14 18:16:52 +0200 | [diff] [blame] | 954 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_07', {}) |
| 955 | call term_sendkeys(buf, "\<Esc>") |
| 956 | |
| 957 | " Cursorline highlighting at cursor when no match |
| 958 | call term_sendkeys(buf, ':9,10s/bar') |
Bram Moolenaar | 2f6a346 | 2018-08-14 18:16:52 +0200 | [diff] [blame] | 959 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_08', {}) |
| 960 | call term_sendkeys(buf, "\<Esc>") |
| 961 | |
Bram Moolenaar | 8b0d5ce | 2018-08-22 23:05:44 +0200 | [diff] [blame] | 962 | " Only \v handled as empty pattern, does not move cursor |
| 963 | call term_sendkeys(buf, '3G4G') |
| 964 | call term_sendkeys(buf, ":nohlsearch\<CR>") |
| 965 | call term_sendkeys(buf, ':6,7s/\v') |
Bram Moolenaar | 8b0d5ce | 2018-08-22 23:05:44 +0200 | [diff] [blame] | 966 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_09', {}) |
| 967 | call term_sendkeys(buf, "\<Esc>") |
| 968 | |
Bram Moolenaar | f13daa4 | 2018-08-31 22:09:54 +0200 | [diff] [blame] | 969 | call term_sendkeys(buf, ":set nocursorline\<CR>") |
| 970 | |
| 971 | " All matches are highlighted for 'hlsearch' after the incsearch canceled |
| 972 | call term_sendkeys(buf, "1G*") |
| 973 | call term_sendkeys(buf, ":2,5s/foo") |
| 974 | sleep 100m |
| 975 | call term_sendkeys(buf, "\<Esc>") |
| 976 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_10', {}) |
| 977 | |
Bram Moolenaar | 65985ac | 2018-09-16 17:08:04 +0200 | [diff] [blame] | 978 | call term_sendkeys(buf, ":split\<CR>") |
| 979 | call term_sendkeys(buf, ":let @/ = 'xyz'\<CR>") |
| 980 | call term_sendkeys(buf, ":%s/.") |
| 981 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_11', {}) |
| 982 | call term_sendkeys(buf, "\<BS>") |
| 983 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_12', {}) |
| 984 | call term_sendkeys(buf, "\<Esc>") |
| 985 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_13', {}) |
Bram Moolenaar | c672525 | 2019-11-23 21:56:46 +0100 | [diff] [blame] | 986 | call term_sendkeys(buf, ":%bwipe!\<CR>") |
| 987 | call term_sendkeys(buf, ":only!\<CR>") |
| 988 | |
| 989 | " get :'<,'>s command in history |
| 990 | call term_sendkeys(buf, ":set cmdheight=2\<CR>") |
| 991 | call term_sendkeys(buf, "aasdfasdf\<Esc>") |
| 992 | call term_sendkeys(buf, "V:s/a/b/g\<CR>") |
| 993 | " Using '<,'> does not give E20 |
| 994 | call term_sendkeys(buf, ":new\<CR>") |
| 995 | call term_sendkeys(buf, "aasdfasdf\<Esc>") |
| 996 | call term_sendkeys(buf, ":\<Up>\<Up>") |
| 997 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_14', {}) |
| 998 | call term_sendkeys(buf, "<Esc>") |
Bram Moolenaar | 65985ac | 2018-09-16 17:08:04 +0200 | [diff] [blame] | 999 | |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 1000 | call StopVimInTerminal(buf) |
| 1001 | call delete('Xis_subst_script') |
| 1002 | endfunc |
| 1003 | |
Bram Moolenaar | 4a7d2d3 | 2019-02-21 16:25:50 +0100 | [diff] [blame] | 1004 | func Test_incsearch_with_change() |
| 1005 | if !has('timers') || !exists('+incsearch') || !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1006 | throw 'Skipped: cannot make screendumps and/or timers feature and/or incsearch option missing' |
Bram Moolenaar | 4a7d2d3 | 2019-02-21 16:25:50 +0100 | [diff] [blame] | 1007 | endif |
| 1008 | |
| 1009 | call writefile([ |
| 1010 | \ 'set incsearch hlsearch scrolloff=0', |
| 1011 | \ 'call setline(1, ["one", "two ------ X", "three"])', |
| 1012 | \ 'call timer_start(200, { _ -> setline(2, "x")})', |
| 1013 | \ ], 'Xis_change_script') |
| 1014 | let buf = RunVimInTerminal('-S Xis_change_script', {'rows': 9, 'cols': 70}) |
| 1015 | " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by |
| 1016 | " the 'ambiwidth' check. |
Bram Moolenaar | e86ecbd | 2019-02-21 17:48:59 +0100 | [diff] [blame] | 1017 | sleep 300m |
Bram Moolenaar | 4a7d2d3 | 2019-02-21 16:25:50 +0100 | [diff] [blame] | 1018 | |
| 1019 | " Highlight X, it will be deleted by the timer callback. |
| 1020 | call term_sendkeys(buf, ':%s/X') |
| 1021 | call VerifyScreenDump(buf, 'Test_incsearch_change_01', {}) |
| 1022 | call term_sendkeys(buf, "\<Esc>") |
| 1023 | |
| 1024 | call StopVimInTerminal(buf) |
| 1025 | call delete('Xis_change_script') |
| 1026 | endfunc |
| 1027 | |
Bram Moolenaar | 81f5653 | 2018-08-18 16:19:42 +0200 | [diff] [blame] | 1028 | " Similar to Test_incsearch_substitute_dump() for :sort |
Bram Moolenaar | 4edfe2d | 2018-08-23 20:55:45 +0200 | [diff] [blame] | 1029 | func Test_incsearch_sort_dump() |
Bram Moolenaar | 81f5653 | 2018-08-18 16:19:42 +0200 | [diff] [blame] | 1030 | if !exists('+incsearch') |
| 1031 | return |
| 1032 | endif |
| 1033 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1034 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 81f5653 | 2018-08-18 16:19:42 +0200 | [diff] [blame] | 1035 | endif |
| 1036 | call writefile([ |
| 1037 | \ 'set incsearch hlsearch scrolloff=0', |
| 1038 | \ 'call setline(1, ["another one 2", "that one 3", "the one 1"])', |
| 1039 | \ ], 'Xis_sort_script') |
| 1040 | let buf = RunVimInTerminal('-S Xis_sort_script', {'rows': 9, 'cols': 70}) |
| 1041 | " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by |
| 1042 | " the 'ambiwidth' check. |
| 1043 | sleep 100m |
| 1044 | |
| 1045 | " Need to send one key at a time to force a redraw. |
| 1046 | call term_sendkeys(buf, ':sort ni u /on') |
Bram Moolenaar | 81f5653 | 2018-08-18 16:19:42 +0200 | [diff] [blame] | 1047 | call VerifyScreenDump(buf, 'Test_incsearch_sort_01', {}) |
| 1048 | call term_sendkeys(buf, "\<Esc>") |
| 1049 | |
| 1050 | call StopVimInTerminal(buf) |
| 1051 | call delete('Xis_sort_script') |
| 1052 | endfunc |
| 1053 | |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1054 | " Similar to Test_incsearch_substitute_dump() for :vimgrep famiry |
| 1055 | func Test_incsearch_vimgrep_dump() |
| 1056 | if !exists('+incsearch') |
| 1057 | return |
| 1058 | endif |
| 1059 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1060 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1061 | endif |
| 1062 | call writefile([ |
| 1063 | \ 'set incsearch hlsearch scrolloff=0', |
| 1064 | \ 'call setline(1, ["another one 2", "that one 3", "the one 1"])', |
| 1065 | \ ], 'Xis_vimgrep_script') |
| 1066 | let buf = RunVimInTerminal('-S Xis_vimgrep_script', {'rows': 9, 'cols': 70}) |
| 1067 | " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by |
| 1068 | " the 'ambiwidth' check. |
| 1069 | sleep 100m |
| 1070 | |
| 1071 | " Need to send one key at a time to force a redraw. |
| 1072 | call term_sendkeys(buf, ':vimgrep on') |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1073 | call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_01', {}) |
| 1074 | call term_sendkeys(buf, "\<Esc>") |
| 1075 | |
| 1076 | call term_sendkeys(buf, ':vimg /on/ *.txt') |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1077 | call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_02', {}) |
| 1078 | call term_sendkeys(buf, "\<Esc>") |
| 1079 | |
| 1080 | call term_sendkeys(buf, ':vimgrepadd "\<on') |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1081 | call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_03', {}) |
| 1082 | call term_sendkeys(buf, "\<Esc>") |
| 1083 | |
| 1084 | call term_sendkeys(buf, ':lv "tha') |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1085 | call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_04', {}) |
| 1086 | call term_sendkeys(buf, "\<Esc>") |
| 1087 | |
| 1088 | call term_sendkeys(buf, ':lvimgrepa "the" **/*.txt') |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1089 | call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_05', {}) |
| 1090 | call term_sendkeys(buf, "\<Esc>") |
| 1091 | |
| 1092 | call StopVimInTerminal(buf) |
| 1093 | call delete('Xis_vimgrep_script') |
| 1094 | endfunc |
| 1095 | |
Bram Moolenaar | 198cb66 | 2018-09-06 21:44:17 +0200 | [diff] [blame] | 1096 | func Test_keep_last_search_pattern() |
| 1097 | if !exists('+incsearch') |
| 1098 | return |
| 1099 | endif |
| 1100 | new |
| 1101 | call setline(1, ['foo', 'foo', 'foo']) |
| 1102 | set incsearch |
| 1103 | call test_override("char_avail", 1) |
| 1104 | let @/ = 'bar' |
| 1105 | call feedkeys(":/foo/s//\<Esc>", 'ntx') |
| 1106 | call assert_equal('bar', @/) |
| 1107 | |
Bram Moolenaar | 50eb16c | 2018-09-15 15:42:40 +0200 | [diff] [blame] | 1108 | " no error message if pattern not found |
| 1109 | call feedkeys(":/xyz/s//\<Esc>", 'ntx') |
| 1110 | call assert_equal('bar', @/) |
| 1111 | |
Bram Moolenaar | 198cb66 | 2018-09-06 21:44:17 +0200 | [diff] [blame] | 1112 | bwipe! |
| 1113 | call test_override("ALL", 0) |
| 1114 | set noincsearch |
| 1115 | endfunc |
| 1116 | |
Bram Moolenaar | 99f043a | 2018-09-09 15:54:14 +0200 | [diff] [blame] | 1117 | func Test_word_under_cursor_after_match() |
| 1118 | if !exists('+incsearch') |
| 1119 | return |
| 1120 | endif |
| 1121 | new |
| 1122 | call setline(1, 'foo bar') |
| 1123 | set incsearch |
| 1124 | call test_override("char_avail", 1) |
| 1125 | try |
| 1126 | call feedkeys("/foo\<C-R>\<C-W>\<CR>", 'ntx') |
| 1127 | catch /E486:/ |
| 1128 | endtry |
| 1129 | call assert_equal('foobar', @/) |
| 1130 | |
| 1131 | bwipe! |
| 1132 | call test_override("ALL", 0) |
| 1133 | set noincsearch |
| 1134 | endfunc |
| 1135 | |
| 1136 | func Test_subst_word_under_cursor() |
| 1137 | if !exists('+incsearch') |
| 1138 | return |
| 1139 | endif |
| 1140 | new |
| 1141 | call setline(1, ['int SomeLongName;', 'for (xxx = 1; xxx < len; ++xxx)']) |
| 1142 | set incsearch |
| 1143 | call test_override("char_avail", 1) |
| 1144 | call feedkeys("/LongName\<CR>", 'ntx') |
| 1145 | call feedkeys(":%s/xxx/\<C-R>\<C-W>/g\<CR>", 'ntx') |
| 1146 | call assert_equal('for (SomeLongName = 1; SomeLongName < len; ++SomeLongName)', getline(2)) |
| 1147 | |
| 1148 | bwipe! |
| 1149 | call test_override("ALL", 0) |
| 1150 | set noincsearch |
| 1151 | endfunc |
| 1152 | |
Bram Moolenaar | f45938c | 2017-11-02 15:59:57 +0100 | [diff] [blame] | 1153 | func Test_search_undefined_behaviour() |
| 1154 | if !has("terminal") |
| 1155 | return |
| 1156 | endif |
| 1157 | let h = winheight(0) |
| 1158 | if h < 3 |
| 1159 | return |
| 1160 | endif |
| 1161 | " did cause an undefined left shift |
| 1162 | let g:buf = term_start([GetVimProg(), '--clean', '-e', '-s', '-c', 'call search(getline("."))', 'samples/test000'], {'term_rows': 3}) |
| 1163 | call assert_equal([''], getline(1, '$')) |
| 1164 | call term_sendkeys(g:buf, ":qa!\<cr>") |
| 1165 | bwipe! |
| 1166 | endfunc |
Bram Moolenaar | 2973daa | 2017-11-02 23:15:40 +0100 | [diff] [blame] | 1167 | |
| 1168 | func Test_search_undefined_behaviour2() |
| 1169 | call search("\%UC0000000") |
| 1170 | endfunc |
Bram Moolenaar | fb094e1 | 2017-11-05 20:59:28 +0100 | [diff] [blame] | 1171 | |
| 1172 | " Test for search('multi-byte char', 'bce') |
| 1173 | func Test_search_multibyte() |
Bram Moolenaar | fb094e1 | 2017-11-05 20:59:28 +0100 | [diff] [blame] | 1174 | let save_enc = &encoding |
| 1175 | set encoding=utf8 |
| 1176 | enew! |
| 1177 | call append('$', 'A') |
| 1178 | call cursor(2, 1) |
| 1179 | call assert_equal(2, search('A', 'bce', line('.'))) |
| 1180 | enew! |
| 1181 | let &encoding = save_enc |
| 1182 | endfunc |
Bram Moolenaar | 890dd05 | 2017-12-16 19:59:37 +0100 | [diff] [blame] | 1183 | |
| 1184 | " This was causing E874. Also causes an invalid read? |
| 1185 | func Test_look_behind() |
| 1186 | new |
| 1187 | call setline(1, '0\|\&\n\@<=') |
| 1188 | call search(getline(".")) |
| 1189 | bwipe! |
| 1190 | endfunc |
Bram Moolenaar | 8ada6aa | 2017-12-19 21:23:21 +0100 | [diff] [blame] | 1191 | |
| 1192 | func Test_search_sentence() |
| 1193 | new |
| 1194 | " this used to cause a crash |
Bram Moolenaar | 1bd999f | 2017-12-19 22:25:40 +0100 | [diff] [blame] | 1195 | call assert_fails("/\\%')", 'E486') |
Bram Moolenaar | 8ada6aa | 2017-12-19 21:23:21 +0100 | [diff] [blame] | 1196 | call assert_fails("/", 'E486') |
Bram Moolenaar | 1bd999f | 2017-12-19 22:25:40 +0100 | [diff] [blame] | 1197 | /\%'( |
| 1198 | / |
Bram Moolenaar | 8ada6aa | 2017-12-19 21:23:21 +0100 | [diff] [blame] | 1199 | endfunc |
Bram Moolenaar | 2fb8f68 | 2018-12-01 13:14:45 +0100 | [diff] [blame] | 1200 | |
| 1201 | " Test that there is no crash when there is a last search pattern but no last |
| 1202 | " substitute pattern. |
| 1203 | func Test_no_last_substitute_pat() |
| 1204 | " Use viminfo to set the last search pattern to a string and make the last |
| 1205 | " substitute pattern the most recent used and make it empty (NULL). |
| 1206 | call writefile(['~MSle0/bar', '~MSle0~&'], 'Xviminfo') |
| 1207 | rviminfo! Xviminfo |
| 1208 | call assert_fails('normal n', 'E35:') |
| 1209 | |
| 1210 | call delete('Xviminfo') |
| 1211 | endfunc |
Bram Moolenaar | 5f5e203 | 2018-12-14 15:47:03 +0100 | [diff] [blame] | 1212 | |
| 1213 | func Test_search_Ctrl_L_combining() |
| 1214 | " Make sure, that Ctrl-L works correctly with combining characters. |
| 1215 | " It uses an artificial example of an 'a' with 4 combining chars: |
| 1216 | " 'a' U+0061 Dec:97 LATIN SMALL LETTER A a /\%u61\Z "\u0061" |
| 1217 | " ' ̀' U+0300 Dec:768 COMBINING GRAVE ACCENT ̀ /\%u300\Z "\u0300" |
| 1218 | " ' ́' U+0301 Dec:769 COMBINING ACUTE ACCENT ́ /\%u301\Z "\u0301" |
| 1219 | " ' ̇' U+0307 Dec:775 COMBINING DOT ABOVE ̇ /\%u307\Z "\u0307" |
| 1220 | " ' ̣' U+0323 Dec:803 COMBINING DOT BELOW ̣ /\%u323 "\u0323" |
| 1221 | " Those should also appear on the commandline |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 1222 | if !exists('+incsearch') |
Bram Moolenaar | 5f5e203 | 2018-12-14 15:47:03 +0100 | [diff] [blame] | 1223 | return |
| 1224 | endif |
| 1225 | call Cmdline3_prep() |
| 1226 | 1 |
| 1227 | let bufcontent = ['', 'Miạ̀́̇m'] |
| 1228 | call append('$', bufcontent) |
| 1229 | call feedkeys("/Mi\<c-l>\<c-l>\<cr>", 'tx') |
| 1230 | call assert_equal(5, line('.')) |
| 1231 | call assert_equal(bufcontent[1], @/) |
| 1232 | call Incsearch_cleanup() |
| 1233 | endfunc |
Bram Moolenaar | 527a2d8 | 2019-02-21 22:28:51 +0100 | [diff] [blame] | 1234 | |
Bram Moolenaar | ab350f8 | 2019-02-28 06:25:00 +0100 | [diff] [blame] | 1235 | func Test_large_hex_chars1() |
Bram Moolenaar | 527a2d8 | 2019-02-21 22:28:51 +0100 | [diff] [blame] | 1236 | " This used to cause a crash, the character becomes an NFA state. |
| 1237 | try |
| 1238 | /\%Ufffffc23 |
| 1239 | catch |
| 1240 | call assert_match('E678:', v:exception) |
| 1241 | endtry |
Bram Moolenaar | ab350f8 | 2019-02-28 06:25:00 +0100 | [diff] [blame] | 1242 | try |
| 1243 | set re=1 |
| 1244 | /\%Ufffffc23 |
| 1245 | catch |
| 1246 | call assert_match('E678:', v:exception) |
| 1247 | endtry |
| 1248 | set re& |
| 1249 | endfunc |
| 1250 | |
| 1251 | func Test_large_hex_chars2() |
| 1252 | " This used to cause a crash, the character becomes an NFA state. |
| 1253 | try |
| 1254 | /[\Ufffffc1f] |
| 1255 | catch |
| 1256 | call assert_match('E486:', v:exception) |
| 1257 | endtry |
| 1258 | try |
| 1259 | set re=1 |
| 1260 | /[\Ufffffc1f] |
| 1261 | catch |
| 1262 | call assert_match('E486:', v:exception) |
| 1263 | endtry |
| 1264 | set re& |
Bram Moolenaar | 527a2d8 | 2019-02-21 22:28:51 +0100 | [diff] [blame] | 1265 | endfunc |
Bram Moolenaar | cd62512 | 2019-02-22 17:29:43 +0100 | [diff] [blame] | 1266 | |
| 1267 | func Test_one_error_msg() |
| 1268 | " This was also giving an internal error |
| 1269 | call assert_fails('call search(" \\((\\v[[=P=]]){185}+ ")', 'E871:') |
| 1270 | endfunc |
Bram Moolenaar | 730f48f | 2019-04-11 13:45:57 +0200 | [diff] [blame] | 1271 | |
| 1272 | func Test_incsearch_add_char_under_cursor() |
| 1273 | if !exists('+incsearch') |
| 1274 | return |
| 1275 | endif |
| 1276 | set incsearch |
| 1277 | new |
| 1278 | call setline(1, ['find match', 'anything']) |
| 1279 | 1 |
| 1280 | call test_override('char_avail', 1) |
| 1281 | call feedkeys("fc/m\<C-L>\<C-L>\<C-L>\<C-L>\<C-L>\<CR>", 'tx') |
| 1282 | call assert_equal('match', @/) |
| 1283 | call test_override('char_avail', 0) |
| 1284 | |
| 1285 | set incsearch& |
| 1286 | bwipe! |
| 1287 | endfunc |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 1288 | |
| 1289 | " Test for the search() function with match at the cursor position |
| 1290 | func Test_search_match_at_curpos() |
| 1291 | new |
| 1292 | call append(0, ['foobar', '', 'one two', '']) |
| 1293 | |
| 1294 | normal gg |
| 1295 | |
Bram Moolenaar | 196b466 | 2019-09-06 21:34:30 +0200 | [diff] [blame] | 1296 | eval 'foobar'->search('c') |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 1297 | call assert_equal([1, 1], [line('.'), col('.')]) |
| 1298 | |
| 1299 | normal j |
| 1300 | call search('^$', 'c') |
| 1301 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1302 | |
| 1303 | call search('^$', 'bc') |
| 1304 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1305 | |
| 1306 | exe "normal /two\<CR>" |
| 1307 | call search('.', 'c') |
| 1308 | call assert_equal([3, 5], [line('.'), col('.')]) |
| 1309 | |
| 1310 | close! |
| 1311 | endfunc |
Bram Moolenaar | db294ad | 2019-06-06 12:49:29 +0200 | [diff] [blame] | 1312 | |
| 1313 | func Test_search_display_pattern() |
| 1314 | new |
| 1315 | call setline(1, ['foo', 'bar', 'foobar']) |
| 1316 | |
| 1317 | call cursor(1, 1) |
| 1318 | let @/ = 'foo' |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1319 | let pat = @/->escape('()*?'. '\s\+') |
Bram Moolenaar | db294ad | 2019-06-06 12:49:29 +0200 | [diff] [blame] | 1320 | let g:a = execute(':unsilent :norm! n') |
| 1321 | call assert_match(pat, g:a) |
| 1322 | |
| 1323 | " right-left |
| 1324 | if exists("+rightleft") |
| 1325 | set rl |
| 1326 | call cursor(1, 1) |
| 1327 | let @/ = 'foo' |
| 1328 | let pat = 'oof/\s\+' |
| 1329 | let g:a = execute(':unsilent :norm! n') |
| 1330 | call assert_match(pat, g:a) |
| 1331 | set norl |
| 1332 | endif |
| 1333 | endfunc |
Bram Moolenaar | 196b466 | 2019-09-06 21:34:30 +0200 | [diff] [blame] | 1334 | |
| 1335 | func Test_searchdecl() |
| 1336 | let lines =<< trim END |
| 1337 | int global; |
| 1338 | |
| 1339 | func() |
| 1340 | { |
| 1341 | int global; |
| 1342 | if (cond) { |
| 1343 | int local; |
| 1344 | } |
| 1345 | int local; |
| 1346 | // comment |
| 1347 | } |
| 1348 | END |
| 1349 | new |
| 1350 | call setline(1, lines) |
| 1351 | 10 |
| 1352 | call assert_equal(0, searchdecl('local', 0, 0)) |
| 1353 | call assert_equal(7, getcurpos()[1]) |
| 1354 | |
| 1355 | 10 |
| 1356 | call assert_equal(0, 'local'->searchdecl(0, 1)) |
| 1357 | call assert_equal(9, getcurpos()[1]) |
| 1358 | |
| 1359 | 10 |
| 1360 | call assert_equal(0, searchdecl('global')) |
| 1361 | call assert_equal(5, getcurpos()[1]) |
| 1362 | |
| 1363 | 10 |
| 1364 | call assert_equal(0, searchdecl('global', 1)) |
| 1365 | call assert_equal(1, getcurpos()[1]) |
| 1366 | |
| 1367 | bwipe! |
| 1368 | endfunc |