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