unit_tests.vim 39 KB

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