neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

test_listlbr.vim (11190B)


      1 " Test for linebreak and list option (non-utf8)
      2 
      3 scriptencoding latin1
      4 
      5 source check.vim
      6 CheckOption linebreak
      7 CheckFeature conceal
      8 
      9 source view_util.vim
     10 source screendump.vim
     11 
     12 function s:screen_lines(lnum, width) abort
     13  return ScreenLines(a:lnum, a:width)
     14 endfunction
     15 
     16 func s:compare_lines(expect, actual)
     17  call assert_equal(a:expect, a:actual)
     18 endfunc
     19 
     20 function s:test_windows(...)
     21  call NewWindow(10, 20)
     22  setl ts=8 sw=4 sts=4 linebreak sbr= wrap
     23  exe get(a:000, 0, '')
     24 endfunction
     25 
     26 function s:close_windows(...)
     27  call CloseWindow()
     28  exe get(a:000, 0, '')
     29 endfunction
     30 
     31 func Test_set_linebreak()
     32  call s:test_windows('setl ts=4 sbr=+')
     33  call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ")
     34  let lines = s:screen_lines([1, 4], winwidth(0))
     35  let expect = [
     36 \ "    abcdef          ",
     37 \ "+hijklmn            ",
     38 \ "+pqrstuvwxyz_1060ABC",
     39 \ "+DEFGHIJKLMNOP      ",
     40 \ ]
     41  call s:compare_lines(expect, lines)
     42  call s:close_windows()
     43 endfunc
     44 
     45 func Test_linebreak_with_list()
     46  throw 'skipped: Nvim does not support enc=latin1'
     47  set listchars=
     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()
     59  set listchars&vim
     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 
     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 
    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 
    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 
    161 " Test that cursor is drawn at correct position after an operator when
    162 " 'linebreak' is enabled.
    163 func Test_linebreak_reset_restore()
    164  CheckScreendump
    165 
    166  " f_wincol() calls validate_cursor()
    167  let lines =<< trim END
    168    set linebreak showcmd noshowmode formatexpr=wincol()-wincol()
    169    call setline(1, repeat('a', &columns - 10) .. ' bbbbbbbbbb c')
    170  END
    171  call writefile(lines, 'XlbrResetRestore', 'D')
    172  let buf = RunVimInTerminal('-S XlbrResetRestore', {'rows': 8})
    173 
    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])})
    193  call VerifyScreenDump(buf, 'Test_linebreak_reset_restore_1', {})
    194 
    195  " clean up
    196  call term_sendkeys(buf, "\<Esc>")
    197  call StopVimInTerminal(buf)
    198 endfunc
    199 
    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 = [
    226 \ "<<<bar foobar       ",
    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  throw 'skipped: Nvim does not support enc=latin1'
    284  call s:test_windows()
    285  call setline(1, repeat("a", 150))
    286  exe "norm! 0yypk147|\<C-V>jr0"
    287  call assert_equal(repeat("a", 146) . "0aaa", getline(1))
    288  call assert_equal(repeat("a", 146) . "0aaa", getline(2))
    289  let lines = s:screen_lines([1, 10], winwidth(0))
    290  let expect = [
    291 \ "aaaaaaaaaaaaaaaaaaaa",
    292 \ "aaaaaaaaaaaaaaaaaaaa",
    293 \ "aaaaaaaaaaaaaaaaaaaa",
    294 \ "aaaaaaaaaaaaaaaaaaaa",
    295 \ "aaaaaaaaaaaaaaaaaaaa",
    296 \ "aaaaaaaaaaaaaaaaaaaa",
    297 \ "aaaaaaaaaaaaaaaaaaaa",
    298 \ "aaaaaa0aaa          ",
    299 \ "@                   ",
    300 \ "@                   ",
    301 \ ]
    302  call s:compare_lines(expect, lines)
    303  call s:close_windows()
    304 endfunc
    305 
    306 func Test_list_with_listchars()
    307  call s:test_windows('setl list listchars=space:_,trail:-,tab:>-,eol:$')
    308  call setline(1, "a aaaaaaaaaaaaaaaaaaaaaa\ta ")
    309  let lines = s:screen_lines([1, 3], winwidth(0))
    310  let expect = [
    311 \ "a_                  ",
    312 \ "aaaaaaaaaaaaaaaaaaaa",
    313 \ "aa>-----a-$         ",
    314 \ ]
    315  call s:compare_lines(expect, lines)
    316  call s:close_windows()
    317 endfunc
    318 
    319 func Test_list_with_tab_and_skipping_first_chars()
    320  call s:test_windows('setl list listchars=tab:>- ts=70 nowrap')
    321  call setline(1, ["iiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa"])
    322  call cursor(4,64)
    323  norm! 2zl
    324  let lines = s:screen_lines([1, 4], winwidth(0))
    325  let expect = [
    326 \ "---------------aaaaa",
    327 \ "---------------aaaaa",
    328 \ "---------------aaaaa",
    329 \ "iiiiiiiii>-----aaaaa",
    330 \ ]
    331  call s:compare_lines(expect, lines)
    332  call s:close_windows()
    333 endfunc
    334 
    335 func Test_ctrl_char_on_wrap_column()
    336  call s:test_windows("setl nolbr wrap sbr=")
    337  call setline(1, 'aaa' .. repeat("\<C-A>", 150) .. 'bbb')
    338  call cursor(1,1)
    339  norm! $
    340  redraw!
    341  let expect=[
    342 \ '<<<^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^A^A^A^A^A^A^A^A^A^',
    351 \ 'A^Abbb              ']
    352  let lines = s:screen_lines([1, 10], winwidth(0))
    353  call s:compare_lines(expect, lines)
    354  call assert_equal(len(expect), winline())
    355  call assert_equal(strwidth(trim(expect[-1], ' ', 2)), wincol())
    356  setl sbr=!!
    357  redraw!
    358  let expect=[
    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^A^A^A^',
    368 \ '!!A^A^A^A^A^A^Abbb  ']
    369  let lines = s:screen_lines([1, 10], winwidth(0))
    370  call s:compare_lines(expect, lines)
    371  call assert_equal(len(expect), winline())
    372  call assert_equal(strwidth(trim(expect[-1], ' ', 2)), wincol())
    373  call s:close_windows()
    374 endfunc
    375 
    376 func Test_linebreak_no_break_after_whitespace_only()
    377  call s:test_windows('setl ts=4 linebreak wrap')
    378  call setline(1, "\t  abcdefghijklmnopqrstuvwxyz" ..
    379        \ "abcdefghijklmnopqrstuvwxyz")
    380  let lines = s:screen_lines([1, 4], winwidth(0))
    381  let expect = [
    382 \ "      abcdefghijklmn",
    383 \ "opqrstuvwxyzabcdefgh",
    384 \ "ijklmnopqrstuvwxyz  ",
    385 \ "~                   ",
    386 \ ]
    387  call s:compare_lines(expect, lines)
    388  call s:close_windows()
    389 endfunc
    390 
    391 " vim: shiftwidth=2 sts=2 expandtab