| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830 |
- " MRU plugin unit-tests
- " MRU plugin settings
- let MRU_File='vim_mru_file'
- let MRU_Auto_Close=1
- let MRU_Max_Entries=10
- let MRU_buffer_name = '-RecentFiles-'
- " Set the $MRU_PROFILE environment variable to profile the MRU plugin
- let s:do_profile = 0
- if exists('$MRU_PROFILE')
- let s:do_profile = 1
- endif
- " Profile the MRU plugin
- if s:do_profile
- profile start mru_profile.txt
- profile! file */mru.vim
- endif
- " Tests assume that 'hidden' option is not set
- set nohidden
- source ../plugin/mru.vim
- " Function to log test results
- func! LogResult(test, result)
- call add(g:results, a:test . ': ' . a:result)
- endfunc
- " ==========================================================================
- " Test1
- " When the MRU list is empty, invoking the MRU command should return an error
- " ==========================================================================
- func Test_01()
- let test_name = 'test1'
- redir => msg
- MRU
- redir END
- if msg =~# "MRU file list is empty"
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endfunc
- " ==========================================================================
- " Test2
- " Open the MRU window and check the order of files listed in the window
- " Open the MRU window when the window is already opened.
- " ==========================================================================
- func Test_02()
- let test_name = 'test2'
- edit file1.txt
- edit file2.txt
- edit file3.txt
- edit file2.txt
- edit file1.txt
- MRU
- MRU
- let l = getline(1, "$")
- if l[0] =~# "file1.txt" && l[1] =~# "file2.txt" && l[2] =~# "file3.txt"
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endfunc
- " ==========================================================================
- " Test3
- " Select a file from the MRU window and check whether it is opened
- " ==========================================================================
- func Test_03()
- let test_name = 'test3'
- " Go to the last but one line
- $
- " Select the last file in the MRU window
- exe "normal \<Enter>"
- if fnamemodify(@%, ':p:t') !=# 'file3.txt'
- call LogResult(test_name, "FAIL (1)")
- else
- " Make sure the MRU window is closed
- if bufwinnr(g:MRU_buffer_name) == -1
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, "FAIL (2)")
- endif
- endif
- endfunc
- " ==========================================================================
- " Test4
- " MRU opens a selected file in the previous/last window
- " ==========================================================================
- func Test_04()
- let test_name = 'test4'
- " Edit a file and then open a new window, open the MRU window and select the
- " file
- split file1.txt
- only
- below new
- MRU
- call search('file2.txt')
- exe "normal \<Enter>"
- if winnr() == 2
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endfunc
- " ==========================================================================
- " Test5
- " MRU opens a selected file in the same window if the file is already opened
- " ==========================================================================
- func Test_05()
- let test_name = 'test5'
- edit file1.txt
- only
- below split file2.txt
- below split file3.txt
- MRU
- call search('file1.txt')
- exe "normal \<Enter>"
- if winnr() != 1 || fnamemodify(@%, ':p:t') !=# 'file1.txt'
- call LogResult(test_name, "FAIL (1)")
- else
- MRU
- call search('file2.txt')
- exe "normal \<Enter>"
- if winnr() != 2 || fnamemodify(@%, ':p:t') !=# 'file2.txt'
- call LogResult(test_name, "FAIL (2)")
- else
- MRU
- call search('file3.txt')
- exe "normal \<Enter>"
- if winnr() != 3 || fnamemodify(@%, ':p:t') !=# 'file3.txt'
- call LogResult(test_name, "FAIL (3)")
- else
- call LogResult(test_name, 'pass')
- endif
- endif
- endif
- endfunc
- " ==========================================================================
- " Test6
- " MRU opens a file selected with 'o' command in a new window
- " ==========================================================================
- func Test_06()
- let test_name = 'test6'
- enew | only
- edit file1.txt
- below new
- MRU
- normal o
- if winnr() == 3 && fnamemodify(@%, ':p:t') ==# 'file1.txt'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endfunc
- " ==========================================================================
- " Test7
- " MRU opens the selected file in a new window if the previous buffer is
- " modified.
- " ==========================================================================
- func Test_07()
- let test_name = 'test7'
- enew | only
- insert
- MRU plugin test
- .
- MRU
- call search('file3.txt')
- exe "normal \<Enter>"
- if winnr() == 1 && winnr('$') == 2 &&
- \ fnamemodify(@%, ':p:t') ==# 'file3.txt'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- " Discard changes in the new buffer
- wincmd b
- enew!
- only
- endfunc
- " ==========================================================================
- " Test8
- " MRU opens a file selected with 'v' command in read-only mode in the current
- " window.
- " ==========================================================================
- func Test_08()
- let test_name = 'test8'
- enew | only
- MRU
- call search('file1.txt')
- normal v
- let r1 = &readonly
- MRU
- call search('file2.txt')
- exe "normal \<Enter>"
- let r2 = &readonly
- MRU
- call search('file1.txt')
- exe "normal \<Enter>"
- let r3 = &readonly
- if r1 == 1 && r2 == 0 && r3 == 1
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endfunc
- " ==========================================================================
- " Test9
- " Use 'O' in the MRU window to open a file in a vertically split window
- " ==========================================================================
- func Test_09()
- let test_name = 'test9'
- enew | only
- edit file1.txt
- MRU
- call search('file2.txt')
- normal O
- let b1 = @%
- wincmd h
- let b2 = @%
- wincmd l
- let b3 = @%
- if winnr('$') == 2 && b1 ==# 'file2.txt' &&
- \ b2 ==# 'file1.txt' && b3 ==# 'file2.txt'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endfunc
- " ==========================================================================
- " Test10
- " Use 'p' in the MRU window to open a file in the preview window
- " ==========================================================================
- func Test_10()
- let test_name = 'test10'
- enew | only
- MRU
- call search('file3.txt')
- normal p
- wincmd P
- let p1 = &previewwindow
- let b1 = @%
- if winnr('$') == 2 && &previewwindow && @% =~# 'file3.txt'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- pclose
- endfunc
- " ==========================================================================
- " Test11
- " MRU opens a file selected with 't' command in a new tab and the tab
- " is opened at the end
- " ==========================================================================
- func Test_11()
- let test_name = 'test11'
- enew | only
- edit a1.txt
- tabnew a2.txt
- tabnew a3.txt
- tabnew a4.txt
- tabfirst
- MRU
- call search('file3.txt')
- normal t
- if fnamemodify(@%, ':p:t') ==# 'file3.txt' && tabpagenr() == 5
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- call LogResult(test_name, "file = " . fnamemodify(@%, ':p:t'))
- call LogResult(test_name, "tab page = " . tabpagenr())
- endif
- tabonly
- endfunc
- " ==========================================================================
- " Test12
- " The 'q' command closes the MRU window
- " ==========================================================================
- func Test_12()
- let test_name = 'test12'
- enew | only
- MRU
- normal q
- if bufwinnr(g:MRU_buffer_name) == -1
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endfunc
- " ==========================================================================
- " Test13
- " A selected file is opened in a new window if the previous window is a
- " preview window
- " ==========================================================================
- func Test_13()
- let test_name = 'test13'
- enew | only
- setlocal previewwindow
- MRU
- call search('file2.txt')
- exe "normal \<Enter>"
- if winnr() == 1 && winnr('$') == 2 &&
- \ &previewwindow == 0 &&
- \ fnamemodify(@%, ':p:t') ==# 'file2.txt'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- " Close the preview window created by this test
- new
- only
- endfunc
- " ==========================================================================
- " Test14
- " A selected file is opened in a new window if the previous window contains
- " a special buffer (used by some other plugin)
- " ==========================================================================
- func Test_14()
- let test_name = 'test14'
- enew | only
- setlocal buftype=nofile
- MRU
- call search('file3.txt')
- exe "normal \<Enter>"
- if winnr() == 1 && winnr('$') == 2 &&
- \ &buftype == '' &&
- \ fnamemodify(@%, ':p:t') ==# 'file3.txt'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- " Discard the special buffer
- enew
- endfunc
- " ==========================================================================
- " Test15
- " If a file selected using the 't' command is already opened in a tab,
- " then jump to that tab (instead of opening a new tab)
- " ==========================================================================
- func Test_15()
- let test_name = 'test15'
- enew | only
- " Open the test files in the middle window with empty windows at the top and
- " bottom
- edit file1.txt
- above new
- botright new
- tabedit file2.txt
- above new
- botright new
- tabedit file3.txt
- above new
- botright new
- tabfirst
- MRU
- call search('file3.txt')
- exe "normal t"
- if tabpagenr() != 3
- \ || fnamemodify(@%, ':p:t') !=# 'file3.txt'
- \ || winnr() != 2
- call LogResult(test_name, "FAIL (1)")
- else
- MRU
- call search('file1.txt')
- exe "normal t"
- if tabpagenr() != 1
- \ || fnamemodify(@%, ':p:t') !=# 'file1.txt'
- \ || winnr() != 2
- call LogResult(test_name, "FAIL (2)")
- else
- MRU
- call search('file2.txt')
- exe "normal t"
- if tabpagenr() != 2
- \ || fnamemodify(@%, ':p:t') !=# 'file2.txt'
- \ || winnr() != 2
- call LogResult(test_name, "FAIL (3)")
- else
- call LogResult(test_name, 'pass')
- endif
- endif
- endif
- " Close all the other tabs
- tabonly
- enew
- only
- endfunc
- " ==========================================================================
- " Test16
- " Open multiple files from the MRU window using the visual mode and by using a
- " count. Each file should be opened in a separate window.
- " ==========================================================================
- func Test_16()
- let test_name = 'test16'
- enew | only
- edit file3.txt
- edit file2.txt
- edit file1.txt
- enew
- MRU
- exe "normal 3\<Enter>"
- if winnr('$') == 3 &&
- \ bufwinnr('file3.txt') == 1 &&
- \ bufwinnr('file2.txt') == 2 &&
- \ bufwinnr('file1.txt') == 3
- let test_result = 'pass'
- else
- let test_result = 'FAIL'
- endif
- only | enew
- if test_result == 'pass'
- MRU
- exe "normal V2j\<Enter>"
- if winnr('$') == 3 &&
- \ bufwinnr('file1.txt') == 1 &&
- \ bufwinnr('file2.txt') == 2 &&
- \ bufwinnr('file3.txt') == 3
- let test_result = 'pass'
- else
- let test_result = 'FAIL'
- endif
- endif
- if test_result == 'pass'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endfunc
- " ==========================================================================
- " Test17
- " When the MRU list is updated, the MRU file also should updated.
- " ==========================================================================
- func Test_17()
- let test_name = 'test17'
- enew | only
- edit file1.txt
- let l = readfile(g:MRU_File)
- if l[1] =~# 'file1.txt'
- edit file2.txt
- let l = readfile(g:MRU_File)
- if l[1] =~# 'file2.txt'
- edit file3.txt
- let l = readfile(g:MRU_File)
- if l[1] =~# 'file3.txt'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, "FAIL (3)")
- endif
- else
- call LogResult(test_name, "FAIL (2)")
- endif
- else
- call LogResult(test_name, "FAIL (1)")
- endif
- endfunc
- " MRU_Test_Add_Files
- " Add the supplied List of files to the beginning of the MRU file
- func! s:MRU_Test_Add_Files(fnames)
- let l = readfile(g:MRU_File)
- call extend(l, a:fnames, 1)
- call writefile(l, g:MRU_File)
- endfunc
- " ==========================================================================
- " Test18
- " When the MRU file is updated by another Vim instance, the MRU plugin
- " should update the MRU list
- " ==========================================================================
- func Test_18()
- let test_name = 'test18'
- enew | only
- call s:MRU_Test_Add_Files(['/software/editors/vim',
- \ '/software/editors/emacs',
- \ '/software/editors/nano'])
- MRU
- if getline(1) ==# 'vim (/software/editors/vim)'
- \ && getline(2) ==# 'emacs (/software/editors/emacs)'
- \ && getline(3) ==# 'nano (/software/editors/nano)'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- " Close the MRU window
- close
- endfunc
- " ==========================================================================
- " Test19
- " When the MRU file is updated by another Vim instance, the MRU file names
- " from the current instance should be merged with that list
- " ==========================================================================
- func Test_19()
- let test_name = 'test19'
- enew | only
- " Remove all the files from the MRU file
- let l = readfile(g:MRU_File)
- call remove(l, 1, -1)
- call writefile(l, g:MRU_File)
- edit file1.txt
- call s:MRU_Test_Add_Files(['/software/os/unix'])
- edit file2.txt
- call s:MRU_Test_Add_Files(['/software/os/windows'])
- edit file3.txt
- call s:MRU_Test_Add_Files(['/software/os/osx'])
- MRU
- if getline(1) ==# 'osx (/software/os/osx)'
- \ && getline(2) =~# 'file3.txt'
- \ && getline(3) ==# 'windows (/software/os/windows)'
- \ && getline(4) =~# 'file2.txt'
- \ && getline(5) ==# 'unix (/software/os/unix)'
- \ && getline(6) =~# 'file1.txt'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- close
- endfunc
- " ==========================================================================
- " Test20
- " When the MRU list has more than g:MRU_Max_Entries, the list should be
- " trimmed. The last entries should be removed.
- " ==========================================================================
- func Test_20()
- let test_name = 'test20'
- enew | only
- " Create a MRU list with MRU_Max_Entries
- let flist = []
- for i in range(1, g:MRU_Max_Entries)
- let flist += ['/usr/share/mru_test/mru_file' . i . '.abc']
- endfor
- " Modify the MRU file to contain max entries
- let l = readfile(g:MRU_File)
- call remove(l, 1, -1)
- call extend(l, flist)
- call writefile(l, g:MRU_File)
- enew
- edit file1.txt
- let l = readfile(g:MRU_File)
- if len(l) == (g:MRU_Max_Entries + 1) &&
- \ l[g:MRU_Max_Entries] != '/usr/share/mru_test/mru_file9.abc'
- call LogResult(test_name, "FAIL (1)")
- else
- edit file2.txt
- let l = readfile(g:MRU_File)
- if len(l) == (g:MRU_Max_Entries + 1) &&
- \ l[g:MRU_Max_Entries] != '/usr/share/mru_test/mru_file8.abc'
- call LogResult(test_name, "FAIL (2)")
- else
- edit file3.txt
- let l = readfile(g:MRU_File)
- if len(l) == (g:MRU_Max_Entries + 1) &&
- \ l[g:MRU_Max_Entries] != '/usr/share/mru_test/mru_file7.abc'
- call LogResult(test_name, "FAIL (3)")
- else
- call LogResult(test_name, 'pass')
- endif
- endif
- endif
- endfunc
- " ==========================================================================
- " Test21
- " When an filename (already present in the MRU list) is specified to the MRU
- " command, it should edit the file.
- " ==========================================================================
- func Test_21()
- let test_name = 'test21'
- enew | only
- edit file1.txt
- edit file2.txt
- edit file3.txt
- enew
- MRU file2.txt
- if fnamemodify(@%, ':p:t') ==# 'file2.txt' && winnr('$') == 1
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endfunc
- " ==========================================================================
- " Test22
- " When a pattern (matching multiple filenames) is specified to the MRU
- " command, then the MRU window should be opened with all the matching
- " filenames
- " ==========================================================================
- func Test_22()
- let test_name = 'test22'
- enew | only
- edit file1.txt
- edit file2.txt
- edit file3.txt
- only
- MRU file.*
- if @% != g:MRU_buffer_name
- call LogResult(test_name, 'FAIL')
- else
- let l = getline(1, "$")
- if l[0] =~# "file3.txt" && l[1] =~# "file2.txt" && l[2] =~# "file1.txt"
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endif
- close
- endfunc
- " ==========================================================================
- " Test23
- " When a partial filename (matching multiple filenames) is specified to the
- " MRU command, then the MRU window should be opened with all the matching
- " filenames
- " ==========================================================================
- func Test_23()
- let test_name = 'test23'
- enew | only
- let g:MRU_FuzzyMatch = 0
- edit file1.txt
- edit file2.txt
- edit file3.txt
- only
- MRU file
- if @% != g:MRU_buffer_name
- call LogResult(test_name, 'FAIL')
- else
- let l = getline(1, "$")
- if l[0] =~# "file3.txt" && l[1] =~# "file2.txt" && l[2] =~# "file1.txt"
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endif
- close
- endfunc
- " ==========================================================================
- " Test24
- " When a non-existing filename is specified to the MRU command, an error
- " message should be displayed.
- " ==========================================================================
- func Test_24()
- let test_name = 'test24'
- let g:MRU_FuzzyMatch = 0
- redir => msg
- MRU nonexistingfile.txt
- redir END
- if @% == g:MRU_buffer_name ||
- \ msg !~# "MRU file list doesn't contain files " .
- \ "matching nonexistingfile.txt"
- call LogResult(test_name, 'FAIL')
- else
- call LogResult(test_name, 'pass')
- endif
- endfunc
- " ==========================================================================
- " Test25
- " The MRU command should support filename completion. Supply a partial file
- " name to the MRU command and complete the filenames.
- " ==========================================================================
- func Test_25()
- let test_name = 'test25'
- enew | only
- edit file1.txt
- edit file2.txt
- edit file3.txt
- exe 'normal! :MRU file' . "\<C-A>" . "\<Home>let m='\<End>'\<CR>"
- let fnames = split(m)
- if fnames[1] =~# 'file3.txt' && fnames[2] =~# 'file2.txt' &&
- \ fnames[3] =~# 'file1.txt'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endfunc
- " ==========================================================================
- " Test26
- " When trying to complete filenames for the MRU command without specifying
- " any text should return the entire MRU list.
- " ==========================================================================
- func Test_26()
- let test_name = 'test26'
- enew | only
- call delete(g:MRU_File)
- edit file1.txt
- edit file2.txt
- edit file3.txt
- exe 'normal! :MRU ' . "\<C-A>" . "\<Home>let m='\<End>'\<CR>"
- let fnames = split(m)
- if fnames[1] =~# 'file3.txt' && fnames[2] =~# 'file2.txt' &&
- \ fnames[3] =~# 'file1.txt'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endfunc
- " ==========================================================================
- " Test27
- " When the current file/buffer has unsaved changes, MRU should open a selected
- " file in a new window (if the 'hidden' option is not set)
- " ==========================================================================
- func Test_27()
- let test_name = 'test27'
- enew | only
- edit file1.txt
- edit file2.txt
- call append(line('$'), 'Temporary changes to buffer')
- MRU
- call search('file1.txt')
- exe "normal \<Enter>"
- if winnr() == 1 && winnr('$') == 2 &&
- \ fnamemodify(@%, ':p:t') ==# 'file1.txt'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- close
- edit!
- endfunc
- " ==========================================================================
- " Test28
- " When the current file/buffer has unsaved changes and the 'hidden' option is
- " set, then MRU should open a selected file in the current window
- " ==========================================================================
- func Test_28()
- let test_name = 'test28'
- enew | only
- edit file2.txt
- edit file1.txt
- call append(line('$'), 'Temporary changes to buffer')
- set hidden
- MRU
- call search('file2.txt')
- exe "normal \<Enter>"
- if winnr('$') == 1 &&
- \ fnamemodify(@%, ':p:t') ==# 'file2.txt'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- edit file1.txt
- edit!
- set nohidden
- %bw!
- endfunc
- " ==========================================================================
- " Test29
- " Every edited file is added to the top of the MRU list. If a file is already
- " present in the MRU list, then it is moved to the top of the list.
- " ==========================================================================
- func Test_29()
- let test_name = 'test29'
- enew | only
- edit file1.txt
- let f1 = readfile(g:MRU_File, '', 2)
- edit file2.txt
- let f2 = readfile(g:MRU_File, '', 2)
- edit file3.txt
- let f3 = readfile(g:MRU_File, '', 2)
- edit file1.txt
- let f4 = readfile(g:MRU_File, '', 2)
- if f1[1] =~# 'file1.txt' && f2[1] =~# 'file2.txt' && f3[1] =~# 'file3.txt' &&
- \ f4[1] =~# 'file1.txt'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endfunc
- " ==========================================================================
- " Test30
- " Only file names matching the regular expression in the MRU_Include_Files
- " variable should be added to the MRU list.
- " ==========================================================================
- func Test_30()
- let test_name = 'test30'
- enew | only
- edit file1.txt
- let g:MRU_Include_Files='\.c'
- edit abc.c
- let f1 = readfile(g:MRU_File, '', 2)
- edit file1.txt
- let f2 = readfile(g:MRU_File, '', 2)
- edit def.c
- let f3 = readfile(g:MRU_File, '', 2)
- if f1[1] =~# 'abc.c' && f2[1] =~# 'abc.c' && f3[1] =~# 'def.c'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- let g:MRU_Include_Files=''
- endfunc
- " ==========================================================================
- " Test31
- " File names matching the regular expression in the MRU_Exclude_Files
- " variable should not be added to the MRU list.
- " ==========================================================================
- func Test_31()
- let test_name = 'test31'
- enew | only
- let g:MRU_Exclude_Files='\.txt'
- edit abc.c
- let f1 = readfile(g:MRU_File, '', 2)
- edit file1.txt
- edit file2.txt
- edit file3.txt
- let f2 = readfile(g:MRU_File, '', 2)
- edit def.c
- let f3 = readfile(g:MRU_File, '', 2)
- let g:MRU_Exclude_Files=''
- edit file1.txt
- let f4 = readfile(g:MRU_File, '', 2)
- if f1[1] =~# 'abc.c' && f2[1] =~# 'abc.c' && f3[1] =~# 'def.c' &&
- \ f4[1] =~# 'file1.txt'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endfunc
- " ==========================================================================
- " Test32
- " If the MRU window is open, when adding a file name to the list, the MRU
- " window should be refreshed.
- " ==========================================================================
- func Test_32()
- let test_name = 'test32'
- enew | only
- MRU
- wincmd p
- edit abc.c
- wincmd p
- let s1 = getline(1)
- wincmd p
- edit file1.txt
- wincmd p
- let s2 = getline(1)
- close
- if s1 =~# 'abc.c' && s2 =~# 'file1.txt'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endfunc
- " ==========================================================================
- " Test33
- " When MRU_Use_Current_Window is set, the MRU list should be displayed in
- " the current window.
- " Selecting a file from the MRU window should replace
- " the MRU buffer with the selected file.
- " ==========================================================================
- func Test_33()
- let test_name = 'test33'
- enew | only
- edit file1.txt
- let g:MRU_Use_Current_Window=1
- MRU
- if winnr('$') == 1 && @% == g:MRU_buffer_name
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- let g:MRU_Use_Current_Window=0
- endfunc
- " ==========================================================================
- " Test34
- " When MRU_Use_Current_Window is set, selecting a file from the MRU window
- " should replace the MRU buffer with the selected file.
- " ==========================================================================
- func Test_34()
- let test_name = 'test34'
- enew | only
- let g:MRU_Use_Current_Window=1
- let w:marker=1
- MRU
- if winnr('$') == 1 && w:marker && @% == g:MRU_buffer_name
- call search('file2.txt')
- exe "normal \<Enter>"
- if winnr('$') == 1 && w:marker && @% == 'file2.txt'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- else
- call LogResult(test_name, 'FAIL')
- endif
- unlet w:marker
- let g:MRU_Use_Current_Window=0
- endfunc
- " ==========================================================================
- " Test35
- " When MRU_Use_Current_Window is set, if the current buffer has unsaved
- " changes, then the MRU window should be opened in a split window
- " ==========================================================================
- func Test_35()
- let test_name = 'test35'
- enew | only
- let g:MRU_Use_Current_Window=1
- set modified
- MRU
- if winnr('$') == 2 && winnr() == 2 && @% == g:MRU_buffer_name
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- close
- set nomodified
- let g:MRU_Use_Current_Window=0
- enew | only
- endfunc
- " ==========================================================================
- " Test36
- " When MRU_Auto_Close is not set, the MRU window should not automatically
- " close when a file is selected. The MRU window should be kept open.
- " ==========================================================================
- func Test_36()
- let test_name = 'test36'
- enew | only
- let g:MRU_Auto_Close=0
- new
- MRU
- call search('file1.txt')
- exe "normal \<Enter>"
- 2wincmd w
- MRU
- call search('file2.txt')
- exe "normal \<Enter>"
- if winnr('$') == 3 &&
- \ bufwinnr('file1.txt') == 1 &&
- \ bufwinnr('file2.txt') == 2 &&
- \ bufwinnr(g:MRU_buffer_name) == 3
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- wincmd b
- close
- let g:MRU_Auto_Close=1
- only
- endfunc
- " ==========================================================================
- " Test37
- " When MRU_Open_File_Use_Tabs is set, a selected file should be opened in a
- " tab. If the file is already opened in a tab, then the focus should be moved
- " to that tab.
- " ==========================================================================
- func Test_37()
- let test_name = 'test37'
- enew | only
- let g:MRU_Open_File_Use_Tabs=1
- edit file1.txt
- MRU
- call search('file2.txt')
- exe "normal \<Enter>"
- MRU
- call search('file3.txt')
- exe "normal \<Enter>"
- MRU file1.txt
- let t1 = tabpagenr()
- MRU
- call search('file2.txt')
- exe "normal \<Enter>"
- let t2 = tabpagenr()
- MRU
- call search('file3.txt')
- exe "normal \<Enter>"
- let t3 = tabpagenr()
- tabonly | enew
- if t1 == 1 && t2 == 2 && t3 == 3
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- let g:MRU_Open_File_Use_Tabs=0
- endfunc
- " ==========================================================================
- " Test38
- " If the MRU_Window_Open_Always is set to 0, when the MRU command finds a
- " single matching file name, then it should open the MRU window. If this
- " variable is set to 1, then the file should be opened without opening the MRU
- " window.
- " ==========================================================================
- func Test_38()
- let test_name = 'test38'
- enew | only
- edit file3.txt
- enew
- let g:MRU_Window_Open_Always=1
- MRU file3.txt
- if winnr('$') == 2 &&
- \ bufwinnr(g:MRU_buffer_name) == 2
- let test_result = 'pass'
- else
- let test_result = 'FAIL'
- endif
- close
- enew | only
- if test_result == 'pass'
- let g:MRU_Window_Open_Always=0
- MRU file3.txt
- if winnr('$') == 1 &&
- \ bufwinnr('file3.txt') == 1
- let test_result = 'pass'
- else
- let test_result = 'FAIL'
- endif
- endif
- let g:MRU_Window_Open_Always=0
- if test_result == 'pass'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endfunc
- " ==========================================================================
- " Test39
- " If the current tabpage is empty, then pressing 't' in the MRU window
- " should open the file in the current tabpage.
- " ==========================================================================
- func Test_39()
- let test_name = 'test39'
- enew | only | tabonly
- tabnew
- tabnew
- tabnext 2
- MRU
- call search('file2.txt')
- normal t
- if fnamemodify(@%, ':p:t') ==# 'file2.txt' && tabpagenr() == 2
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- call LogResult(test_name, "file = " . fnamemodify(@%, ':p:t'))
- call LogResult(test_name, "tab page = " . tabpagenr())
- endif
- tabonly
- endfunc
- " ==========================================================================
- " Test40
- " Pressing 'd' in the MRU window should delete the file under the cursor
- " from the MRU list
- " ==========================================================================
- func Test_40()
- let test_name = 'test40'
- edit file2.txt
- enew
- MRU
- call search('file2.txt')
- normal d
- close
- let l = readfile(g:MRU_File)
- if match(l, 'file2.txt') == -1
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- endfunc
- " ==========================================================================
- " Test41
- " Running the :vimgrep command should not add the files to the MRU list
- " ==========================================================================
- func Test_41()
- let test_name = 'test41'
- call writefile(['bright'], 'dummy1.txt')
- call writefile(['bright'], 'dummy2.txt')
- vimgrep /bright/j dummy*
- let l = readfile(g:MRU_File)
- if match(l, 'dummy') == -1
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- call delete('dummy1.txt')
- call delete('dummy2.txt')
- endfunc
- " ==========================================================================
- " Test42
- " Using a command modifier with the MRU command to open the MRU window
- " ==========================================================================
- func Test_42()
- if v:version < 800
- " The <mods> command modifier is supported only by Vim 8.0 and above
- return
- endif
- let test_name = 'test42'
- enew | only
- topleft MRU
- if winnr() == 1 && winnr('$') == 2
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- enew | only
- botright MRU
- if winnr() == 2 && winnr('$') == 2
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- enew | only
- botright MRU
- if winnr() == 2 && winnr('$') == 2
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- enew | only
- endfunc
- " ==========================================================================
- " Test43
- " Opening a file using the MRU command should jump to the window containing
- " the file (if it is already opened).
- " ==========================================================================
- func Test_43()
- let test_name = 'test43'
- only
- edit file3.txt
- below split file2.txt
- below split file1.txt
- wincmd t
- MRU file1.txt
- if winnr() != 3 || fnamemodify(@%, ':p:t') !=# 'file1.txt'
- call LogResult(test_name, 'FAIL (1)')
- else
- MRU file2.txt
- if winnr() != 2 && fnamemodify(@%, ':p:t') !=# 'file2.txt'
- call LogResult(test_name, 'FAIL (2)')
- else
- MRU file3.txt
- if winnr() != 1 && fnamemodify(@%, ':p:t') !=# 'file3.txt'
- call LogResult(test_name, 'FAIL (3)')
- else
- call LogResult(test_name, 'pass')
- endif
- endif
- endif
- enew | only
- endfunc
- " ==========================================================================
- " Test44
- " Opening a file using the MRU command should open the file in a new window if
- " the current buffer has unsaved changes.
- " ==========================================================================
- func Test_44()
- let test_name = 'test44'
- only
- set modified
- MRU file2.txt
- if winnr('$') == 2 && winnr() == 1 &&
- \ fnamemodify(@%, ':p:t') ==# 'file2.txt'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- close
- set nomodified
- endfunc
- " ==========================================================================
- " Test45
- " Opening a file from the MRU window using 'v' should open the file in a new
- " window if the current buffer has unsaved changes.
- " ==========================================================================
- func Test_45()
- let test_name = 'test45'
- only
- set modified
- MRU
- call search('file3.txt')
- normal v
- if winnr('$') == 2 && winnr() == 1
- \ && fnamemodify(@%, ':p:t') ==# 'file3.txt'
- \ && &readonly
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- close
- set nomodified
- endfunc
- " ==========================================================================
- " Test46
- " Specify a count to the :MRU command to set the MRU window height/width
- " ==========================================================================
- func Test_46()
- let test_name = 'test46'
- only
- " default height is 8
- MRU
- if winnr() != 2 || winheight(0) != 8
- call LogResult(test_name, 'FAIL (1)')
- return
- endif
- close
- " use a specific height value
- 15MRU
- if winnr() != 2 || winheight(0) != 15
- call LogResult(test_name, 'FAIL (2)')
- return
- endif
- close
- if v:version >= 800
- " use a specific height value with a command modifier
- topleft 12MRU
- if winnr() != 1 || winheight(0) != 12
- call LogResult(test_name, 'FAIL (3)')
- return
- endif
- close
- " check for the width (leftmost window)
- vertical topleft 20MRU
- if winnr() != 1 || winwidth(0) != 20
- call LogResult(test_name, 'FAIL (4)')
- return
- endif
- close
- " check for the width (rightmost window)
- vertical botright 25MRU
- if winnr() != 2 || winwidth(0) != 25
- call LogResult(test_name, 'FAIL (5)')
- return
- endif
- close
- endif
- call LogResult(test_name, 'pass')
- endfunc
- " ==========================================================================
- " Test47
- " The height of the MRU window should be MRU_Window_Height
- " ==========================================================================
- func Test_47()
- let test_name = 'test47'
- only
- " default height is 8
- MRU
- if winheight(0) != 8
- call LogResult(test_name, 'FAIL (1)')
- return
- endif
- close
- let g:MRU_Window_Height = 2
- MRU
- if winheight(0) != 2
- call LogResult(test_name, 'FAIL (2)')
- return
- endif
- close
- let g:MRU_Window_Height = 12
- MRU
- if winheight(0) != 12
- call LogResult(test_name, 'FAIL (3)')
- return
- endif
- close
- call LogResult(test_name, 'pass')
- let g:MRU_Window_Height = 8
- endfunc
- " ==========================================================================
- " Test48
- " Fuzzy search file names with MRU_FuzzyMatch set to 1.
- " ==========================================================================
- func Test_48()
- if !exists('*matchfuzzy')
- return
- endif
- let test_name = 'test48'
- enew | only
- let g:MRU_FuzzyMatch = 1
- MRU F1
- if fnamemodify(@%, ':p:t') ==# 'file1.txt' && winnr('$') == 1
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL (1)')
- endif
- let g:MRU_FuzzyMatch = 0
- redir => msg
- MRU F1
- redir END
- if msg =~# "MRU file list doesn't contain files matching F1"
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL (2)')
- endif
- let g:MRU_FuzzyMatch = 1
- endfunc
- " ==========================================================================
- " Test49
- " Test for creating a new file by saving an unnamed buffer.
- " ==========================================================================
- func Test_49()
- let test_name = 'test49'
- enew | only
- call setline(1, 'sample file')
- write sample.txt
- let l = readfile(g:MRU_File)
- if match(l, 'sample.txt') != -1
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL')
- endif
- call delete('sample.txt')
- bwipe sample.txt
- endfunc
- " ==========================================================================
- " Test50
- " Test for the MruGetFiles() function
- " ==========================================================================
- func Test_50()
- let test_name = 'test50'
- enew | only
- let list1 = MruGetFiles()
- let list2 = readfile(g:MRU_File)
- if list1 != list2[1:]
- call LogResult(test_name, 'FAIL (1)')
- return
- endif
- if MruGetFiles('x1y2z3') == []
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL (2)')
- endif
- endfunc
- " ==========================================================================
- " Test51
- " Test for the :MruRefresh command
- " ==========================================================================
- func Test_51()
- let test_name = 'test51'
- enew | only
- if match(MruGetFiles(), 'sample.txt') == -1
- call LogResult(test_name, 'FAIL (1)')
- return
- endif
- MruRefresh
- if match(MruGetFiles(), 'sample.txt') == -1
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL (2)')
- endif
- endfunc
- " ==========================================================================
- " Test52
- " Test for the re-opening a deleted buffer from the MRU list
- " ==========================================================================
- func Test_52()
- let test_name = 'test52'
- edit file1.txt
- edit file2.txt
- bd
- " select the file from the MRU window
- MRU
- call search('file2.txt')
- exe "normal \<Enter>"
- if !&buflisted || fnamemodify(@%, ':p:t') !=# 'file2.txt'
- call LogResult(test_name, 'FAIL (1)')
- return
- endif
- " open the file directly using the command
- bw file1.txt file2.txt
- edit file2.txt
- edit file1.txt
- bd
- MRU file1.txt
- if !&buflisted || fnamemodify(@%, ':p:t') !=# 'file1.txt'
- call LogResult(test_name, 'FAIL (2)')
- return
- endif
- call LogResult(test_name, 'pass')
- endfunc
- " ==========================================================================
- " Test53
- " Test for using a command modifier when directly opening a file using the
- " MRU command.
- " ==========================================================================
- func Test_53()
- if v:version < 800
- return
- endif
- let test_name = 'test53'
- %bw!
- topleft MRU file2.txt
- if winnr('$') == 2 && winnr() == 1 && fnamemodify(@%, ':p:t') ==# 'file2.txt'
- wincmd j
- if winnr() != 2
- call LogResult(test_name, 'FAIL (1)')
- return
- endif
- else
- call LogResult(test_name, 'FAIL (2)')
- return
- endif
- %bw
- belowright MRU file2.txt
- if winnr('$') == 2 && winnr() == 2 && fnamemodify(@%, ':p:t') ==# 'file2.txt'
- wincmd k
- if winnr() != 1
- call LogResult(test_name, 'FAIL (3)')
- return
- endif
- else
- call LogResult(test_name, 'FAIL (4)')
- return
- endif
- %bw
- vertical topleft MRU file2.txt
- if winnr('$') == 2 && winnr() == 1 && fnamemodify(@%, ':p:t') ==# 'file2.txt'
- wincmd l
- if winnr() != 2
- call LogResult(test_name, 'FAIL (5)')
- return
- endif
- else
- call LogResult(test_name, 'FAIL (6)')
- return
- endif
- %bw
- vertical belowright MRU file2.txt
- if winnr('$') == 2 && winnr() == 2 && fnamemodify(@%, ':p:t') ==# 'file2.txt'
- wincmd h
- if winnr() != 1
- call LogResult(test_name, 'FAIL (7)')
- return
- endif
- else
- call LogResult(test_name, 'FAIL (8)')
- return
- endif
- %bw
- tab MRU file2.txt
- if tabpagenr() != 2 || fnamemodify(@%, ':p:t') !=# 'file2.txt'
- call LogResult(test_name, 'FAIL (9)')
- return
- endif
- %bw
- call LogResult(test_name, 'pass')
- endfunc
- " ==========================================================================
- " Test54
- " Test for the :MRUToggle command.
- " ==========================================================================
- func Test_54()
- let test_name = 'test54'
- only
- " open the MRU window
- MRUToggle
- if bufwinnr(g:MRU_buffer_name) != 2 || winnr() != 2
- call LogResult(test_name, 'FAIL (1)')
- return
- endif
- " close the MRU window
- MRUToggle
- if bufwinnr(g:MRU_buffer_name) != -1 || winnr() != 1
- call LogResult(test_name, 'FAIL (2)')
- return
- endif
- " close the MRU window from some other window
- MRUToggle
- wincmd k
- MRUToggle
- if bufwinnr(g:MRU_buffer_name) != -1 || winnr() != 1
- call LogResult(test_name, 'FAIL (3)')
- return
- endif
- call LogResult(test_name, 'pass')
- endfunc
- " ==========================================================================
- " Test55
- " Editing a file selected from the MRU window should set the current file to
- " be the alternate file.
- " ==========================================================================
- func Test_55()
- let test_name = 'test55'
- silent! bw file1.txt file2.txt file3.txt
- new
- edit file1.txt
- edit file2.txt
- MRU
- call search('file3.txt')
- exe "normal \<Enter>"
- if fnamemodify(@%, ':p:t') !=# 'file3.txt'
- \ || fnamemodify(@#, ':p:t') !=# 'file2.txt'
- call LogResult(test_name, 'FAIL')
- return
- endif
- call LogResult(test_name, 'pass')
- endfunc
- " ==========================================================================
- " Test56
- " With MRU_Use_Current_Window set to 1, editing a file from the MRU list
- " should not change the alternate file.
- " ==========================================================================
- func Test_56()
- let test_name = 'test56'
- let g:MRU_Use_Current_Window = 1
- bw file1.txt file2.txt file3.txt
- new
- edit file3.txt
- edit file1.txt
- edit file2.txt
- MRU
- call search('file3.txt')
- exe "normal \<Enter>"
- if fnamemodify(@%, ':p:t') !=# 'file3.txt'
- \ || fnamemodify(@#, ':p:t') !=# 'file2.txt'
- call LogResult(test_name, 'FAIL (1)')
- return
- endif
- " try viewing a file
- MRU
- call search('file1.txt')
- normal v
- if fnamemodify(@%, ':p:t') !=# 'file1.txt'
- \ || fnamemodify(@#, ':p:t') !=# 'file3.txt'
- \ || !&readonly
- call LogResult(test_name, 'FAIL (2)')
- return
- endif
- " try opening a wiped out buffer
- bw file2.txt
- MRU
- call search('file2.txt')
- exe "normal \<Enter>"
- if fnamemodify(@%, ':p:t') !=# 'file2.txt'
- \ || fnamemodify(@#, ':p:t') !=# 'file1.txt'
- \ || &readonly
- call LogResult(test_name, 'FAIL (3)')
- return
- endif
- let g:MRU_Use_Current_Window = 0
- bw!
- call LogResult(test_name, 'pass')
- endfunc
- " ==========================================================================
- " Test57
- " When the MRU window is closed, the MRU buffer should be unloaded.
- " If 'MRU_Use_Current_Window' is set, then the MRU buffer should be wiped out.
- " ==========================================================================
- func Test_57()
- let test_name = 'test57'
- MRU
- let mrubnum = bufnr('')
- close
- if bufloaded(mrubnum)
- call LogResult(test_name, 'FAIL (1)')
- return
- endif
- let g:MRU_Use_Current_Window = 1
- new
- edit Xfile
- MRU
- let mrubnum = bufnr('')
- edit #
- if bufexists(mrubnum) || @% != 'Xfile'
- call LogResult(test_name, 'FAIL (2)')
- return
- endif
- let g:MRU_Use_Current_Window = 0
- bw!
- call LogResult(test_name, 'pass')
- endfunc
- " ==========================================================================
- " Test58
- " When the MRU window is toggled with MRU_Use_Current_Window set to 1, the
- " previous buffer should be loaded.
- " ==========================================================================
- func Test_58()
- let test_name = 'test58'
- let g:MRU_Use_Current_Window = 1
- new
- edit Xfile
- MRUToggle
- if @% != g:MRU_buffer_name || winnr('$') != 2
- call LogResult(test_name, 'FAIL (1)')
- return
- endif
- MRUToggle
- if @% != 'Xfile' || winnr('$') != 2
- call LogResult(test_name, 'FAIL (2)')
- return
- endif
- let g:MRU_Use_Current_Window = 0
- bw!
- call LogResult(test_name, 'pass')
- endfunc
- " ==========================================================================
- " Test59
- " When the MRU_Set_Alternate_File is set to 1, on plugin startup, the
- " alternate file should be set to the first file in the MRU list.
- " ==========================================================================
- func Test_59()
- if v:version < 802
- return
- endif
- let test_name = 'test59'
- call writefile([], 'Xfirstfile')
- edit Xfirstfile
- call writefile([
- \ "let MRU_File='vim_mru_file'",
- \ "let MRU_Set_Alternate_File=1",
- \ "source ../plugin/mru.vim",
- \ "call writefile([@#], 'Xoutput')"
- \ ], 'Xscript')
- silent! !vim -u NONE --noplugin i NONE -N -S Xscript -c "qa"
- if !filereadable('Xoutput')
- call LogResult(test_name, 'FAIL (1)')
- else
- let lines = readfile('Xoutput')
- if len(lines) == 1 && lines[0] =~ 'Xfirstfile$'
- call LogResult(test_name, 'pass')
- else
- call LogResult(test_name, 'FAIL (2)')
- endif
- endif
- call delete('Xscript')
- call delete('Xoutput')
- call delete('Xfirstfile')
- endfunc
- " ==========================================================================
- " Test60
- " With MRU_Use_Current_Window set to 1, MRU opens a selected file in the
- " current window, even when the file is already open in another window
- " ==========================================================================
- func Test_60()
- let test_name = 'test60'
- let g:MRU_Use_Current_Window = 1
- edit file1.txt
- let bnum = bufnr()
- only
- below split file2.txt
- MRU
- call search('file1.txt')
- exe "normal \<Enter>"
- if winnr() == 2 && winbufnr(1) == bnum && winbufnr(2) == bnum
- call LogResult(test_name, "pass")
- else
- call LogResult(test_name, "FAIL")
- endif
- let g:MRU_Use_Current_Window = 0
- endfunc
- " ==========================================================================
- " Create the files used by the tests
- call writefile(['MRU test file1'], 'file1.txt')
- call writefile(['MRU test file2'], 'file2.txt')
- call writefile(['MRU test file3'], 'file3.txt')
- call writefile(['#include <stdio.h', 'int main(){}'], 'abc.c')
- call writefile(['#include <stdlib.h', 'int main(){}'], 'def.c')
- " Remove the results from the previous test runs
- call delete('results.txt')
- call delete(g:MRU_File)
- let results = []
- " Generate a sorted list of Test_ functions to run
- redir @q
- silent function /^Test_
- redir END
- let s:tests = split(substitute(@q, '\(function\) \(\k*()\)', '\2', 'g'))
- " Run the tests
- set nomore
- set debug=beep
- for one_test in sort(s:tests)
- exe 'call ' . one_test
- endfor
- set more
- call writefile(results, 'results.txt')
- " TODO:
- " Add the following tests:
- " 1. When the MRU list is modified, the MRU menu should be refreshed.
- " 2. Try to jump to an already open file from the MRU window and using the
- " MRU command.
- " Cleanup the files used by the tests
- call delete('file1.txt')
- call delete('file2.txt')
- call delete('file3.txt')
- call delete('abc.c')
- call delete('def.c')
- call delete(g:MRU_File)
- " End of unit test execution
- qall
- " vim: shiftwidth=2 sts=2 expandtab
|