Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 1 | " Tests for 'listchars' display with 'list' and :list |
| 2 | |
| 3 | source view_util.vim |
| 4 | |
| 5 | func Test_listchars() |
| 6 | enew! |
| 7 | set ff=unix |
| 8 | set list |
| 9 | |
| 10 | set listchars+=tab:>-,space:.,trail:< |
| 11 | call append(0, [ |
| 12 | \ ' aa ', |
| 13 | \ ' bb ', |
| 14 | \ ' cccc ', |
| 15 | \ 'dd ee ', |
| 16 | \ ' ' |
| 17 | \ ]) |
| 18 | let expected = [ |
| 19 | \ '>-------aa>-----$', |
| 20 | \ '..bb>---<<$', |
| 21 | \ '...cccc><$', |
| 22 | \ 'dd........ee<<>-$', |
| 23 | \ '<$' |
| 24 | \ ] |
| 25 | redraw! |
| 26 | for i in range(1, 5) |
| 27 | call cursor(i, 1) |
| 28 | call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) |
| 29 | endfor |
| 30 | |
| 31 | set listchars-=trail:< |
| 32 | let expected = [ |
| 33 | \ '>-------aa>-----$', |
| 34 | \ '..bb>---..$', |
| 35 | \ '...cccc>.$', |
| 36 | \ 'dd........ee..>-$', |
| 37 | \ '.$' |
| 38 | \ ] |
| 39 | redraw! |
| 40 | for i in range(1, 5) |
| 41 | call cursor(i, 1) |
| 42 | call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) |
| 43 | endfor |
| 44 | |
Bram Moolenaar | 83a5217 | 2019-01-16 22:41:54 +0100 | [diff] [blame] | 45 | " tab with 3rd character. |
| 46 | set listchars-=tab:>- |
| 47 | set listchars+=tab:<=>,trail:- |
| 48 | let expected = [ |
| 49 | \ '<======>aa<====>$', |
| 50 | \ '..bb<==>--$', |
| 51 | \ '...cccc>-$', |
| 52 | \ 'dd........ee--<>$', |
| 53 | \ '-$' |
| 54 | \ ] |
| 55 | redraw! |
| 56 | for i in range(1, 5) |
| 57 | call cursor(i, 1) |
| 58 | call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) |
| 59 | endfor |
| 60 | |
| 61 | set listchars-=trail:- |
| 62 | let expected = [ |
| 63 | \ '<======>aa<====>$', |
| 64 | \ '..bb<==>..$', |
| 65 | \ '...cccc>.$', |
| 66 | \ 'dd........ee..<>$', |
| 67 | \ '.$' |
| 68 | \ ] |
| 69 | redraw! |
| 70 | for i in range(1, 5) |
| 71 | call cursor(i, 1) |
| 72 | call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) |
| 73 | endfor |
| 74 | |
| 75 | set listchars-=tab:<=> |
| 76 | set listchars+=tab:>- |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 77 | set listchars+=trail:< |
| 78 | set nolist |
| 79 | normal ggdG |
| 80 | call append(0, [ |
| 81 | \ ' fff ', |
| 82 | \ ' gg ', |
| 83 | \ ' h ', |
| 84 | \ 'iii ', |
| 85 | \ ]) |
| 86 | let l = split(execute("%list"), "\n") |
| 87 | call assert_equal([ |
| 88 | \ '..fff>--<<$', |
| 89 | \ '>-------gg>-----$', |
| 90 | \ '.....h>-$', |
| 91 | \ 'iii<<<<><<$', '$'], l) |
| 92 | |
Bram Moolenaar | 895d966 | 2019-01-31 21:57:21 +0100 | [diff] [blame] | 93 | |
| 94 | " test nbsp |
| 95 | normal ggdG |
| 96 | set listchars=nbsp:X,trail:Y |
| 97 | set list |
| 98 | " Non-breaking space |
| 99 | let nbsp = nr2char(0xa0) |
| 100 | call append(0, [ ">".nbsp."<" ]) |
| 101 | |
| 102 | let expected = '>X< ' |
| 103 | |
| 104 | redraw! |
| 105 | call cursor(1, 1) |
| 106 | call assert_equal([expected], ScreenLines(1, virtcol('$'))) |
| 107 | |
| 108 | set listchars=nbsp:X |
| 109 | redraw! |
| 110 | call cursor(1, 1) |
| 111 | call assert_equal([expected], ScreenLines(1, virtcol('$'))) |
| 112 | |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 113 | enew! |
| 114 | set listchars& ff& |
| 115 | endfunc |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 116 | |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame^] | 117 | " Test that unicode listchars characters get properly inserted |
| 118 | func Test_listchars_unicode() |
| 119 | enew! |
| 120 | let oldencoding=&encoding |
| 121 | set encoding=utf-8 |
| 122 | set ff=unix |
| 123 | |
| 124 | set listchars=eol:⇔,space:␣,nbsp:≠,tab:←↔→ |
| 125 | set list |
| 126 | |
| 127 | let nbsp = nr2char(0xa0) |
| 128 | call append(0, [ |
| 129 | \ "a\tb c".nbsp."d" |
| 130 | \ ]) |
| 131 | let expected = [ |
| 132 | \ 'a←↔↔↔↔↔→b␣c≠d⇔' |
| 133 | \ ] |
| 134 | redraw! |
| 135 | call cursor(1, 1) |
| 136 | call assert_equal(expected, ScreenLines(1, virtcol('$'))) |
| 137 | let &encoding=oldencoding |
| 138 | enew! |
| 139 | set listchars& ff& |
| 140 | endfunction |
| 141 | |
| 142 | " Tests that space characters following composing character won't get replaced |
| 143 | " by listchars. |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 144 | func Test_listchars_composing() |
| 145 | enew! |
| 146 | let oldencoding=&encoding |
| 147 | set encoding=utf-8 |
| 148 | set ff=unix |
| 149 | set list |
| 150 | |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame^] | 151 | set listchars=eol:$,space:_,nbsp:= |
| 152 | |
| 153 | let nbsp1 = nr2char(0xa0) |
| 154 | let nbsp2 = nr2char(0x202f) |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 155 | call append(0, [ |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame^] | 156 | \ " \u3099\t \u309A".nbsp1.nbsp1."\u0302".nbsp2.nbsp2."\u0302", |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 157 | \ ]) |
| 158 | let expected = [ |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame^] | 159 | \ "_ \u3099^I \u309A=".nbsp1."\u0302=".nbsp2."\u0302$" |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 160 | \ ] |
| 161 | redraw! |
| 162 | call cursor(1, 1) |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame^] | 163 | call assert_equal(expected, ScreenLines(1, virtcol('$'))) |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 164 | let &encoding=oldencoding |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame^] | 165 | enew! |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 166 | set listchars& ff& |
| 167 | endfunction |