diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2021-09-19 14:31:10 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-19 14:31:10 -0400 |
commit | 89db07556dbdce97c0c150ed7e47d80e1ddacad3 (patch) | |
tree | a45ab65e275790c0ed853ad4906bcfa3bcd5154d /src/nvim/testdir | |
parent | 2aa662568a995ccfece490ca0f0f0cbdb9d57560 (diff) | |
parent | f4ce4c1677819472d1b094ef31b8db9c2549e55e (diff) | |
download | rneovim-89db07556dbdce97c0c150ed7e47d80e1ddacad3.tar.gz rneovim-89db07556dbdce97c0c150ed7e47d80e1ddacad3.tar.bz2 rneovim-89db07556dbdce97c0c150ed7e47d80e1ddacad3.zip |
Merge pull request #15630 from zeertzjq/vim-8.2.3424
vim-patch:8.1.{1071,1078,1079,1110},8.2.{2640,3424,3425,3437}
Diffstat (limited to 'src/nvim/testdir')
-rw-r--r-- | src/nvim/testdir/test_listchars.vim | 186 | ||||
-rw-r--r-- | src/nvim/testdir/test_utf8.vim | 35 | ||||
-rw-r--r-- | src/nvim/testdir/view_util.vim | 3 |
3 files changed, 222 insertions, 2 deletions
diff --git a/src/nvim/testdir/test_listchars.vim b/src/nvim/testdir/test_listchars.vim index 4cb609aaf0..8a1393a45d 100644 --- a/src/nvim/testdir/test_listchars.vim +++ b/src/nvim/testdir/test_listchars.vim @@ -140,13 +140,100 @@ func Test_listchars() call assert_equal(expected, split(execute("%list"), "\n")) + " Test multispace + normal ggdG + set listchars=eol:$ + set listchars+=multispace:yYzZ + set list + + call append(0, [ + \ ' ffff ', + \ ' i i gg', + \ ' h ', + \ ' j ', + \ ' 0 0 ', + \ ]) + + let expected = [ + \ 'yYzZffffyYzZ$', + \ 'yYi iyYzZygg$', + \ ' hyYzZyYzZyY$', + \ 'yYzZyYzZyYj $', + \ 'yYzZ0yY0yYzZ$', + \ '$' + \ ] + redraw! + for i in range(1, 5) + call cursor(i, 1) + call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) + endfor + + call assert_equal(expected, split(execute("%list"), "\n")) + + " the last occurrence of 'multispace:' is used + set listchars+=space:x,multispace:XyY + + let expected = [ + \ 'XyYXffffXyYX$', + \ 'XyixiXyYXygg$', + \ 'xhXyYXyYXyYX$', + \ 'XyYXyYXyYXjx$', + \ 'XyYX0Xy0XyYX$', + \ '$' + \ ] + redraw! + for i in range(1, 5) + call cursor(i, 1) + call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) + endfor + + call assert_equal(expected, split(execute("%list"), "\n")) + + set listchars+=lead:>,trail:< + + let expected = [ + \ '>>>>ffff<<<<$', + \ '>>ixiXyYXygg$', + \ '>h<<<<<<<<<<$', + \ '>>>>>>>>>>j<$', + \ '>>>>0Xy0<<<<$', + \ '$' + \ ] + redraw! + for i in range(1, 5) + call cursor(i, 1) + call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) + endfor + + call assert_equal(expected, split(execute("%list"), "\n")) + + " removing 'multispace:' + set listchars-=multispace:XyY + set listchars-=multispace:yYzZ + + let expected = [ + \ '>>>>ffff<<<<$', + \ '>>ixixxxxxgg$', + \ '>h<<<<<<<<<<$', + \ '>>>>>>>>>>j<$', + \ '>>>>0xx0<<<<$', + \ '$' + \ ] + redraw! + for i in range(1, 5) + call cursor(i, 1) + call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) + endfor + + call assert_equal(expected, split(execute("%list"), "\n")) + " test nbsp normal ggdG set listchars=nbsp:X,trail:Y set list " Non-breaking space let nbsp = nr2char(0xa0) - call append(0, [ ">".nbsp."<" ]) + call append(0, [ ">" .. nbsp .. "<" ]) let expected = '>X< ' @@ -181,3 +268,100 @@ func Test_listchars() enew! set listchars& ff& endfunc + +" Test that unicode listchars characters get properly inserted +func Test_listchars_unicode() + enew! + let oldencoding=&encoding + set encoding=utf-8 + set ff=unix + + set listchars=eol:⇔,space:␣,multispace:≡≢≣,nbsp:≠,tab:←↔→ + set list + + let nbsp = nr2char(0xa0) + call append(0, [" a\tb c" .. nbsp .. "d "]) + let expected = ['≡≢≣≡≢≣≡≢a←↔↔↔↔↔→b␣c≠d≡≢⇔'] + redraw! + call cursor(1, 1) + call assert_equal(expected, ScreenLines(1, virtcol('$'))) + + set listchars+=lead:⇨,trail:⇦ + let expected = ['⇨⇨⇨⇨⇨⇨⇨⇨a←↔↔↔↔↔→b␣c≠d⇦⇦⇔'] + redraw! + call cursor(1, 1) + call assert_equal(expected, ScreenLines(1, virtcol('$'))) + + let &encoding=oldencoding + enew! + set listchars& ff& +endfunction + +func Test_listchars_invalid() + enew! + set ff=unix + + set listchars=eol:$ + set list + set ambiwidth=double + + " No colon + call assert_fails('set listchars=x', 'E474:') + call assert_fails('set listchars=x', 'E474:') + call assert_fails('set listchars=multispace', 'E474:') + + " Too short + call assert_fails('set listchars=space:', 'E474:') + call assert_fails('set listchars=tab:x', 'E474:') + call assert_fails('set listchars=multispace:', 'E474:') + + " One occurrence too short + call assert_fails('set listchars=space:,space:x', 'E474:') + call assert_fails('set listchars=space:x,space:', 'E474:') + call assert_fails('set listchars=tab:x,tab:xx', 'E474:') + call assert_fails('set listchars=tab:xx,tab:x', 'E474:') + call assert_fails('set listchars=multispace:,multispace:x', 'E474:') + call assert_fails('set listchars=multispace:x,multispace:', 'E474:') + + " Too long + call assert_fails('set listchars=space:xx', 'E474:') + call assert_fails('set listchars=tab:xxxx', 'E474:') + + " Has non-single width character + call assert_fails('set listchars=space:·', 'E474:') + call assert_fails('set listchars=tab:·x', 'E474:') + call assert_fails('set listchars=tab:x·', 'E474:') + call assert_fails('set listchars=tab:xx·', 'E474:') + call assert_fails('set listchars=multispace:·', 'E474:') + call assert_fails('set listchars=multispace:xxx·', 'E474:') + + enew! + set ambiwidth& listchars& ff& +endfunction + +" Tests that space characters following composing character won't get replaced +" by listchars. +func Test_listchars_composing() + enew! + let oldencoding=&encoding + set encoding=utf-8 + set ff=unix + set list + + set listchars=eol:$,space:_,nbsp:= + + let nbsp1 = nr2char(0xa0) + let nbsp2 = nr2char(0x202f) + call append(0, [ + \ " \u3099\t \u309A" .. nbsp1 .. nbsp1 .. "\u0302" .. nbsp2 .. nbsp2 .. "\u0302", + \ ]) + let expected = [ + \ "_ \u3099^I \u309A=" .. nbsp1 .. "\u0302=" .. nbsp2 .. "\u0302$" + \ ] + redraw! + call cursor(1, 1) + call assert_equal(expected, ScreenLines(1, virtcol('$'))) + let &encoding=oldencoding + enew! + set listchars& ff& +endfunction diff --git a/src/nvim/testdir/test_utf8.vim b/src/nvim/testdir/test_utf8.vim index c51fb3a759..735efac36d 100644 --- a/src/nvim/testdir/test_utf8.vim +++ b/src/nvim/testdir/test_utf8.vim @@ -1,5 +1,6 @@ " Tests for Unicode manipulations +source view_util.vim " Visual block Insert adjusts for multi-byte char func Test_visual_block_insert() @@ -61,6 +62,40 @@ func Test_getvcol() call assert_equal(2, virtcol("']")) endfunc +func Test_screenchar_utf8() + new + + " 1-cell, with composing characters + call setline(1, ["ABC\u0308"]) + redraw + call assert_equal([0x0041], screenchars(1, 1)) + call assert_equal([0x0042], screenchars(1, 2)) + call assert_equal([0x0043, 0x0308], screenchars(1, 3)) + call assert_equal("A", screenstring(1, 1)) + call assert_equal("B", screenstring(1, 2)) + call assert_equal("C\u0308", screenstring(1, 3)) + + " 2-cells, with composing characters + let text = "\u3042\u3044\u3046\u3099" + call setline(1, text) + redraw + call assert_equal([0x3042], screenchars(1, 1)) + call assert_equal([0], screenchars(1, 2)) + call assert_equal([0x3044], screenchars(1, 3)) + call assert_equal([0], screenchars(1, 4)) + call assert_equal([0x3046, 0x3099], screenchars(1, 5)) + + call assert_equal("\u3042", screenstring(1, 1)) + call assert_equal("", screenstring(1, 2)) + call assert_equal("\u3044", screenstring(1, 3)) + call assert_equal("", screenstring(1, 4)) + call assert_equal("\u3046\u3099", screenstring(1, 5)) + + call assert_equal([text . ' '], ScreenLines(1, 8)) + + bwipe! +endfunc + func Test_list2str_str2list_utf8() " One Unicode codepoint let s = "\u3042\u3044" diff --git a/src/nvim/testdir/view_util.vim b/src/nvim/testdir/view_util.vim index 1def201a05..1cdce21602 100644 --- a/src/nvim/testdir/view_util.vim +++ b/src/nvim/testdir/view_util.vim @@ -16,6 +16,7 @@ func Screenline(lnum) return matchstr(line, '^.\{-}\ze\s*$') endfunc +" Get text on the screen, including composing characters. " ScreenLines(lnum, width) or " ScreenLines([start, end], width) function! ScreenLines(lnum, width) abort @@ -29,7 +30,7 @@ function! ScreenLines(lnum, width) abort endif let lines = [] for l in range(start, end) - let lines += [join(map(range(1, a:width), 'nr2char(screenchar(l, v:val))'), '')] + let lines += [join(map(range(1, a:width), 'screenstring(l, v:val)'), '')] endfor return lines endfunction |