Damien | d7af21e | 2024-08-05 20:24:11 +0200 | [diff] [blame] | 1 | so check.vim |
| 2 | |
| 3 | CheckExecutable unzip |
| 4 | |
| 5 | if 0 " Find uncovered line |
| 6 | profile start zip_profile |
| 7 | profile! file */zip*.vim |
| 8 | endif |
| 9 | |
| 10 | runtime plugin/zipPlugin.vim |
| 11 | |
| 12 | def Test_zip_basic() |
Damien | d7af21e | 2024-08-05 20:24:11 +0200 | [diff] [blame] | 13 | |
| 14 | ### get our zip file |
| 15 | if !filecopy("samples/test.zip", "X.zip") |
| 16 | assert_report("Can't copy samples/test.zip") |
| 17 | return |
| 18 | endif |
| 19 | defer delete("X.zip") |
| 20 | |
| 21 | e X.zip |
| 22 | |
| 23 | ### Check header |
| 24 | assert_match('^" zip\.vim version v\d\+', getline(1)) |
| 25 | assert_match('^" Browsing zipfile .*/X.zip', getline(2)) |
| 26 | assert_match('^" Select a file with cursor and press ENTER', getline(3)) |
| 27 | assert_match('^$', getline(4)) |
| 28 | |
| 29 | ### Check files listing |
| 30 | assert_equal(["Xzip/", "Xzip/dir/", "Xzip/file.txt"], getline(5, 7)) |
| 31 | |
| 32 | ### Check ENTER on header |
| 33 | :1 |
| 34 | exe ":normal \<cr>" |
| 35 | assert_equal("X.zip", @%) |
| 36 | |
| 37 | ### Check ENTER on directory |
| 38 | :1|:/^$//dir/ |
| 39 | assert_match('Please specify a file, not a directory', |
| 40 | execute("normal \<CR>")) |
| 41 | |
| 42 | ### Check ENTER on file |
| 43 | :1|:/^$//file/ |
| 44 | exe ":normal \<cr>" |
| 45 | assert_match('zipfile://.*/X.zip::Xzip/file.txt', @%) |
| 46 | assert_equal('one', getline(1)) |
| 47 | |
| 48 | ### Check editing file |
| 49 | if executable("zip") |
| 50 | s/one/two/ |
| 51 | assert_equal("two", getline(1)) |
| 52 | w |
| 53 | bw|bw |
| 54 | e X.zip |
| 55 | |
| 56 | :1|:/^$//file/ |
| 57 | exe "normal \<cr>" |
| 58 | assert_equal("two", getline(1)) |
| 59 | endif |
| 60 | |
| 61 | only |
| 62 | e X.zip |
| 63 | |
| 64 | ### Check extracting file |
| 65 | :1|:/^$//file/ |
| 66 | normal x |
| 67 | assert_true(filereadable("Xzip/file.txt")) |
| 68 | delete("Xzip", "rf") |
| 69 | |
| 70 | ### Check extracting directory |
| 71 | :1|:/^$//dir/ |
| 72 | assert_match('Please specify a file, not a directory', execute("normal x")) |
| 73 | assert_equal("X.zip", @%) |
| 74 | |
| 75 | ### Check "x" on header |
| 76 | :1 |
| 77 | normal x |
| 78 | assert_equal("X.zip", @%) |
| 79 | bw |
| 80 | |
| 81 | ### Check opening zip when "unzip" program is missing |
| 82 | var save_zip_unzipcmd = g:zip_unzipcmd |
| 83 | g:zip_unzipcmd = "/" |
| 84 | assert_match('unzip not available on your system', execute("e X.zip")) |
| 85 | |
| 86 | ### Check when "unzip" don't work |
| 87 | if executable("false") |
| 88 | g:zip_unzipcmd = "false" |
| 89 | assert_match('X\.zip is not a zip file', execute("e X.zip")) |
| 90 | endif |
| 91 | bw |
| 92 | |
| 93 | g:zip_unzipcmd = save_zip_unzipcmd |
| 94 | e X.zip |
| 95 | |
| 96 | ### Check opening file when "unzip" is missing |
| 97 | g:zip_unzipcmd = "/" |
| 98 | assert_match('sorry, your system doesn''t appear to have the / program', |
| 99 | execute("normal \<CR>")) |
| 100 | |
| 101 | bw|bw |
| 102 | g:zip_unzipcmd = save_zip_unzipcmd |
| 103 | e X.zip |
| 104 | |
| 105 | ### Check :write when "zip" program is missing |
| 106 | :1|:/^$//file/ |
| 107 | exe "normal \<cr>Goanother\<esc>" |
| 108 | var save_zip_zipcmd = g:zip_zipcmd |
| 109 | g:zip_zipcmd = "/" |
| 110 | assert_match('sorry, your system doesn''t appear to have the / program', |
| 111 | execute("write")) |
| 112 | |
| 113 | ### Check when "zip" report failure |
| 114 | if executable("false") |
| 115 | g:zip_zipcmd = "false" |
| 116 | assert_match('sorry, unable to update .*/X.zip with Xzip/file.txt', |
| 117 | execute("write")) |
| 118 | endif |
| 119 | bw!|bw |
| 120 | |
| 121 | g:zip_zipcmd = save_zip_zipcmd |
| 122 | |
| 123 | ### Check opening an no zipfile |
| 124 | writefile(["qsdf"], "Xcorupt.zip", "D") |
| 125 | e! Xcorupt.zip |
| 126 | assert_equal("qsdf", getline(1)) |
| 127 | |
| 128 | bw |
| 129 | |
| 130 | ### Check no existing zipfile |
| 131 | assert_match('File not readable', execute("e Xnot_exists.zip")) |
| 132 | |
| 133 | bw |
| 134 | |
Damien | d7af21e | 2024-08-05 20:24:11 +0200 | [diff] [blame] | 135 | enddef |