Most Recently Used (MRU) Vim Plugin
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1044 lines
28 KiB

  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 = '__MRU_Files__'
  7. " Function to log test results
  8. function! LogResult(test, result)
  9. redir >> results.txt
  10. silent echon "\r" . a:test . ': ' . a:result . "\n"
  11. redir END
  12. endfunction
  13. " Set the following variable to 1, to profile the MRU plugin
  14. let s:do_profile=0
  15. " Profile the MRU plugin
  16. if s:do_profile
  17. profile start mru_profile.txt
  18. profile! file */mru.vim
  19. endif
  20. runtime plugin/mru.vim
  21. " Create the files used by the tests
  22. call writefile(['MRU test file1'], 'file1.txt')
  23. call writefile(['MRU test file2'], 'file2.txt')
  24. call writefile(['MRU test file3'], 'file3.txt')
  25. call writefile(['#include <stdio.h', 'int main(){}'], 'abc.c')
  26. call writefile(['#include <stdlib.h', 'int main(){}'], 'def.c')
  27. " Remove the results from the previous test runs
  28. call delete('results.txt')
  29. call delete(MRU_File)
  30. " ==========================================================================
  31. " Test1
  32. " When the MRU list is empty, invoking the MRU command should return an error
  33. " ==========================================================================
  34. let test_name = 'test1'
  35. redir => msg
  36. MRU
  37. redir END
  38. if msg =~# "MRU file list is empty"
  39. call LogResult(test_name, 'pass')
  40. else
  41. call LogResult(test_name, 'FAIL')
  42. endif
  43. " ==========================================================================
  44. " Test2
  45. " Open the MRU window and check the order of files listed in the window
  46. " Open the MRU window when the window is already opened.
  47. " ==========================================================================
  48. let test_name = 'test2'
  49. edit file1.txt
  50. edit file2.txt
  51. edit file3.txt
  52. edit file2.txt
  53. edit file1.txt
  54. MRU
  55. MRU
  56. let l = getline(1, "$")
  57. if l[0] =~# "file1.txt" && l[1] =~# "file2.txt" && l[2] =~# "file3.txt"
  58. call LogResult(test_name, 'pass')
  59. else
  60. call LogResult(test_name, 'FAIL')
  61. endif
  62. " ==========================================================================
  63. " Test3
  64. " Select a file from the MRU window and check whether it is opened
  65. " ==========================================================================
  66. let test_name = 'test3'
  67. " Go to the last but one line
  68. $
  69. " Select the last file in the MRU window
  70. exe "normal \<Enter>"
  71. if fnamemodify(bufname('%'), ':p:t') !=# 'file3.txt'
  72. call LogResult(test_name, "FAIL (1)")
  73. else
  74. " Make sure the MRU window is closed
  75. if bufwinnr(g:MRU_buffer_name) == -1
  76. call LogResult(test_name, 'pass')
  77. else
  78. call LogResult(test_name, "FAIL (2)")
  79. endif
  80. endif
  81. " ==========================================================================
  82. " Test4
  83. " MRU opens a selected file in the previous/last window
  84. " ==========================================================================
  85. let test_name = 'test4'
  86. " Edit a file and then open a new window, open the MRU window and select the
  87. " file
  88. split file1.txt
  89. only
  90. below new
  91. MRU
  92. call search('file2.txt')
  93. exe "normal \<Enter>"
  94. if winnr() == 2
  95. call LogResult(test_name, 'pass')
  96. else
  97. call LogResult(test_name, 'FAIL')
  98. endif
  99. " ==========================================================================
  100. " Test5
  101. " MRU opens a selected file in the same window if the file is already opened
  102. " ==========================================================================
  103. let test_name = 'test5'
  104. edit file1.txt
  105. only
  106. below split file2.txt
  107. below split file3.txt
  108. MRU
  109. call search('file1.txt')
  110. exe "normal \<Enter>"
  111. if winnr() != 1 || fnamemodify(bufname('%'), ':p:t') !=# 'file1.txt'
  112. call LogResult(test_name, "FAIL (1)")
  113. else
  114. MRU
  115. call search('file2.txt')
  116. exe "normal \<Enter>"
  117. if winnr() != 2 || fnamemodify(bufname('%'), ':p:t') !=# 'file2.txt'
  118. call LogResult(test_name, "FAIL (2)")
  119. else
  120. MRU
  121. call search('file3.txt')
  122. exe "normal \<Enter>"
  123. if winnr() != 3 || fnamemodify(bufname('%'), ':p:t') !=# 'file3.txt'
  124. call LogResult(test_name, "FAIL (3)")
  125. else
  126. call LogResult(test_name, 'pass')
  127. endif
  128. endif
  129. endif
  130. " ==========================================================================
  131. " Test6
  132. " MRU opens a file selected with 'o' command in a new window
  133. " ==========================================================================
  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(bufname('%'), ':p:t') ==# 'file1.txt'
  141. call LogResult(test_name, 'pass')
  142. else
  143. call LogResult(test_name, 'FAIL')
  144. endif
  145. " ==========================================================================
  146. " Test7
  147. " MRU opens the selected file in a new window if the previous buffer is
  148. " modified.
  149. " ==========================================================================
  150. let test_name = 'test7'
  151. enew | only
  152. insert
  153. MRU plugin test
  154. .
  155. MRU
  156. call search('file3.txt')
  157. exe "normal \<Enter>"
  158. if winnr() == 1 && winnr('$') == 2 &&
  159. \ fnamemodify(bufname('%'), ':p:t') ==# 'file3.txt'
  160. call LogResult(test_name, 'pass')
  161. else
  162. call LogResult(test_name, 'FAIL')
  163. endif
  164. " Discard changes in the new buffer
  165. wincmd b
  166. enew!
  167. only
  168. " ==========================================================================
  169. " Test8
  170. " MRU opens a file selected with 'v' command in read-only mode in the current
  171. " window.
  172. " ==========================================================================
  173. let test_name = 'test8'
  174. enew | only
  175. MRU
  176. call search('file1.txt')
  177. normal v
  178. let r1 = &readonly
  179. MRU
  180. call search('file2.txt')
  181. exe "normal \<Enter>"
  182. let r2 = &readonly
  183. MRU
  184. call search('file1.txt')
  185. exe "normal \<Enter>"
  186. let r3 = &readonly
  187. if r1 == 1 && r2 == 0 && r3 == 0
  188. call LogResult(test_name, 'pass')
  189. else
  190. call LogResult(test_name, 'FAIL')
  191. endif
  192. " ==========================================================================
  193. " Test9
  194. " Use 'O' in the MRU window to open a file in a veritcally split window
  195. " ==========================================================================
  196. let test_name = 'test9'
  197. enew | only
  198. edit file1.txt
  199. MRU
  200. call search('file2.txt')
  201. normal O
  202. let b1 = bufname('%')
  203. wincmd h
  204. let b2 = bufname('%')
  205. wincmd l
  206. let b3 = bufname('%')
  207. if winnr('$') == 2 && b1 ==# 'file2.txt' &&
  208. \ b2 ==# 'file1.txt' && b3 ==# 'file2.txt'
  209. call LogResult(test_name, 'pass')
  210. else
  211. call LogResult(test_name, 'FAIL')
  212. endif
  213. " ==========================================================================
  214. " Test10
  215. " Use 'p' in the MRU window to open a file in the preview window
  216. " ==========================================================================
  217. let test_name = 'test10'
  218. enew | only
  219. MRU
  220. call search('file3.txt')
  221. normal p
  222. wincmd P
  223. let p1 = &previewwindow
  224. let b1 = bufname('%')
  225. if winnr('$') == 2 && &previewwindow && bufname('%') =~# 'file3.txt'
  226. call LogResult(test_name, 'pass')
  227. else
  228. call LogResult(test_name, 'FAIL')
  229. endif
  230. pclose
  231. " ==========================================================================
  232. " Test11
  233. " MRU opens a file selected with 't' command in a new tab and the tab
  234. " is opened at the end
  235. " ==========================================================================
  236. let test_name = 'test11'
  237. enew | only
  238. tabnew
  239. tabnew
  240. tabnew
  241. tabfirst
  242. MRU
  243. call search('file3.txt')
  244. normal t
  245. if fnamemodify(bufname('%'), ':p:t') ==# 'file3.txt' && tabpagenr() == 5
  246. call LogResult(test_name, 'pass')
  247. else
  248. call LogResult(test_name, 'FAIL')
  249. call LogResult(test_name, "file = " . fnamemodify(bufname('%'), ':p:t'))
  250. call LogResult(test_name, "tab page = " . tabpagenr())
  251. endif
  252. tabonly
  253. " ==========================================================================
  254. " Test12
  255. " The 'q' command closes the MRU window
  256. " ==========================================================================
  257. let test_name = 'test12'
  258. enew | only
  259. MRU
  260. normal q
  261. if bufwinnr(g:MRU_buffer_name) == -1
  262. call LogResult(test_name, 'pass')
  263. else
  264. call LogResult(test_name, 'FAIL')
  265. endif
  266. " ==========================================================================
  267. " Test13
  268. " A selected file is opened in a new window if the previous window is a
  269. " preview window
  270. " ==========================================================================
  271. let test_name = 'test13'
  272. enew | only
  273. setlocal previewwindow
  274. MRU
  275. call search('file2.txt')
  276. exe "normal \<Enter>"
  277. if winnr() == 1 && winnr('$') == 2 &&
  278. \ &previewwindow == 0 &&
  279. \ fnamemodify(bufname('%'), ':p:t') ==# 'file2.txt'
  280. call LogResult(test_name, 'pass')
  281. else
  282. call LogResult(test_name, 'FAIL')
  283. endif
  284. " Close the preview window created by this test
  285. new
  286. only
  287. " ==========================================================================
  288. " Test14
  289. " A selected file is opened in a new window if the previous window contains
  290. " a special buffer (used by some other plugin)
  291. " ==========================================================================
  292. let test_name = 'test14'
  293. enew | only
  294. setlocal buftype=nofile
  295. MRU
  296. call search('file3.txt')
  297. exe "normal \<Enter>"
  298. if winnr() == 1 && winnr('$') == 2 &&
  299. \ &buftype == '' &&
  300. \ fnamemodify(bufname('%'), ':p:t') ==# 'file3.txt'
  301. call LogResult(test_name, 'pass')
  302. else
  303. call LogResult(test_name, 'FAIL')
  304. endif
  305. " Discard the special buffer
  306. enew
  307. " ==========================================================================
  308. " Test15
  309. " If a file selected using the 't' command is already opened in a tab,
  310. " then jump to that tab (instead of opening a new tab)
  311. " ==========================================================================
  312. let test_name = 'test15'
  313. enew | only
  314. " Open the test files in the middle window with empty windows at the top and
  315. " bottom
  316. edit file1.txt
  317. above new
  318. botright new
  319. tabedit file2.txt
  320. above new
  321. botright new
  322. tabedit file3.txt
  323. above new
  324. botright new
  325. tabfirst
  326. MRU
  327. call search('file3.txt')
  328. exe "normal t"
  329. if tabpagenr() != 3
  330. \ || fnamemodify(bufname('%'), ':p:t') !=# 'file3.txt'
  331. \ || winnr() != 2
  332. call LogResult(test_name, "FAIL (1)")
  333. else
  334. MRU
  335. call search('file1.txt')
  336. exe "normal t"
  337. if tabpagenr() != 1
  338. \ || fnamemodify(bufname('%'), ':p:t') !=# 'file1.txt'
  339. \ || winnr() != 2
  340. call LogResult(test_name, "FAIL (2)")
  341. else
  342. MRU
  343. call search('file2.txt')
  344. exe "normal t"
  345. if tabpagenr() != 2
  346. \ || fnamemodify(bufname('%'), ':p:t') !=# 'file2.txt'
  347. \ || winnr() != 2
  348. call LogResult(test_name, "FAIL (3)")
  349. else
  350. call LogResult(test_name, 'pass')
  351. endif
  352. endif
  353. endif
  354. " Close all the other tabs
  355. tabonly
  356. enew
  357. only
  358. " ==========================================================================
  359. " Test16
  360. " Open multiple files from the MRU window using the visual mode and by using a
  361. " count. Each file should be opened in a separate window.
  362. " ==========================================================================
  363. let test_name = 'test16'
  364. enew | only
  365. edit file3.txt
  366. edit file2.txt
  367. edit file1.txt
  368. enew
  369. MRU
  370. exe "normal 3\<Enter>"
  371. if winnr('$') == 3 &&
  372. \ bufwinnr('file3.txt') == 1 &&
  373. \ bufwinnr('file2.txt') == 2 &&
  374. \ bufwinnr('file1.txt') == 3
  375. let test_result = 'pass'
  376. else
  377. let test_result = 'FAIL'
  378. endif
  379. only | enew
  380. if test_result == 'pass'
  381. MRU
  382. exe "normal V2j\<Enter>"
  383. if winnr('$') == 3 &&
  384. \ bufwinnr('file1.txt') == 1 &&
  385. \ bufwinnr('file2.txt') == 2 &&
  386. \ bufwinnr('file3.txt') == 3
  387. let test_result = 'pass'
  388. else
  389. let test_result = 'FAIL'
  390. endif
  391. endif
  392. if test_result == 'pass'
  393. call LogResult(test_name, 'pass')
  394. else
  395. call LogResult(test_name, 'FAIL')
  396. endif
  397. " ==========================================================================
  398. " Test17
  399. " When the MRU list is updated, the MRU file also should updated.
  400. " ==========================================================================
  401. let test_name = 'test17'
  402. enew | only
  403. edit file1.txt
  404. let l = readfile(g:MRU_File)
  405. if l[1] =~# 'file1.txt'
  406. edit file2.txt
  407. let l = readfile(g:MRU_File)
  408. if l[1] =~# 'file2.txt'
  409. edit file3.txt
  410. let l = readfile(g:MRU_File)
  411. if l[1] =~# 'file3.txt'
  412. call LogResult(test_name, 'pass')
  413. else
  414. call LogResult(test_name, "FAIL (3)")
  415. endif
  416. else
  417. call LogResult(test_name, "FAIL (2)")
  418. endif
  419. else
  420. call LogResult(test_name, "FAIL (1)")
  421. endif
  422. " MRU_Test_Add_Files
  423. " Add the supplied List of files to the beginning of the MRU file
  424. function! s:MRU_Test_Add_Files(fnames)
  425. let l = readfile(g:MRU_File)
  426. call extend(l, a:fnames, 1)
  427. call writefile(l, g:MRU_File)
  428. endfunction
  429. " ==========================================================================
  430. " Test18
  431. " When the MRU file is updated by another Vim instance, the MRU plugin
  432. " should update the MRU list
  433. " ==========================================================================
  434. let test_name = 'test18'
  435. enew | only
  436. call s:MRU_Test_Add_Files(['/software/editors/vim',
  437. \ '/software/editors/emacs',
  438. \ '/software/editors/nano'])
  439. MRU
  440. if getline(1) ==# 'vim (/software/editors/vim)'
  441. \ && getline(2) ==# 'emacs (/software/editors/emacs)'
  442. \ && getline(3) ==# 'nano (/software/editors/nano)'
  443. call LogResult(test_name, 'pass')
  444. else
  445. call LogResult(test_name, 'FAIL')
  446. endif
  447. " Close the MRU window
  448. close
  449. " ==========================================================================
  450. " Test19
  451. " When the MRU file is updated by another Vim instance, the MRU file names
  452. " from the current instance should be merged with that list
  453. " ==========================================================================
  454. let test_name = 'test19'
  455. enew | only
  456. " Remove all the files from the MRU file
  457. let l = readfile(g:MRU_File)
  458. call remove(l, 1, -1)
  459. call writefile(l, g:MRU_File)
  460. edit file1.txt
  461. call s:MRU_Test_Add_Files(['/software/os/unix'])
  462. edit file2.txt
  463. call s:MRU_Test_Add_Files(['/software/os/windows'])
  464. edit file3.txt
  465. call s:MRU_Test_Add_Files(['/software/os/osx'])
  466. MRU
  467. if getline(1) ==# 'osx (/software/os/osx)'
  468. \ && getline(2) =~# 'file3.txt'
  469. \ && getline(3) ==# 'windows (/software/os/windows)'
  470. \ && getline(4) =~# 'file2.txt'
  471. \ && getline(5) ==# 'unix (/software/os/unix)'
  472. \ && getline(6) =~# 'file1.txt'
  473. call LogResult(test_name, 'pass')
  474. else
  475. call LogResult(test_name, 'FAIL')
  476. endif
  477. close
  478. " ==========================================================================
  479. " Test20
  480. " When the MRU list has more than g:MRU_Max_Entries, the list should be
  481. " trimmed. The last entries should be removed.
  482. " ==========================================================================
  483. let test_name = 'test20'
  484. enew | only
  485. " Create a MRU list with MRU_Max_Entries
  486. let flist = []
  487. for i in range(1, g:MRU_Max_Entries)
  488. let flist += ['/usr/share/mru_test/mru_file' . i . '.abc']
  489. endfor
  490. " Modify the MRU file to contain max entries
  491. let l = readfile(g:MRU_File)
  492. call remove(l, 1, -1)
  493. call extend(l, flist)
  494. call writefile(l, g:MRU_File)
  495. enew
  496. edit file1.txt
  497. let l = readfile(g:MRU_File)
  498. if len(l) == (g:MRU_Max_Entries + 1) &&
  499. \ l[g:MRU_Max_Entries] != '/usr/share/mru_test/mru_file9.abc'
  500. call LogResult(test_name, "FAIL (1)")
  501. else
  502. edit file2.txt
  503. let l = readfile(g:MRU_File)
  504. if len(l) == (g:MRU_Max_Entries + 1) &&
  505. \ l[g:MRU_Max_Entries] != '/usr/share/mru_test/mru_file8.abc'
  506. call LogResult(test_name, "FAIL (2)")
  507. else
  508. edit file3.txt
  509. let l = readfile(g:MRU_File)
  510. if len(l) == (g:MRU_Max_Entries + 1) &&
  511. \ l[g:MRU_Max_Entries] != '/usr/share/mru_test/mru_file7.abc'
  512. call LogResult(test_name, "FAIL (3)")
  513. else
  514. call LogResult(test_name, 'pass')
  515. endif
  516. endif
  517. endif
  518. " ==========================================================================
  519. " Test21
  520. " When an filename (already present in the MRU list) is specified to the MRU
  521. " command, it should edit the file.
  522. " ==========================================================================
  523. let test_name = 'test21'
  524. enew | only
  525. edit file1.txt
  526. edit file2.txt
  527. edit file3.txt
  528. enew
  529. MRU file2.txt
  530. if fnamemodify(bufname('%'), ':p:t') ==# 'file2.txt' && winnr('$') == 1
  531. call LogResult(test_name, 'pass')
  532. else
  533. call LogResult(test_name, 'FAIL')
  534. endif
  535. " ==========================================================================
  536. " Test22
  537. " When a pattern (matching multiple filenames) is specified to the MRU
  538. " command, then the MRU window should be opened with all the matching
  539. " filenames
  540. " ==========================================================================
  541. let test_name = 'test22'
  542. enew | only
  543. edit file1.txt
  544. edit file2.txt
  545. edit file3.txt
  546. only
  547. MRU file.*
  548. if bufname('%') != g:MRU_buffer_name
  549. call LogResult(test_name, 'FAIL')
  550. else
  551. let l = getline(1, "$")
  552. if l[0] =~# "file3.txt" && l[1] =~# "file2.txt" && l[2] =~# "file1.txt"
  553. call LogResult(test_name, 'pass')
  554. else
  555. call LogResult(test_name, 'FAIL')
  556. endif
  557. endif
  558. close
  559. " ==========================================================================
  560. " Test23
  561. " When a partial filename (matching multiple filenames) is specified to the
  562. " MRU command, then the MRU window should be opened with all the matching
  563. " filenames
  564. " ==========================================================================
  565. let test_name = 'test23'
  566. enew | only
  567. edit file1.txt
  568. edit file2.txt
  569. edit file3.txt
  570. only
  571. MRU file
  572. if bufname('%') != g:MRU_buffer_name
  573. call LogResult(test_name, 'FAIL')
  574. else
  575. let l = getline(1, "$")
  576. if l[0] =~# "file3.txt" && l[1] =~# "file2.txt" && l[2] =~# "file1.txt"
  577. call LogResult(test_name, 'pass')
  578. else
  579. call LogResult(test_name, 'FAIL')
  580. endif
  581. endif
  582. close
  583. " ==========================================================================
  584. " Test24
  585. " When a non-existing filename is specified to the MRU command, an error
  586. " message should be displayed.
  587. " ==========================================================================
  588. let test_name = 'test24'
  589. redir => msg
  590. MRU nonexistingfile.txt
  591. redir END
  592. if bufname('%') == g:MRU_buffer_name ||
  593. \ msg !~# "MRU file list doesn't contain files " .
  594. \ "matching nonexistingfile.txt"
  595. call LogResult(test_name, 'FAIL')
  596. else
  597. call LogResult(test_name, 'pass')
  598. endif
  599. " ==========================================================================
  600. " Test25
  601. " The MRU command should support filename completion. Supply a partial file
  602. " name to the MRU command and complete the filenames.
  603. " ==========================================================================
  604. let test_name = 'test25'
  605. enew | only
  606. edit file1.txt
  607. edit file2.txt
  608. edit file3.txt
  609. exe 'normal! :MRU file' . "\<C-A>" . "\<Home>let m='\<End>'\<CR>"
  610. let fnames = split(m)
  611. if fnames[1] =~# 'file3.txt' && fnames[2] =~# 'file2.txt' &&
  612. \ fnames[3] =~# 'file1.txt'
  613. call LogResult(test_name, 'pass')
  614. else
  615. call LogResult(test_name, 'FAIL')
  616. endif
  617. " ==========================================================================
  618. " Test26
  619. " When trying to complete filenames for the MRU command without specifying
  620. " any text should return the the entire MRU list.
  621. " ==========================================================================
  622. let test_name = 'test26'
  623. enew | only
  624. call delete(MRU_File)
  625. edit file1.txt
  626. edit file2.txt
  627. edit file3.txt
  628. exe 'normal! :MRU ' . "\<C-A>" . "\<Home>let m='\<End>'\<CR>"
  629. let fnames = split(m)
  630. if fnames[1] =~# 'file3.txt' && fnames[2] =~# 'file2.txt' &&
  631. \ fnames[3] =~# 'file1.txt'
  632. call LogResult(test_name, 'pass')
  633. else
  634. call LogResult(test_name, 'FAIL')
  635. endif
  636. " ==========================================================================
  637. " Test27
  638. " When the current file/buffer has unsaved changes, MRU should open a selected
  639. " file in a new window (if the 'hidden' option is not set)
  640. " ==========================================================================
  641. let test_name = 'test27'
  642. enew | only
  643. edit file1.txt
  644. edit file2.txt
  645. call append(line('$'), 'Temporary changes to buffer')
  646. MRU
  647. call search('file1.txt')
  648. exe "normal \<Enter>"
  649. if winnr() == 1 && winnr('$') == 2 &&
  650. \ fnamemodify(bufname('%'), ':p:t') ==# 'file1.txt'
  651. call LogResult(test_name, 'pass')
  652. else
  653. call LogResult(test_name, 'FAIL')
  654. endif
  655. close
  656. edit!
  657. " ==========================================================================
  658. " Test28
  659. " When the current file/buffer has unsaved changes and the 'hidden' option is
  660. " set, then MRU should open a selected file in the current window
  661. " ==========================================================================
  662. let test_name = 'test28'
  663. enew | only
  664. edit file2.txt
  665. edit file1.txt
  666. call append(line('$'), 'Temporary changes to buffer')
  667. set hidden
  668. MRU
  669. call search('file2.txt')
  670. exe "normal \<Enter>"
  671. if winnr('$') == 1 &&
  672. \ fnamemodify(bufname('%'), ':p:t') ==# 'file2.txt'
  673. call LogResult(test_name, 'pass')
  674. else
  675. call LogResult(test_name, 'FAIL')
  676. endif
  677. edit file1.txt
  678. edit!
  679. set nohidden
  680. " ==========================================================================
  681. " Test29
  682. " Every edited file is added to the top of the MRU list. If a file is already
  683. " present in the MRU list, then it is moved to the top of the list.
  684. " ==========================================================================
  685. let test_name = 'test29'
  686. enew | only
  687. edit file1.txt
  688. let f1 = readfile(g:MRU_File, '', 2)
  689. edit file2.txt
  690. let f2 = readfile(g:MRU_File, '', 2)
  691. edit file3.txt
  692. let f3 = readfile(g:MRU_File, '', 2)
  693. edit file1.txt
  694. let f4 = readfile(g:MRU_File, '', 2)
  695. if f1[1] =~# 'file1.txt' && f2[1] =~# 'file2.txt' && f3[1] =~# 'file3.txt' &&
  696. \ f4[1] =~# 'file1.txt'
  697. call LogResult(test_name, 'pass')
  698. else
  699. call LogResult(test_name, 'FAIL')
  700. endif
  701. " ==========================================================================
  702. " Test30
  703. " Only file names matching the regular expression in the MRU_Include_Files
  704. " variable should be added to the MRU list.
  705. " ==========================================================================
  706. let test_name = 'test30'
  707. enew | only
  708. edit file1.txt
  709. let MRU_Include_Files='\.c'
  710. edit abc.c
  711. let f1 = readfile(g:MRU_File, '', 2)
  712. edit file1.txt
  713. let f2 = readfile(g:MRU_File, '', 2)
  714. edit def.c
  715. let f3 = readfile(g:MRU_File, '', 2)
  716. if f1[1] =~# 'abc.c' && f2[1] =~# 'abc.c' && f3[1] =~# 'def.c'
  717. call LogResult(test_name, 'pass')
  718. else
  719. call LogResult(test_name, 'FAIL')
  720. endif
  721. let MRU_Include_Files=''
  722. " ==========================================================================
  723. " Test31
  724. " File names matching the regular expression in the MRU_Exclude_Files
  725. " variable should not be added to the MRU list.
  726. " ==========================================================================
  727. let test_name = 'test31'
  728. enew | only
  729. let MRU_Exclude_Files='\.txt'
  730. edit abc.c
  731. let f1 = readfile(g:MRU_File, '', 2)
  732. edit file1.txt
  733. edit file2.txt
  734. edit file3.txt
  735. let f2 = readfile(g:MRU_File, '', 2)
  736. edit def.c
  737. let f3 = readfile(g:MRU_File, '', 2)
  738. let MRU_Exclude_Files=''
  739. edit file1.txt
  740. let f4 = readfile(g:MRU_File, '', 2)
  741. if f1[1] =~# 'abc.c' && f2[1] =~# 'abc.c' && f3[1] =~# 'def.c' &&
  742. \ f4[1] =~# 'file1.txt'
  743. call LogResult(test_name, 'pass')
  744. else
  745. call LogResult(test_name, 'FAIL')
  746. endif
  747. " ==========================================================================
  748. " Test32
  749. " If the MRU window is open, when adding a file name to the list, the MRU
  750. " window should be refreshed.
  751. " ==========================================================================
  752. let test_name = 'test32'
  753. enew | only
  754. MRU
  755. wincmd p
  756. edit abc.c
  757. wincmd p
  758. let s1 = getline(1)
  759. wincmd p
  760. edit file1.txt
  761. wincmd p
  762. let s2 = getline(1)
  763. close
  764. if s1 =~# 'abc.c' && s2 =~# 'file1.txt'
  765. call LogResult(test_name, 'pass')
  766. else
  767. call LogResult(test_name, 'FAIL')
  768. endif
  769. " ==========================================================================
  770. " Test33
  771. " When MRU_Use_Current_Window is set, the MRU list should be displayed in
  772. " the current window.
  773. " Selecting a file from the MRU window should replace
  774. " the MRU buffer with the selected file.
  775. " ==========================================================================
  776. let test_name = 'test33'
  777. enew | only
  778. edit file1.txt
  779. let MRU_Use_Current_Window=1
  780. MRU
  781. if winnr('$') == 1 && bufname('%') == g:MRU_buffer_name
  782. call LogResult(test_name, 'pass')
  783. else
  784. call LogResult(test_name, 'FAIL')
  785. endif
  786. let MRU_Use_Current_Window=0
  787. " ==========================================================================
  788. " Test34
  789. " When MRU_Use_Current_Window is set, selecting a file from the MRU window
  790. " should replace the MRU buffer with the selected file.
  791. " ==========================================================================
  792. let test_name = 'test34'
  793. enew | only
  794. let MRU_Use_Current_Window=1
  795. let w:marker=1
  796. MRU
  797. if winnr('$') == 1 && w:marker && bufname('%') == g:MRU_buffer_name
  798. call search('file2.txt')
  799. exe "normal \<Enter>"
  800. if winnr('$') == 1 && w:marker && bufname('%') == 'file2.txt'
  801. call LogResult(test_name, 'pass')
  802. else
  803. call LogResult(test_name, 'FAIL')
  804. endif
  805. else
  806. call LogResult(test_name, 'FAIL')
  807. endif
  808. unlet w:marker
  809. let MRU_Use_Current_Window=0
  810. " ==========================================================================
  811. " Test35
  812. " When MRU_Auto_Close is not set, the MRU window should not automatically
  813. " close when a file is selected. The MRU window should be kept open.
  814. " ==========================================================================
  815. let test_name = 'test35'
  816. enew | only
  817. let MRU_Auto_Close=0
  818. new
  819. MRU
  820. call search('file1.txt')
  821. exe "normal \<Enter>"
  822. 2wincmd w
  823. MRU
  824. call search('file2.txt')
  825. exe "normal \<Enter>"
  826. if winnr('$') == 3 &&
  827. \ bufwinnr('file1.txt') == 1 &&
  828. \ bufwinnr('file2.txt') == 2 &&
  829. \ bufwinnr(g:MRU_buffer_name) == 3
  830. call LogResult(test_name, 'pass')
  831. else
  832. call LogResult(test_name, 'FAIL')
  833. endif
  834. wincmd b
  835. close
  836. let MRU_Auto_Close=1
  837. only
  838. " ==========================================================================
  839. " Test36
  840. " When MRU_Open_File_Use_Tabs is set, a selected file should be opened in a
  841. " tab. If the file is already opened in a tab, then the focus should be moved
  842. " to that tab.
  843. " ==========================================================================
  844. let test_name = 'test36'
  845. enew | only
  846. let MRU_Open_File_Use_Tabs=1
  847. edit file1.txt
  848. MRU
  849. call search('file2.txt')
  850. exe "normal \<Enter>"
  851. MRU
  852. call search('file3.txt')
  853. exe "normal \<Enter>"
  854. MRU file1.txt
  855. let t1 = tabpagenr()
  856. MRU
  857. call search('file2.txt')
  858. exe "normal \<Enter>"
  859. let t2 = tabpagenr()
  860. MRU
  861. call search('file3.txt')
  862. exe "normal \<Enter>"
  863. let t3 = tabpagenr()
  864. tabonly | enew
  865. if t1 == 1 && t2 == 2 && t3 == 3
  866. call LogResult(test_name, 'pass')
  867. else
  868. call LogResult(test_name, 'FAIL')
  869. endif
  870. let MRU_Open_File_Use_Tabs=0
  871. " ==========================================================================
  872. " Test37
  873. " If the MRU_Window_Open_Always is set to 0, when the MRU command finds a
  874. " single matching file name, then it should open the MRU window. If this
  875. " variable is set to 1, then the file should be opened without opening the MRU
  876. " window.
  877. " ==========================================================================
  878. let test_name = 'test37'
  879. enew | only
  880. edit file3.txt
  881. enew
  882. let MRU_Window_Open_Always=1
  883. MRU file3.txt
  884. if winnr('$') == 2 &&
  885. \ bufwinnr(g:MRU_buffer_name) == 2
  886. let test_result = 'pass'
  887. else
  888. let test_result = 'FAIL'
  889. endif
  890. close
  891. enew | only
  892. if test_result == 'pass'
  893. let MRU_Window_Open_Always=0
  894. MRU file3.txt
  895. if winnr('$') == 1 &&
  896. \ bufwinnr('file3.txt') == 1
  897. let test_result = 'pass'
  898. else
  899. let test_result = 'FAIL'
  900. endif
  901. endif
  902. let MRU_Window_Open_Always=0
  903. if test_result == 'pass'
  904. call LogResult(test_name, 'pass')
  905. else
  906. call LogResult(test_name, 'FAIL')
  907. endif
  908. " TODO:
  909. " 1. When the MRU list is modified, the MRU menu should be refreshed.
  910. " 2. Lock and Unlock the MRU list.
  911. " 3. Try to jump to an already open file from the MRU window and using the
  912. " MRU command.
  913. " 4. Open an existing file but not present in the MRU list using the MRU command
  914. " 5. Split open a file in readonly mode.
  915. " Cleanup the files used by the tests
  916. call delete('file1.txt')
  917. call delete('file2.txt')
  918. call delete('file3.txt')
  919. call delete('abc.c')
  920. call delete('def.c')
  921. call delete(MRU_File)
  922. " End of unit test execution
  923. qall