123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806 |
- local t = require('test.testutil')
- local n = require('test.functional.testnvim')()
- local Screen = require('test.functional.ui.screen')
- local clear = n.clear
- local command = n.command
- local exec = n.exec
- local feed = n.feed
- local api = n.api
- local expect_pos = function(row, col)
- return t.eq({ row, col }, n.eval('[screenrow(), screencol()]'))
- end
- describe('Conceal', function()
- before_each(function()
- clear()
- command('set nohlsearch')
- end)
- -- oldtest: Test_conceal_two_windows()
- it('works', function()
- local screen = Screen.new(75, 12)
- exec([[
- let lines = ["one one one one one", "two |hidden| here", "three |hidden| three"]
- call setline(1, lines)
- syntax match test /|hidden|/ conceal
- set conceallevel=2
- set concealcursor=
- exe "normal /here\r"
- new
- call setline(1, lines)
- call setline(4, "Second window")
- syntax match test /|hidden|/ conceal
- set conceallevel=2
- set concealcursor=nc
- exe "normal /here\r"
- ]])
- -- Check that cursor line is concealed
- screen:expect([[
- one one one one one |
- two ^here |
- three three |
- Second window |
- {1:~ }|
- {3:[No Name] [+] }|
- one one one one one |
- two here |
- three three |
- {1:~ }|
- {2:[No Name] [+] }|
- /here |
- ]])
- -- Check that with concealed text vertical cursor movement is correct.
- feed('k')
- screen:expect([[
- one one one o^ne one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {3:[No Name] [+] }|
- one one one one one |
- two here |
- three three |
- {1:~ }|
- {2:[No Name] [+] }|
- /here |
- ]])
- -- Check that with cursor line is not concealed
- feed('j')
- command('set concealcursor=')
- screen:expect([[
- one one one one one |
- two |hidden| ^here |
- three three |
- Second window |
- {1:~ }|
- {3:[No Name] [+] }|
- one one one one one |
- two here |
- three three |
- {1:~ }|
- {2:[No Name] [+] }|
- /here |
- ]])
- -- Check that with cursor line is not concealed when moving cursor down
- feed('j')
- screen:expect([[
- one one one one one |
- two here |
- three |hidden^| three |
- Second window |
- {1:~ }|
- {3:[No Name] [+] }|
- one one one one one |
- two here |
- three three |
- {1:~ }|
- {2:[No Name] [+] }|
- /here |
- ]])
- -- Check that with cursor line is not concealed when switching windows
- feed('<C-W><C-W>')
- screen:expect([[
- one one one one one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {2:[No Name] [+] }|
- one one one one one |
- two |hidden| ^here |
- three three |
- {1:~ }|
- {3:[No Name] [+] }|
- /here |
- ]])
- -- Check that with cursor line is only concealed in Normal mode
- command('set concealcursor=n')
- screen:expect([[
- one one one one one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {2:[No Name] [+] }|
- one one one one one |
- two ^here |
- three three |
- {1:~ }|
- {3:[No Name] [+] }|
- /here |
- ]])
- feed('a')
- screen:expect([[
- one one one one one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {2:[No Name] [+] }|
- one one one one one |
- two |hidden| h^ere |
- three three |
- {1:~ }|
- {3:[No Name] [+] }|
- {5:-- INSERT --} |
- ]])
- feed('<Esc>/e')
- screen:expect([[
- one one one one one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {2:[No Name] [+] }|
- one one one one one |
- two |hidden| h{2:e}re |
- three three |
- {1:~ }|
- {3:[No Name] [+] }|
- /e^ |
- ]])
- feed('<Esc>v')
- screen:expect([[
- one one one one one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {2:[No Name] [+] }|
- one one one one one |
- two |hidden| ^here |
- three three |
- {1:~ }|
- {3:[No Name] [+] }|
- {5:-- VISUAL --} |
- ]])
- feed('<Esc>')
- -- Check that with cursor line is only concealed in Insert mode
- command('set concealcursor=i')
- screen:expect([[
- one one one one one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {2:[No Name] [+] }|
- one one one one one |
- two |hidden| ^here |
- three three |
- {1:~ }|
- {3:[No Name] [+] }|
- |
- ]])
- feed('a')
- screen:expect([[
- one one one one one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {2:[No Name] [+] }|
- one one one one one |
- two h^ere |
- three three |
- {1:~ }|
- {3:[No Name] [+] }|
- {5:-- INSERT --} |
- ]])
- feed('<Esc>/e')
- screen:expect([[
- one one one one one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {2:[No Name] [+] }|
- one one one one one |
- two |hidden| h{2:e}re |
- three three |
- {1:~ }|
- {3:[No Name] [+] }|
- /e^ |
- ]])
- feed('<Esc>v')
- screen:expect([[
- one one one one one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {2:[No Name] [+] }|
- one one one one one |
- two |hidden| ^here |
- three three |
- {1:~ }|
- {3:[No Name] [+] }|
- {5:-- VISUAL --} |
- ]])
- feed('<Esc>')
- -- Check that with cursor line is only concealed in Visual mode
- command('set concealcursor=v')
- screen:expect([[
- one one one one one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {2:[No Name] [+] }|
- one one one one one |
- two |hidden| ^here |
- three three |
- {1:~ }|
- {3:[No Name] [+] }|
- |
- ]])
- feed('a')
- screen:expect([[
- one one one one one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {2:[No Name] [+] }|
- one one one one one |
- two |hidden| h^ere |
- three three |
- {1:~ }|
- {3:[No Name] [+] }|
- {5:-- INSERT --} |
- ]])
- feed('<Esc>/e')
- screen:expect([[
- one one one one one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {2:[No Name] [+] }|
- one one one one one |
- two |hidden| h{2:e}re |
- three three |
- {1:~ }|
- {3:[No Name] [+] }|
- /e^ |
- ]])
- feed('<Esc>v')
- screen:expect([[
- one one one one one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {2:[No Name] [+] }|
- one one one one one |
- two ^here |
- three three |
- {1:~ }|
- {3:[No Name] [+] }|
- {5:-- VISUAL --} |
- ]])
- feed('<Esc>')
- -- Check moving the cursor while in insert mode.
- command('set concealcursor=')
- feed('a')
- screen:expect([[
- one one one one one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {2:[No Name] [+] }|
- one one one one one |
- two |hidden| h^ere |
- three three |
- {1:~ }|
- {3:[No Name] [+] }|
- {5:-- INSERT --} |
- ]])
- feed('<Down>')
- screen:expect([[
- one one one one one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {2:[No Name] [+] }|
- one one one one one |
- two here |
- three |hidden|^ three |
- {1:~ }|
- {3:[No Name] [+] }|
- {5:-- INSERT --} |
- ]])
- feed('<Esc>')
- -- Check the "o" command
- screen:expect([[
- one one one one one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {2:[No Name] [+] }|
- one one one one one |
- two here |
- three |hidden^| three |
- {1:~ }|
- {3:[No Name] [+] }|
- |
- ]])
- feed('o')
- screen:expect([[
- one one one one one |
- two here |
- three three |
- Second window |
- {1:~ }|
- {2:[No Name] [+] }|
- one one one one one |
- two here |
- three three |
- ^ |
- {3:[No Name] [+] }|
- {5:-- INSERT --} |
- ]])
- feed('<Esc>')
- end)
- -- oldtest: Test_conceal_with_cursorcolumn()
- it('CursorColumn and ColorColumn on wrapped line', function()
- local screen = Screen.new(40, 10)
- screen:add_extra_attr_ids {
- [100] = { background = Screen.colors.LightRed },
- }
- -- Check that cursorcolumn and colorcolumn don't get broken in presence of
- -- wrapped lines containing concealed text
- -- luacheck: push ignore 613 (trailing whitespace in a string)
- exec([[
- let lines = ["one one one |hidden| one one one one one one one one",
- \ "two two two two |hidden| here two two",
- \ "three |hidden| three three three three three three three three"]
- call setline(1, lines)
- set wrap linebreak
- set showbreak=\ >>>\
- syntax match test /|hidden|/ conceal
- set conceallevel=2
- set concealcursor=
- exe "normal /here\r"
- set cursorcolumn
- set colorcolumn=50
- ]])
- -- luacheck: pop
- screen:expect([[
- one one one one one one {21:o}ne |
- {1: >>> }one {100:o}ne one one |
- two two two two |hidden| ^here two two |
- three three three three {21:t}hree |
- {1: >>> }thre{100:e} three three three |
- {1:~ }|*4
- /here |
- ]])
- -- move cursor to the end of line (the cursor jumps to the next screen line)
- feed('$')
- screen:expect([[
- one one one one one one one |
- {1: >>> }one {100:o}ne one one |
- two two two two |hidden| here two tw^o |
- three three three three three |
- {1: >>> }thre{100:e} three three three |
- {1:~ }|*4
- /here |
- ]])
- end)
- -- oldtest: Test_conceal_wrapped_cursorline_wincolor()
- it('CursorLine highlight on wrapped lines', function()
- local screen = Screen.new(40, 4)
- screen:add_extra_attr_ids {
- [100] = { background = Screen.colors.WebGreen },
- }
- exec([[
- call setline(1, 'one one one |hidden| one one one one one one one one')
- syntax match test /|hidden|/ conceal
- set conceallevel=2 concealcursor=n cursorline
- normal! g$
- hi! CursorLine guibg=Green
- ]])
- screen:expect([[
- {100:one one one one one one one on^e }|
- {100: one one one }|
- {1:~ }|
- |
- ]])
- command('hi! CursorLine guibg=NONE guifg=Red')
- screen:expect([[
- {19:one one one one one one one on^e }|
- {19: one one one }|
- {1:~ }|
- |
- ]])
- end)
- -- oldtest: Test_conceal_wrapped_cursorline_wincolor_rightleft()
- it('CursorLine highlight on wrapped lines with rightleft', function()
- local screen = Screen.new(40, 4)
- screen:add_extra_attr_ids {
- [100] = { background = Screen.colors.WebGreen },
- }
- exec([[
- call setline(1, 'one one one |hidden| one one one one one one one one')
- syntax match test /|hidden|/ conceal
- set conceallevel=2 concealcursor=n cursorline rightleft
- normal! g$
- hi! CursorLine guibg=Green
- ]])
- screen:expect([[
- {100: ^eno eno eno eno eno eno eno eno}|
- {100: eno eno eno }|
- {1: ~}|
- |
- ]])
- command('hi! CursorLine guibg=NONE guifg=Red')
- screen:expect([[
- {19: ^eno eno eno eno eno eno eno eno}|
- {19: eno eno eno }|
- {1: ~}|
- |
- ]])
- end)
- -- oldtest: Test_conceal_resize_term()
- it('resize editor', function()
- local screen = Screen.new(75, 6)
- exec([[
- call setline(1, '`one` `two` `three` `four` `five`, the backticks should be concealed')
- setl cocu=n cole=3
- syn region CommentCodeSpan matchgroup=Comment start=/`/ end=/`/ concealends
- normal fb
- ]])
- screen:expect([[
- one two three four five, the ^backticks should be concealed |
- {1:~ }|*4
- |
- ]])
- screen:try_resize(75, 7)
- screen:expect([[
- one two three four five, the ^backticks should be concealed |
- {1:~ }|*5
- |
- ]])
- end)
- -- oldtest: Test_conceal_linebreak()
- it('with linebreak', function()
- local screen = Screen.new(75, 8)
- exec([[
- let &wrap = v:true
- let &conceallevel = 2
- let &concealcursor = 'nc'
- let &linebreak = v:true
- let &showbreak = '+ '
- let line = 'a`a`a`a`'
- \ .. 'a'->repeat(&columns - 15)
- \ .. ' b`b`'
- \ .. 'b'->repeat(&columns - 10)
- \ .. ' cccccc'
- eval ['x'->repeat(&columns), '', line]->setline(1)
- syntax region CodeSpan matchgroup=Delimiter start=/\z(`\+\)/ end=/\z1/ concealends
- ]])
- screen:expect([[
- ^xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
- |
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
- {1:+ }bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
- {1:+ }cccccc |
- {1:~ }|*2
- |
- ]])
- end)
- -- Tests for correct display (cursor column position) with +conceal and tabulators.
- -- oldtest: Test_conceal_cursor_pos()
- it('cursor and column position with conceal and tabulators', function()
- exec([[
- let l = ['start:', '.concealed. text', "|concealed|\ttext"]
- let l += ['', "\t.concealed.\ttext", "\t|concealed|\ttext", '']
- let l += [".a.\t.b.\t.c.\t.d.", "|a|\t|b|\t|c|\t|d|"]
- call append(0, l)
- call cursor(1, 1)
- " Conceal settings.
- set conceallevel=2
- set concealcursor=nc
- syntax match test /|/ conceal
- ]])
- feed('ztj')
- expect_pos(2, 1)
- -- We should end up in the same column when running these commands on the
- -- two lines.
- feed('ft')
- expect_pos(2, 17)
- feed('$')
- expect_pos(2, 20)
- feed('0j')
- expect_pos(3, 1)
- feed('ft')
- expect_pos(3, 17)
- feed('$')
- expect_pos(3, 20)
- feed('j0j')
- expect_pos(5, 8)
- -- Same for next test block.
- feed('ft')
- expect_pos(5, 25)
- feed('$')
- expect_pos(5, 28)
- feed('0j')
- expect_pos(6, 8)
- feed('ft')
- expect_pos(6, 25)
- feed('$')
- expect_pos(6, 28)
- feed('0j0j')
- expect_pos(8, 1)
- -- And check W with multiple tabs and conceals in a line.
- feed('W')
- expect_pos(8, 9)
- feed('W')
- expect_pos(8, 17)
- feed('W')
- expect_pos(8, 25)
- feed('$')
- expect_pos(8, 27)
- feed('0j')
- expect_pos(9, 1)
- feed('W')
- expect_pos(9, 9)
- feed('W')
- expect_pos(9, 17)
- feed('W')
- expect_pos(9, 25)
- feed('$')
- expect_pos(9, 26)
- command('set lbr')
- feed('$')
- expect_pos(9, 26)
- command('set list listchars=tab:>-')
- feed('0')
- expect_pos(9, 1)
- feed('W')
- expect_pos(9, 9)
- feed('W')
- expect_pos(9, 17)
- feed('W')
- expect_pos(9, 25)
- feed('$')
- expect_pos(9, 26)
- end)
- local function test_conceal_virtualedit_after_eol(wrap)
- local screen = Screen.new(60, 3)
- api.nvim_set_option_value('wrap', wrap, {})
- exec([[
- call setline(1, 'abcdefgh|hidden|ijklmnpop')
- syntax match test /|hidden|/ conceal
- set conceallevel=2 concealcursor=n virtualedit=all
- normal! $
- ]])
- screen:expect([[
- abcdefghijklmnpo^p |
- {1:~ }|
- |
- ]])
- feed('l')
- screen:expect([[
- abcdefghijklmnpop^ |
- {1:~ }|
- |
- ]])
- feed('l')
- screen:expect([[
- abcdefghijklmnpop ^ |
- {1:~ }|
- |
- ]])
- feed('l')
- screen:expect([[
- abcdefghijklmnpop ^ |
- {1:~ }|
- |
- ]])
- feed('rr')
- screen:expect([[
- abcdefghijklmnpop ^r |
- {1:~ }|
- |
- ]])
- end
- -- oldtest: Test_conceal_virtualedit_after_eol()
- describe('cursor drawn at correct column with virtualedit', function()
- it('with wrapping', function()
- test_conceal_virtualedit_after_eol(true)
- end)
- it('without wrapping', function()
- test_conceal_virtualedit_after_eol(false)
- end)
- end)
- local function test_conceal_virtualedit_after_eol_rightleft(wrap)
- local screen = Screen.new(60, 3)
- api.nvim_set_option_value('wrap', wrap, {})
- exec([[
- call setline(1, 'abcdefgh|hidden|ijklmnpop')
- syntax match test /|hidden|/ conceal
- set conceallevel=2 concealcursor=n virtualedit=all rightleft
- normal! $
- ]])
- screen:expect([[
- ^popnmlkjihgfedcba|
- {1: ~}|
- |
- ]])
- feed('h')
- screen:expect([[
- ^ popnmlkjihgfedcba|
- {1: ~}|
- |
- ]])
- feed('h')
- screen:expect([[
- ^ popnmlkjihgfedcba|
- {1: ~}|
- |
- ]])
- feed('h')
- screen:expect([[
- ^ popnmlkjihgfedcba|
- {1: ~}|
- |
- ]])
- feed('rr')
- screen:expect([[
- ^r popnmlkjihgfedcba|
- {1: ~}|
- |
- ]])
- end
- -- oldtest: Test_conceal_virtualedit_after_eol_rightleft()
- describe('cursor drawn correctly with virtualedit and rightleft', function()
- it('with wrapping', function()
- test_conceal_virtualedit_after_eol_rightleft(true)
- end)
- it('without wrapping', function()
- test_conceal_virtualedit_after_eol_rightleft(false)
- end)
- end)
- local function test_conceal_double_width(wrap)
- local screen = Screen.new(60, 4)
- screen:add_extra_attr_ids {
- [100] = { background = Screen.colors.LightRed },
- }
- api.nvim_set_option_value('wrap', wrap, {})
- exec([[
- call setline(1, ['aaaaa口=口bbbbb口=口ccccc', 'foobar'])
- syntax match test /口=口/ conceal cchar=β
- set conceallevel=2 concealcursor=n colorcolumn=30
- normal! $
- ]])
- screen:expect([[
- aaaaa{14:β}bbbbb{14:β}cccc^c {100: } |
- foobar {100: } |
- {1:~ }|
- |
- ]])
- feed('gM')
- screen:expect([[
- aaaaa{14:β}bb^bbb{14:β}ccccc {100: } |
- foobar {100: } |
- {1:~ }|
- |
- ]])
- command('set conceallevel=3')
- screen:expect([[
- aaaaabb^bbbccccc {100: } |
- foobar {100: } |
- {1:~ }|
- |
- ]])
- feed('$')
- screen:expect([[
- aaaaabbbbbcccc^c {100: } |
- foobar {100: } |
- {1:~ }|
- |
- ]])
- end
- -- oldtest: Test_conceal_double_width()
- describe('cursor drawn correctly when double-width chars are concealed', function()
- it('with wrapping', function()
- test_conceal_double_width(true)
- end)
- it('without wrapping', function()
- test_conceal_double_width(false)
- end)
- end)
- -- oldtest: Test_conceal_double_width_wrap()
- it('line wraps correctly when double-width chars are concealed', function()
- local screen = Screen.new(20, 4)
- screen:add_extra_attr_ids {
- [100] = { background = Screen.colors.LightRed },
- }
- exec([[
- call setline(1, 'aaaaaaaaaa口=口bbbbbbbbbb口=口cccccccccc')
- syntax match test /口=口/ conceal cchar=β
- set conceallevel=2 concealcursor=n
- normal! $
- ]])
- screen:expect([[
- aaaaaaaaaa{14:β}bbbbb |
- bbbbb{14:β}ccccccccc^c |
- {1:~ }|
- |
- ]])
- feed('gM')
- screen:expect([[
- aaaaaaaaaa{14:β}bbbbb |
- ^bbbbb{14:β}cccccccccc |
- {1:~ }|
- |
- ]])
- command('set conceallevel=3')
- screen:expect([[
- aaaaaaaaaabbbbb |
- ^bbbbbcccccccccc |
- {1:~ }|
- |
- ]])
- feed('$')
- screen:expect([[
- aaaaaaaaaabbbbb |
- bbbbbccccccccc^c |
- {1:~ }|
- |
- ]])
- end)
- end)
|