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 | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 5 | |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 6 | func Test_search_cmdline() |
| 7 | if !exists('+incsearch') |
| 8 | return |
| 9 | endif |
| 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') |
| 20 | call feedkeys("/the\<cr>",'tx') |
| 21 | call assert_equal('the', @/) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +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 |
| 59 | " eigth 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 |
| 101 | " eigth 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() |
| 204 | if !exists('+incsearch') |
| 205 | return |
| 206 | endif |
| 207 | " need to disable char_avail, |
| 208 | " so that expansion of commandline works |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 209 | call test_override("char_avail", 1) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 210 | new |
| 211 | call setline(1, [' 1', ' 2 these', ' 3 the theother']) |
| 212 | " Test 1 |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 213 | " Ctrl-T goes correctly back and forth |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 214 | set incsearch |
| 215 | 1 |
| 216 | " first match |
| 217 | call feedkeys("/the\<cr>", 'tx') |
| 218 | call assert_equal(' 2 these', getline('.')) |
| 219 | 1 |
| 220 | " go to next match (on next line) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 221 | call feedkeys("/the\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 222 | call assert_equal(' 3 the theother', getline('.')) |
| 223 | 1 |
| 224 | " go to next match (still on line 3) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 225 | call feedkeys("/the\<C-G>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 226 | call assert_equal(' 3 the theother', getline('.')) |
| 227 | 1 |
| 228 | " go to next match (still on line 3) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 229 | call feedkeys("/the\<C-G>\<C-G>\<C-G>\<cr>", 'tx') |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 230 | call assert_equal(' 3 the theother', getline('.')) |
| 231 | 1 |
| 232 | " go to previous match (on line 3) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 233 | 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] | 234 | call assert_equal(' 3 the theother', getline('.')) |
| 235 | 1 |
| 236 | " go to previous match (on line 3) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 237 | 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] | 238 | call assert_equal(' 3 the theother', getline('.')) |
| 239 | 1 |
| 240 | " go to previous match (on line 2) |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 241 | 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] | 242 | call assert_equal(' 2 these', getline('.')) |
| 243 | |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 244 | " Test 2: keep the view, |
| 245 | " after deleting a character from the search cmd |
| 246 | call setline(1, [' 1', ' 2 these', ' 3 the', ' 4 their', ' 5 there', ' 6 their', ' 7 the', ' 8 them', ' 9 these', ' 10 foobar']) |
| 247 | resize 5 |
| 248 | 1 |
| 249 | call feedkeys("/foo\<bs>\<cr>", 'tx') |
| 250 | redraw |
| 251 | call assert_equal({'lnum': 10, 'leftcol': 0, 'col': 4, 'topfill': 0, 'topline': 6, 'coladd': 0, 'skipcol': 0, 'curswant': 4}, winsaveview()) |
| 252 | |
| 253 | " remove all history entries |
| 254 | for i in range(10) |
| 255 | call histdel('/') |
| 256 | endfor |
| 257 | |
| 258 | " Test 3: reset the view, |
| 259 | " after deleting all characters from the search cmd |
| 260 | norm! 1gg0 |
| 261 | " unfortunately, neither "/foo\<c-w>\<cr>", nor "/foo\<bs>\<bs>\<bs>\<cr>", |
| 262 | " nor "/foo\<c-u>\<cr>" works to delete the commandline. |
| 263 | " In that case Vim should return "E35 no previous regular expression", |
| 264 | " but it looks like Vim still sees /foo and therefore the test fails. |
| 265 | " Therefore, disableing this test |
| 266 | "call assert_fails(feedkeys("/foo\<c-w>\<cr>", 'tx'), 'E35') |
| 267 | "call assert_equal({'lnum': 1, 'leftcol': 0, 'col': 0, 'topfill': 0, 'topline': 1, 'coladd': 0, 'skipcol': 0, 'curswant': 0}, winsaveview()) |
| 268 | |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 269 | " clean up |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 270 | set noincsearch |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 271 | call test_override("char_avail", 0) |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 272 | bw! |
| 273 | endfunc |
Bram Moolenaar | ea683da | 2016-09-09 21:41:34 +0200 | [diff] [blame] | 274 | |
| 275 | func Test_use_sub_pat() |
| 276 | split |
| 277 | let @/ = '' |
| 278 | func X() |
| 279 | s/^/a/ |
| 280 | / |
| 281 | endfunc |
| 282 | call X() |
| 283 | bwipe! |
| 284 | endfunc |
Bram Moolenaar | 6e450a5 | 2017-01-06 20:03:58 +0100 | [diff] [blame] | 285 | |
| 286 | func Test_searchpair() |
| 287 | new |
| 288 | call setline(1, ['other code here', '', '[', '" cursor here', ']']) |
| 289 | 4 |
| 290 | let a=searchpair('\[','',']','bW') |
| 291 | call assert_equal(3, a) |
| 292 | set nomagic |
| 293 | 4 |
| 294 | let a=searchpair('\[','',']','bW') |
| 295 | call assert_equal(3, a) |
| 296 | set magic |
| 297 | q! |
| 298 | endfunc |
| 299 | |
Bram Moolenaar | 4857048 | 2017-10-30 21:48:41 +0100 | [diff] [blame] | 300 | func Test_searchpair_skip() |
| 301 | func Zero() |
| 302 | return 0 |
| 303 | endfunc |
| 304 | func Partial(x) |
| 305 | return a:x |
| 306 | endfunc |
| 307 | new |
| 308 | call setline(1, ['{', 'foo', 'foo', 'foo', '}']) |
| 309 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', '')) |
| 310 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', '0')) |
| 311 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', {-> 0})) |
| 312 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Zero'))) |
| 313 | 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Partial', [0]))) |
| 314 | " invalid argument |
| 315 | 3 | call assert_equal(0, searchpair('{', '', '}', 'bWn', 0)) |
| 316 | bw! |
| 317 | endfunc |
| 318 | |
Bram Moolenaar | 66727e1 | 2017-03-01 22:17:05 +0100 | [diff] [blame] | 319 | func Test_searchc() |
| 320 | " These commands used to cause memory overflow in searchc(). |
| 321 | new |
| 322 | norm ixx |
| 323 | exe "norm 0t\u93cf" |
| 324 | bw! |
| 325 | endfunc |
Bram Moolenaar | a693d05 | 2017-06-29 22:23:06 +0200 | [diff] [blame] | 326 | |
| 327 | func Test_search_cmdline3() |
| 328 | if !exists('+incsearch') |
| 329 | return |
| 330 | endif |
| 331 | " need to disable char_avail, |
| 332 | " so that expansion of commandline works |
| 333 | call test_override("char_avail", 1) |
| 334 | new |
| 335 | call setline(1, [' 1', ' 2 the~e', ' 3 the theother']) |
| 336 | set incsearch |
| 337 | 1 |
| 338 | " first match |
| 339 | call feedkeys("/the\<c-l>\<cr>", 'tx') |
| 340 | call assert_equal(' 2 the~e', getline('.')) |
| 341 | " clean up |
| 342 | set noincsearch |
| 343 | call test_override("char_avail", 0) |
| 344 | bw! |
| 345 | endfunc |
Bram Moolenaar | da5116d | 2017-07-01 23:11:17 +0200 | [diff] [blame] | 346 | |
| 347 | func Test_search_cmdline4() |
| 348 | if !exists('+incsearch') |
| 349 | return |
| 350 | endif |
| 351 | " need to disable char_avail, |
| 352 | " so that expansion of commandline works |
| 353 | call test_override("char_avail", 1) |
| 354 | new |
| 355 | call setline(1, [' 1 the first', ' 2 the second', ' 3 the third']) |
| 356 | set incsearch |
| 357 | $ |
| 358 | call feedkeys("?the\<c-g>\<cr>", 'tx') |
| 359 | call assert_equal(' 3 the third', getline('.')) |
| 360 | $ |
| 361 | call feedkeys("?the\<c-g>\<c-g>\<cr>", 'tx') |
| 362 | call assert_equal(' 1 the first', getline('.')) |
| 363 | $ |
| 364 | call feedkeys("?the\<c-g>\<c-g>\<c-g>\<cr>", 'tx') |
| 365 | call assert_equal(' 2 the second', getline('.')) |
| 366 | $ |
| 367 | call feedkeys("?the\<c-t>\<cr>", 'tx') |
| 368 | call assert_equal(' 1 the first', getline('.')) |
| 369 | $ |
| 370 | call feedkeys("?the\<c-t>\<c-t>\<cr>", 'tx') |
| 371 | call assert_equal(' 3 the third', getline('.')) |
| 372 | $ |
| 373 | call feedkeys("?the\<c-t>\<c-t>\<c-t>\<cr>", 'tx') |
| 374 | call assert_equal(' 2 the second', getline('.')) |
| 375 | " clean up |
| 376 | set noincsearch |
| 377 | call test_override("char_avail", 0) |
| 378 | bw! |
| 379 | endfunc |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 380 | |
Bram Moolenaar | f8e8c06 | 2017-10-22 14:44:17 +0200 | [diff] [blame] | 381 | func Test_search_cmdline5() |
| 382 | if !exists('+incsearch') |
| 383 | return |
| 384 | endif |
| 385 | " Do not call test_override("char_avail", 1) so that <C-g> and <C-t> work |
| 386 | " regardless char_avail. |
| 387 | new |
| 388 | call setline(1, [' 1 the first', ' 2 the second', ' 3 the third']) |
| 389 | set incsearch |
| 390 | 1 |
| 391 | call feedkeys("/the\<c-g>\<c-g>\<cr>", 'tx') |
| 392 | call assert_equal(' 3 the third', getline('.')) |
| 393 | $ |
| 394 | call feedkeys("?the\<c-t>\<c-t>\<c-t>\<cr>", 'tx') |
| 395 | call assert_equal(' 2 the second', getline('.')) |
| 396 | " clean up |
| 397 | set noincsearch |
| 398 | bw! |
| 399 | endfunc |
| 400 | |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 401 | func Test_search_cmdline6() |
| 402 | " Test that consecutive matches |
| 403 | " are caught by <c-g>/<c-t> |
| 404 | if !exists('+incsearch') |
| 405 | return |
| 406 | endif |
| 407 | " need to disable char_avail, |
| 408 | " so that expansion of commandline works |
| 409 | call test_override("char_avail", 1) |
| 410 | new |
| 411 | call setline(1, [' bbvimb', '']) |
| 412 | set incsearch |
| 413 | " first match |
| 414 | norm! gg0 |
| 415 | call feedkeys("/b\<cr>", 'tx') |
| 416 | call assert_equal([0,1,2,0], getpos('.')) |
| 417 | " second match |
| 418 | norm! gg0 |
| 419 | call feedkeys("/b\<c-g>\<cr>", 'tx') |
| 420 | call assert_equal([0,1,3,0], getpos('.')) |
| 421 | " third match |
| 422 | norm! gg0 |
| 423 | call feedkeys("/b\<c-g>\<c-g>\<cr>", 'tx') |
| 424 | call assert_equal([0,1,7,0], getpos('.')) |
| 425 | " first match again |
| 426 | norm! gg0 |
| 427 | call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx') |
| 428 | call assert_equal([0,1,2,0], getpos('.')) |
| 429 | set nowrapscan |
| 430 | " last match |
| 431 | norm! gg0 |
| 432 | call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx') |
| 433 | call assert_equal([0,1,7,0], getpos('.')) |
| 434 | " clean up |
| 435 | set wrapscan&vim |
| 436 | set noincsearch |
| 437 | call test_override("char_avail", 0) |
| 438 | bw! |
| 439 | endfunc |
| 440 | |
| 441 | func Test_search_cmdline7() |
| 442 | " Test that an pressing <c-g> in an empty command line |
| 443 | " does not move the cursor |
| 444 | if !exists('+incsearch') |
| 445 | return |
| 446 | endif |
| 447 | " need to disable char_avail, |
| 448 | " so that expansion of commandline works |
| 449 | call test_override("char_avail", 1) |
| 450 | new |
| 451 | let @/='b' |
| 452 | call setline(1, [' bbvimb', '']) |
| 453 | set incsearch |
| 454 | " first match |
| 455 | norm! gg0 |
| 456 | " moves to next match of previous search pattern, just like /<cr> |
| 457 | call feedkeys("/\<c-g>\<cr>", 'tx') |
| 458 | call assert_equal([0,1,2,0], getpos('.')) |
| 459 | " moves to next match of previous search pattern, just like /<cr> |
| 460 | call feedkeys("/\<cr>", 'tx') |
| 461 | call assert_equal([0,1,3,0], getpos('.')) |
| 462 | " moves to next match of previous search pattern, just like /<cr> |
| 463 | call feedkeys("/\<c-t>\<cr>", 'tx') |
| 464 | call assert_equal([0,1,7,0], getpos('.')) |
Bram Moolenaar | d048009 | 2017-11-16 22:20:39 +0100 | [diff] [blame] | 465 | |
| 466 | " using an offset uses the last search pattern |
| 467 | call cursor(1, 1) |
| 468 | call setline(1, ['1 bbvimb', ' 2 bbvimb']) |
| 469 | let @/ = 'b' |
| 470 | call feedkeys("//e\<c-g>\<cr>", 'tx') |
| 471 | call assert_equal('1 bbvimb', getline('.')) |
| 472 | call assert_equal(4, col('.')) |
| 473 | |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 474 | set noincsearch |
| 475 | call test_override("char_avail", 0) |
| 476 | bw! |
| 477 | endfunc |
| 478 | |
| 479 | func Test_search_cmdline8() |
| 480 | " Highlighting is cleared in all windows |
| 481 | " since hls applies to all windows |
| 482 | if !exists('+incsearch') || !has('terminal') || has('gui_running') || winwidth(0) < 30 |
| 483 | return |
| 484 | endif |
| 485 | if has("win32") |
| 486 | throw "Skipped: Bug with sending <ESC> to terminal window not fixed yet" |
| 487 | endif |
| 488 | let h = winheight(0) |
| 489 | if h < 3 |
| 490 | return |
| 491 | endif |
| 492 | " Prepare buffer text |
| 493 | let lines = ['abb vim vim vi', 'vimvivim'] |
| 494 | call writefile(lines, 'Xsearch.txt') |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 495 | 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] | 496 | |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 497 | call WaitFor({-> lines == [term_getline(buf, 1), term_getline(buf, 2)] }) |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 498 | |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 499 | call term_sendkeys(buf, ":set incsearch hlsearch\<cr>") |
| 500 | call term_sendkeys(buf, ":14vsp\<cr>") |
| 501 | call term_sendkeys(buf, "/vim\<cr>") |
| 502 | call term_sendkeys(buf, "/b\<esc>") |
| 503 | call term_sendkeys(buf, "gg0") |
| 504 | call term_wait(buf, 500) |
| 505 | let screen_line = term_scrape(buf, 1) |
Bram Moolenaar | f8f8b2e | 2017-11-02 19:08:48 +0100 | [diff] [blame] | 506 | let [a0,a1,a2,a3] = [screen_line[3].attr, screen_line[4].attr, |
| 507 | \ screen_line[18].attr, screen_line[19].attr] |
| 508 | call assert_notequal(a0, a1) |
| 509 | call assert_notequal(a0, a3) |
| 510 | call assert_notequal(a1, a2) |
| 511 | call assert_equal(a0, a2) |
| 512 | call assert_equal(a1, a3) |
| 513 | " clean up |
| 514 | call delete('Xsearch.txt') |
| 515 | |
| 516 | bwipe! |
| 517 | endfunc |
| 518 | |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 519 | " Tests for regexp with various magic settings |
| 520 | func Test_search_regexp() |
| 521 | enew! |
| 522 | |
| 523 | put ='1 a aa abb abbccc' |
| 524 | exe 'normal! /a*b\{2}c\+/e' . "\<CR>" |
| 525 | call assert_equal([0, 2, 17, 0], getpos('.')) |
| 526 | |
| 527 | put ='2 d dd dee deefff' |
| 528 | exe 'normal! /\Md\*e\{2}f\+/e' . "\<CR>" |
| 529 | call assert_equal([0, 3, 17, 0], getpos('.')) |
| 530 | |
| 531 | set nomagic |
| 532 | put ='3 g gg ghh ghhiii' |
| 533 | exe 'normal! /g\*h\{2}i\+/e' . "\<CR>" |
| 534 | call assert_equal([0, 4, 17, 0], getpos('.')) |
| 535 | |
| 536 | put ='4 j jj jkk jkklll' |
| 537 | exe 'normal! /\mj*k\{2}l\+/e' . "\<CR>" |
| 538 | call assert_equal([0, 5, 17, 0], getpos('.')) |
| 539 | |
| 540 | put ='5 m mm mnn mnnooo' |
| 541 | exe 'normal! /\vm*n{2}o+/e' . "\<CR>" |
| 542 | call assert_equal([0, 6, 17, 0], getpos('.')) |
| 543 | |
| 544 | put ='6 x ^aa$ x' |
| 545 | exe 'normal! /\V^aa$' . "\<CR>" |
| 546 | call assert_equal([0, 7, 5, 0], getpos('.')) |
| 547 | |
| 548 | set magic |
| 549 | put ='7 (a)(b) abbaa' |
| 550 | exe 'normal! /\v(a)(b)\2\1\1/e' . "\<CR>" |
| 551 | call assert_equal([0, 8, 14, 0], getpos('.')) |
| 552 | |
| 553 | put ='8 axx [ab]xx' |
| 554 | exe 'normal! /\V[ab]\(\[xy]\)\1' . "\<CR>" |
| 555 | call assert_equal([0, 9, 7, 0], getpos('.')) |
| 556 | |
| 557 | set undolevels=100 |
| 558 | put ='9 foobar' |
| 559 | put ='' |
| 560 | exe "normal! a\<C-G>u\<Esc>" |
| 561 | normal G |
| 562 | exe 'normal! dv?bar?' . "\<CR>" |
| 563 | call assert_equal('9 foo', getline('.')) |
| 564 | call assert_equal([0, 10, 5, 0], getpos('.')) |
| 565 | call assert_equal(10, line('$')) |
| 566 | normal u |
| 567 | call assert_equal('9 foobar', getline('.')) |
| 568 | call assert_equal([0, 10, 6, 0], getpos('.')) |
| 569 | call assert_equal(11, line('$')) |
| 570 | |
| 571 | set undolevels& |
| 572 | enew! |
| 573 | endfunc |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 574 | |
| 575 | func Test_search_cmdline_incsearch_highlight() |
| 576 | if !exists('+incsearch') |
| 577 | return |
| 578 | endif |
| 579 | set incsearch hlsearch |
| 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, ['aaa 1 the first', ' 2 the second', ' 3 the third']) |
| 585 | |
| 586 | 1 |
| 587 | call feedkeys("/second\<cr>", 'tx') |
| 588 | call assert_equal('second', @/) |
| 589 | call assert_equal(' 2 the second', getline('.')) |
| 590 | |
| 591 | " Canceling search won't change @/ |
| 592 | 1 |
| 593 | let @/ = 'last pattern' |
| 594 | call feedkeys("/third\<C-c>", 'tx') |
| 595 | call assert_equal('last pattern', @/) |
| 596 | call feedkeys("/third\<Esc>", 'tx') |
| 597 | call assert_equal('last pattern', @/) |
| 598 | call feedkeys("/3\<bs>\<bs>", 'tx') |
| 599 | call assert_equal('last pattern', @/) |
| 600 | call feedkeys("/third\<c-g>\<c-t>\<Esc>", 'tx') |
| 601 | call assert_equal('last pattern', @/) |
| 602 | |
| 603 | " clean up |
| 604 | set noincsearch nohlsearch |
| 605 | bw! |
| 606 | endfunc |
| 607 | |
| 608 | func Test_search_cmdline_incsearch_highlight_attr() |
| 609 | if !exists('+incsearch') || !has('terminal') || has('gui_running') |
| 610 | return |
| 611 | endif |
| 612 | let h = winheight(0) |
| 613 | if h < 3 |
| 614 | return |
| 615 | endif |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 616 | |
| 617 | " Prepare buffer text |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 618 | let lines = ['abb vim vim vi', 'vimvivim'] |
| 619 | call writefile(lines, 'Xsearch.txt') |
| 620 | let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3}) |
| 621 | |
| 622 | call WaitFor({-> lines == [term_getline(buf, 1), term_getline(buf, 2)] }) |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 623 | " wait for vim to complete initialization |
| 624 | call term_wait(buf) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 625 | |
| 626 | " Get attr of normal(a0), incsearch(a1), hlsearch(a2) highlight |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 627 | call term_sendkeys(buf, ":set incsearch hlsearch\<cr>") |
| 628 | call term_sendkeys(buf, '/b') |
| 629 | call term_wait(buf, 200) |
| 630 | let screen_line1 = term_scrape(buf, 1) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 631 | call assert_true(len(screen_line1) > 2) |
| 632 | " a0: attr_normal |
| 633 | let a0 = screen_line1[0].attr |
| 634 | " a1: attr_incsearch |
| 635 | let a1 = screen_line1[1].attr |
| 636 | " a2: attr_hlsearch |
| 637 | let a2 = screen_line1[2].attr |
| 638 | call assert_notequal(a0, a1) |
| 639 | call assert_notequal(a0, a2) |
| 640 | call assert_notequal(a1, a2) |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 641 | call term_sendkeys(buf, "\<cr>gg0") |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 642 | |
| 643 | " Test incremental highlight search |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 644 | call term_sendkeys(buf, "/vim") |
| 645 | call term_wait(buf, 200) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 646 | " Buffer: |
| 647 | " abb vim vim vi |
| 648 | " vimvivim |
| 649 | " Search: /vim |
| 650 | let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a2,a2,a2,a0,a0,a0] |
| 651 | let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 652 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 653 | 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] | 654 | |
| 655 | " Test <C-g> |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 656 | call term_sendkeys(buf, "\<C-g>\<C-g>") |
| 657 | call term_wait(buf, 200) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 658 | let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] |
| 659 | let attr_line2 = [a1,a1,a1,a0,a0,a2,a2,a2] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 660 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 661 | 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] | 662 | |
| 663 | " Test <C-t> |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 664 | call term_sendkeys(buf, "\<C-t>") |
| 665 | call term_wait(buf, 200) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 666 | let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a1,a1,a1,a0,a0,a0] |
| 667 | let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 668 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 669 | 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] | 670 | |
| 671 | " Type Enter and a1(incsearch highlight) should become a2(hlsearch highlight) |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 672 | call term_sendkeys(buf, "\<cr>") |
| 673 | call term_wait(buf, 200) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 674 | let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] |
| 675 | let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 676 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 677 | 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] | 678 | |
| 679 | " Test nohlsearch. a2(hlsearch highlight) should become a0(normal highlight) |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 680 | call term_sendkeys(buf, ":1\<cr>") |
| 681 | call term_sendkeys(buf, ":set nohlsearch\<cr>") |
| 682 | call term_sendkeys(buf, "/vim") |
| 683 | call term_wait(buf, 200) |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 684 | let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a0,a0,a0,a0,a0,a0] |
| 685 | let attr_line2 = [a0,a0,a0,a0,a0,a0,a0,a0] |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 686 | call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 687 | 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] | 688 | call delete('Xsearch.txt') |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 689 | |
Bram Moolenaar | b94340c | 2017-11-02 16:16:31 +0100 | [diff] [blame] | 690 | call delete('Xsearch.txt') |
Bram Moolenaar | 2e51d9a | 2017-10-29 16:40:30 +0100 | [diff] [blame] | 691 | bwipe! |
| 692 | endfunc |
Bram Moolenaar | f45938c | 2017-11-02 15:59:57 +0100 | [diff] [blame] | 693 | |
Bram Moolenaar | 9d34d90 | 2018-04-27 22:18:12 +0200 | [diff] [blame] | 694 | func Test_incsearch_scrolling() |
| 695 | if !CanRunVimInTerminal() |
| 696 | return |
| 697 | endif |
| 698 | call assert_equal(0, &scrolloff) |
| 699 | call writefile([ |
| 700 | \ 'let dots = repeat(".", 120)', |
| 701 | \ 'set incsearch cmdheight=2 scrolloff=0', |
| 702 | \ 'call setline(1, [dots, dots, dots, "", "target", dots, dots])', |
| 703 | \ 'normal gg', |
| 704 | \ 'redraw', |
| 705 | \ ], 'Xscript') |
| 706 | let buf = RunVimInTerminal('-S Xscript', {'rows': 9, 'cols': 70}) |
| 707 | " Need to send one key at a time to force a redraw |
| 708 | call term_sendkeys(buf, '/') |
| 709 | sleep 100m |
| 710 | call term_sendkeys(buf, 't') |
| 711 | sleep 100m |
| 712 | call term_sendkeys(buf, 'a') |
| 713 | sleep 100m |
| 714 | call term_sendkeys(buf, 'r') |
| 715 | sleep 100m |
| 716 | call term_sendkeys(buf, 'g') |
| 717 | call VerifyScreenDump(buf, 'Test_incsearch_scrolling_01', {}) |
| 718 | |
| 719 | call term_sendkeys(buf, "\<Esc>") |
| 720 | call StopVimInTerminal(buf) |
| 721 | call delete('Xscript') |
| 722 | endfunc |
| 723 | |
Bram Moolenaar | f45938c | 2017-11-02 15:59:57 +0100 | [diff] [blame] | 724 | func Test_search_undefined_behaviour() |
| 725 | if !has("terminal") |
| 726 | return |
| 727 | endif |
| 728 | let h = winheight(0) |
| 729 | if h < 3 |
| 730 | return |
| 731 | endif |
| 732 | " did cause an undefined left shift |
| 733 | let g:buf = term_start([GetVimProg(), '--clean', '-e', '-s', '-c', 'call search(getline("."))', 'samples/test000'], {'term_rows': 3}) |
| 734 | call assert_equal([''], getline(1, '$')) |
| 735 | call term_sendkeys(g:buf, ":qa!\<cr>") |
| 736 | bwipe! |
| 737 | endfunc |
Bram Moolenaar | 2973daa | 2017-11-02 23:15:40 +0100 | [diff] [blame] | 738 | |
| 739 | func Test_search_undefined_behaviour2() |
| 740 | call search("\%UC0000000") |
| 741 | endfunc |
Bram Moolenaar | fb094e1 | 2017-11-05 20:59:28 +0100 | [diff] [blame] | 742 | |
| 743 | " Test for search('multi-byte char', 'bce') |
| 744 | func Test_search_multibyte() |
| 745 | if !has('multi_byte') |
| 746 | return |
| 747 | endif |
| 748 | let save_enc = &encoding |
| 749 | set encoding=utf8 |
| 750 | enew! |
| 751 | call append('$', 'A') |
| 752 | call cursor(2, 1) |
| 753 | call assert_equal(2, search('A', 'bce', line('.'))) |
| 754 | enew! |
| 755 | let &encoding = save_enc |
| 756 | endfunc |
Bram Moolenaar | 890dd05 | 2017-12-16 19:59:37 +0100 | [diff] [blame] | 757 | |
| 758 | " This was causing E874. Also causes an invalid read? |
| 759 | func Test_look_behind() |
| 760 | new |
| 761 | call setline(1, '0\|\&\n\@<=') |
| 762 | call search(getline(".")) |
| 763 | bwipe! |
| 764 | endfunc |
Bram Moolenaar | 8ada6aa | 2017-12-19 21:23:21 +0100 | [diff] [blame] | 765 | |
| 766 | func Test_search_sentence() |
| 767 | new |
| 768 | " this used to cause a crash |
Bram Moolenaar | 1bd999f | 2017-12-19 22:25:40 +0100 | [diff] [blame] | 769 | call assert_fails("/\\%')", 'E486') |
Bram Moolenaar | 8ada6aa | 2017-12-19 21:23:21 +0100 | [diff] [blame] | 770 | call assert_fails("/", 'E486') |
Bram Moolenaar | 1bd999f | 2017-12-19 22:25:40 +0100 | [diff] [blame] | 771 | /\%'( |
| 772 | / |
Bram Moolenaar | 8ada6aa | 2017-12-19 21:23:21 +0100 | [diff] [blame] | 773 | endfunc |