test_find_complete.vim 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. " Tests for the 'find' command completion.
  2. " Do all the tests in a separate window to avoid E211 when we recursively
  3. " delete the Xfind directory during cleanup
  4. func Test_find_complete()
  5. set belloff=all
  6. " On windows a stale "Xfind" directory may exist, remove it so that
  7. " we start from a clean state.
  8. call delete("Xfind", "rf")
  9. let cwd = getcwd()
  10. let test_out = cwd . '/test.out'
  11. call mkdir('Xfind')
  12. cd Xfind
  13. new
  14. set path=
  15. call assert_fails('call feedkeys(":find \t\n", "xt")', 'E471:')
  16. close
  17. new
  18. set path=.
  19. call assert_fails('call feedkeys(":find \t\n", "xt")', 'E471:')
  20. close
  21. new
  22. set path=.,,
  23. call assert_fails('call feedkeys(":find \t\n", "xt")', 'E471:')
  24. close
  25. new
  26. set path=./**
  27. call assert_fails('call feedkeys(":find \t\n", "xt")', 'E471:')
  28. close
  29. " We shouldn't find any file till this point
  30. call mkdir('in/path', 'p')
  31. call chdir(cwd)
  32. call writefile(['Holy Grail'], 'Xfind/file.txt')
  33. call writefile(['Jimmy Hoffa'], 'Xfind/in/file.txt')
  34. call writefile(['Another Holy Grail'], 'Xfind/in/stuff.txt')
  35. call writefile(['E.T.'], 'Xfind/in/path/file.txt')
  36. new
  37. set path=Xfind/**
  38. call feedkeys(":find file\t\n", "xt")
  39. call assert_equal('Holy Grail', getline(1))
  40. call feedkeys(":find file\t\t\n", "xt")
  41. call assert_equal('Jimmy Hoffa', getline(1))
  42. call feedkeys(":find file\t\t\t\n", "xt")
  43. call assert_equal('E.T.', getline(1))
  44. " Rerun the previous three find completions, using fullpath in 'path'
  45. exec "set path=" . cwd . "/Xfind/**"
  46. call feedkeys(":find file\t\n", "xt")
  47. call assert_equal('Holy Grail', getline(1))
  48. call feedkeys(":find file\t\t\n", "xt")
  49. call assert_equal('Jimmy Hoffa', getline(1))
  50. call feedkeys(":find file\t\t\t\n", "xt")
  51. call assert_equal('E.T.', getline(1))
  52. " Same steps again, using relative and fullpath items that point to the same
  53. " recursive location.
  54. " This is to test that there are no duplicates in the completion list.
  55. set path+=Xfind/**
  56. call feedkeys(":find file\t\n", "xt")
  57. call assert_equal('Holy Grail', getline(1))
  58. call feedkeys(":find file\t\t\n", "xt")
  59. call assert_equal('Jimmy Hoffa', getline(1))
  60. call feedkeys(":find file\t\t\t\n", "xt")
  61. call assert_equal('E.T.', getline(1))
  62. call feedkeys(":find file\t\t\n", "xt")
  63. " Test find completion for directory of current buffer, which at this point
  64. " is Xfind/in/file.txt.
  65. set path=.
  66. call feedkeys(":find st\t\n", "xt")
  67. call assert_equal('Another Holy Grail', getline(1))
  68. " Test find completion for empty path item ",," which is the current
  69. " directory
  70. cd Xfind
  71. set path=,,
  72. call feedkeys(":find f\t\n", "xt")
  73. call assert_equal('Holy Grail', getline(1))
  74. " Test that find completion on directory appends a slash
  75. call feedkeys(":find in/pa\tfile.txt\n", "xt")
  76. call assert_equal('E.T.', getline(1))
  77. call feedkeys(":find ./i\tstuff.txt\n", "xt")
  78. call assert_equal('Another Holy Grail', getline(1))
  79. " Test shortening of
  80. "
  81. " foo/x/bar/voyager.txt
  82. " foo/y/bar/voyager.txt
  83. "
  84. " When current directory is above foo/ they should be shortened to (in order
  85. " of appearance):
  86. "
  87. " x/bar/voyager.txt
  88. " y/bar/voyager.txt
  89. call mkdir('foo/x/bar', 'p')
  90. call mkdir('foo/y/bar', 'p')
  91. call writefile(['Voyager 1'], 'foo/x/bar/voyager.txt')
  92. call writefile(['Voyager 2'], 'foo/y/bar/voyager.txt')
  93. exec "set path=" . cwd . "/Xfind/**"
  94. call feedkeys(":find voyager\t\n", "xt")
  95. call assert_equal('Voyager 1', getline(1))
  96. call feedkeys(":find voyager\t\t\n", "xt")
  97. call assert_equal('Voyager 2', getline(1))
  98. "
  99. " When current directory is .../foo/y/bar they should be shortened to (in
  100. " order of appearance):
  101. "
  102. " ./voyager.txt
  103. " x/bar/voyager.txt
  104. cd foo/y/bar
  105. call feedkeys(":find voyager\t\n", "xt")
  106. call assert_equal('Voyager 2', getline(1))
  107. call feedkeys(":find voyager\t\t\n", "xt")
  108. call assert_equal('Voyager 1', getline(1))
  109. " Check the opposite too:
  110. cd ../../x/bar
  111. call feedkeys(":find voyager\t\n", "xt")
  112. call assert_equal('Voyager 1', getline(1))
  113. call feedkeys(":find voyager\t\t\n", "xt")
  114. call assert_equal('Voyager 2', getline(1))
  115. " Check for correct handling of shorten_fname()'s behavior on windows
  116. call chdir(cwd .. "/Xfind/in")
  117. call feedkeys(":find file\t\n", "xt")
  118. call assert_equal('Jimmy Hoffa', getline(1))
  119. " Test for relative to current buffer 'path' item
  120. call chdir(cwd . "/Xfind/")
  121. set path=./path
  122. " Open the file where Jimmy Hoffa is found
  123. e in/file.txt
  124. " Find the file containing 'E.T.' in the Xfind/in/path directory
  125. call feedkeys(":find file\t\n", "xt")
  126. call assert_equal('E.T.', getline(1))
  127. " Test that completion works when path=.,,
  128. set path=.,,
  129. " Open Jimmy Hoffa file
  130. e in/file.txt
  131. call assert_equal('Jimmy Hoffa', getline(1))
  132. " Search for the file containing Holy Grail in same directory as in/path.txt
  133. call feedkeys(":find stu\t\n", "xt")
  134. call assert_equal('Another Holy Grail', getline(1))
  135. enew | only
  136. call chdir(cwd)
  137. call delete('Xfind', 'rf')
  138. set path&
  139. endfunc