Browse Source

Search for files in the MRU list ignoring case

Yegappan Lakshmanan 3 năm trước cách đây
mục cha
commit
5d5f41a984
4 tập tin đã thay đổi với 66 bổ sung17 xóa
  1. 6 2
      plugin/mru.vim
  2. 3 3
      test/run_mru_tests.cmd
  3. 10 9
      test/run_mru_tests.sh
  4. 47 3
      test/unit_tests.vim

+ 6 - 2
plugin/mru.vim

@@ -757,7 +757,9 @@ func! s:MRU_Open_Window(pat, splitdir, winsz) abort
     if g:MRU_FuzzyMatch
       let m = matchfuzzy(s:MRU_files, a:pat)
     else
-      let m = filter(copy(s:MRU_files), 'stridx(v:val, a:pat) != -1')
+      " do case insensitive file name comparison
+      let spat = tolower(a:pat)
+      let m = filter(copy(s:MRU_files), 'stridx(tolower(v:val), spat) != -1')
     endif
     if len(m) == 0
       " No match. Try using it as a regular expression
@@ -829,7 +831,9 @@ func! s:MRU_Cmd(pat, splitdir, winsz) abort
   if g:MRU_FuzzyMatch
     let m = matchfuzzy(s:MRU_files, a:pat)
   else
-    let m = filter(copy(s:MRU_files), 'stridx(v:val, a:pat) != -1')
+    " do case insensitive file name comparison
+    let spat = tolower(a:pat)
+    let m = filter(copy(s:MRU_files), 'stridx(tolower(v:val), spat) != -1')
   endif
   if len(m) > 0
     if len(m) == 1 && !g:MRU_Window_Open_Always

+ 3 - 3
test/run_mru_tests.cmd

@@ -6,13 +6,13 @@ SETLOCAL
 SET VIMPRG="vim.exe"
 REM SET VIMPRG="C:\Program Files (x86)\vim\vim82\vim.exe"
 REM SET VIMPRG="C:\Program Files (x86)\vim\vim73\vim.exe"
-SET VIM_CMD=%VIMPRG% -N -u NONE -U NONE -i NONE --not-a-term
+SET VIM_CMD=%VIMPRG% -N -u NONE -U NONE -i NONE
 
 %VIM_CMD% -S unit_tests.vim
 
 echo MRU unit test results
-type results.txt
+type test.log
 
-findstr /I FAIL results.txt > nul 2>&1
+findstr /I FAIL test.log > nul 2>&1
 if %ERRORLEVEL% EQU 0 echo ERROR: Some test failed.
 if %ERRORLEVEL% NEQ 0 echo SUCCESS: All the tests passed.

+ 10 - 9
test/run_mru_tests.sh

@@ -3,23 +3,24 @@
 # Script to run the unit-tests for the MRU Vim plugin
 
 VIMPRG=${VIMPRG:=/usr/bin/vim}
-VIM_CMD="$VIMPRG -N -u NONE -U NONE -i NONE"
+VIM_CMD="$VIMPRG -N -u NONE -U NONE -i NONE --noplugin"
 
-$VIM_CMD -S unit_tests.vim
+rm -f test.log
 
-echo "MRU unit test results"
-echo
+$VIM_CMD -S unit_tests.vim
 
-if [ ! -f results.txt ]
+if [ ! -f test.log ]
 then
-  echo "ERROR: Test results file 'results.txt' is not found"
+  echo "ERROR: Test results file 'test.log' is not found"
   exit 1
 fi
 
-cat results.txt
-
+echo "MRU unit test results:"
+echo "====================="
+cat test.log
 echo
-grep FAIL results.txt > /dev/null 2>&1
+
+grep FAIL test.log > /dev/null 2>&1
 if [ $? -eq 0 ]
 then
   echo "ERROR: Some test(s) failed."

+ 47 - 3
test/unit_tests.vim

@@ -1737,7 +1737,7 @@ func Test_59()
         \ "source ../plugin/mru.vim",
         \ "call writefile([@#], 'Xoutput')"
         \ ], 'Xscript')
-  silent! !vim -u NONE --noplugin i NONE -N -S Xscript -c "qa"
+  silent! !vim -u NONE --noplugin -i NONE -N -S Xscript -c "qa"
   if !filereadable('Xoutput')
     call LogResult(test_name, 'FAIL (1)')
   else
@@ -1779,6 +1779,49 @@ func Test_60()
   let g:MRU_Use_Current_Window = 0
 endfunc
 
+" ==========================================================================
+" Test61
+" The :MRU command should do case-insensitive file name comparison
+" Works only in Unix-like systems.
+" ==========================================================================
+func Test_61()
+  if !has('unix')
+    return
+  endif
+  let test_name = 'test61'
+
+  let l = readfile(g:MRU_File)
+  call remove(l, 1, -1)
+  call writefile(l, g:MRU_File)
+  call s:MRU_Test_Add_Files(['/my/home/my1298file',
+        \ '/my/home/mY1298fIlE', '/my/home/MY1298FILE', '/my/home/My1298File'])
+
+  let expected = [
+        \ 'my1298file (/my/home/my1298file)',
+        \ 'mY1298fIlE (/my/home/mY1298fIlE)',
+        \ 'MY1298FILE (/my/home/MY1298FILE)',
+        \ 'My1298File (/my/home/My1298File)'
+        \ ]
+
+  let g:MRU_FuzzyMatch = 0
+
+  try
+    for p in ['my12', 'mY1298', 'MY1298', 'My1298File']
+      exe 'MRU ' . p
+      let lines = getline(1, '$')
+      if lines !=# expected
+        call LogResult(test_name, 'FAIL (' . p . ')')
+        return
+      endif
+      close
+    endfor
+
+    call LogResult(test_name, 'pass')
+  finally
+    let g:MRU_FuzzyMatch = 1
+  endtry
+endfunc
+
 " ==========================================================================
 
 " Create the files used by the tests
@@ -1790,7 +1833,7 @@ call writefile(['#include <stdio.h', 'int main(){}'], 'abc.c')
 call writefile(['#include <stdlib.h', 'int main(){}'], 'def.c')
 
 " Remove the results from the previous test runs
-call delete('results.txt')
+call delete('test.log')
 call delete(g:MRU_File)
 let results = []
 
@@ -1804,11 +1847,12 @@ let s:tests = split(substitute(@q, '\(function\) \(\k*()\)', '\2', 'g'))
 set nomore
 set debug=beep
 for one_test in sort(s:tests)
+  echo 'Executing ' . one_test
   exe 'call ' . one_test
 endfor
 set more
 
-call writefile(results, 'results.txt')
+call writefile(results, 'test.log')
 
 " TODO:
 " Add the following tests: