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