aboutsummaryrefslogtreecommitdiff
path: root/test/functional/legacy/listchars_spec.lua
blob: b4d07e03efc75481d2477572a6303f0e091dea54 (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
-- Tests for 'listchars' display with 'list' and :list.

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

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

-- luacheck: ignore 621 (Indentation)
describe("'listchars'", function()
  before_each(function()
    clear()
    feed_command('set listchars=eol:$')
  end)

  -- luacheck: ignore 613 (Trailing whitespace in a string)
  it("works with 'list'", function()
    exec([[
      function GetScreenCharsForLine(lnum)
        return join(map(range(1, virtcol('$')), 'nr2char(screenchar(a:lnum, v:val))'), '')
      endfunction
      nnoremap <expr> GG ":call add(g:lines, GetScreenCharsForLine(".screenrow()."))\<CR>"
    ]])

    insert([[
      start:
      	aa	
        bb	  
         cccc	 
      dd        ee  	
       ]])

    feed_command('let g:lines = []')

    -- Set up 'listchars', switch on 'list', and use the "GG" mapping to record
    -- what the buffer lines look like.
    feed_command('set listchars+=tab:>-,space:.,trail:<')
    feed_command('set list')
    feed_command('/^start:/')
    feed_command('normal! jzt')
    feed('GG<cr>')
    feed('GG<cr>')
    feed('GG<cr>')
    feed('GG<cr>')
    feed('GGH')

    -- Repeat without displaying "trail" spaces.
    feed_command('set listchars-=trail:<')
    feed('GG<cr>')
    feed('GG<cr>')
    feed('GG<cr>')
    feed('GG<cr>')
    feed('GG')

    -- Delete the buffer contents and :put the collected lines.
    feed_command('%d')
    feed_command('put =g:lines', '1d')

    -- Assert buffer contents.
    expect([[
      >-------aa>-----$
      ..bb>---<<$
      ...cccc><$
      dd........ee<<>-$
      <$
      >-------aa>-----$
      ..bb>---..$
      ...cccc>.$
      dd........ee..>-$
      .$]])
  end)

  it('works with :list', function()
    insert([[
      start:
        fff	  
      	gg	
           h	
      iii    	  ]])

    -- Set up 'listchars', switch 'list' *off* (:list must show the 'listchars'
    -- even when 'list' is off), then run :list and collect the output.
    feed_command('set listchars+=tab:>-,space:.,trail:<')
    feed_command('set nolist')
    feed_command('/^start:/')
    feed_command('redir! => g:lines')
    feed_command('+1,$list')
    feed_command('redir END')

    -- Delete the buffer contents and :put the collected lines.
    feed_command('%d')
    feed_command('put =g:lines', '1d')

    -- Assert buffer contents.
    expect([[


      ..fff>--<<$
      >-------gg>-----$
      .....h>-$
      iii<<<<><<$]])
  end)

  it('"exceeds" character does not appear in foldcolumn vim-patch:8.2.3121', function()
    local screen = Screen.new(60, 10)
    exec([[
      call setline(1, ['aaa', '', 'a', 'aaaaaa'])
      vsplit
      vsplit
      windo set signcolumn=yes foldcolumn=1 winminwidth=0 nowrap list listchars=extends:>,precedes:<
    ]])
    feed('13<C-W>>')
    screen:expect([[
      {7:   }aaa              │{7:   }a{1:>}│{7:   }^aaa                           |
      {7:   }                 │{7:   }  │{7:   }                              |
      {7:   }a                │{7:   }a │{7:   }a                             |
      {7:   }aaaaaa           │{7:   }a{1:>}│{7:   }aaaaaa                        |
      {1:~                   }│{1:~    }│{1:~                                }|*4
      {2:[No Name] [+]        <[+]  }{3:[No Name] [+]                    }|
                                                                  |
    ]])
    feed('<C-W>>')
    screen:expect([[
      {7:   }aaa              │{7:   }{1:>}│{7:   }^aaa                            |
      {7:   }                 │{7:   } │{7:   }                               |
      {7:   }a                │{7:   }a│{7:   }a                              |
      {7:   }aaaaaa           │{7:   }{1:>}│{7:   }aaaaaa                         |
      {1:~                   }│{1:~   }│{1:~                                 }|*4
      {2:[No Name] [+]        <+]  }{3:[No Name] [+]                     }|
                                                                  |
    ]])
    feed('<C-W>>')
    screen:expect([[
      {7:   }aaa              │{7:   }│{7:   }^aaa                             |
      {7:   }                 │{7:   }│{7:   }                                |
      {7:   }a                │{7:   }│{7:   }a                               |
      {7:   }aaaaaa           │{7:   }│{7:   }aaaaaa                          |
      {1:~                   }│{1:~  }│{1:~                                  }|*4
      {2:[No Name] [+]        <]  }{3:[No Name] [+]                      }|
                                                                  |
    ]])
    feed('<C-W>>')
    screen:expect([[
      {7:   }aaa              │{7:  }│{7:   }^aaa                              |
      {7:   }                 │{7:  }│{7:   }                                 |
      {7:   }a                │{7:  }│{7:   }a                                |
      {7:   }aaaaaa           │{7:  }│{7:   }aaaaaa                           |
      {1:~                   }│{1:~ }│{1:~                                   }|*4
      {2:[No Name] [+]        <  }{3:[No Name] [+]                       }|
                                                                  |
    ]])
    feed('<C-W>>')
    screen:expect([[
      {7:   }aaa              │{7: }│{7:   }^aaa                               |
      {7:   }                 │{7: }│{7:   }                                  |
      {7:   }a                │{7: }│{7:   }a                                 |
      {7:   }aaaaaa           │{7: }│{7:   }aaaaaa                            |
      {1:~                   }│{1:~}│{1:~                                    }|*4
      {2:[No Name] [+]        < }{3:[No Name] [+]                        }|
                                                                  |
    ]])
    feed('<C-W>h')
    feed_command('set nowrap foldcolumn=4')
    screen:expect([[
      {7:   }aaa              │{7:      }^aaa           │{7:   }aaa            |
      {7:   }                 │{7:      }              │{7:   }               |
      {7:   }a                │{7:      }a             │{7:   }a              |
      {7:   }aaaaaa           │{7:      }aaaaaa        │{7:   }aaaaaa         |
      {1:~                   }│{1:~                   }│{1:~                 }|*4
      {2:[No Name] [+]        }{3:[No Name] [+]        }{2:[No Name] [+]     }|
      :set nowrap foldcolumn=4                                    |
    ]])
    feed('15<C-W><lt>')
    screen:expect([[
      {7:   }aaa              │{7:     }│{7:   }aaa                           |
      {7:   }                 │{7:     }│{7:   }                              |
      {7:   }a                │{7:     }│{7:   }a                             |
      {7:   }aaaaaa           │{7:    ^ }│{7:   }aaaaaa                        |
      {1:~                   }│{1:~    }│{1:~                                }|*4
      {2:[No Name] [+]        }{3:<[+]  }{2:[No Name] [+]                    }|
      :set nowrap foldcolumn=4                                    |
    ]])
    feed('4<C-W><lt>')
    screen:expect([[
      {7:   }aaa              │{7: }│{7:   }aaa                               |
      {7:   }                 │{7: }│{7:   }                                  |
      {7:   }a                │{7: }│{7:   }a                                 |
      {7:   }aaaaaa           │{7:^ }│{7:   }aaaaaa                            |
      {1:~                   }│{1:~}│{1:~                                    }|*4
      {2:[No Name] [+]        }{3:< }{2:[No Name] [+]                        }|
      :set nowrap foldcolumn=4                                    |
    ]])
  end)
end)