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 |