Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 1 | " Test for linebreak and list option (non-utf8) |
| 2 | |
| 3 | set encoding=latin1 |
| 4 | scriptencoding latin1 |
| 5 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 6 | source check.vim |
| 7 | CheckOption linebreak |
| 8 | CheckFeature conceal |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 9 | |
| 10 | source view_util.vim |
Bram Moolenaar | 16dab41 | 2022-10-08 16:41:32 +0100 | [diff] [blame] | 11 | source screendump.vim |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 12 | |
| 13 | function s:screen_lines(lnum, width) abort |
| 14 | return ScreenLines(a:lnum, a:width) |
| 15 | endfunction |
| 16 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 17 | func s:compare_lines(expect, actual) |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 18 | call assert_equal(a:expect, a:actual) |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 19 | endfunc |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 20 | |
| 21 | function s:test_windows(...) |
| 22 | call NewWindow(10, 20) |
| 23 | setl ts=8 sw=4 sts=4 linebreak sbr= wrap |
| 24 | exe get(a:000, 0, '') |
| 25 | endfunction |
| 26 | |
| 27 | function s:close_windows(...) |
| 28 | call CloseWindow() |
| 29 | exe get(a:000, 0, '') |
| 30 | endfunction |
| 31 | |
| 32 | func Test_set_linebreak() |
| 33 | call s:test_windows('setl ts=4 sbr=+') |
| 34 | call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ") |
| 35 | let lines = s:screen_lines([1, 4], winwidth(0)) |
| 36 | let expect = [ |
| 37 | \ " abcdef ", |
| 38 | \ "+hijklmn ", |
| 39 | \ "+pqrstuvwxyz_1060ABC", |
| 40 | \ "+DEFGHIJKLMNOP ", |
| 41 | \ ] |
| 42 | call s:compare_lines(expect, lines) |
| 43 | call s:close_windows() |
| 44 | endfunc |
| 45 | |
| 46 | func Test_linebreak_with_list() |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 47 | set listchars= |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 48 | call s:test_windows('setl ts=4 sbr=+ list listchars=') |
| 49 | call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ") |
| 50 | let lines = s:screen_lines([1, 4], winwidth(0)) |
| 51 | let expect = [ |
| 52 | \ "^Iabcdef hijklmn^I ", |
| 53 | \ "+pqrstuvwxyz_1060ABC", |
| 54 | \ "+DEFGHIJKLMNOP ", |
| 55 | \ "~ ", |
| 56 | \ ] |
| 57 | call s:compare_lines(expect, lines) |
| 58 | call s:close_windows() |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 59 | set listchars&vim |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 60 | endfunc |
| 61 | |
| 62 | func Test_linebreak_with_nolist() |
| 63 | call s:test_windows('setl ts=4 sbr=+ nolist') |
| 64 | call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ") |
| 65 | let lines = s:screen_lines([1, 4], winwidth(0)) |
| 66 | let expect = [ |
| 67 | \ " abcdef ", |
| 68 | \ "+hijklmn ", |
| 69 | \ "+pqrstuvwxyz_1060ABC", |
| 70 | \ "+DEFGHIJKLMNOP ", |
| 71 | \ ] |
| 72 | call s:compare_lines(expect, lines) |
| 73 | call s:close_windows() |
| 74 | endfunc |
| 75 | |
h-east | 194555c | 2023-03-02 18:49:09 +0000 | [diff] [blame] | 76 | func Test_linebreak_with_list_and_number() |
| 77 | call s:test_windows('setl list listchars+=tab:>-') |
| 78 | call setline(1, ["abcdefg\thijklmnopqrstu", "v"]) |
| 79 | let lines = s:screen_lines([1, 4], winwidth(0)) |
| 80 | let expect_nonumber = [ |
| 81 | \ "abcdefg>------------", |
| 82 | \ "hijklmnopqrstu$ ", |
| 83 | \ "v$ ", |
| 84 | \ "~ ", |
| 85 | \ ] |
| 86 | call s:compare_lines(expect_nonumber, lines) |
| 87 | |
| 88 | setl number |
| 89 | let lines = s:screen_lines([1, 4], winwidth(0)) |
| 90 | let expect_number = [ |
| 91 | \ " 1 abcdefg>--------", |
| 92 | \ " hijklmnopqrstu$ ", |
| 93 | \ " 2 v$ ", |
| 94 | \ "~ ", |
| 95 | \ ] |
| 96 | call s:compare_lines(expect_number, lines) |
| 97 | call s:close_windows() |
| 98 | endfunc |
| 99 | |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 100 | func Test_should_break() |
| 101 | call s:test_windows('setl sbr=+ nolist') |
| 102 | call setline(1, "1\t" . repeat('a', winwidth(0)-2)) |
| 103 | let lines = s:screen_lines([1, 4], winwidth(0)) |
| 104 | let expect = [ |
| 105 | \ "1 ", |
| 106 | \ "+aaaaaaaaaaaaaaaaaa ", |
| 107 | \ "~ ", |
| 108 | \ "~ ", |
| 109 | \ ] |
| 110 | call s:compare_lines(expect, lines) |
| 111 | call s:close_windows() |
| 112 | endfunc |
| 113 | |
| 114 | func Test_linebreak_with_conceal() |
| 115 | call s:test_windows('setl cpo&vim sbr=+ list conceallevel=2 concealcursor=nv listchars=tab:ab') |
| 116 | call setline(1, "_S_\t bla") |
| 117 | syn match ConcealVar contained /_/ conceal |
| 118 | syn match All /.*/ contains=ConcealVar |
| 119 | let lines = s:screen_lines([1, 4], winwidth(0)) |
| 120 | let expect = [ |
| 121 | \ "Sabbbbbb bla ", |
| 122 | \ "~ ", |
| 123 | \ "~ ", |
| 124 | \ "~ ", |
| 125 | \ ] |
| 126 | call s:compare_lines(expect, lines) |
| 127 | call s:close_windows() |
| 128 | endfunc |
| 129 | |
Bram Moolenaar | 03c3bd9 | 2020-01-23 20:58:09 +0100 | [diff] [blame] | 130 | func Test_linebreak_with_visual_operations() |
| 131 | call s:test_windows() |
| 132 | let line = '1234567890 2234567890 3234567890' |
| 133 | call setline(1, line) |
| 134 | |
| 135 | " yank |
| 136 | exec "norm! ^w\<C-V>ey" |
| 137 | call assert_equal('2234567890', @@) |
| 138 | exec "norm! w\<C-V>ey" |
| 139 | call assert_equal('3234567890', @@) |
| 140 | |
| 141 | " increment / decrement |
| 142 | exec "norm! ^w\<C-V>\<C-A>w\<C-V>\<C-X>" |
| 143 | call assert_equal('1234567890 3234567890 2234567890', getline(1)) |
| 144 | |
| 145 | " replace |
| 146 | exec "norm! ^w\<C-V>3lraw\<C-V>3lrb" |
| 147 | call assert_equal('1234567890 aaaa567890 bbbb567890', getline(1)) |
| 148 | |
| 149 | " tilde |
| 150 | exec "norm! ^w\<C-V>2l~w\<C-V>2l~" |
| 151 | call assert_equal('1234567890 AAAa567890 BBBb567890', getline(1)) |
| 152 | |
| 153 | " delete and insert |
| 154 | exec "norm! ^w\<C-V>3lc2345\<Esc>w\<C-V>3lc3456\<Esc>" |
| 155 | call assert_equal('1234567890 2345567890 3456567890', getline(1)) |
| 156 | call assert_equal('BBBb', @@) |
| 157 | |
| 158 | call s:close_windows() |
| 159 | endfunc |
| 160 | |
zeertzjq | 30c0c46 | 2022-10-09 11:44:28 +0100 | [diff] [blame] | 161 | " Test that cursor is drawn at correct position after an operator when |
| 162 | " 'linebreak' is enabled. |
Bram Moolenaar | 16dab41 | 2022-10-08 16:41:32 +0100 | [diff] [blame] | 163 | func Test_linebreak_reset_restore() |
| 164 | CheckScreendump |
| 165 | |
zeertzjq | 30c0c46 | 2022-10-09 11:44:28 +0100 | [diff] [blame] | 166 | " f_wincol() calls validate_cursor() |
Bram Moolenaar | 16dab41 | 2022-10-08 16:41:32 +0100 | [diff] [blame] | 167 | let lines =<< trim END |
zeertzjq | 30c0c46 | 2022-10-09 11:44:28 +0100 | [diff] [blame] | 168 | set linebreak showcmd noshowmode formatexpr=wincol()-wincol() |
| 169 | call setline(1, repeat('a', &columns - 10) .. ' bbbbbbbbbb c') |
Bram Moolenaar | 16dab41 | 2022-10-08 16:41:32 +0100 | [diff] [blame] | 170 | END |
| 171 | call writefile(lines, 'XlbrResetRestore', 'D') |
| 172 | let buf = RunVimInTerminal('-S XlbrResetRestore', {'rows': 8}) |
| 173 | |
zeertzjq | 30c0c46 | 2022-10-09 11:44:28 +0100 | [diff] [blame] | 174 | call term_sendkeys(buf, '$v$') |
| 175 | call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])}) |
| 176 | call term_sendkeys(buf, 'zo') |
| 177 | call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])}) |
| 178 | |
| 179 | call term_sendkeys(buf, '$v$') |
| 180 | call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])}) |
| 181 | call term_sendkeys(buf, 'gq') |
| 182 | call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])}) |
| 183 | |
| 184 | call term_sendkeys(buf, "$\<C-V>$") |
| 185 | call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])}) |
| 186 | call term_sendkeys(buf, 'I') |
| 187 | call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])}) |
| 188 | |
| 189 | call term_sendkeys(buf, "\<Esc>$v$") |
| 190 | call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])}) |
| 191 | call term_sendkeys(buf, 's') |
| 192 | call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])}) |
Bram Moolenaar | 16dab41 | 2022-10-08 16:41:32 +0100 | [diff] [blame] | 193 | call VerifyScreenDump(buf, 'Test_linebreak_reset_restore_1', {}) |
| 194 | |
zeertzjq | 30c0c46 | 2022-10-09 11:44:28 +0100 | [diff] [blame] | 195 | " clean up |
Bram Moolenaar | 16dab41 | 2022-10-08 16:41:32 +0100 | [diff] [blame] | 196 | call term_sendkeys(buf, "\<Esc>") |
| 197 | call StopVimInTerminal(buf) |
| 198 | endfunc |
| 199 | |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 200 | func Test_virtual_block() |
| 201 | call s:test_windows('setl sbr=+') |
| 202 | call setline(1, [ |
| 203 | \ "REMOVE: this not", |
| 204 | \ "REMOVE: aaaaaaaaaaaaa", |
| 205 | \ ]) |
| 206 | exe "norm! 1/^REMOVE:" |
| 207 | exe "norm! 0\<C-V>jf x" |
| 208 | $put |
| 209 | let lines = s:screen_lines([1, 4], winwidth(0)) |
| 210 | let expect = [ |
| 211 | \ "this not ", |
| 212 | \ "aaaaaaaaaaaaa ", |
| 213 | \ "REMOVE: ", |
| 214 | \ "REMOVE: ", |
| 215 | \ ] |
| 216 | call s:compare_lines(expect, lines) |
| 217 | call s:close_windows() |
| 218 | endfunc |
| 219 | |
| 220 | func Test_virtual_block_and_vbA() |
| 221 | call s:test_windows() |
| 222 | call setline(1, "long line: " . repeat("foobar ", 40) . "TARGET at end") |
| 223 | exe "norm! $3B\<C-v>eAx\<Esc>" |
| 224 | let lines = s:screen_lines([1, 10], winwidth(0)) |
| 225 | let expect = [ |
Bram Moolenaar | 0466d39 | 2022-10-03 17:07:34 +0100 | [diff] [blame] | 226 | \ "<<<bar foobar ", |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 227 | \ "foobar foobar ", |
| 228 | \ "foobar foobar ", |
| 229 | \ "foobar foobar ", |
| 230 | \ "foobar foobar ", |
| 231 | \ "foobar foobar ", |
| 232 | \ "foobar foobar ", |
| 233 | \ "foobar foobar ", |
| 234 | \ "foobar foobar ", |
| 235 | \ "foobar TARGETx at ", |
| 236 | \ ] |
| 237 | call s:compare_lines(expect, lines) |
| 238 | call s:close_windows() |
| 239 | endfunc |
| 240 | |
| 241 | func Test_virtual_char_and_block() |
| 242 | call s:test_windows() |
| 243 | call setline(1, "1111-1111-1111-11-1111-1111-1111") |
| 244 | exe "norm! 0f-lv3lc2222\<Esc>bgj." |
| 245 | let lines = s:screen_lines([1, 2], winwidth(0)) |
| 246 | let expect = [ |
| 247 | \ "1111-2222-1111-11- ", |
| 248 | \ "1111-2222-1111 ", |
| 249 | \ ] |
| 250 | call s:compare_lines(expect, lines) |
| 251 | call s:close_windows() |
| 252 | endfunc |
| 253 | |
| 254 | func Test_undo_after_block_visual() |
| 255 | call s:test_windows() |
| 256 | call setline(1, ["aaa", "aaa", "a"]) |
| 257 | exe "norm! gg\<C-V>2j~e." |
| 258 | let lines = s:screen_lines([1, 3], winwidth(0)) |
| 259 | let expect = [ |
| 260 | \ "AaA ", |
| 261 | \ "AaA ", |
| 262 | \ "A ", |
| 263 | \ ] |
| 264 | call s:compare_lines(expect, lines) |
| 265 | call s:close_windows() |
| 266 | endfunc |
| 267 | |
| 268 | func Test_norm_after_block_visual() |
| 269 | call s:test_windows() |
| 270 | call setline(1, ["abcd{ef", "ghijklm", "no}pgrs"]) |
| 271 | exe "norm! ggf{\<C-V>\<C-V>c%" |
| 272 | let lines = s:screen_lines([1, 3], winwidth(0)) |
| 273 | let expect = [ |
| 274 | \ "abcdpgrs ", |
| 275 | \ "~ ", |
| 276 | \ "~ ", |
| 277 | \ ] |
| 278 | call s:compare_lines(expect, lines) |
| 279 | call s:close_windows() |
| 280 | endfunc |
| 281 | |
| 282 | func Test_block_replace_after_wrapping() |
| 283 | call s:test_windows() |
| 284 | call setline(1, repeat("a", 150)) |
| 285 | exe "norm! 0yypk147|\<C-V>jr0" |
| 286 | call assert_equal(repeat("a", 146) . "0aaa", getline(1)) |
| 287 | call assert_equal(repeat("a", 146) . "0aaa", getline(2)) |
| 288 | let lines = s:screen_lines([1, 10], winwidth(0)) |
| 289 | let expect = [ |
| 290 | \ "aaaaaaaaaaaaaaaaaaaa", |
| 291 | \ "aaaaaaaaaaaaaaaaaaaa", |
| 292 | \ "aaaaaaaaaaaaaaaaaaaa", |
| 293 | \ "aaaaaaaaaaaaaaaaaaaa", |
| 294 | \ "aaaaaaaaaaaaaaaaaaaa", |
| 295 | \ "aaaaaaaaaaaaaaaaaaaa", |
| 296 | \ "aaaaaaaaaaaaaaaaaaaa", |
| 297 | \ "aaaaaa0aaa ", |
| 298 | \ "@ ", |
| 299 | \ "@ ", |
| 300 | \ ] |
| 301 | call s:compare_lines(expect, lines) |
| 302 | call s:close_windows() |
| 303 | endfunc |
| 304 | |
| 305 | func Test_list_with_listchars() |
| 306 | call s:test_windows('setl list listchars=space:_,trail:-,tab:>-,eol:$') |
| 307 | call setline(1, "a aaaaaaaaaaaaaaaaaaaaaa\ta ") |
| 308 | let lines = s:screen_lines([1, 3], winwidth(0)) |
| 309 | let expect = [ |
| 310 | \ "a_ ", |
| 311 | \ "aaaaaaaaaaaaaaaaaaaa", |
| 312 | \ "aa>-----a-$ ", |
| 313 | \ ] |
| 314 | call s:compare_lines(expect, lines) |
| 315 | call s:close_windows() |
| 316 | endfunc |
Bram Moolenaar | abc39ab | 2017-03-01 18:04:05 +0100 | [diff] [blame] | 317 | |
| 318 | func Test_list_with_tab_and_skipping_first_chars() |
| 319 | call s:test_windows('setl list listchars=tab:>- ts=70 nowrap') |
| 320 | call setline(1, ["iiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa"]) |
| 321 | call cursor(4,64) |
| 322 | norm! 2zl |
| 323 | let lines = s:screen_lines([1, 4], winwidth(0)) |
| 324 | let expect = [ |
| 325 | \ "---------------aaaaa", |
| 326 | \ "---------------aaaaa", |
| 327 | \ "---------------aaaaa", |
| 328 | \ "iiiiiiiii>-----aaaaa", |
| 329 | \ ] |
| 330 | call s:compare_lines(expect, lines) |
| 331 | call s:close_windows() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 332 | endfunc |
| 333 | |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 334 | func Test_ctrl_char_on_wrap_column() |
| 335 | call s:test_windows("setl nolbr wrap sbr=") |
| 336 | call setline(1, 'aaa' .. repeat("\<C-A>", 150) .. 'bbb') |
| 337 | call cursor(1,1) |
| 338 | norm! $ |
| 339 | redraw! |
| 340 | let expect=[ |
| 341 | \ '<<<^A^A^A^A^A^A^A^A^', |
| 342 | \ 'A^A^A^A^A^A^A^A^A^A^', |
| 343 | \ 'A^A^A^A^A^A^A^A^A^A^', |
| 344 | \ 'A^A^A^A^A^A^A^A^A^A^', |
| 345 | \ 'A^A^A^A^A^A^A^A^A^A^', |
| 346 | \ 'A^A^A^A^A^A^A^A^A^A^', |
| 347 | \ 'A^A^A^A^A^A^A^A^A^A^', |
| 348 | \ 'A^A^A^A^A^A^A^A^A^A^', |
| 349 | \ 'A^A^A^A^A^A^A^A^A^A^', |
| 350 | \ 'A^Abbb '] |
| 351 | let lines = s:screen_lines([1, 10], winwidth(0)) |
| 352 | call s:compare_lines(expect, lines) |
| 353 | call assert_equal(len(expect), winline()) |
| 354 | call assert_equal(strwidth(trim(expect[-1], ' ', 2)), wincol()) |
| 355 | setl sbr=!! |
| 356 | redraw! |
| 357 | let expect=[ |
| 358 | \ '!!A^A^A^A^A^A^A^A^A^', |
| 359 | \ '!!A^A^A^A^A^A^A^A^A^', |
| 360 | \ '!!A^A^A^A^A^A^A^A^A^', |
| 361 | \ '!!A^A^A^A^A^A^A^A^A^', |
| 362 | \ '!!A^A^A^A^A^A^A^A^A^', |
| 363 | \ '!!A^A^A^A^A^A^A^A^A^', |
| 364 | \ '!!A^A^A^A^A^A^A^A^A^', |
| 365 | \ '!!A^A^A^A^A^A^A^A^A^', |
| 366 | \ '!!A^A^A^A^A^A^A^A^A^', |
| 367 | \ '!!A^A^A^A^A^A^Abbb '] |
| 368 | let lines = s:screen_lines([1, 10], winwidth(0)) |
| 369 | call s:compare_lines(expect, lines) |
| 370 | call assert_equal(len(expect), winline()) |
| 371 | call assert_equal(strwidth(trim(expect[-1], ' ', 2)), wincol()) |
| 372 | call s:close_windows() |
| 373 | endfunc |
| 374 | |
Christian Brabandt | dd75fcf | 2023-10-11 21:51:19 +0200 | [diff] [blame] | 375 | func Test_linebreak_no_break_after_whitespace_only() |
| 376 | call s:test_windows('setl ts=4 linebreak wrap') |
| 377 | call setline(1, "\tabcdefghijklmnopqrstuvwxyz" .. |
| 378 | \ "abcdefghijklmnopqrstuvwxyz") |
| 379 | let lines = s:screen_lines([1, 4], winwidth(0)) |
| 380 | let expect = [ |
| 381 | \ " abcdefghijklmnop", |
| 382 | \ "qrstuvwxyzabcdefghij", |
| 383 | \ "klmnopqrstuvwxyz ", |
| 384 | \ "~ ", |
| 385 | \ ] |
| 386 | call s:compare_lines(expect, lines) |
| 387 | call s:close_windows() |
| 388 | endfunc |
| 389 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 390 | " vim: shiftwidth=2 sts=2 expandtab |