Bram Moolenaar | df7df59 | 2020-06-14 13:50:55 +0200 | [diff] [blame] | 1 | " Test for the various 'cpoptions' (cpo) flags |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 2 | |
| 3 | source check.vim |
Bram Moolenaar | df7df59 | 2020-06-14 13:50:55 +0200 | [diff] [blame] | 4 | source shared.vim |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 5 | source view_util.vim |
| 6 | |
| 7 | " Test for the 'a' flag in 'cpo'. Reading a file should set the alternate |
| 8 | " file name. |
| 9 | func Test_cpo_a() |
| 10 | let save_cpo = &cpo |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 11 | call writefile(['one'], 'XfileCpoA', 'D') |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 12 | " Wipe out all the buffers, so that the alternate file is empty |
| 13 | edit Xfoo | %bw |
| 14 | set cpo-=a |
| 15 | new |
Bram Moolenaar | a85e4db | 2022-08-28 17:44:20 +0100 | [diff] [blame] | 16 | read XfileCpoA |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 17 | call assert_equal('', @#) |
| 18 | %d |
| 19 | set cpo+=a |
Bram Moolenaar | a85e4db | 2022-08-28 17:44:20 +0100 | [diff] [blame] | 20 | read XfileCpoA |
| 21 | call assert_equal('XfileCpoA', @#) |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 22 | close! |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 23 | let &cpo = save_cpo |
| 24 | endfunc |
| 25 | |
| 26 | " Test for the 'A' flag in 'cpo'. Writing a file should set the alternate |
| 27 | " file name. |
| 28 | func Test_cpo_A() |
| 29 | let save_cpo = &cpo |
| 30 | " Wipe out all the buffers, so that the alternate file is empty |
| 31 | edit Xfoo | %bw |
| 32 | set cpo-=A |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 33 | new XcpoAfile1 |
| 34 | write XcpoAfile2 |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 35 | call assert_equal('', @#) |
| 36 | %bw |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 37 | call delete('XcpoAfile2') |
| 38 | new XcpoAfile1 |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 39 | set cpo+=A |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 40 | write XcpoAfile2 |
| 41 | call assert_equal('XcpoAfile2', @#) |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 42 | close! |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 43 | call delete('XcpoAfile2') |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 44 | let &cpo = save_cpo |
| 45 | endfunc |
| 46 | |
| 47 | " Test for the 'b' flag in 'cpo'. "\|" at the end of a map command is |
| 48 | " recognized as the end of the map. |
| 49 | func Test_cpo_b() |
| 50 | let save_cpo = &cpo |
| 51 | set cpo+=b |
| 52 | nnoremap <F5> :pwd\<CR>\|let i = 1 |
| 53 | call assert_equal(':pwd\<CR>\', maparg('<F5>')) |
| 54 | nunmap <F5> |
| 55 | exe "nnoremap <F5> :pwd\<C-V>|let i = 1" |
| 56 | call assert_equal(':pwd|let i = 1', maparg('<F5>')) |
| 57 | nunmap <F5> |
| 58 | set cpo-=b |
| 59 | nnoremap <F5> :pwd\<CR>\|let i = 1 |
| 60 | call assert_equal(':pwd\<CR>|let i = 1', maparg('<F5>')) |
| 61 | let &cpo = save_cpo |
| 62 | nunmap <F5> |
| 63 | endfunc |
| 64 | |
Bram Moolenaar | df7df59 | 2020-06-14 13:50:55 +0200 | [diff] [blame] | 65 | " Test for the 'B' flag in 'cpo'. A backslash in mappings, abbreviations, user |
| 66 | " commands and menu commands has no special meaning. |
| 67 | func Test_cpo_B() |
| 68 | let save_cpo = &cpo |
| 69 | new |
| 70 | set cpo-=B |
| 71 | iabbr <buffer> abc ab\<BS>d |
| 72 | exe "normal iabc " |
| 73 | call assert_equal('ab<BS>d ', getline(1)) |
| 74 | %d |
| 75 | set cpo+=B |
| 76 | iabbr <buffer> abc ab\<BS>d |
| 77 | exe "normal iabc " |
| 78 | call assert_equal('abd ', getline(1)) |
| 79 | close! |
| 80 | let &cpo = save_cpo |
| 81 | endfunc |
| 82 | |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 83 | " Test for the 'c' flag in 'cpo'. |
| 84 | func Test_cpo_c() |
| 85 | let save_cpo = &cpo |
| 86 | set cpo+=c |
| 87 | new |
| 88 | call setline(1, ' abababababab') |
| 89 | exe "normal gg/abab\<CR>" |
| 90 | call assert_equal(3, searchcount().total) |
| 91 | set cpo-=c |
| 92 | exe "normal gg/abab\<CR>" |
| 93 | call assert_equal(5, searchcount().total) |
| 94 | close! |
| 95 | let &cpo = save_cpo |
| 96 | endfunc |
| 97 | |
| 98 | " Test for the 'C' flag in 'cpo' (line continuation) |
| 99 | func Test_cpo_C() |
| 100 | let save_cpo = &cpo |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 101 | call writefile(['let l = [', '\ 1,', '\ 2]'], 'XfileCpoC', 'D') |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 102 | set cpo-=C |
Bram Moolenaar | a85e4db | 2022-08-28 17:44:20 +0100 | [diff] [blame] | 103 | source XfileCpoC |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 104 | call assert_equal([1, 2], g:l) |
| 105 | set cpo+=C |
Bram Moolenaar | a85e4db | 2022-08-28 17:44:20 +0100 | [diff] [blame] | 106 | call assert_fails('source XfileCpoC', ['E697:', 'E10:']) |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 107 | let &cpo = save_cpo |
| 108 | endfunc |
| 109 | |
| 110 | " Test for the 'd' flag in 'cpo' (tags relative to the current file) |
| 111 | func Test_cpo_d() |
| 112 | let save_cpo = &cpo |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 113 | call mkdir('XdirCpoD', 'R') |
| 114 | call writefile(["one\tXfile1\t/^one$/"], 'tags', 'D') |
Bram Moolenaar | a85e4db | 2022-08-28 17:44:20 +0100 | [diff] [blame] | 115 | call writefile(["two\tXfile2\t/^two$/"], 'XdirCpoD/tags') |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 116 | set tags=./tags |
| 117 | set cpo-=d |
Bram Moolenaar | a85e4db | 2022-08-28 17:44:20 +0100 | [diff] [blame] | 118 | edit XdirCpoD/Xfile |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 119 | call assert_equal('two', taglist('.*')[0].name) |
| 120 | set cpo+=d |
| 121 | call assert_equal('one', taglist('.*')[0].name) |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 122 | |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 123 | %bw! |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 124 | set tags& |
| 125 | let &cpo = save_cpo |
| 126 | endfunc |
| 127 | |
| 128 | " Test for the 'D' flag in 'cpo' (digraph after a r, f or t) |
| 129 | func Test_cpo_D() |
| 130 | CheckFeature digraphs |
| 131 | let save_cpo = &cpo |
| 132 | new |
| 133 | set cpo-=D |
| 134 | call setline(1, 'abcdefgh|') |
| 135 | exe "norm! 1gg0f\<c-k>!!" |
| 136 | call assert_equal(9, col('.')) |
| 137 | set cpo+=D |
| 138 | exe "norm! 1gg0f\<c-k>!!" |
| 139 | call assert_equal(1, col('.')) |
| 140 | set cpo-=D |
| 141 | close! |
| 142 | let &cpo = save_cpo |
| 143 | endfunc |
| 144 | |
| 145 | " Test for the 'e' flag in 'cpo' |
| 146 | func Test_cpo_e() |
| 147 | let save_cpo = &cpo |
| 148 | let @a='let i = 45' |
| 149 | set cpo+=e |
| 150 | call feedkeys(":@a\<CR>", 'xt') |
| 151 | call assert_equal(45, i) |
| 152 | set cpo-=e |
| 153 | call feedkeys(":@a\<CR>6\<CR>", 'xt') |
| 154 | call assert_equal(456, i) |
| 155 | let &cpo = save_cpo |
| 156 | endfunc |
| 157 | |
| 158 | " Test for the 'E' flag in 'cpo' with yank, change, delete, etc. operators |
| 159 | func Test_cpo_E() |
| 160 | new |
| 161 | call setline(1, '') |
| 162 | set cpo+=E |
| 163 | " yank an empty line |
| 164 | call assert_beeps('normal "ayl') |
| 165 | " change an empty line |
| 166 | call assert_beeps('normal lcTa') |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 167 | call assert_beeps('normal 0c0') |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 168 | " delete an empty line |
| 169 | call assert_beeps('normal D') |
| 170 | call assert_beeps('normal dl') |
| 171 | call assert_equal('', getline(1)) |
| 172 | " change case of an empty line |
| 173 | call assert_beeps('normal gul') |
| 174 | call assert_beeps('normal gUl') |
| 175 | " replace a character |
| 176 | call assert_beeps('normal vrx') |
| 177 | " increment and decrement |
| 178 | call assert_beeps('exe "normal v\<C-A>"') |
| 179 | call assert_beeps('exe "normal v\<C-X>"') |
| 180 | set cpo-=E |
| 181 | close! |
| 182 | endfunc |
| 183 | |
| 184 | " Test for the 'f' flag in 'cpo' (read in an empty buffer sets the file name) |
| 185 | func Test_cpo_f() |
| 186 | let save_cpo = &cpo |
| 187 | new |
| 188 | set cpo-=f |
| 189 | read test_cpoptions.vim |
| 190 | call assert_equal('', @%) |
| 191 | %d |
| 192 | set cpo+=f |
| 193 | read test_cpoptions.vim |
| 194 | call assert_equal('test_cpoptions.vim', @%) |
| 195 | close! |
| 196 | let &cpo = save_cpo |
| 197 | endfunc |
| 198 | |
| 199 | " Test for the 'F' flag in 'cpo' (write in an empty buffer sets the file name) |
| 200 | func Test_cpo_F() |
| 201 | let save_cpo = &cpo |
| 202 | new |
| 203 | set cpo-=F |
Bram Moolenaar | a85e4db | 2022-08-28 17:44:20 +0100 | [diff] [blame] | 204 | write XfileCpoF |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 205 | call assert_equal('', @%) |
Bram Moolenaar | a85e4db | 2022-08-28 17:44:20 +0100 | [diff] [blame] | 206 | call delete('XfileCpoF') |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 207 | set cpo+=F |
Bram Moolenaar | a85e4db | 2022-08-28 17:44:20 +0100 | [diff] [blame] | 208 | write XfileCpoF |
| 209 | call assert_equal('XfileCpoF', @%) |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 210 | close! |
Bram Moolenaar | a85e4db | 2022-08-28 17:44:20 +0100 | [diff] [blame] | 211 | call delete('XfileCpoF') |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 212 | let &cpo = save_cpo |
| 213 | endfunc |
| 214 | |
| 215 | " Test for the 'g' flag in 'cpo' (jump to line 1 when re-editing a file) |
| 216 | func Test_cpo_g() |
| 217 | let save_cpo = &cpo |
| 218 | new test_cpoptions.vim |
| 219 | set cpo-=g |
| 220 | normal 20G |
| 221 | edit |
| 222 | call assert_equal(20, line('.')) |
| 223 | set cpo+=g |
| 224 | edit |
| 225 | call assert_equal(1, line('.')) |
| 226 | close! |
| 227 | let &cpo = save_cpo |
| 228 | endfunc |
| 229 | |
| 230 | " Test for inserting text in a line with only spaces ('H' flag in 'cpoptions') |
| 231 | func Test_cpo_H() |
| 232 | let save_cpo = &cpo |
| 233 | new |
| 234 | set cpo-=H |
| 235 | call setline(1, ' ') |
| 236 | normal! Ia |
| 237 | call assert_equal(' a', getline(1)) |
| 238 | set cpo+=H |
| 239 | call setline(1, ' ') |
| 240 | normal! Ia |
| 241 | call assert_equal(' a ', getline(1)) |
| 242 | close! |
| 243 | let &cpo = save_cpo |
| 244 | endfunc |
| 245 | |
Bram Moolenaar | df7df59 | 2020-06-14 13:50:55 +0200 | [diff] [blame] | 246 | " TODO: Add a test for the 'i' flag in 'cpo' |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 247 | " Interrupting the reading of a file will leave it modified. |
Bram Moolenaar | df7df59 | 2020-06-14 13:50:55 +0200 | [diff] [blame] | 248 | |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 249 | " Test for the 'I' flag in 'cpo' (deleting autoindent when using arrow keys) |
| 250 | func Test_cpo_I() |
| 251 | let save_cpo = &cpo |
| 252 | new |
| 253 | setlocal autoindent |
| 254 | set cpo+=I |
| 255 | exe "normal i one\<CR>\<Up>" |
| 256 | call assert_equal(' ', getline(2)) |
| 257 | set cpo-=I |
| 258 | %d |
| 259 | exe "normal i one\<CR>\<Up>" |
| 260 | call assert_equal('', getline(2)) |
| 261 | close! |
| 262 | let &cpo = save_cpo |
| 263 | endfunc |
| 264 | |
Bram Moolenaar | df7df59 | 2020-06-14 13:50:55 +0200 | [diff] [blame] | 265 | " Test for the 'j' flag in 'cpo' is in the test_join.vim file. |
| 266 | |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 267 | " Test for the 'J' flag in 'cpo' (two spaces after a sentence) |
| 268 | func Test_cpo_J() |
| 269 | let save_cpo = &cpo |
| 270 | new |
| 271 | set cpo-=J |
| 272 | call setline(1, 'one. two! three? four."'' five.)]') |
| 273 | normal 0 |
| 274 | for colnr in [6, 12, 19, 28, 34] |
| 275 | normal ) |
| 276 | call assert_equal(colnr, col('.')) |
| 277 | endfor |
| 278 | for colnr in [28, 19, 12, 6, 1] |
| 279 | normal ( |
| 280 | call assert_equal(colnr, col('.')) |
| 281 | endfor |
| 282 | set cpo+=J |
| 283 | normal 0 |
| 284 | for colnr in [12, 28, 34] |
| 285 | normal ) |
| 286 | call assert_equal(colnr, col('.')) |
| 287 | endfor |
| 288 | for colnr in [28, 12, 1] |
| 289 | normal ( |
| 290 | call assert_equal(colnr, col('.')) |
| 291 | endfor |
| 292 | close! |
| 293 | let &cpo = save_cpo |
| 294 | endfunc |
| 295 | |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 296 | " TODO: Add a test for the 'k' flag in 'cpo'. |
| 297 | " Disable the recognition of raw key codes in mappings, abbreviations, and the |
| 298 | " "to" part of menu commands. |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 299 | |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 300 | " TODO: Add a test for the 'K' flag in 'cpo'. |
| 301 | " Don't wait for a key code to complete when it is halfway a mapping. |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 302 | |
| 303 | " Test for the 'l' flag in 'cpo' (backslash in a [] range) |
| 304 | func Test_cpo_l() |
| 305 | let save_cpo = &cpo |
| 306 | new |
| 307 | call setline(1, ['', "a\tc" .. '\t']) |
| 308 | set cpo-=l |
| 309 | exe 'normal gg/[\t]' .. "\<CR>" |
| 310 | call assert_equal([2, 8], [col('.'), virtcol('.')]) |
| 311 | set cpo+=l |
| 312 | exe 'normal gg/[\t]' .. "\<CR>" |
| 313 | call assert_equal([4, 10], [col('.'), virtcol('.')]) |
| 314 | close! |
| 315 | let &cpo = save_cpo |
| 316 | endfunc |
| 317 | |
| 318 | " Test for inserting tab in virtual replace mode ('L' flag in 'cpoptions') |
| 319 | func Test_cpo_L() |
| 320 | let save_cpo = &cpo |
| 321 | new |
| 322 | set cpo-=L |
| 323 | call setline(1, 'abcdefghijklmnopqr') |
| 324 | exe "normal 0gR\<Tab>" |
| 325 | call assert_equal("\<Tab>ijklmnopqr", getline(1)) |
| 326 | set cpo+=L |
| 327 | set list |
| 328 | call setline(1, 'abcdefghijklmnopqr') |
| 329 | exe "normal 0gR\<Tab>" |
| 330 | call assert_equal("\<Tab>cdefghijklmnopqr", getline(1)) |
| 331 | set nolist |
| 332 | call setline(1, 'abcdefghijklmnopqr') |
| 333 | exe "normal 0gR\<Tab>" |
| 334 | call assert_equal("\<Tab>ijklmnopqr", getline(1)) |
| 335 | close! |
| 336 | let &cpo = save_cpo |
| 337 | endfunc |
| 338 | |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 339 | " TODO: Add a test for the 'm' flag in 'cpo'. |
| 340 | " When included, a showmatch will always wait half a second. When not |
| 341 | " included, a showmatch will wait half a second or until a character is typed. |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 342 | |
| 343 | " Test for the 'M' flag in 'cpo' (% with escape parenthesis) |
| 344 | func Test_cpo_M() |
| 345 | let save_cpo = &cpo |
| 346 | new |
| 347 | call setline(1, ['( \( )', '\( ( \)']) |
| 348 | |
| 349 | set cpo-=M |
| 350 | call cursor(1, 1) |
| 351 | normal % |
| 352 | call assert_equal(6, col('.')) |
| 353 | call cursor(1, 4) |
| 354 | call assert_beeps('normal %') |
| 355 | call cursor(2, 2) |
| 356 | normal % |
| 357 | call assert_equal(7, col('.')) |
| 358 | call cursor(2, 4) |
| 359 | call assert_beeps('normal %') |
| 360 | |
| 361 | set cpo+=M |
| 362 | call cursor(1, 4) |
| 363 | normal % |
| 364 | call assert_equal(6, col('.')) |
| 365 | call cursor(1, 1) |
| 366 | call assert_beeps('normal %') |
| 367 | call cursor(2, 4) |
| 368 | normal % |
| 369 | call assert_equal(7, col('.')) |
| 370 | call cursor(2, 1) |
| 371 | call assert_beeps('normal %') |
| 372 | |
| 373 | close! |
| 374 | let &cpo = save_cpo |
| 375 | endfunc |
| 376 | |
| 377 | " Test for the 'n' flag in 'cpo' (using number column for wrapped lines) |
| 378 | func Test_cpo_n() |
| 379 | let save_cpo = &cpo |
| 380 | new |
| 381 | call setline(1, repeat('a', &columns)) |
| 382 | setlocal number |
| 383 | set cpo-=n |
| 384 | redraw! |
| 385 | call assert_equal(' aaaa', Screenline(2)) |
| 386 | set cpo+=n |
| 387 | redraw! |
| 388 | call assert_equal('aaaa', Screenline(2)) |
| 389 | close! |
| 390 | let &cpo = save_cpo |
| 391 | endfunc |
| 392 | |
| 393 | " Test for the 'o' flag in 'cpo' (line offset to search command) |
| 394 | func Test_cpo_o() |
| 395 | let save_cpo = &cpo |
| 396 | new |
| 397 | call setline(1, ['', 'one', 'two', 'three', 'one', 'two', 'three']) |
| 398 | set cpo-=o |
| 399 | exe "normal /one/+2\<CR>" |
| 400 | normal n |
| 401 | call assert_equal(7, line('.')) |
| 402 | set cpo+=o |
| 403 | exe "normal /one/+2\<CR>" |
| 404 | normal n |
| 405 | call assert_equal(5, line('.')) |
| 406 | close! |
| 407 | let &cpo = save_cpo |
| 408 | endfunc |
| 409 | |
| 410 | " Test for the 'O' flag in 'cpo' (overwriting an existing file) |
| 411 | func Test_cpo_O() |
| 412 | let save_cpo = &cpo |
Bram Moolenaar | a85e4db | 2022-08-28 17:44:20 +0100 | [diff] [blame] | 413 | new XfileCpoO |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 414 | call setline(1, 'one') |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 415 | call writefile(['two'], 'XfileCpoO', 'D') |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 416 | set cpo-=O |
| 417 | call assert_fails('write', 'E13:') |
| 418 | set cpo+=O |
| 419 | write |
Bram Moolenaar | a85e4db | 2022-08-28 17:44:20 +0100 | [diff] [blame] | 420 | call assert_equal(['one'], readfile('XfileCpoO')) |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 421 | close! |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 422 | let &cpo = save_cpo |
| 423 | endfunc |
| 424 | |
Bram Moolenaar | d26c580 | 2022-10-13 12:30:08 +0100 | [diff] [blame] | 425 | " Test for the 'p' flag in 'cpo' is in the test_lispindent.vim file. |
Bram Moolenaar | df7df59 | 2020-06-14 13:50:55 +0200 | [diff] [blame] | 426 | |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 427 | " Test for the 'P' flag in 'cpo' (appending to a file sets the current file |
| 428 | " name) |
| 429 | func Test_cpo_P() |
| 430 | let save_cpo = &cpo |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 431 | call writefile([], 'XfileCpoP', 'D') |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 432 | new |
| 433 | call setline(1, 'one') |
| 434 | set cpo+=F |
| 435 | set cpo-=P |
Bram Moolenaar | a85e4db | 2022-08-28 17:44:20 +0100 | [diff] [blame] | 436 | write >> XfileCpoP |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 437 | call assert_equal('', @%) |
| 438 | set cpo+=P |
Bram Moolenaar | a85e4db | 2022-08-28 17:44:20 +0100 | [diff] [blame] | 439 | write >> XfileCpoP |
| 440 | call assert_equal('XfileCpoP', @%) |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 441 | close! |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 442 | let &cpo = save_cpo |
| 443 | endfunc |
| 444 | |
| 445 | " Test for the 'q' flag in 'cpo' (joining multiple lines) |
| 446 | func Test_cpo_q() |
| 447 | let save_cpo = &cpo |
| 448 | new |
| 449 | call setline(1, ['one', 'two', 'three', 'four', 'five']) |
| 450 | set cpo-=q |
| 451 | normal gg4J |
| 452 | call assert_equal(14, col('.')) |
| 453 | %d |
| 454 | call setline(1, ['one', 'two', 'three', 'four', 'five']) |
| 455 | set cpo+=q |
| 456 | normal gg4J |
| 457 | call assert_equal(4, col('.')) |
| 458 | close! |
| 459 | let &cpo = save_cpo |
| 460 | endfunc |
| 461 | |
| 462 | " Test for the 'r' flag in 'cpo' (redo command with a search motion) |
| 463 | func Test_cpo_r() |
| 464 | let save_cpo = &cpo |
| 465 | new |
| 466 | call setline(1, repeat(['one two three four'], 2)) |
| 467 | set cpo-=r |
| 468 | exe "normal ggc/two\<CR>abc " |
| 469 | let @/ = 'three' |
| 470 | normal 2G. |
| 471 | call assert_equal('abc two three four', getline(2)) |
| 472 | %d |
| 473 | call setline(1, repeat(['one two three four'], 2)) |
| 474 | set cpo+=r |
| 475 | exe "normal ggc/two\<CR>abc " |
| 476 | let @/ = 'three' |
| 477 | normal 2G. |
| 478 | call assert_equal('abc three four', getline(2)) |
| 479 | close! |
| 480 | let &cpo = save_cpo |
| 481 | endfunc |
| 482 | |
| 483 | " Test for the 'R' flag in 'cpo' (clear marks after a filter command) |
| 484 | func Test_cpo_R() |
| 485 | CheckUnix |
| 486 | let save_cpo = &cpo |
| 487 | new |
| 488 | call setline(1, ['three', 'one', 'two']) |
| 489 | set cpo-=R |
| 490 | 3mark r |
| 491 | %!sort |
| 492 | call assert_equal(3, line("'r")) |
| 493 | %d |
| 494 | call setline(1, ['three', 'one', 'two']) |
| 495 | set cpo+=R |
| 496 | 3mark r |
| 497 | %!sort |
| 498 | call assert_equal(0, line("'r")) |
| 499 | close! |
| 500 | let &cpo = save_cpo |
| 501 | endfunc |
| 502 | |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 503 | " TODO: Add a test for the 's' flag in 'cpo'. |
| 504 | " Set buffer options when entering the buffer for the first time. If not |
| 505 | " present the options are set when the buffer is created. |
Bram Moolenaar | df7df59 | 2020-06-14 13:50:55 +0200 | [diff] [blame] | 506 | |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 507 | " Test for the 'S' flag in 'cpo' (copying buffer options) |
| 508 | func Test_cpo_S() |
| 509 | let save_cpo = &cpo |
| 510 | new Xfile1 |
| 511 | set noautoindent |
| 512 | new Xfile2 |
| 513 | set cpo-=S |
| 514 | set autoindent |
| 515 | wincmd p |
| 516 | call assert_equal(0, &autoindent) |
| 517 | wincmd p |
| 518 | call assert_equal(1, &autoindent) |
| 519 | set cpo+=S |
| 520 | wincmd p |
| 521 | call assert_equal(1, &autoindent) |
| 522 | set noautoindent |
| 523 | wincmd p |
| 524 | call assert_equal(0, &autoindent) |
| 525 | wincmd t |
| 526 | close! |
| 527 | close! |
| 528 | let &cpo = save_cpo |
| 529 | endfunc |
| 530 | |
Bram Moolenaar | df7df59 | 2020-06-14 13:50:55 +0200 | [diff] [blame] | 531 | " Test for the 't' flag in 'cpo' is in the test_tagjump.vim file. |
| 532 | |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 533 | " Test for the 'u' flag in 'cpo' (Vi-compatible undo) |
| 534 | func Test_cpo_u() |
| 535 | let save_cpo = &cpo |
| 536 | new |
| 537 | set cpo-=u |
| 538 | exe "normal iabc\<C-G>udef\<C-G>ughi" |
| 539 | normal uu |
| 540 | call assert_equal('abc', getline(1)) |
| 541 | %d |
| 542 | set cpo+=u |
| 543 | exe "normal iabc\<C-G>udef\<C-G>ughi" |
| 544 | normal uu |
| 545 | call assert_equal('abcdefghi', getline(1)) |
| 546 | close! |
| 547 | let &cpo = save_cpo |
| 548 | endfunc |
| 549 | |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 550 | " TODO: Add a test for the 'v' flag in 'cpo'. |
| 551 | " Backspaced characters remain visible on the screen in Insert mode. |
Bram Moolenaar | df7df59 | 2020-06-14 13:50:55 +0200 | [diff] [blame] | 552 | |
| 553 | " Test for the 'w' flag in 'cpo' ('cw' on a blank character changes only one |
| 554 | " character) |
| 555 | func Test_cpo_w() |
| 556 | let save_cpo = &cpo |
| 557 | new |
| 558 | set cpo+=w |
| 559 | call setline(1, 'here are some words') |
| 560 | norm! 1gg0elcwZZZ |
| 561 | call assert_equal('hereZZZ are some words', getline('.')) |
| 562 | norm! 1gg2elcWYYY |
| 563 | call assert_equal('hereZZZ areYYY some words', getline('.')) |
| 564 | set cpo-=w |
| 565 | call setline(1, 'here are some words') |
| 566 | norm! 1gg0elcwZZZ |
| 567 | call assert_equal('hereZZZare some words', getline('.')) |
| 568 | norm! 1gg2elcWYYY |
| 569 | call assert_equal('hereZZZare someYYYwords', getline('.')) |
| 570 | close! |
| 571 | let &cpo = save_cpo |
| 572 | endfunc |
| 573 | |
| 574 | " Test for the 'W' flag in 'cpo' is in the test_writefile.vim file |
| 575 | |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 576 | " Test for the 'x' flag in 'cpo' (Esc on command-line executes command) |
| 577 | func Test_cpo_x() |
| 578 | let save_cpo = &cpo |
| 579 | set cpo-=x |
| 580 | let i = 1 |
| 581 | call feedkeys(":let i=10\<Esc>", 'xt') |
| 582 | call assert_equal(1, i) |
| 583 | set cpo+=x |
| 584 | call feedkeys(":let i=10\<Esc>", 'xt') |
| 585 | call assert_equal(10, i) |
| 586 | let &cpo = save_cpo |
| 587 | endfunc |
| 588 | |
| 589 | " Test for the 'X' flag in 'cpo' ('R' with a count) |
| 590 | func Test_cpo_X() |
| 591 | let save_cpo = &cpo |
| 592 | new |
| 593 | call setline(1, 'aaaaaa') |
| 594 | set cpo-=X |
| 595 | normal gg4Rx |
| 596 | call assert_equal('xxxxaa', getline(1)) |
| 597 | normal ggRy |
| 598 | normal 4. |
| 599 | call assert_equal('yyyyaa', getline(1)) |
| 600 | call setline(1, 'aaaaaa') |
| 601 | set cpo+=X |
| 602 | normal gg4Rx |
| 603 | call assert_equal('xxxxaaaaa', getline(1)) |
| 604 | normal ggRy |
| 605 | normal 4. |
| 606 | call assert_equal('yyyyxxxaaaaa', getline(1)) |
| 607 | close! |
| 608 | let &cpo = save_cpo |
| 609 | endfunc |
| 610 | |
| 611 | " Test for the 'y' flag in 'cpo' (repeating a yank command) |
| 612 | func Test_cpo_y() |
| 613 | let save_cpo = &cpo |
| 614 | new |
| 615 | call setline(1, ['one', 'two']) |
| 616 | set cpo-=y |
| 617 | normal ggyy |
| 618 | normal 2G. |
| 619 | call assert_equal("one\n", @") |
| 620 | %d |
| 621 | call setline(1, ['one', 'two']) |
| 622 | set cpo+=y |
| 623 | normal ggyy |
| 624 | normal 2G. |
| 625 | call assert_equal("two\n", @") |
| 626 | close! |
| 627 | let &cpo = save_cpo |
| 628 | endfunc |
| 629 | |
| 630 | " Test for the 'Z' flag in 'cpo' (write! resets 'readonly') |
| 631 | func Test_cpo_Z() |
| 632 | let save_cpo = &cpo |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 633 | call writefile([], 'XfileCpoZ', 'D') |
Bram Moolenaar | a85e4db | 2022-08-28 17:44:20 +0100 | [diff] [blame] | 634 | new XfileCpoZ |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 635 | setlocal readonly |
| 636 | set cpo-=Z |
| 637 | write! |
| 638 | call assert_equal(0, &readonly) |
| 639 | set cpo+=Z |
| 640 | setlocal readonly |
| 641 | write! |
| 642 | call assert_equal(1, &readonly) |
| 643 | close! |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 644 | let &cpo = save_cpo |
| 645 | endfunc |
| 646 | |
Bram Moolenaar | df7df59 | 2020-06-14 13:50:55 +0200 | [diff] [blame] | 647 | " Test for the '!' flag in 'cpo' is in the test_normal.vim file |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 648 | |
| 649 | " Test for displaying dollar when changing text ('$' flag in 'cpoptions') |
| 650 | func Test_cpo_dollar() |
| 651 | new |
| 652 | let g:Line = '' |
| 653 | func SaveFirstLine() |
| 654 | let g:Line = Screenline(1) |
| 655 | return '' |
| 656 | endfunc |
| 657 | inoremap <expr> <buffer> <F2> SaveFirstLine() |
| 658 | call test_override('redraw_flag', 1) |
| 659 | set cpo+=$ |
| 660 | call setline(1, 'one two three') |
| 661 | redraw! |
| 662 | exe "normal c2w\<F2>vim" |
| 663 | call assert_equal('one tw$ three', g:Line) |
| 664 | call assert_equal('vim three', getline(1)) |
| 665 | set cpo-=$ |
| 666 | call test_override('ALL', 0) |
| 667 | delfunc SaveFirstLine |
| 668 | %bw! |
| 669 | endfunc |
| 670 | |
Bram Moolenaar | df7df59 | 2020-06-14 13:50:55 +0200 | [diff] [blame] | 671 | " Test for the '%' flag in 'cpo' (parenthesis matching inside strings) |
| 672 | func Test_cpo_percent() |
| 673 | let save_cpo = &cpo |
| 674 | new |
| 675 | call setline(1, ' if (strcmp("ab)cd(", s))') |
| 676 | set cpo-=% |
| 677 | normal 8|% |
| 678 | call assert_equal(28, col('.')) |
| 679 | normal 15|% |
| 680 | call assert_equal(27, col('.')) |
| 681 | normal 27|% |
| 682 | call assert_equal(15, col('.')) |
| 683 | call assert_beeps("normal 19|%") |
| 684 | call assert_beeps("normal 22|%") |
| 685 | set cpo+=% |
| 686 | normal 8|% |
| 687 | call assert_equal(28, col('.')) |
| 688 | normal 15|% |
| 689 | call assert_equal(19, col('.')) |
| 690 | normal 27|% |
| 691 | call assert_equal(22, col('.')) |
| 692 | normal 19|% |
| 693 | call assert_equal(15, col('.')) |
| 694 | normal 22|% |
| 695 | call assert_equal(27, col('.')) |
| 696 | close! |
| 697 | let &cpo = save_cpo |
| 698 | endfunc |
| 699 | |
| 700 | " Test for cursor movement with '-' in 'cpoptions' |
| 701 | func Test_cpo_minus() |
| 702 | new |
| 703 | call setline(1, ['foo', 'bar', 'baz']) |
| 704 | let save_cpo = &cpo |
| 705 | set cpo+=- |
| 706 | call assert_beeps('normal 10j') |
| 707 | call assert_equal(1, line('.')) |
| 708 | normal G |
| 709 | call assert_beeps('normal 10k') |
| 710 | call assert_equal(3, line('.')) |
| 711 | call assert_fails(10, 'E16:') |
| 712 | close! |
| 713 | let &cpo = save_cpo |
| 714 | endfunc |
| 715 | |
| 716 | " Test for the '+' flag in 'cpo' ('write file' command resets the 'modified' |
| 717 | " flag) |
| 718 | func Test_cpo_plus() |
| 719 | let save_cpo = &cpo |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 720 | call writefile([], 'XfileCpoPlus', 'D') |
Bram Moolenaar | a85e4db | 2022-08-28 17:44:20 +0100 | [diff] [blame] | 721 | new XfileCpoPlus |
Bram Moolenaar | df7df59 | 2020-06-14 13:50:55 +0200 | [diff] [blame] | 722 | call setline(1, 'foo') |
| 723 | write X1 |
| 724 | call assert_equal(1, &modified) |
| 725 | set cpo+=+ |
| 726 | write X2 |
| 727 | call assert_equal(0, &modified) |
| 728 | close! |
Bram Moolenaar | df7df59 | 2020-06-14 13:50:55 +0200 | [diff] [blame] | 729 | call delete('X1') |
| 730 | call delete('X2') |
| 731 | let &cpo = save_cpo |
| 732 | endfunc |
| 733 | |
| 734 | " Test for the '*' flag in 'cpo' (':*' is same as ':@') |
| 735 | func Test_cpo_star() |
| 736 | let save_cpo = &cpo |
| 737 | let x = 0 |
| 738 | new |
| 739 | set cpo-=* |
| 740 | let @a = 'let x += 1' |
| 741 | call assert_fails('*a', 'E20:') |
| 742 | set cpo+=* |
| 743 | *a |
| 744 | call assert_equal(1, x) |
| 745 | close! |
| 746 | let &cpo = save_cpo |
| 747 | endfunc |
| 748 | |
| 749 | " Test for the '<' flag in 'cpo' is in the test_mapping.vim file |
| 750 | |
| 751 | " Test for the '>' flag in 'cpo' (use a new line when appending to a register) |
| 752 | func Test_cpo_gt() |
| 753 | let save_cpo = &cpo |
| 754 | new |
| 755 | call setline(1, 'one two') |
| 756 | set cpo-=> |
| 757 | let @r = '' |
| 758 | normal gg"Rye |
| 759 | normal "Rye |
| 760 | call assert_equal("oneone", @r) |
| 761 | set cpo+=> |
| 762 | let @r = '' |
| 763 | normal gg"Rye |
| 764 | normal "Rye |
| 765 | call assert_equal("\none\none", @r) |
| 766 | close! |
| 767 | let &cpo = save_cpo |
| 768 | endfunc |
| 769 | |
| 770 | " Test for the ';' flag in 'cpo' |
| 771 | " Test for t,f,F,T movement commands and 'cpo-;' setting |
| 772 | func Test_cpo_semicolon() |
| 773 | let save_cpo = &cpo |
| 774 | new |
| 775 | call append(0, ["aaa two three four", " zzz", "yyy ", |
| 776 | \ "bbb yee yoo four", "ccc two three four", |
| 777 | \ "ddd yee yoo four"]) |
| 778 | set cpo-=; |
| 779 | 1 |
| 780 | normal! 0tt;D |
| 781 | 2 |
| 782 | normal! 0fz;D |
| 783 | 3 |
| 784 | normal! $Fy;D |
| 785 | 4 |
| 786 | normal! $Ty;D |
| 787 | set cpo+=; |
| 788 | 5 |
| 789 | normal! 0tt;;D |
| 790 | 6 |
| 791 | normal! $Ty;;D |
| 792 | |
| 793 | call assert_equal('aaa two', getline(1)) |
| 794 | call assert_equal(' z', getline(2)) |
| 795 | call assert_equal('y', getline(3)) |
| 796 | call assert_equal('bbb y', getline(4)) |
| 797 | call assert_equal('ccc', getline(5)) |
| 798 | call assert_equal('ddd yee y', getline(6)) |
| 799 | close! |
| 800 | let &cpo = save_cpo |
| 801 | endfunc |
| 802 | |
| 803 | " Test for the '#' flag in 'cpo' (count before 'D', 'o' and 'O' operators) |
| 804 | func Test_cpo_hash() |
| 805 | let save_cpo = &cpo |
| 806 | new |
| 807 | set cpo-=# |
| 808 | call setline(1, ['one', 'two', 'three']) |
| 809 | normal gg2D |
| 810 | call assert_equal(['three'], getline(1, '$')) |
| 811 | normal gg2ofour |
| 812 | call assert_equal(['three', 'four', 'four'], getline(1, '$')) |
| 813 | normal gg2Otwo |
| 814 | call assert_equal(['two', 'two', 'three', 'four', 'four'], getline(1, '$')) |
| 815 | %d |
| 816 | set cpo+=# |
| 817 | call setline(1, ['one', 'two', 'three']) |
| 818 | normal gg2D |
| 819 | call assert_equal(['', 'two', 'three'], getline(1, '$')) |
| 820 | normal gg2oone |
| 821 | call assert_equal(['', 'one', 'two', 'three'], getline(1, '$')) |
| 822 | normal gg2Ozero |
| 823 | call assert_equal(['zero', '', 'one', 'two', 'three'], getline(1, '$')) |
| 824 | close! |
| 825 | let &cpo = save_cpo |
| 826 | endfunc |
| 827 | |
| 828 | " Test for the '&' flag in 'cpo'. The swap file is kept when a buffer is still |
| 829 | " loaded and ':preserve' is used. |
| 830 | func Test_cpo_ampersand() |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 831 | call writefile(['one'], 'XfileCpoAmp', 'D') |
Bram Moolenaar | df7df59 | 2020-06-14 13:50:55 +0200 | [diff] [blame] | 832 | let after =<< trim [CODE] |
| 833 | set cpo+=& |
| 834 | preserve |
| 835 | qall |
| 836 | [CODE] |
Bram Moolenaar | a85e4db | 2022-08-28 17:44:20 +0100 | [diff] [blame] | 837 | if RunVim([], after, 'XfileCpoAmp') |
| 838 | call assert_equal(1, filereadable('.XfileCpoAmp.swp')) |
| 839 | call delete('.XfileCpoAmp.swp') |
Bram Moolenaar | df7df59 | 2020-06-14 13:50:55 +0200 | [diff] [blame] | 840 | endif |
Bram Moolenaar | df7df59 | 2020-06-14 13:50:55 +0200 | [diff] [blame] | 841 | endfunc |
| 842 | |
| 843 | " Test for the '\' flag in 'cpo' (backslash in a [] range in a search pattern) |
| 844 | func Test_cpo_backslash() |
| 845 | let save_cpo = &cpo |
| 846 | new |
| 847 | call setline(1, ['', " \\-string"]) |
| 848 | set cpo-=\ |
| 849 | exe 'normal gg/[ \-]' .. "\<CR>n" |
| 850 | call assert_equal(3, col('.')) |
| 851 | set cpo+=\ |
| 852 | exe 'normal gg/[ \-]' .. "\<CR>n" |
| 853 | call assert_equal(2, col('.')) |
| 854 | close! |
| 855 | let &cpo = save_cpo |
| 856 | endfunc |
| 857 | |
| 858 | " Test for the '/' flag in 'cpo' is in the test_substitute.vim file |
| 859 | |
| 860 | " Test for the '{' flag in 'cpo' (the "{" and "}" commands stop at a { |
| 861 | " character at the start of a line) |
| 862 | func Test_cpo_brace() |
| 863 | let save_cpo = &cpo |
| 864 | new |
| 865 | call setline(1, ['', '{', ' int i;', '}', '']) |
| 866 | set cpo-={ |
| 867 | normal gg} |
| 868 | call assert_equal(5, line('.')) |
| 869 | normal G{ |
| 870 | call assert_equal(1, line('.')) |
| 871 | set cpo+={ |
| 872 | normal gg} |
| 873 | call assert_equal(2, line('.')) |
| 874 | normal G{ |
| 875 | call assert_equal(2, line('.')) |
| 876 | close! |
| 877 | let &cpo = save_cpo |
| 878 | endfunc |
| 879 | |
| 880 | " Test for the '.' flag in 'cpo' (:cd command fails if the current buffer is |
| 881 | " modified) |
| 882 | func Test_cpo_dot() |
| 883 | let save_cpo = &cpo |
| 884 | new Xfoo |
| 885 | call setline(1, 'foo') |
| 886 | let save_dir = getcwd() |
| 887 | set cpo+=. |
| 888 | |
| 889 | " :cd should fail when buffer is modified and 'cpo' contains dot. |
| 890 | call assert_fails('cd ..', 'E747:') |
| 891 | call assert_equal(save_dir, getcwd()) |
| 892 | |
| 893 | " :cd with exclamation mark should succeed. |
| 894 | cd! .. |
| 895 | call assert_notequal(save_dir, getcwd()) |
| 896 | |
| 897 | " :cd should succeed when buffer has been written. |
| 898 | w! |
| 899 | exe 'cd ' .. fnameescape(save_dir) |
| 900 | call assert_equal(save_dir, getcwd()) |
| 901 | |
| 902 | call delete('Xfoo') |
| 903 | set cpo& |
| 904 | close! |
| 905 | let &cpo = save_cpo |
| 906 | endfunc |
| 907 | |
Bram Moolenaar | c9630d2 | 2020-06-13 13:20:48 +0200 | [diff] [blame] | 908 | " vim: shiftwidth=2 sts=2 expandtab |