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