robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
7.9 KiB196 linesraw
1-- Tests for 'listchars' display with 'list' and :list.
2
3local n = require('test.functional.testnvim')()
4local t = require('test.testutil')
5local Screen = require('test.functional.ui.screen')
6
7local describe, it, before_each = t.describe, t.it, t.before_each
8local feed, insert, exec = n.feed, n.insert, n.exec
9local clear, feed_command, expect = n.clear, n.feed_command, n.expect
10
11-- luacheck: ignore 621 (Indentation)
12describe("'listchars'", function()
13  before_each(function()
14    clear()
15    feed_command('set listchars=eol:$')
16  end)
17
18  -- luacheck: ignore 613 (Trailing whitespace in a string)
19  it("works with 'list'", function()
20    exec([[
21      function GetScreenCharsForLine(lnum)
22        return join(map(range(1, virtcol('$')), 'nr2char(screenchar(a:lnum, v:val))'), '')
23      endfunction
24      nnoremap <expr> GG ":call add(g:lines, GetScreenCharsForLine(".screenrow()."))\<CR>"
25    ]])
26
27    insert([[
28      start:
29      	aa	
30        bb	  
31         cccc	 
32      dd        ee  	
33       ]])
34
35    feed_command('let g:lines = []')
36
37    -- Set up 'listchars', switch on 'list', and use the "GG" mapping to record
38    -- what the buffer lines look like.
39    feed_command('set listchars+=tab:>-,space:.,trail:<')
40    feed_command('set list')
41    feed_command('/^start:/')
42    feed_command('normal! jzt')
43    feed('GG<cr>')
44    feed('GG<cr>')
45    feed('GG<cr>')
46    feed('GG<cr>')
47    feed('GGH')
48
49    -- Repeat without displaying "trail" spaces.
50    feed_command('set listchars-=trail:<')
51    feed('GG<cr>')
52    feed('GG<cr>')
53    feed('GG<cr>')
54    feed('GG<cr>')
55    feed('GG')
56
57    -- Delete the buffer contents and :put the collected lines.
58    feed_command('%d')
59    feed_command('put =g:lines', '1d')
60
61    -- Assert buffer contents.
62    expect([[
63      >-------aa>-----$
64      ..bb>---<<$
65      ...cccc><$
66      dd........ee<<>-$
67      $
68      >-------aa>-----$
69      ..bb>---..$
70      ...cccc>.$
71      dd........ee..>-$
72      $]])
73  end)
74
75  it('works with :list', function()
76    insert([[
77      start:
78        fff	  
79      	gg	
80           h	
81      iii    	  ]])
82
83    -- Set up 'listchars', switch 'list' *off* (:list must show the 'listchars'
84    -- even when 'list' is off), then run :list and collect the output.
85    feed_command('set listchars+=tab:>-,space:.,trail:<')
86    feed_command('set nolist')
87    feed_command('/^start:/')
88    feed_command('redir! => g:lines')
89    feed_command('+1,$list')
90    feed_command('redir END')
91
92    -- Delete the buffer contents and :put the collected lines.
93    feed_command('%d')
94    feed_command('put =g:lines', '1d')
95
96    -- Assert buffer contents.
97    expect([[
98
99
100      ..fff>--<<$
101      >-------gg>-----$
102      .....h>-$
103      iii<<<<><<$]])
104  end)
105
106  it('"exceeds" character does not appear in foldcolumn vim-patch:8.2.3121', function()
107    local screen = Screen.new(60, 10)
108    exec([[
109      call setline(1, ['aaa', '', 'a', 'aaaaaa'])
110      vsplit
111      vsplit
112      windo set signcolumn=yes foldcolumn=1 winminwidth=0 nowrap list listchars=extends:>,precedes:<
113    ]])
114    feed('13<C-W>>')
115    screen:expect([[
116      {7:   }aaa              │{7:   }a{1:>}│{7:   }^aaa                           |
117      {7:   }                 │{7:   }  │{7:   }                              |
118      {7:   }a                │{7:   }a │{7:   }a                             |
119      {7:   }aaaaaa           │{7:   }a{1:>}│{7:   }aaaaaa                        |
120      {1:~                   }│{1:~    }│{1:~                                }|*4
121      {2:[No Name] [+]        <[+]  }{3:[No Name] [+]                    }|
122                                                                  |
123    ]])
124    feed('<C-W>>')
125    screen:expect([[
126      {7:   }aaa              │{7:   }{1:>}│{7:   }^aaa                            |
127      {7:   }                 │{7:   } │{7:   }                               |
128      {7:   }a                │{7:   }a│{7:   }a                              |
129      {7:   }aaaaaa           │{7:   }{1:>}│{7:   }aaaaaa                         |
130      {1:~                   }│{1:~   }│{1:~                                 }|*4
131      {2:[No Name] [+]        <+]  }{3:[No Name] [+]                     }|
132                                                                  |
133    ]])
134    feed('<C-W>>')
135    screen:expect([[
136      {7:   }aaa              │{7:   }│{7:   }^aaa                             |
137      {7:   }                 │{7:   }│{7:   }                                |
138      {7:   }a                │{7:   }│{7:   }a                               |
139      {7:   }aaaaaa           │{7:   }│{7:   }aaaaaa                          |
140      {1:~                   }│{1:~  }│{1:~                                  }|*4
141      {2:[No Name] [+]        <]  }{3:[No Name] [+]                      }|
142                                                                  |
143    ]])
144    feed('<C-W>>')
145    screen:expect([[
146      {7:   }aaa              │{7:  }│{7:   }^aaa                              |
147      {7:   }                 │{7:  }│{7:   }                                 |
148      {7:   }a                │{7:  }│{7:   }a                                |
149      {7:   }aaaaaa           │{7:  }│{7:   }aaaaaa                           |
150      {1:~                   }│{1:~ }│{1:~                                   }|*4
151      {2:[No Name] [+]        <  }{3:[No Name] [+]                       }|
152                                                                  |
153    ]])
154    feed('<C-W>>')
155    screen:expect([[
156      {7:   }aaa              │{7: }│{7:   }^aaa                               |
157      {7:   }                 │{7: }│{7:   }                                  |
158      {7:   }a                │{7: }│{7:   }a                                 |
159      {7:   }aaaaaa           │{7: }│{7:   }aaaaaa                            |
160      {1:~                   }│{1:~}│{1:~                                    }|*4
161      {2:[No Name] [+]        < }{3:[No Name] [+]                        }|
162                                                                  |
163    ]])
164    feed('<C-W>h')
165    feed_command('set nowrap foldcolumn=4')
166    screen:expect([[
167      {7:   }aaa              │{7:      }^aaa           │{7:   }aaa            |
168      {7:   }                 │{7:      }              │{7:   }               |
169      {7:   }a                │{7:      }a             │{7:   }a              |
170      {7:   }aaaaaa           │{7:      }aaaaaa        │{7:   }aaaaaa         |
171      {1:~                   }│{1:~                   }│{1:~                 }|*4
172      {2:[No Name] [+]        }{3:[No Name] [+]        }{2:[No Name] [+]     }|
173      :set nowrap foldcolumn=4                                    |
174    ]])
175    feed('15<C-W><lt>')
176    screen:expect([[
177      {7:   }aaa              │{7:     }│{7:   }aaa                           |
178      {7:   }                 │{7:     }│{7:   }                              |
179      {7:   }a                │{7:     }│{7:   }a                             |
180      {7:   }aaaaaa           │{7:    ^ }│{7:   }aaaaaa                        |
181      {1:~                   }│{1:~    }│{1:~                                }|*4
182      {2:[No Name] [+]        }{3:<[+]  }{2:[No Name] [+]                    }|
183      :set nowrap foldcolumn=4                                    |
184    ]])
185    feed('4<C-W><lt>')
186    screen:expect([[
187      {7:   }aaa              │{7: }│{7:   }aaa                               |
188      {7:   }                 │{7: }│{7:   }                                  |
189      {7:   }a                │{7: }│{7:   }a                                 |
190      {7:   }aaaaaa           │{7:^ }│{7:   }aaaaaa                            |
191      {1:~                   }│{1:~}│{1:~                                    }|*4
192      {2:[No Name] [+]        }{3:< }{2:[No Name] [+]                        }|
193      :set nowrap foldcolumn=4                                    |
194    ]])
195  end)
196end)