unit_tests.vim 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516
  1. " MRU plugin unit-tests
  2. " MRU plugin settings
  3. let MRU_File='vim_mru_file'
  4. let MRU_Auto_Close=1
  5. let MRU_Max_Entries=10
  6. let MRU_buffer_name = '-RecentFiles-'
  7. " Set the $MRU_PROFILE environment variable to profile the MRU plugin
  8. let s:do_profile = 0
  9. if exists('$MRU_PROFILE')
  10. let s:do_profile = 1
  11. endif
  12. " Profile the MRU plugin
  13. if s:do_profile
  14. profile start mru_profile.txt
  15. profile! file */mru.vim
  16. endif
  17. source ../plugin/mru.vim
  18. " Function to log test results
  19. func! LogResult(test, result)
  20. call add(g:results, a:test . ': ' . a:result)
  21. endfunc
  22. " ==========================================================================
  23. " Test1
  24. " When the MRU list is empty, invoking the MRU command should return an error
  25. " ==========================================================================
  26. func Test_01()
  27. let test_name = 'test1'
  28. redir => msg
  29. MRU
  30. redir END
  31. if msg =~# "MRU file list is empty"
  32. call LogResult(test_name, 'pass')
  33. else
  34. call LogResult(test_name, 'FAIL')
  35. endif
  36. endfunc
  37. " ==========================================================================
  38. " Test2
  39. " Open the MRU window and check the order of files listed in the window
  40. " Open the MRU window when the window is already opened.
  41. " ==========================================================================
  42. func Test_02()
  43. let test_name = 'test2'
  44. edit file1.txt
  45. edit file2.txt
  46. edit file3.txt
  47. edit file2.txt
  48. edit file1.txt
  49. MRU
  50. MRU
  51. let l = getline(1, "$")
  52. if l[0] =~# "file1.txt" && l[1] =~# "file2.txt" && l[2] =~# "file3.txt"
  53. call LogResult(test_name, 'pass')
  54. else
  55. call LogResult(test_name, 'FAIL')
  56. endif
  57. endfunc
  58. " ==========================================================================
  59. " Test3
  60. " Select a file from the MRU window and check whether it is opened
  61. " ==========================================================================
  62. func Test_03()
  63. let test_name = 'test3'
  64. " Go to the last but one line
  65. $
  66. " Select the last file in the MRU window
  67. exe "normal \<Enter>"
  68. if fnamemodify(@%, ':p:t') !=# 'file3.txt'
  69. call LogResult(test_name, "FAIL (1)")
  70. else
  71. " Make sure the MRU window is closed
  72. if bufwinnr(g:MRU_buffer_name) == -1
  73. call LogResult(test_name, 'pass')
  74. else
  75. call LogResult(test_name, "FAIL (2)")
  76. endif
  77. endif
  78. endfunc
  79. " ==========================================================================
  80. " Test4
  81. " MRU opens a selected file in the previous/last window
  82. " ==========================================================================
  83. func Test_04()
  84. let test_name = 'test4'
  85. " Edit a file and then open a new window, open the MRU window and select the
  86. " file
  87. split file1.txt
  88. only
  89. below new
  90. MRU
  91. call search('file2.txt')
  92. exe "normal \<Enter>"
  93. if winnr() == 2
  94. call LogResult(test_name, 'pass')
  95. else
  96. call LogResult(test_name, 'FAIL')
  97. endif
  98. endfunc
  99. " ==========================================================================
  100. " Test5
  101. " MRU opens a selected file in the same window if the file is already opened
  102. " ==========================================================================
  103. func Test_05()
  104. let test_name = 'test5'
  105. edit file1.txt
  106. only
  107. below split file2.txt
  108. below split file3.txt
  109. MRU
  110. call search('file1.txt')
  111. exe "normal \<Enter>"
  112. if winnr() != 1 || fnamemodify(@%, ':p:t') !=# 'file1.txt'
  113. call LogResult(test_name, "FAIL (1)")
  114. else
  115. MRU
  116. call search('file2.txt')
  117. exe "normal \<Enter>"
  118. if winnr() != 2 || fnamemodify(@%, ':p:t') !=# 'file2.txt'
  119. call LogResult(test_name, "FAIL (2)")
  120. else
  121. MRU
  122. call search('file3.txt')
  123. exe "normal \<Enter>"
  124. if winnr() != 3 || fnamemodify(@%, ':p:t') !=# 'file3.txt'
  125. call LogResult(test_name, "FAIL (3)")
  126. else
  127. call LogResult(test_name, 'pass')
  128. endif
  129. endif
  130. endif
  131. endfunc
  132. " ==========================================================================
  133. " Test6
  134. " MRU opens a file selected with 'o' command in a new window
  135. " ==========================================================================
  136. func Test_06()
  137. let test_name = 'test6'
  138. enew | only
  139. edit file1.txt
  140. below new
  141. MRU
  142. normal o
  143. if winnr() == 3 && fnamemodify(@%, ':p:t') ==# 'file1.txt'
  144. call LogResult(test_name, 'pass')
  145. else
  146. call LogResult(test_name, 'FAIL')
  147. endif
  148. endfunc
  149. " ==========================================================================
  150. " Test7
  151. " MRU opens the selected file in a new window if the previous buffer is
  152. " modified.
  153. " ==========================================================================
  154. func Test_07()
  155. let test_name = 'test7'
  156. enew | only
  157. insert
  158. MRU plugin test
  159. .
  160. MRU
  161. call search('file3.txt')
  162. exe "normal \<Enter>"
  163. if winnr() == 1 && winnr('$') == 2 &&
  164. \ fnamemodify(@%, ':p:t') ==# 'file3.txt'
  165. call LogResult(test_name, 'pass')
  166. else
  167. call LogResult(test_name, 'FAIL')
  168. endif
  169. " Discard changes in the new buffer
  170. wincmd b
  171. enew!
  172. only
  173. endfunc
  174. " ==========================================================================
  175. " Test8
  176. " MRU opens a file selected with 'v' command in read-only mode in the current
  177. " window.
  178. " ==========================================================================
  179. func Test_08()
  180. let test_name = 'test8'
  181. enew | only
  182. MRU
  183. call search('file1.txt')
  184. normal v
  185. let r1 = &readonly
  186. MRU
  187. call search('file2.txt')
  188. exe "normal \<Enter>"
  189. let r2 = &readonly
  190. MRU
  191. call search('file1.txt')
  192. exe "normal \<Enter>"
  193. let r3 = &readonly
  194. if r1 == 1 && r2 == 0 && r3 == 1
  195. call LogResult(test_name, 'pass')
  196. else
  197. call LogResult(test_name, 'FAIL')
  198. endif
  199. endfunc
  200. " ==========================================================================
  201. " Test9
  202. " Use 'O' in the MRU window to open a file in a vertically split window
  203. " ==========================================================================
  204. func Test_09()
  205. let test_name = 'test9'
  206. enew | only
  207. edit file1.txt
  208. MRU
  209. call search('file2.txt')
  210. normal O
  211. let b1 = @%
  212. wincmd h
  213. let b2 = @%
  214. wincmd l
  215. let b3 = @%
  216. if winnr('$') == 2 && b1 ==# 'file2.txt' &&
  217. \ b2 ==# 'file1.txt' && b3 ==# 'file2.txt'
  218. call LogResult(test_name, 'pass')
  219. else
  220. call LogResult(test_name, 'FAIL')
  221. endif
  222. endfunc
  223. " ==========================================================================
  224. " Test10
  225. " Use 'p' in the MRU window to open a file in the preview window
  226. " ==========================================================================
  227. func Test_10()
  228. let test_name = 'test10'
  229. enew | only
  230. MRU
  231. call search('file3.txt')
  232. normal p
  233. wincmd P
  234. let p1 = &previewwindow
  235. let b1 = @%
  236. if winnr('$') == 2 && &previewwindow && @% =~# 'file3.txt'
  237. call LogResult(test_name, 'pass')
  238. else
  239. call LogResult(test_name, 'FAIL')
  240. endif
  241. pclose
  242. endfunc
  243. " ==========================================================================
  244. " Test11
  245. " MRU opens a file selected with 't' command in a new tab and the tab
  246. " is opened at the end
  247. " ==========================================================================
  248. func Test_11()
  249. let test_name = 'test11'
  250. enew | only
  251. edit a1.txt
  252. tabnew a2.txt
  253. tabnew a3.txt
  254. tabnew a4.txt
  255. tabfirst
  256. MRU
  257. call search('file3.txt')
  258. normal t
  259. if fnamemodify(@%, ':p:t') ==# 'file3.txt' && tabpagenr() == 5
  260. call LogResult(test_name, 'pass')
  261. else
  262. call LogResult(test_name, 'FAIL')
  263. call LogResult(test_name, "file = " . fnamemodify(@%, ':p:t'))
  264. call LogResult(test_name, "tab page = " . tabpagenr())
  265. endif
  266. tabonly
  267. endfunc
  268. " ==========================================================================
  269. " Test12
  270. " The 'q' command closes the MRU window
  271. " ==========================================================================
  272. func Test_12()
  273. let test_name = 'test12'
  274. enew | only
  275. MRU
  276. normal q
  277. if bufwinnr(g:MRU_buffer_name) == -1
  278. call LogResult(test_name, 'pass')
  279. else
  280. call LogResult(test_name, 'FAIL')
  281. endif
  282. endfunc
  283. " ==========================================================================
  284. " Test13
  285. " A selected file is opened in a new window if the previous window is a
  286. " preview window
  287. " ==========================================================================
  288. func Test_13()
  289. let test_name = 'test13'
  290. enew | only
  291. setlocal previewwindow
  292. MRU
  293. call search('file2.txt')
  294. exe "normal \<Enter>"
  295. if winnr() == 1 && winnr('$') == 2 &&
  296. \ &previewwindow == 0 &&
  297. \ fnamemodify(@%, ':p:t') ==# 'file2.txt'
  298. call LogResult(test_name, 'pass')
  299. else
  300. call LogResult(test_name, 'FAIL')
  301. endif
  302. " Close the preview window created by this test
  303. new
  304. only
  305. endfunc
  306. " ==========================================================================
  307. " Test14
  308. " A selected file is opened in a new window if the previous window contains
  309. " a special buffer (used by some other plugin)
  310. " ==========================================================================
  311. func Test_14()
  312. let test_name = 'test14'
  313. enew | only
  314. setlocal buftype=nofile
  315. MRU
  316. call search('file3.txt')
  317. exe "normal \<Enter>"
  318. if winnr() == 1 && winnr('$') == 2 &&
  319. \ &buftype == '' &&
  320. \ fnamemodify(@%, ':p:t') ==# 'file3.txt'
  321. call LogResult(test_name, 'pass')
  322. else
  323. call LogResult(test_name, 'FAIL')
  324. endif
  325. " Discard the special buffer
  326. enew
  327. endfunc
  328. " ==========================================================================
  329. " Test15
  330. " If a file selected using the 't' command is already opened in a tab,
  331. " then jump to that tab (instead of opening a new tab)
  332. " ==========================================================================
  333. func Test_15()
  334. let test_name = 'test15'
  335. enew | only
  336. " Open the test files in the middle window with empty windows at the top and
  337. " bottom
  338. edit file1.txt
  339. above new
  340. botright new
  341. tabedit file2.txt
  342. above new
  343. botright new
  344. tabedit file3.txt
  345. above new
  346. botright new
  347. tabfirst
  348. MRU
  349. call search('file3.txt')
  350. exe "normal t"
  351. if tabpagenr() != 3
  352. \ || fnamemodify(@%, ':p:t') !=# 'file3.txt'
  353. \ || winnr() != 2
  354. call LogResult(test_name, "FAIL (1)")
  355. else
  356. MRU
  357. call search('file1.txt')
  358. exe "normal t"
  359. if tabpagenr() != 1
  360. \ || fnamemodify(@%, ':p:t') !=# 'file1.txt'
  361. \ || winnr() != 2
  362. call LogResult(test_name, "FAIL (2)")
  363. else
  364. MRU
  365. call search('file2.txt')
  366. exe "normal t"
  367. if tabpagenr() != 2
  368. \ || fnamemodify(@%, ':p:t') !=# 'file2.txt'
  369. \ || winnr() != 2
  370. call LogResult(test_name, "FAIL (3)")
  371. else
  372. call LogResult(test_name, 'pass')
  373. endif
  374. endif
  375. endif
  376. " Close all the other tabs
  377. tabonly
  378. enew
  379. only
  380. endfunc
  381. " ==========================================================================
  382. " Test16
  383. " Open multiple files from the MRU window using the visual mode and by using a
  384. " count. Each file should be opened in a separate window.
  385. " ==========================================================================
  386. func Test_16()
  387. let test_name = 'test16'
  388. enew | only
  389. edit file3.txt
  390. edit file2.txt
  391. edit file1.txt
  392. enew
  393. MRU
  394. exe "normal 3\<Enter>"
  395. if winnr('$') == 3 &&
  396. \ bufwinnr('file3.txt') == 1 &&
  397. \ bufwinnr('file2.txt') == 2 &&
  398. \ bufwinnr('file1.txt') == 3
  399. let test_result = 'pass'
  400. else
  401. let test_result = 'FAIL'
  402. endif
  403. only | enew
  404. if test_result == 'pass'
  405. MRU
  406. exe "normal V2j\<Enter>"
  407. if winnr('$') == 3 &&
  408. \ bufwinnr('file1.txt') == 1 &&
  409. \ bufwinnr('file2.txt') == 2 &&
  410. \ bufwinnr('file3.txt') == 3
  411. let test_result = 'pass'
  412. else
  413. let test_result = 'FAIL'
  414. endif
  415. endif
  416. if test_result == 'pass'
  417. call LogResult(test_name, 'pass')
  418. else
  419. call LogResult(test_name, 'FAIL')
  420. endif
  421. endfunc
  422. " ==========================================================================
  423. " Test17
  424. " When the MRU list is updated, the MRU file also should updated.
  425. " ==========================================================================
  426. func Test_17()
  427. let test_name = 'test17'
  428. enew | only
  429. edit file1.txt
  430. let l = readfile(g:MRU_File)
  431. if l[1] =~# 'file1.txt'
  432. edit file2.txt
  433. let l = readfile(g:MRU_File)
  434. if l[1] =~# 'file2.txt'
  435. edit file3.txt
  436. let l = readfile(g:MRU_File)
  437. if l[1] =~# 'file3.txt'
  438. call LogResult(test_name, 'pass')
  439. else
  440. call LogResult(test_name, "FAIL (3)")
  441. endif
  442. else
  443. call LogResult(test_name, "FAIL (2)")
  444. endif
  445. else
  446. call LogResult(test_name, "FAIL (1)")
  447. endif
  448. endfunc
  449. " MRU_Test_Add_Files
  450. " Add the supplied List of files to the beginning of the MRU file
  451. func! s:MRU_Test_Add_Files(fnames)
  452. let l = readfile(g:MRU_File)
  453. call extend(l, a:fnames, 1)
  454. call writefile(l, g:MRU_File)
  455. endfunc
  456. " ==========================================================================
  457. " Test18
  458. " When the MRU file is updated by another Vim instance, the MRU plugin
  459. " should update the MRU list
  460. " ==========================================================================
  461. func Test_18()
  462. let test_name = 'test18'
  463. enew | only
  464. call s:MRU_Test_Add_Files(['/software/editors/vim',
  465. \ '/software/editors/emacs',
  466. \ '/software/editors/nano'])
  467. MRU
  468. if getline(1) ==# 'vim (/software/editors/vim)'
  469. \ && getline(2) ==# 'emacs (/software/editors/emacs)'
  470. \ && getline(3) ==# 'nano (/software/editors/nano)'
  471. call LogResult(test_name, 'pass')
  472. else
  473. call LogResult(test_name, 'FAIL')
  474. endif
  475. " Close the MRU window
  476. close
  477. endfunc
  478. " ==========================================================================
  479. " Test19
  480. " When the MRU file is updated by another Vim instance, the MRU file names
  481. " from the current instance should be merged with that list
  482. " ==========================================================================
  483. func Test_19()
  484. let test_name = 'test19'
  485. enew | only
  486. " Remove all the files from the MRU file
  487. let l = readfile(g:MRU_File)
  488. call remove(l, 1, -1)
  489. call writefile(l, g:MRU_File)
  490. edit file1.txt
  491. call s:MRU_Test_Add_Files(['/software/os/unix'])
  492. edit file2.txt
  493. call s:MRU_Test_Add_Files(['/software/os/windows'])
  494. edit file3.txt
  495. call s:MRU_Test_Add_Files(['/software/os/osx'])
  496. MRU
  497. if getline(1) ==# 'osx (/software/os/osx)'
  498. \ && getline(2) =~# 'file3.txt'
  499. \ && getline(3) ==# 'windows (/software/os/windows)'
  500. \ && getline(4) =~# 'file2.txt'
  501. \ && getline(5) ==# 'unix (/software/os/unix)'
  502. \ && getline(6) =~# 'file1.txt'
  503. call LogResult(test_name, 'pass')
  504. else
  505. call LogResult(test_name, 'FAIL')
  506. endif
  507. close
  508. endfunc
  509. " ==========================================================================
  510. " Test20
  511. " When the MRU list has more than g:MRU_Max_Entries, the list should be
  512. " trimmed. The last entries should be removed.
  513. " ==========================================================================
  514. func Test_20()
  515. let test_name = 'test20'
  516. enew | only
  517. " Create a MRU list with MRU_Max_Entries
  518. let flist = []
  519. for i in range(1, g:MRU_Max_Entries)
  520. let flist += ['/usr/share/mru_test/mru_file' . i . '.abc']
  521. endfor
  522. " Modify the MRU file to contain max entries
  523. let l = readfile(g:MRU_File)
  524. call remove(l, 1, -1)
  525. call extend(l, flist)
  526. call writefile(l, g:MRU_File)
  527. enew
  528. edit file1.txt
  529. let l = readfile(g:MRU_File)
  530. if len(l) == (g:MRU_Max_Entries + 1) &&
  531. \ l[g:MRU_Max_Entries] != '/usr/share/mru_test/mru_file9.abc'
  532. call LogResult(test_name, "FAIL (1)")
  533. else
  534. edit file2.txt
  535. let l = readfile(g:MRU_File)
  536. if len(l) == (g:MRU_Max_Entries + 1) &&
  537. \ l[g:MRU_Max_Entries] != '/usr/share/mru_test/mru_file8.abc'
  538. call LogResult(test_name, "FAIL (2)")
  539. else
  540. edit file3.txt
  541. let l = readfile(g:MRU_File)
  542. if len(l) == (g:MRU_Max_Entries + 1) &&
  543. \ l[g:MRU_Max_Entries] != '/usr/share/mru_test/mru_file7.abc'
  544. call LogResult(test_name, "FAIL (3)")
  545. else
  546. call LogResult(test_name, 'pass')
  547. endif
  548. endif
  549. endif
  550. endfunc
  551. " ==========================================================================
  552. " Test21
  553. " When an filename (already present in the MRU list) is specified to the MRU
  554. " command, it should edit the file.
  555. " ==========================================================================
  556. func Test_21()
  557. let test_name = 'test21'
  558. enew | only
  559. edit file1.txt
  560. edit file2.txt
  561. edit file3.txt
  562. enew
  563. MRU file2.txt
  564. if fnamemodify(@%, ':p:t') ==# 'file2.txt' && winnr('$') == 1
  565. call LogResult(test_name, 'pass')
  566. else
  567. call LogResult(test_name, 'FAIL')
  568. endif
  569. endfunc
  570. " ==========================================================================
  571. " Test22
  572. " When a pattern (matching multiple filenames) is specified to the MRU
  573. " command, then the MRU window should be opened with all the matching
  574. " filenames
  575. " ==========================================================================
  576. func Test_22()
  577. let test_name = 'test22'
  578. enew | only
  579. edit file1.txt
  580. edit file2.txt
  581. edit file3.txt
  582. only
  583. MRU file.*
  584. if @% != g:MRU_buffer_name
  585. call LogResult(test_name, 'FAIL')
  586. else
  587. let l = getline(1, "$")
  588. if l[0] =~# "file3.txt" && l[1] =~# "file2.txt" && l[2] =~# "file1.txt"
  589. call LogResult(test_name, 'pass')
  590. else
  591. call LogResult(test_name, 'FAIL')
  592. endif
  593. endif
  594. close
  595. endfunc
  596. " ==========================================================================
  597. " Test23
  598. " When a partial filename (matching multiple filenames) is specified to the
  599. " MRU command, then the MRU window should be opened with all the matching
  600. " filenames
  601. " ==========================================================================
  602. func Test_23()
  603. let test_name = 'test23'
  604. enew | only
  605. let g:MRU_FuzzyMatch = 0
  606. edit file1.txt
  607. edit file2.txt
  608. edit file3.txt
  609. only
  610. MRU file
  611. if @% != g:MRU_buffer_name
  612. call LogResult(test_name, 'FAIL')
  613. else
  614. let l = getline(1, "$")
  615. if l[0] =~# "file3.txt" && l[1] =~# "file2.txt" && l[2] =~# "file1.txt"
  616. call LogResult(test_name, 'pass')
  617. else
  618. call LogResult(test_name, 'FAIL')
  619. endif
  620. endif
  621. close
  622. endfunc
  623. " ==========================================================================
  624. " Test24
  625. " When a non-existing filename is specified to the MRU command, an error
  626. " message should be displayed.
  627. " ==========================================================================
  628. func Test_24()
  629. let test_name = 'test24'
  630. let g:MRU_FuzzyMatch = 0
  631. redir => msg
  632. MRU nonexistingfile.txt
  633. redir END
  634. if @% == g:MRU_buffer_name ||
  635. \ msg !~# "MRU file list doesn't contain files " .
  636. \ "matching nonexistingfile.txt"
  637. call LogResult(test_name, 'FAIL')
  638. else
  639. call LogResult(test_name, 'pass')
  640. endif
  641. endfunc
  642. " ==========================================================================
  643. " Test25
  644. " The MRU command should support filename completion. Supply a partial file
  645. " name to the MRU command and complete the filenames.
  646. " ==========================================================================
  647. func Test_25()
  648. let test_name = 'test25'
  649. enew | only
  650. edit file1.txt
  651. edit file2.txt
  652. edit file3.txt
  653. exe 'normal! :MRU file' . "\<C-A>" . "\<Home>let m='\<End>'\<CR>"
  654. let fnames = split(m)
  655. if fnames[1] =~# 'file3.txt' && fnames[2] =~# 'file2.txt' &&
  656. \ fnames[3] =~# 'file1.txt'
  657. call LogResult(test_name, 'pass')
  658. else
  659. call LogResult(test_name, 'FAIL')
  660. endif
  661. endfunc
  662. " ==========================================================================
  663. " Test26
  664. " When trying to complete filenames for the MRU command without specifying
  665. " any text should return the entire MRU list.
  666. " ==========================================================================
  667. func Test_26()
  668. let test_name = 'test26'
  669. enew | only
  670. call delete(g:MRU_File)
  671. edit file1.txt
  672. edit file2.txt
  673. edit file3.txt
  674. exe 'normal! :MRU ' . "\<C-A>" . "\<Home>let m='\<End>'\<CR>"
  675. let fnames = split(m)
  676. if fnames[1] =~# 'file3.txt' && fnames[2] =~# 'file2.txt' &&
  677. \ fnames[3] =~# 'file1.txt'
  678. call LogResult(test_name, 'pass')
  679. else
  680. call LogResult(test_name, 'FAIL')
  681. endif
  682. endfunc
  683. " ==========================================================================
  684. " Test27
  685. " When the current file/buffer has unsaved changes, MRU should open a selected
  686. " file in a new window (if the 'hidden' option is not set)
  687. " ==========================================================================
  688. func Test_27()
  689. let test_name = 'test27'
  690. enew | only
  691. edit file1.txt
  692. edit file2.txt
  693. call append(line('$'), 'Temporary changes to buffer')
  694. MRU
  695. call search('file1.txt')
  696. exe "normal \<Enter>"
  697. if winnr() == 1 && winnr('$') == 2 &&
  698. \ fnamemodify(@%, ':p:t') ==# 'file1.txt'
  699. call LogResult(test_name, 'pass')
  700. else
  701. call LogResult(test_name, 'FAIL')
  702. endif
  703. close
  704. edit!
  705. endfunc
  706. " ==========================================================================
  707. " Test28
  708. " When the current file/buffer has unsaved changes and the 'hidden' option is
  709. " set, then MRU should open a selected file in the current window
  710. " ==========================================================================
  711. func Test_28()
  712. let test_name = 'test28'
  713. enew | only
  714. edit file2.txt
  715. edit file1.txt
  716. call append(line('$'), 'Temporary changes to buffer')
  717. set hidden
  718. MRU
  719. call search('file2.txt')
  720. exe "normal \<Enter>"
  721. if winnr('$') == 1 &&
  722. \ fnamemodify(@%, ':p:t') ==# 'file2.txt'
  723. call LogResult(test_name, 'pass')
  724. else
  725. call LogResult(test_name, 'FAIL')
  726. endif
  727. edit file1.txt
  728. edit!
  729. set nohidden
  730. %bw!
  731. endfunc
  732. " ==========================================================================
  733. " Test29
  734. " Every edited file is added to the top of the MRU list. If a file is already
  735. " present in the MRU list, then it is moved to the top of the list.
  736. " ==========================================================================
  737. func Test_29()
  738. let test_name = 'test29'
  739. enew | only
  740. edit file1.txt
  741. let f1 = readfile(g:MRU_File, '', 2)
  742. edit file2.txt
  743. let f2 = readfile(g:MRU_File, '', 2)
  744. edit file3.txt
  745. let f3 = readfile(g:MRU_File, '', 2)
  746. edit file1.txt
  747. let f4 = readfile(g:MRU_File, '', 2)
  748. if f1[1] =~# 'file1.txt' && f2[1] =~# 'file2.txt' && f3[1] =~# 'file3.txt' &&
  749. \ f4[1] =~# 'file1.txt'
  750. call LogResult(test_name, 'pass')
  751. else
  752. call LogResult(test_name, 'FAIL')
  753. endif
  754. endfunc
  755. " ==========================================================================
  756. " Test30
  757. " Only file names matching the regular expression in the MRU_Include_Files
  758. " variable should be added to the MRU list.
  759. " ==========================================================================
  760. func Test_30()
  761. let test_name = 'test30'
  762. enew | only
  763. edit file1.txt
  764. let g:MRU_Include_Files='\.c'
  765. edit abc.c
  766. let f1 = readfile(g:MRU_File, '', 2)
  767. edit file1.txt
  768. let f2 = readfile(g:MRU_File, '', 2)
  769. edit def.c
  770. let f3 = readfile(g:MRU_File, '', 2)
  771. if f1[1] =~# 'abc.c' && f2[1] =~# 'abc.c' && f3[1] =~# 'def.c'
  772. call LogResult(test_name, 'pass')
  773. else
  774. call LogResult(test_name, 'FAIL')
  775. endif
  776. let g:MRU_Include_Files=''
  777. endfunc
  778. " ==========================================================================
  779. " Test31
  780. " File names matching the regular expression in the MRU_Exclude_Files
  781. " variable should not be added to the MRU list.
  782. " ==========================================================================
  783. func Test_31()
  784. let test_name = 'test31'
  785. enew | only
  786. let g:MRU_Exclude_Files='\.txt'
  787. edit abc.c
  788. let f1 = readfile(g:MRU_File, '', 2)
  789. edit file1.txt
  790. edit file2.txt
  791. edit file3.txt
  792. let f2 = readfile(g:MRU_File, '', 2)
  793. edit def.c
  794. let f3 = readfile(g:MRU_File, '', 2)
  795. let g:MRU_Exclude_Files=''
  796. edit file1.txt
  797. let f4 = readfile(g:MRU_File, '', 2)
  798. if f1[1] =~# 'abc.c' && f2[1] =~# 'abc.c' && f3[1] =~# 'def.c' &&
  799. \ f4[1] =~# 'file1.txt'
  800. call LogResult(test_name, 'pass')
  801. else
  802. call LogResult(test_name, 'FAIL')
  803. endif
  804. endfunc
  805. " ==========================================================================
  806. " Test32
  807. " If the MRU window is open, when adding a file name to the list, the MRU
  808. " window should be refreshed.
  809. " ==========================================================================
  810. func Test_32()
  811. let test_name = 'test32'
  812. enew | only
  813. MRU
  814. wincmd p
  815. edit abc.c
  816. wincmd p
  817. let s1 = getline(1)
  818. wincmd p
  819. edit file1.txt
  820. wincmd p
  821. let s2 = getline(1)
  822. close
  823. if s1 =~# 'abc.c' && s2 =~# 'file1.txt'
  824. call LogResult(test_name, 'pass')
  825. else
  826. call LogResult(test_name, 'FAIL')
  827. endif
  828. endfunc
  829. " ==========================================================================
  830. " Test33
  831. " When MRU_Use_Current_Window is set, the MRU list should be displayed in
  832. " the current window.
  833. " Selecting a file from the MRU window should replace
  834. " the MRU buffer with the selected file.
  835. " ==========================================================================
  836. func Test_33()
  837. let test_name = 'test33'
  838. enew | only
  839. edit file1.txt
  840. let g:MRU_Use_Current_Window=1
  841. MRU
  842. if winnr('$') == 1 && @% == g:MRU_buffer_name
  843. call LogResult(test_name, 'pass')
  844. else
  845. call LogResult(test_name, 'FAIL')
  846. endif
  847. let g:MRU_Use_Current_Window=0
  848. endfunc
  849. " ==========================================================================
  850. " Test34
  851. " When MRU_Use_Current_Window is set, selecting a file from the MRU window
  852. " should replace the MRU buffer with the selected file.
  853. " ==========================================================================
  854. func Test_34()
  855. let test_name = 'test34'
  856. enew | only
  857. let g:MRU_Use_Current_Window=1
  858. let w:marker=1
  859. MRU
  860. if winnr('$') == 1 && w:marker && @% == g:MRU_buffer_name
  861. call search('file2.txt')
  862. exe "normal \<Enter>"
  863. if winnr('$') == 1 && w:marker && @% == 'file2.txt'
  864. call LogResult(test_name, 'pass')
  865. else
  866. call LogResult(test_name, 'FAIL')
  867. endif
  868. else
  869. call LogResult(test_name, 'FAIL')
  870. endif
  871. unlet w:marker
  872. let g:MRU_Use_Current_Window=0
  873. endfunc
  874. " ==========================================================================
  875. " Test35
  876. " When MRU_Use_Current_Window is set, if the current buffer has unsaved
  877. " changes, then the MRU window should be opened in a split window
  878. " ==========================================================================
  879. func Test_35()
  880. let test_name = 'test35'
  881. enew | only
  882. let g:MRU_Use_Current_Window=1
  883. set modified
  884. MRU
  885. if winnr('$') == 2 && winnr() == 2 && @% == g:MRU_buffer_name
  886. call LogResult(test_name, 'pass')
  887. else
  888. call LogResult(test_name, 'FAIL')
  889. endif
  890. close
  891. set nomodified
  892. let g:MRU_Use_Current_Window=0
  893. enew | only
  894. endfunc
  895. " ==========================================================================
  896. " Test36
  897. " When MRU_Auto_Close is not set, the MRU window should not automatically
  898. " close when a file is selected. The MRU window should be kept open.
  899. " ==========================================================================
  900. func Test_36()
  901. let test_name = 'test36'
  902. enew | only
  903. let g:MRU_Auto_Close=0
  904. new
  905. MRU
  906. call search('file1.txt')
  907. exe "normal \<Enter>"
  908. 2wincmd w
  909. MRU
  910. call search('file2.txt')
  911. exe "normal \<Enter>"
  912. if winnr('$') == 3 &&
  913. \ bufwinnr('file1.txt') == 1 &&
  914. \ bufwinnr('file2.txt') == 2 &&
  915. \ bufwinnr(g:MRU_buffer_name) == 3
  916. call LogResult(test_name, 'pass')
  917. else
  918. call LogResult(test_name, 'FAIL')
  919. endif
  920. wincmd b
  921. close
  922. let g:MRU_Auto_Close=1
  923. only
  924. endfunc
  925. " ==========================================================================
  926. " Test37
  927. " When MRU_Open_File_Use_Tabs is set, a selected file should be opened in a
  928. " tab. If the file is already opened in a tab, then the focus should be moved
  929. " to that tab.
  930. " ==========================================================================
  931. func Test_37()
  932. let test_name = 'test37'
  933. enew | only
  934. let g:MRU_Open_File_Use_Tabs=1
  935. edit file1.txt
  936. MRU
  937. call search('file2.txt')
  938. exe "normal \<Enter>"
  939. MRU
  940. call search('file3.txt')
  941. exe "normal \<Enter>"
  942. MRU file1.txt
  943. let t1 = tabpagenr()
  944. MRU
  945. call search('file2.txt')
  946. exe "normal \<Enter>"
  947. let t2 = tabpagenr()
  948. MRU
  949. call search('file3.txt')
  950. exe "normal \<Enter>"
  951. let t3 = tabpagenr()
  952. tabonly | enew
  953. if t1 == 1 && t2 == 2 && t3 == 3
  954. call LogResult(test_name, 'pass')
  955. else
  956. call LogResult(test_name, 'FAIL')
  957. endif
  958. let g:MRU_Open_File_Use_Tabs=0
  959. endfunc
  960. " ==========================================================================
  961. " Test38
  962. " If the MRU_Window_Open_Always is set to 0, when the MRU command finds a
  963. " single matching file name, then it should open the MRU window. If this
  964. " variable is set to 1, then the file should be opened without opening the MRU
  965. " window.
  966. " ==========================================================================
  967. func Test_38()
  968. let test_name = 'test38'
  969. enew | only
  970. edit file3.txt
  971. enew
  972. let g:MRU_Window_Open_Always=1
  973. MRU file3.txt
  974. if winnr('$') == 2 &&
  975. \ bufwinnr(g:MRU_buffer_name) == 2
  976. let test_result = 'pass'
  977. else
  978. let test_result = 'FAIL'
  979. endif
  980. close
  981. enew | only
  982. if test_result == 'pass'
  983. let g:MRU_Window_Open_Always=0
  984. MRU file3.txt
  985. if winnr('$') == 1 &&
  986. \ bufwinnr('file3.txt') == 1
  987. let test_result = 'pass'
  988. else
  989. let test_result = 'FAIL'
  990. endif
  991. endif
  992. let g:MRU_Window_Open_Always=0
  993. if test_result == 'pass'
  994. call LogResult(test_name, 'pass')
  995. else
  996. call LogResult(test_name, 'FAIL')
  997. endif
  998. endfunc
  999. " ==========================================================================
  1000. " Test39
  1001. " If the current tabpage is empty, then pressing 't' in the MRU window
  1002. " should open the file in the current tabpage.
  1003. " ==========================================================================
  1004. func Test_39()
  1005. let test_name = 'test39'
  1006. enew | only | tabonly
  1007. tabnew
  1008. tabnew
  1009. tabnext 2
  1010. MRU
  1011. call search('file2.txt')
  1012. normal t
  1013. if fnamemodify(@%, ':p:t') ==# 'file2.txt' && tabpagenr() == 2
  1014. call LogResult(test_name, 'pass')
  1015. else
  1016. call LogResult(test_name, 'FAIL')
  1017. call LogResult(test_name, "file = " . fnamemodify(@%, ':p:t'))
  1018. call LogResult(test_name, "tab page = " . tabpagenr())
  1019. endif
  1020. tabonly
  1021. endfunc
  1022. " ==========================================================================
  1023. " Test40
  1024. " Pressing 'd' in the MRU window should delete the file under the cursor
  1025. " from the MRU list
  1026. " ==========================================================================
  1027. func Test_40()
  1028. let test_name = 'test40'
  1029. edit file2.txt
  1030. enew
  1031. MRU
  1032. call search('file2.txt')
  1033. normal d
  1034. close
  1035. let l = readfile(g:MRU_File)
  1036. if match(l, 'file2.txt') == -1
  1037. call LogResult(test_name, 'pass')
  1038. else
  1039. call LogResult(test_name, 'FAIL')
  1040. endif
  1041. endfunc
  1042. " ==========================================================================
  1043. " Test41
  1044. " Running the :vimgrep command should not add the files to the MRU list
  1045. " ==========================================================================
  1046. func Test_41()
  1047. let test_name = 'test41'
  1048. call writefile(['bright'], 'dummy1.txt')
  1049. call writefile(['bright'], 'dummy2.txt')
  1050. vimgrep /bright/j dummy*
  1051. let l = readfile(g:MRU_File)
  1052. if match(l, 'dummy') == -1
  1053. call LogResult(test_name, 'pass')
  1054. else
  1055. call LogResult(test_name, 'FAIL')
  1056. endif
  1057. call delete('dummy1.txt')
  1058. call delete('dummy2.txt')
  1059. endfunc
  1060. " ==========================================================================
  1061. " Test42
  1062. " Using a command modifier with the MRU command to open the MRU window
  1063. " ==========================================================================
  1064. func Test_42()
  1065. if v:version < 800
  1066. " The <mods> command modifier is supported only by Vim 8.0 and above
  1067. return
  1068. endif
  1069. let test_name = 'test42'
  1070. enew | only
  1071. topleft MRU
  1072. if winnr() == 1 && winnr('$') == 2
  1073. call LogResult(test_name, 'pass')
  1074. else
  1075. call LogResult(test_name, 'FAIL')
  1076. endif
  1077. enew | only
  1078. botright MRU
  1079. if winnr() == 2 && winnr('$') == 2
  1080. call LogResult(test_name, 'pass')
  1081. else
  1082. call LogResult(test_name, 'FAIL')
  1083. endif
  1084. enew | only
  1085. botright MRU
  1086. if winnr() == 2 && winnr('$') == 2
  1087. call LogResult(test_name, 'pass')
  1088. else
  1089. call LogResult(test_name, 'FAIL')
  1090. endif
  1091. enew | only
  1092. endfunc
  1093. " ==========================================================================
  1094. " Test43
  1095. " Opening a file using the MRU command should jump to the window containing
  1096. " the file (if it is already opened).
  1097. " ==========================================================================
  1098. func Test_43()
  1099. let test_name = 'test43'
  1100. only
  1101. edit file3.txt
  1102. below split file2.txt
  1103. below split file1.txt
  1104. wincmd t
  1105. MRU file1.txt
  1106. if winnr() != 3 || fnamemodify(@%, ':p:t') !=# 'file1.txt'
  1107. call LogResult(test_name, 'FAIL (1)')
  1108. else
  1109. MRU file2.txt
  1110. if winnr() != 2 && fnamemodify(@%, ':p:t') !=# 'file2.txt'
  1111. call LogResult(test_name, 'FAIL (2)')
  1112. else
  1113. MRU file3.txt
  1114. if winnr() != 1 && fnamemodify(@%, ':p:t') !=# 'file3.txt'
  1115. call LogResult(test_name, 'FAIL (3)')
  1116. else
  1117. call LogResult(test_name, 'pass')
  1118. endif
  1119. endif
  1120. endif
  1121. enew | only
  1122. endfunc
  1123. " ==========================================================================
  1124. " Test44
  1125. " Opening a file using the MRU command should open the file in a new window if
  1126. " the current buffer has unsaved changes.
  1127. " ==========================================================================
  1128. func Test_44()
  1129. let test_name = 'test44'
  1130. only
  1131. set modified
  1132. MRU file2.txt
  1133. if winnr('$') == 2 && winnr() == 1 &&
  1134. \ fnamemodify(@%, ':p:t') ==# 'file2.txt'
  1135. call LogResult(test_name, 'pass')
  1136. else
  1137. call LogResult(test_name, 'FAIL')
  1138. endif
  1139. close
  1140. set nomodified
  1141. endfunc
  1142. " ==========================================================================
  1143. " Test45
  1144. " Opening a file from the MRU window using 'v' should open the file in a new
  1145. " window if the current buffer has unsaved changes.
  1146. " ==========================================================================
  1147. func Test_45()
  1148. let test_name = 'test45'
  1149. only
  1150. set modified
  1151. MRU
  1152. call search('file3.txt')
  1153. normal v
  1154. if winnr('$') == 2 && winnr() == 1
  1155. \ && fnamemodify(@%, ':p:t') ==# 'file3.txt'
  1156. \ && &readonly
  1157. call LogResult(test_name, 'pass')
  1158. else
  1159. call LogResult(test_name, 'FAIL')
  1160. endif
  1161. close
  1162. set nomodified
  1163. endfunc
  1164. " ==========================================================================
  1165. " Test46
  1166. " Specify a count to the :MRU command to set the MRU window height/width
  1167. " ==========================================================================
  1168. func Test_46()
  1169. let test_name = 'test46'
  1170. only
  1171. " default height is 8
  1172. MRU
  1173. if winnr() != 2 || winheight(0) != 8
  1174. call LogResult(test_name, 'FAIL (1)')
  1175. return
  1176. endif
  1177. close
  1178. " use a specific height value
  1179. 15MRU
  1180. if winnr() != 2 || winheight(0) != 15
  1181. call LogResult(test_name, 'FAIL (2)')
  1182. return
  1183. endif
  1184. close
  1185. if v:version >= 800
  1186. " use a specific height value with a command modifier
  1187. topleft 12MRU
  1188. if winnr() != 1 || winheight(0) != 12
  1189. call LogResult(test_name, 'FAIL (3)')
  1190. return
  1191. endif
  1192. close
  1193. " check for the width (leftmost window)
  1194. vertical topleft 20MRU
  1195. if winnr() != 1 || winwidth(0) != 20
  1196. call LogResult(test_name, 'FAIL (4)')
  1197. return
  1198. endif
  1199. close
  1200. " check for the width (rightmost window)
  1201. vertical botright 25MRU
  1202. if winnr() != 2 || winwidth(0) != 25
  1203. call LogResult(test_name, 'FAIL (5)')
  1204. return
  1205. endif
  1206. close
  1207. endif
  1208. call LogResult(test_name, 'pass')
  1209. endfunc
  1210. " ==========================================================================
  1211. " Test47
  1212. " The height of the MRU window should be MRU_Window_Height
  1213. " ==========================================================================
  1214. func Test_47()
  1215. let test_name = 'test47'
  1216. only
  1217. " default height is 8
  1218. MRU
  1219. if winheight(0) != 8
  1220. call LogResult(test_name, 'FAIL (1)')
  1221. return
  1222. endif
  1223. close
  1224. let g:MRU_Window_Height = 2
  1225. MRU
  1226. if winheight(0) != 2
  1227. call LogResult(test_name, 'FAIL (2)')
  1228. return
  1229. endif
  1230. close
  1231. let g:MRU_Window_Height = 12
  1232. MRU
  1233. if winheight(0) != 12
  1234. call LogResult(test_name, 'FAIL (3)')
  1235. return
  1236. endif
  1237. close
  1238. call LogResult(test_name, 'pass')
  1239. let g:MRU_Window_Height = 8
  1240. endfunc
  1241. " ==========================================================================
  1242. " Test48
  1243. " Fuzzy search file names with MRU_FuzzyMatch set to 1.
  1244. " ==========================================================================
  1245. func Test_48()
  1246. if !exists('*matchfuzzy')
  1247. return
  1248. endif
  1249. let test_name = 'test48'
  1250. enew | only
  1251. let g:MRU_FuzzyMatch = 1
  1252. MRU F1
  1253. if fnamemodify(@%, ':p:t') ==# 'file1.txt' && winnr('$') == 1
  1254. call LogResult(test_name, 'pass')
  1255. else
  1256. call LogResult(test_name, 'FAIL (1)')
  1257. endif
  1258. let g:MRU_FuzzyMatch = 0
  1259. redir => msg
  1260. MRU F1
  1261. redir END
  1262. if msg =~# "MRU file list doesn't contain files matching F1"
  1263. call LogResult(test_name, 'pass')
  1264. else
  1265. call LogResult(test_name, 'FAIL (2)')
  1266. endif
  1267. let g:MRU_FuzzyMatch = 1
  1268. endfunc
  1269. " ==========================================================================
  1270. " Test49
  1271. " Test for creating a new file by saving an unnamed buffer.
  1272. " ==========================================================================
  1273. func Test_49()
  1274. let test_name = 'test49'
  1275. enew | only
  1276. call setline(1, 'sample file')
  1277. write sample.txt
  1278. let l = readfile(g:MRU_File)
  1279. if match(l, 'sample.txt') != -1
  1280. call LogResult(test_name, 'pass')
  1281. else
  1282. call LogResult(test_name, 'FAIL')
  1283. endif
  1284. call delete('sample.txt')
  1285. bwipe sample.txt
  1286. endfunc
  1287. " ==========================================================================
  1288. " Test50
  1289. " Test for the MruGetFiles() function
  1290. " ==========================================================================
  1291. func Test_50()
  1292. let test_name = 'test50'
  1293. enew | only
  1294. let list1 = MruGetFiles()
  1295. let list2 = readfile(g:MRU_File)
  1296. if list1 != list2[1:]
  1297. call LogResult(test_name, 'FAIL 1')
  1298. return
  1299. endif
  1300. if MruGetFiles('x1y2z3') == []
  1301. call LogResult(test_name, 'pass')
  1302. else
  1303. call LogResult(test_name, 'FAIL 2')
  1304. endif
  1305. endfunc
  1306. " ==========================================================================
  1307. " Test51
  1308. " Test for the :MruRefresh command
  1309. " ==========================================================================
  1310. func Test_51()
  1311. let test_name = 'test51'
  1312. enew | only
  1313. if match(MruGetFiles(), 'sample.txt') == -1
  1314. call LogResult(test_name, 'FAIL 1')
  1315. return
  1316. endif
  1317. MruRefresh
  1318. if match(MruGetFiles(), 'sample.txt') == -1
  1319. call LogResult(test_name, 'pass')
  1320. else
  1321. call LogResult(test_name, 'FAIL 2')
  1322. endif
  1323. endfunc
  1324. " ==========================================================================
  1325. " Create the files used by the tests
  1326. call writefile(['MRU test file1'], 'file1.txt')
  1327. call writefile(['MRU test file2'], 'file2.txt')
  1328. call writefile(['MRU test file3'], 'file3.txt')
  1329. call writefile(['#include <stdio.h', 'int main(){}'], 'abc.c')
  1330. call writefile(['#include <stdlib.h', 'int main(){}'], 'def.c')
  1331. " Remove the results from the previous test runs
  1332. call delete('results.txt')
  1333. call delete(g:MRU_File)
  1334. let results = []
  1335. " Generate a sorted list of Test_ functions to run
  1336. redir @q
  1337. silent function /^Test_
  1338. redir END
  1339. let s:tests = split(substitute(@q, '\(function\) \(\k*()\)', '\2', 'g'))
  1340. " Run the tests
  1341. set nomore
  1342. set debug=beep
  1343. for one_test in sort(s:tests)
  1344. exe 'call ' . one_test
  1345. endfor
  1346. set more
  1347. call writefile(results, 'results.txt')
  1348. " TODO:
  1349. " Add the following tests:
  1350. " 1. When the MRU list is modified, the MRU menu should be refreshed.
  1351. " 2. Try to jump to an already open file from the MRU window and using the
  1352. " MRU command.
  1353. " Cleanup the files used by the tests
  1354. call delete('file1.txt')
  1355. call delete('file2.txt')
  1356. call delete('file3.txt')
  1357. call delete('abc.c')
  1358. call delete('def.c')
  1359. call delete(g:MRU_File)
  1360. " End of unit test execution
  1361. qall
  1362. " vim: shiftwidth=2 sts=2 expandtab