robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3 4local describe , it , setup =t . describe , t . it , t . setup 5local eq =t . eq 6local eval =n . eval 7local command =n . command 8local clear =n . clear 9local fn =n . fn 10local pcall_err =t . pcall_err 11 12setup ( clear ) 13for _ , func in ipairs ( { 'min' , 'max' } ) do 14describe ( func .. '()' , function () 15it ( 'gives a single error message when multiple values failed conversions' , function () 16eq ( 17'Vim(echo):E745: Using a List as a Number' , 18pcall_err ( command , 'echo ' .. func .. '([-5, [], [], [], 5])' ) 19) 20eq ( 21'Vim(echo):E745: Using a List as a Number' , 22pcall_err ( command , 'echo ' .. func .. '({1:-5, 2:[], 3:[], 4:[], 5:5})' ) 23) 24for errmsg , errinput in pairs ( { 25[ 'Vim(echo):E745: Using a List as a Number' ] ='[]' , 26[ 'Vim(echo):E805: Using a Float as a Number' ] ='0.0' , 27[ 'Vim(echo):E703: Using a Funcref as a Number' ] ='function("tr")' , 28[ 'Vim(echo):E728: Using a Dictionary as a Number' ] ='{}' , 29} ) do 30eq ( errmsg , pcall_err ( command , 'echo ' .. func .. '([' .. errinput .. '])' )) 31eq ( errmsg , pcall_err ( command , 'echo ' .. func .. '({1:' .. errinput .. '})' )) 32end 33end ) 34it ( 'works with arrays/dictionaries with zero items' , function () 35eq ( 0 , fn [ func ]( {} )) 36eq ( 0 , eval ( func .. '({})' )) 37end ) 38it ( 'works with arrays/dictionaries with one item' , function () 39eq ( 5 , fn [ func ]( { 5 } )) 40eq ( 5 , fn [ func ]( { test =5 } )) 41end ) 42it ( 'works with NULL arrays/dictionaries' , function () 43eq ( 0 , eval ( func .. '(v:_null_list)' )) 44eq ( 0 , eval ( func .. '(v:_null_dict)' )) 45end ) 46it ( 'errors out for invalid types' , function () 47for _ , errinput in ipairs ( { 48'1' , 49'v:true' , 50'v:false' , 51'v:null' , 52'function("tr")' , 53'""' , 54} ) do 55eq ( 56( 'Vim(echo):E712: Argument of %s() must be a List or Dictionary' ): format ( func ), 57pcall_err ( command , 'echo ' .. func .. '(' .. errinput .. ')' ) 58) 59end 60end ) 61end ) 62end