fix rubocop Style/Blocks cop
This commit is contained in:
parent
0c6a10e631
commit
d2d8590ef8
|
@ -67,11 +67,6 @@ Style/AccessorMethodName:
|
||||||
Style/BarePercentLiterals:
|
Style/BarePercentLiterals:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
# Offense count: 137
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
Style/Blocks:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
# Offense count: 3
|
# Offense count: 3
|
||||||
Style/CaseEquality:
|
Style/CaseEquality:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
|
@ -256,25 +256,25 @@ module Zip
|
||||||
end
|
end
|
||||||
|
|
||||||
def chown(ownerInt, groupInt, *filenames)
|
def chown(ownerInt, groupInt, *filenames)
|
||||||
filenames.each { |fileName|
|
filenames.each do |fileName|
|
||||||
e = get_entry(fileName)
|
e = get_entry(fileName)
|
||||||
unless e.extra.member?("IUnix")
|
unless e.extra.member?("IUnix")
|
||||||
e.extra.create("IUnix")
|
e.extra.create("IUnix")
|
||||||
end
|
end
|
||||||
e.extra["IUnix"].uid = ownerInt
|
e.extra["IUnix"].uid = ownerInt
|
||||||
e.extra["IUnix"].gid = groupInt
|
e.extra["IUnix"].gid = groupInt
|
||||||
}
|
end
|
||||||
filenames.size
|
filenames.size
|
||||||
end
|
end
|
||||||
|
|
||||||
def chmod (modeInt, *filenames)
|
def chmod (modeInt, *filenames)
|
||||||
filenames.each { |fileName|
|
filenames.each do |fileName|
|
||||||
e = get_entry(fileName)
|
e = get_entry(fileName)
|
||||||
e.fstype = 3 # force convertion filesystem type to unix
|
e.fstype = 3 # force convertion filesystem type to unix
|
||||||
e.unix_perms = modeInt
|
e.unix_perms = modeInt
|
||||||
e.external_file_attributes = modeInt << 16
|
e.external_file_attributes = modeInt << 16
|
||||||
e.dirty = true
|
e.dirty = true
|
||||||
}
|
end
|
||||||
filenames.size
|
filenames.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -307,9 +307,9 @@ module Zip
|
||||||
end
|
end
|
||||||
|
|
||||||
def utime(modifiedTime, *fileNames)
|
def utime(modifiedTime, *fileNames)
|
||||||
fileNames.each { |fileName|
|
fileNames.each do |fileName|
|
||||||
get_entry(fileName).time = modifiedTime
|
get_entry(fileName).time = modifiedTime
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def mtime(fileName)
|
def mtime(fileName)
|
||||||
|
@ -404,13 +404,12 @@ module Zip
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(*args)
|
def delete(*args)
|
||||||
args.each {
|
args.each do |fileName|
|
||||||
|fileName|
|
|
||||||
if directory?(fileName)
|
if directory?(fileName)
|
||||||
raise Errno::EISDIR, "Is a directory - \"#{fileName}\""
|
raise Errno::EISDIR, "Is a directory - \"#{fileName}\""
|
||||||
end
|
end
|
||||||
@mappedZip.remove(fileName)
|
@mappedZip.remove(fileName)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def rename(fileToRename, newName)
|
def rename(fileToRename, newName)
|
||||||
|
@ -483,11 +482,10 @@ module Zip
|
||||||
path << '/' unless path.end_with?('/')
|
path << '/' unless path.end_with?('/')
|
||||||
path = Regexp.escape(path)
|
path = Regexp.escape(path)
|
||||||
subDirEntriesRegex = Regexp.new("^#{path}([^/]+)$")
|
subDirEntriesRegex = Regexp.new("^#{path}([^/]+)$")
|
||||||
@mappedZip.each {
|
@mappedZip.each do |fileName|
|
||||||
|fileName|
|
|
||||||
match = subDirEntriesRegex.match(fileName)
|
match = subDirEntriesRegex.match(fileName)
|
||||||
yield(match[1]) unless match == nil
|
yield(match[1]) unless match == nil
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(entryName)
|
def delete(entryName)
|
||||||
|
@ -595,10 +593,9 @@ module Zip
|
||||||
# Turns entries into strings and adds leading /
|
# Turns entries into strings and adds leading /
|
||||||
# and removes trailing slash on directories
|
# and removes trailing slash on directories
|
||||||
def each
|
def each
|
||||||
@zipFile.each {
|
@zipFile.each do |e|
|
||||||
|e|
|
|
||||||
yield("/"+e.to_s.chomp("/"))
|
yield("/"+e.to_s.chomp("/"))
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def expand_path(aPath)
|
def expand_path(aPath)
|
||||||
|
|
|
@ -7,34 +7,30 @@ require 'zip'
|
||||||
|
|
||||||
####### Using ZipInputStream alone: #######
|
####### Using ZipInputStream alone: #######
|
||||||
|
|
||||||
Zip::InputStream.open("example.zip") {
|
Zip::InputStream.open("example.zip") do |zis|
|
||||||
|zis|
|
|
||||||
entry = zis.get_next_entry
|
entry = zis.get_next_entry
|
||||||
print "First line of '#{entry.name} (#{entry.size} bytes): "
|
print "First line of '#{entry.name} (#{entry.size} bytes): "
|
||||||
puts "'#{zis.gets.chomp}'"
|
puts "'#{zis.gets.chomp}'"
|
||||||
entry = zis.get_next_entry
|
entry = zis.get_next_entry
|
||||||
print "First line of '#{entry.name} (#{entry.size} bytes): "
|
print "First line of '#{entry.name} (#{entry.size} bytes): "
|
||||||
puts "'#{zis.gets.chomp}'"
|
puts "'#{zis.gets.chomp}'"
|
||||||
}
|
end
|
||||||
|
|
||||||
|
|
||||||
####### Using ZipFile to read the directory of a zip file: #######
|
####### Using ZipFile to read the directory of a zip file: #######
|
||||||
|
|
||||||
zf = Zip::File.new("example.zip")
|
zf = Zip::File.new("example.zip")
|
||||||
zf.each_with_index {
|
zf.each_with_index do |entry, index|
|
||||||
|entry, index|
|
|
||||||
|
|
||||||
puts "entry #{index} is #{entry.name}, size = #{entry.size}, compressed size = #{entry.compressed_size}"
|
puts "entry #{index} is #{entry.name}, size = #{entry.size}, compressed size = #{entry.compressed_size}"
|
||||||
# use zf.get_input_stream(entry) to get a ZipInputStream for the entry
|
# use zf.get_input_stream(entry) to get a ZipInputStream for the entry
|
||||||
# entry can be the ZipEntry object or any object which has a to_s method that
|
# entry can be the ZipEntry object or any object which has a to_s method that
|
||||||
# returns the name of the entry.
|
# returns the name of the entry.
|
||||||
}
|
end
|
||||||
|
|
||||||
|
|
||||||
####### Using ZipOutputStream to write a zip file: #######
|
####### Using ZipOutputStream to write a zip file: #######
|
||||||
|
|
||||||
Zip::OutputStream.open("exampleout.zip") {
|
Zip::OutputStream.open("exampleout.zip") do |zos|
|
||||||
|zos|
|
|
||||||
zos.put_next_entry("the first little entry")
|
zos.put_next_entry("the first little entry")
|
||||||
zos.puts "Hello hello hello hello hello hello hello hello hello"
|
zos.puts "Hello hello hello hello hello hello hello hello hello"
|
||||||
|
|
||||||
|
@ -43,24 +39,22 @@ Zip::OutputStream.open("exampleout.zip") {
|
||||||
|
|
||||||
# Use rubyzip or your zip client of choice to verify
|
# Use rubyzip or your zip client of choice to verify
|
||||||
# the contents of exampleout.zip
|
# the contents of exampleout.zip
|
||||||
}
|
end
|
||||||
|
|
||||||
####### Using ZipFile to change a zip file: #######
|
####### Using ZipFile to change a zip file: #######
|
||||||
|
|
||||||
Zip::File.open("exampleout.zip") {
|
Zip::File.open("exampleout.zip") do |zip_file|
|
||||||
|zip_file|
|
|
||||||
zip_file.add("thisFile.rb", "example.rb")
|
zip_file.add("thisFile.rb", "example.rb")
|
||||||
zip_file.rename("thisFile.rb", "ILikeThisName.rb")
|
zip_file.rename("thisFile.rb", "ILikeThisName.rb")
|
||||||
zip_file.add("Again", "example.rb")
|
zip_file.add("Again", "example.rb")
|
||||||
}
|
end
|
||||||
|
|
||||||
# Lets check
|
# Lets check
|
||||||
Zip::File.open("exampleout.zip") {
|
Zip::File.open("exampleout.zip") do |zip_file|
|
||||||
|zip_file|
|
|
||||||
puts "Changed zip file contains: #{zip_file.entries.join(', ')}"
|
puts "Changed zip file contains: #{zip_file.entries.join(', ')}"
|
||||||
zip_file.remove("Again")
|
zip_file.remove("Again")
|
||||||
puts "Without 'Again': #{zip_file.entries.join(', ')}"
|
puts "Without 'Again': #{zip_file.entries.join(', ')}"
|
||||||
}
|
end
|
||||||
|
|
||||||
####### Using ZipFile to split a zip file: #######
|
####### Using ZipFile to split a zip file: #######
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,7 @@ EXAMPLE_ZIP = "filesystem.zip"
|
||||||
|
|
||||||
File.delete(EXAMPLE_ZIP) if File.exist?(EXAMPLE_ZIP)
|
File.delete(EXAMPLE_ZIP) if File.exist?(EXAMPLE_ZIP)
|
||||||
|
|
||||||
Zip::File.open(EXAMPLE_ZIP, Zip::File::CREATE) {
|
Zip::File.open(EXAMPLE_ZIP, Zip::File::CREATE) do |zf|
|
||||||
|zf|
|
|
||||||
zf.file.open("file1.txt", "w") { |os| os.write "first file1.txt" }
|
zf.file.open("file1.txt", "w") { |os| os.write "first file1.txt" }
|
||||||
zf.dir.mkdir("dir1")
|
zf.dir.mkdir("dir1")
|
||||||
zf.dir.chdir("dir1")
|
zf.dir.chdir("dir1")
|
||||||
|
@ -19,12 +18,11 @@ Zip::File.open(EXAMPLE_ZIP, Zip::File::CREATE) {
|
||||||
zf.dir.chdir("..")
|
zf.dir.chdir("..")
|
||||||
zf.file.open("file2.txt", "w") { |os| os.write "first file2.txt" }
|
zf.file.open("file2.txt", "w") { |os| os.write "first file2.txt" }
|
||||||
puts "Entries: #{zf.entries.join(', ')}"
|
puts "Entries: #{zf.entries.join(', ')}"
|
||||||
}
|
end
|
||||||
|
|
||||||
Zip::File.open(EXAMPLE_ZIP) {
|
Zip::File.open(EXAMPLE_ZIP) do |zf|
|
||||||
|zf|
|
|
||||||
puts "Entries from reloaded zip: #{zf.entries.join(', ')}"
|
puts "Entries from reloaded zip: #{zf.entries.join(', ')}"
|
||||||
}
|
end
|
||||||
|
|
||||||
# For other examples, look at zip.rb and ziptest.rb
|
# For other examples, look at zip.rb and ziptest.rb
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ class ZipFileGenerator
|
||||||
private
|
private
|
||||||
def writeEntries(entries, path, io)
|
def writeEntries(entries, path, io)
|
||||||
|
|
||||||
entries.each { |e|
|
entries.each do |e|
|
||||||
zipFilePath = path == "" ? e : File.join(path, e)
|
zipFilePath = path == "" ? e : File.join(path, e)
|
||||||
diskFilePath = File.join(@inputDir, zipFilePath)
|
diskFilePath = File.join(@inputDir, zipFilePath)
|
||||||
puts "Deflating " + diskFilePath
|
puts "Deflating " + diskFilePath
|
||||||
|
@ -42,7 +42,7 @@ class ZipFileGenerator
|
||||||
else
|
else
|
||||||
io.get_output_stream(zipFilePath) { |f| f.puts(File.open(diskFilePath, "rb").read())}
|
io.get_output_stream(zipFilePath) { |f| f.puts(File.open(diskFilePath, "rb").read())}
|
||||||
end
|
end
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,12 +19,12 @@ class MainApp < Gtk::Window
|
||||||
|
|
||||||
@zipfile = nil
|
@zipfile = nil
|
||||||
@buttonPanel = ButtonPanel.new
|
@buttonPanel = ButtonPanel.new
|
||||||
@buttonPanel.openButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
@buttonPanel.openButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
|
||||||
show_file_selector
|
show_file_selector
|
||||||
}
|
end
|
||||||
@buttonPanel.extractButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
@buttonPanel.extractButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
|
||||||
puts "Not implemented!"
|
puts "Not implemented!"
|
||||||
}
|
end
|
||||||
box.pack_start(@buttonPanel, false, false, 0)
|
box.pack_start(@buttonPanel, false, false, 0)
|
||||||
|
|
||||||
sw = Gtk::ScrolledWindow.new
|
sw = Gtk::ScrolledWindow.new
|
||||||
|
@ -35,10 +35,9 @@ class MainApp < Gtk::Window
|
||||||
@clist.set_selection_mode(Gtk::SELECTION_BROWSE)
|
@clist.set_selection_mode(Gtk::SELECTION_BROWSE)
|
||||||
@clist.set_column_width(0, 120)
|
@clist.set_column_width(0, 120)
|
||||||
@clist.set_column_width(1, 120)
|
@clist.set_column_width(1, 120)
|
||||||
@clist.signal_connect(Gtk::CList::SIGNAL_SELECT_ROW) {
|
@clist.signal_connect(Gtk::CList::SIGNAL_SELECT_ROW) do |_w, row, _column, _event|
|
||||||
|_w, row, _column, _event|
|
|
||||||
@selected_row = row
|
@selected_row = row
|
||||||
}
|
end
|
||||||
sw.add(@clist)
|
sw.add(@clist)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -58,24 +57,23 @@ class MainApp < Gtk::Window
|
||||||
def show_file_selector
|
def show_file_selector
|
||||||
@fileSelector = Gtk::FileSelection.new("Open zip file")
|
@fileSelector = Gtk::FileSelection.new("Open zip file")
|
||||||
@fileSelector.show
|
@fileSelector.show
|
||||||
@fileSelector.ok_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
@fileSelector.ok_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
|
||||||
open_zip(@fileSelector.filename)
|
open_zip(@fileSelector.filename)
|
||||||
@fileSelector.destroy
|
@fileSelector.destroy
|
||||||
}
|
end
|
||||||
@fileSelector.cancel_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
@fileSelector.cancel_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
|
||||||
@fileSelector.destroy
|
@fileSelector.destroy
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def open_zip(filename)
|
def open_zip(filename)
|
||||||
@zipfile = Zip::File.open(filename)
|
@zipfile = Zip::File.open(filename)
|
||||||
@clist.clear
|
@clist.clear
|
||||||
@zipfile.each {
|
@zipfile.each do |entry|
|
||||||
|entry|
|
|
||||||
@clist.append([ entry.name,
|
@clist.append([ entry.name,
|
||||||
entry.size.to_s,
|
entry.size.to_s,
|
||||||
(100.0*entry.compressedSize/entry.size).to_s+"%" ])
|
(100.0*entry.compressedSize/entry.size).to_s+"%" ])
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -35,10 +35,9 @@ class ZipDialog < ZipDialogUI
|
||||||
def refresh()
|
def refresh()
|
||||||
lv = child("entry_list_view")
|
lv = child("entry_list_view")
|
||||||
lv.clear
|
lv.clear
|
||||||
each {
|
each do |e|
|
||||||
|e|
|
|
||||||
lv.insert_item(Qt::ListViewItem.new(lv, e.name, e.size.to_s))
|
lv.insert_item(Qt::ListViewItem.new(lv, e.name, e.size.to_s))
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,13 +48,11 @@ class ZipDialog < ZipDialogUI
|
||||||
|
|
||||||
def add_files
|
def add_files
|
||||||
l = Qt::FileDialog.getOpenFileNames(nil, nil, self)
|
l = Qt::FileDialog.getOpenFileNames(nil, nil, self)
|
||||||
zipfile {
|
zipfile do |zf|
|
||||||
|zf|
|
l.each do |path|
|
||||||
l.each {
|
|
||||||
|path|
|
|
||||||
zf.add(File.basename(path), path)
|
zf.add(File.basename(path), path)
|
||||||
}
|
end
|
||||||
}
|
end
|
||||||
refresh
|
refresh
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
$: << "../lib"
|
$: << "../lib"
|
||||||
|
|
||||||
require 'zip'
|
require 'zip'
|
||||||
|
|
||||||
include Zip
|
include Zip
|
||||||
|
|
||||||
OutputStream.open('simple.zip') {
|
OutputStream.open('simple.zip') do |zos|
|
||||||
|zos|
|
zos.put_next_entry 'entry.txt'
|
||||||
zos.put_next_entry 'entry.txt'
|
zos.puts "Hello world"
|
||||||
zos.puts "Hello world"
|
end
|
||||||
}
|
|
||||||
|
|
|
@ -10,27 +10,24 @@ require 'find'
|
||||||
module Zip
|
module Zip
|
||||||
module ZipFind
|
module ZipFind
|
||||||
def self.find(path, zipFilePattern = /\.zip$/i)
|
def self.find(path, zipFilePattern = /\.zip$/i)
|
||||||
Find.find(path) {
|
Find.find(path) do |fileName|
|
||||||
|fileName|
|
yield(fileName)
|
||||||
yield(fileName)
|
if zipFilePattern.match(fileName) && File.file?(fileName)
|
||||||
if zipFilePattern.match(fileName) && File.file?(fileName)
|
begin
|
||||||
begin
|
Zip::File.foreach(fileName) do |zipEntry|
|
||||||
Zip::File.foreach(fileName) {
|
yield(fileName + File::SEPARATOR + zipEntry.to_s)
|
||||||
|zipEntry|
|
end
|
||||||
yield(fileName + File::SEPARATOR + zipEntry.to_s)
|
rescue Errno::EACCES => ex
|
||||||
}
|
puts ex
|
||||||
rescue Errno::EACCES => ex
|
end
|
||||||
puts ex
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_file(path, fileNamePattern, zipFilePattern = /\.zip$/i)
|
def self.find_file(path, fileNamePattern, zipFilePattern = /\.zip$/i)
|
||||||
self.find(path, zipFilePattern) {
|
self.find(path, zipFilePattern) do |fileName|
|
||||||
|fileName|
|
yield(fileName) if fileNamePattern.match(fileName)
|
||||||
yield(fileName) if fileNamePattern.match(fileName)
|
end
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -47,16 +44,15 @@ if __FILE__ == $0
|
||||||
check_args(args)
|
check_args(args)
|
||||||
Zip::ZipFind.find_file(args[PATH_ARG_INDEX],
|
Zip::ZipFind.find_file(args[PATH_ARG_INDEX],
|
||||||
args[FILENAME_PATTERN_ARG_INDEX],
|
args[FILENAME_PATTERN_ARG_INDEX],
|
||||||
args[ZIPFILE_PATTERN_ARG_INDEX]) {
|
args[ZIPFILE_PATTERN_ARG_INDEX]) do |fileName|
|
||||||
|fileName|
|
report_entry_found fileName
|
||||||
report_entry_found fileName
|
end
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.check_args(args)
|
def self.check_args(args)
|
||||||
if (args.size != 3)
|
if (args.size != 3)
|
||||||
usage
|
usage
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,26 +16,24 @@ class BasicZipFileTest < MiniTest::Test
|
||||||
def test_each
|
def test_each
|
||||||
count = 0
|
count = 0
|
||||||
visited = {}
|
visited = {}
|
||||||
@zip_file.each {
|
@zip_file.each do |entry|
|
||||||
|entry|
|
|
||||||
assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
|
assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
|
||||||
assert(!visited.include?(entry.name))
|
assert(!visited.include?(entry.name))
|
||||||
visited[entry.name] = nil
|
visited[entry.name] = nil
|
||||||
count = count.succ
|
count = count.succ
|
||||||
}
|
end
|
||||||
assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_foreach
|
def test_foreach
|
||||||
count = 0
|
count = 0
|
||||||
visited = {}
|
visited = {}
|
||||||
::Zip::File.foreach(TestZipFile::TEST_ZIP2.zip_name) {
|
::Zip::File.foreach(TestZipFile::TEST_ZIP2.zip_name) do |entry|
|
||||||
|entry|
|
|
||||||
assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
|
assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
|
||||||
assert(!visited.include?(entry.name))
|
assert(!visited.include?(entry.name))
|
||||||
visited[entry.name] = nil
|
visited[entry.name] = nil
|
||||||
count = count.succ
|
count = count.succ
|
||||||
}
|
end
|
||||||
assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -53,12 +51,11 @@ class BasicZipFileTest < MiniTest::Test
|
||||||
|
|
||||||
def test_get_input_streamBlock
|
def test_get_input_streamBlock
|
||||||
fileAndEntryName = @zip_file.entries.first.name
|
fileAndEntryName = @zip_file.entries.first.name
|
||||||
@zip_file.get_input_stream(fileAndEntryName) {
|
@zip_file.get_input_stream(fileAndEntryName) do |zis|
|
||||||
|zis|
|
|
||||||
assert_entryContentsForStream(fileAndEntryName,
|
assert_entryContentsForStream(fileAndEntryName,
|
||||||
zis,
|
zis,
|
||||||
fileAndEntryName)
|
fileAndEntryName)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,8 +3,7 @@ require 'test_helper'
|
||||||
class ZipCentralDirectoryEntryTest < MiniTest::Test
|
class ZipCentralDirectoryEntryTest < MiniTest::Test
|
||||||
|
|
||||||
def test_read_from_stream
|
def test_read_from_stream
|
||||||
File.open("test/data/testDirectory.bin", "rb") {
|
File.open("test/data/testDirectory.bin", "rb") do |file|
|
||||||
|file|
|
|
||||||
entry = ::Zip::Entry.read_c_dir_entry(file)
|
entry = ::Zip::Entry.read_c_dir_entry(file)
|
||||||
|
|
||||||
assert_equal("longAscii.txt", entry.name)
|
assert_equal("longAscii.txt", entry.name)
|
||||||
|
@ -57,7 +56,7 @@ class ZipCentralDirectoryEntryTest < MiniTest::Test
|
||||||
# extra field (variable size)
|
# extra field (variable size)
|
||||||
# file comment (variable size)
|
# file comment (variable size)
|
||||||
|
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ReadEntryFromTruncatedZipFile
|
def test_ReadEntryFromTruncatedZipFile
|
||||||
|
|
|
@ -7,25 +7,22 @@ class ZipCentralDirectoryTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_read_from_stream
|
def test_read_from_stream
|
||||||
::File.open(TestZipFile::TEST_ZIP2.zip_name, "rb") {
|
::File.open(TestZipFile::TEST_ZIP2.zip_name, "rb") do |zipFile|
|
||||||
|zipFile|
|
|
||||||
cdir = ::Zip::CentralDirectory.read_from_stream(zipFile)
|
cdir = ::Zip::CentralDirectory.read_from_stream(zipFile)
|
||||||
|
|
||||||
assert_equal(TestZipFile::TEST_ZIP2.entry_names.size, cdir.size)
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names.size, cdir.size)
|
||||||
assert(cdir.entries.sort.compare_enumerables(TestZipFile::TEST_ZIP2.entry_names.sort) {
|
assert(cdir.entries.sort.compare_enumerables(TestZipFile::TEST_ZIP2.entry_names.sort) do |cdirEntry, testEntryName|
|
||||||
|cdirEntry, testEntryName|
|
|
||||||
cdirEntry.name == testEntryName
|
cdirEntry.name == testEntryName
|
||||||
})
|
end)
|
||||||
assert_equal(TestZipFile::TEST_ZIP2.comment, cdir.comment)
|
assert_equal(TestZipFile::TEST_ZIP2.comment, cdir.comment)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_readFromInvalidStream
|
def test_readFromInvalidStream
|
||||||
File.open("test/data/file2.txt", "rb") {
|
File.open("test/data/file2.txt", "rb") do |zipFile|
|
||||||
|zipFile|
|
|
||||||
cdir = ::Zip::CentralDirectory.new
|
cdir = ::Zip::CentralDirectory.new
|
||||||
cdir.read_from_stream(zipFile)
|
cdir.read_from_stream(zipFile)
|
||||||
}
|
end
|
||||||
fail "ZipError expected!"
|
fail "ZipError expected!"
|
||||||
rescue ::Zip::Error
|
rescue ::Zip::Error
|
||||||
end
|
end
|
||||||
|
|
|
@ -42,23 +42,21 @@ class DeflaterTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def deflate(data, fileName)
|
def deflate(data, fileName)
|
||||||
File.open(fileName, "wb") {
|
File.open(fileName, "wb") do |file|
|
||||||
|file|
|
|
||||||
deflater = ::Zip::Deflater.new(file)
|
deflater = ::Zip::Deflater.new(file)
|
||||||
deflater << data
|
deflater << data
|
||||||
deflater.finish
|
deflater.finish
|
||||||
assert_equal(deflater.size, data.size)
|
assert_equal(deflater.size, data.size)
|
||||||
file << "trailing data for zlib with -MAX_WBITS"
|
file << "trailing data for zlib with -MAX_WBITS"
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def inflate(fileName)
|
def inflate(fileName)
|
||||||
txt = nil
|
txt = nil
|
||||||
File.open(fileName, "rb") {
|
File.open(fileName, "rb") do |file|
|
||||||
|file|
|
|
||||||
inflater = ::Zip::Inflater.new(file)
|
inflater = ::Zip::Inflater.new(file)
|
||||||
txt = inflater.sysread
|
txt = inflater.sysread
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_crc
|
def test_crc
|
||||||
|
|
|
@ -11,10 +11,9 @@ class ZipFileExtractDirectoryTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_test_dir(&aProc)
|
def extract_test_dir(&aProc)
|
||||||
open_zip {
|
open_zip do |zf|
|
||||||
|zf|
|
|
||||||
zf.extract(TestFiles::EMPTY_TEST_DIR, TEST_OUT_NAME, &aProc)
|
zf.extract(TestFiles::EMPTY_TEST_DIR, TEST_OUT_NAME, &aProc)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
|
@ -43,13 +42,12 @@ class ZipFileExtractDirectoryTest < MiniTest::Test
|
||||||
def test_extractDirectoryExistsAsFileOverwrite
|
def test_extractDirectoryExistsAsFileOverwrite
|
||||||
File.open(TEST_OUT_NAME, "w") { |f| f.puts "something" }
|
File.open(TEST_OUT_NAME, "w") { |f| f.puts "something" }
|
||||||
gotCalled = false
|
gotCalled = false
|
||||||
extract_test_dir {
|
extract_test_dir do |entry, destPath|
|
||||||
|entry, destPath|
|
|
||||||
gotCalled = true
|
gotCalled = true
|
||||||
assert_equal(TEST_OUT_NAME, destPath)
|
assert_equal(TEST_OUT_NAME, destPath)
|
||||||
assert(entry.directory?)
|
assert(entry.directory?)
|
||||||
true
|
true
|
||||||
}
|
end
|
||||||
assert(gotCalled)
|
assert(gotCalled)
|
||||||
assert(File.directory?(TEST_OUT_NAME))
|
assert(File.directory?(TEST_OUT_NAME))
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,8 +11,7 @@ class ZipFileExtractTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_extract
|
def test_extract
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
|zf|
|
|
||||||
zf.extract(ENTRY_TO_EXTRACT, EXTRACTED_FILENAME)
|
zf.extract(ENTRY_TO_EXTRACT, EXTRACTED_FILENAME)
|
||||||
|
|
||||||
assert(File.exist?(EXTRACTED_FILENAME))
|
assert(File.exist?(EXTRACTED_FILENAME))
|
||||||
|
@ -29,21 +28,21 @@ class ZipFileExtractTest < MiniTest::Test
|
||||||
AssertEntry::assert_contents(EXTRACTED_FILENAME,
|
AssertEntry::assert_contents(EXTRACTED_FILENAME,
|
||||||
entry.get_input_stream() { |is| is.read })
|
entry.get_input_stream() { |is| is.read })
|
||||||
|
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_extractExists
|
def test_extractExists
|
||||||
writtenText = "written text"
|
writtenText = "written text"
|
||||||
::File.open(EXTRACTED_FILENAME, "w") { |f| f.write(writtenText) }
|
::File.open(EXTRACTED_FILENAME, "w") { |f| f.write(writtenText) }
|
||||||
|
|
||||||
assert_raises(::Zip::DestinationFileExistsError) {
|
assert_raises(::Zip::DestinationFileExistsError) do
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) { |zf|
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
zf.extract(zf.entries.first, EXTRACTED_FILENAME)
|
zf.extract(zf.entries.first, EXTRACTED_FILENAME)
|
||||||
}
|
end
|
||||||
}
|
end
|
||||||
File.open(EXTRACTED_FILENAME, "r") { |f|
|
File.open(EXTRACTED_FILENAME, "r") do |f|
|
||||||
assert_equal(writtenText, f.read)
|
assert_equal(writtenText, f.read)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_extractExistsOverwrite
|
def test_extractExistsOverwrite
|
||||||
|
@ -51,21 +50,18 @@ class ZipFileExtractTest < MiniTest::Test
|
||||||
::File.open(EXTRACTED_FILENAME, "w") { |f| f.write(writtenText) }
|
::File.open(EXTRACTED_FILENAME, "w") { |f| f.write(writtenText) }
|
||||||
|
|
||||||
gotCalledCorrectly = false
|
gotCalledCorrectly = false
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
|zf|
|
zf.extract(zf.entries.first, EXTRACTED_FILENAME) do |entry, extractLoc|
|
||||||
zf.extract(zf.entries.first, EXTRACTED_FILENAME) {
|
|
||||||
|entry, extractLoc|
|
|
||||||
gotCalledCorrectly = zf.entries.first == entry &&
|
gotCalledCorrectly = zf.entries.first == entry &&
|
||||||
extractLoc == EXTRACTED_FILENAME
|
extractLoc == EXTRACTED_FILENAME
|
||||||
true
|
true
|
||||||
}
|
end
|
||||||
}
|
end
|
||||||
|
|
||||||
assert(gotCalledCorrectly)
|
assert(gotCalledCorrectly)
|
||||||
::File.open(EXTRACTED_FILENAME, "r") {
|
::File.open(EXTRACTED_FILENAME, "r") do |f|
|
||||||
|f|
|
|
||||||
assert(writtenText != f.read)
|
assert(writtenText != f.read)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_extractNonEntry
|
def test_extractNonEntry
|
||||||
|
@ -77,13 +73,13 @@ class ZipFileExtractTest < MiniTest::Test
|
||||||
|
|
||||||
def test_extractNonEntry2
|
def test_extractNonEntry2
|
||||||
outFile = "outfile"
|
outFile = "outfile"
|
||||||
assert_raises(Errno::ENOENT) {
|
assert_raises(Errno::ENOENT) do
|
||||||
zf = ::Zip::File.new(TEST_ZIP.zip_name)
|
zf = ::Zip::File.new(TEST_ZIP.zip_name)
|
||||||
nonEntry = "hotdog-diddelidoo"
|
nonEntry = "hotdog-diddelidoo"
|
||||||
assert(!zf.entries.include?(nonEntry))
|
assert(!zf.entries.include?(nonEntry))
|
||||||
zf.extract(nonEntry, outFile)
|
zf.extract(nonEntry, outFile)
|
||||||
zf.close
|
zf.close
|
||||||
}
|
end
|
||||||
assert(!File.exist?(outFile))
|
assert(!File.exist?(outFile))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -43,28 +43,24 @@ class ZipFileTest < MiniTest::Test
|
||||||
|
|
||||||
def test_get_output_stream
|
def test_get_output_stream
|
||||||
entryCount = nil
|
entryCount = nil
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
|zf|
|
|
||||||
entryCount = zf.size
|
entryCount = zf.size
|
||||||
zf.get_output_stream('newEntry.txt') {
|
zf.get_output_stream('newEntry.txt') do |os|
|
||||||
|os|
|
|
||||||
os.write "Putting stuff in newEntry.txt"
|
os.write "Putting stuff in newEntry.txt"
|
||||||
}
|
end
|
||||||
assert_equal(entryCount+1, zf.size)
|
assert_equal(entryCount+1, zf.size)
|
||||||
assert_equal("Putting stuff in newEntry.txt", zf.read("newEntry.txt"))
|
assert_equal("Putting stuff in newEntry.txt", zf.read("newEntry.txt"))
|
||||||
|
|
||||||
zf.get_output_stream(zf.get_entry('test/data/generated/empty.txt')) {
|
zf.get_output_stream(zf.get_entry('test/data/generated/empty.txt')) do |os|
|
||||||
|os|
|
|
||||||
os.write "Putting stuff in data/generated/empty.txt"
|
os.write "Putting stuff in data/generated/empty.txt"
|
||||||
}
|
end
|
||||||
assert_equal(entryCount+1, zf.size)
|
assert_equal(entryCount+1, zf.size)
|
||||||
assert_equal("Putting stuff in data/generated/empty.txt", zf.read("test/data/generated/empty.txt"))
|
assert_equal("Putting stuff in data/generated/empty.txt", zf.read("test/data/generated/empty.txt"))
|
||||||
|
|
||||||
custom_entry_args = [ZipEntryTest::TEST_COMMENT, ZipEntryTest::TEST_EXTRA, ZipEntryTest::TEST_COMPRESSED_SIZE, ZipEntryTest::TEST_CRC, ::Zip::Entry::STORED, ZipEntryTest::TEST_SIZE, ZipEntryTest::TEST_TIME]
|
custom_entry_args = [ZipEntryTest::TEST_COMMENT, ZipEntryTest::TEST_EXTRA, ZipEntryTest::TEST_COMPRESSED_SIZE, ZipEntryTest::TEST_CRC, ::Zip::Entry::STORED, ZipEntryTest::TEST_SIZE, ZipEntryTest::TEST_TIME]
|
||||||
zf.get_output_stream('entry_with_custom_args.txt', nil, *custom_entry_args) {
|
zf.get_output_stream('entry_with_custom_args.txt', nil, *custom_entry_args) do |os|
|
||||||
|os|
|
|
||||||
os.write "Some data"
|
os.write "Some data"
|
||||||
}
|
end
|
||||||
assert_equal(entryCount+2, zf.size)
|
assert_equal(entryCount+2, zf.size)
|
||||||
entry = zf.get_entry('entry_with_custom_args.txt')
|
entry = zf.get_entry('entry_with_custom_args.txt')
|
||||||
assert_equal(custom_entry_args[0], entry.comment)
|
assert_equal(custom_entry_args[0], entry.comment)
|
||||||
|
@ -74,19 +70,17 @@ class ZipFileTest < MiniTest::Test
|
||||||
assert_equal(custom_entry_args[5], entry.size)
|
assert_equal(custom_entry_args[5], entry.size)
|
||||||
assert_equal(custom_entry_args[6], entry.time)
|
assert_equal(custom_entry_args[6], entry.time)
|
||||||
|
|
||||||
zf.get_output_stream('entry.bin') {
|
zf.get_output_stream('entry.bin') do |os|
|
||||||
|os|
|
|
||||||
os.write(::File.open('test/data/generated/5entry.zip', 'rb').read)
|
os.write(::File.open('test/data/generated/5entry.zip', 'rb').read)
|
||||||
}
|
end
|
||||||
}
|
end
|
||||||
|
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
|zf|
|
|
||||||
assert_equal(entryCount+3, zf.size)
|
assert_equal(entryCount+3, zf.size)
|
||||||
assert_equal("Putting stuff in newEntry.txt", zf.read("newEntry.txt"))
|
assert_equal("Putting stuff in newEntry.txt", zf.read("newEntry.txt"))
|
||||||
assert_equal("Putting stuff in data/generated/empty.txt", zf.read("test/data/generated/empty.txt"))
|
assert_equal("Putting stuff in data/generated/empty.txt", zf.read("test/data/generated/empty.txt"))
|
||||||
assert_equal(File.open('test/data/generated/5entry.zip', 'rb').read, zf.read("entry.bin"))
|
assert_equal(File.open('test/data/generated/5entry.zip', 'rb').read, zf.read("entry.bin"))
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cleans_up_tempfiles_after_close
|
def test_cleans_up_tempfiles_after_close
|
||||||
|
@ -133,39 +127,34 @@ class ZipFileTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_addExistingEntryName
|
def test_addExistingEntryName
|
||||||
assert_raises(::Zip::EntryExistsError) {
|
assert_raises(::Zip::EntryExistsError) do
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
|zf|
|
|
||||||
zf.add(zf.entries.first.name, "test/data/file2.txt")
|
zf.add(zf.entries.first.name, "test/data/file2.txt")
|
||||||
}
|
end
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_addExistingEntryNameReplace
|
def test_addExistingEntryNameReplace
|
||||||
gotCalled = false
|
gotCalled = false
|
||||||
replacedEntry = nil
|
replacedEntry = nil
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
|zf|
|
|
||||||
replacedEntry = zf.entries.first.name
|
replacedEntry = zf.entries.first.name
|
||||||
zf.add(replacedEntry, "test/data/file2.txt") { gotCalled = true; true }
|
zf.add(replacedEntry, "test/data/file2.txt") { gotCalled = true; true }
|
||||||
}
|
end
|
||||||
assert(gotCalled)
|
assert(gotCalled)
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
|zf|
|
|
||||||
assert_contains(zf, replacedEntry, "test/data/file2.txt")
|
assert_contains(zf, replacedEntry, "test/data/file2.txt")
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_addDirectory
|
def test_addDirectory
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
|zf|
|
|
||||||
zf.add(TestFiles::EMPTY_TEST_DIR, TestFiles::EMPTY_TEST_DIR)
|
zf.add(TestFiles::EMPTY_TEST_DIR, TestFiles::EMPTY_TEST_DIR)
|
||||||
}
|
end
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
|zf|
|
|
||||||
dirEntry = zf.entries.detect { |e| e.name == TestFiles::EMPTY_TEST_DIR+"/" }
|
dirEntry = zf.entries.detect { |e| e.name == TestFiles::EMPTY_TEST_DIR+"/" }
|
||||||
assert(dirEntry.directory?)
|
assert(dirEntry.directory?)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_remove
|
def test_remove
|
||||||
|
@ -281,9 +270,7 @@ class ZipFileTest < MiniTest::Test
|
||||||
target_entry = "target_entryName"
|
target_entry = "target_entryName"
|
||||||
zf = ::Zip::File.new(TEST_ZIP.zip_name)
|
zf = ::Zip::File.new(TEST_ZIP.zip_name)
|
||||||
assert(!zf.entries.include?(nonEntry))
|
assert(!zf.entries.include?(nonEntry))
|
||||||
assert_raises(Errno::ENOENT) {
|
assert_raises(Errno::ENOENT) { zf.rename(nonEntry, target_entry) }
|
||||||
zf.rename(nonEntry, target_entry)
|
|
||||||
}
|
|
||||||
zf.commit
|
zf.commit
|
||||||
assert(!zf.entries.include?(target_entry))
|
assert(!zf.entries.include?(target_entry))
|
||||||
ensure
|
ensure
|
||||||
|
@ -293,9 +280,7 @@ class ZipFileTest < MiniTest::Test
|
||||||
def test_renameEntryToExistingEntry
|
def test_renameEntryToExistingEntry
|
||||||
entry1, entry2, * = TEST_ZIP.entry_names
|
entry1, entry2, * = TEST_ZIP.entry_names
|
||||||
zf = ::Zip::File.new(TEST_ZIP.zip_name)
|
zf = ::Zip::File.new(TEST_ZIP.zip_name)
|
||||||
assert_raises(::Zip::EntryExistsError) {
|
assert_raises(::Zip::EntryExistsError) { zf.rename(entry1, entry2) }
|
||||||
zf.rename(entry1, entry2)
|
|
||||||
}
|
|
||||||
ensure
|
ensure
|
||||||
zf.close
|
zf.close
|
||||||
end
|
end
|
||||||
|
@ -321,12 +306,9 @@ class ZipFileTest < MiniTest::Test
|
||||||
|
|
||||||
def test_replaceNonEntry
|
def test_replaceNonEntry
|
||||||
entryToReplace = "nonExistingEntryname"
|
entryToReplace = "nonExistingEntryname"
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
|zf|
|
assert_raises(Errno::ENOENT) { zf.replace(entryToReplace, "test/data/file2.txt") }
|
||||||
assert_raises(Errno::ENOENT) {
|
end
|
||||||
zf.replace(entryToReplace, "test/data/file2.txt")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_commit
|
def test_commit
|
||||||
|
@ -420,11 +402,10 @@ class ZipFileTest < MiniTest::Test
|
||||||
zf.rename(entry_to_rename, renamedName)
|
zf.rename(entry_to_rename, renamedName)
|
||||||
assert_contains(zf, renamedName)
|
assert_contains(zf, renamedName)
|
||||||
|
|
||||||
TestFiles::BINARY_TEST_FILES.each {
|
TestFiles::BINARY_TEST_FILES.each do |filename|
|
||||||
|filename|
|
|
||||||
zf.add(filename, filename)
|
zf.add(filename, filename)
|
||||||
assert_contains(zf, filename)
|
assert_contains(zf, filename)
|
||||||
}
|
end
|
||||||
|
|
||||||
assert_contains(zf, originalEntries.last.to_s)
|
assert_contains(zf, originalEntries.last.to_s)
|
||||||
filename_to_remove = originalEntries.map(&:to_s).find { |name| name.match('longBinary') }
|
filename_to_remove = originalEntries.map(&:to_s).find { |name| name.match('longBinary') }
|
||||||
|
@ -438,10 +419,9 @@ class ZipFileTest < MiniTest::Test
|
||||||
zfRead = ::Zip::File.new(TEST_ZIP.zip_name)
|
zfRead = ::Zip::File.new(TEST_ZIP.zip_name)
|
||||||
assert_contains(zfRead, TestFiles::RANDOM_ASCII_FILE1)
|
assert_contains(zfRead, TestFiles::RANDOM_ASCII_FILE1)
|
||||||
assert_contains(zfRead, renamedName)
|
assert_contains(zfRead, renamedName)
|
||||||
TestFiles::BINARY_TEST_FILES.each {
|
TestFiles::BINARY_TEST_FILES.each do |filename|
|
||||||
|filename|
|
|
||||||
assert_contains(zfRead, filename)
|
assert_contains(zfRead, filename)
|
||||||
}
|
end
|
||||||
assert_not_contains(zfRead, filename_to_remove)
|
assert_not_contains(zfRead, filename_to_remove)
|
||||||
ensure
|
ensure
|
||||||
zfRead.close
|
zfRead.close
|
||||||
|
@ -453,18 +433,16 @@ class ZipFileTest < MiniTest::Test
|
||||||
zf = ::Zip::File.new(TEST_ZIP.zip_name)
|
zf = ::Zip::File.new(TEST_ZIP.zip_name)
|
||||||
originalEntries = zf.entries.dup
|
originalEntries = zf.entries.dup
|
||||||
|
|
||||||
originalEntries.each {
|
originalEntries.each do |entry|
|
||||||
|entry|
|
|
||||||
zf.remove(entry)
|
zf.remove(entry)
|
||||||
assert_not_contains(zf, entry)
|
assert_not_contains(zf, entry)
|
||||||
}
|
end
|
||||||
assert(zf.entries.empty?)
|
assert(zf.entries.empty?)
|
||||||
|
|
||||||
TestFiles::ASCII_TEST_FILES.each {
|
TestFiles::ASCII_TEST_FILES.each do |filename|
|
||||||
|filename|
|
|
||||||
zf.add(filename, filename)
|
zf.add(filename, filename)
|
||||||
assert_contains(zf, filename)
|
assert_contains(zf, filename)
|
||||||
}
|
end
|
||||||
assert_equal(zf.entries.sort.map { |e| e.name }, TestFiles::ASCII_TEST_FILES)
|
assert_equal(zf.entries.sort.map { |e| e.name }, TestFiles::ASCII_TEST_FILES)
|
||||||
|
|
||||||
zf.rename(TestFiles::ASCII_TEST_FILES[0], "newName")
|
zf.rename(TestFiles::ASCII_TEST_FILES[0], "newName")
|
||||||
|
@ -477,10 +455,9 @@ class ZipFileTest < MiniTest::Test
|
||||||
zfRead = ::Zip::File.new(TEST_ZIP.zip_name)
|
zfRead = ::Zip::File.new(TEST_ZIP.zip_name)
|
||||||
asciiTestFiles = TestFiles::ASCII_TEST_FILES.dup
|
asciiTestFiles = TestFiles::ASCII_TEST_FILES.dup
|
||||||
asciiTestFiles.shift
|
asciiTestFiles.shift
|
||||||
asciiTestFiles.each {
|
asciiTestFiles.each do |filename|
|
||||||
|filename|
|
|
||||||
assert_contains(zf, filename)
|
assert_contains(zf, filename)
|
||||||
}
|
end
|
||||||
|
|
||||||
assert_contains(zf, "newName")
|
assert_contains(zf, "newName")
|
||||||
ensure
|
ensure
|
||||||
|
@ -498,30 +475,26 @@ class ZipFileTest < MiniTest::Test
|
||||||
|
|
||||||
def test_preserve_file_order
|
def test_preserve_file_order
|
||||||
entryNames = nil
|
entryNames = nil
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
|zf|
|
|
||||||
entryNames = zf.entries.map { |e| e.to_s }
|
entryNames = zf.entries.map { |e| e.to_s }
|
||||||
zf.get_output_stream("a.txt") { |os| os.write "this is a.txt" }
|
zf.get_output_stream("a.txt") { |os| os.write "this is a.txt" }
|
||||||
zf.get_output_stream("z.txt") { |os| os.write "this is z.txt" }
|
zf.get_output_stream("z.txt") { |os| os.write "this is z.txt" }
|
||||||
zf.get_output_stream("k.txt") { |os| os.write "this is k.txt" }
|
zf.get_output_stream("k.txt") { |os| os.write "this is k.txt" }
|
||||||
entryNames << "a.txt" << "z.txt" << "k.txt"
|
entryNames << "a.txt" << "z.txt" << "k.txt"
|
||||||
}
|
end
|
||||||
|
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
|zf|
|
|
||||||
assert_equal(entryNames, zf.entries.map { |e| e.to_s })
|
assert_equal(entryNames, zf.entries.map { |e| e.to_s })
|
||||||
entries = zf.entries.sort_by { |e| e.name }.reverse
|
entries = zf.entries.sort_by { |e| e.name }.reverse
|
||||||
entries.each {
|
entries.each do |e|
|
||||||
|e|
|
|
||||||
zf.remove e
|
zf.remove e
|
||||||
zf.get_output_stream(e) { |os| os.write "foo" }
|
zf.get_output_stream(e) { |os| os.write "foo" }
|
||||||
}
|
end
|
||||||
entryNames = entries.map { |e| e.to_s }
|
entryNames = entries.map { |e| e.to_s }
|
||||||
}
|
end
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
|zf|
|
|
||||||
assert_equal(entryNames, zf.entries.map { |e| e.to_s })
|
assert_equal(entryNames, zf.entries.map { |e| e.to_s })
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_streaming
|
def test_streaming
|
||||||
|
|
|
@ -11,21 +11,21 @@ class ZipFsDirIteratorTest < MiniTest::Test
|
||||||
|
|
||||||
def test_close
|
def test_close
|
||||||
@dirIt.close
|
@dirIt.close
|
||||||
assert_raises(IOError, "closed directory") {
|
assert_raises(IOError, "closed directory") do
|
||||||
@dirIt.each { |e| p e }
|
@dirIt.each { |e| p e }
|
||||||
}
|
end
|
||||||
assert_raises(IOError, "closed directory") {
|
assert_raises(IOError, "closed directory") do
|
||||||
@dirIt.read
|
@dirIt.read
|
||||||
}
|
end
|
||||||
assert_raises(IOError, "closed directory") {
|
assert_raises(IOError, "closed directory") do
|
||||||
@dirIt.rewind
|
@dirIt.rewind
|
||||||
}
|
end
|
||||||
assert_raises(IOError, "closed directory") {
|
assert_raises(IOError, "closed directory") do
|
||||||
@dirIt.seek(0)
|
@dirIt.seek(0)
|
||||||
}
|
end
|
||||||
assert_raises(IOError, "closed directory") {
|
assert_raises(IOError, "closed directory") do
|
||||||
@dirIt.tell
|
@dirIt.tell
|
||||||
}
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -35,10 +35,9 @@ class ZipFsDirIteratorTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_read
|
def test_read
|
||||||
FILENAME_ARRAY.size.times {
|
FILENAME_ARRAY.size.times do |i|
|
||||||
|i|
|
|
||||||
assert_equal(FILENAME_ARRAY[i], @dirIt.read)
|
assert_equal(FILENAME_ARRAY[i], @dirIt.read)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rewind
|
def test_rewind
|
||||||
|
|
|
@ -9,50 +9,47 @@ class ZipFsDirectoryTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_delete
|
def test_delete
|
||||||
::Zip::File.open(TEST_ZIP) {
|
::Zip::File.open(TEST_ZIP) do |zf|
|
||||||
|zf|
|
assert_raises(Errno::ENOENT, "No such file or directory - NoSuchFile.txt") do
|
||||||
assert_raises(Errno::ENOENT, "No such file or directory - NoSuchFile.txt") {
|
|
||||||
zf.dir.delete("NoSuchFile.txt")
|
zf.dir.delete("NoSuchFile.txt")
|
||||||
}
|
end
|
||||||
assert_raises(Errno::EINVAL, "Invalid argument - file1") {
|
assert_raises(Errno::EINVAL, "Invalid argument - file1") do
|
||||||
zf.dir.delete("file1")
|
zf.dir.delete("file1")
|
||||||
}
|
end
|
||||||
assert(zf.file.exists?("dir1"))
|
assert(zf.file.exists?("dir1"))
|
||||||
zf.dir.delete("dir1")
|
zf.dir.delete("dir1")
|
||||||
assert(! zf.file.exists?("dir1"))
|
assert(! zf.file.exists?("dir1"))
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mkdir
|
def test_mkdir
|
||||||
::Zip::File.open(TEST_ZIP) {
|
::Zip::File.open(TEST_ZIP) do |zf|
|
||||||
|zf|
|
assert_raises(Errno::EEXIST, "File exists - dir1") do
|
||||||
assert_raises(Errno::EEXIST, "File exists - dir1") {
|
|
||||||
zf.dir.mkdir("file1")
|
zf.dir.mkdir("file1")
|
||||||
}
|
end
|
||||||
assert_raises(Errno::EEXIST, "File exists - dir1") {
|
assert_raises(Errno::EEXIST, "File exists - dir1") do
|
||||||
zf.dir.mkdir("dir1")
|
zf.dir.mkdir("dir1")
|
||||||
}
|
end
|
||||||
assert(!zf.file.exists?("newDir"))
|
assert(!zf.file.exists?("newDir"))
|
||||||
zf.dir.mkdir("newDir")
|
zf.dir.mkdir("newDir")
|
||||||
assert(zf.file.directory?("newDir"))
|
assert(zf.file.directory?("newDir"))
|
||||||
assert(!zf.file.exists?("newDir2"))
|
assert(!zf.file.exists?("newDir2"))
|
||||||
zf.dir.mkdir("newDir2", 3485)
|
zf.dir.mkdir("newDir2", 3485)
|
||||||
assert(zf.file.directory?("newDir2"))
|
assert(zf.file.directory?("newDir2"))
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_pwd_chdir_entries
|
def test_pwd_chdir_entries
|
||||||
::Zip::File.open(TEST_ZIP) {
|
::Zip::File.open(TEST_ZIP) do |zf|
|
||||||
|zf|
|
|
||||||
assert_equal("/", zf.dir.pwd)
|
assert_equal("/", zf.dir.pwd)
|
||||||
|
|
||||||
assert_raises(Errno::ENOENT, "No such file or directory - no such dir") {
|
assert_raises(Errno::ENOENT, "No such file or directory - no such dir") do
|
||||||
zf.dir.chdir "no such dir"
|
zf.dir.chdir "no such dir"
|
||||||
}
|
end
|
||||||
|
|
||||||
assert_raises(Errno::EINVAL, "Invalid argument - file1") {
|
assert_raises(Errno::EINVAL, "Invalid argument - file1") do
|
||||||
zf.dir.chdir "file1"
|
zf.dir.chdir "file1"
|
||||||
}
|
end
|
||||||
|
|
||||||
assert_equal(%w(dir1 dir2 file1).sort, zf.dir.entries(".").sort)
|
assert_equal(%w(dir1 dir2 file1).sort, zf.dir.entries(".").sort)
|
||||||
zf.dir.chdir "dir1"
|
zf.dir.chdir "dir1"
|
||||||
|
@ -62,22 +59,20 @@ class ZipFsDirectoryTest < MiniTest::Test
|
||||||
zf.dir.chdir "../dir2/dir21"
|
zf.dir.chdir "../dir2/dir21"
|
||||||
assert_equal("/dir2/dir21", zf.dir.pwd)
|
assert_equal("/dir2/dir21", zf.dir.pwd)
|
||||||
assert_equal(["dir221"].sort, zf.dir.entries(".").sort)
|
assert_equal(["dir221"].sort, zf.dir.entries(".").sort)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_foreach
|
def test_foreach
|
||||||
::Zip::File.open(TEST_ZIP) {
|
::Zip::File.open(TEST_ZIP) do |zf|
|
||||||
|zf|
|
|
||||||
|
|
||||||
blockCalled = false
|
blockCalled = false
|
||||||
assert_raises(Errno::ENOENT, "No such file or directory - noSuchDir") {
|
assert_raises(Errno::ENOENT, "No such file or directory - noSuchDir") do
|
||||||
zf.dir.foreach("noSuchDir") { |_e| blockCalled = true }
|
zf.dir.foreach("noSuchDir") { |_e| blockCalled = true }
|
||||||
}
|
end
|
||||||
assert(! blockCalled)
|
assert(! blockCalled)
|
||||||
|
|
||||||
assert_raises(Errno::ENOTDIR, "Not a directory - file1") {
|
assert_raises(Errno::ENOTDIR, "Not a directory - file1") do
|
||||||
zf.dir.foreach("file1") { |_e| blockCalled = true }
|
zf.dir.foreach("file1") { |_e| blockCalled = true }
|
||||||
}
|
end
|
||||||
assert(! blockCalled)
|
assert(! blockCalled)
|
||||||
|
|
||||||
entries = []
|
entries = []
|
||||||
|
@ -87,16 +82,15 @@ class ZipFsDirectoryTest < MiniTest::Test
|
||||||
entries = []
|
entries = []
|
||||||
zf.dir.foreach("dir1") { |e| entries << e }
|
zf.dir.foreach("dir1") { |e| entries << e }
|
||||||
assert_equal(%w(dir11 file11 file12), entries.sort)
|
assert_equal(%w(dir11 file11 file12), entries.sort)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_chroot
|
def test_chroot
|
||||||
::Zip::File.open(TEST_ZIP) {
|
::Zip::File.open(TEST_ZIP) do |zf|
|
||||||
|zf|
|
assert_raises(NotImplementedError) do
|
||||||
assert_raises(NotImplementedError) {
|
|
||||||
zf.dir.chroot
|
zf.dir.chroot
|
||||||
}
|
end
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Globbing not supported yet
|
# Globbing not supported yet
|
||||||
|
@ -106,26 +100,23 @@ class ZipFsDirectoryTest < MiniTest::Test
|
||||||
#end
|
#end
|
||||||
|
|
||||||
def test_open_new
|
def test_open_new
|
||||||
::Zip::File.open(TEST_ZIP) {
|
::Zip::File.open(TEST_ZIP) do |zf|
|
||||||
|zf|
|
assert_raises(Errno::ENOTDIR, "Not a directory - file1") do
|
||||||
|
|
||||||
assert_raises(Errno::ENOTDIR, "Not a directory - file1") {
|
|
||||||
zf.dir.new("file1")
|
zf.dir.new("file1")
|
||||||
}
|
end
|
||||||
|
|
||||||
assert_raises(Errno::ENOENT, "No such file or directory - noSuchFile") {
|
assert_raises(Errno::ENOENT, "No such file or directory - noSuchFile") do
|
||||||
zf.dir.new("noSuchFile")
|
zf.dir.new("noSuchFile")
|
||||||
}
|
end
|
||||||
|
|
||||||
d = zf.dir.new(".")
|
d = zf.dir.new(".")
|
||||||
assert_equal(%w(file1 dir1 dir2).sort, d.entries.sort)
|
assert_equal(%w(file1 dir1 dir2).sort, d.entries.sort)
|
||||||
d.close
|
d.close
|
||||||
|
|
||||||
zf.dir.open("dir1") {
|
zf.dir.open("dir1") do |dir|
|
||||||
|dir|
|
|
||||||
assert_equal(%w(dir11 file11 file12).sort, dir.entries.sort)
|
assert_equal(%w(dir11 file11 file12).sort, dir.entries.sort)
|
||||||
}
|
end
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,58 +19,49 @@ class ZipFsFileMutatingTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_open_write
|
def test_open_write
|
||||||
::Zip::File.open(TEST_ZIP) {
|
::Zip::File.open(TEST_ZIP) do |zf|
|
||||||
|zf|
|
zf.file.open("test_open_write_entry", "w") do |f|
|
||||||
|
|
||||||
zf.file.open("test_open_write_entry", "w") {
|
|
||||||
|f|
|
|
||||||
f.write "This is what I'm writing"
|
f.write "This is what I'm writing"
|
||||||
}
|
end
|
||||||
assert_equal("This is what I'm writing",
|
assert_equal("This is what I'm writing",
|
||||||
zf.file.read("test_open_write_entry"))
|
zf.file.read("test_open_write_entry"))
|
||||||
|
|
||||||
# Test with existing entry
|
# Test with existing entry
|
||||||
zf.file.open("file1", "wb") { #also check that 'b' option is ignored
|
zf.file.open("file1", "wb") do |f| #also check that 'b' option is ignored
|
||||||
|f|
|
|
||||||
f.write "This is what I'm writing too"
|
f.write "This is what I'm writing too"
|
||||||
}
|
end
|
||||||
assert_equal("This is what I'm writing too",
|
assert_equal("This is what I'm writing too",
|
||||||
zf.file.read("file1"))
|
zf.file.read("file1"))
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rename
|
def test_rename
|
||||||
::Zip::File.open(TEST_ZIP) {
|
::Zip::File.open(TEST_ZIP) do |zf|
|
||||||
|zf|
|
assert_raises(Errno::ENOENT, "") do
|
||||||
assert_raises(Errno::ENOENT, "") {
|
|
||||||
zf.file.rename("NoSuchFile", "bimse")
|
zf.file.rename("NoSuchFile", "bimse")
|
||||||
}
|
end
|
||||||
zf.file.rename("file1", "newNameForFile1")
|
zf.file.rename("file1", "newNameForFile1")
|
||||||
}
|
end
|
||||||
|
|
||||||
::Zip::File.open(TEST_ZIP) {
|
::Zip::File.open(TEST_ZIP) do |zf|
|
||||||
|zf|
|
|
||||||
assert(! zf.file.exists?("file1"))
|
assert(! zf.file.exists?("file1"))
|
||||||
assert(zf.file.exists?("newNameForFile1"))
|
assert(zf.file.exists?("newNameForFile1"))
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_chmod
|
def test_chmod
|
||||||
::Zip::File.open(TEST_ZIP) {
|
::Zip::File.open(TEST_ZIP) do |zf|
|
||||||
|zf|
|
|
||||||
|
|
||||||
zf.file.chmod(0765, "file1")
|
zf.file.chmod(0765, "file1")
|
||||||
}
|
end
|
||||||
|
|
||||||
::Zip::File.open(TEST_ZIP) {
|
::Zip::File.open(TEST_ZIP) do |zf|
|
||||||
|zf|
|
|
||||||
assert_equal(0100765, zf.file.stat("file1").mode)
|
assert_equal(0100765, zf.file.stat("file1").mode)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def do_test_delete_or_unlink(symbol)
|
def do_test_delete_or_unlink(symbol)
|
||||||
::Zip::File.open(TEST_ZIP) {
|
::Zip::File.open(TEST_ZIP) do |zf|
|
||||||
|zf|
|
|
||||||
assert(zf.file.exists?("dir2/dir21/dir221/file2221"))
|
assert(zf.file.exists?("dir2/dir21/dir221/file2221"))
|
||||||
zf.file.send(symbol, "dir2/dir21/dir221/file2221")
|
zf.file.send(symbol, "dir2/dir21/dir221/file2221")
|
||||||
assert(! zf.file.exists?("dir2/dir21/dir221/file2221"))
|
assert(! zf.file.exists?("dir2/dir21/dir221/file2221"))
|
||||||
|
@ -84,17 +75,16 @@ class ZipFsFileMutatingTest < MiniTest::Test
|
||||||
assert_raises(Errno::ENOENT) { zf.file.send(symbol, "noSuchFile") }
|
assert_raises(Errno::ENOENT) { zf.file.send(symbol, "noSuchFile") }
|
||||||
assert_raises(Errno::EISDIR) { zf.file.send(symbol, "dir1/dir11") }
|
assert_raises(Errno::EISDIR) { zf.file.send(symbol, "dir1/dir11") }
|
||||||
assert_raises(Errno::EISDIR) { zf.file.send(symbol, "dir1/dir11/") }
|
assert_raises(Errno::EISDIR) { zf.file.send(symbol, "dir1/dir11/") }
|
||||||
}
|
end
|
||||||
|
|
||||||
::Zip::File.open(TEST_ZIP) {
|
::Zip::File.open(TEST_ZIP) do |zf|
|
||||||
|zf|
|
|
||||||
assert(! zf.file.exists?("dir2/dir21/dir221/file2221"))
|
assert(! zf.file.exists?("dir2/dir21/dir221/file2221"))
|
||||||
assert(! zf.file.exists?("dir1/file11"))
|
assert(! zf.file.exists?("dir1/file11"))
|
||||||
assert(! zf.file.exists?("dir1/file12"))
|
assert(! zf.file.exists?("dir1/file12"))
|
||||||
|
|
||||||
assert(zf.file.exists?("dir1/dir11"))
|
assert(zf.file.exists?("dir1/dir11"))
|
||||||
assert(zf.file.exists?("dir1/dir11/"))
|
assert(zf.file.exists?("dir1/dir11/"))
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,37 +32,34 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
||||||
|
|
||||||
def test_open_read
|
def test_open_read
|
||||||
blockCalled = false
|
blockCalled = false
|
||||||
@zip_file.file.open("file1", "r") {
|
@zip_file.file.open("file1", "r") do |f|
|
||||||
|f|
|
|
||||||
blockCalled = true
|
blockCalled = true
|
||||||
assert_equal("this is the entry 'file1' in my test archive!",
|
assert_equal("this is the entry 'file1' in my test archive!",
|
||||||
f.readline.chomp)
|
f.readline.chomp)
|
||||||
}
|
end
|
||||||
assert(blockCalled)
|
assert(blockCalled)
|
||||||
|
|
||||||
blockCalled = false
|
blockCalled = false
|
||||||
@zip_file.file.open("file1", "rb") { # test binary flag is ignored
|
@zip_file.file.open("file1", "rb") do |f| # test binary flag is ignored
|
||||||
|f|
|
|
||||||
blockCalled = true
|
blockCalled = true
|
||||||
assert_equal("this is the entry 'file1' in my test archive!",
|
assert_equal("this is the entry 'file1' in my test archive!",
|
||||||
f.readline.chomp)
|
f.readline.chomp)
|
||||||
}
|
end
|
||||||
assert(blockCalled)
|
assert(blockCalled)
|
||||||
|
|
||||||
blockCalled = false
|
blockCalled = false
|
||||||
@zip_file.dir.chdir "dir2"
|
@zip_file.dir.chdir "dir2"
|
||||||
@zip_file.file.open("file21", "r") {
|
@zip_file.file.open("file21", "r") do |f|
|
||||||
|f|
|
|
||||||
blockCalled = true
|
blockCalled = true
|
||||||
assert_equal("this is the entry 'dir2/file21' in my test archive!",
|
assert_equal("this is the entry 'dir2/file21' in my test archive!",
|
||||||
f.readline.chomp)
|
f.readline.chomp)
|
||||||
}
|
end
|
||||||
assert(blockCalled)
|
assert(blockCalled)
|
||||||
@zip_file.dir.chdir "/"
|
@zip_file.dir.chdir "/"
|
||||||
|
|
||||||
assert_raises(Errno::ENOENT) {
|
assert_raises(Errno::ENOENT) do
|
||||||
@zip_file.file.open("noSuchEntry")
|
@zip_file.file.open("noSuchEntry")
|
||||||
}
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
is = @zip_file.file.open("file1")
|
is = @zip_file.file.open("file1")
|
||||||
|
@ -82,18 +79,18 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
||||||
is.close if is
|
is.close if is
|
||||||
end
|
end
|
||||||
begin
|
begin
|
||||||
is = @zip_file.file.new("file1") {
|
is = @zip_file.file.new("file1") do
|
||||||
fail "should not call block"
|
fail "should not call block"
|
||||||
}
|
end
|
||||||
ensure
|
ensure
|
||||||
is.close if is
|
is.close if is
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_symlink
|
def test_symlink
|
||||||
assert_raises(NotImplementedError) {
|
assert_raises(NotImplementedError) do
|
||||||
@zip_file.file.symlink("file1", "aSymlink")
|
@zip_file.file.symlink("file1", "aSymlink")
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_size
|
def test_size
|
||||||
|
@ -130,21 +127,21 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
||||||
include ExtraAssertions
|
include ExtraAssertions
|
||||||
|
|
||||||
def test_dirname
|
def test_dirname
|
||||||
assert_forwarded(File, :dirname, "retVal", "a/b/c/d") {
|
assert_forwarded(File, :dirname, "retVal", "a/b/c/d") do
|
||||||
@zip_file.file.dirname("a/b/c/d")
|
@zip_file.file.dirname("a/b/c/d")
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_basename
|
def test_basename
|
||||||
assert_forwarded(File, :basename, "retVal", "a/b/c/d") {
|
assert_forwarded(File, :basename, "retVal", "a/b/c/d") do
|
||||||
@zip_file.file.basename("a/b/c/d")
|
@zip_file.file.basename("a/b/c/d")
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_split
|
def test_split
|
||||||
assert_forwarded(File, :split, "retVal", "a/b/c/d") {
|
assert_forwarded(File, :split, "retVal", "a/b/c/d") do
|
||||||
@zip_file.file.split("a/b/c/d")
|
@zip_file.file.split("a/b/c/d")
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_join
|
def test_join
|
||||||
|
@ -201,15 +198,15 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_truncate
|
def test_truncate
|
||||||
assert_raises(StandardError, "truncate not supported") {
|
assert_raises(StandardError, "truncate not supported") do
|
||||||
@zip_file.file.truncate("file1", 100)
|
@zip_file.file.truncate("file1", 100)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_e_n_o_e_n_t(operation, args = ["NoSuchFile"])
|
def assert_e_n_o_e_n_t(operation, args = ["NoSuchFile"])
|
||||||
assert_raises(Errno::ENOENT) {
|
assert_raises(Errno::ENOENT) do
|
||||||
@zip_file.file.send(operation, *args)
|
@zip_file.file.send(operation, *args)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ftype
|
def test_ftype
|
||||||
|
@ -220,9 +217,9 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_link
|
def test_link
|
||||||
assert_raises(NotImplementedError) {
|
assert_raises(NotImplementedError) do
|
||||||
@zip_file.file.link("file1", "someOtherString")
|
@zip_file.file.link("file1", "someOtherString")
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_directory?
|
def test_directory?
|
||||||
|
@ -252,34 +249,31 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
||||||
assert(! @zip_file.file.zero?("file1"))
|
assert(! @zip_file.file.zero?("file1"))
|
||||||
assert(@zip_file.file.zero?("dir1"))
|
assert(@zip_file.file.zero?("dir1"))
|
||||||
blockCalled = false
|
blockCalled = false
|
||||||
::Zip::File.open("test/data/generated/5entry.zip") {
|
::Zip::File.open("test/data/generated/5entry.zip") do |zf|
|
||||||
|zf|
|
|
||||||
blockCalled = true
|
blockCalled = true
|
||||||
assert(zf.file.zero?("test/data/generated/empty.txt"))
|
assert(zf.file.zero?("test/data/generated/empty.txt"))
|
||||||
}
|
end
|
||||||
assert(blockCalled)
|
assert(blockCalled)
|
||||||
|
|
||||||
assert(! @zip_file.file.stat("file1").zero?)
|
assert(! @zip_file.file.stat("file1").zero?)
|
||||||
assert(@zip_file.file.stat("dir1").zero?)
|
assert(@zip_file.file.stat("dir1").zero?)
|
||||||
blockCalled = false
|
blockCalled = false
|
||||||
::Zip::File.open("test/data/generated/5entry.zip") {
|
::Zip::File.open("test/data/generated/5entry.zip") do |zf|
|
||||||
|zf|
|
|
||||||
blockCalled = true
|
blockCalled = true
|
||||||
assert(zf.file.stat("test/data/generated/empty.txt").zero?)
|
assert(zf.file.stat("test/data/generated/empty.txt").zero?)
|
||||||
}
|
end
|
||||||
assert(blockCalled)
|
assert(blockCalled)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_expand_path
|
def test_expand_path
|
||||||
::Zip::File.open("test/data/zipWithDirs.zip") {
|
::Zip::File.open("test/data/zipWithDirs.zip") do |zf|
|
||||||
|zf|
|
|
||||||
assert_equal("/", zf.file.expand_path("."))
|
assert_equal("/", zf.file.expand_path("."))
|
||||||
zf.dir.chdir "dir1"
|
zf.dir.chdir "dir1"
|
||||||
assert_equal("/dir1", zf.file.expand_path("."))
|
assert_equal("/dir1", zf.file.expand_path("."))
|
||||||
assert_equal("/dir1/file12", zf.file.expand_path("file12"))
|
assert_equal("/dir1/file12", zf.file.expand_path("file12"))
|
||||||
assert_equal("/", zf.file.expand_path(".."))
|
assert_equal("/", zf.file.expand_path(".."))
|
||||||
assert_equal("/dir2/dir21", zf.file.expand_path("../dir2/dir21"))
|
assert_equal("/dir2/dir21", zf.file.expand_path("../dir2/dir21"))
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mtime
|
def test_mtime
|
||||||
|
@ -287,9 +281,9 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
||||||
@zip_file.file.mtime("dir2/file21"))
|
@zip_file.file.mtime("dir2/file21"))
|
||||||
assert_equal(::Zip::DOSTime.at(1027690863),
|
assert_equal(::Zip::DOSTime.at(1027690863),
|
||||||
@zip_file.file.mtime("dir2/dir21"))
|
@zip_file.file.mtime("dir2/dir21"))
|
||||||
assert_raises(Errno::ENOENT) {
|
assert_raises(Errno::ENOENT) do
|
||||||
@zip_file.file.mtime("noSuchEntry")
|
@zip_file.file.mtime("noSuchEntry")
|
||||||
}
|
end
|
||||||
|
|
||||||
assert_equal(::Zip::DOSTime.at(1027694306),
|
assert_equal(::Zip::DOSTime.at(1027694306),
|
||||||
@zip_file.file.stat("dir2/file21").mtime)
|
@zip_file.file.stat("dir2/file21").mtime)
|
||||||
|
@ -385,17 +379,17 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_readlink
|
def test_readlink
|
||||||
assert_raises(NotImplementedError) {
|
assert_raises(NotImplementedError) do
|
||||||
@zip_file.file.readlink("someString")
|
@zip_file.file.readlink("someString")
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_stat
|
def test_stat
|
||||||
s = @zip_file.file.stat("file1")
|
s = @zip_file.file.stat("file1")
|
||||||
assert(s.kind_of?(File::Stat)) # It pretends
|
assert(s.kind_of?(File::Stat)) # It pretends
|
||||||
assert_raises(Errno::ENOENT, "No such file or directory - noSuchFile") {
|
assert_raises(Errno::ENOENT, "No such file or directory - noSuchFile") do
|
||||||
@zip_file.file.stat("noSuchFile")
|
@zip_file.file.stat("noSuchFile")
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_lstat
|
def test_lstat
|
||||||
|
@ -403,9 +397,9 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_pipe
|
def test_pipe
|
||||||
assert_raises(NotImplementedError) {
|
assert_raises(NotImplementedError) do
|
||||||
@zip_file.file.pipe
|
@zip_file.file.pipe
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_foreach
|
def test_foreach
|
||||||
|
|
|
@ -11,11 +11,11 @@ class ZipInputStreamTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_openWithBlock
|
def test_openWithBlock
|
||||||
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
|
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do
|
||||||
|zis|
|
|zis|
|
||||||
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
||||||
assert_equal(true, zis.eof?)
|
assert_equal(true, zis.eof?)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_openWithoutBlock
|
def test_openWithoutBlock
|
||||||
|
@ -50,7 +50,7 @@ class ZipInputStreamTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_incompleteReads
|
def test_incompleteReads
|
||||||
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
|
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do
|
||||||
|zis|
|
|zis|
|
||||||
entry = zis.get_next_entry # longAscii.txt
|
entry = zis.get_next_entry # longAscii.txt
|
||||||
assert_equal(false, zis.eof?)
|
assert_equal(false, zis.eof?)
|
||||||
|
@ -73,7 +73,7 @@ class ZipInputStreamTest < MiniTest::Test
|
||||||
entry = zis.get_next_entry # longBinary.bin
|
entry = zis.get_next_entry # longBinary.bin
|
||||||
assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
|
||||||
assert zis.gets.length > 0
|
assert zis.gets.length > 0
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_incomplete_reads_from_string_io
|
def test_incomplete_reads_from_string_io
|
||||||
|
@ -114,7 +114,7 @@ class ZipInputStreamTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rewind
|
def test_rewind
|
||||||
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
|
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do
|
||||||
|zis|
|
|zis|
|
||||||
e = zis.get_next_entry
|
e = zis.get_next_entry
|
||||||
assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], e.name)
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], e.name)
|
||||||
|
@ -141,11 +141,11 @@ class ZipInputStreamTest < MiniTest::Test
|
||||||
assert_equal(0, zis.pos)
|
assert_equal(0, zis.pos)
|
||||||
|
|
||||||
assert_entry(e.name, zis, e.name)
|
assert_entry(e.name, zis, e.name)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mix_read_and_gets
|
def test_mix_read_and_gets
|
||||||
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
|
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do
|
||||||
|zis|
|
|zis|
|
||||||
zis.get_next_entry
|
zis.get_next_entry
|
||||||
assert_equal("#!/usr/bin/env ruby", zis.gets.chomp)
|
assert_equal("#!/usr/bin/env ruby", zis.gets.chomp)
|
||||||
|
@ -154,7 +154,7 @@ class ZipInputStreamTest < MiniTest::Test
|
||||||
assert_equal(false, zis.eof?)
|
assert_equal(false, zis.eof?)
|
||||||
assert_equal("$VERBOSE =", zis.read(10))
|
assert_equal("$VERBOSE =", zis.read(10))
|
||||||
assert_equal(false, zis.eof?)
|
assert_equal(false, zis.eof?)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ungetc
|
def test_ungetc
|
||||||
|
|
|
@ -81,11 +81,10 @@ class AbstractInputStreamTest < MiniTest::Test
|
||||||
|
|
||||||
def test_each_line
|
def test_each_line
|
||||||
lineNumber=0
|
lineNumber=0
|
||||||
@io.each_line {
|
@io.each_line do |line|
|
||||||
|line|
|
|
||||||
assert_equal(TEST_LINES[lineNumber], line)
|
assert_equal(TEST_LINES[lineNumber], line)
|
||||||
lineNumber+=1
|
lineNumber+=1
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_readlines
|
def test_readlines
|
||||||
|
|
|
@ -28,19 +28,19 @@ class ZipLocalEntryTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_readDateTime
|
def test_readDateTime
|
||||||
::File.open("test/data/rubycode.zip", "rb") {
|
::File.open("test/data/rubycode.zip", "rb") do
|
||||||
|file|
|
|file|
|
||||||
entry = ::Zip::Entry.read_local_entry(file)
|
entry = ::Zip::Entry.read_local_entry(file)
|
||||||
assert_equal("zippedruby1.rb", entry.name)
|
assert_equal("zippedruby1.rb", entry.name)
|
||||||
assert_equal(::Zip::DOSTime.at(1019261638), entry.time)
|
assert_equal(::Zip::DOSTime.at(1019261638), entry.time)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_read_local_entryFromNonZipFile
|
def test_read_local_entryFromNonZipFile
|
||||||
::File.open("test/data/file2.txt") {
|
::File.open("test/data/file2.txt") do
|
||||||
|file|
|
|file|
|
||||||
assert_equal(nil, ::Zip::Entry.read_local_entry(file))
|
assert_equal(nil, ::Zip::Entry.read_local_entry(file))
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_read_local_entryFromTruncatedZipFile
|
def test_read_local_entryFromTruncatedZipFile
|
||||||
|
|
|
@ -113,11 +113,11 @@ class ZipOutputStreamTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_i_o_error_in_closed_stream
|
def assert_i_o_error_in_closed_stream
|
||||||
assert_raises(IOError) {
|
assert_raises(IOError) do
|
||||||
zos = ::Zip::OutputStream.new("test/data/generated/test_putOnClosedStream.zip")
|
zos = ::Zip::OutputStream.new("test/data/generated/test_putOnClosedStream.zip")
|
||||||
zos.close
|
zos.close
|
||||||
yield zos
|
yield zos
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_test_zip(zos)
|
def write_test_zip(zos)
|
||||||
|
|
|
@ -4,8 +4,7 @@ class PassThruCompressorTest < MiniTest::Test
|
||||||
include CrcTest
|
include CrcTest
|
||||||
|
|
||||||
def test_size
|
def test_size
|
||||||
File.open("test/data/generated/dummy.txt", "wb") {
|
File.open("test/data/generated/dummy.txt", "wb") do |file|
|
||||||
|file|
|
|
||||||
compressor = ::Zip::PassThruCompressor.new(file)
|
compressor = ::Zip::PassThruCompressor.new(file)
|
||||||
|
|
||||||
assert_equal(0, compressor.size)
|
assert_equal(0, compressor.size)
|
||||||
|
@ -22,7 +21,7 @@ class PassThruCompressorTest < MiniTest::Test
|
||||||
|
|
||||||
compressor << t3
|
compressor << t3
|
||||||
assert_equal(compressor.size, t1.size + t2.size + t3.size)
|
assert_equal(compressor.size, t1.size + t2.size + t3.size)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_crc
|
def test_crc
|
||||||
|
|
|
@ -23,10 +23,9 @@ class ZipSettingsTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_test_dir(&aProc)
|
def extract_test_dir(&aProc)
|
||||||
open_zip {
|
open_zip do |zf|
|
||||||
|zf|
|
|
||||||
zf.extract(TestFiles::EMPTY_TEST_DIR, TEST_OUT_NAME, &aProc)
|
zf.extract(TestFiles::EMPTY_TEST_DIR, TEST_OUT_NAME, &aProc)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_true_on_exists_proc
|
def test_true_on_exists_proc
|
||||||
|
|
|
@ -98,8 +98,7 @@ module AssertEntry
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_entryContentsForStream(filename, zis, entryName)
|
def assert_entryContentsForStream(filename, zis, entryName)
|
||||||
File.open(filename, "rb") {
|
File.open(filename, "rb") do |file|
|
||||||
|file|
|
|
||||||
expected = file.read
|
expected = file.read
|
||||||
actual = zis.read
|
actual = zis.read
|
||||||
if (expected != actual)
|
if (expected != actual)
|
||||||
|
@ -111,7 +110,7 @@ module AssertEntry
|
||||||
assert_equal(expected, actual)
|
assert_equal(expected, actual)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def AssertEntry.assert_contents(filename, aString)
|
def AssertEntry.assert_contents(filename, aString)
|
||||||
|
@ -182,10 +181,9 @@ end
|
||||||
module Enumerable
|
module Enumerable
|
||||||
def compare_enumerables(otherEnumerable)
|
def compare_enumerables(otherEnumerable)
|
||||||
otherAsArray = otherEnumerable.to_a
|
otherAsArray = otherEnumerable.to_a
|
||||||
each_with_index {
|
each_with_index do |element, index|
|
||||||
|element, index|
|
|
||||||
return false unless yield(element, otherAsArray[index])
|
return false unless yield(element, otherAsArray[index])
|
||||||
}
|
end
|
||||||
return self.size == otherAsArray.size
|
return self.size == otherAsArray.size
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue