robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- Tests for :setlocal and :setglobal 2 3local t =require ( 'test.testutil' ) 4local n =require ( 'test.functional.testnvim' )() 5 6local describe , it , before_each =t . describe , t . it , t . before_each 7local clear , command , eval , eq , api =n . clear , n . command , n . eval , t . eq , n . api 8local matches , pcall_err =t . matches , t . pcall_err 9 10local function should_fail ( opt , value , errmsg ) 11matches ( errmsg .. ':' , pcall_err ( command , 'setglobal ' .. opt .. '=' .. value )) 12matches ( errmsg .. ':' , pcall_err ( command , 'setlocal ' .. opt .. '=' .. value )) 13matches ( errmsg .. ':' , pcall_err ( api . nvim_set_option_value , opt , value , {} )) 14end 15 16local function should_succeed ( opt , value ) 17command ( 'setglobal ' .. opt .. '=' .. value ) 18command ( 'setlocal ' .. opt .. '=' .. value ) 19api . nvim_set_option_value ( opt , value , {} ) 20eq ( value , api . nvim_get_option_value ( opt , {} )) 21end 22 23describe ( ':setlocal' , function () 24before_each ( clear ) 25 26it ( 'setlocal sets only local value' , function () 27eq ( 0 , api . nvim_get_option_value ( 'iminsert' , { scope ='global' } )) 28command ( 'setlocal iminsert=1' ) 29eq ( 0 , api . nvim_get_option_value ( 'iminsert' , { scope ='global' } )) 30eq ( - 1 , api . nvim_get_option_value ( 'imsearch' , { scope ='global' } )) 31command ( 'setlocal imsearch=1' ) 32eq ( - 1 , api . nvim_get_option_value ( 'imsearch' , { scope ='global' } )) 33end ) 34end ) 35 36describe ( ':set validation' , function () 37before_each ( clear ) 38 39it ( 'setlocal and setglobal validate values' , function () 40should_fail ( 'shiftwidth' , - 10 , 'E487' ) 41should_succeed ( 'shiftwidth' , 0 ) 42should_fail ( 'tabstop' , - 10 , 'E487' ) 43should_fail ( 'winheight' , - 10 , 'E487' ) 44should_fail ( 'winheight' , 0 , 'E487' ) 45should_fail ( 'winminheight' , - 1 , 'E487' ) 46should_succeed ( 'winminheight' , 0 ) 47should_fail ( 'winwidth' , 0 , 'E487' ) 48should_fail ( 'helpheight' , - 1 , 'E487' ) 49should_fail ( 'iminsert' , 3 , 'E474' ) 50should_fail ( 'imsearch' , 3 , 'E474' ) 51should_fail ( 'titlelen' , - 1 , 'E487' ) 52should_fail ( 'cmdheight' , - 1 , 'E487' ) 53should_fail ( 'updatecount' , - 1 , 'E487' ) 54should_fail ( 'textwidth' , - 1 , 'E487' ) 55should_fail ( 'tabstop' , 0 , 'E487' ) 56should_fail ( 'timeoutlen' , - 1 , 'E487' ) 57should_fail ( 'history' , 1000000 , 'E474' ) 58should_fail ( 'regexpengine' , - 1 , 'E474' ) 59should_fail ( 'regexpengine' , 3 , 'E474' ) 60should_succeed ( 'regexpengine' , 2 ) 61should_fail ( 'report' , - 1 , 'E487' ) 62should_succeed ( 'report' , 0 ) 63should_fail ( 'sidescroll' , - 1 , 'E487' ) 64should_fail ( 'cmdwinheight' , 0 , 'E487' ) 65should_fail ( 'updatetime' , - 1 , 'E487' ) 66 67should_fail ( 'foldlevel' , - 5 , 'E487' ) 68should_fail ( 'foldcolumn' , '13' , 'E474' ) 69should_fail ( 'conceallevel' , 4 , 'E474' ) 70should_fail ( 'numberwidth' , 21 , 'E474' ) 71should_fail ( 'numberwidth' , 0 , 'E487' ) 72 73-- If smaller than 1 this one is set to 'lines'-1 74command ( 'setglobal window=-10' ) 75api . nvim_set_option_value ( 'window' , - 10 , {} ) 76eq ( 23 , api . nvim_get_option_value ( 'window' , {} )) 77eq ( '' , eval ( 'v:errmsg' )) 78 79-- 'scrolloff' and 'sidescrolloff' can have a -1 value when 80-- set for the current window, but not globally 81matches ( 'E487:' , pcall_err ( command , 'setglobal scrolloff=-1' )) 82matches ( 'E487:' , pcall_err ( command , 'setglobal sidescrolloff=-1' )) 83 84eq ( true , pcall ( command , 'setlocal scrolloff=-1' )) 85eq ( true , pcall ( command , 'setlocal sidescrolloff=-1' )) 86end ) 87 88it ( 'set wmh/wh wmw/wiw checks' , function () 89command ( 'set winheight=2' ) 90matches ( 'E591:' , pcall_err ( command , 'set winminheight=3' )) 91 92command ( 'set winwidth=2' ) 93matches ( 'E592:' , pcall_err ( command , 'set winminwidth=3' )) 94end ) 95 96it ( 'set maxcombine resets to 6' , function () 97local function setto ( value ) 98command ( 'setglobal maxcombine=' .. value ) 99command ( 'setlocal maxcombine=' .. value ) 100api . nvim_set_option_value ( 'maxcombine' , value , {} ) 101eq ( 6 , api . nvim_get_option_value ( 'maxcombine' , {} )) 102eq ( '' , eval ( 'v:errmsg' )) 103end 104setto ( 0 ) 105setto ( 1 ) 106setto ( 6 ) 107setto ( 7 ) 108end ) 109end )