aboutsummaryrefslogtreecommitdiff
path: root/test/functional/legacy/listlbr_spec.lua
blob: da641c3b6f9129c2ed8870c3b87b3679eae7fc00 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
-- Test for linebreak and list option (non-utf8)

local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')

local feed, insert, source = n.feed, n.insert, n.source
local clear, feed_command, expect = n.clear, n.feed_command, n.expect

describe('listlbr', function()
  before_each(clear)

  -- luacheck: ignore 621 (Indentation)
  -- luacheck: ignore 611 (Line contains only whitespaces)
  -- luacheck: ignore 613 (Trailing whitespaces in a string)
  it('is working', function()
    insert([[
      dummy text]])

    feed_command('set wildchar=^E')
    feed_command('10new')
    feed_command('vsp')
    feed_command('vert resize 20')
    feed_command([[put =\"\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP \"]])
    feed_command('norm! zt')
    feed_command('set ts=4 sw=4 sts=4 linebreak sbr=+ wrap')
    source([[
      fu! ScreenChar(width)
        let c=''
        for j in range(1,4)
          for i in range(1,a:width)
            let c.=nr2char(screenchar(j, i))
          endfor
          let c.="\n"
        endfor
        return c
      endfu
      fu! DoRecordScreen()
        wincmd l
        $put =printf(\"\n%s\", g:test)
        $put =g:line
        wincmd p
      endfu
    ]])
    feed_command('let g:test="Test 1: set linebreak"')
    feed_command('redraw!')
    feed_command('let line=ScreenChar(winwidth(0))')
    feed_command('call DoRecordScreen()')

    feed_command('let g:test="Test 2: set linebreak + set list"')
    feed_command('set linebreak list listchars=')
    feed_command('redraw!')
    feed_command('let line=ScreenChar(winwidth(0))')
    feed_command('call DoRecordScreen()')

    feed_command('let g:test ="Test 3: set linebreak nolist"')
    feed_command('set nolist linebreak')
    feed_command('redraw!')
    feed_command('let line=ScreenChar(winwidth(0))')
    feed_command('call DoRecordScreen()')

    feed_command(
      'let g:test ="Test 4: set linebreak with tab and 1 line as long as screen: should break!"'
    )
    feed_command('set nolist linebreak ts=8')
    feed_command([[let line="1\t".repeat('a', winwidth(0)-2)]])
    feed_command('$put =line')
    feed_command('$')
    feed_command('norm! zt')
    feed_command('redraw!')
    feed_command('let line=ScreenChar(winwidth(0))')
    feed_command('call DoRecordScreen()')
    feed_command([[let line="_S_\t bla"]])
    feed_command('$put =line')
    feed_command('$')
    feed_command('norm! zt')

    feed_command(
      'let g:test ="Test 5: set linebreak with conceal and set list and tab displayed by different char (line may not be truncated)"'
    )
    feed_command('set cpo&vim list linebreak conceallevel=2 concealcursor=nv listchars=tab:ab')
    feed_command('syn match ConcealVar contained /_/ conceal')
    feed_command('syn match All /.*/ contains=ConcealVar')
    feed_command('let line=ScreenChar(winwidth(0))')
    feed_command('call DoRecordScreen()')
    feed_command('set cpo&vim linebreak')

    feed_command('let g:test ="Test 6: set linebreak with visual block mode"')
    feed_command('let line="REMOVE: this not"')
    feed_command('$put =g:test')
    feed_command('$put =line')
    feed_command('let line="REMOVE: aaaaaaaaaaaaa"')
    feed_command('$put =line')
    feed_command('1/^REMOVE:')
    feed('0<C-V>jf x')
    feed_command('$put')
    feed_command('set cpo&vim linebreak')

    feed_command('let g:test ="Test 7: set linebreak with visual block mode and v_b_A"')
    feed_command('$put =g:test')
    feed('Golong line: <esc>40afoobar <esc>aTARGET at end<esc>')
    feed_command([[exe "norm! $3B\<C-v>eAx\<Esc>"]])
    feed_command('set cpo&vim linebreak sbr=')

    feed_command('let g:test ="Test 8: set linebreak with visual char mode and changing block"')
    feed_command('$put =g:test')
    feed('Go1111-1111-1111-11-1111-1111-1111<esc>0f-lv3lc2222<esc>bgj.')

    feed_command('let g:test ="Test 9: using redo after block visual mode"')
    feed_command('$put =g:test')
    feed('Go<CR>')
    feed('aaa<CR>')
    feed('aaa<CR>')
    feed('a<ESC>2k<C-V>2j~e.<CR>')

    feed_command('let g:test ="Test 10: using normal commands after block-visual"')
    feed_command('$put =g:test')
    feed_command('set linebreak')
    feed('Go<cr>')
    feed('abcd{ef<cr>')
    feed('ghijklm<cr>')
    feed('no}pqrs<esc>2k0f{<C-V><C-V>c%<esc>')

    feed_command('let g:test ="Test 11: using block replace mode after wrapping"')
    feed_command('$put =g:test')
    feed_command('set linebreak wrap')
    feed('Go<esc>150aa<esc>yypk147|<C-V>jr0<cr>')

    feed_command('let g:test ="Test 12: set linebreak list listchars=space:_,tab:>-,tail:-,eol:$"')
    feed_command('set list listchars=space:_,trail:-,tab:>-,eol:$')
    feed_command('$put =g:test')
    feed_command([[let line="a aaaaaaaaaaaaaaaaaaaaaa\ta "]])
    feed_command('$put =line')
    feed_command('$')
    feed_command('norm! zt')
    feed_command('redraw!')
    feed_command('let line=ScreenChar(winwidth(0))')
    feed_command('call DoRecordScreen()')

    -- Assert buffer contents.
    expect([[

      	abcdef hijklmn	pqrstuvwxyz_1060ABCDEFGHIJKLMNOP 

      Test 1: set linebreak
          abcdef          
      +hijklmn            
      +pqrstuvwxyz_1060ABC
      +DEFGHIJKLMNOP      

      Test 2: set linebreak + set list
      ^Iabcdef hijklmn^I  
      +pqrstuvwxyz_1060ABC
      +DEFGHIJKLMNOP      
                          

      Test 3: set linebreak nolist
          abcdef          
      +hijklmn            
      +pqrstuvwxyz_1060ABC
      +DEFGHIJKLMNOP      
      1	aaaaaaaaaaaaaaaaaa

      Test 4: set linebreak with tab and 1 line as long as screen: should break!
      1                   
      +aaaaaaaaaaaaaaaaaa 
      ~                   
      ~                   
      _S_	 bla

      Test 5: set linebreak with conceal and set list and tab displayed by different char (line may not be truncated)
      Sabbbbbb bla        
      ~                   
      ~                   
      ~                   
      Test 6: set linebreak with visual block mode
      this not
      aaaaaaaaaaaaa
      REMOVE: 
      REMOVE: 
      Test 7: set linebreak with visual block mode and v_b_A
      long line: foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar TARGETx at end
      Test 8: set linebreak with visual char mode and changing block
      1111-2222-1111-11-1111-2222-1111
      Test 9: using redo after block visual mode

      AaA
      AaA
      A
      Test 10: using normal commands after block-visual

      abcdpqrs
      Test 11: using block replace mode after wrapping
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0aaa
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0aaa
      Test 12: set linebreak list listchars=space:_,tab:>-,tail:-,eol:$
      a aaaaaaaaaaaaaaaaaaaaaa	a 

      Test 12: set linebreak list listchars=space:_,tab:>-,tail:-,eol:$
      a_                  
      aaaaaaaaaaaaaaaaaaaa
      aa>-----a-$         
      ~                   ]])
  end)

  -- oldtest: Test_linebreak_reset_restore()
  it('cursor position is drawn correctly after operator', function()
    local screen = Screen.new(60, 6)
    screen:attach()

    -- f_wincol() calls validate_cursor()
    source([[
      set linebreak showcmd noshowmode formatexpr=wincol()-wincol()
      call setline(1, repeat('a', &columns - 10) .. ' bbbbbbbbbb c')
    ]])

    feed('$v$')
    screen:expect([[
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa          |
      bbbbbbbbbb {17:c}^                                                |
      {1:~                                                           }|*3
                                                       2          |
    ]])
    feed('zo')
    screen:expect([[
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa          |
      bbbbbbbbbb ^c                                                |
      {1:~                                                           }|*3
      {9:E490: No fold found}                                         |
    ]])

    feed('$v$')
    screen:expect([[
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa          |
      bbbbbbbbbb {17:c}^                                                |
      {1:~                                                           }|*3
      {9:E490: No fold found}                              2          |
    ]])
    feed('gq')
    screen:expect([[
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa          |
      bbbbbbbbbb ^c                                                |
      {1:~                                                           }|*3
      {9:E490: No fold found}                                         |
    ]])

    feed('$<C-V>$')
    screen:expect([[
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa          |
      bbbbbbbbbb {17:c}^                                                |
      {1:~                                                           }|*3
      {9:E490: No fold found}                              1x2        |
    ]])
    feed('I')
    screen:expect([[
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa          |
      bbbbbbbbbb ^c                                                |
      {1:~                                                           }|*3
      {9:E490: No fold found}                                         |
    ]])

    feed('<Esc>$v$')
    screen:expect([[
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa          |
      bbbbbbbbbb {17:c}^                                                |
      {1:~                                                           }|*3
      {9:E490: No fold found}                              2          |
    ]])
    feed('s')
    screen:expect([[
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa          |
      bbbbbbbbbb ^                                                 |
      {1:~                                                           }|*3
      {9:E490: No fold found}                                         |
    ]])
  end)
end)