Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 1 | " Test for the search command |
| 2 | |
| 3 | func Test_search_cmdline() |
| 4 | if !exists('+incsearch') |
| 5 | return |
| 6 | endif |
| 7 | " need to disable char_avail, |
| 8 | " so that expansion of commandline works |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 9 | call test_override("char_avail", 1) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 10 | new |
| 11 | call setline(1, [' 1', ' 2 these', ' 3 the', ' 4 their', ' 5 there', ' 6 their', ' 7 the', ' 8 them', ' 9 these', ' 10 foobar']) |
| 12 | " Test 1 |
| 13 | " CTRL-N / CTRL-P skips through the previous search history |
| 14 | set noincsearch |
| 15 | :1 |
| 16 | call feedkeys("/foobar\<cr>", 'tx') |
| 17 | call feedkeys("/the\<cr>",'tx') |
| 18 | call assert_equal('the', @/) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 19 | call feedkeys("/thes\<C-P>\<C-P>\<cr>",'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 20 | call assert_equal('foobar', @/) |
| 21 | |
| 22 | " Test 2 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 23 | " Ctrl-G goes from one match to the next |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 24 | " until the end of the buffer |
| 25 | set incsearch nowrapscan |
| 26 | :1 |
| 27 | " first match |
| 28 | call feedkeys("/the\<cr>", 'tx') |
| 29 | call assert_equal(' 2 these', getline('.')) |
| 30 | :1 |
| 31 | " second match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 32 | call feedkeys("/the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 33 | call assert_equal(' 3 the', getline('.')) |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 34 | call assert_equal([0, 0, 0, 0], getpos('"')) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 35 | :1 |
| 36 | " third match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 37 | call feedkeys("/the".repeat("\<C-G>", 2)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 38 | call assert_equal(' 4 their', getline('.')) |
| 39 | :1 |
| 40 | " fourth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 41 | call feedkeys("/the".repeat("\<C-G>", 3)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 42 | call assert_equal(' 5 there', getline('.')) |
| 43 | :1 |
| 44 | " fifth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 45 | call feedkeys("/the".repeat("\<C-G>", 4)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 46 | call assert_equal(' 6 their', getline('.')) |
| 47 | :1 |
| 48 | " sixth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 49 | call feedkeys("/the".repeat("\<C-G>", 5)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 50 | call assert_equal(' 7 the', getline('.')) |
| 51 | :1 |
| 52 | " seventh match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 53 | call feedkeys("/the".repeat("\<C-G>", 6)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 54 | call assert_equal(' 8 them', getline('.')) |
| 55 | :1 |
| 56 | " eigth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 57 | call feedkeys("/the".repeat("\<C-G>", 7)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 58 | call assert_equal(' 9 these', getline('.')) |
| 59 | :1 |
| 60 | " no further match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 61 | call feedkeys("/the".repeat("\<C-G>", 8)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 62 | call assert_equal(' 9 these', getline('.')) |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 63 | call assert_equal([0, 0, 0, 0], getpos('"')) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 64 | |
| 65 | " Test 3 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 66 | " Ctrl-G goes from one match to the next |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 67 | " and continues back at the top |
| 68 | set incsearch wrapscan |
| 69 | :1 |
| 70 | " first match |
| 71 | call feedkeys("/the\<cr>", 'tx') |
| 72 | call assert_equal(' 2 these', getline('.')) |
| 73 | :1 |
| 74 | " second match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 75 | call feedkeys("/the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 76 | call assert_equal(' 3 the', getline('.')) |
| 77 | :1 |
| 78 | " third match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 79 | call feedkeys("/the".repeat("\<C-G>", 2)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 80 | call assert_equal(' 4 their', getline('.')) |
| 81 | :1 |
| 82 | " fourth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 83 | call feedkeys("/the".repeat("\<C-G>", 3)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 84 | call assert_equal(' 5 there', getline('.')) |
| 85 | :1 |
| 86 | " fifth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 87 | call feedkeys("/the".repeat("\<C-G>", 4)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 88 | call assert_equal(' 6 their', getline('.')) |
| 89 | :1 |
| 90 | " sixth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 91 | call feedkeys("/the".repeat("\<C-G>", 5)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 92 | call assert_equal(' 7 the', getline('.')) |
| 93 | :1 |
| 94 | " seventh match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 95 | call feedkeys("/the".repeat("\<C-G>", 6)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 96 | call assert_equal(' 8 them', getline('.')) |
| 97 | :1 |
| 98 | " eigth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 99 | call feedkeys("/the".repeat("\<C-G>", 7)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 100 | call assert_equal(' 9 these', getline('.')) |
| 101 | :1 |
| 102 | " back at first match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 103 | call feedkeys("/the".repeat("\<C-G>", 8)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 104 | call assert_equal(' 2 these', getline('.')) |
| 105 | |
| 106 | " Test 4 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 107 | " CTRL-T goes to the previous match |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 108 | set incsearch nowrapscan |
| 109 | $ |
| 110 | " first match |
| 111 | call feedkeys("?the\<cr>", 'tx') |
| 112 | call assert_equal(' 9 these', getline('.')) |
| 113 | $ |
| 114 | " first match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 115 | call feedkeys("?the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 116 | call assert_equal(' 9 these', getline('.')) |
| 117 | $ |
| 118 | " second match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 119 | call feedkeys("?the".repeat("\<C-T>", 1)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 120 | call assert_equal(' 8 them', getline('.')) |
| 121 | $ |
| 122 | " last match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 123 | call feedkeys("?the".repeat("\<C-T>", 7)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 124 | call assert_equal(' 2 these', getline('.')) |
| 125 | $ |
| 126 | " last match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 127 | call feedkeys("?the".repeat("\<C-T>", 8)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 128 | call assert_equal(' 2 these', getline('.')) |
| 129 | |
| 130 | " Test 5 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 131 | " CTRL-T goes to the previous match |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 132 | set incsearch wrapscan |
| 133 | $ |
| 134 | " first match |
| 135 | call feedkeys("?the\<cr>", 'tx') |
| 136 | call assert_equal(' 9 these', getline('.')) |
| 137 | $ |
| 138 | " first match at the top |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 139 | call feedkeys("?the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 140 | call assert_equal(' 2 these', getline('.')) |
| 141 | $ |
| 142 | " second match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 143 | call feedkeys("?the".repeat("\<C-T>", 1)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 144 | call assert_equal(' 8 them', getline('.')) |
| 145 | $ |
| 146 | " last match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 147 | call feedkeys("?the".repeat("\<C-T>", 7)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 148 | call assert_equal(' 2 these', getline('.')) |
| 149 | $ |
| 150 | " back at the bottom of the buffer |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 151 | call feedkeys("?the".repeat("\<C-T>", 8)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 152 | call assert_equal(' 9 these', getline('.')) |
| 153 | |
| 154 | " Test 6 |
| 155 | " CTRL-L adds to the search pattern |
| 156 | set incsearch wrapscan |
| 157 | 1 |
| 158 | " first match |
| 159 | call feedkeys("/the\<c-l>\<cr>", 'tx') |
| 160 | call assert_equal(' 2 these', getline('.')) |
| 161 | 1 |
| 162 | " go to next match of 'thes' |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 163 | call feedkeys("/the\<c-l>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 164 | call assert_equal(' 9 these', getline('.')) |
| 165 | 1 |
| 166 | " wrap around |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 167 | call feedkeys("/the\<c-l>\<C-G>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 168 | call assert_equal(' 2 these', getline('.')) |
| 169 | 1 |
| 170 | " wrap around |
| 171 | set nowrapscan |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 172 | call feedkeys("/the\<c-l>\<C-G>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 173 | call assert_equal(' 9 these', getline('.')) |
| 174 | |
| 175 | " Test 7 |
| 176 | " <bs> remove from match, but stay at current match |
| 177 | set incsearch wrapscan |
| 178 | 1 |
| 179 | " first match |
| 180 | call feedkeys("/thei\<cr>", 'tx') |
| 181 | call assert_equal(' 4 their', getline('.')) |
| 182 | 1 |
| 183 | " delete one char, add another |
| 184 | call feedkeys("/thei\<bs>s\<cr>", 'tx') |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 185 | call assert_equal(' 2 these', getline('.')) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 186 | 1 |
| 187 | " delete one char, add another, go to previous match, add one char |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 188 | call feedkeys("/thei\<bs>s\<bs>\<C-T>\<c-l>\<cr>", 'tx') |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 189 | call assert_equal(' 9 these', getline('.')) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 190 | 1 |
| 191 | " delete all chars, start from the beginning again |
| 192 | call feedkeys("/them". repeat("\<bs>",4).'the\>'."\<cr>", 'tx') |
| 193 | call assert_equal(' 3 the', getline('.')) |
| 194 | |
| 195 | " clean up |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 196 | call test_override("char_avail", 0) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 197 | bw! |
| 198 | endfunc |
| 199 | |
| 200 | func Test_search_cmdline2() |
| 201 | if !exists('+incsearch') |
| 202 | return |
| 203 | endif |
| 204 | " need to disable char_avail, |
| 205 | " so that expansion of commandline works |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 206 | call test_override("char_avail", 1) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 207 | new |
| 208 | call setline(1, [' 1', ' 2 these', ' 3 the theother']) |
| 209 | " Test 1 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 210 | " Ctrl-T goes correctly back and forth |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 211 | set incsearch |
| 212 | 1 |
| 213 | " first match |
| 214 | call feedkeys("/the\<cr>", 'tx') |
| 215 | call assert_equal(' 2 these', getline('.')) |
| 216 | 1 |
| 217 | " go to next match (on next line) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 218 | call feedkeys("/the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 219 | call assert_equal(' 3 the theother', getline('.')) |
| 220 | 1 |
| 221 | " go to next match (still on line 3) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 222 | call feedkeys("/the\<C-G>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 223 | call assert_equal(' 3 the theother', getline('.')) |
| 224 | 1 |
| 225 | " go to next match (still on line 3) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 226 | call feedkeys("/the\<C-G>\<C-G>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 227 | call assert_equal(' 3 the theother', getline('.')) |
| 228 | 1 |
| 229 | " go to previous match (on line 3) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 230 | call feedkeys("/the\<C-G>\<C-G>\<C-G>\<C-T>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 231 | call assert_equal(' 3 the theother', getline('.')) |
| 232 | 1 |
| 233 | " go to previous match (on line 3) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 234 | call feedkeys("/the\<C-G>\<C-G>\<C-G>\<C-T>\<C-T>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 235 | call assert_equal(' 3 the theother', getline('.')) |
| 236 | 1 |
| 237 | " go to previous match (on line 2) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 238 | call feedkeys("/the\<C-G>\<C-G>\<C-G>\<C-T>\<C-T>\<C-T>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 239 | call assert_equal(' 2 these', getline('.')) |
| 240 | |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 241 | " Test 2: keep the view, |
| 242 | " after deleting a character from the search cmd |
| 243 | call setline(1, [' 1', ' 2 these', ' 3 the', ' 4 their', ' 5 there', ' 6 their', ' 7 the', ' 8 them', ' 9 these', ' 10 foobar']) |
| 244 | resize 5 |
| 245 | 1 |
| 246 | call feedkeys("/foo\<bs>\<cr>", 'tx') |
| 247 | redraw |
| 248 | call assert_equal({'lnum': 10, 'leftcol': 0, 'col': 4, 'topfill': 0, 'topline': 6, 'coladd': 0, 'skipcol': 0, 'curswant': 4}, winsaveview()) |
| 249 | |
| 250 | " remove all history entries |
| 251 | for i in range(10) |
| 252 | call histdel('/') |
| 253 | endfor |
| 254 | |
| 255 | " Test 3: reset the view, |
| 256 | " after deleting all characters from the search cmd |
| 257 | norm! 1gg0 |
| 258 | " unfortunately, neither "/foo\<c-w>\<cr>", nor "/foo\<bs>\<bs>\<bs>\<cr>", |
| 259 | " nor "/foo\<c-u>\<cr>" works to delete the commandline. |
| 260 | " In that case Vim should return "E35 no previous regular expression", |
| 261 | " but it looks like Vim still sees /foo and therefore the test fails. |
| 262 | " Therefore, disableing this test |
| 263 | "call assert_fails(feedkeys("/foo\<c-w>\<cr>", 'tx'), 'E35') |
| 264 | "call assert_equal({'lnum': 1, 'leftcol': 0, 'col': 0, 'topfill': 0, 'topline': 1, 'coladd': 0, 'skipcol': 0, 'curswant': 0}, winsaveview()) |
| 265 | |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 266 | " clean up |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 267 | set noincsearch |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 268 | call test_override("char_avail", 0) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 269 | bw! |
| 270 | endfunc |
Bram Moolenaar | ea683da | 2016-09-09 21:41:34 +0200 | [diff] [blame] | 271 | |
| 272 | func Test_use_sub_pat() |
| 273 | split |
| 274 | let @/ = '' |
| 275 | func X() |
| 276 | s/^/a/ |
| 277 | / |
| 278 | endfunc |
| 279 | call X() |
| 280 | bwipe! |
| 281 | endfunc |
Bram Moolenaar | 6e450a5 | 2017-01-06 20:03:58 +0100 | [diff] [blame] | 282 | |
| 283 | func Test_searchpair() |
| 284 | new |
| 285 | call setline(1, ['other code here', '', '[', '" cursor here', ']']) |
| 286 | 4 |
| 287 | let a=searchpair('\[','',']','bW') |
| 288 | call assert_equal(3, a) |
| 289 | set nomagic |
| 290 | 4 |
| 291 | let a=searchpair('\[','',']','bW') |
| 292 | call assert_equal(3, a) |
| 293 | set magic |
| 294 | q! |
| 295 | endfunc |
| 296 | |
Bram Moolenaar | 66727e1 | 2017-03-01 22:17:05 +0100 | [diff] [blame] | 297 | func Test_searchc() |
| 298 | " These commands used to cause memory overflow in searchc(). |
| 299 | new |
| 300 | norm ixx |
| 301 | exe "norm 0t\u93cf" |
| 302 | bw! |
| 303 | endfunc |
Bram Moolenaar | a693d05 | 2017-06-29 22:23:06 +0200 | [diff] [blame] | 304 | |
| 305 | func Test_search_cmdline3() |
| 306 | if !exists('+incsearch') |
| 307 | return |
| 308 | endif |
| 309 | " need to disable char_avail, |
| 310 | " so that expansion of commandline works |
| 311 | call test_override("char_avail", 1) |
| 312 | new |
| 313 | call setline(1, [' 1', ' 2 the~e', ' 3 the theother']) |
| 314 | set incsearch |
| 315 | 1 |
| 316 | " first match |
| 317 | call feedkeys("/the\<c-l>\<cr>", 'tx') |
| 318 | call assert_equal(' 2 the~e', getline('.')) |
| 319 | " clean up |
| 320 | set noincsearch |
| 321 | call test_override("char_avail", 0) |
| 322 | bw! |
| 323 | endfunc |
Bram Moolenaar | da5116d | 2017-07-01 23:11:17 +0200 | [diff] [blame] | 324 | |
| 325 | func Test_search_cmdline4() |
| 326 | if !exists('+incsearch') |
| 327 | return |
| 328 | endif |
| 329 | " need to disable char_avail, |
| 330 | " so that expansion of commandline works |
| 331 | call test_override("char_avail", 1) |
| 332 | new |
| 333 | call setline(1, [' 1 the first', ' 2 the second', ' 3 the third']) |
| 334 | set incsearch |
| 335 | $ |
| 336 | call feedkeys("?the\<c-g>\<cr>", 'tx') |
| 337 | call assert_equal(' 3 the third', getline('.')) |
| 338 | $ |
| 339 | call feedkeys("?the\<c-g>\<c-g>\<cr>", 'tx') |
| 340 | call assert_equal(' 1 the first', getline('.')) |
| 341 | $ |
| 342 | call feedkeys("?the\<c-g>\<c-g>\<c-g>\<cr>", 'tx') |
| 343 | call assert_equal(' 2 the second', getline('.')) |
| 344 | $ |
| 345 | call feedkeys("?the\<c-t>\<cr>", 'tx') |
| 346 | call assert_equal(' 1 the first', getline('.')) |
| 347 | $ |
| 348 | call feedkeys("?the\<c-t>\<c-t>\<cr>", 'tx') |
| 349 | call assert_equal(' 3 the third', getline('.')) |
| 350 | $ |
| 351 | call feedkeys("?the\<c-t>\<c-t>\<c-t>\<cr>", 'tx') |
| 352 | call assert_equal(' 2 the second', getline('.')) |
| 353 | " clean up |
| 354 | set noincsearch |
| 355 | call test_override("char_avail", 0) |
| 356 | bw! |
| 357 | endfunc |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 358 | |
| 359 | " Tests for regexp with various magic settings |
| 360 | func Test_search_regexp() |
| 361 | enew! |
| 362 | |
| 363 | put ='1 a aa abb abbccc' |
| 364 | exe 'normal! /a*b\{2}c\+/e' . "\<CR>" |
| 365 | call assert_equal([0, 2, 17, 0], getpos('.')) |
| 366 | |
| 367 | put ='2 d dd dee deefff' |
| 368 | exe 'normal! /\Md\*e\{2}f\+/e' . "\<CR>" |
| 369 | call assert_equal([0, 3, 17, 0], getpos('.')) |
| 370 | |
| 371 | set nomagic |
| 372 | put ='3 g gg ghh ghhiii' |
| 373 | exe 'normal! /g\*h\{2}i\+/e' . "\<CR>" |
| 374 | call assert_equal([0, 4, 17, 0], getpos('.')) |
| 375 | |
| 376 | put ='4 j jj jkk jkklll' |
| 377 | exe 'normal! /\mj*k\{2}l\+/e' . "\<CR>" |
| 378 | call assert_equal([0, 5, 17, 0], getpos('.')) |
| 379 | |
| 380 | put ='5 m mm mnn mnnooo' |
| 381 | exe 'normal! /\vm*n{2}o+/e' . "\<CR>" |
| 382 | call assert_equal([0, 6, 17, 0], getpos('.')) |
| 383 | |
| 384 | put ='6 x ^aa$ x' |
| 385 | exe 'normal! /\V^aa$' . "\<CR>" |
| 386 | call assert_equal([0, 7, 5, 0], getpos('.')) |
| 387 | |
| 388 | set magic |
| 389 | put ='7 (a)(b) abbaa' |
| 390 | exe 'normal! /\v(a)(b)\2\1\1/e' . "\<CR>" |
| 391 | call assert_equal([0, 8, 14, 0], getpos('.')) |
| 392 | |
| 393 | put ='8 axx [ab]xx' |
| 394 | exe 'normal! /\V[ab]\(\[xy]\)\1' . "\<CR>" |
| 395 | call assert_equal([0, 9, 7, 0], getpos('.')) |
| 396 | |
| 397 | set undolevels=100 |
| 398 | put ='9 foobar' |
| 399 | put ='' |
| 400 | exe "normal! a\<C-G>u\<Esc>" |
| 401 | normal G |
| 402 | exe 'normal! dv?bar?' . "\<CR>" |
| 403 | call assert_equal('9 foo', getline('.')) |
| 404 | call assert_equal([0, 10, 5, 0], getpos('.')) |
| 405 | call assert_equal(10, line('$')) |
| 406 | normal u |
| 407 | call assert_equal('9 foobar', getline('.')) |
| 408 | call assert_equal([0, 10, 6, 0], getpos('.')) |
| 409 | call assert_equal(11, line('$')) |
| 410 | |
| 411 | set undolevels& |
| 412 | enew! |
| 413 | endfunc |