test_zip_plugin.vim 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. so check.vim
  2. CheckExecutable unzip
  3. if 0 " Find uncovered line
  4. profile start zip_profile
  5. profile! file */zip*.vim
  6. endif
  7. runtime plugin/zipPlugin.vim
  8. func Test_zip_basic()
  9. "## get our zip file
  10. if !filecopy("samples/test.zip", "X.zip")
  11. call assert_report("Can't copy samples/test.zip")
  12. return
  13. endif
  14. defer delete("X.zip")
  15. e X.zip
  16. "## Check header
  17. call assert_match('^" zip\.vim version v\d\+', getline(1))
  18. call assert_match('^" Browsing zipfile .*/X.zip', getline(2))
  19. call assert_match('^" Select a file with cursor and press ENTER', getline(3))
  20. call assert_match('^$', getline(4))
  21. "## Check files listing
  22. call assert_equal(["Xzip/", "Xzip/dir/", "Xzip/file.txt"], getline(5, 7))
  23. "## Check ENTER on header
  24. :1
  25. exe ":normal \<cr>"
  26. call assert_equal("X.zip", @%)
  27. "## Check ENTER on directory
  28. :1|:/^$//dir/
  29. call assert_match('Please specify a file, not a directory',
  30. \ execute("normal \<CR>"))
  31. "## Check ENTER on file
  32. :1
  33. call search('file.txt')
  34. exe ":normal \<cr>"
  35. call assert_match('zipfile://.*/X.zip::Xzip/file.txt', @%)
  36. call assert_equal('one', getline(1))
  37. "## Check editing file
  38. if executable("zip")
  39. s/one/two/
  40. call assert_equal("two", getline(1))
  41. w
  42. bw|bw
  43. e X.zip
  44. :1|:/^$//file/
  45. exe "normal \<cr>"
  46. call assert_equal("two", getline(1))
  47. endif
  48. only
  49. e X.zip
  50. "## Check extracting file
  51. :1|:/^$//file/
  52. normal x
  53. call assert_true(filereadable("Xzip/file.txt"))
  54. "## Check not overwriting existing file
  55. call assert_match('<Xzip/file.txt> .* not overwriting!', execute("normal x"))
  56. call delete("Xzip", "rf")
  57. "## Check extracting directory
  58. :1|:/^$//dir/
  59. call assert_match('Please specify a file, not a directory', execute("normal x"))
  60. call assert_equal("X.zip", @%)
  61. "## Check "x" on header
  62. :1
  63. normal x
  64. call assert_equal("X.zip", @%)
  65. bw
  66. "## Check opening zip when "unzip" program is missing
  67. let save_zip_unzipcmd = g:zip_unzipcmd
  68. let g:zip_unzipcmd = "/"
  69. call assert_match('unzip not available on your system', execute("e X.zip"))
  70. "## Check when "unzip" don't work
  71. if executable("false")
  72. let g:zip_unzipcmd = "false"
  73. call assert_match('X\.zip is not a zip file', execute("e X.zip"))
  74. endif
  75. bw
  76. let g:zip_unzipcmd = save_zip_unzipcmd
  77. e X.zip
  78. "## Check opening file when "unzip" is missing
  79. let g:zip_unzipcmd = "/"
  80. call assert_match('sorry, your system doesn''t appear to have the / program',
  81. \ execute("normal \<CR>"))
  82. bw|bw
  83. let g:zip_unzipcmd = save_zip_unzipcmd
  84. e X.zip
  85. "## Check :write when "zip" program is missing
  86. :1|:/^$//file/
  87. exe "normal \<cr>Goanother\<esc>"
  88. let save_zip_zipcmd = g:zip_zipcmd
  89. let g:zip_zipcmd = "/"
  90. call assert_match('sorry, your system doesn''t appear to have the / program',
  91. \ execute("write"))
  92. "## Check when "zip" report failure
  93. if executable("false")
  94. let g:zip_zipcmd = "false"
  95. call assert_match('sorry, unable to update .*/X.zip with Xzip/file.txt',
  96. \ execute("write"))
  97. endif
  98. bw!|bw
  99. let g:zip_zipcmd = save_zip_zipcmd
  100. "## Check opening an no zipfile
  101. call writefile(["qsdf"], "Xcorupt.zip", "D")
  102. e! Xcorupt.zip
  103. call assert_equal("qsdf", getline(1))
  104. bw
  105. "## Check no existing zipfile
  106. call assert_match('File not readable', execute("e Xnot_exists.zip"))
  107. bw
  108. endfunc
  109. func Test_zip_glob_fname()
  110. CheckNotMSWindows
  111. " does not work on Windows, why?
  112. "## copy sample zip file
  113. if !filecopy("samples/testa.zip", "X.zip")
  114. call assert_report("Can't copy samples/testa.zip")
  115. return
  116. endif
  117. defer delete("X.zip")
  118. defer delete('zipglob', 'rf')
  119. e X.zip
  120. "## 1) Check extracting strange files
  121. :1
  122. let fname = 'a[a].txt'
  123. call search('\V' .. fname)
  124. normal x
  125. call assert_true(filereadable('zipglob/' .. fname))
  126. call delete('zipglob', 'rf')
  127. :1
  128. let fname = 'a*.txt'
  129. call search('\V' .. fname)
  130. normal x
  131. call assert_true(filereadable('zipglob/' .. fname))
  132. call delete('zipglob', 'rf')
  133. :1
  134. let fname = 'a?.txt'
  135. call search('\V' .. fname)
  136. normal x
  137. call assert_true(filereadable('zipglob/' .. fname))
  138. call delete('zipglob', 'rf')
  139. :1
  140. let fname = 'a\.txt'
  141. call search('\V' .. escape(fname, '\\'))
  142. normal x
  143. call assert_true(filereadable('zipglob/' .. fname))
  144. call delete('zipglob', 'rf')
  145. :1
  146. let fname = 'a\\.txt'
  147. call search('\V' .. escape(fname, '\\'))
  148. normal x
  149. call assert_true(filereadable('zipglob/' .. fname))
  150. call delete('zipglob', 'rf')
  151. "## 2) Check entering strange file names
  152. :1
  153. let fname = 'a[a].txt'
  154. call search('\V' .. fname)
  155. exe ":normal \<cr>"
  156. call assert_match('zipfile://.*/X.zip::zipglob/a\[a\].txt', @%)
  157. call assert_equal('a test file with []', getline(1))
  158. bw
  159. e X.zip
  160. :1
  161. let fname = 'a*.txt'
  162. call search('\V' .. fname)
  163. exe ":normal \<cr>"
  164. call assert_match('zipfile://.*/X.zip::zipglob/a\*.txt', @%)
  165. call assert_equal('a test file with a*', getline(1))
  166. bw
  167. e X.zip
  168. :1
  169. let fname = 'a?.txt'
  170. call search('\V' .. fname)
  171. exe ":normal \<cr>"
  172. call assert_match('zipfile://.*/X.zip::zipglob/a?.txt', @%)
  173. call assert_equal('a test file with a?', getline(1))
  174. bw
  175. e X.zip
  176. :1
  177. let fname = 'a\.txt'
  178. call search('\V' .. escape(fname, '\\'))
  179. exe ":normal \<cr>"
  180. call assert_match('zipfile://.*/X.zip::zipglob/a\\.txt', @%)
  181. call assert_equal('a test file with a\', getline(1))
  182. bw
  183. e X.zip
  184. :1
  185. let fname = 'a\\.txt'
  186. call search('\V' .. escape(fname, '\\'))
  187. exe ":normal \<cr>"
  188. call assert_match('zipfile://.*/X.zip::zipglob/a\\\\.txt', @%)
  189. call assert_equal('a test file with a double \', getline(1))
  190. bw
  191. bw
  192. endfunc