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 |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 60 | " eighth 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 |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 102 | " eighth 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 |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 293 | call setline(1, ['other code', 'here [', ' [', ' " cursor here', ' ]]']) |
| 294 | |
Bram Moolenaar | 6e450a5 | 2017-01-06 20:03:58 +0100 | [diff] [blame] | 295 | 4 |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 296 | call assert_equal(3, searchpair('\[', '', ']', 'bW')) |
| 297 | call assert_equal([0, 3, 2, 0], getpos('.')) |
| 298 | 4 |
| 299 | call assert_equal(2, searchpair('\[', '', ']', 'bWr')) |
| 300 | call assert_equal([0, 2, 6, 0], getpos('.')) |
| 301 | 4 |
| 302 | call assert_equal(1, searchpair('\[', '', ']', 'bWm')) |
| 303 | call assert_equal([0, 3, 2, 0], getpos('.')) |
| 304 | 4|norm ^ |
| 305 | call assert_equal(5, searchpair('\[', '', ']', 'Wn')) |
| 306 | call assert_equal([0, 4, 2, 0], getpos('.')) |
| 307 | 4 |
| 308 | call assert_equal(2, searchpair('\[', '', ']', 'bW', |
| 309 | \ 'getline(".") =~ "^\\s*\["')) |
| 310 | call assert_equal([0, 2, 6, 0], getpos('.')) |
Bram Moolenaar | 6e450a5 | 2017-01-06 20:03:58 +0100 | [diff] [blame] | 311 | set nomagic |
| 312 | 4 |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 313 | call assert_equal(3, searchpair('\[', '', ']', 'bW')) |
| 314 | call assert_equal([0, 3, 2, 0], getpos('.')) |
Bram Moolenaar | 6e450a5 | 2017-01-06 20:03:58 +0100 | [diff] [blame] | 315 | set magic |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 316 | 4|norm ^ |
| 317 | call assert_equal(0, searchpair('{', '', '}', 'bW')) |
| 318 | call assert_equal([0, 4, 2, 0], getpos('.')) |
| 319 | |
| 320 | %d |
| 321 | call setline(1, ['if 1', ' if 2', ' else', ' endif 2', 'endif 1']) |
| 322 | |
| 323 | /\<if 1 |
| 324 | call assert_equal(5, searchpair('\<if\>', '\<else\>', '\<endif\>', 'W')) |
| 325 | call assert_equal([0, 5, 1, 0], getpos('.')) |
| 326 | /\<if 2 |
| 327 | call assert_equal(3, searchpair('\<if\>', '\<else\>', '\<endif\>', 'W')) |
| 328 | call assert_equal([0, 3, 3, 0], getpos('.')) |
| 329 | |
| 330 | q! |
| 331 | endfunc |
| 332 | |
| 333 | func Test_searchpairpos() |
| 334 | new |
| 335 | call setline(1, ['other code', 'here [', ' [', ' " cursor here', ' ]]']) |
| 336 | |
| 337 | 4 |
| 338 | call assert_equal([3, 2], searchpairpos('\[', '', ']', 'bW')) |
| 339 | call assert_equal([0, 3, 2, 0], getpos('.')) |
| 340 | 4 |
| 341 | call assert_equal([2, 6], searchpairpos('\[', '', ']', 'bWr')) |
| 342 | call assert_equal([0, 2, 6, 0], getpos('.')) |
| 343 | 4|norm ^ |
| 344 | call assert_equal([5, 2], searchpairpos('\[', '', ']', 'Wn')) |
| 345 | call assert_equal([0, 4, 2, 0], getpos('.')) |
| 346 | 4 |
| 347 | call assert_equal([2, 6], searchpairpos('\[', '', ']', 'bW', |
| 348 | \ 'getline(".") =~ "^\\s*\["')) |
| 349 | call assert_equal([0, 2, 6, 0], getpos('.')) |
| 350 | 4 |
| 351 | call assert_equal([2, 6], searchpairpos('\[', '', ']', 'bWr')) |
| 352 | call assert_equal([0, 2, 6, 0], getpos('.')) |
| 353 | set nomagic |
| 354 | 4 |
| 355 | call assert_equal([3, 2], searchpairpos('\[', '', ']', 'bW')) |
| 356 | call assert_equal([0, 3, 2, 0], getpos('.')) |
| 357 | set magic |
| 358 | 4|norm ^ |
| 359 | call assert_equal([0, 0], searchpairpos('{', '', '}', 'bW')) |
| 360 | call assert_equal([0, 4, 2, 0], getpos('.')) |
| 361 | |
| 362 | %d |
| 363 | call setline(1, ['if 1', ' if 2', ' else', ' endif 2', 'endif 1']) |
| 364 | /\<if 1 |
| 365 | call assert_equal([5, 1], searchpairpos('\<if\>', '\<else\>', '\<endif\>', 'W')) |
| 366 | call assert_equal([0, 5, 1, 0], getpos('.')) |
| 367 | /\<if 2 |
| 368 | call assert_equal([3, 3], searchpairpos('\<if\>', '\<else\>', '\<endif\>', 'W')) |
| 369 | call assert_equal([0, 3, 3, 0], getpos('.')) |
| 370 | |
Bram Moolenaar | 6e450a5 | 2017-01-06 20:03:58 +0100 | [diff] [blame] | 371 | q! |
| 372 | endfunc |
| 373 | |
Bram Moolenaar | 3dddb09 | 2018-06-24 19:01:59 +0200 | [diff] [blame] | 374 | func Test_searchpair_errors() |
| 375 | call assert_fails("call searchpair([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: using List as a String') |
| 376 | call assert_fails("call searchpair('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: using Funcref as a String') |
| 377 | call assert_fails("call searchpair('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: using Dictionary as a String') |
| 378 | call assert_fails("call searchpair('start', 'middle', 'end', 'flags', 'skip', 99, 100)", 'E475: Invalid argument: flags') |
| 379 | call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 0, 99, 100)", 'E475: Invalid argument: 0') |
| 380 | call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', -99, 100)", 'E475: Invalid argument: -99') |
| 381 | call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', 99, -100)", 'E475: Invalid argument: -100') |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 382 | call assert_fails("call searchpair('start', 'middle', 'end', 'e')", 'E475: Invalid argument: e') |
| 383 | call assert_fails("call searchpair('start', 'middle', 'end', 'sn')", 'E475: Invalid argument: sn') |
| 384 | endfunc |
| 385 | |
| 386 | func Test_searchpairpos_errors() |
| 387 | call assert_fails("call searchpairpos([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: using List as a String') |
| 388 | call assert_fails("call searchpairpos('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: using Funcref as a String') |
| 389 | call assert_fails("call searchpairpos('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: using Dictionary as a String') |
| 390 | call assert_fails("call searchpairpos('start', 'middle', 'end', 'flags', 'skip', 99, 100)", 'E475: Invalid argument: flags') |
| 391 | call assert_fails("call searchpairpos('start', 'middle', 'end', 'bW', 0, 99, 100)", 'E475: Invalid argument: 0') |
| 392 | call assert_fails("call searchpairpos('start', 'middle', 'end', 'bW', 'func', -99, 100)", 'E475: Invalid argument: -99') |
| 393 | call assert_fails("call searchpairpos('start', 'middle', 'end', 'bW', 'func', 99, -100)", 'E475: Invalid argument: -100') |
| 394 | call assert_fails("call searchpairpos('start', 'middle', 'end', 'e')", 'E475: Invalid argument: e') |
| 395 | call assert_fails("call searchpairpos('start', 'middle', 'end', 'sn')", 'E475: Invalid argument: sn') |
Bram Moolenaar | 3dddb09 | 2018-06-24 19:01:59 +0200 | [diff] [blame] | 396 | endfunc |
| 397 | |
Bram Moolenaar | 4857048 | 2017-10-30 21:48:41 +0100 | [diff] [blame] | 398 | func Test_searchpair_skip() |
| 399 | func Zero() |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 400 | return 0 |
Bram Moolenaar | 4857048 | 2017-10-30 21:48:41 +0100 | [diff] [blame] | 401 | endfunc |
| 402 | func Partial(x) |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 403 | return a:x |
Bram Moolenaar | 4857048 | 2017-10-30 21:48:41 +0100 | [diff] [blame] | 404 | endfunc |
| 405 | new |
| 406 | call setline(1, ['{', 'foo', 'foo', 'foo', '}']) |
| 407 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', '')) |
| 408 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', '0')) |
| 409 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', {-> 0})) |
| 410 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Zero'))) |
| 411 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Partial', [0]))) |
Bram Moolenaar | 4857048 | 2017-10-30 21:48:41 +0100 | [diff] [blame] | 412 | bw! |
| 413 | endfunc |
| 414 | |
Bram Moolenaar | a43ebe9 | 2018-07-14 17:25:01 +0200 | [diff] [blame] | 415 | func Test_searchpair_leak() |
| 416 | new |
| 417 | call setline(1, 'if one else another endif') |
| 418 | |
| 419 | " The error in the skip expression caused memory to leak. |
| 420 | call assert_fails("call searchpair('\\<if\\>', '\\<else\\>', '\\<endif\\>', '', '\"foo\" 2')", 'E15:') |
| 421 | |
| 422 | bwipe! |
| 423 | endfunc |
| 424 | |
Bram Moolenaar | 66727e1 | 2017-03-01 22:17:05 +0100 | [diff] [blame] | 425 | func Test_searchc() |
| 426 | " These commands used to cause memory overflow in searchc(). |
| 427 | new |
| 428 | norm ixx |
| 429 | exe "norm 0t\u93cf" |
| 430 | bw! |
| 431 | endfunc |
Bram Moolenaar | a693d05 | 2017-06-29 22:23:06 +0200 | [diff] [blame] | 432 | |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 433 | func Cmdline3_prep() |
| 434 | " need to disable char_avail, |
| 435 | " so that expansion of commandline works |
| 436 | call test_override("char_avail", 1) |
| 437 | new |
| 438 | call setline(1, [' 1', ' 2 the~e', ' 3 the theother']) |
| 439 | set incsearch |
| 440 | endfunc |
| 441 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 442 | func Incsearch_cleanup() |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 443 | set noincsearch |
| 444 | call test_override("char_avail", 0) |
| 445 | bw! |
| 446 | endfunc |
| 447 | |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 448 | func Test_search_cmdline3() |
| 449 | if !exists('+incsearch') |
| 450 | return |
| 451 | endif |
| 452 | call Cmdline3_prep() |
| 453 | 1 |
| 454 | " first match |
| 455 | call feedkeys("/the\<c-l>\<cr>", 'tx') |
| 456 | call assert_equal(' 2 the~e', getline('.')) |
| 457 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 458 | call Incsearch_cleanup() |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 459 | endfunc |
| 460 | |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 461 | func Test_search_cmdline3s() |
| 462 | if !exists('+incsearch') |
| 463 | return |
| 464 | endif |
| 465 | call Cmdline3_prep() |
| 466 | 1 |
| 467 | call feedkeys(":%s/the\<c-l>/xxx\<cr>", 'tx') |
| 468 | call assert_equal(' 2 xxxe', getline('.')) |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 469 | undo |
| 470 | call feedkeys(":%subs/the\<c-l>/xxx\<cr>", 'tx') |
| 471 | call assert_equal(' 2 xxxe', getline('.')) |
| 472 | undo |
| 473 | call feedkeys(":%substitute/the\<c-l>/xxx\<cr>", 'tx') |
| 474 | call assert_equal(' 2 xxxe', getline('.')) |
Bram Moolenaar | 167ae42 | 2018-08-14 21:32:21 +0200 | [diff] [blame] | 475 | undo |
| 476 | call feedkeys(":%smagic/the.e/xxx\<cr>", 'tx') |
| 477 | call assert_equal(' 2 xxx', getline('.')) |
| 478 | undo |
| 479 | call assert_fails(":%snomagic/the.e/xxx\<cr>", 'E486') |
| 480 | " |
| 481 | call feedkeys(":%snomagic/the\\.e/xxx\<cr>", 'tx') |
| 482 | call assert_equal(' 2 xxx', getline('.')) |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 483 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 484 | call Incsearch_cleanup() |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 485 | endfunc |
| 486 | |
| 487 | func Test_search_cmdline3g() |
| 488 | if !exists('+incsearch') |
| 489 | return |
| 490 | endif |
| 491 | call Cmdline3_prep() |
| 492 | 1 |
| 493 | call feedkeys(":g/the\<c-l>/d\<cr>", 'tx') |
| 494 | call assert_equal(' 3 the theother', getline(2)) |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 495 | undo |
| 496 | call feedkeys(":global/the\<c-l>/d\<cr>", 'tx') |
| 497 | call assert_equal(' 3 the theother', getline(2)) |
Bram Moolenaar | def7b1d | 2018-08-13 22:54:35 +0200 | [diff] [blame] | 498 | undo |
| 499 | call feedkeys(":g!/the\<c-l>/d\<cr>", 'tx') |
| 500 | call assert_equal(1, line('$')) |
| 501 | call assert_equal(' 2 the~e', getline(1)) |
| 502 | undo |
| 503 | call feedkeys(":global!/the\<c-l>/d\<cr>", 'tx') |
| 504 | call assert_equal(1, line('$')) |
| 505 | call assert_equal(' 2 the~e', getline(1)) |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 506 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 507 | call Incsearch_cleanup() |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 508 | endfunc |
| 509 | |
| 510 | func Test_search_cmdline3v() |
| 511 | if !exists('+incsearch') |
| 512 | return |
| 513 | endif |
| 514 | call Cmdline3_prep() |
| 515 | 1 |
| 516 | call feedkeys(":v/the\<c-l>/d\<cr>", 'tx') |
| 517 | call assert_equal(1, line('$')) |
| 518 | call assert_equal(' 2 the~e', getline(1)) |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 519 | undo |
| 520 | call feedkeys(":vglobal/the\<c-l>/d\<cr>", 'tx') |
| 521 | call assert_equal(1, line('$')) |
| 522 | call assert_equal(' 2 the~e', getline(1)) |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 523 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 524 | call Incsearch_cleanup() |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 525 | endfunc |
| 526 | |
Bram Moolenaar | da5116d | 2017-07-01 23:11:17 +0200 | [diff] [blame] | 527 | func Test_search_cmdline4() |
| 528 | if !exists('+incsearch') |
| 529 | return |
| 530 | endif |
| 531 | " need to disable char_avail, |
| 532 | " so that expansion of commandline works |
| 533 | call test_override("char_avail", 1) |
| 534 | new |
| 535 | call setline(1, [' 1 the first', ' 2 the second', ' 3 the third']) |
| 536 | set incsearch |
| 537 | $ |
| 538 | call feedkeys("?the\<c-g>\<cr>", 'tx') |
| 539 | call assert_equal(' 3 the third', getline('.')) |
| 540 | $ |
| 541 | call feedkeys("?the\<c-g>\<c-g>\<cr>", 'tx') |
| 542 | call assert_equal(' 1 the first', getline('.')) |
| 543 | $ |
| 544 | call feedkeys("?the\<c-g>\<c-g>\<c-g>\<cr>", 'tx') |
| 545 | call assert_equal(' 2 the second', getline('.')) |
| 546 | $ |
| 547 | call feedkeys("?the\<c-t>\<cr>", 'tx') |
| 548 | call assert_equal(' 1 the first', getline('.')) |
| 549 | $ |
| 550 | call feedkeys("?the\<c-t>\<c-t>\<cr>", 'tx') |
| 551 | call assert_equal(' 3 the third', getline('.')) |
| 552 | $ |
| 553 | call feedkeys("?the\<c-t>\<c-t>\<c-t>\<cr>", 'tx') |
| 554 | call assert_equal(' 2 the second', getline('.')) |
| 555 | " clean up |
| 556 | set noincsearch |
| 557 | call test_override("char_avail", 0) |
| 558 | bw! |
| 559 | endfunc |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 560 | |
Bram Moolenaar | f8e8c06 | 2017-10-22 14:44:17 +0200 | [diff] [blame] | 561 | func Test_search_cmdline5() |
| 562 | if !exists('+incsearch') |
| 563 | return |
| 564 | endif |
| 565 | " Do not call test_override("char_avail", 1) so that <C-g> and <C-t> work |
| 566 | " regardless char_avail. |
| 567 | new |
Bram Moolenaar | 69a5b86 | 2019-07-16 21:38:51 +0200 | [diff] [blame] | 568 | call setline(1, [' 1 the first', ' 2 the second', ' 3 the third', '']) |
Bram Moolenaar | f8e8c06 | 2017-10-22 14:44:17 +0200 | [diff] [blame] | 569 | set incsearch |
| 570 | 1 |
| 571 | call feedkeys("/the\<c-g>\<c-g>\<cr>", 'tx') |
| 572 | call assert_equal(' 3 the third', getline('.')) |
| 573 | $ |
| 574 | call feedkeys("?the\<c-t>\<c-t>\<c-t>\<cr>", 'tx') |
Bram Moolenaar | 69a5b86 | 2019-07-16 21:38:51 +0200 | [diff] [blame] | 575 | call assert_equal(' 1 the first', getline('.')) |
Bram Moolenaar | f8e8c06 | 2017-10-22 14:44:17 +0200 | [diff] [blame] | 576 | " clean up |
| 577 | set noincsearch |
| 578 | bw! |
| 579 | endfunc |
| 580 | |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 581 | func Test_search_cmdline6() |
| 582 | " Test that consecutive matches |
| 583 | " are caught by <c-g>/<c-t> |
| 584 | if !exists('+incsearch') |
| 585 | return |
| 586 | endif |
| 587 | " need to disable char_avail, |
| 588 | " so that expansion of commandline works |
| 589 | call test_override("char_avail", 1) |
| 590 | new |
| 591 | call setline(1, [' bbvimb', '']) |
| 592 | set incsearch |
| 593 | " first match |
| 594 | norm! gg0 |
| 595 | call feedkeys("/b\<cr>", 'tx') |
| 596 | call assert_equal([0,1,2,0], getpos('.')) |
| 597 | " second match |
| 598 | norm! gg0 |
| 599 | call feedkeys("/b\<c-g>\<cr>", 'tx') |
| 600 | call assert_equal([0,1,3,0], getpos('.')) |
| 601 | " third match |
| 602 | norm! gg0 |
| 603 | call feedkeys("/b\<c-g>\<c-g>\<cr>", 'tx') |
| 604 | call assert_equal([0,1,7,0], getpos('.')) |
| 605 | " first match again |
| 606 | norm! gg0 |
| 607 | call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx') |
| 608 | call assert_equal([0,1,2,0], getpos('.')) |
| 609 | set nowrapscan |
| 610 | " last match |
| 611 | norm! gg0 |
| 612 | call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx') |
| 613 | call assert_equal([0,1,7,0], getpos('.')) |
| 614 | " clean up |
| 615 | set wrapscan&vim |
| 616 | set noincsearch |
| 617 | call test_override("char_avail", 0) |
| 618 | bw! |
| 619 | endfunc |
| 620 | |
| 621 | func Test_search_cmdline7() |
| 622 | " Test that an pressing <c-g> in an empty command line |
| 623 | " does not move the cursor |
| 624 | if !exists('+incsearch') |
| 625 | return |
| 626 | endif |
| 627 | " need to disable char_avail, |
| 628 | " so that expansion of commandline works |
| 629 | call test_override("char_avail", 1) |
| 630 | new |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 631 | let @/ = 'b' |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 632 | call setline(1, [' bbvimb', '']) |
| 633 | set incsearch |
| 634 | " first match |
| 635 | norm! gg0 |
| 636 | " moves to next match of previous search pattern, just like /<cr> |
| 637 | call feedkeys("/\<c-g>\<cr>", 'tx') |
| 638 | call assert_equal([0,1,2,0], getpos('.')) |
| 639 | " moves to next match of previous search pattern, just like /<cr> |
| 640 | call feedkeys("/\<cr>", 'tx') |
| 641 | call assert_equal([0,1,3,0], getpos('.')) |
| 642 | " moves to next match of previous search pattern, just like /<cr> |
| 643 | call feedkeys("/\<c-t>\<cr>", 'tx') |
| 644 | call assert_equal([0,1,7,0], getpos('.')) |
Bram Moolenaar | d048009 | 2017-11-16 22:20:39 +0100 | [diff] [blame] | 645 | |
| 646 | " using an offset uses the last search pattern |
| 647 | call cursor(1, 1) |
| 648 | call setline(1, ['1 bbvimb', ' 2 bbvimb']) |
| 649 | let @/ = 'b' |
| 650 | call feedkeys("//e\<c-g>\<cr>", 'tx') |
| 651 | call assert_equal('1 bbvimb', getline('.')) |
| 652 | call assert_equal(4, col('.')) |
| 653 | |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 654 | set noincsearch |
| 655 | call test_override("char_avail", 0) |
| 656 | bw! |
| 657 | endfunc |
| 658 | |
| 659 | func Test_search_cmdline8() |
| 660 | " Highlighting is cleared in all windows |
| 661 | " since hls applies to all windows |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 662 | CheckOption incsearch |
| 663 | CheckFeature terminal |
| 664 | CheckNotGui |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 665 | if has("win32") |
| 666 | throw "Skipped: Bug with sending <ESC> to terminal window not fixed yet" |
| 667 | endif |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 668 | |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 669 | let h = winheight(0) |
| 670 | if h < 3 |
| 671 | return |
| 672 | endif |
| 673 | " Prepare buffer text |
| 674 | let lines = ['abb vim vim vi', 'vimvivim'] |
| 675 | call writefile(lines, 'Xsearch.txt') |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 676 | 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] | 677 | |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 678 | 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] | 679 | |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 680 | call term_sendkeys(buf, ":set incsearch hlsearch\<cr>") |
| 681 | call term_sendkeys(buf, ":14vsp\<cr>") |
| 682 | call term_sendkeys(buf, "/vim\<cr>") |
| 683 | call term_sendkeys(buf, "/b\<esc>") |
| 684 | call term_sendkeys(buf, "gg0") |
| 685 | call term_wait(buf, 500) |
| 686 | let screen_line = term_scrape(buf, 1) |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 687 | let [a0,a1,a2,a3] = [screen_line[3].attr, screen_line[4].attr, |
| 688 | \ screen_line[18].attr, screen_line[19].attr] |
| 689 | call assert_notequal(a0, a1) |
| 690 | call assert_notequal(a0, a3) |
| 691 | call assert_notequal(a1, a2) |
| 692 | call assert_equal(a0, a2) |
| 693 | call assert_equal(a1, a3) |
| 694 | " clean up |
| 695 | call delete('Xsearch.txt') |
| 696 | |
| 697 | bwipe! |
| 698 | endfunc |
| 699 | |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 700 | " Tests for regexp with various magic settings |
| 701 | func Test_search_regexp() |
| 702 | enew! |
| 703 | |
| 704 | put ='1 a aa abb abbccc' |
| 705 | exe 'normal! /a*b\{2}c\+/e' . "\<CR>" |
| 706 | call assert_equal([0, 2, 17, 0], getpos('.')) |
| 707 | |
| 708 | put ='2 d dd dee deefff' |
| 709 | exe 'normal! /\Md\*e\{2}f\+/e' . "\<CR>" |
| 710 | call assert_equal([0, 3, 17, 0], getpos('.')) |
| 711 | |
| 712 | set nomagic |
| 713 | put ='3 g gg ghh ghhiii' |
| 714 | exe 'normal! /g\*h\{2}i\+/e' . "\<CR>" |
| 715 | call assert_equal([0, 4, 17, 0], getpos('.')) |
| 716 | |
| 717 | put ='4 j jj jkk jkklll' |
| 718 | exe 'normal! /\mj*k\{2}l\+/e' . "\<CR>" |
| 719 | call assert_equal([0, 5, 17, 0], getpos('.')) |
| 720 | |
| 721 | put ='5 m mm mnn mnnooo' |
| 722 | exe 'normal! /\vm*n{2}o+/e' . "\<CR>" |
| 723 | call assert_equal([0, 6, 17, 0], getpos('.')) |
| 724 | |
| 725 | put ='6 x ^aa$ x' |
| 726 | exe 'normal! /\V^aa$' . "\<CR>" |
| 727 | call assert_equal([0, 7, 5, 0], getpos('.')) |
| 728 | |
| 729 | set magic |
| 730 | put ='7 (a)(b) abbaa' |
| 731 | exe 'normal! /\v(a)(b)\2\1\1/e' . "\<CR>" |
| 732 | call assert_equal([0, 8, 14, 0], getpos('.')) |
| 733 | |
| 734 | put ='8 axx [ab]xx' |
| 735 | exe 'normal! /\V[ab]\(\[xy]\)\1' . "\<CR>" |
| 736 | call assert_equal([0, 9, 7, 0], getpos('.')) |
| 737 | |
| 738 | set undolevels=100 |
| 739 | put ='9 foobar' |
| 740 | put ='' |
| 741 | exe "normal! a\<C-G>u\<Esc>" |
| 742 | normal G |
| 743 | exe 'normal! dv?bar?' . "\<CR>" |
| 744 | call assert_equal('9 foo', getline('.')) |
| 745 | call assert_equal([0, 10, 5, 0], getpos('.')) |
| 746 | call assert_equal(10, line('$')) |
| 747 | normal u |
| 748 | call assert_equal('9 foobar', getline('.')) |
| 749 | call assert_equal([0, 10, 6, 0], getpos('.')) |
| 750 | call assert_equal(11, line('$')) |
| 751 | |
| 752 | set undolevels& |
| 753 | enew! |
| 754 | endfunc |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 755 | |
| 756 | func Test_search_cmdline_incsearch_highlight() |
| 757 | if !exists('+incsearch') |
| 758 | return |
| 759 | endif |
| 760 | set incsearch hlsearch |
| 761 | " need to disable char_avail, |
| 762 | " so that expansion of commandline works |
| 763 | call test_override("char_avail", 1) |
| 764 | new |
| 765 | call setline(1, ['aaa 1 the first', ' 2 the second', ' 3 the third']) |
| 766 | |
| 767 | 1 |
| 768 | call feedkeys("/second\<cr>", 'tx') |
| 769 | call assert_equal('second', @/) |
| 770 | call assert_equal(' 2 the second', getline('.')) |
| 771 | |
| 772 | " Canceling search won't change @/ |
| 773 | 1 |
| 774 | let @/ = 'last pattern' |
| 775 | call feedkeys("/third\<C-c>", 'tx') |
| 776 | call assert_equal('last pattern', @/) |
| 777 | call feedkeys("/third\<Esc>", 'tx') |
| 778 | call assert_equal('last pattern', @/) |
| 779 | call feedkeys("/3\<bs>\<bs>", 'tx') |
| 780 | call assert_equal('last pattern', @/) |
| 781 | call feedkeys("/third\<c-g>\<c-t>\<Esc>", 'tx') |
| 782 | call assert_equal('last pattern', @/) |
| 783 | |
| 784 | " clean up |
| 785 | set noincsearch nohlsearch |
| 786 | bw! |
| 787 | endfunc |
| 788 | |
| 789 | func Test_search_cmdline_incsearch_highlight_attr() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 790 | CheckOption incsearch |
| 791 | CheckFeature terminal |
| 792 | CheckNotGui |
| 793 | |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 794 | let h = winheight(0) |
| 795 | if h < 3 |
| 796 | return |
| 797 | endif |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 798 | |
| 799 | " Prepare buffer text |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 800 | let lines = ['abb vim vim vi', 'vimvivim'] |
| 801 | call writefile(lines, 'Xsearch.txt') |
| 802 | let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3}) |
| 803 | |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 804 | 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] | 805 | " wait for vim to complete initialization |
| 806 | call term_wait(buf) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 807 | |
| 808 | " Get attr of normal(a0), incsearch(a1), hlsearch(a2) highlight |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 809 | call term_sendkeys(buf, ":set incsearch hlsearch\<cr>") |
| 810 | call term_sendkeys(buf, '/b') |
| 811 | call term_wait(buf, 200) |
| 812 | let screen_line1 = term_scrape(buf, 1) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 813 | call assert_true(len(screen_line1) > 2) |
| 814 | " a0: attr_normal |
| 815 | let a0 = screen_line1[0].attr |
| 816 | " a1: attr_incsearch |
| 817 | let a1 = screen_line1[1].attr |
| 818 | " a2: attr_hlsearch |
| 819 | let a2 = screen_line1[2].attr |
| 820 | call assert_notequal(a0, a1) |
| 821 | call assert_notequal(a0, a2) |
| 822 | call assert_notequal(a1, a2) |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 823 | call term_sendkeys(buf, "\<cr>gg0") |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 824 | |
| 825 | " Test incremental highlight search |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 826 | call term_sendkeys(buf, "/vim") |
| 827 | call term_wait(buf, 200) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 828 | " Buffer: |
| 829 | " abb vim vim vi |
| 830 | " vimvivim |
| 831 | " Search: /vim |
| 832 | let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a2,a2,a2,a0,a0,a0] |
| 833 | let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 834 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 835 | 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] | 836 | |
| 837 | " Test <C-g> |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 838 | call term_sendkeys(buf, "\<C-g>\<C-g>") |
| 839 | call term_wait(buf, 200) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 840 | let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] |
| 841 | let attr_line2 = [a1,a1,a1,a0,a0,a2,a2,a2] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 842 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 843 | 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] | 844 | |
| 845 | " Test <C-t> |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 846 | call term_sendkeys(buf, "\<C-t>") |
| 847 | call term_wait(buf, 200) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 848 | let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a1,a1,a1,a0,a0,a0] |
| 849 | let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 850 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 851 | 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] | 852 | |
| 853 | " Type Enter and a1(incsearch highlight) should become a2(hlsearch highlight) |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 854 | call term_sendkeys(buf, "\<cr>") |
| 855 | call term_wait(buf, 200) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 856 | let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] |
| 857 | let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 858 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 859 | 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] | 860 | |
| 861 | " Test nohlsearch. a2(hlsearch highlight) should become a0(normal highlight) |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 862 | call term_sendkeys(buf, ":1\<cr>") |
| 863 | call term_sendkeys(buf, ":set nohlsearch\<cr>") |
| 864 | call term_sendkeys(buf, "/vim") |
| 865 | call term_wait(buf, 200) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 866 | let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a0,a0,a0,a0,a0,a0] |
| 867 | let attr_line2 = [a0,a0,a0,a0,a0,a0,a0,a0] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 868 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 869 | 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] | 870 | call delete('Xsearch.txt') |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 871 | |
Bram Moolenaar | b94340c | 2017-11-02 16:16:31 +0100 | [diff] [blame] | 872 | call delete('Xsearch.txt') |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 873 | bwipe! |
| 874 | endfunc |
Bram Moolenaar | f45938c | 2017-11-02 15:59:57 +0100 | [diff] [blame] | 875 | |
Bram Moolenaar | 548e598 | 2018-12-26 21:45:00 +0100 | [diff] [blame] | 876 | func Test_incsearch_cmdline_modifier() |
| 877 | if !exists('+incsearch') |
| 878 | return |
| 879 | endif |
| 880 | call test_override("char_avail", 1) |
| 881 | new |
| 882 | call setline(1, ['foo']) |
| 883 | set incsearch |
| 884 | " Test that error E14 does not occur in parsing command modifier. |
| 885 | call feedkeys("V:tab", 'tx') |
| 886 | |
| 887 | call Incsearch_cleanup() |
| 888 | endfunc |
| 889 | |
Bram Moolenaar | 9d34d90 | 2018-04-27 22:18:12 +0200 | [diff] [blame] | 890 | func Test_incsearch_scrolling() |
| 891 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 892 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 9d34d90 | 2018-04-27 22:18:12 +0200 | [diff] [blame] | 893 | endif |
| 894 | call assert_equal(0, &scrolloff) |
| 895 | call writefile([ |
| 896 | \ 'let dots = repeat(".", 120)', |
| 897 | \ 'set incsearch cmdheight=2 scrolloff=0', |
| 898 | \ 'call setline(1, [dots, dots, dots, "", "target", dots, dots])', |
| 899 | \ 'normal gg', |
| 900 | \ 'redraw', |
| 901 | \ ], 'Xscript') |
| 902 | let buf = RunVimInTerminal('-S Xscript', {'rows': 9, 'cols': 70}) |
| 903 | " Need to send one key at a time to force a redraw |
| 904 | call term_sendkeys(buf, '/') |
| 905 | sleep 100m |
| 906 | call term_sendkeys(buf, 't') |
| 907 | sleep 100m |
| 908 | call term_sendkeys(buf, 'a') |
| 909 | sleep 100m |
| 910 | call term_sendkeys(buf, 'r') |
| 911 | sleep 100m |
| 912 | call term_sendkeys(buf, 'g') |
| 913 | call VerifyScreenDump(buf, 'Test_incsearch_scrolling_01', {}) |
| 914 | |
| 915 | call term_sendkeys(buf, "\<Esc>") |
| 916 | call StopVimInTerminal(buf) |
| 917 | call delete('Xscript') |
| 918 | endfunc |
| 919 | |
Bram Moolenaar | 4edfe2d | 2018-08-23 20:55:45 +0200 | [diff] [blame] | 920 | func Test_incsearch_search_dump() |
| 921 | if !exists('+incsearch') |
| 922 | return |
| 923 | endif |
| 924 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 925 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 4edfe2d | 2018-08-23 20:55:45 +0200 | [diff] [blame] | 926 | endif |
| 927 | call writefile([ |
| 928 | \ 'set incsearch hlsearch scrolloff=0', |
| 929 | \ 'for n in range(1, 8)', |
| 930 | \ ' call setline(n, "foo " . n)', |
| 931 | \ 'endfor', |
| 932 | \ '3', |
| 933 | \ ], 'Xis_search_script') |
| 934 | let buf = RunVimInTerminal('-S Xis_search_script', {'rows': 9, 'cols': 70}) |
| 935 | " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by |
| 936 | " the 'ambiwidth' check. |
| 937 | sleep 100m |
| 938 | |
| 939 | " Need to send one key at a time to force a redraw. |
| 940 | call term_sendkeys(buf, '/fo') |
Bram Moolenaar | 4edfe2d | 2018-08-23 20:55:45 +0200 | [diff] [blame] | 941 | call VerifyScreenDump(buf, 'Test_incsearch_search_01', {}) |
| 942 | call term_sendkeys(buf, "\<Esc>") |
| 943 | sleep 100m |
| 944 | |
| 945 | call term_sendkeys(buf, '/\v') |
Bram Moolenaar | 4edfe2d | 2018-08-23 20:55:45 +0200 | [diff] [blame] | 946 | call VerifyScreenDump(buf, 'Test_incsearch_search_02', {}) |
| 947 | call term_sendkeys(buf, "\<Esc>") |
| 948 | |
| 949 | call StopVimInTerminal(buf) |
| 950 | call delete('Xis_search_script') |
| 951 | endfunc |
| 952 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 953 | func Test_incsearch_substitute() |
| 954 | if !exists('+incsearch') |
| 955 | return |
| 956 | endif |
| 957 | call test_override("char_avail", 1) |
| 958 | new |
| 959 | set incsearch |
| 960 | for n in range(1, 10) |
| 961 | call setline(n, 'foo ' . n) |
| 962 | endfor |
| 963 | 4 |
| 964 | call feedkeys(":.,.+2s/foo\<BS>o\<BS>o/xxx\<cr>", 'tx') |
| 965 | call assert_equal('foo 3', getline(3)) |
| 966 | call assert_equal('xxx 4', getline(4)) |
| 967 | call assert_equal('xxx 5', getline(5)) |
| 968 | call assert_equal('xxx 6', getline(6)) |
| 969 | call assert_equal('foo 7', getline(7)) |
| 970 | |
| 971 | call Incsearch_cleanup() |
| 972 | endfunc |
| 973 | |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 974 | " Similar to Test_incsearch_substitute() but with a screendump halfway. |
| 975 | func Test_incsearch_substitute_dump() |
| 976 | if !exists('+incsearch') |
| 977 | return |
| 978 | endif |
| 979 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 980 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 981 | endif |
| 982 | call writefile([ |
| 983 | \ 'set incsearch hlsearch scrolloff=0', |
| 984 | \ 'for n in range(1, 10)', |
| 985 | \ ' call setline(n, "foo " . n)', |
| 986 | \ 'endfor', |
Bram Moolenaar | 2f6a346 | 2018-08-14 18:16:52 +0200 | [diff] [blame] | 987 | \ 'call setline(11, "bar 11")', |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 988 | \ '3', |
| 989 | \ ], 'Xis_subst_script') |
| 990 | let buf = RunVimInTerminal('-S Xis_subst_script', {'rows': 9, 'cols': 70}) |
| 991 | " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by |
| 992 | " the 'ambiwidth' check. |
| 993 | sleep 100m |
| 994 | |
| 995 | " Need to send one key at a time to force a redraw. |
Bram Moolenaar | c7f08b7 | 2018-08-12 17:39:14 +0200 | [diff] [blame] | 996 | " Select three lines at the cursor with typed pattern. |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 997 | call term_sendkeys(buf, ':.,.+2s/') |
| 998 | sleep 100m |
| 999 | call term_sendkeys(buf, 'f') |
| 1000 | sleep 100m |
| 1001 | call term_sendkeys(buf, 'o') |
| 1002 | sleep 100m |
| 1003 | call term_sendkeys(buf, 'o') |
| 1004 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_01', {}) |
Bram Moolenaar | c7f08b7 | 2018-08-12 17:39:14 +0200 | [diff] [blame] | 1005 | call term_sendkeys(buf, "\<Esc>") |
| 1006 | |
| 1007 | " Select three lines at the cursor using previous pattern. |
| 1008 | call term_sendkeys(buf, "/foo\<CR>") |
| 1009 | sleep 100m |
| 1010 | call term_sendkeys(buf, ':.,.+2s//') |
Bram Moolenaar | c7f08b7 | 2018-08-12 17:39:14 +0200 | [diff] [blame] | 1011 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_02', {}) |
| 1012 | |
| 1013 | " Deleting last slash should remove the match. |
| 1014 | call term_sendkeys(buf, "\<BS>") |
Bram Moolenaar | c7f08b7 | 2018-08-12 17:39:14 +0200 | [diff] [blame] | 1015 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_03', {}) |
Bram Moolenaar | 60d0871 | 2018-08-12 21:53:15 +0200 | [diff] [blame] | 1016 | call term_sendkeys(buf, "\<Esc>") |
| 1017 | |
| 1018 | " Reverse range is accepted |
| 1019 | call term_sendkeys(buf, ':5,2s/foo') |
Bram Moolenaar | 60d0871 | 2018-08-12 21:53:15 +0200 | [diff] [blame] | 1020 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_04', {}) |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 1021 | call term_sendkeys(buf, "\<Esc>") |
Bram Moolenaar | 2b926fc | 2018-08-13 11:07:57 +0200 | [diff] [blame] | 1022 | |
| 1023 | " White space after the command is skipped |
| 1024 | call term_sendkeys(buf, ':2,3sub /fo') |
Bram Moolenaar | 2b926fc | 2018-08-13 11:07:57 +0200 | [diff] [blame] | 1025 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_05', {}) |
| 1026 | call term_sendkeys(buf, "\<Esc>") |
| 1027 | |
Bram Moolenaar | 33c4dbb | 2018-08-14 16:06:16 +0200 | [diff] [blame] | 1028 | " Command modifiers are skipped |
| 1029 | 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] | 1030 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_06', {}) |
| 1031 | call term_sendkeys(buf, "\<Esc>") |
| 1032 | |
Bram Moolenaar | 2f6a346 | 2018-08-14 18:16:52 +0200 | [diff] [blame] | 1033 | " Cursorline highlighting at match |
| 1034 | call term_sendkeys(buf, ":set cursorline\<CR>") |
| 1035 | call term_sendkeys(buf, 'G9G') |
| 1036 | call term_sendkeys(buf, ':9,11s/bar') |
Bram Moolenaar | 2f6a346 | 2018-08-14 18:16:52 +0200 | [diff] [blame] | 1037 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_07', {}) |
| 1038 | call term_sendkeys(buf, "\<Esc>") |
| 1039 | |
| 1040 | " Cursorline highlighting at cursor when no match |
| 1041 | call term_sendkeys(buf, ':9,10s/bar') |
Bram Moolenaar | 2f6a346 | 2018-08-14 18:16:52 +0200 | [diff] [blame] | 1042 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_08', {}) |
| 1043 | call term_sendkeys(buf, "\<Esc>") |
| 1044 | |
Bram Moolenaar | 8b0d5ce | 2018-08-22 23:05:44 +0200 | [diff] [blame] | 1045 | " Only \v handled as empty pattern, does not move cursor |
| 1046 | call term_sendkeys(buf, '3G4G') |
| 1047 | call term_sendkeys(buf, ":nohlsearch\<CR>") |
| 1048 | call term_sendkeys(buf, ':6,7s/\v') |
Bram Moolenaar | 8b0d5ce | 2018-08-22 23:05:44 +0200 | [diff] [blame] | 1049 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_09', {}) |
| 1050 | call term_sendkeys(buf, "\<Esc>") |
| 1051 | |
Bram Moolenaar | f13daa4 | 2018-08-31 22:09:54 +0200 | [diff] [blame] | 1052 | call term_sendkeys(buf, ":set nocursorline\<CR>") |
| 1053 | |
| 1054 | " All matches are highlighted for 'hlsearch' after the incsearch canceled |
| 1055 | call term_sendkeys(buf, "1G*") |
| 1056 | call term_sendkeys(buf, ":2,5s/foo") |
| 1057 | sleep 100m |
| 1058 | call term_sendkeys(buf, "\<Esc>") |
| 1059 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_10', {}) |
| 1060 | |
Bram Moolenaar | 65985ac | 2018-09-16 17:08:04 +0200 | [diff] [blame] | 1061 | call term_sendkeys(buf, ":split\<CR>") |
| 1062 | call term_sendkeys(buf, ":let @/ = 'xyz'\<CR>") |
| 1063 | call term_sendkeys(buf, ":%s/.") |
| 1064 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_11', {}) |
| 1065 | call term_sendkeys(buf, "\<BS>") |
| 1066 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_12', {}) |
| 1067 | call term_sendkeys(buf, "\<Esc>") |
| 1068 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_13', {}) |
Bram Moolenaar | c672525 | 2019-11-23 21:56:46 +0100 | [diff] [blame] | 1069 | call term_sendkeys(buf, ":%bwipe!\<CR>") |
| 1070 | call term_sendkeys(buf, ":only!\<CR>") |
| 1071 | |
| 1072 | " get :'<,'>s command in history |
| 1073 | call term_sendkeys(buf, ":set cmdheight=2\<CR>") |
| 1074 | call term_sendkeys(buf, "aasdfasdf\<Esc>") |
| 1075 | call term_sendkeys(buf, "V:s/a/b/g\<CR>") |
| 1076 | " Using '<,'> does not give E20 |
| 1077 | call term_sendkeys(buf, ":new\<CR>") |
| 1078 | call term_sendkeys(buf, "aasdfasdf\<Esc>") |
| 1079 | call term_sendkeys(buf, ":\<Up>\<Up>") |
| 1080 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_14', {}) |
| 1081 | call term_sendkeys(buf, "<Esc>") |
Bram Moolenaar | 65985ac | 2018-09-16 17:08:04 +0200 | [diff] [blame] | 1082 | |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 1083 | call StopVimInTerminal(buf) |
| 1084 | call delete('Xis_subst_script') |
| 1085 | endfunc |
| 1086 | |
Bram Moolenaar | 4a7d2d3 | 2019-02-21 16:25:50 +0100 | [diff] [blame] | 1087 | func Test_incsearch_with_change() |
| 1088 | if !has('timers') || !exists('+incsearch') || !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1089 | 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] | 1090 | endif |
| 1091 | |
| 1092 | call writefile([ |
| 1093 | \ 'set incsearch hlsearch scrolloff=0', |
| 1094 | \ 'call setline(1, ["one", "two ------ X", "three"])', |
| 1095 | \ 'call timer_start(200, { _ -> setline(2, "x")})', |
| 1096 | \ ], 'Xis_change_script') |
| 1097 | let buf = RunVimInTerminal('-S Xis_change_script', {'rows': 9, 'cols': 70}) |
| 1098 | " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by |
| 1099 | " the 'ambiwidth' check. |
Bram Moolenaar | e86ecbd | 2019-02-21 17:48:59 +0100 | [diff] [blame] | 1100 | sleep 300m |
Bram Moolenaar | 4a7d2d3 | 2019-02-21 16:25:50 +0100 | [diff] [blame] | 1101 | |
| 1102 | " Highlight X, it will be deleted by the timer callback. |
| 1103 | call term_sendkeys(buf, ':%s/X') |
| 1104 | call VerifyScreenDump(buf, 'Test_incsearch_change_01', {}) |
| 1105 | call term_sendkeys(buf, "\<Esc>") |
| 1106 | |
| 1107 | call StopVimInTerminal(buf) |
| 1108 | call delete('Xis_change_script') |
| 1109 | endfunc |
| 1110 | |
Bram Moolenaar | 81f5653 | 2018-08-18 16:19:42 +0200 | [diff] [blame] | 1111 | " Similar to Test_incsearch_substitute_dump() for :sort |
Bram Moolenaar | 4edfe2d | 2018-08-23 20:55:45 +0200 | [diff] [blame] | 1112 | func Test_incsearch_sort_dump() |
Bram Moolenaar | 81f5653 | 2018-08-18 16:19:42 +0200 | [diff] [blame] | 1113 | if !exists('+incsearch') |
| 1114 | return |
| 1115 | endif |
| 1116 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1117 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 81f5653 | 2018-08-18 16:19:42 +0200 | [diff] [blame] | 1118 | endif |
| 1119 | call writefile([ |
| 1120 | \ 'set incsearch hlsearch scrolloff=0', |
| 1121 | \ 'call setline(1, ["another one 2", "that one 3", "the one 1"])', |
| 1122 | \ ], 'Xis_sort_script') |
| 1123 | let buf = RunVimInTerminal('-S Xis_sort_script', {'rows': 9, 'cols': 70}) |
| 1124 | " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by |
| 1125 | " the 'ambiwidth' check. |
| 1126 | sleep 100m |
| 1127 | |
| 1128 | " Need to send one key at a time to force a redraw. |
| 1129 | call term_sendkeys(buf, ':sort ni u /on') |
Bram Moolenaar | 81f5653 | 2018-08-18 16:19:42 +0200 | [diff] [blame] | 1130 | call VerifyScreenDump(buf, 'Test_incsearch_sort_01', {}) |
| 1131 | call term_sendkeys(buf, "\<Esc>") |
| 1132 | |
| 1133 | call StopVimInTerminal(buf) |
| 1134 | call delete('Xis_sort_script') |
| 1135 | endfunc |
| 1136 | |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1137 | " Similar to Test_incsearch_substitute_dump() for :vimgrep famiry |
| 1138 | func Test_incsearch_vimgrep_dump() |
| 1139 | if !exists('+incsearch') |
| 1140 | return |
| 1141 | endif |
| 1142 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1143 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1144 | endif |
| 1145 | call writefile([ |
| 1146 | \ 'set incsearch hlsearch scrolloff=0', |
| 1147 | \ 'call setline(1, ["another one 2", "that one 3", "the one 1"])', |
| 1148 | \ ], 'Xis_vimgrep_script') |
| 1149 | let buf = RunVimInTerminal('-S Xis_vimgrep_script', {'rows': 9, 'cols': 70}) |
| 1150 | " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by |
| 1151 | " the 'ambiwidth' check. |
| 1152 | sleep 100m |
| 1153 | |
| 1154 | " Need to send one key at a time to force a redraw. |
| 1155 | call term_sendkeys(buf, ':vimgrep on') |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1156 | call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_01', {}) |
| 1157 | call term_sendkeys(buf, "\<Esc>") |
| 1158 | |
| 1159 | call term_sendkeys(buf, ':vimg /on/ *.txt') |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1160 | call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_02', {}) |
| 1161 | call term_sendkeys(buf, "\<Esc>") |
| 1162 | |
| 1163 | call term_sendkeys(buf, ':vimgrepadd "\<on') |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1164 | call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_03', {}) |
| 1165 | call term_sendkeys(buf, "\<Esc>") |
| 1166 | |
| 1167 | call term_sendkeys(buf, ':lv "tha') |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1168 | call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_04', {}) |
| 1169 | call term_sendkeys(buf, "\<Esc>") |
| 1170 | |
| 1171 | call term_sendkeys(buf, ':lvimgrepa "the" **/*.txt') |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1172 | call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_05', {}) |
| 1173 | call term_sendkeys(buf, "\<Esc>") |
| 1174 | |
| 1175 | call StopVimInTerminal(buf) |
| 1176 | call delete('Xis_vimgrep_script') |
| 1177 | endfunc |
| 1178 | |
Bram Moolenaar | 198cb66 | 2018-09-06 21:44:17 +0200 | [diff] [blame] | 1179 | func Test_keep_last_search_pattern() |
| 1180 | if !exists('+incsearch') |
| 1181 | return |
| 1182 | endif |
| 1183 | new |
| 1184 | call setline(1, ['foo', 'foo', 'foo']) |
| 1185 | set incsearch |
| 1186 | call test_override("char_avail", 1) |
| 1187 | let @/ = 'bar' |
| 1188 | call feedkeys(":/foo/s//\<Esc>", 'ntx') |
| 1189 | call assert_equal('bar', @/) |
| 1190 | |
Bram Moolenaar | 50eb16c | 2018-09-15 15:42:40 +0200 | [diff] [blame] | 1191 | " no error message if pattern not found |
| 1192 | call feedkeys(":/xyz/s//\<Esc>", 'ntx') |
| 1193 | call assert_equal('bar', @/) |
| 1194 | |
Bram Moolenaar | 198cb66 | 2018-09-06 21:44:17 +0200 | [diff] [blame] | 1195 | bwipe! |
| 1196 | call test_override("ALL", 0) |
| 1197 | set noincsearch |
| 1198 | endfunc |
| 1199 | |
Bram Moolenaar | 99f043a | 2018-09-09 15:54:14 +0200 | [diff] [blame] | 1200 | func Test_word_under_cursor_after_match() |
| 1201 | if !exists('+incsearch') |
| 1202 | return |
| 1203 | endif |
| 1204 | new |
| 1205 | call setline(1, 'foo bar') |
| 1206 | set incsearch |
| 1207 | call test_override("char_avail", 1) |
| 1208 | try |
| 1209 | call feedkeys("/foo\<C-R>\<C-W>\<CR>", 'ntx') |
| 1210 | catch /E486:/ |
| 1211 | endtry |
| 1212 | call assert_equal('foobar', @/) |
| 1213 | |
| 1214 | bwipe! |
| 1215 | call test_override("ALL", 0) |
| 1216 | set noincsearch |
| 1217 | endfunc |
| 1218 | |
| 1219 | func Test_subst_word_under_cursor() |
| 1220 | if !exists('+incsearch') |
| 1221 | return |
| 1222 | endif |
| 1223 | new |
| 1224 | call setline(1, ['int SomeLongName;', 'for (xxx = 1; xxx < len; ++xxx)']) |
| 1225 | set incsearch |
| 1226 | call test_override("char_avail", 1) |
| 1227 | call feedkeys("/LongName\<CR>", 'ntx') |
| 1228 | call feedkeys(":%s/xxx/\<C-R>\<C-W>/g\<CR>", 'ntx') |
| 1229 | call assert_equal('for (SomeLongName = 1; SomeLongName < len; ++SomeLongName)', getline(2)) |
| 1230 | |
| 1231 | bwipe! |
| 1232 | call test_override("ALL", 0) |
| 1233 | set noincsearch |
| 1234 | endfunc |
| 1235 | |
Bram Moolenaar | f45938c | 2017-11-02 15:59:57 +0100 | [diff] [blame] | 1236 | func Test_search_undefined_behaviour() |
| 1237 | if !has("terminal") |
| 1238 | return |
| 1239 | endif |
| 1240 | let h = winheight(0) |
| 1241 | if h < 3 |
| 1242 | return |
| 1243 | endif |
| 1244 | " did cause an undefined left shift |
| 1245 | let g:buf = term_start([GetVimProg(), '--clean', '-e', '-s', '-c', 'call search(getline("."))', 'samples/test000'], {'term_rows': 3}) |
| 1246 | call assert_equal([''], getline(1, '$')) |
| 1247 | call term_sendkeys(g:buf, ":qa!\<cr>") |
| 1248 | bwipe! |
| 1249 | endfunc |
Bram Moolenaar | 2973daa | 2017-11-02 23:15:40 +0100 | [diff] [blame] | 1250 | |
| 1251 | func Test_search_undefined_behaviour2() |
| 1252 | call search("\%UC0000000") |
| 1253 | endfunc |
Bram Moolenaar | fb094e1 | 2017-11-05 20:59:28 +0100 | [diff] [blame] | 1254 | |
| 1255 | " Test for search('multi-byte char', 'bce') |
| 1256 | func Test_search_multibyte() |
Bram Moolenaar | fb094e1 | 2017-11-05 20:59:28 +0100 | [diff] [blame] | 1257 | let save_enc = &encoding |
| 1258 | set encoding=utf8 |
| 1259 | enew! |
| 1260 | call append('$', 'A') |
| 1261 | call cursor(2, 1) |
| 1262 | call assert_equal(2, search('A', 'bce', line('.'))) |
| 1263 | enew! |
| 1264 | let &encoding = save_enc |
| 1265 | endfunc |
Bram Moolenaar | 890dd05 | 2017-12-16 19:59:37 +0100 | [diff] [blame] | 1266 | |
| 1267 | " This was causing E874. Also causes an invalid read? |
| 1268 | func Test_look_behind() |
| 1269 | new |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 1270 | call setline(1, '0\|\&\n\@<=') |
Bram Moolenaar | 890dd05 | 2017-12-16 19:59:37 +0100 | [diff] [blame] | 1271 | call search(getline(".")) |
| 1272 | bwipe! |
| 1273 | endfunc |
Bram Moolenaar | 8ada6aa | 2017-12-19 21:23:21 +0100 | [diff] [blame] | 1274 | |
| 1275 | func Test_search_sentence() |
| 1276 | new |
| 1277 | " this used to cause a crash |
Bram Moolenaar | 1bd999f | 2017-12-19 22:25:40 +0100 | [diff] [blame] | 1278 | call assert_fails("/\\%')", 'E486') |
Bram Moolenaar | 8ada6aa | 2017-12-19 21:23:21 +0100 | [diff] [blame] | 1279 | call assert_fails("/", 'E486') |
Bram Moolenaar | 1bd999f | 2017-12-19 22:25:40 +0100 | [diff] [blame] | 1280 | /\%'( |
| 1281 | / |
Bram Moolenaar | 8ada6aa | 2017-12-19 21:23:21 +0100 | [diff] [blame] | 1282 | endfunc |
Bram Moolenaar | 2fb8f68 | 2018-12-01 13:14:45 +0100 | [diff] [blame] | 1283 | |
| 1284 | " Test that there is no crash when there is a last search pattern but no last |
| 1285 | " substitute pattern. |
| 1286 | func Test_no_last_substitute_pat() |
| 1287 | " Use viminfo to set the last search pattern to a string and make the last |
| 1288 | " substitute pattern the most recent used and make it empty (NULL). |
| 1289 | call writefile(['~MSle0/bar', '~MSle0~&'], 'Xviminfo') |
| 1290 | rviminfo! Xviminfo |
| 1291 | call assert_fails('normal n', 'E35:') |
| 1292 | |
| 1293 | call delete('Xviminfo') |
| 1294 | endfunc |
Bram Moolenaar | 5f5e203 | 2018-12-14 15:47:03 +0100 | [diff] [blame] | 1295 | |
| 1296 | func Test_search_Ctrl_L_combining() |
| 1297 | " Make sure, that Ctrl-L works correctly with combining characters. |
| 1298 | " It uses an artificial example of an 'a' with 4 combining chars: |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 1299 | " 'a' U+0061 Dec:97 LATIN SMALL LETTER A a /\%u61\Z "\u0061" |
Bram Moolenaar | 5f5e203 | 2018-12-14 15:47:03 +0100 | [diff] [blame] | 1300 | " ' ̀' U+0300 Dec:768 COMBINING GRAVE ACCENT ̀ /\%u300\Z "\u0300" |
| 1301 | " ' ́' U+0301 Dec:769 COMBINING ACUTE ACCENT ́ /\%u301\Z "\u0301" |
| 1302 | " ' ̇' U+0307 Dec:775 COMBINING DOT ABOVE ̇ /\%u307\Z "\u0307" |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 1303 | " ' ̣' U+0323 Dec:803 COMBINING DOT BELOW ̣ /\%u323 "\u0323" |
Bram Moolenaar | 5f5e203 | 2018-12-14 15:47:03 +0100 | [diff] [blame] | 1304 | " Those should also appear on the commandline |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 1305 | if !exists('+incsearch') |
Bram Moolenaar | 5f5e203 | 2018-12-14 15:47:03 +0100 | [diff] [blame] | 1306 | return |
| 1307 | endif |
| 1308 | call Cmdline3_prep() |
| 1309 | 1 |
| 1310 | let bufcontent = ['', 'Miạ̀́̇m'] |
| 1311 | call append('$', bufcontent) |
| 1312 | call feedkeys("/Mi\<c-l>\<c-l>\<cr>", 'tx') |
| 1313 | call assert_equal(5, line('.')) |
| 1314 | call assert_equal(bufcontent[1], @/) |
| 1315 | call Incsearch_cleanup() |
| 1316 | endfunc |
Bram Moolenaar | 527a2d8 | 2019-02-21 22:28:51 +0100 | [diff] [blame] | 1317 | |
Bram Moolenaar | ab350f8 | 2019-02-28 06:25:00 +0100 | [diff] [blame] | 1318 | func Test_large_hex_chars1() |
Bram Moolenaar | 527a2d8 | 2019-02-21 22:28:51 +0100 | [diff] [blame] | 1319 | " This used to cause a crash, the character becomes an NFA state. |
| 1320 | try |
| 1321 | /\%Ufffffc23 |
| 1322 | catch |
| 1323 | call assert_match('E678:', v:exception) |
| 1324 | endtry |
Bram Moolenaar | ab350f8 | 2019-02-28 06:25:00 +0100 | [diff] [blame] | 1325 | try |
| 1326 | set re=1 |
| 1327 | /\%Ufffffc23 |
| 1328 | catch |
| 1329 | call assert_match('E678:', v:exception) |
| 1330 | endtry |
| 1331 | set re& |
| 1332 | endfunc |
| 1333 | |
| 1334 | func Test_large_hex_chars2() |
| 1335 | " This used to cause a crash, the character becomes an NFA state. |
| 1336 | try |
| 1337 | /[\Ufffffc1f] |
| 1338 | catch |
| 1339 | call assert_match('E486:', v:exception) |
| 1340 | endtry |
| 1341 | try |
| 1342 | set re=1 |
| 1343 | /[\Ufffffc1f] |
| 1344 | catch |
| 1345 | call assert_match('E486:', v:exception) |
| 1346 | endtry |
| 1347 | set re& |
Bram Moolenaar | 527a2d8 | 2019-02-21 22:28:51 +0100 | [diff] [blame] | 1348 | endfunc |
Bram Moolenaar | cd62512 | 2019-02-22 17:29:43 +0100 | [diff] [blame] | 1349 | |
| 1350 | func Test_one_error_msg() |
| 1351 | " This was also giving an internal error |
| 1352 | call assert_fails('call search(" \\((\\v[[=P=]]){185}+ ")', 'E871:') |
| 1353 | endfunc |
Bram Moolenaar | 730f48f | 2019-04-11 13:45:57 +0200 | [diff] [blame] | 1354 | |
| 1355 | func Test_incsearch_add_char_under_cursor() |
| 1356 | if !exists('+incsearch') |
| 1357 | return |
| 1358 | endif |
| 1359 | set incsearch |
| 1360 | new |
| 1361 | call setline(1, ['find match', 'anything']) |
| 1362 | 1 |
| 1363 | call test_override('char_avail', 1) |
| 1364 | call feedkeys("fc/m\<C-L>\<C-L>\<C-L>\<C-L>\<C-L>\<CR>", 'tx') |
| 1365 | call assert_equal('match', @/) |
| 1366 | call test_override('char_avail', 0) |
| 1367 | |
| 1368 | set incsearch& |
| 1369 | bwipe! |
| 1370 | endfunc |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 1371 | |
| 1372 | " Test for the search() function with match at the cursor position |
| 1373 | func Test_search_match_at_curpos() |
| 1374 | new |
| 1375 | call append(0, ['foobar', '', 'one two', '']) |
| 1376 | |
| 1377 | normal gg |
| 1378 | |
Bram Moolenaar | 196b466 | 2019-09-06 21:34:30 +0200 | [diff] [blame] | 1379 | eval 'foobar'->search('c') |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 1380 | call assert_equal([1, 1], [line('.'), col('.')]) |
| 1381 | |
| 1382 | normal j |
| 1383 | call search('^$', 'c') |
| 1384 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1385 | |
| 1386 | call search('^$', 'bc') |
| 1387 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1388 | |
| 1389 | exe "normal /two\<CR>" |
| 1390 | call search('.', 'c') |
| 1391 | call assert_equal([3, 5], [line('.'), col('.')]) |
| 1392 | |
| 1393 | close! |
| 1394 | endfunc |
Bram Moolenaar | db294ad | 2019-06-06 12:49:29 +0200 | [diff] [blame] | 1395 | |
| 1396 | func Test_search_display_pattern() |
| 1397 | new |
| 1398 | call setline(1, ['foo', 'bar', 'foobar']) |
| 1399 | |
| 1400 | call cursor(1, 1) |
| 1401 | let @/ = 'foo' |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1402 | let pat = @/->escape('()*?'. '\s\+') |
Bram Moolenaar | db294ad | 2019-06-06 12:49:29 +0200 | [diff] [blame] | 1403 | let g:a = execute(':unsilent :norm! n') |
| 1404 | call assert_match(pat, g:a) |
| 1405 | |
| 1406 | " right-left |
| 1407 | if exists("+rightleft") |
| 1408 | set rl |
| 1409 | call cursor(1, 1) |
| 1410 | let @/ = 'foo' |
| 1411 | let pat = 'oof/\s\+' |
| 1412 | let g:a = execute(':unsilent :norm! n') |
| 1413 | call assert_match(pat, g:a) |
| 1414 | set norl |
| 1415 | endif |
| 1416 | endfunc |
Bram Moolenaar | 196b466 | 2019-09-06 21:34:30 +0200 | [diff] [blame] | 1417 | |
| 1418 | func Test_searchdecl() |
| 1419 | let lines =<< trim END |
| 1420 | int global; |
| 1421 | |
| 1422 | func() |
| 1423 | { |
| 1424 | int global; |
| 1425 | if (cond) { |
| 1426 | int local; |
| 1427 | } |
| 1428 | int local; |
| 1429 | // comment |
| 1430 | } |
| 1431 | END |
| 1432 | new |
| 1433 | call setline(1, lines) |
| 1434 | 10 |
| 1435 | call assert_equal(0, searchdecl('local', 0, 0)) |
| 1436 | call assert_equal(7, getcurpos()[1]) |
| 1437 | |
| 1438 | 10 |
| 1439 | call assert_equal(0, 'local'->searchdecl(0, 1)) |
| 1440 | call assert_equal(9, getcurpos()[1]) |
| 1441 | |
| 1442 | 10 |
| 1443 | call assert_equal(0, searchdecl('global')) |
| 1444 | call assert_equal(5, getcurpos()[1]) |
| 1445 | |
| 1446 | 10 |
| 1447 | call assert_equal(0, searchdecl('global', 1)) |
| 1448 | call assert_equal(1, getcurpos()[1]) |
| 1449 | |
| 1450 | bwipe! |
| 1451 | endfunc |
Bram Moolenaar | 98a336d | 2020-01-20 20:22:30 +0100 | [diff] [blame] | 1452 | |
| 1453 | func Test_search_special() |
Bram Moolenaar | fe4bbac | 2020-01-20 21:12:20 +0100 | [diff] [blame] | 1454 | " this was causing illegal memory access and an endless loop |
| 1455 | set t_PE= |
Bram Moolenaar | 98a336d | 2020-01-20 20:22:30 +0100 | [diff] [blame] | 1456 | exe "norm /\x80PS" |
| 1457 | endfunc |
Bram Moolenaar | 07ada5f | 2020-02-05 20:38:22 +0100 | [diff] [blame] | 1458 | |
| 1459 | " Test for command failures when the last search pattern is not set. |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 1460 | " Need to run this in a new vim instance where last search pattern is not set. |
Bram Moolenaar | 07ada5f | 2020-02-05 20:38:22 +0100 | [diff] [blame] | 1461 | func Test_search_with_no_last_pat() |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 1462 | let lines =<< trim [SCRIPT] |
| 1463 | call assert_fails("normal i\<C-R>/\e", 'E35:') |
| 1464 | call assert_fails("exe '/'", 'E35:') |
| 1465 | call assert_fails("exe '?'", 'E35:') |
| 1466 | call assert_fails("/", 'E35:') |
| 1467 | call assert_fails("?", 'E35:') |
| 1468 | call assert_fails("normal n", 'E35:') |
| 1469 | call assert_fails("normal N", 'E35:') |
| 1470 | call assert_fails("normal gn", 'E35:') |
| 1471 | call assert_fails("normal gN", 'E35:') |
| 1472 | call assert_fails("normal cgn", 'E35:') |
| 1473 | call assert_fails("normal cgN", 'E35:') |
| 1474 | let p = [] |
| 1475 | let p = @/ |
| 1476 | call assert_equal('', p) |
| 1477 | call assert_fails("normal :\<C-R>/", 'E35:') |
| 1478 | call assert_fails("//p", 'E35:') |
| 1479 | call assert_fails(";//p", 'E35:') |
| 1480 | call assert_fails("??p", 'E35:') |
| 1481 | call assert_fails(";??p", 'E35:') |
| 1482 | call assert_fails('g//p', 'E476:') |
| 1483 | call assert_fails('v//p', 'E476:') |
| 1484 | call writefile(v:errors, 'Xresult') |
| 1485 | qall! |
| 1486 | [SCRIPT] |
| 1487 | call writefile(lines, 'Xscript') |
| 1488 | |
| 1489 | if RunVim([], [], '--clean -S Xscript') |
| 1490 | call assert_equal([], readfile('Xresult')) |
| 1491 | endif |
| 1492 | call delete('Xscript') |
| 1493 | call delete('Xresult') |
Bram Moolenaar | 07ada5f | 2020-02-05 20:38:22 +0100 | [diff] [blame] | 1494 | endfunc |
| 1495 | |
| 1496 | " Test for using tilde (~) atom in search. This should use the last used |
| 1497 | " substitute pattern |
| 1498 | func Test_search_tilde_pat() |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 1499 | let lines =<< trim [SCRIPT] |
| 1500 | set regexpengine=1 |
| 1501 | call assert_fails('exe "normal /~\<CR>"', 'E33:') |
| 1502 | call assert_fails('exe "normal ?~\<CR>"', 'E33:') |
| 1503 | set regexpengine=2 |
| 1504 | call assert_fails('exe "normal /~\<CR>"', 'E383:') |
| 1505 | call assert_fails('exe "normal ?~\<CR>"', 'E383:') |
| 1506 | set regexpengine& |
| 1507 | call writefile(v:errors, 'Xresult') |
| 1508 | qall! |
| 1509 | [SCRIPT] |
| 1510 | call writefile(lines, 'Xscript') |
| 1511 | if RunVim([], [], '--clean -S Xscript') |
| 1512 | call assert_equal([], readfile('Xresult')) |
| 1513 | endif |
| 1514 | call delete('Xscript') |
| 1515 | call delete('Xresult') |
Bram Moolenaar | 07ada5f | 2020-02-05 20:38:22 +0100 | [diff] [blame] | 1516 | endfunc |
| 1517 | |
| 1518 | " vim: shiftwidth=2 sts=2 expandtab |