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() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 8 | CheckOption incsearch |
| 9 | |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 10 | " need to disable char_avail, |
| 11 | " so that expansion of commandline works |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 12 | call test_override("char_avail", 1) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 13 | new |
| 14 | call setline(1, [' 1', ' 2 these', ' 3 the', ' 4 their', ' 5 there', ' 6 their', ' 7 the', ' 8 them', ' 9 these', ' 10 foobar']) |
| 15 | " Test 1 |
| 16 | " CTRL-N / CTRL-P skips through the previous search history |
| 17 | set noincsearch |
| 18 | :1 |
| 19 | call feedkeys("/foobar\<cr>", 'tx') |
Bram Moolenaar | 8832a34 | 2020-04-11 18:36:38 +0200 | [diff] [blame] | 20 | call feedkeys("/the\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 21 | call assert_equal('the', @/) |
Bram Moolenaar | 8832a34 | 2020-04-11 18:36:38 +0200 | [diff] [blame] | 22 | call feedkeys("/thes\<C-P>\<C-P>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 23 | call assert_equal('foobar', @/) |
| 24 | |
| 25 | " Test 2 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 26 | " Ctrl-G goes from one match to the next |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 27 | " until the end of the buffer |
| 28 | set incsearch nowrapscan |
| 29 | :1 |
| 30 | " first match |
| 31 | call feedkeys("/the\<cr>", 'tx') |
| 32 | call assert_equal(' 2 these', getline('.')) |
| 33 | :1 |
| 34 | " second match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 35 | call feedkeys("/the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 36 | call assert_equal(' 3 the', getline('.')) |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 37 | call assert_equal([0, 0, 0, 0], getpos('"')) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 38 | :1 |
| 39 | " third match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 40 | call feedkeys("/the".repeat("\<C-G>", 2)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 41 | call assert_equal(' 4 their', getline('.')) |
| 42 | :1 |
| 43 | " fourth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 44 | call feedkeys("/the".repeat("\<C-G>", 3)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 45 | call assert_equal(' 5 there', getline('.')) |
| 46 | :1 |
| 47 | " fifth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 48 | call feedkeys("/the".repeat("\<C-G>", 4)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 49 | call assert_equal(' 6 their', getline('.')) |
| 50 | :1 |
| 51 | " sixth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 52 | call feedkeys("/the".repeat("\<C-G>", 5)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 53 | call assert_equal(' 7 the', getline('.')) |
| 54 | :1 |
| 55 | " seventh match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 56 | call feedkeys("/the".repeat("\<C-G>", 6)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 57 | call assert_equal(' 8 them', getline('.')) |
| 58 | :1 |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 59 | " eighth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 60 | call feedkeys("/the".repeat("\<C-G>", 7)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 61 | call assert_equal(' 9 these', getline('.')) |
| 62 | :1 |
| 63 | " no further match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 64 | call feedkeys("/the".repeat("\<C-G>", 8)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 65 | call assert_equal(' 9 these', getline('.')) |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 66 | call assert_equal([0, 0, 0, 0], getpos('"')) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 67 | |
| 68 | " Test 3 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 69 | " Ctrl-G goes from one match to the next |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 70 | " and continues back at the top |
| 71 | set incsearch wrapscan |
| 72 | :1 |
| 73 | " first match |
| 74 | call feedkeys("/the\<cr>", 'tx') |
| 75 | call assert_equal(' 2 these', getline('.')) |
| 76 | :1 |
| 77 | " second match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 78 | call feedkeys("/the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 79 | call assert_equal(' 3 the', getline('.')) |
| 80 | :1 |
| 81 | " third match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 82 | call feedkeys("/the".repeat("\<C-G>", 2)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 83 | call assert_equal(' 4 their', getline('.')) |
| 84 | :1 |
| 85 | " fourth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 86 | call feedkeys("/the".repeat("\<C-G>", 3)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 87 | call assert_equal(' 5 there', getline('.')) |
| 88 | :1 |
| 89 | " fifth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 90 | call feedkeys("/the".repeat("\<C-G>", 4)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 91 | call assert_equal(' 6 their', getline('.')) |
| 92 | :1 |
| 93 | " sixth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 94 | call feedkeys("/the".repeat("\<C-G>", 5)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 95 | call assert_equal(' 7 the', getline('.')) |
| 96 | :1 |
| 97 | " seventh match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 98 | call feedkeys("/the".repeat("\<C-G>", 6)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 99 | call assert_equal(' 8 them', getline('.')) |
| 100 | :1 |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 101 | " eighth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 102 | call feedkeys("/the".repeat("\<C-G>", 7)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 103 | call assert_equal(' 9 these', getline('.')) |
| 104 | :1 |
| 105 | " back at first match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 106 | call feedkeys("/the".repeat("\<C-G>", 8)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 107 | call assert_equal(' 2 these', getline('.')) |
| 108 | |
| 109 | " Test 4 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 110 | " CTRL-T goes to the previous match |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 111 | set incsearch nowrapscan |
| 112 | $ |
| 113 | " first match |
| 114 | call feedkeys("?the\<cr>", 'tx') |
| 115 | call assert_equal(' 9 these', getline('.')) |
| 116 | $ |
| 117 | " first match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 118 | call feedkeys("?the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 119 | call assert_equal(' 9 these', getline('.')) |
| 120 | $ |
| 121 | " second match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 122 | call feedkeys("?the".repeat("\<C-T>", 1)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 123 | call assert_equal(' 8 them', getline('.')) |
| 124 | $ |
| 125 | " last match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 126 | call feedkeys("?the".repeat("\<C-T>", 7)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 127 | call assert_equal(' 2 these', getline('.')) |
| 128 | $ |
| 129 | " last match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 130 | call feedkeys("?the".repeat("\<C-T>", 8)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 131 | call assert_equal(' 2 these', getline('.')) |
| 132 | |
| 133 | " Test 5 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 134 | " CTRL-T goes to the previous match |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 135 | set incsearch wrapscan |
| 136 | $ |
| 137 | " first match |
| 138 | call feedkeys("?the\<cr>", 'tx') |
| 139 | call assert_equal(' 9 these', getline('.')) |
| 140 | $ |
| 141 | " first match at the top |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 142 | call feedkeys("?the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 143 | call assert_equal(' 2 these', getline('.')) |
| 144 | $ |
| 145 | " second match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 146 | call feedkeys("?the".repeat("\<C-T>", 1)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 147 | call assert_equal(' 8 them', getline('.')) |
| 148 | $ |
| 149 | " last match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 150 | call feedkeys("?the".repeat("\<C-T>", 7)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 151 | call assert_equal(' 2 these', getline('.')) |
| 152 | $ |
| 153 | " back at the bottom of the buffer |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 154 | call feedkeys("?the".repeat("\<C-T>", 8)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 155 | call assert_equal(' 9 these', getline('.')) |
| 156 | |
| 157 | " Test 6 |
| 158 | " CTRL-L adds to the search pattern |
| 159 | set incsearch wrapscan |
| 160 | 1 |
| 161 | " first match |
| 162 | call feedkeys("/the\<c-l>\<cr>", 'tx') |
| 163 | call assert_equal(' 2 these', getline('.')) |
| 164 | 1 |
| 165 | " go to next match of 'thes' |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 166 | call feedkeys("/the\<c-l>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 167 | call assert_equal(' 9 these', getline('.')) |
| 168 | 1 |
| 169 | " wrap around |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 170 | call feedkeys("/the\<c-l>\<C-G>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 171 | call assert_equal(' 2 these', getline('.')) |
| 172 | 1 |
| 173 | " wrap around |
| 174 | set nowrapscan |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 175 | call feedkeys("/the\<c-l>\<C-G>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 176 | call assert_equal(' 9 these', getline('.')) |
| 177 | |
| 178 | " Test 7 |
| 179 | " <bs> remove from match, but stay at current match |
| 180 | set incsearch wrapscan |
| 181 | 1 |
| 182 | " first match |
| 183 | call feedkeys("/thei\<cr>", 'tx') |
| 184 | call assert_equal(' 4 their', getline('.')) |
| 185 | 1 |
| 186 | " delete one char, add another |
| 187 | call feedkeys("/thei\<bs>s\<cr>", 'tx') |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 188 | call assert_equal(' 2 these', getline('.')) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 189 | 1 |
| 190 | " delete one char, add another, go to previous match, add one char |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 191 | call feedkeys("/thei\<bs>s\<bs>\<C-T>\<c-l>\<cr>", 'tx') |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 192 | call assert_equal(' 9 these', getline('.')) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 193 | 1 |
| 194 | " delete all chars, start from the beginning again |
| 195 | call feedkeys("/them". repeat("\<bs>",4).'the\>'."\<cr>", 'tx') |
| 196 | call assert_equal(' 3 the', getline('.')) |
| 197 | |
| 198 | " clean up |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 199 | call test_override("char_avail", 0) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 200 | bw! |
| 201 | endfunc |
| 202 | |
| 203 | func Test_search_cmdline2() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 204 | CheckOption incsearch |
| 205 | |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 206 | " need to disable char_avail, |
| 207 | " so that expansion of commandline works |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 208 | call test_override("char_avail", 1) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 209 | new |
| 210 | call setline(1, [' 1', ' 2 these', ' 3 the theother']) |
| 211 | " Test 1 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 212 | " Ctrl-T goes correctly back and forth |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 213 | set incsearch |
| 214 | 1 |
| 215 | " first match |
| 216 | call feedkeys("/the\<cr>", 'tx') |
| 217 | call assert_equal(' 2 these', getline('.')) |
| 218 | 1 |
| 219 | " go to next match (on next line) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 220 | call feedkeys("/the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 221 | call assert_equal(' 3 the theother', getline('.')) |
| 222 | 1 |
| 223 | " go to next match (still on line 3) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 224 | call feedkeys("/the\<C-G>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 225 | call assert_equal(' 3 the theother', getline('.')) |
| 226 | 1 |
| 227 | " go to next match (still on line 3) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 228 | call feedkeys("/the\<C-G>\<C-G>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 229 | call assert_equal(' 3 the theother', getline('.')) |
| 230 | 1 |
| 231 | " go to previous match (on line 3) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 232 | 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] | 233 | call assert_equal(' 3 the theother', getline('.')) |
| 234 | 1 |
| 235 | " go to previous match (on line 3) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 236 | 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] | 237 | call assert_equal(' 3 the theother', getline('.')) |
| 238 | 1 |
| 239 | " go to previous match (on line 2) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 240 | 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] | 241 | call assert_equal(' 2 these', getline('.')) |
Bram Moolenaar | 69a5b86 | 2019-07-16 21:38:51 +0200 | [diff] [blame] | 242 | 1 |
| 243 | " go to previous match (on line 2) |
| 244 | call feedkeys("/the\<C-G>\<C-R>\<C-W>\<cr>", 'tx') |
| 245 | call assert_equal('theother', @/) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 246 | |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 247 | " Test 2: keep the view, |
| 248 | " after deleting a character from the search cmd |
| 249 | call setline(1, [' 1', ' 2 these', ' 3 the', ' 4 their', ' 5 there', ' 6 their', ' 7 the', ' 8 them', ' 9 these', ' 10 foobar']) |
| 250 | resize 5 |
| 251 | 1 |
| 252 | call feedkeys("/foo\<bs>\<cr>", 'tx') |
| 253 | redraw |
| 254 | call assert_equal({'lnum': 10, 'leftcol': 0, 'col': 4, 'topfill': 0, 'topline': 6, 'coladd': 0, 'skipcol': 0, 'curswant': 4}, winsaveview()) |
| 255 | |
| 256 | " remove all history entries |
Bram Moolenaar | 69a5b86 | 2019-07-16 21:38:51 +0200 | [diff] [blame] | 257 | for i in range(11) |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 258 | call histdel('/') |
| 259 | endfor |
| 260 | |
| 261 | " Test 3: reset the view, |
| 262 | " after deleting all characters from the search cmd |
| 263 | norm! 1gg0 |
| 264 | " unfortunately, neither "/foo\<c-w>\<cr>", nor "/foo\<bs>\<bs>\<bs>\<cr>", |
| 265 | " nor "/foo\<c-u>\<cr>" works to delete the commandline. |
| 266 | " In that case Vim should return "E35 no previous regular expression", |
| 267 | " 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] | 268 | " Therefore, disabling this test |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 269 | "call assert_fails(feedkeys("/foo\<c-w>\<cr>", 'tx'), 'E35:') |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 270 | "call assert_equal({'lnum': 1, 'leftcol': 0, 'col': 0, 'topfill': 0, 'topline': 1, 'coladd': 0, 'skipcol': 0, 'curswant': 0}, winsaveview()) |
| 271 | |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 272 | " clean up |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 273 | set noincsearch |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 274 | call test_override("char_avail", 0) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 275 | bw! |
| 276 | endfunc |
Bram Moolenaar | ea683da | 2016-09-09 21:41:34 +0200 | [diff] [blame] | 277 | |
| 278 | func Test_use_sub_pat() |
| 279 | split |
| 280 | let @/ = '' |
| 281 | func X() |
| 282 | s/^/a/ |
| 283 | / |
| 284 | endfunc |
| 285 | call X() |
| 286 | bwipe! |
| 287 | endfunc |
Bram Moolenaar | 6e450a5 | 2017-01-06 20:03:58 +0100 | [diff] [blame] | 288 | |
| 289 | func Test_searchpair() |
| 290 | new |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 291 | call setline(1, ['other code', 'here [', ' [', ' " cursor here', ' ]]']) |
| 292 | |
Bram Moolenaar | bade44e | 2020-09-26 22:39:24 +0200 | [diff] [blame] | 293 | " should not give an error for using "42" |
| 294 | call assert_equal(0, searchpair('a', 'b', 'c', '', 42)) |
| 295 | |
Bram Moolenaar | 6e450a5 | 2017-01-06 20:03:58 +0100 | [diff] [blame] | 296 | 4 |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 297 | call assert_equal(3, searchpair('\[', '', ']', 'bW')) |
| 298 | call assert_equal([0, 3, 2, 0], getpos('.')) |
| 299 | 4 |
| 300 | call assert_equal(2, searchpair('\[', '', ']', 'bWr')) |
| 301 | call assert_equal([0, 2, 6, 0], getpos('.')) |
| 302 | 4 |
| 303 | call assert_equal(1, searchpair('\[', '', ']', 'bWm')) |
| 304 | call assert_equal([0, 3, 2, 0], getpos('.')) |
| 305 | 4|norm ^ |
| 306 | call assert_equal(5, searchpair('\[', '', ']', 'Wn')) |
| 307 | call assert_equal([0, 4, 2, 0], getpos('.')) |
| 308 | 4 |
| 309 | call assert_equal(2, searchpair('\[', '', ']', 'bW', |
| 310 | \ 'getline(".") =~ "^\\s*\["')) |
| 311 | call assert_equal([0, 2, 6, 0], getpos('.')) |
Bram Moolenaar | 6e450a5 | 2017-01-06 20:03:58 +0100 | [diff] [blame] | 312 | set nomagic |
| 313 | 4 |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 314 | call assert_equal(3, searchpair('\[', '', ']', 'bW')) |
| 315 | call assert_equal([0, 3, 2, 0], getpos('.')) |
Bram Moolenaar | 6e450a5 | 2017-01-06 20:03:58 +0100 | [diff] [blame] | 316 | set magic |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 317 | 4|norm ^ |
| 318 | call assert_equal(0, searchpair('{', '', '}', 'bW')) |
| 319 | call assert_equal([0, 4, 2, 0], getpos('.')) |
| 320 | |
| 321 | %d |
| 322 | call setline(1, ['if 1', ' if 2', ' else', ' endif 2', 'endif 1']) |
| 323 | |
| 324 | /\<if 1 |
| 325 | call assert_equal(5, searchpair('\<if\>', '\<else\>', '\<endif\>', 'W')) |
| 326 | call assert_equal([0, 5, 1, 0], getpos('.')) |
| 327 | /\<if 2 |
| 328 | call assert_equal(3, searchpair('\<if\>', '\<else\>', '\<endif\>', 'W')) |
| 329 | call assert_equal([0, 3, 3, 0], getpos('.')) |
| 330 | |
Bram Moolenaar | 5ea38d1 | 2022-06-16 21:20:48 +0100 | [diff] [blame] | 331 | bwipe! |
| 332 | endfunc |
| 333 | |
| 334 | func Test_searchpair_timeout() |
| 335 | CheckFeature reltime |
Bram Moolenaar | 73171ba | 2022-06-20 12:39:39 +0100 | [diff] [blame] | 336 | let g:test_is_flaky = 1 |
Bram Moolenaar | 5ea38d1 | 2022-06-16 21:20:48 +0100 | [diff] [blame] | 337 | |
| 338 | func Waitabit() |
| 339 | sleep 20m |
| 340 | return 1 " skip match |
| 341 | endfunc |
| 342 | |
| 343 | new |
| 344 | call setline(1, range(100)) |
| 345 | call setline(1, "(start here") |
| 346 | call setline(100, "end here)") |
| 347 | let starttime = reltime() |
| 348 | |
| 349 | " A timeout of 100 msec should happen after about five times of 20 msec wait |
| 350 | " in Waitabit(). When the timeout applies to each search the elapsed time |
| 351 | " will be much longer. |
| 352 | call assert_equal(0, searchpair('(', '\d', ')', '', "Waitabit()", 0, 100)) |
| 353 | let elapsed = reltime(starttime)->reltimefloat() |
| 354 | call assert_inrange(0.09, 0.300, elapsed) |
| 355 | |
Bram Moolenaar | 12a4940 | 2022-06-21 22:35:40 +0100 | [diff] [blame] | 356 | delfunc Waitabit |
Bram Moolenaar | 5ea38d1 | 2022-06-16 21:20:48 +0100 | [diff] [blame] | 357 | bwipe! |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 358 | endfunc |
| 359 | |
Bram Moolenaar | e530395 | 2022-06-19 17:05:47 +0100 | [diff] [blame] | 360 | func SearchpairSkip() |
| 361 | let id = synID(line('.'), col('.'), 0) |
| 362 | let attr = synIDattr(id, 'name') |
| 363 | return attr !~ 'comment' |
| 364 | endfunc |
| 365 | |
| 366 | func Test_searchpair_timeout_with_skip() |
| 367 | let g:test_is_flaky = 1 |
| 368 | |
| 369 | edit ../evalfunc.c |
| 370 | if has('win32') |
| 371 | " Windows timeouts are rather coarse grained, about 16ms. |
| 372 | let ms = 20 |
| 373 | let min_time = 0.016 |
| 374 | let max_time = min_time * 10.0 |
| 375 | else |
| 376 | let ms = 1 |
| 377 | let min_time = 0.001 |
| 378 | let max_time = min_time * 10.0 |
Bram Moolenaar | e366ed4 | 2022-06-19 20:13:56 +0100 | [diff] [blame] | 379 | if RunningWithValgrind() |
Bram Moolenaar | e530395 | 2022-06-19 17:05:47 +0100 | [diff] [blame] | 380 | let max_time += 0.04 " this can be slow with valgrind |
| 381 | endif |
| 382 | endif |
| 383 | let start = reltime() |
| 384 | let found = searchpair('(', '', ')', 'crnm', 'SearchpairSkip()', 0, ms) |
| 385 | let elapsed = reltimefloat(reltime(start)) |
| 386 | call assert_inrange(min_time, max_time, elapsed) |
| 387 | |
| 388 | bwipe! |
| 389 | endfunc |
| 390 | |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 391 | func Test_searchpairpos() |
| 392 | new |
| 393 | call setline(1, ['other code', 'here [', ' [', ' " cursor here', ' ]]']) |
| 394 | |
| 395 | 4 |
| 396 | call assert_equal([3, 2], searchpairpos('\[', '', ']', 'bW')) |
| 397 | call assert_equal([0, 3, 2, 0], getpos('.')) |
| 398 | 4 |
| 399 | call assert_equal([2, 6], searchpairpos('\[', '', ']', 'bWr')) |
| 400 | call assert_equal([0, 2, 6, 0], getpos('.')) |
| 401 | 4|norm ^ |
| 402 | call assert_equal([5, 2], searchpairpos('\[', '', ']', 'Wn')) |
| 403 | call assert_equal([0, 4, 2, 0], getpos('.')) |
| 404 | 4 |
| 405 | call assert_equal([2, 6], searchpairpos('\[', '', ']', 'bW', |
| 406 | \ 'getline(".") =~ "^\\s*\["')) |
| 407 | call assert_equal([0, 2, 6, 0], getpos('.')) |
| 408 | 4 |
| 409 | call assert_equal([2, 6], searchpairpos('\[', '', ']', 'bWr')) |
| 410 | call assert_equal([0, 2, 6, 0], getpos('.')) |
| 411 | set nomagic |
| 412 | 4 |
| 413 | call assert_equal([3, 2], searchpairpos('\[', '', ']', 'bW')) |
| 414 | call assert_equal([0, 3, 2, 0], getpos('.')) |
| 415 | set magic |
| 416 | 4|norm ^ |
| 417 | call assert_equal([0, 0], searchpairpos('{', '', '}', 'bW')) |
| 418 | call assert_equal([0, 4, 2, 0], getpos('.')) |
| 419 | |
| 420 | %d |
| 421 | call setline(1, ['if 1', ' if 2', ' else', ' endif 2', 'endif 1']) |
| 422 | /\<if 1 |
| 423 | call assert_equal([5, 1], searchpairpos('\<if\>', '\<else\>', '\<endif\>', 'W')) |
| 424 | call assert_equal([0, 5, 1, 0], getpos('.')) |
| 425 | /\<if 2 |
| 426 | call assert_equal([3, 3], searchpairpos('\<if\>', '\<else\>', '\<endif\>', 'W')) |
| 427 | call assert_equal([0, 3, 3, 0], getpos('.')) |
| 428 | |
Bram Moolenaar | 6e450a5 | 2017-01-06 20:03:58 +0100 | [diff] [blame] | 429 | q! |
| 430 | endfunc |
| 431 | |
Bram Moolenaar | 3dddb09 | 2018-06-24 19:01:59 +0200 | [diff] [blame] | 432 | func Test_searchpair_errors() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 433 | call assert_fails("call searchpair([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: Using a List as a String') |
| 434 | call assert_fails("call searchpair('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: Using a Funcref as a String') |
| 435 | call assert_fails("call searchpair('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: Using a Dictionary as a String') |
Bram Moolenaar | 3dddb09 | 2018-06-24 19:01:59 +0200 | [diff] [blame] | 436 | call assert_fails("call searchpair('start', 'middle', 'end', 'flags', 'skip', 99, 100)", 'E475: Invalid argument: flags') |
Bram Moolenaar | 3dddb09 | 2018-06-24 19:01:59 +0200 | [diff] [blame] | 437 | call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', -99, 100)", 'E475: Invalid argument: -99') |
| 438 | 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] | 439 | call assert_fails("call searchpair('start', 'middle', 'end', 'e')", 'E475: Invalid argument: e') |
| 440 | call assert_fails("call searchpair('start', 'middle', 'end', 'sn')", 'E475: Invalid argument: sn') |
| 441 | endfunc |
| 442 | |
| 443 | func Test_searchpairpos_errors() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 444 | call assert_fails("call searchpairpos([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: Using a List as a String') |
| 445 | call assert_fails("call searchpairpos('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: Using a Funcref as a String') |
| 446 | call assert_fails("call searchpairpos('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: Using a Dictionary as a String') |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 447 | call assert_fails("call searchpairpos('start', 'middle', 'end', 'flags', 'skip', 99, 100)", 'E475: Invalid argument: flags') |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 448 | call assert_fails("call searchpairpos('start', 'middle', 'end', 'bW', 'func', -99, 100)", 'E475: Invalid argument: -99') |
| 449 | call assert_fails("call searchpairpos('start', 'middle', 'end', 'bW', 'func', 99, -100)", 'E475: Invalid argument: -100') |
| 450 | call assert_fails("call searchpairpos('start', 'middle', 'end', 'e')", 'E475: Invalid argument: e') |
| 451 | 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] | 452 | endfunc |
| 453 | |
Bram Moolenaar | 4857048 | 2017-10-30 21:48:41 +0100 | [diff] [blame] | 454 | func Test_searchpair_skip() |
| 455 | func Zero() |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 456 | return 0 |
Bram Moolenaar | 4857048 | 2017-10-30 21:48:41 +0100 | [diff] [blame] | 457 | endfunc |
| 458 | func Partial(x) |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 459 | return a:x |
Bram Moolenaar | 4857048 | 2017-10-30 21:48:41 +0100 | [diff] [blame] | 460 | endfunc |
| 461 | new |
| 462 | call setline(1, ['{', 'foo', 'foo', 'foo', '}']) |
| 463 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', '')) |
| 464 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', '0')) |
| 465 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', {-> 0})) |
| 466 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Zero'))) |
| 467 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Partial', [0]))) |
Bram Moolenaar | 4857048 | 2017-10-30 21:48:41 +0100 | [diff] [blame] | 468 | bw! |
| 469 | endfunc |
| 470 | |
Bram Moolenaar | a43ebe9 | 2018-07-14 17:25:01 +0200 | [diff] [blame] | 471 | func Test_searchpair_leak() |
| 472 | new |
| 473 | call setline(1, 'if one else another endif') |
| 474 | |
| 475 | " The error in the skip expression caused memory to leak. |
| 476 | call assert_fails("call searchpair('\\<if\\>', '\\<else\\>', '\\<endif\\>', '', '\"foo\" 2')", 'E15:') |
| 477 | |
| 478 | bwipe! |
| 479 | endfunc |
| 480 | |
Bram Moolenaar | 66727e1 | 2017-03-01 22:17:05 +0100 | [diff] [blame] | 481 | func Test_searchc() |
| 482 | " These commands used to cause memory overflow in searchc(). |
| 483 | new |
| 484 | norm ixx |
| 485 | exe "norm 0t\u93cf" |
| 486 | bw! |
| 487 | endfunc |
Bram Moolenaar | a693d05 | 2017-06-29 22:23:06 +0200 | [diff] [blame] | 488 | |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 489 | func Cmdline3_prep() |
| 490 | " need to disable char_avail, |
| 491 | " so that expansion of commandline works |
| 492 | call test_override("char_avail", 1) |
| 493 | new |
| 494 | call setline(1, [' 1', ' 2 the~e', ' 3 the theother']) |
| 495 | set incsearch |
| 496 | endfunc |
| 497 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 498 | func Incsearch_cleanup() |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 499 | set noincsearch |
| 500 | call test_override("char_avail", 0) |
| 501 | bw! |
| 502 | endfunc |
| 503 | |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 504 | func Test_search_cmdline3() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 505 | CheckOption incsearch |
| 506 | |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 507 | call Cmdline3_prep() |
| 508 | 1 |
| 509 | " first match |
| 510 | call feedkeys("/the\<c-l>\<cr>", 'tx') |
| 511 | call assert_equal(' 2 the~e', getline('.')) |
| 512 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 513 | call Incsearch_cleanup() |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 514 | endfunc |
| 515 | |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 516 | func Test_search_cmdline3s() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 517 | CheckOption incsearch |
| 518 | |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 519 | call Cmdline3_prep() |
| 520 | 1 |
| 521 | call feedkeys(":%s/the\<c-l>/xxx\<cr>", 'tx') |
| 522 | call assert_equal(' 2 xxxe', getline('.')) |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 523 | undo |
| 524 | call feedkeys(":%subs/the\<c-l>/xxx\<cr>", 'tx') |
| 525 | call assert_equal(' 2 xxxe', getline('.')) |
| 526 | undo |
| 527 | call feedkeys(":%substitute/the\<c-l>/xxx\<cr>", 'tx') |
| 528 | call assert_equal(' 2 xxxe', getline('.')) |
Bram Moolenaar | 167ae42 | 2018-08-14 21:32:21 +0200 | [diff] [blame] | 529 | undo |
| 530 | call feedkeys(":%smagic/the.e/xxx\<cr>", 'tx') |
| 531 | call assert_equal(' 2 xxx', getline('.')) |
| 532 | undo |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 533 | call assert_fails(":%snomagic/the.e/xxx\<cr>", 'E486:') |
Bram Moolenaar | 167ae42 | 2018-08-14 21:32:21 +0200 | [diff] [blame] | 534 | " |
| 535 | call feedkeys(":%snomagic/the\\.e/xxx\<cr>", 'tx') |
| 536 | call assert_equal(' 2 xxx', getline('.')) |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 537 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 538 | call Incsearch_cleanup() |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 539 | endfunc |
| 540 | |
| 541 | func Test_search_cmdline3g() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 542 | CheckOption incsearch |
| 543 | |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 544 | call Cmdline3_prep() |
| 545 | 1 |
| 546 | call feedkeys(":g/the\<c-l>/d\<cr>", 'tx') |
| 547 | call assert_equal(' 3 the theother', getline(2)) |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 548 | undo |
| 549 | call feedkeys(":global/the\<c-l>/d\<cr>", 'tx') |
| 550 | call assert_equal(' 3 the theother', getline(2)) |
Bram Moolenaar | def7b1d | 2018-08-13 22:54:35 +0200 | [diff] [blame] | 551 | undo |
| 552 | call feedkeys(":g!/the\<c-l>/d\<cr>", 'tx') |
| 553 | call assert_equal(1, line('$')) |
| 554 | call assert_equal(' 2 the~e', getline(1)) |
| 555 | undo |
| 556 | call feedkeys(":global!/the\<c-l>/d\<cr>", 'tx') |
| 557 | call assert_equal(1, line('$')) |
| 558 | call assert_equal(' 2 the~e', getline(1)) |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 559 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 560 | call Incsearch_cleanup() |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 561 | endfunc |
| 562 | |
| 563 | func Test_search_cmdline3v() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 564 | CheckOption incsearch |
| 565 | |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 566 | call Cmdline3_prep() |
| 567 | 1 |
| 568 | call feedkeys(":v/the\<c-l>/d\<cr>", 'tx') |
| 569 | call assert_equal(1, line('$')) |
| 570 | call assert_equal(' 2 the~e', getline(1)) |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 571 | undo |
| 572 | call feedkeys(":vglobal/the\<c-l>/d\<cr>", 'tx') |
| 573 | call assert_equal(1, line('$')) |
| 574 | call assert_equal(' 2 the~e', getline(1)) |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 575 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 576 | call Incsearch_cleanup() |
Bram Moolenaar | b0acacd | 2018-08-11 16:40:43 +0200 | [diff] [blame] | 577 | endfunc |
| 578 | |
Bram Moolenaar | da5116d | 2017-07-01 23:11:17 +0200 | [diff] [blame] | 579 | func Test_search_cmdline4() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 580 | CheckOption incsearch |
| 581 | |
Bram Moolenaar | da5116d | 2017-07-01 23:11:17 +0200 | [diff] [blame] | 582 | " need to disable char_avail, |
| 583 | " so that expansion of commandline works |
| 584 | call test_override("char_avail", 1) |
| 585 | new |
| 586 | call setline(1, [' 1 the first', ' 2 the second', ' 3 the third']) |
| 587 | set incsearch |
| 588 | $ |
| 589 | call feedkeys("?the\<c-g>\<cr>", 'tx') |
| 590 | call assert_equal(' 3 the third', getline('.')) |
| 591 | $ |
| 592 | call feedkeys("?the\<c-g>\<c-g>\<cr>", 'tx') |
| 593 | call assert_equal(' 1 the first', getline('.')) |
| 594 | $ |
| 595 | call feedkeys("?the\<c-g>\<c-g>\<c-g>\<cr>", 'tx') |
| 596 | call assert_equal(' 2 the second', getline('.')) |
| 597 | $ |
| 598 | call feedkeys("?the\<c-t>\<cr>", 'tx') |
| 599 | call assert_equal(' 1 the first', getline('.')) |
| 600 | $ |
| 601 | call feedkeys("?the\<c-t>\<c-t>\<cr>", 'tx') |
| 602 | call assert_equal(' 3 the third', getline('.')) |
| 603 | $ |
| 604 | call feedkeys("?the\<c-t>\<c-t>\<c-t>\<cr>", 'tx') |
| 605 | call assert_equal(' 2 the second', getline('.')) |
| 606 | " clean up |
| 607 | set noincsearch |
| 608 | call test_override("char_avail", 0) |
| 609 | bw! |
| 610 | endfunc |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 611 | |
Bram Moolenaar | f8e8c06 | 2017-10-22 14:44:17 +0200 | [diff] [blame] | 612 | func Test_search_cmdline5() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 613 | CheckOption incsearch |
| 614 | |
Bram Moolenaar | f8e8c06 | 2017-10-22 14:44:17 +0200 | [diff] [blame] | 615 | " Do not call test_override("char_avail", 1) so that <C-g> and <C-t> work |
| 616 | " regardless char_avail. |
| 617 | new |
Bram Moolenaar | 69a5b86 | 2019-07-16 21:38:51 +0200 | [diff] [blame] | 618 | call setline(1, [' 1 the first', ' 2 the second', ' 3 the third', '']) |
Bram Moolenaar | f8e8c06 | 2017-10-22 14:44:17 +0200 | [diff] [blame] | 619 | set incsearch |
| 620 | 1 |
| 621 | call feedkeys("/the\<c-g>\<c-g>\<cr>", 'tx') |
| 622 | call assert_equal(' 3 the third', getline('.')) |
| 623 | $ |
| 624 | call feedkeys("?the\<c-t>\<c-t>\<c-t>\<cr>", 'tx') |
Bram Moolenaar | 69a5b86 | 2019-07-16 21:38:51 +0200 | [diff] [blame] | 625 | call assert_equal(' 1 the first', getline('.')) |
Bram Moolenaar | f8e8c06 | 2017-10-22 14:44:17 +0200 | [diff] [blame] | 626 | " clean up |
| 627 | set noincsearch |
| 628 | bw! |
| 629 | endfunc |
| 630 | |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 631 | func Test_search_cmdline6() |
| 632 | " Test that consecutive matches |
| 633 | " are caught by <c-g>/<c-t> |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 634 | CheckOption incsearch |
| 635 | |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 636 | " need to disable char_avail, |
| 637 | " so that expansion of commandline works |
| 638 | call test_override("char_avail", 1) |
| 639 | new |
| 640 | call setline(1, [' bbvimb', '']) |
| 641 | set incsearch |
| 642 | " first match |
| 643 | norm! gg0 |
| 644 | call feedkeys("/b\<cr>", 'tx') |
| 645 | call assert_equal([0,1,2,0], getpos('.')) |
| 646 | " second match |
| 647 | norm! gg0 |
| 648 | call feedkeys("/b\<c-g>\<cr>", 'tx') |
| 649 | call assert_equal([0,1,3,0], getpos('.')) |
| 650 | " third match |
| 651 | norm! gg0 |
| 652 | call feedkeys("/b\<c-g>\<c-g>\<cr>", 'tx') |
| 653 | call assert_equal([0,1,7,0], getpos('.')) |
| 654 | " first match again |
| 655 | norm! gg0 |
| 656 | call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx') |
| 657 | call assert_equal([0,1,2,0], getpos('.')) |
| 658 | set nowrapscan |
| 659 | " last match |
| 660 | norm! gg0 |
| 661 | call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx') |
| 662 | call assert_equal([0,1,7,0], getpos('.')) |
| 663 | " clean up |
| 664 | set wrapscan&vim |
| 665 | set noincsearch |
| 666 | call test_override("char_avail", 0) |
| 667 | bw! |
| 668 | endfunc |
| 669 | |
| 670 | func Test_search_cmdline7() |
Bram Moolenaar | d66cdcd | 2020-07-26 13:27:16 +0200 | [diff] [blame] | 671 | " Test that pressing <c-g> in an empty command line |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 672 | " does not move the cursor |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 673 | CheckOption incsearch |
| 674 | |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 675 | " need to disable char_avail, |
| 676 | " so that expansion of commandline works |
| 677 | call test_override("char_avail", 1) |
| 678 | new |
Bram Moolenaar | 21f990e | 2018-08-11 19:20:49 +0200 | [diff] [blame] | 679 | let @/ = 'b' |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 680 | call setline(1, [' bbvimb', '']) |
| 681 | set incsearch |
| 682 | " first match |
| 683 | norm! gg0 |
| 684 | " moves to next match of previous search pattern, just like /<cr> |
| 685 | call feedkeys("/\<c-g>\<cr>", 'tx') |
| 686 | call assert_equal([0,1,2,0], getpos('.')) |
| 687 | " moves to next match of previous search pattern, just like /<cr> |
| 688 | call feedkeys("/\<cr>", 'tx') |
| 689 | call assert_equal([0,1,3,0], getpos('.')) |
| 690 | " moves to next match of previous search pattern, just like /<cr> |
| 691 | call feedkeys("/\<c-t>\<cr>", 'tx') |
| 692 | call assert_equal([0,1,7,0], getpos('.')) |
Bram Moolenaar | d048009 | 2017-11-16 22:20:39 +0100 | [diff] [blame] | 693 | |
| 694 | " using an offset uses the last search pattern |
| 695 | call cursor(1, 1) |
| 696 | call setline(1, ['1 bbvimb', ' 2 bbvimb']) |
| 697 | let @/ = 'b' |
| 698 | call feedkeys("//e\<c-g>\<cr>", 'tx') |
| 699 | call assert_equal('1 bbvimb', getline('.')) |
| 700 | call assert_equal(4, col('.')) |
| 701 | |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 702 | set noincsearch |
| 703 | call test_override("char_avail", 0) |
| 704 | bw! |
| 705 | endfunc |
| 706 | |
| 707 | func Test_search_cmdline8() |
| 708 | " Highlighting is cleared in all windows |
| 709 | " since hls applies to all windows |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 710 | CheckOption incsearch |
| 711 | CheckFeature terminal |
| 712 | CheckNotGui |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 713 | if has("win32") |
| 714 | throw "Skipped: Bug with sending <ESC> to terminal window not fixed yet" |
| 715 | endif |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 716 | |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 717 | let h = winheight(0) |
| 718 | if h < 3 |
| 719 | return |
| 720 | endif |
| 721 | " Prepare buffer text |
| 722 | let lines = ['abb vim vim vi', 'vimvivim'] |
| 723 | call writefile(lines, 'Xsearch.txt') |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 724 | 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] | 725 | |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 726 | 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] | 727 | |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 728 | call term_sendkeys(buf, ":set incsearch hlsearch\<cr>") |
| 729 | call term_sendkeys(buf, ":14vsp\<cr>") |
| 730 | call term_sendkeys(buf, "/vim\<cr>") |
| 731 | call term_sendkeys(buf, "/b\<esc>") |
| 732 | call term_sendkeys(buf, "gg0") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 733 | call TermWait(buf, 250) |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 734 | let screen_line = term_scrape(buf, 1) |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 735 | let [a0,a1,a2,a3] = [screen_line[3].attr, screen_line[4].attr, |
| 736 | \ screen_line[18].attr, screen_line[19].attr] |
| 737 | call assert_notequal(a0, a1) |
| 738 | call assert_notequal(a0, a3) |
| 739 | call assert_notequal(a1, a2) |
| 740 | call assert_equal(a0, a2) |
| 741 | call assert_equal(a1, a3) |
| 742 | " clean up |
| 743 | call delete('Xsearch.txt') |
| 744 | |
| 745 | bwipe! |
| 746 | endfunc |
| 747 | |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 748 | " Tests for regexp with various magic settings |
Bram Moolenaar | 4d23c52 | 2020-04-09 18:42:11 +0200 | [diff] [blame] | 749 | func Run_search_regexp_magic_opt() |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 750 | put ='1 a aa abb abbccc' |
| 751 | exe 'normal! /a*b\{2}c\+/e' . "\<CR>" |
| 752 | call assert_equal([0, 2, 17, 0], getpos('.')) |
| 753 | |
| 754 | put ='2 d dd dee deefff' |
| 755 | exe 'normal! /\Md\*e\{2}f\+/e' . "\<CR>" |
| 756 | call assert_equal([0, 3, 17, 0], getpos('.')) |
| 757 | |
| 758 | set nomagic |
| 759 | put ='3 g gg ghh ghhiii' |
| 760 | exe 'normal! /g\*h\{2}i\+/e' . "\<CR>" |
| 761 | call assert_equal([0, 4, 17, 0], getpos('.')) |
| 762 | |
| 763 | put ='4 j jj jkk jkklll' |
| 764 | exe 'normal! /\mj*k\{2}l\+/e' . "\<CR>" |
| 765 | call assert_equal([0, 5, 17, 0], getpos('.')) |
| 766 | |
| 767 | put ='5 m mm mnn mnnooo' |
| 768 | exe 'normal! /\vm*n{2}o+/e' . "\<CR>" |
| 769 | call assert_equal([0, 6, 17, 0], getpos('.')) |
| 770 | |
| 771 | put ='6 x ^aa$ x' |
| 772 | exe 'normal! /\V^aa$' . "\<CR>" |
| 773 | call assert_equal([0, 7, 5, 0], getpos('.')) |
| 774 | |
| 775 | set magic |
| 776 | put ='7 (a)(b) abbaa' |
| 777 | exe 'normal! /\v(a)(b)\2\1\1/e' . "\<CR>" |
| 778 | call assert_equal([0, 8, 14, 0], getpos('.')) |
| 779 | |
| 780 | put ='8 axx [ab]xx' |
| 781 | exe 'normal! /\V[ab]\(\[xy]\)\1' . "\<CR>" |
| 782 | call assert_equal([0, 9, 7, 0], getpos('.')) |
| 783 | |
Bram Moolenaar | 4d23c52 | 2020-04-09 18:42:11 +0200 | [diff] [blame] | 784 | %d |
| 785 | endfunc |
| 786 | |
| 787 | func Test_search_regexp() |
| 788 | enew! |
| 789 | |
| 790 | set regexpengine=1 |
| 791 | call Run_search_regexp_magic_opt() |
| 792 | set regexpengine=2 |
| 793 | call Run_search_regexp_magic_opt() |
| 794 | set regexpengine& |
| 795 | |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 796 | set undolevels=100 |
| 797 | put ='9 foobar' |
| 798 | put ='' |
| 799 | exe "normal! a\<C-G>u\<Esc>" |
| 800 | normal G |
| 801 | exe 'normal! dv?bar?' . "\<CR>" |
| 802 | call assert_equal('9 foo', getline('.')) |
Bram Moolenaar | 4d23c52 | 2020-04-09 18:42:11 +0200 | [diff] [blame] | 803 | call assert_equal([0, 2, 5, 0], getpos('.')) |
| 804 | call assert_equal(2, line('$')) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 805 | normal u |
| 806 | call assert_equal('9 foobar', getline('.')) |
Bram Moolenaar | 4d23c52 | 2020-04-09 18:42:11 +0200 | [diff] [blame] | 807 | call assert_equal([0, 2, 6, 0], getpos('.')) |
| 808 | call assert_equal(3, line('$')) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 809 | |
| 810 | set undolevels& |
| 811 | enew! |
| 812 | endfunc |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 813 | |
| 814 | func Test_search_cmdline_incsearch_highlight() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 815 | CheckOption incsearch |
| 816 | |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 817 | set incsearch hlsearch |
| 818 | " need to disable char_avail, |
| 819 | " so that expansion of commandline works |
| 820 | call test_override("char_avail", 1) |
| 821 | new |
| 822 | call setline(1, ['aaa 1 the first', ' 2 the second', ' 3 the third']) |
| 823 | |
| 824 | 1 |
| 825 | call feedkeys("/second\<cr>", 'tx') |
| 826 | call assert_equal('second', @/) |
| 827 | call assert_equal(' 2 the second', getline('.')) |
| 828 | |
| 829 | " Canceling search won't change @/ |
| 830 | 1 |
| 831 | let @/ = 'last pattern' |
| 832 | call feedkeys("/third\<C-c>", 'tx') |
| 833 | call assert_equal('last pattern', @/) |
| 834 | call feedkeys("/third\<Esc>", 'tx') |
| 835 | call assert_equal('last pattern', @/) |
| 836 | call feedkeys("/3\<bs>\<bs>", 'tx') |
| 837 | call assert_equal('last pattern', @/) |
| 838 | call feedkeys("/third\<c-g>\<c-t>\<Esc>", 'tx') |
| 839 | call assert_equal('last pattern', @/) |
| 840 | |
| 841 | " clean up |
| 842 | set noincsearch nohlsearch |
| 843 | bw! |
| 844 | endfunc |
| 845 | |
| 846 | func Test_search_cmdline_incsearch_highlight_attr() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 847 | CheckOption incsearch |
| 848 | CheckFeature terminal |
| 849 | CheckNotGui |
| 850 | |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 851 | let h = winheight(0) |
| 852 | if h < 3 |
| 853 | return |
| 854 | endif |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 855 | |
| 856 | " Prepare buffer text |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 857 | let lines = ['abb vim vim vi', 'vimvivim'] |
| 858 | call writefile(lines, 'Xsearch.txt') |
| 859 | let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3}) |
| 860 | |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 861 | 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] | 862 | " wait for vim to complete initialization |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 863 | call TermWait(buf) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 864 | |
| 865 | " Get attr of normal(a0), incsearch(a1), hlsearch(a2) highlight |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 866 | call term_sendkeys(buf, ":set incsearch hlsearch\<cr>") |
| 867 | call term_sendkeys(buf, '/b') |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 868 | call TermWait(buf, 100) |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 869 | let screen_line1 = term_scrape(buf, 1) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 870 | call assert_true(len(screen_line1) > 2) |
| 871 | " a0: attr_normal |
| 872 | let a0 = screen_line1[0].attr |
| 873 | " a1: attr_incsearch |
| 874 | let a1 = screen_line1[1].attr |
| 875 | " a2: attr_hlsearch |
| 876 | let a2 = screen_line1[2].attr |
| 877 | call assert_notequal(a0, a1) |
| 878 | call assert_notequal(a0, a2) |
| 879 | call assert_notequal(a1, a2) |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 880 | call term_sendkeys(buf, "\<cr>gg0") |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 881 | |
| 882 | " Test incremental highlight search |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 883 | call term_sendkeys(buf, "/vim") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 884 | call TermWait(buf, 100) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 885 | " Buffer: |
| 886 | " abb vim vim vi |
| 887 | " vimvivim |
| 888 | " Search: /vim |
| 889 | let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a2,a2,a2,a0,a0,a0] |
| 890 | let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 891 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 892 | 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] | 893 | |
| 894 | " Test <C-g> |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 895 | call term_sendkeys(buf, "\<C-g>\<C-g>") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 896 | call TermWait(buf, 100) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 897 | let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] |
| 898 | let attr_line2 = [a1,a1,a1,a0,a0,a2,a2,a2] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 899 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 900 | 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] | 901 | |
| 902 | " Test <C-t> |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 903 | call term_sendkeys(buf, "\<C-t>") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 904 | call TermWait(buf, 100) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 905 | let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a1,a1,a1,a0,a0,a0] |
| 906 | let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 907 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 908 | 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] | 909 | |
| 910 | " Type Enter and a1(incsearch highlight) should become a2(hlsearch highlight) |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 911 | call term_sendkeys(buf, "\<cr>") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 912 | call TermWait(buf, 100) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 913 | let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] |
| 914 | let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 915 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 916 | 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] | 917 | |
| 918 | " Test nohlsearch. a2(hlsearch highlight) should become a0(normal highlight) |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 919 | call term_sendkeys(buf, ":1\<cr>") |
| 920 | call term_sendkeys(buf, ":set nohlsearch\<cr>") |
| 921 | call term_sendkeys(buf, "/vim") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 922 | call TermWait(buf, 100) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 923 | let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a0,a0,a0,a0,a0,a0] |
| 924 | let attr_line2 = [a0,a0,a0,a0,a0,a0,a0,a0] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 925 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 926 | 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] | 927 | call delete('Xsearch.txt') |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 928 | |
Bram Moolenaar | b94340c | 2017-11-02 16:16:31 +0100 | [diff] [blame] | 929 | call delete('Xsearch.txt') |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 930 | bwipe! |
| 931 | endfunc |
Bram Moolenaar | f45938c | 2017-11-02 15:59:57 +0100 | [diff] [blame] | 932 | |
Bram Moolenaar | 548e598 | 2018-12-26 21:45:00 +0100 | [diff] [blame] | 933 | func Test_incsearch_cmdline_modifier() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 934 | CheckOption incsearch |
| 935 | |
Bram Moolenaar | 548e598 | 2018-12-26 21:45:00 +0100 | [diff] [blame] | 936 | call test_override("char_avail", 1) |
| 937 | new |
| 938 | call setline(1, ['foo']) |
| 939 | set incsearch |
| 940 | " Test that error E14 does not occur in parsing command modifier. |
| 941 | call feedkeys("V:tab", 'tx') |
| 942 | |
| 943 | call Incsearch_cleanup() |
| 944 | endfunc |
| 945 | |
Bram Moolenaar | 9d34d90 | 2018-04-27 22:18:12 +0200 | [diff] [blame] | 946 | func Test_incsearch_scrolling() |
Bram Moolenaar | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 947 | CheckRunVimInTerminal |
Bram Moolenaar | 9d34d90 | 2018-04-27 22:18:12 +0200 | [diff] [blame] | 948 | call assert_equal(0, &scrolloff) |
| 949 | call writefile([ |
| 950 | \ 'let dots = repeat(".", 120)', |
| 951 | \ 'set incsearch cmdheight=2 scrolloff=0', |
| 952 | \ 'call setline(1, [dots, dots, dots, "", "target", dots, dots])', |
| 953 | \ 'normal gg', |
| 954 | \ 'redraw', |
| 955 | \ ], 'Xscript') |
| 956 | let buf = RunVimInTerminal('-S Xscript', {'rows': 9, 'cols': 70}) |
| 957 | " Need to send one key at a time to force a redraw |
| 958 | call term_sendkeys(buf, '/') |
| 959 | sleep 100m |
| 960 | call term_sendkeys(buf, 't') |
| 961 | sleep 100m |
| 962 | call term_sendkeys(buf, 'a') |
| 963 | sleep 100m |
| 964 | call term_sendkeys(buf, 'r') |
| 965 | sleep 100m |
| 966 | call term_sendkeys(buf, 'g') |
| 967 | call VerifyScreenDump(buf, 'Test_incsearch_scrolling_01', {}) |
| 968 | |
| 969 | call term_sendkeys(buf, "\<Esc>") |
| 970 | call StopVimInTerminal(buf) |
| 971 | call delete('Xscript') |
| 972 | endfunc |
| 973 | |
Bram Moolenaar | 4edfe2d | 2018-08-23 20:55:45 +0200 | [diff] [blame] | 974 | func Test_incsearch_search_dump() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 975 | CheckOption incsearch |
| 976 | CheckScreendump |
| 977 | |
Bram Moolenaar | 4edfe2d | 2018-08-23 20:55:45 +0200 | [diff] [blame] | 978 | call writefile([ |
| 979 | \ 'set incsearch hlsearch scrolloff=0', |
| 980 | \ 'for n in range(1, 8)', |
| 981 | \ ' call setline(n, "foo " . n)', |
| 982 | \ 'endfor', |
| 983 | \ '3', |
| 984 | \ ], 'Xis_search_script') |
| 985 | let buf = RunVimInTerminal('-S Xis_search_script', {'rows': 9, 'cols': 70}) |
| 986 | " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by |
| 987 | " the 'ambiwidth' check. |
| 988 | sleep 100m |
| 989 | |
| 990 | " Need to send one key at a time to force a redraw. |
| 991 | call term_sendkeys(buf, '/fo') |
Bram Moolenaar | 4edfe2d | 2018-08-23 20:55:45 +0200 | [diff] [blame] | 992 | call VerifyScreenDump(buf, 'Test_incsearch_search_01', {}) |
| 993 | call term_sendkeys(buf, "\<Esc>") |
| 994 | sleep 100m |
| 995 | |
| 996 | call term_sendkeys(buf, '/\v') |
Bram Moolenaar | 4edfe2d | 2018-08-23 20:55:45 +0200 | [diff] [blame] | 997 | call VerifyScreenDump(buf, 'Test_incsearch_search_02', {}) |
| 998 | call term_sendkeys(buf, "\<Esc>") |
| 999 | |
| 1000 | call StopVimInTerminal(buf) |
| 1001 | call delete('Xis_search_script') |
| 1002 | endfunc |
| 1003 | |
Bram Moolenaar | 41f0895 | 2021-02-22 22:13:49 +0100 | [diff] [blame] | 1004 | func Test_hlsearch_dump() |
| 1005 | CheckOption hlsearch |
| 1006 | CheckScreendump |
| 1007 | |
| 1008 | call writefile([ |
| 1009 | \ 'set hlsearch cursorline', |
| 1010 | \ 'call setline(1, ["xxx", "xxx", "xxx"])', |
| 1011 | \ '/.*', |
| 1012 | \ '2', |
| 1013 | \ ], 'Xhlsearch_script') |
| 1014 | let buf = RunVimInTerminal('-S Xhlsearch_script', {'rows': 6, 'cols': 50}) |
| 1015 | call VerifyScreenDump(buf, 'Test_hlsearch_1', {}) |
| 1016 | |
| 1017 | call term_sendkeys(buf, "/\\_.*\<CR>") |
| 1018 | call VerifyScreenDump(buf, 'Test_hlsearch_2', {}) |
| 1019 | |
| 1020 | call StopVimInTerminal(buf) |
| 1021 | call delete('Xhlsearch_script') |
| 1022 | endfunc |
| 1023 | |
Bram Moolenaar | 2d5f385 | 2021-04-21 15:11:42 +0200 | [diff] [blame] | 1024 | func Test_hlsearch_and_visual() |
| 1025 | CheckOption hlsearch |
| 1026 | CheckScreendump |
| 1027 | |
| 1028 | call writefile([ |
| 1029 | \ 'set hlsearch', |
| 1030 | \ 'call setline(1, repeat(["xxx yyy zzz"], 3))', |
| 1031 | \ 'hi Search cterm=bold', |
| 1032 | \ '/yyy', |
| 1033 | \ 'call cursor(1, 6)', |
| 1034 | \ ], 'Xhlvisual_script') |
| 1035 | let buf = RunVimInTerminal('-S Xhlvisual_script', {'rows': 6, 'cols': 40}) |
| 1036 | call term_sendkeys(buf, "vjj") |
| 1037 | call VerifyScreenDump(buf, 'Test_hlsearch_visual_1', {}) |
| 1038 | call term_sendkeys(buf, "\<Esc>") |
| 1039 | |
| 1040 | call StopVimInTerminal(buf) |
| 1041 | call delete('Xhlvisual_script') |
| 1042 | endfunc |
| 1043 | |
Bram Moolenaar | e71c0eb | 2021-05-30 16:43:11 +0200 | [diff] [blame] | 1044 | func Test_hlsearch_block_visual_match() |
| 1045 | CheckScreendump |
| 1046 | |
| 1047 | let lines =<< trim END |
| 1048 | set hlsearch |
| 1049 | call setline(1, ['aa', 'bbbb', 'cccccc']) |
| 1050 | END |
| 1051 | call writefile(lines, 'Xhlsearch_block') |
| 1052 | let buf = RunVimInTerminal('-S Xhlsearch_block', {'rows': 9, 'cols': 60}) |
| 1053 | |
| 1054 | call term_sendkeys(buf, "G\<C-V>$kk\<Esc>") |
| 1055 | sleep 100m |
| 1056 | call term_sendkeys(buf, "/\\%V\<CR>") |
| 1057 | sleep 100m |
| 1058 | call VerifyScreenDump(buf, 'Test_hlsearch_block_visual_match', {}) |
| 1059 | |
| 1060 | call StopVimInTerminal(buf) |
| 1061 | call delete('Xhlsearch_block') |
| 1062 | endfunc |
| 1063 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 1064 | func Test_incsearch_substitute() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 1065 | CheckOption incsearch |
| 1066 | |
Bram Moolenaar | 976b847 | 2018-08-12 15:49:47 +0200 | [diff] [blame] | 1067 | call test_override("char_avail", 1) |
| 1068 | new |
| 1069 | set incsearch |
| 1070 | for n in range(1, 10) |
| 1071 | call setline(n, 'foo ' . n) |
| 1072 | endfor |
| 1073 | 4 |
| 1074 | call feedkeys(":.,.+2s/foo\<BS>o\<BS>o/xxx\<cr>", 'tx') |
| 1075 | call assert_equal('foo 3', getline(3)) |
| 1076 | call assert_equal('xxx 4', getline(4)) |
| 1077 | call assert_equal('xxx 5', getline(5)) |
| 1078 | call assert_equal('xxx 6', getline(6)) |
| 1079 | call assert_equal('foo 7', getline(7)) |
| 1080 | |
| 1081 | call Incsearch_cleanup() |
| 1082 | endfunc |
| 1083 | |
Bram Moolenaar | 795aaa1 | 2020-10-02 20:36:01 +0200 | [diff] [blame] | 1084 | func Test_incsearch_substitute_long_line() |
| 1085 | new |
| 1086 | call test_override("char_avail", 1) |
| 1087 | set incsearch |
| 1088 | |
| 1089 | call repeat('x', 100000)->setline(1) |
| 1090 | call feedkeys(':s/\%c', 'xt') |
| 1091 | redraw |
| 1092 | call feedkeys("\<Esc>", 'xt') |
| 1093 | |
| 1094 | call Incsearch_cleanup() |
| 1095 | bwipe! |
| 1096 | endfunc |
| 1097 | |
LemonBoy | a439938 | 2022-04-09 21:04:08 +0100 | [diff] [blame] | 1098 | func Test_hlsearch_cursearch() |
| 1099 | CheckScreendump |
| 1100 | |
| 1101 | let lines =<< trim END |
| 1102 | set hlsearch scrolloff=0 |
Bram Moolenaar | 9b36750 | 2022-04-22 20:07:21 +0100 | [diff] [blame] | 1103 | call setline(1, ['one', 'foo', 'bar', 'baz', 'foo the foo and foo', 'bar']) |
LemonBoy | a439938 | 2022-04-09 21:04:08 +0100 | [diff] [blame] | 1104 | hi Search ctermbg=yellow |
| 1105 | hi CurSearch ctermbg=blue |
| 1106 | END |
| 1107 | call writefile(lines, 'Xhlsearch_cursearch') |
| 1108 | let buf = RunVimInTerminal('-S Xhlsearch_cursearch', {'rows': 9, 'cols': 60}) |
| 1109 | |
| 1110 | call term_sendkeys(buf, "gg/foo\<CR>") |
| 1111 | call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_1', {}) |
| 1112 | |
| 1113 | call term_sendkeys(buf, "n") |
| 1114 | call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_2', {}) |
| 1115 | |
Bram Moolenaar | 9b36750 | 2022-04-22 20:07:21 +0100 | [diff] [blame] | 1116 | call term_sendkeys(buf, "n") |
| 1117 | call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_2a', {}) |
| 1118 | |
| 1119 | call term_sendkeys(buf, "n") |
| 1120 | call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_2b', {}) |
| 1121 | |
| 1122 | call term_sendkeys(buf, ":call setline(5, 'foo')\<CR>") |
| 1123 | call term_sendkeys(buf, "0?\<CR>") |
LemonBoy | a439938 | 2022-04-09 21:04:08 +0100 | [diff] [blame] | 1124 | call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_3', {}) |
| 1125 | |
| 1126 | call term_sendkeys(buf, "gg/foo\\nbar\<CR>") |
Bram Moolenaar | 693ccd1 | 2022-04-16 12:04:37 +0100 | [diff] [blame] | 1127 | call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_multiple_line_1', {}) |
| 1128 | |
| 1129 | call term_sendkeys(buf, ":call setline(1, ['---', 'abcdefg', 'hijkl', '---', 'abcdefg', 'hijkl'])\<CR>") |
| 1130 | call term_sendkeys(buf, "gg/efg\\nhij\<CR>") |
| 1131 | call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_multiple_line_2', {}) |
| 1132 | call term_sendkeys(buf, "h\<C-L>") |
| 1133 | call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_multiple_line_3', {}) |
| 1134 | call term_sendkeys(buf, "j\<C-L>") |
| 1135 | call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_multiple_line_4', {}) |
| 1136 | call term_sendkeys(buf, "h\<C-L>") |
| 1137 | call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_multiple_line_5', {}) |
LemonBoy | a439938 | 2022-04-09 21:04:08 +0100 | [diff] [blame] | 1138 | |
Bram Moolenaar | 368137a | 2022-05-31 13:43:12 +0100 | [diff] [blame] | 1139 | " check clearing CurSearch when using it for another match |
| 1140 | call term_sendkeys(buf, "G?^abcd\<CR>Y") |
| 1141 | call term_sendkeys(buf, "kkP") |
| 1142 | call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_changed_1', {}) |
| 1143 | |
LemonBoy | a439938 | 2022-04-09 21:04:08 +0100 | [diff] [blame] | 1144 | call StopVimInTerminal(buf) |
| 1145 | call delete('Xhlsearch_cursearch') |
| 1146 | endfunc |
| 1147 | |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 1148 | " Similar to Test_incsearch_substitute() but with a screendump halfway. |
| 1149 | func Test_incsearch_substitute_dump() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 1150 | CheckOption incsearch |
| 1151 | CheckScreendump |
| 1152 | |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 1153 | call writefile([ |
| 1154 | \ 'set incsearch hlsearch scrolloff=0', |
| 1155 | \ 'for n in range(1, 10)', |
| 1156 | \ ' call setline(n, "foo " . n)', |
| 1157 | \ 'endfor', |
Bram Moolenaar | 2f6a346 | 2018-08-14 18:16:52 +0200 | [diff] [blame] | 1158 | \ 'call setline(11, "bar 11")', |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 1159 | \ '3', |
| 1160 | \ ], 'Xis_subst_script') |
| 1161 | let buf = RunVimInTerminal('-S Xis_subst_script', {'rows': 9, 'cols': 70}) |
| 1162 | " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by |
| 1163 | " the 'ambiwidth' check. |
| 1164 | sleep 100m |
| 1165 | |
| 1166 | " Need to send one key at a time to force a redraw. |
Bram Moolenaar | c7f08b7 | 2018-08-12 17:39:14 +0200 | [diff] [blame] | 1167 | " Select three lines at the cursor with typed pattern. |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 1168 | call term_sendkeys(buf, ':.,.+2s/') |
| 1169 | sleep 100m |
| 1170 | call term_sendkeys(buf, 'f') |
| 1171 | sleep 100m |
| 1172 | call term_sendkeys(buf, 'o') |
| 1173 | sleep 100m |
| 1174 | call term_sendkeys(buf, 'o') |
| 1175 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_01', {}) |
Bram Moolenaar | c7f08b7 | 2018-08-12 17:39:14 +0200 | [diff] [blame] | 1176 | call term_sendkeys(buf, "\<Esc>") |
| 1177 | |
| 1178 | " Select three lines at the cursor using previous pattern. |
| 1179 | call term_sendkeys(buf, "/foo\<CR>") |
| 1180 | sleep 100m |
| 1181 | call term_sendkeys(buf, ':.,.+2s//') |
Bram Moolenaar | c7f08b7 | 2018-08-12 17:39:14 +0200 | [diff] [blame] | 1182 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_02', {}) |
| 1183 | |
| 1184 | " Deleting last slash should remove the match. |
| 1185 | call term_sendkeys(buf, "\<BS>") |
Bram Moolenaar | c7f08b7 | 2018-08-12 17:39:14 +0200 | [diff] [blame] | 1186 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_03', {}) |
Bram Moolenaar | 60d0871 | 2018-08-12 21:53:15 +0200 | [diff] [blame] | 1187 | call term_sendkeys(buf, "\<Esc>") |
| 1188 | |
| 1189 | " Reverse range is accepted |
| 1190 | call term_sendkeys(buf, ':5,2s/foo') |
Bram Moolenaar | 60d0871 | 2018-08-12 21:53:15 +0200 | [diff] [blame] | 1191 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_04', {}) |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 1192 | call term_sendkeys(buf, "\<Esc>") |
Bram Moolenaar | 2b926fc | 2018-08-13 11:07:57 +0200 | [diff] [blame] | 1193 | |
| 1194 | " White space after the command is skipped |
| 1195 | call term_sendkeys(buf, ':2,3sub /fo') |
Bram Moolenaar | 2b926fc | 2018-08-13 11:07:57 +0200 | [diff] [blame] | 1196 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_05', {}) |
| 1197 | call term_sendkeys(buf, "\<Esc>") |
| 1198 | |
Bram Moolenaar | 33c4dbb | 2018-08-14 16:06:16 +0200 | [diff] [blame] | 1199 | " Command modifiers are skipped |
| 1200 | 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] | 1201 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_06', {}) |
| 1202 | call term_sendkeys(buf, "\<Esc>") |
| 1203 | |
Bram Moolenaar | 2f6a346 | 2018-08-14 18:16:52 +0200 | [diff] [blame] | 1204 | " Cursorline highlighting at match |
| 1205 | call term_sendkeys(buf, ":set cursorline\<CR>") |
| 1206 | call term_sendkeys(buf, 'G9G') |
| 1207 | call term_sendkeys(buf, ':9,11s/bar') |
Bram Moolenaar | 2f6a346 | 2018-08-14 18:16:52 +0200 | [diff] [blame] | 1208 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_07', {}) |
| 1209 | call term_sendkeys(buf, "\<Esc>") |
| 1210 | |
| 1211 | " Cursorline highlighting at cursor when no match |
| 1212 | call term_sendkeys(buf, ':9,10s/bar') |
Bram Moolenaar | 2f6a346 | 2018-08-14 18:16:52 +0200 | [diff] [blame] | 1213 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_08', {}) |
| 1214 | call term_sendkeys(buf, "\<Esc>") |
| 1215 | |
Bram Moolenaar | 8b0d5ce | 2018-08-22 23:05:44 +0200 | [diff] [blame] | 1216 | " Only \v handled as empty pattern, does not move cursor |
| 1217 | call term_sendkeys(buf, '3G4G') |
| 1218 | call term_sendkeys(buf, ":nohlsearch\<CR>") |
| 1219 | call term_sendkeys(buf, ':6,7s/\v') |
Bram Moolenaar | 8b0d5ce | 2018-08-22 23:05:44 +0200 | [diff] [blame] | 1220 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_09', {}) |
| 1221 | call term_sendkeys(buf, "\<Esc>") |
| 1222 | |
Bram Moolenaar | f13daa4 | 2018-08-31 22:09:54 +0200 | [diff] [blame] | 1223 | call term_sendkeys(buf, ":set nocursorline\<CR>") |
| 1224 | |
| 1225 | " All matches are highlighted for 'hlsearch' after the incsearch canceled |
| 1226 | call term_sendkeys(buf, "1G*") |
| 1227 | call term_sendkeys(buf, ":2,5s/foo") |
| 1228 | sleep 100m |
| 1229 | call term_sendkeys(buf, "\<Esc>") |
| 1230 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_10', {}) |
| 1231 | |
Bram Moolenaar | 65985ac | 2018-09-16 17:08:04 +0200 | [diff] [blame] | 1232 | call term_sendkeys(buf, ":split\<CR>") |
| 1233 | call term_sendkeys(buf, ":let @/ = 'xyz'\<CR>") |
| 1234 | call term_sendkeys(buf, ":%s/.") |
| 1235 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_11', {}) |
| 1236 | call term_sendkeys(buf, "\<BS>") |
| 1237 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_12', {}) |
| 1238 | call term_sendkeys(buf, "\<Esc>") |
| 1239 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_13', {}) |
Bram Moolenaar | c672525 | 2019-11-23 21:56:46 +0100 | [diff] [blame] | 1240 | call term_sendkeys(buf, ":%bwipe!\<CR>") |
| 1241 | call term_sendkeys(buf, ":only!\<CR>") |
| 1242 | |
| 1243 | " get :'<,'>s command in history |
| 1244 | call term_sendkeys(buf, ":set cmdheight=2\<CR>") |
| 1245 | call term_sendkeys(buf, "aasdfasdf\<Esc>") |
| 1246 | call term_sendkeys(buf, "V:s/a/b/g\<CR>") |
| 1247 | " Using '<,'> does not give E20 |
| 1248 | call term_sendkeys(buf, ":new\<CR>") |
| 1249 | call term_sendkeys(buf, "aasdfasdf\<Esc>") |
| 1250 | call term_sendkeys(buf, ":\<Up>\<Up>") |
| 1251 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_14', {}) |
| 1252 | call term_sendkeys(buf, "<Esc>") |
Bram Moolenaar | 65985ac | 2018-09-16 17:08:04 +0200 | [diff] [blame] | 1253 | |
Bram Moolenaar | 164251f | 2018-08-12 16:26:58 +0200 | [diff] [blame] | 1254 | call StopVimInTerminal(buf) |
| 1255 | call delete('Xis_subst_script') |
| 1256 | endfunc |
| 1257 | |
Bram Moolenaar | c036e87 | 2020-02-21 21:30:52 +0100 | [diff] [blame] | 1258 | func Test_incsearch_highlighting() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 1259 | CheckOption incsearch |
| 1260 | CheckScreendump |
Bram Moolenaar | c036e87 | 2020-02-21 21:30:52 +0100 | [diff] [blame] | 1261 | |
| 1262 | call writefile([ |
| 1263 | \ 'set incsearch hlsearch', |
| 1264 | \ 'call setline(1, "hello/there")', |
| 1265 | \ ], 'Xis_subst_hl_script') |
| 1266 | let buf = RunVimInTerminal('-S Xis_subst_hl_script', {'rows': 4, 'cols': 20}) |
| 1267 | " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by |
| 1268 | " the 'ambiwidth' check. |
| 1269 | sleep 300m |
| 1270 | |
| 1271 | " Using a different search delimiter should still highlight matches |
| 1272 | " that contain a '/'. |
| 1273 | call term_sendkeys(buf, ":%s;ello/the") |
| 1274 | call VerifyScreenDump(buf, 'Test_incsearch_substitute_15', {}) |
| 1275 | call term_sendkeys(buf, "<Esc>") |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 1276 | |
| 1277 | call StopVimInTerminal(buf) |
| 1278 | call delete('Xis_subst_hl_script') |
Bram Moolenaar | c036e87 | 2020-02-21 21:30:52 +0100 | [diff] [blame] | 1279 | endfunc |
| 1280 | |
Bram Moolenaar | 4a7d2d3 | 2019-02-21 16:25:50 +0100 | [diff] [blame] | 1281 | func Test_incsearch_with_change() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 1282 | CheckFeature timers |
| 1283 | CheckOption incsearch |
| 1284 | CheckScreendump |
Bram Moolenaar | 4a7d2d3 | 2019-02-21 16:25:50 +0100 | [diff] [blame] | 1285 | |
| 1286 | call writefile([ |
| 1287 | \ 'set incsearch hlsearch scrolloff=0', |
| 1288 | \ 'call setline(1, ["one", "two ------ X", "three"])', |
| 1289 | \ 'call timer_start(200, { _ -> setline(2, "x")})', |
| 1290 | \ ], 'Xis_change_script') |
| 1291 | let buf = RunVimInTerminal('-S Xis_change_script', {'rows': 9, 'cols': 70}) |
| 1292 | " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by |
| 1293 | " the 'ambiwidth' check. |
Bram Moolenaar | e86ecbd | 2019-02-21 17:48:59 +0100 | [diff] [blame] | 1294 | sleep 300m |
Bram Moolenaar | 4a7d2d3 | 2019-02-21 16:25:50 +0100 | [diff] [blame] | 1295 | |
| 1296 | " Highlight X, it will be deleted by the timer callback. |
| 1297 | call term_sendkeys(buf, ':%s/X') |
| 1298 | call VerifyScreenDump(buf, 'Test_incsearch_change_01', {}) |
| 1299 | call term_sendkeys(buf, "\<Esc>") |
| 1300 | |
| 1301 | call StopVimInTerminal(buf) |
| 1302 | call delete('Xis_change_script') |
| 1303 | endfunc |
| 1304 | |
Bram Moolenaar | 81f5653 | 2018-08-18 16:19:42 +0200 | [diff] [blame] | 1305 | " Similar to Test_incsearch_substitute_dump() for :sort |
Bram Moolenaar | 4edfe2d | 2018-08-23 20:55:45 +0200 | [diff] [blame] | 1306 | func Test_incsearch_sort_dump() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 1307 | CheckOption incsearch |
| 1308 | CheckScreendump |
| 1309 | |
Bram Moolenaar | 81f5653 | 2018-08-18 16:19:42 +0200 | [diff] [blame] | 1310 | call writefile([ |
| 1311 | \ 'set incsearch hlsearch scrolloff=0', |
| 1312 | \ 'call setline(1, ["another one 2", "that one 3", "the one 1"])', |
| 1313 | \ ], 'Xis_sort_script') |
| 1314 | let buf = RunVimInTerminal('-S Xis_sort_script', {'rows': 9, 'cols': 70}) |
| 1315 | " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by |
| 1316 | " the 'ambiwidth' check. |
| 1317 | sleep 100m |
| 1318 | |
Bram Moolenaar | 81f5653 | 2018-08-18 16:19:42 +0200 | [diff] [blame] | 1319 | call term_sendkeys(buf, ':sort ni u /on') |
Bram Moolenaar | 81f5653 | 2018-08-18 16:19:42 +0200 | [diff] [blame] | 1320 | call VerifyScreenDump(buf, 'Test_incsearch_sort_01', {}) |
| 1321 | call term_sendkeys(buf, "\<Esc>") |
| 1322 | |
Bram Moolenaar | 333015a | 2020-04-25 15:54:16 +0200 | [diff] [blame] | 1323 | call term_sendkeys(buf, ':sort! /on') |
| 1324 | call VerifyScreenDump(buf, 'Test_incsearch_sort_02', {}) |
| 1325 | call term_sendkeys(buf, "\<Esc>") |
| 1326 | |
Bram Moolenaar | 81f5653 | 2018-08-18 16:19:42 +0200 | [diff] [blame] | 1327 | call StopVimInTerminal(buf) |
| 1328 | call delete('Xis_sort_script') |
| 1329 | endfunc |
| 1330 | |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1331 | " Similar to Test_incsearch_substitute_dump() for :vimgrep famiry |
| 1332 | func Test_incsearch_vimgrep_dump() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 1333 | CheckOption incsearch |
| 1334 | CheckScreendump |
| 1335 | |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1336 | call writefile([ |
| 1337 | \ 'set incsearch hlsearch scrolloff=0', |
| 1338 | \ 'call setline(1, ["another one 2", "that one 3", "the one 1"])', |
| 1339 | \ ], 'Xis_vimgrep_script') |
| 1340 | let buf = RunVimInTerminal('-S Xis_vimgrep_script', {'rows': 9, 'cols': 70}) |
| 1341 | " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by |
| 1342 | " the 'ambiwidth' check. |
| 1343 | sleep 100m |
| 1344 | |
| 1345 | " Need to send one key at a time to force a redraw. |
| 1346 | call term_sendkeys(buf, ':vimgrep on') |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1347 | call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_01', {}) |
| 1348 | call term_sendkeys(buf, "\<Esc>") |
| 1349 | |
| 1350 | call term_sendkeys(buf, ':vimg /on/ *.txt') |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1351 | call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_02', {}) |
| 1352 | call term_sendkeys(buf, "\<Esc>") |
| 1353 | |
| 1354 | call term_sendkeys(buf, ':vimgrepadd "\<on') |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1355 | call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_03', {}) |
| 1356 | call term_sendkeys(buf, "\<Esc>") |
| 1357 | |
| 1358 | call term_sendkeys(buf, ':lv "tha') |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1359 | call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_04', {}) |
| 1360 | call term_sendkeys(buf, "\<Esc>") |
| 1361 | |
| 1362 | call term_sendkeys(buf, ':lvimgrepa "the" **/*.txt') |
Bram Moolenaar | 264cf5c | 2018-08-18 21:05:31 +0200 | [diff] [blame] | 1363 | call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_05', {}) |
| 1364 | call term_sendkeys(buf, "\<Esc>") |
| 1365 | |
| 1366 | call StopVimInTerminal(buf) |
| 1367 | call delete('Xis_vimgrep_script') |
| 1368 | endfunc |
| 1369 | |
Bram Moolenaar | 198cb66 | 2018-09-06 21:44:17 +0200 | [diff] [blame] | 1370 | func Test_keep_last_search_pattern() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 1371 | CheckOption incsearch |
| 1372 | |
Bram Moolenaar | 198cb66 | 2018-09-06 21:44:17 +0200 | [diff] [blame] | 1373 | new |
| 1374 | call setline(1, ['foo', 'foo', 'foo']) |
| 1375 | set incsearch |
| 1376 | call test_override("char_avail", 1) |
| 1377 | let @/ = 'bar' |
| 1378 | call feedkeys(":/foo/s//\<Esc>", 'ntx') |
| 1379 | call assert_equal('bar', @/) |
| 1380 | |
Bram Moolenaar | 50eb16c | 2018-09-15 15:42:40 +0200 | [diff] [blame] | 1381 | " no error message if pattern not found |
| 1382 | call feedkeys(":/xyz/s//\<Esc>", 'ntx') |
| 1383 | call assert_equal('bar', @/) |
| 1384 | |
Bram Moolenaar | 198cb66 | 2018-09-06 21:44:17 +0200 | [diff] [blame] | 1385 | bwipe! |
| 1386 | call test_override("ALL", 0) |
| 1387 | set noincsearch |
| 1388 | endfunc |
| 1389 | |
Bram Moolenaar | 99f043a | 2018-09-09 15:54:14 +0200 | [diff] [blame] | 1390 | func Test_word_under_cursor_after_match() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 1391 | CheckOption incsearch |
| 1392 | |
Bram Moolenaar | 99f043a | 2018-09-09 15:54:14 +0200 | [diff] [blame] | 1393 | new |
| 1394 | call setline(1, 'foo bar') |
| 1395 | set incsearch |
| 1396 | call test_override("char_avail", 1) |
| 1397 | try |
| 1398 | call feedkeys("/foo\<C-R>\<C-W>\<CR>", 'ntx') |
| 1399 | catch /E486:/ |
| 1400 | endtry |
| 1401 | call assert_equal('foobar', @/) |
| 1402 | |
| 1403 | bwipe! |
| 1404 | call test_override("ALL", 0) |
| 1405 | set noincsearch |
| 1406 | endfunc |
| 1407 | |
| 1408 | func Test_subst_word_under_cursor() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 1409 | CheckOption incsearch |
| 1410 | |
Bram Moolenaar | 99f043a | 2018-09-09 15:54:14 +0200 | [diff] [blame] | 1411 | new |
| 1412 | call setline(1, ['int SomeLongName;', 'for (xxx = 1; xxx < len; ++xxx)']) |
| 1413 | set incsearch |
| 1414 | call test_override("char_avail", 1) |
| 1415 | call feedkeys("/LongName\<CR>", 'ntx') |
| 1416 | call feedkeys(":%s/xxx/\<C-R>\<C-W>/g\<CR>", 'ntx') |
| 1417 | call assert_equal('for (SomeLongName = 1; SomeLongName < len; ++SomeLongName)', getline(2)) |
| 1418 | |
| 1419 | bwipe! |
| 1420 | call test_override("ALL", 0) |
| 1421 | set noincsearch |
| 1422 | endfunc |
| 1423 | |
Bram Moolenaar | f45938c | 2017-11-02 15:59:57 +0100 | [diff] [blame] | 1424 | func Test_search_undefined_behaviour() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 1425 | CheckFeature terminal |
| 1426 | |
Bram Moolenaar | f45938c | 2017-11-02 15:59:57 +0100 | [diff] [blame] | 1427 | let h = winheight(0) |
| 1428 | if h < 3 |
| 1429 | return |
| 1430 | endif |
| 1431 | " did cause an undefined left shift |
| 1432 | let g:buf = term_start([GetVimProg(), '--clean', '-e', '-s', '-c', 'call search(getline("."))', 'samples/test000'], {'term_rows': 3}) |
| 1433 | call assert_equal([''], getline(1, '$')) |
| 1434 | call term_sendkeys(g:buf, ":qa!\<cr>") |
| 1435 | bwipe! |
| 1436 | endfunc |
Bram Moolenaar | 2973daa | 2017-11-02 23:15:40 +0100 | [diff] [blame] | 1437 | |
| 1438 | func Test_search_undefined_behaviour2() |
| 1439 | call search("\%UC0000000") |
| 1440 | endfunc |
Bram Moolenaar | fb094e1 | 2017-11-05 20:59:28 +0100 | [diff] [blame] | 1441 | |
| 1442 | " Test for search('multi-byte char', 'bce') |
| 1443 | func Test_search_multibyte() |
Bram Moolenaar | fb094e1 | 2017-11-05 20:59:28 +0100 | [diff] [blame] | 1444 | let save_enc = &encoding |
| 1445 | set encoding=utf8 |
| 1446 | enew! |
| 1447 | call append('$', 'A') |
| 1448 | call cursor(2, 1) |
| 1449 | call assert_equal(2, search('A', 'bce', line('.'))) |
| 1450 | enew! |
| 1451 | let &encoding = save_enc |
| 1452 | endfunc |
Bram Moolenaar | 890dd05 | 2017-12-16 19:59:37 +0100 | [diff] [blame] | 1453 | |
| 1454 | " This was causing E874. Also causes an invalid read? |
| 1455 | func Test_look_behind() |
| 1456 | new |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 1457 | call setline(1, '0\|\&\n\@<=') |
Bram Moolenaar | 890dd05 | 2017-12-16 19:59:37 +0100 | [diff] [blame] | 1458 | call search(getline(".")) |
| 1459 | bwipe! |
| 1460 | endfunc |
Bram Moolenaar | 8ada6aa | 2017-12-19 21:23:21 +0100 | [diff] [blame] | 1461 | |
Bram Moolenaar | 872bee5 | 2021-05-24 22:56:15 +0200 | [diff] [blame] | 1462 | func Test_search_visual_area_linewise() |
| 1463 | new |
| 1464 | call setline(1, ['aa', 'bb', 'cc']) |
| 1465 | exe "normal 2GV\<Esc>" |
| 1466 | for engine in [1, 2] |
| 1467 | exe 'set regexpengine=' .. engine |
| 1468 | exe "normal gg/\\%'<\<CR>>" |
| 1469 | call assert_equal([0, 2, 1, 0, 1], getcurpos(), 'engine ' .. engine) |
| 1470 | exe "normal gg/\\%'>\<CR>" |
| 1471 | call assert_equal([0, 2, 2, 0, 2], getcurpos(), 'engine ' .. engine) |
| 1472 | endfor |
| 1473 | |
| 1474 | bwipe! |
| 1475 | set regexpengine& |
| 1476 | endfunc |
| 1477 | |
Bram Moolenaar | 8ada6aa | 2017-12-19 21:23:21 +0100 | [diff] [blame] | 1478 | func Test_search_sentence() |
| 1479 | new |
| 1480 | " this used to cause a crash |
Bram Moolenaar | 1bd999f | 2017-12-19 22:25:40 +0100 | [diff] [blame] | 1481 | /\%'( |
| 1482 | / |
Bram Moolenaar | 872bee5 | 2021-05-24 22:56:15 +0200 | [diff] [blame] | 1483 | bwipe |
Bram Moolenaar | 8ada6aa | 2017-12-19 21:23:21 +0100 | [diff] [blame] | 1484 | endfunc |
Bram Moolenaar | 2fb8f68 | 2018-12-01 13:14:45 +0100 | [diff] [blame] | 1485 | |
| 1486 | " Test that there is no crash when there is a last search pattern but no last |
| 1487 | " substitute pattern. |
| 1488 | func Test_no_last_substitute_pat() |
| 1489 | " Use viminfo to set the last search pattern to a string and make the last |
| 1490 | " substitute pattern the most recent used and make it empty (NULL). |
| 1491 | call writefile(['~MSle0/bar', '~MSle0~&'], 'Xviminfo') |
| 1492 | rviminfo! Xviminfo |
| 1493 | call assert_fails('normal n', 'E35:') |
| 1494 | |
| 1495 | call delete('Xviminfo') |
| 1496 | endfunc |
Bram Moolenaar | 5f5e203 | 2018-12-14 15:47:03 +0100 | [diff] [blame] | 1497 | |
| 1498 | func Test_search_Ctrl_L_combining() |
| 1499 | " Make sure, that Ctrl-L works correctly with combining characters. |
| 1500 | " It uses an artificial example of an 'a' with 4 combining chars: |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 1501 | " '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] | 1502 | " ' ̀' U+0300 Dec:768 COMBINING GRAVE ACCENT ̀ /\%u300\Z "\u0300" |
| 1503 | " ' ́' U+0301 Dec:769 COMBINING ACUTE ACCENT ́ /\%u301\Z "\u0301" |
| 1504 | " ' ̇' U+0307 Dec:775 COMBINING DOT ABOVE ̇ /\%u307\Z "\u0307" |
Bram Moolenaar | 3ba3540 | 2019-12-21 22:00:50 +0100 | [diff] [blame] | 1505 | " ' ̣' U+0323 Dec:803 COMBINING DOT BELOW ̣ /\%u323 "\u0323" |
Bram Moolenaar | 5f5e203 | 2018-12-14 15:47:03 +0100 | [diff] [blame] | 1506 | " Those should also appear on the commandline |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 1507 | CheckOption incsearch |
| 1508 | |
Bram Moolenaar | 5f5e203 | 2018-12-14 15:47:03 +0100 | [diff] [blame] | 1509 | call Cmdline3_prep() |
| 1510 | 1 |
| 1511 | let bufcontent = ['', 'Miạ̀́̇m'] |
| 1512 | call append('$', bufcontent) |
| 1513 | call feedkeys("/Mi\<c-l>\<c-l>\<cr>", 'tx') |
| 1514 | call assert_equal(5, line('.')) |
| 1515 | call assert_equal(bufcontent[1], @/) |
| 1516 | call Incsearch_cleanup() |
| 1517 | endfunc |
Bram Moolenaar | 527a2d8 | 2019-02-21 22:28:51 +0100 | [diff] [blame] | 1518 | |
Bram Moolenaar | ab350f8 | 2019-02-28 06:25:00 +0100 | [diff] [blame] | 1519 | func Test_large_hex_chars1() |
Bram Moolenaar | 527a2d8 | 2019-02-21 22:28:51 +0100 | [diff] [blame] | 1520 | " This used to cause a crash, the character becomes an NFA state. |
| 1521 | try |
| 1522 | /\%Ufffffc23 |
| 1523 | catch |
| 1524 | call assert_match('E678:', v:exception) |
| 1525 | endtry |
Bram Moolenaar | ab350f8 | 2019-02-28 06:25:00 +0100 | [diff] [blame] | 1526 | try |
| 1527 | set re=1 |
| 1528 | /\%Ufffffc23 |
| 1529 | catch |
| 1530 | call assert_match('E678:', v:exception) |
| 1531 | endtry |
| 1532 | set re& |
| 1533 | endfunc |
| 1534 | |
| 1535 | func Test_large_hex_chars2() |
| 1536 | " This used to cause a crash, the character becomes an NFA state. |
| 1537 | try |
| 1538 | /[\Ufffffc1f] |
| 1539 | catch |
| 1540 | call assert_match('E486:', v:exception) |
| 1541 | endtry |
| 1542 | try |
| 1543 | set re=1 |
| 1544 | /[\Ufffffc1f] |
| 1545 | catch |
| 1546 | call assert_match('E486:', v:exception) |
| 1547 | endtry |
| 1548 | set re& |
Bram Moolenaar | 527a2d8 | 2019-02-21 22:28:51 +0100 | [diff] [blame] | 1549 | endfunc |
Bram Moolenaar | cd62512 | 2019-02-22 17:29:43 +0100 | [diff] [blame] | 1550 | |
| 1551 | func Test_one_error_msg() |
Bram Moolenaar | 8832a34 | 2020-04-11 18:36:38 +0200 | [diff] [blame] | 1552 | " This was also giving an internal error |
Bram Moolenaar | cd62512 | 2019-02-22 17:29:43 +0100 | [diff] [blame] | 1553 | call assert_fails('call search(" \\((\\v[[=P=]]){185}+ ")', 'E871:') |
| 1554 | endfunc |
Bram Moolenaar | 730f48f | 2019-04-11 13:45:57 +0200 | [diff] [blame] | 1555 | |
| 1556 | func Test_incsearch_add_char_under_cursor() |
Bram Moolenaar | b68df22 | 2020-03-19 15:05:28 +0100 | [diff] [blame] | 1557 | CheckOption incsearch |
| 1558 | |
Bram Moolenaar | 730f48f | 2019-04-11 13:45:57 +0200 | [diff] [blame] | 1559 | set incsearch |
| 1560 | new |
| 1561 | call setline(1, ['find match', 'anything']) |
| 1562 | 1 |
| 1563 | call test_override('char_avail', 1) |
| 1564 | call feedkeys("fc/m\<C-L>\<C-L>\<C-L>\<C-L>\<C-L>\<CR>", 'tx') |
| 1565 | call assert_equal('match', @/) |
| 1566 | call test_override('char_avail', 0) |
| 1567 | |
| 1568 | set incsearch& |
| 1569 | bwipe! |
| 1570 | endfunc |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 1571 | |
| 1572 | " Test for the search() function with match at the cursor position |
| 1573 | func Test_search_match_at_curpos() |
| 1574 | new |
| 1575 | call append(0, ['foobar', '', 'one two', '']) |
| 1576 | |
| 1577 | normal gg |
| 1578 | |
Bram Moolenaar | 196b466 | 2019-09-06 21:34:30 +0200 | [diff] [blame] | 1579 | eval 'foobar'->search('c') |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 1580 | call assert_equal([1, 1], [line('.'), col('.')]) |
| 1581 | |
| 1582 | normal j |
| 1583 | call search('^$', 'c') |
| 1584 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1585 | |
| 1586 | call search('^$', 'bc') |
| 1587 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1588 | |
| 1589 | exe "normal /two\<CR>" |
| 1590 | call search('.', 'c') |
| 1591 | call assert_equal([3, 5], [line('.'), col('.')]) |
| 1592 | |
| 1593 | close! |
| 1594 | endfunc |
Bram Moolenaar | db294ad | 2019-06-06 12:49:29 +0200 | [diff] [blame] | 1595 | |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 1596 | " Test for error cases with the search() function |
| 1597 | func Test_search_errors() |
| 1598 | call assert_fails("call search('pat', [])", 'E730:') |
| 1599 | call assert_fails("call search('pat', 'b', {})", 'E728:') |
| 1600 | call assert_fails("call search('pat', 'b', 1, [])", 'E745:') |
| 1601 | call assert_fails("call search('pat', 'ns')", 'E475:') |
| 1602 | call assert_fails("call search('pat', 'mr')", 'E475:') |
Bram Moolenaar | 8832a34 | 2020-04-11 18:36:38 +0200 | [diff] [blame] | 1603 | |
| 1604 | new |
| 1605 | call setline(1, ['foo', 'bar']) |
| 1606 | call assert_fails('call feedkeys("/foo/;/bar/;\<CR>", "tx")', 'E386:') |
| 1607 | bwipe! |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 1608 | endfunc |
| 1609 | |
Paul Ollis | 6574577 | 2022-06-05 16:55:54 +0100 | [diff] [blame] | 1610 | func Test_search_timeout() |
Bram Moolenaar | 73171ba | 2022-06-20 12:39:39 +0100 | [diff] [blame] | 1611 | let g:test_is_flaky = 1 |
Paul Ollis | 6574577 | 2022-06-05 16:55:54 +0100 | [diff] [blame] | 1612 | new |
Bram Moolenaar | 616592e | 2022-06-17 15:17:10 +0100 | [diff] [blame] | 1613 | " use a complicated pattern that should be slow with the BT engine |
Paul Ollis | 6574577 | 2022-06-05 16:55:54 +0100 | [diff] [blame] | 1614 | let pattern = '\%#=1a*.*X\@<=b*' |
Bram Moolenaar | 616592e | 2022-06-17 15:17:10 +0100 | [diff] [blame] | 1615 | |
| 1616 | " use a timeout of 50 msec |
| 1617 | let search_timeout = 0.05 |
| 1618 | |
| 1619 | " fill the buffer so that it takes 15 times the timeout to search |
Paul Ollis | 6574577 | 2022-06-05 16:55:54 +0100 | [diff] [blame] | 1620 | let slow_target_timeout = search_timeout * 15.0 |
| 1621 | |
Bram Moolenaar | 616592e | 2022-06-17 15:17:10 +0100 | [diff] [blame] | 1622 | " Fill the buffer with more and more text until searching takes more time |
| 1623 | " than slow_target_timeout. |
Paul Ollis | 6574577 | 2022-06-05 16:55:54 +0100 | [diff] [blame] | 1624 | for n in range(40, 400, 30) |
| 1625 | call setline(1, ['aaa', repeat('abc ', n), 'ccc']) |
| 1626 | let start = reltime() |
| 1627 | call search(pattern, '', 0) |
| 1628 | let elapsed = reltimefloat(reltime(start)) |
| 1629 | if elapsed > slow_target_timeout |
| 1630 | break |
| 1631 | endif |
| 1632 | endfor |
| 1633 | call assert_true(elapsed > slow_target_timeout) |
| 1634 | |
Bram Moolenaar | 616592e | 2022-06-17 15:17:10 +0100 | [diff] [blame] | 1635 | " Check that the timeout kicks in, the time should be less than half of what |
| 1636 | " we measured without the timeout. This is permissive, because the timer is |
| 1637 | " known to overrun, especially when using valgrind. |
Paul Ollis | 6574577 | 2022-06-05 16:55:54 +0100 | [diff] [blame] | 1638 | let max_time = elapsed / 2.0 |
| 1639 | let start = reltime() |
| 1640 | call search(pattern, '', 0, float2nr(search_timeout * 1000)) |
| 1641 | let elapsed = reltimefloat(reltime(start)) |
Bram Moolenaar | 616592e | 2022-06-17 15:17:10 +0100 | [diff] [blame] | 1642 | call assert_inrange(search_timeout * 0.9, max_time, elapsed) |
Paul Ollis | 6574577 | 2022-06-05 16:55:54 +0100 | [diff] [blame] | 1643 | |
| 1644 | bwipe! |
| 1645 | endfunc |
| 1646 | |
Bram Moolenaar | db294ad | 2019-06-06 12:49:29 +0200 | [diff] [blame] | 1647 | func Test_search_display_pattern() |
| 1648 | new |
| 1649 | call setline(1, ['foo', 'bar', 'foobar']) |
| 1650 | |
| 1651 | call cursor(1, 1) |
| 1652 | let @/ = 'foo' |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1653 | let pat = @/->escape('()*?'. '\s\+') |
Bram Moolenaar | db294ad | 2019-06-06 12:49:29 +0200 | [diff] [blame] | 1654 | let g:a = execute(':unsilent :norm! n') |
| 1655 | call assert_match(pat, g:a) |
| 1656 | |
| 1657 | " right-left |
| 1658 | if exists("+rightleft") |
| 1659 | set rl |
| 1660 | call cursor(1, 1) |
| 1661 | let @/ = 'foo' |
| 1662 | let pat = 'oof/\s\+' |
| 1663 | let g:a = execute(':unsilent :norm! n') |
| 1664 | call assert_match(pat, g:a) |
| 1665 | set norl |
| 1666 | endif |
| 1667 | endfunc |
Bram Moolenaar | 196b466 | 2019-09-06 21:34:30 +0200 | [diff] [blame] | 1668 | |
| 1669 | func Test_searchdecl() |
| 1670 | let lines =<< trim END |
| 1671 | int global; |
| 1672 | |
| 1673 | func() |
| 1674 | { |
| 1675 | int global; |
| 1676 | if (cond) { |
| 1677 | int local; |
| 1678 | } |
| 1679 | int local; |
| 1680 | // comment |
| 1681 | } |
| 1682 | END |
| 1683 | new |
| 1684 | call setline(1, lines) |
| 1685 | 10 |
| 1686 | call assert_equal(0, searchdecl('local', 0, 0)) |
| 1687 | call assert_equal(7, getcurpos()[1]) |
| 1688 | |
| 1689 | 10 |
| 1690 | call assert_equal(0, 'local'->searchdecl(0, 1)) |
| 1691 | call assert_equal(9, getcurpos()[1]) |
| 1692 | |
| 1693 | 10 |
| 1694 | call assert_equal(0, searchdecl('global')) |
| 1695 | call assert_equal(5, getcurpos()[1]) |
| 1696 | |
| 1697 | 10 |
| 1698 | call assert_equal(0, searchdecl('global', 1)) |
| 1699 | call assert_equal(1, getcurpos()[1]) |
| 1700 | |
| 1701 | bwipe! |
| 1702 | endfunc |
Bram Moolenaar | 98a336d | 2020-01-20 20:22:30 +0100 | [diff] [blame] | 1703 | |
| 1704 | func Test_search_special() |
Bram Moolenaar | fe4bbac | 2020-01-20 21:12:20 +0100 | [diff] [blame] | 1705 | " this was causing illegal memory access and an endless loop |
| 1706 | set t_PE= |
Bram Moolenaar | 98a336d | 2020-01-20 20:22:30 +0100 | [diff] [blame] | 1707 | exe "norm /\x80PS" |
| 1708 | endfunc |
Bram Moolenaar | 07ada5f | 2020-02-05 20:38:22 +0100 | [diff] [blame] | 1709 | |
| 1710 | " Test for command failures when the last search pattern is not set. |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 1711 | " 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] | 1712 | func Test_search_with_no_last_pat() |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 1713 | let lines =<< trim [SCRIPT] |
| 1714 | call assert_fails("normal i\<C-R>/\e", 'E35:') |
| 1715 | call assert_fails("exe '/'", 'E35:') |
| 1716 | call assert_fails("exe '?'", 'E35:') |
| 1717 | call assert_fails("/", 'E35:') |
| 1718 | call assert_fails("?", 'E35:') |
| 1719 | call assert_fails("normal n", 'E35:') |
| 1720 | call assert_fails("normal N", 'E35:') |
| 1721 | call assert_fails("normal gn", 'E35:') |
| 1722 | call assert_fails("normal gN", 'E35:') |
| 1723 | call assert_fails("normal cgn", 'E35:') |
| 1724 | call assert_fails("normal cgN", 'E35:') |
| 1725 | let p = [] |
| 1726 | let p = @/ |
| 1727 | call assert_equal('', p) |
| 1728 | call assert_fails("normal :\<C-R>/", 'E35:') |
| 1729 | call assert_fails("//p", 'E35:') |
| 1730 | call assert_fails(";//p", 'E35:') |
| 1731 | call assert_fails("??p", 'E35:') |
| 1732 | call assert_fails(";??p", 'E35:') |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1733 | call assert_fails('g//p', ['E35:', 'E476:']) |
| 1734 | call assert_fails('v//p', ['E35:', 'E476:']) |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 1735 | call writefile(v:errors, 'Xresult') |
| 1736 | qall! |
| 1737 | [SCRIPT] |
| 1738 | call writefile(lines, 'Xscript') |
| 1739 | |
| 1740 | if RunVim([], [], '--clean -S Xscript') |
| 1741 | call assert_equal([], readfile('Xresult')) |
| 1742 | endif |
| 1743 | call delete('Xscript') |
| 1744 | call delete('Xresult') |
Bram Moolenaar | 07ada5f | 2020-02-05 20:38:22 +0100 | [diff] [blame] | 1745 | endfunc |
| 1746 | |
| 1747 | " Test for using tilde (~) atom in search. This should use the last used |
| 1748 | " substitute pattern |
| 1749 | func Test_search_tilde_pat() |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 1750 | let lines =<< trim [SCRIPT] |
| 1751 | set regexpengine=1 |
| 1752 | call assert_fails('exe "normal /~\<CR>"', 'E33:') |
| 1753 | call assert_fails('exe "normal ?~\<CR>"', 'E33:') |
| 1754 | set regexpengine=2 |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1755 | call assert_fails('exe "normal /~\<CR>"', ['E33:', 'E383:']) |
| 1756 | call assert_fails('exe "normal ?~\<CR>"', ['E33:', 'E383:']) |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 1757 | set regexpengine& |
| 1758 | call writefile(v:errors, 'Xresult') |
| 1759 | qall! |
| 1760 | [SCRIPT] |
| 1761 | call writefile(lines, 'Xscript') |
| 1762 | if RunVim([], [], '--clean -S Xscript') |
| 1763 | call assert_equal([], readfile('Xresult')) |
| 1764 | endif |
| 1765 | call delete('Xscript') |
| 1766 | call delete('Xresult') |
Bram Moolenaar | 07ada5f | 2020-02-05 20:38:22 +0100 | [diff] [blame] | 1767 | endfunc |
| 1768 | |
Bram Moolenaar | 406cd90 | 2020-02-18 21:54:41 +0100 | [diff] [blame] | 1769 | " Test for searching a pattern that is not present with 'nowrapscan' |
| 1770 | func Test_search_pat_not_found() |
| 1771 | new |
| 1772 | set nowrapscan |
| 1773 | let @/ = '1abcxyz2' |
| 1774 | call assert_fails('normal n', 'E385:') |
| 1775 | call assert_fails('normal N', 'E384:') |
| 1776 | set wrapscan& |
| 1777 | close |
| 1778 | endfunc |
| 1779 | |
| 1780 | " Test for v:searchforward variable |
| 1781 | func Test_searchforward_var() |
| 1782 | new |
| 1783 | call setline(1, ['foo', '', 'foo']) |
| 1784 | call cursor(2, 1) |
| 1785 | let @/ = 'foo' |
| 1786 | let v:searchforward = 0 |
| 1787 | normal N |
| 1788 | call assert_equal(3, line('.')) |
| 1789 | call cursor(2, 1) |
| 1790 | let v:searchforward = 1 |
| 1791 | normal N |
| 1792 | call assert_equal(1, line('.')) |
| 1793 | close! |
| 1794 | endfunc |
| 1795 | |
Bram Moolenaar | 476a613 | 2020-04-08 19:48:56 +0200 | [diff] [blame] | 1796 | " Test for invalid regular expressions |
| 1797 | func Test_invalid_regexp() |
| 1798 | set regexpengine=1 |
| 1799 | call assert_fails("call search(repeat('\\(.\\)', 10))", 'E51:') |
Bram Moolenaar | 4d23c52 | 2020-04-09 18:42:11 +0200 | [diff] [blame] | 1800 | call assert_fails("call search('\\%(')", 'E53:') |
| 1801 | call assert_fails("call search('\\(')", 'E54:') |
| 1802 | call assert_fails("call search('\\)')", 'E55:') |
Bram Moolenaar | 476a613 | 2020-04-08 19:48:56 +0200 | [diff] [blame] | 1803 | call assert_fails("call search('x\\@#')", 'E59:') |
Bram Moolenaar | 4d23c52 | 2020-04-09 18:42:11 +0200 | [diff] [blame] | 1804 | call assert_fails('call search(''\v%(%(%(%(%(%(%(%(%(%(%(a){1}){1}){1}){1}){1}){1}){1}){1}){1}){1}){1}'')', 'E60:') |
| 1805 | call assert_fails("call search('a\\+*')", 'E61:') |
Bram Moolenaar | 476a613 | 2020-04-08 19:48:56 +0200 | [diff] [blame] | 1806 | call assert_fails("call search('\\_m')", 'E63:') |
| 1807 | call assert_fails("call search('\\+')", 'E64:') |
| 1808 | call assert_fails("call search('\\1')", 'E65:') |
| 1809 | call assert_fails("call search('\\z\\(\\)')", 'E66:') |
| 1810 | call assert_fails("call search('\\z2')", 'E67:') |
| 1811 | call assert_fails("call search('\\zx')", 'E68:') |
| 1812 | call assert_fails("call search('\\%[ab')", 'E69:') |
| 1813 | call assert_fails("call search('\\%[]')", 'E70:') |
| 1814 | call assert_fails("call search('\\%a')", 'E71:') |
| 1815 | call assert_fails("call search('ab\\%[\\(cd\\)]')", 'E369:') |
| 1816 | call assert_fails("call search('ab\\%[\\%(cd\\)]')", 'E369:') |
| 1817 | set regexpengine=2 |
| 1818 | call assert_fails("call search('\\_')", 'E865:') |
| 1819 | call assert_fails("call search('\\+')", 'E866:') |
| 1820 | call assert_fails("call search('\\zx')", 'E867:') |
| 1821 | call assert_fails("call search('\\%a')", 'E867:') |
| 1822 | call assert_fails("call search('x\\@#')", 'E869:') |
| 1823 | call assert_fails("call search(repeat('\\(.\\)', 10))", 'E872:') |
| 1824 | call assert_fails("call search('\\_m')", 'E877:') |
| 1825 | call assert_fails("call search('\\%(')", 'E53:') |
| 1826 | call assert_fails("call search('\\(')", 'E54:') |
| 1827 | call assert_fails("call search('\\)')", 'E55:') |
| 1828 | call assert_fails("call search('\\z\\(\\)')", 'E66:') |
Dominique Pelle | 8bfa0eb | 2022-01-02 16:16:33 +0000 | [diff] [blame] | 1829 | call assert_fails("call search('\\z2')", 'E67:') |
| 1830 | call assert_fails("call search('\\zx')", 'E867:') |
Bram Moolenaar | 476a613 | 2020-04-08 19:48:56 +0200 | [diff] [blame] | 1831 | call assert_fails("call search('\\%[ab')", 'E69:') |
Bram Moolenaar | 4d23c52 | 2020-04-09 18:42:11 +0200 | [diff] [blame] | 1832 | call assert_fails("call search('\\%[]')", 'E70:') |
Bram Moolenaar | 476a613 | 2020-04-08 19:48:56 +0200 | [diff] [blame] | 1833 | call assert_fails("call search('\\%9999999999999999999999999999v')", 'E951:') |
| 1834 | set regexpengine& |
| 1835 | call assert_fails("call search('\\%#=3ab')", 'E864:') |
| 1836 | endfunc |
| 1837 | |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 1838 | " Test for searching a very complex pattern in a string. Should switch the |
| 1839 | " regexp engine from NFA to the old engine. |
| 1840 | func Test_regexp_switch_engine() |
| 1841 | let l = readfile('samples/re.freeze.txt') |
| 1842 | let v = substitute(l[4], '..\@<!', '', '') |
| 1843 | call assert_equal(l[4], v) |
| 1844 | endfunc |
| 1845 | |
| 1846 | " Test for the \%V atom to search within visually selected text |
| 1847 | func Test_search_in_visual_area() |
| 1848 | new |
| 1849 | call setline(1, ['foo bar1', 'foo bar2', 'foo bar3', 'foo bar4']) |
| 1850 | exe "normal 2GVjo/\\%Vbar\<CR>\<Esc>" |
| 1851 | call assert_equal([2, 5], [line('.'), col('.')]) |
| 1852 | exe "normal 2GVj$?\\%Vbar\<CR>\<Esc>" |
| 1853 | call assert_equal([3, 5], [line('.'), col('.')]) |
| 1854 | close! |
| 1855 | endfunc |
| 1856 | |
Bram Moolenaar | ea04a6e | 2020-04-23 13:38:02 +0200 | [diff] [blame] | 1857 | " Test for searching with 'smartcase' and 'ignorecase' |
| 1858 | func Test_search_smartcase() |
| 1859 | new |
| 1860 | call setline(1, ['', 'Hello']) |
| 1861 | set noignorecase nosmartcase |
| 1862 | call assert_fails('exe "normal /\\a\\_.\\(.*\\)O\<CR>"', 'E486:') |
| 1863 | |
| 1864 | set ignorecase nosmartcase |
| 1865 | exe "normal /\\a\\_.\\(.*\\)O\<CR>" |
| 1866 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1867 | |
| 1868 | call cursor(1, 1) |
| 1869 | set ignorecase smartcase |
| 1870 | call assert_fails('exe "normal /\\a\\_.\\(.*\\)O\<CR>"', 'E486:') |
| 1871 | |
| 1872 | exe "normal /\\a\\_.\\(.*\\)o\<CR>" |
| 1873 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1874 | |
Bram Moolenaar | 224a5f1 | 2020-04-28 20:29:07 +0200 | [diff] [blame] | 1875 | " Test for using special atoms with 'smartcase' |
| 1876 | call setline(1, ['', ' Hello\ ']) |
| 1877 | call cursor(1, 1) |
| 1878 | call feedkeys('/\_.\%(\uello\)\' .. "\<CR>", 'xt') |
| 1879 | call assert_equal([2, 4], [line('.'), col('.')]) |
| 1880 | |
Bram Moolenaar | ea04a6e | 2020-04-23 13:38:02 +0200 | [diff] [blame] | 1881 | set ignorecase& smartcase& |
| 1882 | close! |
Bram Moolenaar | d66cdcd | 2020-07-26 13:27:16 +0200 | [diff] [blame] | 1883 | endfun |
| 1884 | |
| 1885 | " Test 'smartcase' with utf-8. |
| 1886 | func Test_search_smartcase_utf8() |
| 1887 | new |
| 1888 | let save_enc = &encoding |
| 1889 | set encoding=utf8 ignorecase smartcase |
| 1890 | |
| 1891 | call setline(1, 'Café cafÉ') |
| 1892 | 1s/café/x/g |
| 1893 | call assert_equal('x x', getline(1)) |
| 1894 | |
| 1895 | call setline(1, 'Café cafÉ') |
| 1896 | 1s/cafÉ/x/g |
| 1897 | call assert_equal('Café x', getline(1)) |
| 1898 | |
| 1899 | set ignorecase& smartcase& |
| 1900 | let &encoding = save_enc |
| 1901 | close! |
Bram Moolenaar | ea04a6e | 2020-04-23 13:38:02 +0200 | [diff] [blame] | 1902 | endfunc |
| 1903 | |
| 1904 | " Test searching past the end of a file |
| 1905 | func Test_search_past_eof() |
| 1906 | new |
| 1907 | call setline(1, ['Line']) |
| 1908 | exe "normal /\\n\\zs\<CR>" |
| 1909 | call assert_equal([1, 4], [line('.'), col('.')]) |
| 1910 | close! |
| 1911 | endfunc |
| 1912 | |
Bram Moolenaar | 224a5f1 | 2020-04-28 20:29:07 +0200 | [diff] [blame] | 1913 | " Test for various search offsets |
| 1914 | func Test_search_offset() |
| 1915 | " With /e, for a match in the first column of a line, the cursor should be |
| 1916 | " placed at the end of the previous line. |
| 1917 | new |
| 1918 | call setline(1, ['one two', 'three four']) |
| 1919 | call search('two\_.', 'e') |
| 1920 | call assert_equal([1, 7], [line('.'), col('.')]) |
| 1921 | |
| 1922 | " with cursor at the beginning of the file, use /s+1 |
| 1923 | call cursor(1, 1) |
| 1924 | exe "normal /two/s+1\<CR>" |
| 1925 | call assert_equal([1, 6], [line('.'), col('.')]) |
| 1926 | |
| 1927 | " with cursor at the end of the file, use /e-1 |
| 1928 | call cursor(2, 10) |
| 1929 | exe "normal ?three?e-1\<CR>" |
| 1930 | call assert_equal([2, 4], [line('.'), col('.')]) |
| 1931 | |
| 1932 | " line offset - after the last line |
| 1933 | call cursor(1, 1) |
| 1934 | exe "normal /three/+1\<CR>" |
| 1935 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1936 | |
| 1937 | " line offset - before the first line |
| 1938 | call cursor(2, 1) |
| 1939 | exe "normal ?one?-1\<CR>" |
| 1940 | call assert_equal([1, 1], [line('.'), col('.')]) |
| 1941 | |
| 1942 | " character offset - before the first character in the file |
| 1943 | call cursor(2, 1) |
| 1944 | exe "normal ?one?s-1\<CR>" |
| 1945 | call assert_equal([1, 1], [line('.'), col('.')]) |
| 1946 | call cursor(2, 1) |
| 1947 | exe "normal ?one?e-3\<CR>" |
| 1948 | call assert_equal([1, 1], [line('.'), col('.')]) |
| 1949 | |
| 1950 | " character offset - after the last character in the file |
| 1951 | call cursor(1, 1) |
| 1952 | exe "normal /four/s+4\<CR>" |
| 1953 | call assert_equal([2, 10], [line('.'), col('.')]) |
| 1954 | call cursor(1, 1) |
| 1955 | exe "normal /four/e+1\<CR>" |
| 1956 | call assert_equal([2, 10], [line('.'), col('.')]) |
| 1957 | |
| 1958 | close! |
| 1959 | endfunc |
| 1960 | |
| 1961 | " Test for searching for matching parenthesis using % |
| 1962 | func Test_search_match_paren() |
| 1963 | new |
| 1964 | call setline(1, "abc(def')'ghi'('jk'\\t'lm)no") |
| 1965 | " searching for a matching parenthesis should skip single quoted characters |
| 1966 | call cursor(1, 4) |
| 1967 | normal % |
| 1968 | call assert_equal([1, 25], [line('.'), col('.')]) |
| 1969 | normal % |
| 1970 | call assert_equal([1, 4], [line('.'), col('.')]) |
| 1971 | call cursor(1, 5) |
| 1972 | normal ]) |
| 1973 | call assert_equal([1, 25], [line('.'), col('.')]) |
| 1974 | call cursor(1, 24) |
| 1975 | normal [( |
| 1976 | call assert_equal([1, 4], [line('.'), col('.')]) |
| 1977 | |
| 1978 | " matching parenthesis in 'virtualedit' mode with cursor after the eol |
| 1979 | call setline(1, 'abc(defgh)') |
| 1980 | set virtualedit=all |
| 1981 | normal 20|% |
| 1982 | call assert_equal(4, col('.')) |
| 1983 | set virtualedit& |
| 1984 | close! |
| 1985 | endfunc |
| 1986 | |
| 1987 | " Test for searching a pattern and stopping before a specified line |
| 1988 | func Test_search_stopline() |
| 1989 | new |
| 1990 | call setline(1, ['', '', '', 'vim']) |
| 1991 | call assert_equal(0, search('vim', 'n', 3)) |
| 1992 | call assert_equal(4, search('vim', 'n', 4)) |
| 1993 | call setline(1, ['vim', '', '', '']) |
| 1994 | call cursor(4, 1) |
| 1995 | call assert_equal(0, search('vim', 'bn', 2)) |
| 1996 | call assert_equal(1, search('vim', 'bn', 1)) |
| 1997 | close! |
| 1998 | endfunc |
| 1999 | |
Bram Moolenaar | 6bed0db | 2020-11-25 17:41:20 +0100 | [diff] [blame] | 2000 | func Test_incsearch_highlighting_newline() |
Bram Moolenaar | 448465e | 2020-11-25 13:49:27 +0100 | [diff] [blame] | 2001 | CheckRunVimInTerminal |
| 2002 | CheckOption incsearch |
| 2003 | CheckScreendump |
| 2004 | new |
| 2005 | call test_override("char_avail", 1) |
| 2006 | |
| 2007 | let commands =<< trim [CODE] |
| 2008 | set incsearch nohls |
| 2009 | call setline(1, ['test', 'xxx']) |
| 2010 | [CODE] |
| 2011 | call writefile(commands, 'Xincsearch_nl') |
| 2012 | let buf = RunVimInTerminal('-S Xincsearch_nl', {'rows': 5, 'cols': 10}) |
Bram Moolenaar | 448465e | 2020-11-25 13:49:27 +0100 | [diff] [blame] | 2013 | call term_sendkeys(buf, '/test') |
Bram Moolenaar | 448465e | 2020-11-25 13:49:27 +0100 | [diff] [blame] | 2014 | call VerifyScreenDump(buf, 'Test_incsearch_newline1', {}) |
Bram Moolenaar | 6bed0db | 2020-11-25 17:41:20 +0100 | [diff] [blame] | 2015 | " Need to send one key at a time to force a redraw |
Bram Moolenaar | 448465e | 2020-11-25 13:49:27 +0100 | [diff] [blame] | 2016 | call term_sendkeys(buf, '\n') |
Bram Moolenaar | 448465e | 2020-11-25 13:49:27 +0100 | [diff] [blame] | 2017 | call VerifyScreenDump(buf, 'Test_incsearch_newline2', {}) |
| 2018 | call term_sendkeys(buf, 'x') |
Bram Moolenaar | 448465e | 2020-11-25 13:49:27 +0100 | [diff] [blame] | 2019 | call VerifyScreenDump(buf, 'Test_incsearch_newline3', {}) |
| 2020 | call term_sendkeys(buf, 'x') |
| 2021 | call VerifyScreenDump(buf, 'Test_incsearch_newline4', {}) |
| 2022 | call term_sendkeys(buf, "\<CR>") |
Bram Moolenaar | 448465e | 2020-11-25 13:49:27 +0100 | [diff] [blame] | 2023 | call VerifyScreenDump(buf, 'Test_incsearch_newline5', {}) |
| 2024 | call StopVimInTerminal(buf) |
| 2025 | |
| 2026 | " clean up |
| 2027 | call delete('Xincsearch_nl') |
| 2028 | call test_override("char_avail", 0) |
| 2029 | bw |
| 2030 | endfunc |
| 2031 | |
Bram Moolenaar | d93a7fc | 2021-01-04 12:42:13 +0100 | [diff] [blame] | 2032 | func Test_incsearch_substitute_dump2() |
| 2033 | CheckOption incsearch |
| 2034 | CheckScreendump |
| 2035 | |
| 2036 | call writefile([ |
| 2037 | \ 'set incsearch hlsearch scrolloff=0', |
| 2038 | \ 'for n in range(1, 4)', |
| 2039 | \ ' call setline(n, "foo " . n)', |
| 2040 | \ 'endfor', |
| 2041 | \ 'call setline(5, "abc|def")', |
| 2042 | \ '3', |
| 2043 | \ ], 'Xis_subst_script2') |
| 2044 | let buf = RunVimInTerminal('-S Xis_subst_script2', {'rows': 9, 'cols': 70}) |
| 2045 | |
| 2046 | call term_sendkeys(buf, ':%s/\vabc|') |
| 2047 | sleep 100m |
| 2048 | call VerifyScreenDump(buf, 'Test_incsearch_sub_01', {}) |
| 2049 | call term_sendkeys(buf, "\<Esc>") |
| 2050 | |
| 2051 | " The following should not be highlighted |
| 2052 | call term_sendkeys(buf, ':1,5s/\v|') |
| 2053 | sleep 100m |
| 2054 | call VerifyScreenDump(buf, 'Test_incsearch_sub_02', {}) |
| 2055 | |
| 2056 | |
| 2057 | call StopVimInTerminal(buf) |
| 2058 | call delete('Xis_subst_script2') |
| 2059 | endfunc |
| 2060 | |
Christian Brabandt | 78ba933 | 2021-08-01 12:44:37 +0200 | [diff] [blame] | 2061 | func Test_pattern_is_uppercase_smartcase() |
| 2062 | new |
| 2063 | let input=['abc', 'ABC', 'Abc', 'abC'] |
| 2064 | call setline(1, input) |
| 2065 | call cursor(1,1) |
| 2066 | " default, matches firstline |
| 2067 | %s/abc//g |
| 2068 | call assert_equal(['', 'ABC', 'Abc', 'abC'], |
| 2069 | \ getline(1, '$')) |
| 2070 | |
| 2071 | set smartcase ignorecase |
| 2072 | sil %d |
| 2073 | call setline(1, input) |
| 2074 | call cursor(1,1) |
| 2075 | " with smartcase and incsearch set, matches everything |
| 2076 | %s/abc//g |
| 2077 | call assert_equal(['', '', '', ''], getline(1, '$')) |
| 2078 | |
| 2079 | sil %d |
| 2080 | call setline(1, input) |
| 2081 | call cursor(1,1) |
| 2082 | " with smartcase and incsearch set and found an uppercase letter, |
| 2083 | " match only that. |
| 2084 | %s/abC//g |
| 2085 | call assert_equal(['abc', 'ABC', 'Abc', ''], |
| 2086 | \ getline(1, '$')) |
| 2087 | |
| 2088 | sil %d |
| 2089 | call setline(1, input) |
| 2090 | call cursor(1,1) |
| 2091 | exe "norm! vG$\<esc>" |
| 2092 | " \%V should not be detected as uppercase letter |
| 2093 | %s/\%Vabc//g |
| 2094 | call assert_equal(['', '', '', ''], getline(1, '$')) |
| 2095 | |
| 2096 | call setline(1, input) |
| 2097 | call cursor(1,1) |
| 2098 | exe "norm! vG$\<esc>" |
| 2099 | " \v%V should not be detected as uppercase letter |
| 2100 | %s/\v%Vabc//g |
| 2101 | call assert_equal(['', '', '', ''], getline(1, '$')) |
| 2102 | |
| 2103 | call setline(1, input) |
| 2104 | call cursor(1,1) |
| 2105 | exe "norm! vG$\<esc>" |
| 2106 | " \v%VabC should be detected as uppercase letter |
| 2107 | %s/\v%VabC//g |
| 2108 | call assert_equal(['abc', 'ABC', 'Abc', ''], |
| 2109 | \ getline(1, '$')) |
| 2110 | |
Christian Brabandt | bc67e5a | 2021-08-05 15:24:59 +0200 | [diff] [blame] | 2111 | call setline(1, input) |
| 2112 | call cursor(1,1) |
| 2113 | " \Vabc should match everything |
| 2114 | %s/\Vabc//g |
| 2115 | call assert_equal(['', '', '', ''], getline(1, '$')) |
| 2116 | |
| 2117 | call setline(1, input + ['_abc']) |
| 2118 | " _ matches normally |
| 2119 | %s/\v_.*//g |
| 2120 | call assert_equal(['abc', 'ABC', 'Abc', 'abC', ''], getline(1, '$')) |
| 2121 | |
Christian Brabandt | 78ba933 | 2021-08-01 12:44:37 +0200 | [diff] [blame] | 2122 | set smartcase& ignorecase& |
| 2123 | bw! |
| 2124 | endfunc |
| 2125 | |
Bram Moolenaar | d8d957d | 2021-10-04 19:47:35 +0100 | [diff] [blame] | 2126 | func Test_no_last_search_pattern() |
| 2127 | CheckOption incsearch |
| 2128 | |
| 2129 | let @/ = "" |
| 2130 | set incsearch |
Bram Moolenaar | 9af9fd6 | 2021-10-04 20:09:19 +0100 | [diff] [blame] | 2131 | " these were causing a crash |
| 2132 | call feedkeys("//\<C-G>", 'xt') |
| 2133 | call feedkeys("//\<C-T>", 'xt') |
| 2134 | call feedkeys("??\<C-G>", 'xt') |
| 2135 | call feedkeys("??\<C-T>", 'xt') |
Bram Moolenaar | d8d957d | 2021-10-04 19:47:35 +0100 | [diff] [blame] | 2136 | endfunc |
| 2137 | |
Bram Moolenaar | 35a319b | 2021-10-09 13:58:55 +0100 | [diff] [blame] | 2138 | func Test_search_with_invalid_range() |
| 2139 | new |
| 2140 | let lines =<< trim END |
| 2141 | /\%.v |
| 2142 | 5/ |
| 2143 | c |
| 2144 | END |
| 2145 | call writefile(lines, 'Xrangesearch') |
| 2146 | source Xrangesearch |
| 2147 | |
| 2148 | bwipe! |
| 2149 | call delete('Xrangesearch') |
| 2150 | endfunc |
| 2151 | |
Bram Moolenaar | d8d957d | 2021-10-04 19:47:35 +0100 | [diff] [blame] | 2152 | |
Bram Moolenaar | 07ada5f | 2020-02-05 20:38:22 +0100 | [diff] [blame] | 2153 | " vim: shiftwidth=2 sts=2 expandtab |