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
|
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local meths = helpers.meths
local execute = helpers.execute
local clear = helpers.clear
local eval = helpers.eval
local eq = helpers.eq
local neq = helpers.neq
if helpers.pending_win32(pending) then return end
local function init_session(...)
local args = { helpers.nvim_prog, '-i', 'NONE', '--embed',
'--cmd', 'set shortmess+=I background=light noswapfile noautoindent',
'--cmd', 'set laststatus=1 undodir=. directory=. viewdir=. backupdir=.'
}
for _, v in ipairs({...}) do
table.insert(args, v)
end
helpers.set_session(helpers.spawn(args))
end
describe('startup defaults', function()
describe(':filetype', function()
local function expect_filetype(expected)
local screen = Screen.new(48, 4)
screen:attach()
execute('filetype')
screen:expect([[
^ |
~ |
~ |
]]..expected
)
end
it('enabled by `-u NORC`', function()
init_session('-u', 'NORC')
expect_filetype(
'filetype detection:ON plugin:ON indent:ON |')
end)
it('disabled by `-u NONE`', function()
init_session('-u', 'NONE')
expect_filetype(
'filetype detection:OFF plugin:OFF indent:OFF |')
end)
it('overridden by early `filetype on`', function()
init_session('-u', 'NORC', '--cmd', 'filetype on')
expect_filetype(
'filetype detection:ON plugin:OFF indent:OFF |')
end)
it('overridden by early `filetype plugin on`', function()
init_session('-u', 'NORC', '--cmd', 'filetype plugin on')
expect_filetype(
'filetype detection:ON plugin:ON indent:OFF |')
end)
it('overridden by early `filetype indent on`', function()
init_session('-u', 'NORC', '--cmd', 'filetype indent on')
expect_filetype(
'filetype detection:ON plugin:OFF indent:ON |')
end)
end)
describe('syntax', function()
it('enabled by `-u NORC`', function()
init_session('-u', 'NORC')
eq(1, eval('g:syntax_on'))
end)
it('disabled by `-u NONE`', function()
init_session('-u', 'NONE')
eq(0, eval('exists("g:syntax_on")'))
end)
it('overridden by early `syntax off`', function()
init_session('-u', 'NORC', '--cmd', 'syntax off')
eq(0, eval('exists("g:syntax_on")'))
end)
end)
describe('packpath', function()
it('defaults to &runtimepath', function()
eq(meths.get_option('runtimepath'), meths.get_option('packpath'))
end)
it('does not follow modifications to runtimepath', function()
meths.command('set runtimepath+=foo')
neq(meths.get_option('runtimepath'), meths.get_option('packpath'))
meths.command('set packpath+=foo')
eq(meths.get_option('runtimepath'), meths.get_option('packpath'))
end)
end)
end)
describe('XDG-based defaults', function()
-- Need to be in separate describe() block to not run clear() twice.
-- Do not put before_each() here for the same reasons.
describe('with too long XDG variables', function()
before_each(function()
clear({env={
XDG_CONFIG_HOME=('/x'):rep(4096),
XDG_CONFIG_DIRS=(('/a'):rep(2048)
.. ':' .. ('/b'):rep(2048)
.. (':/c'):rep(512)),
XDG_DATA_HOME=('/X'):rep(4096),
XDG_DATA_DIRS=(('/A'):rep(2048)
.. ':' .. ('/B'):rep(2048)
.. (':/C'):rep(512)),
}})
end)
it('are correctly set', function()
eq((('/x'):rep(4096) .. '/nvim'
.. ',' .. ('/a'):rep(2048) .. '/nvim'
.. ',' .. ('/b'):rep(2048) .. '/nvim'
.. (',' .. '/c/nvim'):rep(512)
.. ',' .. ('/X'):rep(4096) .. '/nvim/site'
.. ',' .. ('/A'):rep(2048) .. '/nvim/site'
.. ',' .. ('/B'):rep(2048) .. '/nvim/site'
.. (',' .. '/C/nvim/site'):rep(512)
.. ',' .. eval('$VIMRUNTIME')
.. (',' .. '/C/nvim/site/after'):rep(512)
.. ',' .. ('/B'):rep(2048) .. '/nvim/site/after'
.. ',' .. ('/A'):rep(2048) .. '/nvim/site/after'
.. ',' .. ('/X'):rep(4096) .. '/nvim/site/after'
.. (',' .. '/c/nvim/after'):rep(512)
.. ',' .. ('/b'):rep(2048) .. '/nvim/after'
.. ',' .. ('/a'):rep(2048) .. '/nvim/after'
.. ',' .. ('/x'):rep(4096) .. '/nvim/after'
), meths.get_option('runtimepath'))
meths.command('set runtimepath&')
meths.command('set backupdir&')
meths.command('set directory&')
meths.command('set undodir&')
meths.command('set viewdir&')
eq((('/x'):rep(4096) .. '/nvim'
.. ',' .. ('/a'):rep(2048) .. '/nvim'
.. ',' .. ('/b'):rep(2048) .. '/nvim'
.. (',' .. '/c/nvim'):rep(512)
.. ',' .. ('/X'):rep(4096) .. '/nvim/site'
.. ',' .. ('/A'):rep(2048) .. '/nvim/site'
.. ',' .. ('/B'):rep(2048) .. '/nvim/site'
.. (',' .. '/C/nvim/site'):rep(512)
.. ',' .. eval('$VIMRUNTIME')
.. (',' .. '/C/nvim/site/after'):rep(512)
.. ',' .. ('/B'):rep(2048) .. '/nvim/site/after'
.. ',' .. ('/A'):rep(2048) .. '/nvim/site/after'
.. ',' .. ('/X'):rep(4096) .. '/nvim/site/after'
.. (',' .. '/c/nvim/after'):rep(512)
.. ',' .. ('/b'):rep(2048) .. '/nvim/after'
.. ',' .. ('/a'):rep(2048) .. '/nvim/after'
.. ',' .. ('/x'):rep(4096) .. '/nvim/after'
), meths.get_option('runtimepath'))
eq('.,' .. ('/X'):rep(4096) .. '/nvim/backup',
meths.get_option('backupdir'))
eq(('/X'):rep(4096) .. '/nvim/swap//', meths.get_option('directory'))
eq(('/X'):rep(4096) .. '/nvim/undo', meths.get_option('undodir'))
eq(('/X'):rep(4096) .. '/nvim/view', meths.get_option('viewdir'))
end)
end)
describe('with XDG variables that can be expanded', function()
before_each(function()
clear({env={
XDG_CONFIG_HOME='$XDG_DATA_HOME',
XDG_CONFIG_DIRS='$XDG_DATA_DIRS',
XDG_DATA_HOME='$XDG_CONFIG_HOME',
XDG_DATA_DIRS='$XDG_CONFIG_DIRS',
}})
end)
it('are not expanded', function()
eq(('$XDG_DATA_HOME/nvim'
.. ',$XDG_DATA_DIRS/nvim'
.. ',$XDG_CONFIG_HOME/nvim/site'
.. ',$XDG_CONFIG_DIRS/nvim/site'
.. ',' .. eval('$VIMRUNTIME')
.. ',$XDG_CONFIG_DIRS/nvim/site/after'
.. ',$XDG_CONFIG_HOME/nvim/site/after'
.. ',$XDG_DATA_DIRS/nvim/after'
.. ',$XDG_DATA_HOME/nvim/after'
), meths.get_option('runtimepath'))
meths.command('set runtimepath&')
meths.command('set backupdir&')
meths.command('set directory&')
meths.command('set undodir&')
meths.command('set viewdir&')
eq(('$XDG_DATA_HOME/nvim'
.. ',$XDG_DATA_DIRS/nvim'
.. ',$XDG_CONFIG_HOME/nvim/site'
.. ',$XDG_CONFIG_DIRS/nvim/site'
.. ',' .. eval('$VIMRUNTIME')
.. ',$XDG_CONFIG_DIRS/nvim/site/after'
.. ',$XDG_CONFIG_HOME/nvim/site/after'
.. ',$XDG_DATA_DIRS/nvim/after'
.. ',$XDG_DATA_HOME/nvim/after'
), meths.get_option('runtimepath'))
eq('.,$XDG_CONFIG_HOME/nvim/backup', meths.get_option('backupdir'))
eq('$XDG_CONFIG_HOME/nvim/swap//', meths.get_option('directory'))
eq('$XDG_CONFIG_HOME/nvim/undo', meths.get_option('undodir'))
eq('$XDG_CONFIG_HOME/nvim/view', meths.get_option('viewdir'))
meths.command('set all&')
eq(('$XDG_DATA_HOME/nvim'
.. ',$XDG_DATA_DIRS/nvim'
.. ',$XDG_CONFIG_HOME/nvim/site'
.. ',$XDG_CONFIG_DIRS/nvim/site'
.. ',' .. eval('$VIMRUNTIME')
.. ',$XDG_CONFIG_DIRS/nvim/site/after'
.. ',$XDG_CONFIG_HOME/nvim/site/after'
.. ',$XDG_DATA_DIRS/nvim/after'
.. ',$XDG_DATA_HOME/nvim/after'
), meths.get_option('runtimepath'))
eq('.,$XDG_CONFIG_HOME/nvim/backup', meths.get_option('backupdir'))
eq('$XDG_CONFIG_HOME/nvim/swap//', meths.get_option('directory'))
eq('$XDG_CONFIG_HOME/nvim/undo', meths.get_option('undodir'))
eq('$XDG_CONFIG_HOME/nvim/view', meths.get_option('viewdir'))
end)
end)
describe('with commas', function()
before_each(function()
clear({env={
XDG_CONFIG_HOME=', , ,',
XDG_CONFIG_DIRS=',-,-,:-,-,-',
XDG_DATA_HOME=',=,=,',
XDG_DATA_DIRS=',≡,≡,:≡,≡,≡',
}})
end)
it('are escaped properly', function()
eq(('\\, \\, \\,/nvim'
.. ',\\,-\\,-\\,/nvim'
.. ',-\\,-\\,-/nvim'
.. ',\\,=\\,=\\,/nvim/site'
.. ',\\,≡\\,≡\\,/nvim/site'
.. ',≡\\,≡\\,≡/nvim/site'
.. ',' .. eval('$VIMRUNTIME')
.. ',≡\\,≡\\,≡/nvim/site/after'
.. ',\\,≡\\,≡\\,/nvim/site/after'
.. ',\\,=\\,=\\,/nvim/site/after'
.. ',-\\,-\\,-/nvim/after'
.. ',\\,-\\,-\\,/nvim/after'
.. ',\\, \\, \\,/nvim/after'
), meths.get_option('runtimepath'))
meths.command('set runtimepath&')
meths.command('set backupdir&')
meths.command('set directory&')
meths.command('set undodir&')
meths.command('set viewdir&')
eq(('\\, \\, \\,/nvim'
.. ',\\,-\\,-\\,/nvim'
.. ',-\\,-\\,-/nvim'
.. ',\\,=\\,=\\,/nvim/site'
.. ',\\,≡\\,≡\\,/nvim/site'
.. ',≡\\,≡\\,≡/nvim/site'
.. ',' .. eval('$VIMRUNTIME')
.. ',≡\\,≡\\,≡/nvim/site/after'
.. ',\\,≡\\,≡\\,/nvim/site/after'
.. ',\\,=\\,=\\,/nvim/site/after'
.. ',-\\,-\\,-/nvim/after'
.. ',\\,-\\,-\\,/nvim/after'
.. ',\\, \\, \\,/nvim/after'
), meths.get_option('runtimepath'))
eq('.,\\,=\\,=\\,/nvim/backup', meths.get_option('backupdir'))
eq('\\,=\\,=\\,/nvim/swap//', meths.get_option('directory'))
eq('\\,=\\,=\\,/nvim/undo', meths.get_option('undodir'))
eq('\\,=\\,=\\,/nvim/view', meths.get_option('viewdir'))
end)
end)
end)
|