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 , before_each =t . describe , t . it , t . before_each 5local clear , eq , neq , eval =n . clear , t . eq , t . neq , n . eval 6local api =n . api 7local curbuf =n . api . nvim_get_current_buf 8local curwin =n . api . nvim_get_current_win 9local exec_capture =n . exec_capture 10local source , command =n . source , n . command 11 12local function declare_hook_function () 13source ( [[ 14fu! AutoCommand(match, bufnr, winnr) 15let l:acc = { 16\ 'option' : a:match, 17\ 'oldval' : v:option_old, 18\ 'oldval_l' : v:option_oldlocal, 19\ 'oldval_g' : v:option_oldglobal, 20\ 'newval' : v:option_new, 21\ 'scope' : v:option_type, 22\ 'cmd' : v:option_command, 23\ 'attr' : { 24\ 'bufnr' : a:bufnr, 25\ 'winnr' : a:winnr, 26\ } 27\ } 28call add(g:ret, l:acc) 29endfu 30]] ) 31end 32 33local function set_hook ( pattern ) 34command ( 35'au OptionSet ' .. pattern .. ' :call AutoCommand(expand("<amatch>"), bufnr("%"), winnr())' 36) 37end 38 39local function init_var () 40command ( 'let g:ret = []' ) 41end 42 43local function get_result () 44local ret =api . nvim_get_var ( 'ret' ) 45init_var () 46return ret 47end 48 49local function expected_table ( option , oldval , oldval_l , oldval_g , newval , scope , cmd , attr ) 50return { 51option =option , 52oldval =oldval , 53oldval_l =oldval_l , 54oldval_g =oldval_g , 55newval =newval , 56scope =scope , 57cmd =cmd , 58attr =attr , 59} 60end 61 62local function expected_combination ( ... ) 63local args ={ ... } 64local ret =get_result () 65 66if not ( # args == # ret ) then 67local expecteds ={} 68for _ , v in pairs ( args ) do 69table . insert ( expecteds , expected_table ( unpack ( v ))) 70end 71eq ( expecteds , ret ) 72return 73end 74 75for i , v in ipairs ( args ) do 76local attr =v [ 8 ] 77if not attr then 78-- remove attr entries 79ret [ i ]. attr =nil 80else 81-- remove attr entries which are not required 82for k in pairs ( ret [ i ]. attr ) do 83if not attr [ k ] then 84ret [ i ]. attr [ k ] =nil 85end 86end 87end 88eq ( expected_table ( unpack ( v )), ret [ i ]) 89end 90end 91 92local function expected_empty () 93eq ( {} , get_result ()) 94end 95 96local function make_buffer () 97local old_buf =curbuf () 98command ( 'botright new' ) 99local new_buf =curbuf () 100command ( 'wincmd p' ) -- move previous window 101 102neq ( old_buf , new_buf ) 103eq ( old_buf , curbuf ()) 104 105return new_buf 106end 107 108local function get_new_window_number () 109local old_win =curwin () 110command ( 'botright new' ) 111local new_win =curwin () 112local new_winnr =exec_capture ( 'echo winnr()' ) 113command ( 'wincmd p' ) -- move previous window 114 115neq ( old_win , new_win ) 116eq ( old_win , curwin ()) 117 118return new_winnr 119end 120 121describe ( 'au OptionSet' , function () 122describe ( 'with any option (*)' , function () 123before_each ( function () 124clear () 125declare_hook_function () 126init_var () 127set_hook ( '*' ) 128end ) 129 130it ( 'should be called in setting number option' , function () 131command ( 'set nu' ) 132expected_combination ( { 'number' , false , false , false , true , 'global' , 'set' } ) 133 134command ( 'setlocal nonu' ) 135expected_combination ( { 'number' , true , true , '' , false , 'local' , 'setlocal' } ) 136 137command ( 'setglobal nonu' ) 138expected_combination ( { 'number' , true , '' , true , false , 'global' , 'setglobal' } ) 139end ) 140 141it ( 'should be called in setting autoindent option' , function () 142command ( 'setlocal ai' ) 143expected_combination ( { 'autoindent' , false , false , '' , true , 'local' , 'setlocal' } ) 144 145command ( 'setglobal ai' ) 146expected_combination ( { 'autoindent' , false , '' , false , true , 'global' , 'setglobal' } ) 147 148command ( 'set noai' ) 149expected_combination ( { 'autoindent' , true , true , true , false , 'global' , 'set' } ) 150end ) 151 152it ( 'should be called in inverting global autoindent option' , function () 153command ( 'set ai!' ) 154expected_combination ( { 'autoindent' , false , false , false , true , 'global' , 'set' } ) 155end ) 156 157it ( 'should be called in being unset local autoindent option' , function () 158command ( 'setlocal ai' ) 159expected_combination ( { 'autoindent' , false , false , '' , true , 'local' , 'setlocal' } ) 160 161command ( 'setlocal ai<' ) 162expected_combination ( { 'autoindent' , true , true , '' , false , 'local' , 'setlocal' } ) 163end ) 164 165it ( 'should be called in setting global list and number option at the same time' , function () 166command ( 'set list nu' ) 167expected_combination ( 168{ 'list' , false , false , false , true , 'global' , 'set' } , 169{ 'number' , false , false , false , true , 'global' , 'set' } 170) 171end ) 172 173it ( 'should not print anything, use :noa' , function () 174command ( 'noa set nolist nonu' ) 175expected_empty () 176end ) 177 178it ( 'should be called in setting local acd' , function () 179command ( 'setlocal acd' ) 180expected_combination ( { 'autochdir' , false , false , '' , true , 'local' , 'setlocal' } ) 181end ) 182 183it ( 'should be called in setting autoread' , function () 184command ( 'set noar' ) 185expected_combination ( { 'autoread' , true , true , true , false , 'global' , 'set' } ) 186 187command ( 'setlocal ar' ) 188expected_combination ( { 'autoread' , false , false , '' , true , 'local' , 'setlocal' } ) 189end ) 190 191it ( 'should be called in inverting global autoread' , function () 192command ( 'setglobal invar' ) 193expected_combination ( { 'autoread' , true , '' , true , false , 'global' , 'setglobal' } ) 194end ) 195 196it ( 'should be called in setting backspace option through :let' , function () 197local oldval =eval ( '&backspace' ) 198 199command ( 'let &bs=""' ) 200expected_combination ( { 'backspace' , oldval , oldval , oldval , '' , 'global' , 'set' } ) 201end ) 202 203describe ( 'being set by setbufvar()' , function () 204it ( 'should not trigger because option name is invalid' , function () 205command ( 'silent! call setbufvar(1, "&l:bk", 1)' ) 206expected_empty () 207end ) 208 209it ( 'should trigger using correct option name' , function () 210command ( 'call setbufvar(1, "&backup", 1)' ) 211expected_combination ( { 'backup' , false , false , '' , true , 'local' , 'setlocal' } ) 212end ) 213 214it ( 'should trigger if the current buffer is different from the targeted buffer' , function () 215local new_buffer =make_buffer () 216local new_bufnr =api . nvim_buf_get_number ( new_buffer ) 217 218command ( 'call setbufvar(' .. new_bufnr .. ', "&buftype", "nofile")' ) 219expected_combination ( { 220'buftype' , 221'' , 222'' , 223'' , 224'nofile' , 225'local' , 226'setlocal' , 227{ bufnr =new_bufnr } , 228} ) 229end ) 230end ) 231 232it ( 'with string global option' , function () 233local oldval =eval ( '&backupext' ) 234 235command ( 'set backupext=foo' ) 236expected_combination ( { 'backupext' , oldval , oldval , oldval , 'foo' , 'global' , 'set' } ) 237 238command ( 'set backupext&' ) 239expected_combination ( { 'backupext' , 'foo' , 'foo' , 'foo' , oldval , 'global' , 'set' } ) 240 241command ( 'setglobal backupext=bar' ) 242expected_combination ( { 'backupext' , oldval , '' , oldval , 'bar' , 'global' , 'setglobal' } ) 243 244command ( 'noa set backupext&' ) 245-- As this is a global option this sets the global value even though :setlocal is used! 246command ( 'setlocal backupext=baz' ) 247expected_combination ( { 'backupext' , oldval , oldval , '' , 'baz' , 'local' , 'setlocal' } ) 248 249command ( 'noa setglobal backupext=ext_global' ) 250command ( 'noa setlocal backupext=ext_local' ) -- Sets the global(!) value 251command ( 'set backupext=foo' ) 252expected_combination ( { 253'backupext' , 254'ext_local' , 255'ext_local' , 256'ext_local' , 257'foo' , 258'global' , 259'set' , 260} ) 261end ) 262 263it ( 'with string global-local (to buffer) option' , function () 264local oldval =eval ( '&tags' ) 265 266command ( 'set tags=tagpath' ) 267expected_combination ( { 'tags' , oldval , oldval , oldval , 'tagpath' , 'global' , 'set' } ) 268 269command ( 'set tags&' ) 270expected_combination ( { 'tags' , 'tagpath' , 'tagpath' , 'tagpath' , oldval , 'global' , 'set' } ) 271 272command ( 'setglobal tags=tagpath1' ) 273expected_combination ( { 'tags' , oldval , '' , oldval , 'tagpath1' , 'global' , 'setglobal' } ) 274 275command ( 'setlocal tags=tagpath2' ) 276expected_combination ( { 'tags' , 'tagpath1' , 'tagpath1' , '' , 'tagpath2' , 'local' , 'setlocal' } ) 277 278-- Note: v:option_old is the old global value for global-local options. 279-- but the old local value for all other kinds of options. 280command ( 'noa setglobal tags=tag_global' ) 281command ( 'noa setlocal tags=tag_local' ) 282command ( 'set tags=tagpath' ) 283expected_combination ( { 284'tags' , 285'tag_global' , 286'tag_local' , 287'tag_global' , 288'tagpath' , 289'global' , 290'set' , 291} ) 292 293-- Note: v:option_old is the old global value for global-local options. 294-- but the old local value for all other kinds of options. 295command ( 'noa set tags=tag_global' ) 296command ( 'noa setlocal tags=' ) 297command ( 'set tags=tagpath' ) 298expected_combination ( { 299'tags' , 300'tag_global' , 301'tag_global' , 302'tag_global' , 303'tagpath' , 304'global' , 305'set' , 306} ) 307end ) 308 309it ( 'with string local (to buffer) option' , function () 310local oldval =eval ( '&spelllang' ) 311 312command ( 'set spelllang=elvish,klingon' ) 313expected_combination ( { 314'spelllang' , 315oldval , 316oldval , 317oldval , 318'elvish,klingon' , 319'global' , 320'set' , 321} ) 322 323command ( 'set spelllang&' ) 324expected_combination ( { 325'spelllang' , 326'elvish,klingon' , 327'elvish,klingon' , 328'elvish,klingon' , 329oldval , 330'global' , 331'set' , 332} ) 333 334command ( 'setglobal spelllang=elvish' ) 335expected_combination ( { 'spelllang' , oldval , '' , oldval , 'elvish' , 'global' , 'setglobal' } ) 336 337command ( 'noa set spelllang&' ) 338command ( 'setlocal spelllang=klingon' ) 339expected_combination ( { 'spelllang' , oldval , oldval , '' , 'klingon' , 'local' , 'setlocal' } ) 340 341-- Note: v:option_old is the old global value for global-local options. 342-- but the old local value for all other kinds of options. 343command ( 'noa setglobal spelllang=spellglobal' ) 344command ( 'noa setlocal spelllang=spelllocal' ) 345command ( 'set spelllang=foo' ) 346expected_combination ( { 347'spelllang' , 348'spelllocal' , 349'spelllocal' , 350'spellglobal' , 351'foo' , 352'global' , 353'set' , 354} ) 355end ) 356 357it ( 'with string global-local (to window) option' , function () 358local oldval =eval ( '&statusline' ) 359local default_statusline =api . nvim_get_option_info2 ( 'statusline' , {} ). default 360 361command ( 'set statusline=foo' ) 362expected_combination ( { 363'statusline' , 364oldval , 365oldval , 366oldval , 367'foo' , 368'global' , 369'set' , 370} ) 371 372-- Note: v:option_old is the old global value for global-local options. 373-- but the old local value for all other kinds of options. 374command ( 'set statusline&' ) 375expected_combination ( { 376'statusline' , 377'foo' , 378'foo' , 379'foo' , 380default_statusline , 381'global' , 382'set' , 383} ) 384 385command ( 'setglobal statusline=bar' ) 386expected_combination ( { 387'statusline' , 388default_statusline , 389'' , 390default_statusline , 391'bar' , 392'global' , 393'setglobal' , 394} ) 395 396command ( 'noa set statusline&' ) 397command ( 'setlocal statusline=baz' ) 398expected_combination ( { 399'statusline' , 400default_statusline , 401default_statusline , 402'' , 403'baz' , 404'local' , 405'setlocal' , 406} ) 407 408-- Note: v:option_old is the old global value for global-local options. 409-- but the old local value for all other kinds of options. 410command ( 'noa setglobal statusline=bar' ) 411command ( 'noa setlocal statusline=baz' ) 412command ( 'set statusline=foo' ) 413expected_combination ( { 'statusline' , 'bar' , 'baz' , 'bar' , 'foo' , 'global' , 'set' } ) 414end ) 415 416it ( 'with string local (to window) option' , function () 417local oldval =eval ( '&foldignore' ) 418 419command ( 'set foldignore=fo' ) 420expected_combination ( { 'foldignore' , oldval , oldval , oldval , 'fo' , 'global' , 'set' } ) 421 422command ( 'set foldignore&' ) 423expected_combination ( { 'foldignore' , 'fo' , 'fo' , 'fo' , oldval , 'global' , 'set' } ) 424 425command ( 'setglobal foldignore=bar' ) 426expected_combination ( { 'foldignore' , oldval , '' , oldval , 'bar' , 'global' , 'setglobal' } ) 427 428command ( 'noa set foldignore&' ) 429command ( 'setlocal foldignore=baz' ) 430expected_combination ( { 'foldignore' , oldval , oldval , '' , 'baz' , 'local' , 'setlocal' } ) 431 432command ( 'noa setglobal foldignore=glob' ) 433command ( 'noa setlocal foldignore=loc' ) 434command ( 'set foldignore=fo' ) 435expected_combination ( { 'foldignore' , 'loc' , 'loc' , 'glob' , 'fo' , 'global' , 'set' } ) 436end ) 437 438it ( 'with number global option' , function () 439command ( 'noa setglobal cmdheight=8' ) 440command ( 'noa setlocal cmdheight=1' ) -- Sets the global(!) value 441command ( 'setglobal cmdheight=2' ) 442expected_combination ( { 'cmdheight' , 1 , '' , 1 , 2 , 'global' , 'setglobal' } ) 443 444command ( 'noa setglobal cmdheight=8' ) 445command ( 'noa setlocal cmdheight=1' ) -- Sets the global(!) value 446command ( 'setlocal cmdheight=2' ) 447expected_combination ( { 'cmdheight' , 1 , 1 , '' , 2 , 'local' , 'setlocal' } ) 448 449-- Note: v:option_old is the old global value for global-local options. 450-- but the old local value for all other kinds of options. 451command ( 'noa setglobal cmdheight=8' ) 452command ( 'noa setlocal cmdheight=1' ) -- Sets the global(!) value 453command ( 'set cmdheight=2' ) 454expected_combination ( { 'cmdheight' , 1 , 1 , 1 , 2 , 'global' , 'set' } ) 455 456-- Note: v:option_old is the old global value for global-local options. 457-- but the old local value for all other kinds of options. 458command ( 'noa set cmdheight=8' ) 459command ( 'set cmdheight=2' ) 460expected_combination ( { 'cmdheight' , 8 , 8 , 8 , 2 , 'global' , 'set' } ) 461end ) 462 463it ( 'with number global-local (to buffer) option' , function () 464command ( 'noa setglobal undolevels=8' ) 465command ( 'noa setlocal undolevels=1' ) 466command ( 'setglobal undolevels=2' ) 467expected_combination ( { 'undolevels' , 8 , '' , 8 , 2 , 'global' , 'setglobal' } ) 468 469command ( 'noa setglobal undolevels=8' ) 470command ( 'noa setlocal undolevels=1' ) 471command ( 'setlocal undolevels=2' ) 472expected_combination ( { 'undolevels' , 1 , 1 , '' , 2 , 'local' , 'setlocal' } ) 473 474-- Note: v:option_old is the old global value for global-local options. 475-- but the old local value for all other kinds of options. 476command ( 'noa setglobal undolevels=8' ) 477command ( 'noa setlocal undolevels=1' ) 478command ( 'set undolevels=2' ) 479expected_combination ( { 'undolevels' , 8 , 1 , 8 , 2 , 'global' , 'set' } ) 480 481-- Note: v:option_old is the old global value for global-local options. 482-- but the old local value for all other kinds of options. 483command ( 'noa set undolevels=8' ) 484command ( 'set undolevels=2' ) 485expected_combination ( { 'undolevels' , 8 , 8 , 8 , 2 , 'global' , 'set' } ) 486end ) 487 488it ( 'with number local (to buffer) option' , function () 489command ( 'noa setglobal wrapmargin=8' ) 490command ( 'noa setlocal wrapmargin=1' ) 491command ( 'setglobal wrapmargin=2' ) 492expected_combination ( { 'wrapmargin' , 8 , '' , 8 , 2 , 'global' , 'setglobal' } ) 493 494command ( 'noa setglobal wrapmargin=8' ) 495command ( 'noa setlocal wrapmargin=1' ) 496command ( 'setlocal wrapmargin=2' ) 497expected_combination ( { 'wrapmargin' , 1 , 1 , '' , 2 , 'local' , 'setlocal' } ) 498 499command ( 'noa setglobal wrapmargin=8' ) 500command ( 'noa setlocal wrapmargin=1' ) 501command ( 'set wrapmargin=2' ) 502expected_combination ( { 'wrapmargin' , 1 , 1 , 8 , 2 , 'global' , 'set' } ) 503 504command ( 'noa set wrapmargin=8' ) 505command ( 'set wrapmargin=2' ) 506expected_combination ( { 'wrapmargin' , 8 , 8 , 8 , 2 , 'global' , 'set' } ) 507end ) 508 509it ( 'with number global-local (to window) option' , function () 510command ( 'noa setglobal scrolloff=8' ) 511command ( 'noa setlocal scrolloff=1' ) 512command ( 'setglobal scrolloff=2' ) 513expected_combination ( { 'scrolloff' , 8 , '' , 8 , 2 , 'global' , 'setglobal' } ) 514 515command ( 'noa setglobal scrolloff=8' ) 516command ( 'noa setlocal scrolloff=1' ) 517command ( 'setlocal scrolloff=2' ) 518expected_combination ( { 'scrolloff' , 1 , 1 , '' , 2 , 'local' , 'setlocal' } ) 519 520-- Note: v:option_old is the old global value for global-local options. 521-- but the old local value for all other kinds of options. 522command ( 'noa setglobal scrolloff=8' ) 523command ( 'noa setlocal scrolloff=1' ) 524command ( 'set scrolloff=2' ) 525expected_combination ( { 'scrolloff' , 8 , 1 , 8 , 2 , 'global' , 'set' } ) 526 527-- Note: v:option_old is the old global value for global-local options. 528-- but the old local value for all other kinds of options. 529command ( 'noa set scrolloff=8' ) 530command ( 'set scrolloff=2' ) 531expected_combination ( { 'scrolloff' , 8 , 8 , 8 , 2 , 'global' , 'set' } ) 532end ) 533 534it ( 'with number local (to window) option' , function () 535command ( 'noa setglobal foldcolumn=8' ) 536command ( 'noa setlocal foldcolumn=1' ) 537command ( 'setglobal foldcolumn=2' ) 538expected_combination ( { 'foldcolumn' , '8' , '' , '8' , '2' , 'global' , 'setglobal' } ) 539 540command ( 'noa setglobal foldcolumn=8' ) 541command ( 'noa setlocal foldcolumn=1' ) 542command ( 'setlocal foldcolumn=2' ) 543expected_combination ( { 'foldcolumn' , '1' , '1' , '' , '2' , 'local' , 'setlocal' } ) 544 545command ( 'noa setglobal foldcolumn=8' ) 546command ( 'noa setlocal foldcolumn=1' ) 547command ( 'set foldcolumn=2' ) 548expected_combination ( { 'foldcolumn' , '1' , '1' , '8' , '2' , 'global' , 'set' } ) 549 550command ( 'noa set foldcolumn=8' ) 551command ( 'set foldcolumn=2' ) 552expected_combination ( { 'foldcolumn' , '8' , '8' , '8' , '2' , 'global' , 'set' } ) 553end ) 554 555it ( 'with boolean global option' , function () 556command ( 'noa setglobal nowrapscan' ) 557command ( 'noa setlocal wrapscan' ) -- Sets the global(!) value 558command ( 'setglobal nowrapscan' ) 559expected_combination ( { 'wrapscan' , true , '' , true , false , 'global' , 'setglobal' } ) 560 561command ( 'noa setglobal nowrapscan' ) 562command ( 'noa setlocal wrapscan' ) -- Sets the global(!) value 563command ( 'setlocal nowrapscan' ) 564expected_combination ( { 'wrapscan' , true , true , '' , false , 'local' , 'setlocal' } ) 565 566command ( 'noa setglobal nowrapscan' ) 567command ( 'noa setlocal wrapscan' ) -- Sets the global(!) value 568command ( 'set nowrapscan' ) 569expected_combination ( { 'wrapscan' , true , true , true , false , 'global' , 'set' } ) 570 571command ( 'noa set nowrapscan' ) 572command ( 'set wrapscan' ) 573expected_combination ( { 'wrapscan' , false , false , false , true , 'global' , 'set' } ) 574end ) 575 576it ( 'with boolean global-local (to buffer) option' , function () 577command ( 'noa setglobal noautoread' ) 578command ( 'noa setlocal autoread' ) 579command ( 'setglobal autoread' ) 580expected_combination ( { 'autoread' , false , '' , false , true , 'global' , 'setglobal' } ) 581 582command ( 'noa setglobal noautoread' ) 583command ( 'noa setlocal autoread' ) 584command ( 'setlocal noautoread' ) 585expected_combination ( { 'autoread' , true , true , '' , false , 'local' , 'setlocal' } ) 586 587-- Note: v:option_old is the old global value for global-local options. 588-- but the old local value for all other kinds of options. 589command ( 'noa setglobal noautoread' ) 590command ( 'noa setlocal autoread' ) 591command ( 'set autoread' ) 592expected_combination ( { 'autoread' , false , true , false , true , 'global' , 'set' } ) 593 594-- Note: v:option_old is the old global value for global-local options. 595-- but the old local value for all other kinds of options. 596command ( 'noa set noautoread' ) 597command ( 'set autoread' ) 598expected_combination ( { 'autoread' , false , false , false , true , 'global' , 'set' } ) 599end ) 600 601it ( 'with boolean local (to buffer) option' , function () 602command ( 'noa setglobal nocindent' ) 603command ( 'noa setlocal cindent' ) 604command ( 'setglobal cindent' ) 605expected_combination ( { 'cindent' , false , '' , false , true , 'global' , 'setglobal' } ) 606 607command ( 'noa setglobal nocindent' ) 608command ( 'noa setlocal cindent' ) 609command ( 'setlocal nocindent' ) 610expected_combination ( { 'cindent' , true , true , '' , false , 'local' , 'setlocal' } ) 611 612command ( 'noa setglobal nocindent' ) 613command ( 'noa setlocal cindent' ) 614command ( 'set cindent' ) 615expected_combination ( { 'cindent' , true , true , false , true , 'global' , 'set' } ) 616 617command ( 'noa set nocindent' ) 618command ( 'set cindent' ) 619expected_combination ( { 'cindent' , false , false , false , true , 'global' , 'set' } ) 620end ) 621 622it ( 'with boolean local (to window) option' , function () 623command ( 'noa setglobal nocursorcolumn' ) 624command ( 'noa setlocal cursorcolumn' ) 625command ( 'setglobal cursorcolumn' ) 626expected_combination ( { 'cursorcolumn' , false , '' , false , true , 'global' , 'setglobal' } ) 627 628command ( 'noa setglobal nocursorcolumn' ) 629command ( 'noa setlocal cursorcolumn' ) 630command ( 'setlocal nocursorcolumn' ) 631expected_combination ( { 'cursorcolumn' , true , true , '' , false , 'local' , 'setlocal' } ) 632 633command ( 'noa setglobal nocursorcolumn' ) 634command ( 'noa setlocal cursorcolumn' ) 635command ( 'set cursorcolumn' ) 636expected_combination ( { 'cursorcolumn' , true , true , false , true , 'global' , 'set' } ) 637 638command ( 'noa set nocursorcolumn' ) 639command ( 'set cursorcolumn' ) 640expected_combination ( { 'cursorcolumn' , false , false , false , true , 'global' , 'set' } ) 641end ) 642end ) 643 644describe ( 'with specific option' , function () 645before_each ( function () 646clear () 647declare_hook_function () 648init_var () 649end ) 650 651it ( 'should be called iff setting readonly' , function () 652set_hook ( 'readonly' ) 653 654command ( 'set nu' ) 655expected_empty () 656 657command ( 'setlocal ro' ) 658expected_combination ( { 'readonly' , false , false , '' , true , 'local' , 'setlocal' } ) 659 660command ( 'setglobal ro' ) 661expected_combination ( { 'readonly' , false , '' , false , true , 'global' , 'setglobal' } ) 662 663command ( 'set noro' ) 664expected_combination ( { 'readonly' , true , true , true , false , 'global' , 'set' } ) 665end ) 666 667describe ( 'being set by setbufvar()' , function () 668it ( 'should not trigger because option name does not match with backup' , function () 669set_hook ( 'backup' ) 670 671command ( 'silent! call setbufvar(1, "&l:bk", 1)' ) 672expected_empty () 673end ) 674 675it ( 'should trigger, use correct option name backup' , function () 676set_hook ( 'backup' ) 677 678command ( 'call setbufvar(1, "&backup", 1)' ) 679expected_combination ( { 'backup' , false , false , '' , true , 'local' , 'setlocal' } ) 680end ) 681 682it ( 'should trigger if the current buffer is different from the targeted buffer' , function () 683set_hook ( 'buftype' ) 684 685local new_buffer =make_buffer () 686local new_bufnr =api . nvim_buf_get_number ( new_buffer ) 687 688command ( 'call setbufvar(' .. new_bufnr .. ', "&buftype", "nofile")' ) 689expected_combination ( { 690'buftype' , 691'' , 692'' , 693'' , 694'nofile' , 695'local' , 696'setlocal' , 697{ bufnr =new_bufnr } , 698} ) 699end ) 700end ) 701 702describe ( 'being set by setwinvar()' , function () 703it ( 'should not trigger because option name does not match with backup' , function () 704set_hook ( 'backup' ) 705 706command ( 'silent! call setwinvar(1, "&l:bk", 1)' ) 707expected_empty () 708end ) 709 710it ( 'should trigger, use correct option name backup' , function () 711set_hook ( 'backup' ) 712 713command ( 'call setwinvar(1, "&backup", 1)' ) 714expected_combination ( { 'backup' , false , false , '' , true , 'local' , 'setlocal' } ) 715end ) 716 717it ( 718'should not trigger if the current window is different from the targeted window' , 719function () 720set_hook ( 'cursorcolumn' ) 721 722local new_winnr =get_new_window_number () 723 724command ( 'call setwinvar(' .. new_winnr .. ', "&cursorcolumn", 1)' ) 725-- expected_combination({'cursorcolumn', false, true, 'local', {winnr = new_winnr}}) 726expected_empty () 727end 728) 729end ) 730 731describe ( 'being set by neovim api' , function () 732it ( 'should trigger if a boolean option be set globally' , function () 733set_hook ( 'autochdir' ) 734 735api . nvim_set_option_value ( 'autochdir' , true , { scope ='global' } ) 736eq ( true , api . nvim_get_option_value ( 'autochdir' , { scope ='global' } )) 737expected_combination ( { 'autochdir' , false , '' , false , true , 'global' , 'setglobal' } ) 738end ) 739 740it ( 'should trigger if a number option be set globally' , function () 741set_hook ( 'cmdheight' ) 742 743api . nvim_set_option_value ( 'cmdheight' , 5 , { scope ='global' } ) 744eq ( 5 , api . nvim_get_option_value ( 'cmdheight' , { scope ='global' } )) 745expected_combination ( { 'cmdheight' , 1 , '' , 1 , 5 , 'global' , 'setglobal' } ) 746end ) 747 748it ( 'should trigger if a string option be set globally' , function () 749set_hook ( 'ambiwidth' ) 750 751api . nvim_set_option_value ( 'ambiwidth' , 'double' , { scope ='global' } ) 752eq ( 'double' , api . nvim_get_option_value ( 'ambiwidth' , { scope ='global' } )) 753expected_combination ( { 754'ambiwidth' , 755'single' , 756'' , 757'single' , 758'double' , 759'global' , 760'setglobal' , 761} ) 762end ) 763end ) 764end ) 765end )