2024-04-20 17:44:13 +02:00
|
|
|
local t = require('test.testutil')
|
|
|
|
|
local n = require('test.functional.testnvim')()
|
2016-09-04 18:40:19 +03:00
|
|
|
|
2024-04-08 11:03:20 +02:00
|
|
|
local eq = t.eq
|
2024-04-20 17:44:13 +02:00
|
|
|
local eval = n.eval
|
|
|
|
|
local command = n.command
|
|
|
|
|
local clear = n.clear
|
|
|
|
|
local fn = n.fn
|
2024-04-08 11:03:20 +02:00
|
|
|
local pcall_err = t.pcall_err
|
2016-09-04 18:40:19 +03:00
|
|
|
|
|
|
|
|
before_each(clear)
|
|
|
|
|
for _, func in ipairs({ 'min', 'max' }) do
|
|
|
|
|
describe(func .. '()', function()
|
|
|
|
|
it('gives a single error message when multiple values failed conversions', function()
|
2021-09-19 02:29:37 -07:00
|
|
|
eq(
|
|
|
|
|
'Vim(echo):E745: Using a List as a Number',
|
|
|
|
|
pcall_err(command, 'echo ' .. func .. '([-5, [], [], [], 5])')
|
2024-01-03 02:09:18 +01:00
|
|
|
)
|
2021-09-19 02:29:37 -07:00
|
|
|
eq(
|
|
|
|
|
'Vim(echo):E745: Using a List as a Number',
|
|
|
|
|
pcall_err(command, 'echo ' .. func .. '({1:-5, 2:[], 3:[], 4:[], 5:5})')
|
2024-01-03 02:09:18 +01:00
|
|
|
)
|
2016-09-04 18:40:19 +03:00
|
|
|
for errmsg, errinput in pairs({
|
2021-09-19 02:29:37 -07:00
|
|
|
['Vim(echo):E745: Using a List as a Number'] = '[]',
|
|
|
|
|
['Vim(echo):E805: Using a Float as a Number'] = '0.0',
|
|
|
|
|
['Vim(echo):E703: Using a Funcref as a Number'] = 'function("tr")',
|
|
|
|
|
['Vim(echo):E728: Using a Dictionary as a Number'] = '{}',
|
2016-09-04 18:40:19 +03:00
|
|
|
}) do
|
2021-09-19 02:29:37 -07:00
|
|
|
eq(errmsg, pcall_err(command, 'echo ' .. func .. '([' .. errinput .. '])'))
|
|
|
|
|
eq(errmsg, pcall_err(command, 'echo ' .. func .. '({1:' .. errinput .. '})'))
|
2016-09-04 18:40:19 +03:00
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
it('works with arrays/dictionaries with zero items', function()
|
2024-01-12 17:59:57 +00:00
|
|
|
eq(0, fn[func]({}))
|
2016-09-04 18:40:19 +03:00
|
|
|
eq(0, eval(func .. '({})'))
|
|
|
|
|
end)
|
|
|
|
|
it('works with arrays/dictionaries with one item', function()
|
2024-01-12 17:59:57 +00:00
|
|
|
eq(5, fn[func]({ 5 }))
|
|
|
|
|
eq(5, fn[func]({ test = 5 }))
|
2016-09-04 18:40:19 +03:00
|
|
|
end)
|
|
|
|
|
it('works with NULL arrays/dictionaries', function()
|
|
|
|
|
eq(0, eval(func .. '(v:_null_list)'))
|
|
|
|
|
eq(0, eval(func .. '(v:_null_dict)'))
|
|
|
|
|
end)
|
|
|
|
|
it('errors out for invalid types', function()
|
|
|
|
|
for _, errinput in ipairs({
|
|
|
|
|
'1',
|
|
|
|
|
'v:true',
|
|
|
|
|
'v:false',
|
|
|
|
|
'v:null',
|
|
|
|
|
'function("tr")',
|
|
|
|
|
'""',
|
|
|
|
|
}) do
|
2021-09-19 02:29:37 -07:00
|
|
|
eq(
|
|
|
|
|
('Vim(echo):E712: Argument of %s() must be a List or Dictionary'):format(func),
|
|
|
|
|
pcall_err(command, 'echo ' .. func .. '(' .. errinput .. ')')
|
2024-01-03 02:09:18 +01:00
|
|
|
)
|
2016-09-04 18:40:19 +03:00
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end)
|
|
|
|
|
end
|