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 |
| 9 | call test_disable_char_avail(1) |
| 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('.')) |
| 34 | :1 |
| 35 | " third match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 36 | call feedkeys("/the".repeat("\<C-G>", 2)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 37 | call assert_equal(' 4 their', getline('.')) |
| 38 | :1 |
| 39 | " fourth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 40 | call feedkeys("/the".repeat("\<C-G>", 3)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 41 | call assert_equal(' 5 there', getline('.')) |
| 42 | :1 |
| 43 | " fifth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 44 | call feedkeys("/the".repeat("\<C-G>", 4)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 45 | call assert_equal(' 6 their', getline('.')) |
| 46 | :1 |
| 47 | " sixth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 48 | call feedkeys("/the".repeat("\<C-G>", 5)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 49 | call assert_equal(' 7 the', getline('.')) |
| 50 | :1 |
| 51 | " seventh match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 52 | call feedkeys("/the".repeat("\<C-G>", 6)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 53 | call assert_equal(' 8 them', getline('.')) |
| 54 | :1 |
| 55 | " eigth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 56 | call feedkeys("/the".repeat("\<C-G>", 7)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 57 | call assert_equal(' 9 these', getline('.')) |
| 58 | :1 |
| 59 | " no further match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 60 | call feedkeys("/the".repeat("\<C-G>", 8)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 61 | call assert_equal(' 9 these', getline('.')) |
| 62 | |
| 63 | " Test 3 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 64 | " Ctrl-G goes from one match to the next |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 65 | " and continues back at the top |
| 66 | set incsearch wrapscan |
| 67 | :1 |
| 68 | " first match |
| 69 | call feedkeys("/the\<cr>", 'tx') |
| 70 | call assert_equal(' 2 these', getline('.')) |
| 71 | :1 |
| 72 | " second match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 73 | call feedkeys("/the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 74 | call assert_equal(' 3 the', getline('.')) |
| 75 | :1 |
| 76 | " third match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 77 | call feedkeys("/the".repeat("\<C-G>", 2)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 78 | call assert_equal(' 4 their', getline('.')) |
| 79 | :1 |
| 80 | " fourth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 81 | call feedkeys("/the".repeat("\<C-G>", 3)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 82 | call assert_equal(' 5 there', getline('.')) |
| 83 | :1 |
| 84 | " fifth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 85 | call feedkeys("/the".repeat("\<C-G>", 4)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 86 | call assert_equal(' 6 their', getline('.')) |
| 87 | :1 |
| 88 | " sixth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 89 | call feedkeys("/the".repeat("\<C-G>", 5)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 90 | call assert_equal(' 7 the', getline('.')) |
| 91 | :1 |
| 92 | " seventh match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 93 | call feedkeys("/the".repeat("\<C-G>", 6)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 94 | call assert_equal(' 8 them', getline('.')) |
| 95 | :1 |
| 96 | " eigth match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 97 | call feedkeys("/the".repeat("\<C-G>", 7)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 98 | call assert_equal(' 9 these', getline('.')) |
| 99 | :1 |
| 100 | " back at first match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 101 | call feedkeys("/the".repeat("\<C-G>", 8)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 102 | call assert_equal(' 2 these', getline('.')) |
| 103 | |
| 104 | " Test 4 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 105 | " CTRL-T goes to the previous match |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 106 | set incsearch nowrapscan |
| 107 | $ |
| 108 | " first match |
| 109 | call feedkeys("?the\<cr>", 'tx') |
| 110 | call assert_equal(' 9 these', getline('.')) |
| 111 | $ |
| 112 | " first match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 113 | call feedkeys("?the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 114 | call assert_equal(' 9 these', getline('.')) |
| 115 | $ |
| 116 | " second match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 117 | call feedkeys("?the".repeat("\<C-T>", 1)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 118 | call assert_equal(' 8 them', getline('.')) |
| 119 | $ |
| 120 | " last match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 121 | call feedkeys("?the".repeat("\<C-T>", 7)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 122 | call assert_equal(' 2 these', getline('.')) |
| 123 | $ |
| 124 | " last match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 125 | call feedkeys("?the".repeat("\<C-T>", 8)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 126 | call assert_equal(' 2 these', getline('.')) |
| 127 | |
| 128 | " Test 5 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 129 | " CTRL-T goes to the previous match |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 130 | set incsearch wrapscan |
| 131 | $ |
| 132 | " first match |
| 133 | call feedkeys("?the\<cr>", 'tx') |
| 134 | call assert_equal(' 9 these', getline('.')) |
| 135 | $ |
| 136 | " first match at the top |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 137 | call feedkeys("?the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 138 | call assert_equal(' 2 these', getline('.')) |
| 139 | $ |
| 140 | " second match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 141 | call feedkeys("?the".repeat("\<C-T>", 1)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 142 | call assert_equal(' 8 them', getline('.')) |
| 143 | $ |
| 144 | " last match |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 145 | call feedkeys("?the".repeat("\<C-T>", 7)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 146 | call assert_equal(' 2 these', getline('.')) |
| 147 | $ |
| 148 | " back at the bottom of the buffer |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 149 | call feedkeys("?the".repeat("\<C-T>", 8)."\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 150 | call assert_equal(' 9 these', getline('.')) |
| 151 | |
| 152 | " Test 6 |
| 153 | " CTRL-L adds to the search pattern |
| 154 | set incsearch wrapscan |
| 155 | 1 |
| 156 | " first match |
| 157 | call feedkeys("/the\<c-l>\<cr>", 'tx') |
| 158 | call assert_equal(' 2 these', getline('.')) |
| 159 | 1 |
| 160 | " go to next match of 'thes' |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 161 | call feedkeys("/the\<c-l>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 162 | call assert_equal(' 9 these', getline('.')) |
| 163 | 1 |
| 164 | " wrap around |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 165 | call feedkeys("/the\<c-l>\<C-G>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 166 | call assert_equal(' 2 these', getline('.')) |
| 167 | 1 |
| 168 | " wrap around |
| 169 | set nowrapscan |
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(' 9 these', getline('.')) |
| 172 | |
| 173 | " Test 7 |
| 174 | " <bs> remove from match, but stay at current match |
| 175 | set incsearch wrapscan |
| 176 | 1 |
| 177 | " first match |
| 178 | call feedkeys("/thei\<cr>", 'tx') |
| 179 | call assert_equal(' 4 their', getline('.')) |
| 180 | 1 |
| 181 | " delete one char, add another |
| 182 | call feedkeys("/thei\<bs>s\<cr>", 'tx') |
| 183 | call assert_equal(' 9 these', getline('.')) |
| 184 | 1 |
| 185 | " delete one char, add another, go to previous match, add one char |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 186 | call feedkeys("/thei\<bs>s\<bs>\<C-T>\<c-l>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 187 | call assert_equal(' 8 them', getline('.')) |
| 188 | 1 |
| 189 | " delete all chars, start from the beginning again |
| 190 | call feedkeys("/them". repeat("\<bs>",4).'the\>'."\<cr>", 'tx') |
| 191 | call assert_equal(' 3 the', getline('.')) |
| 192 | |
| 193 | " clean up |
| 194 | call test_disable_char_avail(0) |
| 195 | bw! |
| 196 | endfunc |
| 197 | |
| 198 | func Test_search_cmdline2() |
| 199 | if !exists('+incsearch') |
| 200 | return |
| 201 | endif |
| 202 | " need to disable char_avail, |
| 203 | " so that expansion of commandline works |
| 204 | call test_disable_char_avail(1) |
| 205 | new |
| 206 | call setline(1, [' 1', ' 2 these', ' 3 the theother']) |
| 207 | " Test 1 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 208 | " Ctrl-T goes correctly back and forth |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 209 | set incsearch |
| 210 | 1 |
| 211 | " first match |
| 212 | call feedkeys("/the\<cr>", 'tx') |
| 213 | call assert_equal(' 2 these', getline('.')) |
| 214 | 1 |
| 215 | " go to next match (on next line) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 216 | call feedkeys("/the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 217 | call assert_equal(' 3 the theother', getline('.')) |
| 218 | 1 |
| 219 | " go to next match (still on line 3) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 220 | call feedkeys("/the\<C-G>\<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>\<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 previous match (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>\<C-T>\<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>\<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 2) |
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>\<C-T>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 237 | call assert_equal(' 2 these', getline('.')) |
| 238 | |
| 239 | " clean up |
| 240 | call test_disable_char_avail(0) |
| 241 | bw! |
| 242 | endfunc |