diff options
Diffstat (limited to 'test/functional/legacy/conceal_spec.lua')
-rw-r--r-- | test/functional/legacy/conceal_spec.lua | 448 |
1 files changed, 353 insertions, 95 deletions
diff --git a/test/functional/legacy/conceal_spec.lua b/test/functional/legacy/conceal_spec.lua index 9a23d16c5b..f4c1983bb7 100644 --- a/test/functional/legacy/conceal_spec.lua +++ b/test/functional/legacy/conceal_spec.lua @@ -1,12 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local exec = helpers.exec -local feed = helpers.feed + +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 helpers.eq({ row, col }, helpers.eval('[screenrow(), screencol()]')) + return t.eq({ row, col }, n.eval('[screenrow(), screencol()]')) end describe('Conceal', function() @@ -18,12 +21,6 @@ describe('Conceal', function() -- oldtest: Test_conceal_two_windows() it('works', function() local screen = Screen.new(75, 12) - screen:set_default_attr_ids({ - [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText - [1] = { bold = true, reverse = true }, -- StatusLine - [2] = { reverse = true }, -- StatusLineNC, IncSearch - [3] = { bold = true }, -- ModeMsg - }) screen:attach() exec([[ let lines = ["one one one one one", "two |hidden| here", "three |hidden| three"] @@ -47,12 +44,12 @@ describe('Conceal', function() two ^here | three three | Second window | - {0:~ }| - {1:[No Name] [+] }| + {1:~ }| + {3:[No Name] [+] }| one one one one one | two here | three three | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| /here | ]]) @@ -64,12 +61,12 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| - {1:[No Name] [+] }| + {1:~ }| + {3:[No Name] [+] }| one one one one one | two here | three three | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| /here | ]]) @@ -82,12 +79,12 @@ describe('Conceal', function() two |hidden| ^here | three three | Second window | - {0:~ }| - {1:[No Name] [+] }| + {1:~ }| + {3:[No Name] [+] }| one one one one one | two here | three three | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| /here | ]]) @@ -99,12 +96,12 @@ describe('Conceal', function() two here | three |hidden^| three | Second window | - {0:~ }| - {1:[No Name] [+] }| + {1:~ }| + {3:[No Name] [+] }| one one one one one | two here | three three | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| /here | ]]) @@ -116,13 +113,13 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| one one one one one | two |hidden| ^here | three three | - {0:~ }| - {1:[No Name] [+] }| + {1:~ }| + {3:[No Name] [+] }| /here | ]]) @@ -133,13 +130,13 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| one one one one one | two ^here | three three | - {0:~ }| - {1:[No Name] [+] }| + {1:~ }| + {3:[No Name] [+] }| /here | ]]) feed('a') @@ -148,14 +145,14 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| one one one one one | two |hidden| h^ere | three three | - {0:~ }| - {1:[No Name] [+] }| - {3:-- INSERT --} | + {1:~ }| + {3:[No Name] [+] }| + {5:-- INSERT --} | ]]) feed('<Esc>/e') screen:expect([[ @@ -163,13 +160,13 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| one one one one one | two |hidden| h{2:e}re | three three | - {0:~ }| - {1:[No Name] [+] }| + {1:~ }| + {3:[No Name] [+] }| /e^ | ]]) feed('<Esc>v') @@ -178,14 +175,14 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| one one one one one | two |hidden| ^here | three three | - {0:~ }| - {1:[No Name] [+] }| - {3:-- VISUAL --} | + {1:~ }| + {3:[No Name] [+] }| + {5:-- VISUAL --} | ]]) feed('<Esc>') @@ -196,13 +193,13 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| one one one one one | two |hidden| ^here | three three | - {0:~ }| - {1:[No Name] [+] }| + {1:~ }| + {3:[No Name] [+] }| | ]]) feed('a') @@ -211,14 +208,14 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| one one one one one | two h^ere | three three | - {0:~ }| - {1:[No Name] [+] }| - {3:-- INSERT --} | + {1:~ }| + {3:[No Name] [+] }| + {5:-- INSERT --} | ]]) feed('<Esc>/e') screen:expect([[ @@ -226,13 +223,13 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| one one one one one | two |hidden| h{2:e}re | three three | - {0:~ }| - {1:[No Name] [+] }| + {1:~ }| + {3:[No Name] [+] }| /e^ | ]]) feed('<Esc>v') @@ -241,14 +238,14 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| one one one one one | two |hidden| ^here | three three | - {0:~ }| - {1:[No Name] [+] }| - {3:-- VISUAL --} | + {1:~ }| + {3:[No Name] [+] }| + {5:-- VISUAL --} | ]]) feed('<Esc>') @@ -259,13 +256,13 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| one one one one one | two |hidden| ^here | three three | - {0:~ }| - {1:[No Name] [+] }| + {1:~ }| + {3:[No Name] [+] }| | ]]) feed('a') @@ -274,14 +271,14 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| one one one one one | two |hidden| h^ere | three three | - {0:~ }| - {1:[No Name] [+] }| - {3:-- INSERT --} | + {1:~ }| + {3:[No Name] [+] }| + {5:-- INSERT --} | ]]) feed('<Esc>/e') screen:expect([[ @@ -289,13 +286,13 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| one one one one one | two |hidden| h{2:e}re | three three | - {0:~ }| - {1:[No Name] [+] }| + {1:~ }| + {3:[No Name] [+] }| /e^ | ]]) feed('<Esc>v') @@ -304,14 +301,14 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| one one one one one | two ^here | three three | - {0:~ }| - {1:[No Name] [+] }| - {3:-- VISUAL --} | + {1:~ }| + {3:[No Name] [+] }| + {5:-- VISUAL --} | ]]) feed('<Esc>') @@ -323,14 +320,14 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| one one one one one | two |hidden| h^ere | three three | - {0:~ }| - {1:[No Name] [+] }| - {3:-- INSERT --} | + {1:~ }| + {3:[No Name] [+] }| + {5:-- INSERT --} | ]]) feed('<Down>') screen:expect([[ @@ -338,14 +335,14 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| one one one one one | two here | three |hidden|^ three | - {0:~ }| - {1:[No Name] [+] }| - {3:-- INSERT --} | + {1:~ }| + {3:[No Name] [+] }| + {5:-- INSERT --} | ]]) feed('<Esc>') @@ -355,13 +352,13 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| one one one one one | two here | three |hidden^| three | - {0:~ }| - {1:[No Name] [+] }| + {1:~ }| + {3:[No Name] [+] }| | ]]) feed('o') @@ -370,14 +367,14 @@ describe('Conceal', function() two here | three three | Second window | - {0:~ }| + {1:~ }| {2:[No Name] [+] }| one one one one one | two here | three three | ^ | - {1:[No Name] [+] }| - {3:-- INSERT --} | + {3:[No Name] [+] }| + {5:-- INSERT --} | ]]) feed('<Esc>') end) @@ -433,15 +430,73 @@ describe('Conceal', function() ]]) end) - -- oldtest: Test_conceal_resize_term() - it('resize editor', function() - local screen = Screen.new(75, 6) + -- oldtest: Test_conceal_wrapped_cursorline_wincolor() + it('CursorLine highlight on wrapped lines', function() + local screen = Screen.new(40, 4) + screen:set_default_attr_ids({ + [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText + [1] = { background = Screen.colors.Green }, -- CursorLine (low-priority) + [2] = { foreground = Screen.colors.Red }, -- CursorLine (high-priority) + }) + screen:attach() + 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([[ + {1:one one one one one one one on^e }| + {1: one one one }| + {0:~ }| + | + ]]) + command('hi! CursorLine guibg=NONE guifg=Red') + screen:expect([[ + {2:one one one one one one one on^e }| + {2: one one one }| + {0:~ }| + | + ]]) + end) + + -- oldtest: Test_conceal_wrapped_cursorline_wincolor_rightleft() + it('CursorLine highlight on wrapped lines with rightleft', function() + local screen = Screen.new(40, 4) screen:set_default_attr_ids({ [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText - [1] = { foreground = Screen.colors.Blue }, -- Comment + [1] = { background = Screen.colors.Green }, -- CursorLine (low-priority) + [2] = { foreground = Screen.colors.Red }, -- CursorLine (high-priority) }) screen:attach() 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([[ + {1: ^eno eno eno eno eno eno eno eno}| + {1: eno eno eno }| + {0: ~}| + | + ]]) + command('hi! CursorLine guibg=NONE guifg=Red') + screen:expect([[ + {2: ^eno eno eno eno eno eno eno eno}| + {2: eno eno eno }| + {0: ~}| + | + ]]) + end) + + -- oldtest: Test_conceal_resize_term() + it('resize editor', function() + local screen = Screen.new(75, 6) + screen:attach() + 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 @@ -449,14 +504,14 @@ describe('Conceal', function() ]]) screen:expect([[ one two three four five, the ^backticks should be concealed | - {0:~ }|*4 + {1:~ }|*4 | ]]) screen:try_resize(75, 7) screen:expect([[ one two three four five, the ^backticks should be concealed | - {0:~ }|*5 + {1:~ }|*5 | ]]) end) @@ -464,9 +519,6 @@ describe('Conceal', function() -- oldtest: Test_conceal_linebreak() it('with linebreak', function() local screen = Screen.new(75, 8) - screen:set_default_attr_ids({ - [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText - }) screen:attach() exec([[ let &wrap = v:true @@ -486,9 +538,9 @@ describe('Conceal', function() ^xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx| | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | - {0:+ }bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb | - {0:+ }cccccc | - {0:~ }|*2 + {1:+ }bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb | + {1:+ }cccccc | + {1:~ }|*2 | ]]) end) @@ -570,4 +622,210 @@ describe('Conceal', function() feed('$') expect_pos(9, 26) end) + + local function test_conceal_virtualedit_after_eol(wrap) + local screen = Screen.new(60, 3) + screen:set_default_attr_ids({ + [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText + }) + screen:attach() + 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 | + {0:~ }| + | + ]]) + feed('l') + screen:expect([[ + abcdefghijklmnpop^ | + {0:~ }| + | + ]]) + feed('l') + screen:expect([[ + abcdefghijklmnpop ^ | + {0:~ }| + | + ]]) + feed('l') + screen:expect([[ + abcdefghijklmnpop ^ | + {0:~ }| + | + ]]) + feed('rr') + screen:expect([[ + abcdefghijklmnpop ^r | + {0:~ }| + | + ]]) + 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) + screen:set_default_attr_ids({ + [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText + }) + screen:attach() + 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| + {0: ~}| + | + ]]) + feed('h') + screen:expect([[ + ^ popnmlkjihgfedcba| + {0: ~}| + | + ]]) + feed('h') + screen:expect([[ + ^ popnmlkjihgfedcba| + {0: ~}| + | + ]]) + feed('h') + screen:expect([[ + ^ popnmlkjihgfedcba| + {0: ~}| + | + ]]) + feed('rr') + screen:expect([[ + ^r popnmlkjihgfedcba| + {0: ~}| + | + ]]) + 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:set_default_attr_ids({ + [0] = { bold = true, foreground = Screen.colors.Blue }, + [1] = { background = Screen.colors.DarkGrey, foreground = Screen.colors.LightGrey }, + [2] = { background = Screen.colors.LightRed }, + }) + screen:attach() + 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{1:β}bbbbb{1:β}cccc^c {2: } | + foobar {2: } | + {0:~ }| + | + ]]) + feed('gM') + screen:expect([[ + aaaaa{1:β}bb^bbb{1:β}ccccc {2: } | + foobar {2: } | + {0:~ }| + | + ]]) + command('set conceallevel=3') + screen:expect([[ + aaaaabb^bbbccccc {2: } | + foobar {2: } | + {0:~ }| + | + ]]) + feed('$') + screen:expect([[ + aaaaabbbbbcccc^c {2: } | + foobar {2: } | + {0:~ }| + | + ]]) + 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:set_default_attr_ids({ + [0] = { bold = true, foreground = Screen.colors.Blue }, + [1] = { background = Screen.colors.DarkGrey, foreground = Screen.colors.LightGrey }, + [2] = { background = Screen.colors.LightRed }, + }) + screen:attach() + exec([[ + call setline(1, 'aaaaaaaaaa口=口bbbbbbbbbb口=口cccccccccc') + syntax match test /口=口/ conceal cchar=β + set conceallevel=2 concealcursor=n + normal! $ + ]]) + screen:expect([[ + aaaaaaaaaa{1:β}bbbbb | + bbbbb{1:β}ccccccccc^c | + {0:~ }| + | + ]]) + feed('gM') + screen:expect([[ + aaaaaaaaaa{1:β}bbbbb | + ^bbbbb{1:β}cccccccccc | + {0:~ }| + | + ]]) + command('set conceallevel=3') + screen:expect([[ + aaaaaaaaaabbbbb | + ^bbbbbcccccccccc | + {0:~ }| + | + ]]) + feed('$') + screen:expect([[ + aaaaaaaaaabbbbb | + bbbbbccccccccc^c | + {0:~ }| + | + ]]) + end) end) |