robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
a4a544032a
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3 4local describe , it , before_each , setup , teardown = 5t . describe , t . it , t . before_each , t . setup , t . teardown 6local clear =n . clear 7local command =n . command 8local eq =t . eq 9local eval =n . eval 10local request =n . request 11local is_os =t . is_os 12 13describe ( 'autocmd DirChanged and DirChangedPre' , function () 14local curdir =t . fix_slashes ( vim . uv . cwd ()) 15local dirs ={ 16curdir .. '/Xtest-functional-autocmd-dirchanged.dir1' , 17curdir .. '/Xtest-functional-autocmd-dirchanged.dir2' , 18curdir .. '/Xtest-functional-autocmd-dirchanged.dir3' , 19curdir .. '/Xtest-functional-autocmd-dirchanged.dir4' , 20} 21-- The same directories spelled with backslashes and uppercase: on Windows (case-insensitive) 22-- filesystem) they name the same directories, so changing to them must not fire DirChanged. 23local win_dirs =vim . tbl_map ( function ( d ) 24return ( d : upper (): gsub ( '/' , '\\' )) 25end , dirs ) 26 27setup ( function () 28for _ , dir in pairs ( dirs ) do 29t . mkdir ( dir ) 30end 31end ) 32teardown ( function () 33for _ , dir in pairs ( dirs ) do 34n . rmdir ( dir ) 35end 36end ) 37 38before_each ( function () 39clear () 40command ( 41'autocmd DirChangedPre * let [g:evpre, g:amatchpre, g:cdprecount] ' 42.. '= [copy(v:event), expand("<amatch>"), 1 + get(g:, "cdprecount", 0)]' 43) 44command ( 45'autocmd DirChanged * let [g:getcwd, g:ev, g:amatch, g:cdcount] ' 46.. '= [getcwd(), copy(v:event), expand("<amatch>"), 1 + get(g:, "cdcount", 0)]' 47) 48-- Normalize path separators. 49command ( 50[[autocmd DirChangedPre * let g:evpre['directory'] = substitute(g:evpre['directory'], '\\', '/', 'g')]] 51) 52command ( [[autocmd DirChanged * let g:ev['cwd'] = substitute(g:ev['cwd'], '\\', '/', 'g')]] ) 53command ( [[autocmd DirChanged * let g:getcwd = substitute(g:getcwd, '\\', '/', 'g')]] ) 54end ) 55 56--- Runs `cmd` and asserts that it fires no DirChangedPre/DirChanged event. 57local function assert_no_event ( cmd ) 58local counts =eval ( '[g:cdprecount, g:cdcount]' ) 59command ( 'let [g:evpre, g:ev] = [{}, {}]' ) 60command ( cmd ) 61eq ( {} , eval ( 'g:evpre' )) 62eq ( {} , eval ( 'g:ev' )) 63eq ( counts , eval ( '[g:cdprecount, g:cdcount]' )) 64end 65 66it ( 'set v:event and <amatch>' , function () 67command ( 'lcd ' .. dirs [ 1 ]) 68eq ( { directory =dirs [ 1 ], scope ='window' , changed_window =false } , eval ( 'g:evpre' )) 69eq ( { cwd =dirs [ 1 ], scope ='window' , changed_window =false } , eval ( 'g:ev' )) 70eq ( 'window' , eval ( 'g:amatchpre' )) 71eq ( 'window' , eval ( 'g:amatch' )) 72eq ( 1 , eval ( 'g:cdprecount' )) 73eq ( 1 , eval ( 'g:cdcount' )) 74 75command ( 'tcd ' .. dirs [ 2 ]) 76eq ( { directory =dirs [ 2 ], scope ='tabpage' , changed_window =false } , eval ( 'g:evpre' )) 77eq ( { cwd =dirs [ 2 ], scope ='tabpage' , changed_window =false } , eval ( 'g:ev' )) 78eq ( 'tabpage' , eval ( 'g:amatchpre' )) 79eq ( 'tabpage' , eval ( 'g:amatch' )) 80eq ( 2 , eval ( 'g:cdprecount' )) 81eq ( 2 , eval ( 'g:cdcount' )) 82 83command ( 'cd ' .. dirs [ 3 ]) 84eq ( { directory =dirs [ 3 ], scope ='global' , changed_window =false } , eval ( 'g:evpre' )) 85eq ( { cwd =dirs [ 3 ], scope ='global' , changed_window =false } , eval ( 'g:ev' )) 86eq ( 'global' , eval ( 'g:amatchpre' )) 87eq ( 'global' , eval ( 'g:amatch' )) 88eq ( 3 , eval ( 'g:cdprecount' )) 89eq ( 3 , eval ( 'g:cdcount' )) 90 91command ( 'bcd ' .. dirs [ 4 ]) 92eq ( { directory =dirs [ 4 ], scope ='buffer' , changed_window =false } , eval ( 'g:evpre' )) 93eq ( { cwd =dirs [ 4 ], scope ='buffer' , changed_window =false } , eval ( 'g:ev' )) 94eq ( 'buffer' , eval ( 'g:amatchpre' )) 95eq ( 'buffer' , eval ( 'g:amatch' )) 96eq ( 4 , eval ( 'g:cdprecount' )) 97eq ( 4 , eval ( 'g:cdcount' )) 98 99-- Buffer-local dir is NOT cleared by a wider scope. 100assert_no_event ( 'lcd ' .. dirs [ 1 ]) 101assert_no_event ( 'tcd ' .. dirs [ 2 ]) 102assert_no_event ( 'cd ' .. dirs [ 3 ]) 103 104-- ":bcd!" reports the scope that becomes effective, not the one that was unset. 105-- The overridden ":cd" above still reset the window/tab scopes, so that is the global dir. 106command ( 'bcd!' ) 107eq ( { cwd =dirs [ 3 ], scope ='global' , changed_window =false } , eval ( 'g:ev' )) 108eq ( 'global' , eval ( 'g:amatch' )) 109 110-- Same for ":lcd!", landing on the tab-local dir. 111command ( 'tcd ' .. dirs [ 2 ]) 112command ( 'lcd ' .. dirs [ 1 ]) 113command ( 'lcd!' ) 114eq ( { cwd =dirs [ 2 ], scope ='tabpage' , changed_window =false } , eval ( 'g:ev' )) 115eq ( 'tabpage' , eval ( 'g:amatch' )) 116end ) 117 118it ( 'DirChanged set getcwd() during event #6260' , function () 119command ( 'lcd ' .. dirs [ 1 ]) 120eq ( dirs [ 1 ], eval ( 'g:getcwd' )) 121 122command ( 'tcd ' .. dirs [ 2 ]) 123eq ( dirs [ 2 ], eval ( 'g:getcwd' )) 124 125command ( 'cd ' .. dirs [ 3 ]) 126eq ( dirs [ 3 ], eval ( 'g:getcwd' )) 127 128command ( 'bcd ' .. dirs [ 4 ]) 129eq ( dirs [ 4 ], eval ( 'g:getcwd' )) 130end ) 131 132it ( 'disallow recursion' , function () 133command ( 'set shellslash' ) 134-- Set up a _nested_ handler. 135command ( 'autocmd DirChanged * nested lcd ' .. dirs [ 3 ]) 136command ( 'lcd ' .. dirs [ 1 ]) 137eq ( { cwd =dirs [ 1 ], scope ='window' , changed_window =false } , eval ( 'g:ev' )) 138eq ( 1 , eval ( 'g:cdcount' )) 139-- autocmd changed to dirs[3], but did NOT trigger another DirChanged. 140eq ( dirs [ 3 ], eval ( 'getcwd()' )) 141end ) 142 143it ( 'only DirChangedPre is triggered if :cd fails' , function () 144command ( 'let g:ev = {}' ) 145command ( 'let g:cdcount = 0' ) 146 147local status1 , err1 =pcall ( function () 148command ( 'lcd ' .. dirs [ 1 ] .. '/doesnotexist' ) 149end ) 150eq ( 151{ directory =dirs [ 1 ] .. '/doesnotexist' , scope ='window' , changed_window =false } , 152eval ( 'g:evpre' ) 153) 154eq ( {} , eval ( 'g:ev' )) 155eq ( 'window' , eval ( 'g:amatchpre' )) 156eq ( 1 , eval ( 'g:cdprecount' )) 157eq ( 0 , eval ( 'g:cdcount' )) 158 159local status2 , err2 =pcall ( function () 160command ( 'lcd ' .. dirs [ 2 ] .. '/doesnotexist' ) 161end ) 162eq ( 163{ directory =dirs [ 2 ] .. '/doesnotexist' , scope ='window' , changed_window =false } , 164eval ( 'g:evpre' ) 165) 166eq ( {} , eval ( 'g:ev' )) 167eq ( 'window' , eval ( 'g:amatchpre' )) 168eq ( 2 , eval ( 'g:cdprecount' )) 169eq ( 0 , eval ( 'g:cdcount' )) 170 171local status3 , err3 =pcall ( function () 172command ( 'lcd ' .. dirs [ 3 ] .. '/doesnotexist' ) 173end ) 174eq ( 175{ directory =dirs [ 3 ] .. '/doesnotexist' , scope ='window' , changed_window =false } , 176eval ( 'g:evpre' ) 177) 178eq ( {} , eval ( 'g:ev' )) 179eq ( 'window' , eval ( 'g:amatchpre' )) 180eq ( 3 , eval ( 'g:cdprecount' )) 181eq ( 0 , eval ( 'g:cdcount' )) 182 183eq ( false , status1 ) 184eq ( false , status2 ) 185eq ( false , status3 ) 186 187eq ( 'E344:' , string . match ( err1 , 'E%d*:' )) 188eq ( 'E344:' , string . match ( err2 , 'E%d*:' )) 189eq ( 'E344:' , string . match ( err3 , 'E%d*:' )) 190end ) 191 192it ( "triggered by 'autochdir'" , function () 193command ( 'set autochdir' ) 194 195command ( 'split ' .. dirs [ 1 ] .. '/foo' ) 196eq ( { directory =dirs [ 1 ], scope ='window' , changed_window =false } , eval ( 'g:evpre' )) 197eq ( { cwd =dirs [ 1 ], scope ='window' , changed_window =false } , eval ( 'g:ev' )) 198eq ( 'auto' , eval ( 'g:amatchpre' )) 199eq ( 'auto' , eval ( 'g:amatch' )) 200eq ( 1 , eval ( 'g:cdprecount' )) 201eq ( 1 , eval ( 'g:cdcount' )) 202 203command ( 'split ' .. dirs [ 2 ] .. '/bar' ) 204eq ( { directory =dirs [ 2 ], scope ='window' , changed_window =false } , eval ( 'g:evpre' )) 205eq ( { cwd =dirs [ 2 ], scope ='window' , changed_window =false } , eval ( 'g:ev' )) 206eq ( 'auto' , eval ( 'g:amatch' )) 207eq ( 2 , eval ( 'g:cdprecount' )) 208eq ( 2 , eval ( 'g:cdcount' )) 209end ) 210 211it ( 'not triggered if directory has not changed' , function () 212local scopes ={ lcd ='window' , bcd ='buffer' , tcd ='tabpage' , cd ='global' } 213-- ":bcd" last: a buffer-local dir overrides the other scopes. 214for i , cmd in ipairs ( { 'lcd' , 'tcd' , 'cd' , 'bcd' } ) do 215local scope =scopes [ cmd ] 216command (( '%s %s' ): format ( cmd , dirs [ i ])) 217eq ( { directory =dirs [ i ], scope =scope , changed_window =false } , eval ( 'g:evpre' )) 218eq ( { cwd =dirs [ i ], scope =scope , changed_window =false } , eval ( 'g:ev' )) 219eq ( scope , eval ( 'g:amatchpre' )) 220eq ( scope , eval ( 'g:amatch' )) 221eq ( i , eval ( 'g:cdprecount' )) 222eq ( i , eval ( 'g:cdcount' )) 223assert_no_event (( '%s %s' ): format ( cmd , dirs [ i ])) 224if is_os ( 'win' ) then 225assert_no_event (( '%s %s' ): format ( cmd , win_dirs [ i ])) 226end 227end 228 229command ( 'bcd!' ) -- 5th event: the global dir becomes effective again. 230command ( 'set autochdir' ) 231 232command (( 'split %s/foo' ): format ( dirs [ 2 ])) 233eq ( { directory =dirs [ 2 ], scope ='window' , changed_window =false } , eval ( 'g:evpre' )) 234eq ( { cwd =dirs [ 2 ], scope ='window' , changed_window =false } , eval ( 'g:ev' )) 235eq ( 'auto' , eval ( 'g:amatchpre' )) 236eq ( 'auto' , eval ( 'g:amatch' )) 237eq ( 6 , eval ( 'g:cdprecount' )) 238eq ( 6 , eval ( 'g:cdcount' )) 239assert_no_event (( 'split %s/bar' ): format ( dirs [ 2 ])) 240if is_os ( 'win' ) then 241assert_no_event (( 'split %s/baz' ): format ( win_dirs [ 2 ])) 242end 243end ) 244 245it ( 'triggered by switching to win/tab with different CWD #6054' , function () 246command ( 'lcd ' .. dirs [ 3 ]) -- window 3 247command ( 'split ' .. dirs [ 2 ] .. '/foo' ) -- window 2 248command ( 'lcd ' .. dirs [ 2 ]) 249command ( 'split ' .. dirs [ 1 ] .. '/bar' ) -- window 1 250command ( 'lcd ' .. dirs [ 1 ]) 251 252command ( '2wincmd w' ) -- window 2 253eq ( { directory =dirs [ 2 ], scope ='window' , changed_window =true } , eval ( 'g:evpre' )) 254eq ( { cwd =dirs [ 2 ], scope ='window' , changed_window =true } , eval ( 'g:ev' )) 255eq ( 'window' , eval ( 'g:amatchpre' )) 256eq ( 'window' , eval ( 'g:amatch' )) 257 258eq ( 4 , eval ( 'g:cdprecount' )) 259eq ( 4 , eval ( 'g:cdcount' )) 260assert_no_event ( 'tabnew' ) -- tab 2 (same CWD) 261command ( 'tcd ' .. dirs [ 3 ]) 262command ( 'tabnext' ) -- tab 1 (no tab-local CWD) 263eq ( { directory =dirs [ 2 ], scope ='window' , changed_window =true } , eval ( 'g:evpre' )) 264eq ( { cwd =dirs [ 2 ], scope ='window' , changed_window =true } , eval ( 'g:ev' )) 265eq ( 'window' , eval ( 'g:amatchpre' )) 266eq ( 'window' , eval ( 'g:amatch' )) 267command ( 'tabnext' ) -- tab 2 268eq ( { directory =dirs [ 3 ], scope ='tabpage' , changed_window =true } , eval ( 'g:evpre' )) 269eq ( { cwd =dirs [ 3 ], scope ='tabpage' , changed_window =true } , eval ( 'g:ev' )) 270eq ( 'tabpage' , eval ( 'g:amatchpre' )) 271eq ( 'tabpage' , eval ( 'g:amatch' )) 272eq ( 7 , eval ( 'g:cdprecount' )) 273eq ( 7 , eval ( 'g:cdcount' )) 274 275command ( 'tabnext' ) -- tab 1 276command ( '3wincmd w' ) -- window 3 277eq ( 9 , eval ( 'g:cdprecount' )) 278eq ( 9 , eval ( 'g:cdcount' )) 279assert_no_event ( 'tabnext' ) -- tab 2 (has the *same* CWD) 280 281if is_os ( 'win' ) then 282assert_no_event ( 'tabnew' ) -- tab 3 (same CWD) 283assert_no_event ( 'tcd ' .. win_dirs [ 3 ]) 284assert_no_event ( 'tabnext' ) -- tab 1 285assert_no_event ( 'tabprevious' ) -- tab 3 286assert_no_event ( 'tabprevious' ) -- tab 2 287assert_no_event ( 'tabprevious' ) -- tab 1 288assert_no_event ( 'lcd ' .. win_dirs [ 3 ]) -- window 3 289assert_no_event ( 'tabnext' ) -- tab 2 290assert_no_event ( 'tabnext' ) -- tab 3 291assert_no_event ( 'tabnext' ) -- tab 1 292assert_no_event ( 'tabprevious' ) -- tab 3 293end 294end ) 295 296it ( 'triggered by switching to buf/tab with different CWD' , function () 297local files ={ 298dirs [ 1 ] .. '/file' , 299dirs [ 2 ] .. '/file' , 300dirs [ 3 ] .. '/file' , 301} 302 303command ( 'e ' .. files [ 3 ]) -- buffer 3 304command ( 'e ' .. files [ 2 ]) -- buffer 2 305command ( 'e ' .. files [ 1 ]) -- buffer 1 306 307command ( 'bcd ' .. dirs [ 1 ]) 308command ( 'b ' .. files [ 2 ]) -- Switch to buffer 2 309command ( 'bcd ' .. dirs [ 2 ]) 310command ( 'b ' .. files [ 3 ]) -- Switch to buffer 3 311command ( 'bcd ' .. dirs [ 3 ]) 312 313eq ( { directory =dirs [ 3 ], scope ='buffer' , changed_window =false } , eval ( 'g:evpre' )) 314eq ( { cwd =dirs [ 3 ], scope ='buffer' , changed_window =false } , eval ( 'g:ev' )) 315eq ( 'buffer' , eval ( 'g:amatchpre' )) 316eq ( 'buffer' , eval ( 'g:amatch' )) 317 318eq ( 5 , eval ( 'g:cdprecount' )) 319eq ( 5 , eval ( 'g:cdcount' )) 320command ( 'tabnew' ) -- tab 2: its new empty buffer has no local CWD, reverts to global 321eq ( { cwd =curdir , scope ='global' , changed_window =false } , eval ( 'g:ev' )) 322eq ( 6 , eval ( 'g:cdprecount' )) 323eq ( 6 , eval ( 'g:cdcount' )) 324command ( 'tcd ' .. dirs [ 2 ]) 325command ( 'tabnext' ) -- tab 1 (no tab-local CWD) 326eq ( { directory =dirs [ 3 ], scope ='buffer' , changed_window =true } , eval ( 'g:evpre' )) 327eq ( { cwd =dirs [ 3 ], scope ='buffer' , changed_window =true } , eval ( 'g:ev' )) 328eq ( 'buffer' , eval ( 'g:amatchpre' )) 329eq ( 'buffer' , eval ( 'g:amatch' )) 330command ( 'tabnext' ) -- tab 2 331eq ( { directory =dirs [ 2 ], scope ='tabpage' , changed_window =true } , eval ( 'g:evpre' )) 332eq ( { cwd =dirs [ 2 ], scope ='tabpage' , changed_window =true } , eval ( 'g:ev' )) 333eq ( 'tabpage' , eval ( 'g:amatchpre' )) 334eq ( 'tabpage' , eval ( 'g:amatch' )) 335eq ( 9 , eval ( 'g:cdprecount' )) 336eq ( 9 , eval ( 'g:cdcount' )) 337 338command ( 'tabnext' ) -- tab 1 339command ( 'b ' .. files [ 2 ]) -- buffer 2 340eq ( 11 , eval ( 'g:cdprecount' )) 341eq ( 11 , eval ( 'g:cdcount' )) 342assert_no_event ( 'tabnext' ) -- tab 2 (has the *same* CWD) 343 344if is_os ( 'win' ) then 345assert_no_event ( 'tabnew' ) -- tab 3 (same CWD: inherits the tab-local CWD) 346assert_no_event ( 'tcd ' .. win_dirs [ 2 ]) 347assert_no_event ( 'tabnext' ) -- tab 1 348assert_no_event ( 'tabprevious' ) -- tab 3 349assert_no_event ( 'tabprevious' ) -- tab 2 350assert_no_event ( 'tabprevious' ) -- tab 1 351assert_no_event ( 'bcd ' .. win_dirs [ 2 ]) -- buffer 2 352assert_no_event ( 'tabnext' ) -- tab 2 353assert_no_event ( 'tabnext' ) -- tab 3 354assert_no_event ( 'tabnext' ) -- tab 1 355assert_no_event ( 'tabprevious' ) -- tab 3 356end 357end ) 358 359it ( 'triggered by switching to buf/win with different CWD' , function () 360command ( 'lcd ' .. dirs [ 3 ]) -- window 3 361command (( 'split %s/file' ): format ( dirs [ 2 ])) -- window 2 362command ( 'lcd ' .. dirs [ 2 ]) 363command (( 'split %s/file' ): format ( dirs [ 1 ])) -- window 1 364command ( 'lcd ' .. dirs [ 1 ]) 365 366-- All windows have a window-local CWD 367 368command ( '2wincmd w' ) -- window 2 369eq ( { directory =dirs [ 2 ], scope ='window' , changed_window =true } , eval ( 'g:evpre' )) 370eq ( { cwd =dirs [ 2 ], scope ='window' , changed_window =true } , eval ( 'g:ev' )) 371eq ( 'window' , eval ( 'g:amatchpre' )) 372eq ( 'window' , eval ( 'g:amatch' )) 373 374eq ( 4 , eval ( 'g:cdprecount' )) 375eq ( 4 , eval ( 'g:cdcount' )) 376command ( 'bcd ' .. dirs [ 1 ]) -- window 2 now has a buffer with buffer-local CWD (and no window-local CWD) 377eq ( { directory =dirs [ 1 ], scope ='buffer' , changed_window =false } , eval ( 'g:evpre' )) 378eq ( { cwd =dirs [ 1 ], scope ='buffer' , changed_window =false } , eval ( 'g:ev' )) 379eq ( 'buffer' , eval ( 'g:amatchpre' )) 380eq ( 'buffer' , eval ( 'g:amatch' )) 381eq ( 5 , eval ( 'g:cdprecount' )) 382eq ( 5 , eval ( 'g:cdcount' )) 383command ( '3wincmd w' ) -- window 3 (window-local CWD) 384eq ( 6 , eval ( 'g:cdprecount' )) 385eq ( 6 , eval ( 'g:cdcount' )) 386command ( 'bcd ' .. dirs [ 2 ]) -- window 3 now has a buffer with buffer-local CWD (and no window-local CWD) 387command ( '1wincmd w' ) -- window 1 (window-local CWD) 388eq ( { directory =dirs [ 1 ], scope ='window' , changed_window =true } , eval ( 'g:evpre' )) 389eq ( { cwd =dirs [ 1 ], scope ='window' , changed_window =true } , eval ( 'g:ev' )) 390eq ( 'window' , eval ( 'g:amatchpre' )) 391eq ( 'window' , eval ( 'g:amatch' )) 392command ( '2wincmd w' ) -- window 2 (buffer-local CWD) 393eq ( { directory =dirs [ 1 ], scope ='window' , changed_window =true } , eval ( 'g:evpre' )) -- buffer-local CWD 394eq ( { cwd =dirs [ 1 ], scope ='window' , changed_window =true } , eval ( 'g:ev' )) 395eq ( 'window' , eval ( 'g:amatchpre' )) 396eq ( 'window' , eval ( 'g:amatch' )) 397eq ( 8 , eval ( 'g:cdprecount' )) 398eq ( 8 , eval ( 'g:cdcount' )) 399 400assert_no_event ( '1wincmd w' ) -- window 1 (window-local cwd) 401-- No event: window-local CWD has higher priority than the buffer-local CWD. 402assert_no_event (( 'b %s/file' ): format ( dirs [ 2 ])) -- buffer 2 (has buffer-local cwd) 403end ) 404 405it ( 'triggered by nvim_set_current_dir()' , function () 406request ( 'nvim_set_current_dir' , dirs [ 1 ]) 407eq ( { directory =dirs [ 1 ], scope ='global' , changed_window =false } , eval ( 'g:evpre' )) 408eq ( { cwd =dirs [ 1 ], scope ='global' , changed_window =false } , eval ( 'g:ev' )) 409eq ( 1 , eval ( 'g:cdprecount' )) 410eq ( 1 , eval ( 'g:cdcount' )) 411 412request ( 'nvim_set_current_dir' , dirs [ 2 ]) 413eq ( { directory =dirs [ 2 ], scope ='global' , changed_window =false } , eval ( 'g:evpre' )) 414eq ( { cwd =dirs [ 2 ], scope ='global' , changed_window =false } , eval ( 'g:ev' )) 415eq ( 2 , eval ( 'g:cdprecount' )) 416eq ( 2 , eval ( 'g:cdcount' )) 417 418eq ( 419'Vim:E344: Can\'t find directory "/doesnotexist" in cdpath' , 420t . pcall_err ( request , 'nvim_set_current_dir' , '/doesnotexist' ) 421) 422eq ( { directory ='/doesnotexist' , scope ='global' , changed_window =false } , eval ( 'g:evpre' )) 423eq ( 3 , eval ( 'g:cdprecount' )) 424eq ( 2 , eval ( 'g:cdcount' )) 425end ) 426 427it ( 'work when local to buffer' , function () 428command ( 'let g:triggeredpre = 0' ) 429command ( 'let g:triggered = 0' ) 430command ( 'autocmd DirChangedPre <buffer> let g:triggeredpre = 1' ) 431command ( 'autocmd DirChanged <buffer> let g:triggered = 1' ) 432command ( 'cd ' .. dirs [ 1 ]) 433eq ( 1 , eval ( 'g:triggeredpre' )) 434eq ( 1 , eval ( 'g:triggered' )) 435end ) 436end )