fix rubocop Style/StringLiterals cop

This commit is contained in:
Pavel Lobashov 2015-03-21 11:27:44 +03:00
parent 70dd0d0d59
commit b93ef1266f
53 changed files with 773 additions and 779 deletions

View File

@ -340,12 +340,6 @@ Style/SpaceInsideParens:
Style/SpecialGlobalVars: Style/SpecialGlobalVars:
Enabled: false Enabled: false
# Offense count: 1005
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/StringLiterals:
Enabled: false
# Offense count: 22 # Offense count: 22
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: IgnoredMethods. # Configuration parameters: IgnoredMethods.

View File

@ -96,7 +96,7 @@ module Zip
@size_in_bytes = Entry.read_zip_64_long(buf) @size_in_bytes = Entry.read_zip_64_long(buf)
@cdir_offset = Entry.read_zip_64_long(buf) @cdir_offset = Entry.read_zip_64_long(buf)
@zip_64_extensible = buf.slice!(0, buf.bytesize) @zip_64_extensible = buf.slice!(0, buf.bytesize)
raise Error, "Zip consistency problem while reading eocd structure" unless buf.size == 0 raise Error, 'Zip consistency problem while reading eocd structure' unless buf.size == 0
end end
def read_e_o_c_d(buf) #:nodoc: def read_e_o_c_d(buf) #:nodoc:
@ -113,14 +113,14 @@ module Zip
else else
buf.read(comment_length) buf.read(comment_length)
end end
raise Error, "Zip consistency problem while reading eocd structure" unless buf.size == 0 raise Error, 'Zip consistency problem while reading eocd structure' unless buf.size == 0
end end
def read_central_directory_entries(io) #:nodoc: def read_central_directory_entries(io) #:nodoc:
begin begin
io.seek(@cdir_offset, IO::SEEK_SET) io.seek(@cdir_offset, IO::SEEK_SET)
rescue Errno::EINVAL rescue Errno::EINVAL
raise Error, "Zip consistency problem while reading central directory entry" raise Error, 'Zip consistency problem while reading central directory entry'
end end
@entry_set = EntrySet.new @entry_set = EntrySet.new
@size.times do @size.times do
@ -140,7 +140,7 @@ module Zip
def get_e_o_c_d(buf) #:nodoc: def get_e_o_c_d(buf) #:nodoc:
sig_index = buf.rindex([END_OF_CDS].pack('V')) sig_index = buf.rindex([END_OF_CDS].pack('V'))
raise Error, "Zip end of central directory signature not found" unless sig_index raise Error, 'Zip end of central directory signature not found' unless sig_index
buf = buf.slice!((sig_index + 4)..(buf.bytesize)) buf = buf.slice!((sig_index + 4)..(buf.bytesize))
def buf.read(count) def buf.read(count)
@ -165,9 +165,9 @@ module Zip
def get_64_e_o_c_d(buf) #:nodoc: def get_64_e_o_c_d(buf) #:nodoc:
zip_64_start = buf.rindex([ZIP64_END_OF_CDS].pack('V')) zip_64_start = buf.rindex([ZIP64_END_OF_CDS].pack('V'))
raise Error, "Zip64 end of central directory signature not found" unless zip_64_start raise Error, 'Zip64 end of central directory signature not found' unless zip_64_start
zip_64_locator = buf.rindex([ZIP64_EOCD_LOCATOR].pack('V')) zip_64_locator = buf.rindex([ZIP64_EOCD_LOCATOR].pack('V'))
raise Error, "Zip64 end of central directory signature locator not found" unless zip_64_locator raise Error, 'Zip64 end of central directory signature locator not found' unless zip_64_locator
buf = buf.slice!((zip_64_start + 4)..zip_64_locator) buf = buf.slice!((zip_64_start + 4)..zip_64_locator)
def buf.read(count) def buf.read(count)

View File

@ -46,15 +46,15 @@ module Zip
end end
header << (mtime.to_binary_dos_time & 0xff) header << (mtime.to_binary_dos_time & 0xff)
header << (mtime.to_binary_dos_time >> 8) header << (mtime.to_binary_dos_time >> 8)
end.map{|x| encode x}.pack("C*") end.map{|x| encode x}.pack('C*')
end end
def encrypt(data) def encrypt(data)
data.unpack("C*").map{|x| encode x}.pack("C*") data.unpack('C*').map{|x| encode x}.pack('C*')
end end
def data_descriptor(crc32, compressed_size, uncomprssed_size) def data_descriptor(crc32, compressed_size, uncomprssed_size)
[0x08074b50, crc32, compressed_size, uncomprssed_size].pack("VVVV") [0x08074b50, crc32, compressed_size, uncomprssed_size].pack('VVVV')
end end
def reset! def reset!
@ -74,7 +74,7 @@ module Zip
include TraditionalEncryption include TraditionalEncryption
def decrypt(data) def decrypt(data)
data.unpack("C*").map{|x| decode x}.pack("C*") data.unpack('C*').map{|x| decode x}.pack('C*')
end end
def reset!(header) def reset!(header)

View File

@ -223,7 +223,7 @@ module Zip
static_sized_fields_buf = io.read(::Zip::LOCAL_ENTRY_STATIC_HEADER_LENGTH) || '' static_sized_fields_buf = io.read(::Zip::LOCAL_ENTRY_STATIC_HEADER_LENGTH) || ''
unless static_sized_fields_buf.bytesize == ::Zip::LOCAL_ENTRY_STATIC_HEADER_LENGTH unless static_sized_fields_buf.bytesize == ::Zip::LOCAL_ENTRY_STATIC_HEADER_LENGTH
raise Error, "Premature end of file. Not enough data for zip entry local header" raise Error, 'Premature end of file. Not enough data for zip entry local header'
end end
unpack_local_entry(static_sized_fields_buf) unpack_local_entry(static_sized_fields_buf)
@ -239,7 +239,7 @@ module Zip
@name.gsub!('\\', '/') @name.gsub!('\\', '/')
if extra && extra.bytesize != @extra_length if extra && extra.bytesize != @extra_length
raise ::Zip::Error, "Truncated local zip entry header" raise ::Zip::Error, 'Truncated local zip entry header'
else else
if ::Zip::ExtraField === @extra if ::Zip::ExtraField === @extra
@extra.merge(extra) @extra.merge(extra)
@ -345,7 +345,7 @@ module Zip
def check_c_dir_entry_comment_size def check_c_dir_entry_comment_size
unless @comment && @comment.bytesize == @comment_length unless @comment && @comment.bytesize == @comment_length
raise ::Zip::Error, "Truncated cdir zip entry header" raise ::Zip::Error, 'Truncated cdir zip entry header'
end end
end end
@ -557,7 +557,7 @@ module Zip
if @zipfile.is_a?(::IO) || @zipfile.is_a?(::StringIO) if @zipfile.is_a?(::IO) || @zipfile.is_a?(::StringIO)
yield @zipfile yield @zipfile
else else
::File.open(@zipfile, "rb", &block) ::File.open(@zipfile, 'rb', &block)
end end
end end
@ -570,7 +570,7 @@ module Zip
def set_time(binary_dos_date, binary_dos_time) def set_time(binary_dos_date, binary_dos_time)
@time = ::Zip::DOSTime.parse_binary_dos_format(binary_dos_date, binary_dos_time) @time = ::Zip::DOSTime.parse_binary_dos_format(binary_dos_date, binary_dos_time)
rescue ArgumentError rescue ArgumentError
puts "Invalid date/time in zip entry" if ::Zip.warn_invalid_date puts 'Invalid date/time in zip entry' if ::Zip.warn_invalid_date
end end
def create_file(dest_path, _continue_on_exists_proc = proc { Zip.continue_on_exists_proc }) def create_file(dest_path, _continue_on_exists_proc = proc { Zip.continue_on_exists_proc })
@ -578,7 +578,7 @@ module Zip
raise ::Zip::DestinationFileExistsError, raise ::Zip::DestinationFileExistsError,
"Destination '#{dest_path}' already exists" "Destination '#{dest_path}' already exists"
end end
::File.open(dest_path, "wb") do |os| ::File.open(dest_path, 'wb') do |os|
get_input_stream do |is| get_input_stream do |is|
set_extra_attributes_on_path(dest_path) set_extra_attributes_on_path(dest_path)
@ -598,7 +598,7 @@ module Zip
else else
raise ::Zip::DestinationFileExistsError, raise ::Zip::DestinationFileExistsError,
"Cannot create directory '#{dest_path}'. "+ "Cannot create directory '#{dest_path}'. "+
"A file already exists with that name" 'A file already exists with that name'
end end
end end
::FileUtils.mkdir_p(dest_path) ::FileUtils.mkdir_p(dest_path)
@ -623,12 +623,12 @@ module Zip
else else
raise ::Zip::DestinationFileExistsError, raise ::Zip::DestinationFileExistsError,
"Cannot create symlink '#{dest_path}'. "+ "Cannot create symlink '#{dest_path}'. "+
"A symlink already exists with that name" 'A symlink already exists with that name'
end end
else else
raise ::Zip::DestinationFileExistsError, raise ::Zip::DestinationFileExistsError,
"Cannot create symlink '#{dest_path}'. "+ "Cannot create symlink '#{dest_path}'. "+
"A file already exists with that name" 'A file already exists with that name'
end end
end end

View File

@ -7,7 +7,7 @@ module Zip
end end
def self.name def self.name
@name ||= self.to_s.split("::")[-1] @name ||= self.to_s.split('::')[-1]
end end
# return field [size, content] or false # return field [size, content] or false
@ -16,10 +16,10 @@ module Zip
# If nil, start with empty. # If nil, start with empty.
return false return false
elsif binstr[0, 2] != self.class.const_get(:HEADER_ID) elsif binstr[0, 2] != self.class.const_get(:HEADER_ID)
$stderr.puts "Warning: weired extra feild header ID. skip parsing" $stderr.puts 'Warning: weired extra feild header ID. skip parsing'
return false return false
end end
[binstr[2, 2].unpack("v")[0], binstr[4..-1]] [binstr[2, 2].unpack('v')[0], binstr[4..-1]]
end end
def ==(other) def ==(other)
@ -32,12 +32,12 @@ module Zip
def to_local_bin def to_local_bin
s = pack_for_local s = pack_for_local
self.class.const_get(:HEADER_ID) + [s.bytesize].pack("v") << s self.class.const_get(:HEADER_ID) + [s.bytesize].pack('v') << s
end end
def to_c_dir_bin def to_c_dir_bin
s = pack_for_c_dir s = pack_for_c_dir
self.class.const_get(:HEADER_ID) + [s.bytesize].pack("v") << s self.class.const_get(:HEADER_ID) + [s.bytesize].pack('v') << s
end end
end end
end end

View File

@ -27,7 +27,7 @@ module Zip
tag1 = tags[1] tag1 = tags[1]
if tag1 if tag1
ntfs_mtime, ntfs_atime, ntfs_ctime = tag1.unpack("Q<Q<Q<") ntfs_mtime, ntfs_atime, ntfs_ctime = tag1.unpack('Q<Q<Q<')
ntfs_mtime && @mtime ||= from_ntfs_time(ntfs_mtime) ntfs_mtime && @mtime ||= from_ntfs_time(ntfs_mtime)
ntfs_atime && @atime ||= from_ntfs_time(ntfs_atime) ntfs_atime && @atime ||= from_ntfs_time(ntfs_atime)
ntfs_ctime && @ctime ||= from_ntfs_time(ntfs_ctime) ntfs_ctime && @ctime ||= from_ntfs_time(ntfs_ctime)
@ -48,7 +48,7 @@ module Zip
# But 7-zip for Windows only stores at central dir # But 7-zip for Windows only stores at central dir
def pack_for_c_dir def pack_for_c_dir
# reserved 0 and tag 1 # reserved 0 and tag 1
s = [0, 1].pack("Vv") s = [0, 1].pack('Vv')
tag1 = ''.force_encoding(Encoding::BINARY) tag1 = ''.force_encoding(Encoding::BINARY)
if @mtime if @mtime

View File

@ -1,7 +1,7 @@
module Zip module Zip
# Olf Info-ZIP Extra for UNIX uid/gid and file timestampes # Olf Info-ZIP Extra for UNIX uid/gid and file timestampes
class ExtraField::OldUnix < ExtraField::Generic class ExtraField::OldUnix < ExtraField::Generic
HEADER_ID = "UX" HEADER_ID = 'UX'
register_map register_map
def initialize(binstr = nil) def initialize(binstr = nil)
@ -19,7 +19,7 @@ module Zip
size, content = initial_parse(binstr) size, content = initial_parse(binstr)
# size: 0 for central directory. 4 for local header # size: 0 for central directory. 4 for local header
return if (!size || size == 0) return if (!size || size == 0)
atime, mtime, uid, gid = content.unpack("VVvv") atime, mtime, uid, gid = content.unpack('VVvv')
@uid ||= uid @uid ||= uid
@gid ||= gid @gid ||= gid
@atime ||= atime @atime ||= atime
@ -34,11 +34,11 @@ module Zip
end end
def pack_for_local def pack_for_local
[@atime, @mtime, @uid, @gid].pack("VVvv") [@atime, @mtime, @uid, @gid].pack('VVvv')
end end
def pack_for_c_dir def pack_for_c_dir
[@atime, @mtime].pack("VV") [@atime, @mtime].pack('VV')
end end
end end
end end

View File

@ -1,7 +1,7 @@
module Zip module Zip
# Info-ZIP Additional timestamp field # Info-ZIP Additional timestamp field
class ExtraField::UniversalTime < ExtraField::Generic class ExtraField::UniversalTime < ExtraField::Generic
HEADER_ID = "UT" HEADER_ID = 'UT'
register_map register_map
def initialize(binstr = nil) def initialize(binstr = nil)
@ -18,7 +18,7 @@ module Zip
return if binstr.empty? return if binstr.empty?
size, content = initial_parse(binstr) size, content = initial_parse(binstr)
size || return size || return
@flag, mtime, atime, ctime = content.unpack("CVVV") @flag, mtime, atime, ctime = content.unpack('CVVV')
mtime && @mtime ||= ::Zip::DOSTime.at(mtime) mtime && @mtime ||= ::Zip::DOSTime.at(mtime)
atime && @atime ||= ::Zip::DOSTime.at(atime) atime && @atime ||= ::Zip::DOSTime.at(atime)
ctime && @ctime ||= ::Zip::DOSTime.at(ctime) ctime && @ctime ||= ::Zip::DOSTime.at(ctime)
@ -31,16 +31,16 @@ module Zip
end end
def pack_for_local def pack_for_local
s = [@flag].pack("C") s = [@flag].pack('C')
@flag & 1 != 0 && s << [@mtime.to_i].pack("V") @flag & 1 != 0 && s << [@mtime.to_i].pack('V')
@flag & 2 != 0 && s << [@atime.to_i].pack("V") @flag & 2 != 0 && s << [@atime.to_i].pack('V')
@flag & 4 != 0 && s << [@ctime.to_i].pack("V") @flag & 4 != 0 && s << [@ctime.to_i].pack('V')
s s
end end
def pack_for_c_dir def pack_for_c_dir
s = [@flag].pack("C") s = [@flag].pack('C')
@flag & 1 == 1 && s << [@mtime.to_i].pack("V") @flag & 1 == 1 && s << [@mtime.to_i].pack('V')
s s
end end
end end

View File

@ -1,7 +1,7 @@
module Zip module Zip
# Info-ZIP Extra for UNIX uid/gid # Info-ZIP Extra for UNIX uid/gid
class ExtraField::IUnix < ExtraField::Generic class ExtraField::IUnix < ExtraField::Generic
HEADER_ID = "Ux" HEADER_ID = 'Ux'
register_map register_map
def initialize(binstr = nil) def initialize(binstr = nil)
@ -17,7 +17,7 @@ module Zip
size, content = initial_parse(binstr) size, content = initial_parse(binstr)
# size: 0 for central directory. 4 for local header # size: 0 for central directory. 4 for local header
return if (!size || size == 0) return if (!size || size == 0)
uid, gid = content.unpack("vv") uid, gid = content.unpack('vv')
@uid ||= uid @uid ||= uid
@gid ||= gid @gid ||= gid
end end
@ -27,7 +27,7 @@ module Zip
end end
def pack_for_local def pack_for_local
[@uid, @gid].pack("vv") [@uid, @gid].pack('vv')
end end
def pack_for_c_dir def pack_for_c_dir

View File

@ -51,16 +51,16 @@ module Zip
def pack_for_local def pack_for_local
# local header entries must contain original size and compressed size; other fields do not apply # local header entries must contain original size and compressed size; other fields do not apply
return '' unless @original_size && @compressed_size return '' unless @original_size && @compressed_size
[@original_size, @compressed_size].pack("Q<Q<") [@original_size, @compressed_size].pack('Q<Q<')
end end
def pack_for_c_dir def pack_for_c_dir
# central directory entries contain only fields that didn't fit in the main entry part # central directory entries contain only fields that didn't fit in the main entry part
packed = ''.force_encoding('BINARY') packed = ''.force_encoding('BINARY')
packed << [@original_size].pack("Q<") if @original_size packed << [@original_size].pack('Q<') if @original_size
packed << [@compressed_size].pack("Q<") if @compressed_size packed << [@compressed_size].pack('Q<') if @compressed_size
packed << [@relative_header_offset].pack("Q<") if @relative_header_offset packed << [@relative_header_offset].pack('Q<') if @relative_header_offset
packed << [@disk_start_number].pack("V") if @disk_start_number packed << [@disk_start_number].pack('V') if @disk_start_number
packed packed
end end
end end

View File

@ -130,7 +130,7 @@ module Zip
begin begin
zf.write_buffer(io) zf.write_buffer(io)
rescue IOError => e rescue IOError => e
raise unless e.message == "not opened for writing" raise unless e.message == 'not opened for writing'
end end
end end
@ -263,7 +263,7 @@ module Zip
# Convenience method for adding the contents of a file to the archive # Convenience method for adding the contents of a file to the archive
def add(entry, src_path, &continue_on_exists_proc) def add(entry, src_path, &continue_on_exists_proc)
continue_on_exists_proc ||= proc { ::Zip.continue_on_exists_proc } continue_on_exists_proc ||= proc { ::Zip.continue_on_exists_proc }
check_entry_exists(entry, continue_on_exists_proc, "add") check_entry_exists(entry, continue_on_exists_proc, 'add')
new_entry = entry.kind_of?(::Zip::Entry) ? entry : ::Zip::Entry.new(@name, entry.to_s) new_entry = entry.kind_of?(::Zip::Entry) ? entry : ::Zip::Entry.new(@name, entry.to_s)
new_entry.gather_fileinfo_from_srcpath(src_path) new_entry.gather_fileinfo_from_srcpath(src_path)
new_entry.dirty = true new_entry.dirty = true
@ -382,7 +382,7 @@ module Zip
"entry name '#{newEntry}' indicates directory entry, but "+ "entry name '#{newEntry}' indicates directory entry, but "+
"'#{srcPath}' is not a directory" "'#{srcPath}' is not a directory"
elsif !newEntry.is_directory && srcPathIsDirectory elsif !newEntry.is_directory && srcPathIsDirectory
newEntry.name += "/" newEntry.name += '/'
end end
newEntry.is_directory && srcPathIsDirectory newEntry.is_directory && srcPathIsDirectory
end end

View File

@ -102,8 +102,8 @@ module Zip
def gid def gid
e = get_entry e = get_entry
if e.extra.member? "IUnix" if e.extra.member? 'IUnix'
e.extra["IUnix"].gid || 0 e.extra['IUnix'].gid || 0
else else
0 0
end end
@ -111,8 +111,8 @@ module Zip
def uid def uid
e = get_entry e = get_entry
if e.extra.member? "IUnix" if e.extra.member? 'IUnix'
e.extra["IUnix"].uid || 0 e.extra['IUnix'].uid || 0
else else
0 0
end end
@ -130,11 +130,11 @@ module Zip
def ftype def ftype
if file? if file?
return "file" return 'file'
elsif directory? elsif directory?
return "directory" return 'directory'
else else
raise StandardError, "Unknown file type" raise StandardError, 'Unknown file type'
end end
end end
@ -175,7 +175,7 @@ module Zip
private :unix_mode_cmp private :unix_mode_cmp
def exists?(fileName) def exists?(fileName)
expand_path(fileName) == "/" || @mappedZip.find_entry(fileName) != nil expand_path(fileName) == '/' || @mappedZip.find_entry(fileName) != nil
end end
alias_method :exist?, :exists? alias_method :exist?, :exists?
@ -215,27 +215,27 @@ module Zip
end end
def truncate(_fileName, _len) def truncate(_fileName, _len)
raise StandardError, "truncate not supported" raise StandardError, 'truncate not supported'
end end
def directory?(fileName) def directory?(fileName)
entry = @mappedZip.find_entry(fileName) entry = @mappedZip.find_entry(fileName)
expand_path(fileName) == "/" || (entry != nil && entry.directory?) expand_path(fileName) == '/' || (entry != nil && entry.directory?)
end end
def open(fileName, openMode = "r", permissionInt = 0644, &block) def open(fileName, openMode = 'r', permissionInt = 0644, &block)
openMode.gsub!("b", "") # ignore b option openMode.gsub!('b', '') # ignore b option
case openMode case openMode
when "r" when 'r'
@mappedZip.get_input_stream(fileName, &block) @mappedZip.get_input_stream(fileName, &block)
when "w" when 'w'
@mappedZip.get_output_stream(fileName, permissionInt, &block) @mappedZip.get_output_stream(fileName, permissionInt, &block)
else else
raise StandardError, "openmode '#{openMode} not supported" unless openMode == "r" raise StandardError, "openmode '#{openMode} not supported" unless openMode == 'r'
end end
end end
def new(fileName, openMode = "r") def new(fileName, openMode = 'r')
open(fileName, openMode) open(fileName, openMode)
end end
@ -252,11 +252,11 @@ module Zip
def chown(ownerInt, groupInt, *filenames) def chown(ownerInt, groupInt, *filenames)
filenames.each do |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 end
filenames.size filenames.size
end end
@ -312,10 +312,10 @@ module Zip
def atime(fileName) def atime(fileName)
e = get_entry(fileName) e = get_entry(fileName)
if e.extra.member? "UniversalTime" if e.extra.member? 'UniversalTime'
e.extra["UniversalTime"].atime e.extra['UniversalTime'].atime
elsif e.extra.member? "NTFS" elsif e.extra.member? 'NTFS'
e.extra["NTFS"].atime e.extra['NTFS'].atime
else else
nil nil
end end
@ -323,10 +323,10 @@ module Zip
def ctime(fileName) def ctime(fileName)
e = get_entry(fileName) e = get_entry(fileName)
if e.extra.member? "UniversalTime" if e.extra.member? 'UniversalTime'
e.extra["UniversalTime"].ctime e.extra['UniversalTime'].ctime
elsif e.extra.member? "NTFS" elsif e.extra.member? 'NTFS'
e.extra["NTFS"].ctime e.extra['NTFS'].ctime
else else
nil nil
end end
@ -353,23 +353,23 @@ module Zip
end end
def ftype(fileName) def ftype(fileName)
@mappedZip.get_entry(fileName).directory? ? "directory" : "file" @mappedZip.get_entry(fileName).directory? ? 'directory' : 'file'
end end
def readlink(_fileName) def readlink(_fileName)
raise NotImplementedError, "The readlink() function is not implemented" raise NotImplementedError, 'The readlink() function is not implemented'
end end
def symlink(_fileName, _symlinkName) def symlink(_fileName, _symlinkName)
raise NotImplementedError, "The symlink() function is not implemented" raise NotImplementedError, 'The symlink() function is not implemented'
end end
def link(_fileName, _symlinkName) def link(_fileName, _symlinkName)
raise NotImplementedError, "The link() function is not implemented" raise NotImplementedError, 'The link() function is not implemented'
end end
def pipe def pipe
raise NotImplementedError, "The pipe() function is not implemented" raise NotImplementedError, 'The pipe() function is not implemented'
end end
def stat(fileName) def stat(fileName)
@ -495,7 +495,7 @@ module Zip
end end
def chroot(*_args) def chroot(*_args)
raise NotImplementedError, "The chroot() function is not implemented" raise NotImplementedError, 'The chroot() function is not implemented'
end end
end end
@ -512,27 +512,27 @@ module Zip
end end
def each(&aProc) def each(&aProc)
raise IOError, "closed directory" if @fileNames == nil raise IOError, 'closed directory' if @fileNames == nil
@fileNames.each(&aProc) @fileNames.each(&aProc)
end end
def read def read
raise IOError, "closed directory" if @fileNames == nil raise IOError, 'closed directory' if @fileNames == nil
@fileNames[(@index+=1)-1] @fileNames[(@index+=1)-1]
end end
def rewind def rewind
raise IOError, "closed directory" if @fileNames == nil raise IOError, 'closed directory' if @fileNames == nil
@index = 0 @index = 0
end end
def seek(anIntegerPosition) def seek(anIntegerPosition)
raise IOError, "closed directory" if @fileNames == nil raise IOError, 'closed directory' if @fileNames == nil
@index = anIntegerPosition @index = anIntegerPosition
end end
def tell def tell
raise IOError, "closed directory" if @fileNames == nil raise IOError, 'closed directory' if @fileNames == nil
@index @index
end end
end end
@ -544,7 +544,7 @@ module Zip
def initialize(zipFile) def initialize(zipFile)
@zipFile = zipFile @zipFile = zipFile
@pwd = "/" @pwd = '/'
end end
attr_accessor :pwd attr_accessor :pwd
@ -586,15 +586,15 @@ module Zip
# and removes trailing slash on directories # and removes trailing slash on directories
def each def each
@zipFile.each do |e| @zipFile.each do |e|
yield("/"+e.to_s.chomp("/")) yield('/'+e.to_s.chomp('/'))
end end
end end
def expand_path(aPath) def expand_path(aPath)
expanded = aPath.start_with?("/") ? aPath : ::File.join(@pwd, aPath) expanded = aPath.start_with?('/') ? aPath : ::File.join(@pwd, aPath)
expanded.gsub!(/\/\.(\/|$)/, "") expanded.gsub!(/\/\.(\/|$)/, '')
expanded.gsub!(/[^\/]+\/\.\.(\/|$)/, "") expanded.gsub!(/[^\/]+\/\.\.(\/|$)/, '')
expanded.empty? ? "/" : expanded expanded.empty? ? '/' : expanded
end end
private private

View File

@ -103,7 +103,7 @@ module Zip
end end
def open_buffer(filename_or_io, offset = 0) def open_buffer(filename_or_io, offset = 0)
puts "open_buffer is deprecated!!! Use open instead!" puts 'open_buffer is deprecated!!! Use open instead!'
self.open(filename_or_io, offset) self.open(filename_or_io, offset)
end end
end end

View File

@ -35,7 +35,7 @@ module Zip
if tbuf.nil? || tbuf.length == 0 if tbuf.nil? || tbuf.length == 0
return nil if number_of_bytes return nil if number_of_bytes
return "" return ''
end end
@pos += tbuf.length @pos += tbuf.length

View File

@ -3,7 +3,7 @@ module Zip
include Singleton include Singleton
def <<(_data) def <<(_data)
raise IOError, "closed stream" raise IOError, 'closed stream'
end end
attr_reader :size, :compressed_size attr_reader :size, :compressed_size

View File

@ -33,7 +33,7 @@ module Zip
iostream.rewind iostream.rewind
iostream iostream
else else
::File.new(@file_name, "wb") ::File.new(@file_name, 'wb')
end end
@entry_set = ::Zip::EntrySet.new @entry_set = ::Zip::EntrySet.new
@compressor = ::Zip::NullCompressor.instance @compressor = ::Zip::NullCompressor.instance
@ -86,7 +86,7 @@ module Zip
# Closes the current entry and opens a new for writing. # Closes the current entry and opens a new for writing.
# +entry+ can be a ZipEntry object or a string. # +entry+ can be a ZipEntry object or a string.
def put_next_entry(entry_name, comment = nil, extra = nil, compression_method = Entry::DEFLATED, level = Zip.default_compression) def put_next_entry(entry_name, comment = nil, extra = nil, compression_method = Entry::DEFLATED, level = Zip.default_compression)
raise Error, "zip stream is closed" if @closed raise Error, 'zip stream is closed' if @closed
if entry_name.kind_of?(Entry) if entry_name.kind_of?(Entry)
new_entry = entry_name new_entry = entry_name
else else
@ -103,8 +103,8 @@ module Zip
def copy_raw_entry(entry) def copy_raw_entry(entry)
entry = entry.dup entry = entry.dup
raise Error, "zip stream is closed" if @closed raise Error, 'zip stream is closed' if @closed
raise Error, "entry is not a ZipEntry" unless entry.is_a?(Entry) raise Error, 'entry is not a ZipEntry' unless entry.is_a?(Entry)
finalize_current_entry finalize_current_entry
@entry_set << entry @entry_set << entry
src_pos = entry.local_header_offset src_pos = entry.local_header_offset

View File

@ -6,13 +6,13 @@ require 'zip/version'
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = 'rubyzip' s.name = 'rubyzip'
s.version = ::Zip::VERSION s.version = ::Zip::VERSION
s.authors = ["Alexander Simonov"] s.authors = ['Alexander Simonov']
s.email = ["alex@simonov.me"] s.email = ['alex@simonov.me']
s.homepage = 'http://github.com/rubyzip/rubyzip' s.homepage = 'http://github.com/rubyzip/rubyzip'
s.platform = Gem::Platform::RUBY s.platform = Gem::Platform::RUBY
s.summary = 'rubyzip is a ruby module for reading and writing zip files' s.summary = 'rubyzip is a ruby module for reading and writing zip files'
s.files = Dir.glob("{samples,lib}/**/*.rb") + %w{ README.md TODO Rakefile } s.files = Dir.glob('{samples,lib}/**/*.rb') + %w{ README.md TODO Rakefile }
s.test_files = Dir.glob("test/**/*") s.test_files = Dir.glob('test/**/*')
s.require_paths = ['lib'] s.require_paths = ['lib']
s.license = 'BSD 2-Clause' s.license = 'BSD 2-Clause'
s.required_ruby_version = '>= 1.9.2' s.required_ruby_version = '>= 1.9.2'

View File

@ -1,13 +1,13 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
$: << "../lib" $: << '../lib'
system("zip example.zip example.rb gtkRubyzip.rb") system('zip example.zip example.rb gtkRubyzip.rb')
require 'zip' require 'zip'
####### Using ZipInputStream alone: ####### ####### Using ZipInputStream alone: #######
Zip::InputStream.open("example.zip") do |zis| Zip::InputStream.open('example.zip') do |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}'"
@ -18,7 +18,7 @@ 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 do |entry, index| zf.each_with_index do |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
@ -28,12 +28,12 @@ end
####### Using ZipOutputStream to write a zip file: ####### ####### Using ZipOutputStream to write a zip file: #######
Zip::OutputStream.open("exampleout.zip") do |zos| Zip::OutputStream.open('exampleout.zip') do |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'
zos.put_next_entry("the second little entry") zos.put_next_entry('the second little entry')
zos.puts "Hello again" zos.puts 'Hello again'
# 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
@ -41,36 +41,36 @@ end
####### Using ZipFile to change a zip file: ####### ####### Using ZipFile to change a zip file: #######
Zip::File.open("exampleout.zip") do |zip_file| Zip::File.open('exampleout.zip') do |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 end
# Lets check # Lets check
Zip::File.open("exampleout.zip") do |zip_file| Zip::File.open('exampleout.zip') do |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 end
####### Using ZipFile to split a zip file: ####### ####### Using ZipFile to split a zip file: #######
# Creating large zip file for splitting # Creating large zip file for splitting
Zip::OutputStream.open("large_zip_file.zip") do |zos| Zip::OutputStream.open('large_zip_file.zip') do |zos|
puts "Creating zip file..." puts 'Creating zip file...'
10.times do |i| 10.times do |i|
zos.put_next_entry("large_entry_#{i}.txt") zos.put_next_entry("large_entry_#{i}.txt")
zos.puts "Hello" * 104857600 zos.puts 'Hello' * 104857600
end end
end end
# Splitting created large zip file # Splitting created large zip file
part_zips_count = Zip::File.split("large_zip_file.zip", 2097152, false) part_zips_count = Zip::File.split('large_zip_file.zip', 2097152, false)
puts "Zip file splitted in #{part_zips_count} parts" puts "Zip file splitted in #{part_zips_count} parts"
# Track splitting an archive # Track splitting an archive
Zip::File.split("large_zip_file.zip", 1048576, true, 'part_zip_file') do Zip::File.split('large_zip_file.zip', 1048576, true, 'part_zip_file') do
|part_count, part_index, chunk_bytes, segment_bytes| |part_count, part_index, chunk_bytes, segment_bytes|
puts "#{part_index} of #{part_count} part splitting: #{(chunk_bytes.to_f/segment_bytes.to_f * 100).to_i}%" puts "#{part_index} of #{part_count} part splitting: #{(chunk_bytes.to_f/segment_bytes.to_f * 100).to_i}%"
end end

View File

@ -1,22 +1,22 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
$: << "../lib" $: << '../lib'
require 'zip/zipfilesystem' require 'zip/zipfilesystem'
EXAMPLE_ZIP = "filesystem.zip" 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) do |zf| Zip::File.open(EXAMPLE_ZIP, Zip::File::CREATE) do |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')
zf.file.open("file1.txt", "w") { |os| os.write "second file1.txt" } zf.file.open('file1.txt', 'w') { |os| os.write 'second file1.txt' }
puts zf.file.read("file1.txt") puts zf.file.read('file1.txt')
puts zf.file.read("../file1.txt") puts zf.file.read('../file1.txt')
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 end

View File

@ -19,10 +19,10 @@ class ZipFileGenerator
# Zip the input directory. # Zip the input directory.
def write def write
entries = Dir.entries(@inputDir); entries.delete("."); entries.delete("..") entries = Dir.entries(@inputDir); entries.delete('.'); entries.delete('..')
io = Zip::File.open(@outputFile, Zip::File::CREATE); io = Zip::File.open(@outputFile, Zip::File::CREATE);
writeEntries(entries, "", io) writeEntries(entries, '', io)
io.close(); io.close();
end end
@ -32,15 +32,15 @@ class ZipFileGenerator
def writeEntries(entries, path, io) def writeEntries(entries, path, io)
entries.each do |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
if File.directory?(diskFilePath) if File.directory?(diskFilePath)
io.mkdir(zipFilePath) io.mkdir(zipFilePath)
subdir =Dir.entries(diskFilePath); subdir.delete("."); subdir.delete("..") subdir =Dir.entries(diskFilePath); subdir.delete('.'); subdir.delete('..')
writeEntries(subdir, zipFilePath, io) writeEntries(subdir, zipFilePath, io)
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

View File

@ -1,6 +1,6 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
$: << "../lib" $: << '../lib'
$VERBOSE = true $VERBOSE = true
@ -11,7 +11,7 @@ class MainApp < Gtk::Window
def initialize def initialize
super() super()
set_usize(400, 256) set_usize(400, 256)
set_title("rubyzip") set_title('rubyzip')
signal_connect(Gtk::Window::SIGNAL_DESTROY) { Gtk.main_quit } signal_connect(Gtk::Window::SIGNAL_DESTROY) { Gtk.main_quit }
box = Gtk::VBox.new(false, 0) box = Gtk::VBox.new(false, 0)
@ -23,7 +23,7 @@ class MainApp < Gtk::Window
show_file_selector show_file_selector
end end
@buttonPanel.extractButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) do @buttonPanel.extractButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
puts "Not implemented!" puts 'Not implemented!'
end end
box.pack_start(@buttonPanel, false, false, 0) box.pack_start(@buttonPanel, false, false, 0)
@ -47,15 +47,15 @@ class MainApp < Gtk::Window
super super
set_layout(Gtk::BUTTONBOX_START) set_layout(Gtk::BUTTONBOX_START)
set_spacing(0) set_spacing(0)
@openButton = Gtk::Button.new("Open archive") @openButton = Gtk::Button.new('Open archive')
@extractButton = Gtk::Button.new("Extract entry") @extractButton = Gtk::Button.new('Extract entry')
pack_start(@openButton) pack_start(@openButton)
pack_start(@extractButton) pack_start(@extractButton)
end end
end end
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) do @fileSelector.ok_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
open_zip(@fileSelector.filename) open_zip(@fileSelector.filename)
@ -72,7 +72,7 @@ class MainApp < Gtk::Window
@zipfile.each do |entry| @zipfile.each do |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 end

View File

@ -2,7 +2,7 @@
$VERBOSE=true $VERBOSE=true
$: << "../lib" $: << '../lib'
require 'Qt' require 'Qt'
system('rbuic -o zipdialogui.rb zipdialogui.ui') system('rbuic -o zipdialogui.rb zipdialogui.ui')
@ -29,7 +29,7 @@ class ZipDialog < ZipDialogUI
end end
def refresh def refresh
lv = child("entry_list_view") lv = child('entry_list_view')
lv.clear lv.clear
each do |e| each do |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))
@ -70,7 +70,7 @@ class ZipDialog < ZipDialogUI
d = Qt::FileDialog.get_existing_directory(nil, self) d = Qt::FileDialog.get_existing_directory(nil, self)
if (!d) if (!d)
puts "No directory chosen" puts 'No directory chosen'
else else
zipfile { |zf| items.each { |e| zf.extract(e, File.join(d, e)) } } zipfile { |zf| items.each { |e| zf.extract(e, File.join(d, e)) } }
end end

View File

@ -1,6 +1,6 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
$: << "../lib" $: << '../lib'
require 'zip' require 'zip'
@ -8,5 +8,5 @@ include Zip
OutputStream.open('simple.zip') do |zos| OutputStream.open('simple.zip') do |zos|
zos.put_next_entry 'entry.txt' zos.put_next_entry 'entry.txt'
zos.puts "Hello world" zos.puts 'Hello world'
end end

View File

@ -2,7 +2,7 @@
$VERBOSE = true $VERBOSE = true
$: << "../lib" $: << '../lib'
require 'zip' require 'zip'
require 'find' require 'find'

View File

@ -2,34 +2,34 @@ 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") do |file| File.open('test/data/testDirectory.bin', 'rb') do |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)
assert_equal(::Zip::Entry::DEFLATED, entry.compression_method) assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
assert_equal(106490, entry.size) assert_equal(106490, entry.size)
assert_equal(3784, entry.compressed_size) assert_equal(3784, entry.compressed_size)
assert_equal(0xfcd1799c, entry.crc) assert_equal(0xfcd1799c, entry.crc)
assert_equal("", entry.comment) assert_equal('', entry.comment)
entry = ::Zip::Entry.read_c_dir_entry(file) entry = ::Zip::Entry.read_c_dir_entry(file)
assert_equal("empty.txt", entry.name) assert_equal('empty.txt', entry.name)
assert_equal(::Zip::Entry::STORED, entry.compression_method) assert_equal(::Zip::Entry::STORED, entry.compression_method)
assert_equal(0, entry.size) assert_equal(0, entry.size)
assert_equal(0, entry.compressed_size) assert_equal(0, entry.compressed_size)
assert_equal(0x0, entry.crc) assert_equal(0x0, entry.crc)
assert_equal("", entry.comment) assert_equal('', entry.comment)
entry = ::Zip::Entry.read_c_dir_entry(file) entry = ::Zip::Entry.read_c_dir_entry(file)
assert_equal("short.txt", entry.name) assert_equal('short.txt', entry.name)
assert_equal(::Zip::Entry::STORED, entry.compression_method) assert_equal(::Zip::Entry::STORED, entry.compression_method)
assert_equal(6, entry.size) assert_equal(6, entry.size)
assert_equal(6, entry.compressed_size) assert_equal(6, entry.compressed_size)
assert_equal(0xbb76fe69, entry.crc) assert_equal(0xbb76fe69, entry.crc)
assert_equal("", entry.comment) assert_equal('', entry.comment)
entry = ::Zip::Entry.read_c_dir_entry(file) entry = ::Zip::Entry.read_c_dir_entry(file)
assert_equal("longBinary.bin", entry.name) assert_equal('longBinary.bin', entry.name)
assert_equal(::Zip::Entry::DEFLATED, entry.compression_method) assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
assert_equal(1000024, entry.size) assert_equal(1000024, entry.size)
assert_equal(70847, entry.compressed_size) assert_equal(70847, entry.compressed_size)
@ -58,12 +58,12 @@ class ZipCentralDirectoryEntryTest < MiniTest::Test
end end
def test_ReadEntryFromTruncatedZipFile def test_ReadEntryFromTruncatedZipFile
fragment="" fragment=''
File.open("test/data/testDirectory.bin") { |f| fragment = f.read(12) } # cdir entry header is at least 46 bytes File.open('test/data/testDirectory.bin') { |f| fragment = f.read(12) } # cdir entry header is at least 46 bytes
fragment.extend(IOizeString) fragment.extend(IOizeString)
entry = ::Zip::Entry.new entry = ::Zip::Entry.new
entry.read_c_dir_entry(fragment) entry.read_c_dir_entry(fragment)
fail "ZipError expected" fail 'ZipError expected'
rescue ::Zip::Error rescue ::Zip::Error
end end
end end

View File

@ -6,7 +6,7 @@ class ZipCentralDirectoryTest < MiniTest::Test
end end
def test_read_from_stream def test_read_from_stream
::File.open(TestZipFile::TEST_ZIP2.zip_name, "rb") do |zipFile| ::File.open(TestZipFile::TEST_ZIP2.zip_name, 'rb') do |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)
@ -18,75 +18,75 @@ class ZipCentralDirectoryTest < MiniTest::Test
end end
def test_readFromInvalidStream def test_readFromInvalidStream
File.open("test/data/file2.txt", "rb") do |zipFile| File.open('test/data/file2.txt', 'rb') do |zipFile|
cdir = ::Zip::CentralDirectory.new cdir = ::Zip::CentralDirectory.new
cdir.read_from_stream(zipFile) cdir.read_from_stream(zipFile)
end end
fail "ZipError expected!" fail 'ZipError expected!'
rescue ::Zip::Error rescue ::Zip::Error
end end
def test_ReadFromTruncatedZipFile def test_ReadFromTruncatedZipFile
fragment="" fragment=''
File.open("test/data/testDirectory.bin", "rb") { |f| fragment = f.read } File.open('test/data/testDirectory.bin', 'rb') { |f| fragment = f.read }
fragment.slice!(12) # removed part of first cdir entry. eocd structure still complete fragment.slice!(12) # removed part of first cdir entry. eocd structure still complete
fragment.extend(IOizeString) fragment.extend(IOizeString)
entry = ::Zip::CentralDirectory.new entry = ::Zip::CentralDirectory.new
entry.read_from_stream(fragment) entry.read_from_stream(fragment)
fail "ZipError expected" fail 'ZipError expected'
rescue ::Zip::Error rescue ::Zip::Error
end end
def test_write_to_stream def test_write_to_stream
entries = [::Zip::Entry.new("file.zip", "flimse", "myComment", "somethingExtra"), entries = [::Zip::Entry.new('file.zip', 'flimse', 'myComment', 'somethingExtra'),
::Zip::Entry.new("file.zip", "secondEntryName"), ::Zip::Entry.new('file.zip', 'secondEntryName'),
::Zip::Entry.new("file.zip", "lastEntry.txt", "Has a comment too")] ::Zip::Entry.new('file.zip', 'lastEntry.txt', 'Has a comment too')]
cdir = ::Zip::CentralDirectory.new(entries, "my zip comment") cdir = ::Zip::CentralDirectory.new(entries, 'my zip comment')
File.open("test/data/generated/cdirtest.bin", "wb") { |f| cdir.write_to_stream(f) } File.open('test/data/generated/cdirtest.bin', 'wb') { |f| cdir.write_to_stream(f) }
cdirReadback = ::Zip::CentralDirectory.new cdirReadback = ::Zip::CentralDirectory.new
File.open("test/data/generated/cdirtest.bin", "rb") { |f| cdirReadback.read_from_stream(f) } File.open('test/data/generated/cdirtest.bin', 'rb') { |f| cdirReadback.read_from_stream(f) }
assert_equal(cdir.entries.sort, cdirReadback.entries.sort) assert_equal(cdir.entries.sort, cdirReadback.entries.sort)
end end
def test_write64_to_stream def test_write64_to_stream
::Zip.write_zip64_support = true ::Zip.write_zip64_support = true
entries = [::Zip::Entry.new("file.zip", "file1-little", "comment1", "", 200, 101, ::Zip::Entry::STORED, 200), entries = [::Zip::Entry.new('file.zip', 'file1-little', 'comment1', '', 200, 101, ::Zip::Entry::STORED, 200),
::Zip::Entry.new("file.zip", "file2-big", "comment2", "", 18000000000, 102, ::Zip::Entry::DEFLATED, 20000000000), ::Zip::Entry.new('file.zip', 'file2-big', 'comment2', '', 18000000000, 102, ::Zip::Entry::DEFLATED, 20000000000),
::Zip::Entry.new("file.zip", "file3-alsobig", "comment3", "", 15000000000, 103, ::Zip::Entry::DEFLATED, 21000000000), ::Zip::Entry.new('file.zip', 'file3-alsobig', 'comment3', '', 15000000000, 103, ::Zip::Entry::DEFLATED, 21000000000),
::Zip::Entry.new("file.zip", "file4-little", "comment4", "", 100, 104, ::Zip::Entry::DEFLATED, 121)] ::Zip::Entry.new('file.zip', 'file4-little', 'comment4', '', 100, 104, ::Zip::Entry::DEFLATED, 121)]
[0, 250, 18000000300, 33000000350].each_with_index do |offset, index| [0, 250, 18000000300, 33000000350].each_with_index do |offset, index|
entries[index].local_header_offset = offset entries[index].local_header_offset = offset
end end
cdir = ::Zip::CentralDirectory.new(entries, "zip comment") cdir = ::Zip::CentralDirectory.new(entries, 'zip comment')
File.open("test/data/generated/cdir64test.bin", "wb") { |f| cdir.write_to_stream(f) } File.open('test/data/generated/cdir64test.bin', 'wb') { |f| cdir.write_to_stream(f) }
cdirReadback = ::Zip::CentralDirectory.new cdirReadback = ::Zip::CentralDirectory.new
File.open("test/data/generated/cdir64test.bin", "rb") { |f| cdirReadback.read_from_stream(f) } File.open('test/data/generated/cdir64test.bin', 'rb') { |f| cdirReadback.read_from_stream(f) }
assert_equal(cdir.entries.sort, cdirReadback.entries.sort) assert_equal(cdir.entries.sort, cdirReadback.entries.sort)
assert_equal(::Zip::VERSION_NEEDED_TO_EXTRACT_ZIP64, cdirReadback.instance_variable_get(:@version_needed_for_extract)) assert_equal(::Zip::VERSION_NEEDED_TO_EXTRACT_ZIP64, cdirReadback.instance_variable_get(:@version_needed_for_extract))
end end
def test_equality def test_equality
cdir1 = ::Zip::CentralDirectory.new([::Zip::Entry.new("file.zip", "flimse", nil, cdir1 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
"somethingExtra"), 'somethingExtra'),
::Zip::Entry.new("file.zip", "secondEntryName"), ::Zip::Entry.new('file.zip', 'secondEntryName'),
::Zip::Entry.new("file.zip", "lastEntry.txt")], ::Zip::Entry.new('file.zip', 'lastEntry.txt')],
"my zip comment") 'my zip comment')
cdir2 = ::Zip::CentralDirectory.new([::Zip::Entry.new("file.zip", "flimse", nil, cdir2 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
"somethingExtra"), 'somethingExtra'),
::Zip::Entry.new("file.zip", "secondEntryName"), ::Zip::Entry.new('file.zip', 'secondEntryName'),
::Zip::Entry.new("file.zip", "lastEntry.txt")], ::Zip::Entry.new('file.zip', 'lastEntry.txt')],
"my zip comment") 'my zip comment')
cdir3 = ::Zip::CentralDirectory.new([::Zip::Entry.new("file.zip", "flimse", nil, cdir3 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
"somethingExtra"), 'somethingExtra'),
::Zip::Entry.new("file.zip", "secondEntryName"), ::Zip::Entry.new('file.zip', 'secondEntryName'),
::Zip::Entry.new("file.zip", "lastEntry.txt")], ::Zip::Entry.new('file.zip', 'lastEntry.txt')],
"comment?") 'comment?')
cdir4 = ::Zip::CentralDirectory.new([::Zip::Entry.new("file.zip", "flimse", nil, cdir4 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
"somethingExtra"), 'somethingExtra'),
::Zip::Entry.new("file.zip", "lastEntry.txt")], ::Zip::Entry.new('file.zip', 'lastEntry.txt')],
"comment?") 'comment?')
assert_equal(cdir1, cdir1) assert_equal(cdir1, cdir1)
assert_equal(cdir1, cdir2) assert_equal(cdir1, cdir2)
@ -95,6 +95,6 @@ class ZipCentralDirectoryTest < MiniTest::Test
assert(cdir2 != cdir3) assert(cdir2 != cdir3)
assert(cdir3 != cdir4) assert(cdir3 != cdir4)
assert(cdir3 != "hello") assert(cdir3 != 'hello')
end end
end end

View File

@ -16,7 +16,7 @@ class TraditionalEncrypterTest < MiniTest::Test
def test_header def test_header
@encrypter.reset! @encrypter.reset!
exepected = [239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack("C*") exepected = [239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack('C*')
Random.stub(:rand, 1) do Random.stub(:rand, 1) do
assert_equal exepected, @encrypter.header(@mtime) assert_equal exepected, @encrypter.header(@mtime)
end end
@ -28,7 +28,7 @@ class TraditionalEncrypterTest < MiniTest::Test
assert_raises(NoMethodError) { @encrypter.encrypt(nil) } assert_raises(NoMethodError) { @encrypter.encrypt(nil) }
assert_raises(NoMethodError) { @encrypter.encrypt(1) } assert_raises(NoMethodError) { @encrypter.encrypt(1) }
assert_equal '', @encrypter.encrypt('') assert_equal '', @encrypter.encrypt('')
assert_equal [100, 218, 7, 114, 226, 82, 62, 93, 224, 62].pack("C*"), @encrypter.encrypt('a' * 10) assert_equal [100, 218, 7, 114, 226, 82, 62, 93, 224, 62].pack('C*'), @encrypter.encrypt('a' * 10)
end end
def test_reset! def test_reset!
@ -60,19 +60,19 @@ class TraditionalDecrypterTest < MiniTest::Test
end end
def test_decrypt def test_decrypt
@decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack("C*")) @decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack('C*'))
[100, 218, 7, 114, 226, 82, 62, 93, 224, 62].map(&:chr).each do |c| [100, 218, 7, 114, 226, 82, 62, 93, 224, 62].map(&:chr).each do |c|
assert_equal 'a', @decrypter.decrypt(c) assert_equal 'a', @decrypter.decrypt(c)
end end
end end
def test_reset! def test_reset!
@decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack("C*")) @decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack('C*'))
[100, 218, 7, 114, 226, 82, 62, 93, 224, 62].map(&:chr).each do |c| [100, 218, 7, 114, 226, 82, 62, 93, 224, 62].map(&:chr).each do |c|
assert_equal 'a', @decrypter.decrypt(c) assert_equal 'a', @decrypter.decrypt(c)
end end
assert_equal 91.chr, @decrypter.decrypt(2.chr) assert_equal 91.chr, @decrypter.decrypt(2.chr)
@decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack("C*")) @decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack('C*'))
[100, 218, 7, 114, 226, 82, 62, 93, 224, 62].map(&:chr).each do |c| [100, 218, 7, 114, 226, 82, 62, 93, 224, 62].map(&:chr).each do |c|
assert_equal 'a', @decrypter.decrypt(c) assert_equal 'a', @decrypter.decrypt(c)
end end

View File

@ -9,14 +9,14 @@ class DeflaterTest < MiniTest::Test
NO_COMP_FILE = 'test/data/generated/compressiontest_no_compression.bin' NO_COMP_FILE = 'test/data/generated/compressiontest_no_compression.bin'
def test_outputOperator def test_outputOperator
txt = load_file("test/data/file2.txt") txt = load_file('test/data/file2.txt')
deflate(txt, DEFLATER_TEST_FILE) deflate(txt, DEFLATER_TEST_FILE)
inflatedTxt = inflate(DEFLATER_TEST_FILE) inflatedTxt = inflate(DEFLATER_TEST_FILE)
assert_equal(txt, inflatedTxt) assert_equal(txt, inflatedTxt)
end end
def test_default_compression def test_default_compression
txt = load_file("test/data/file2.txt") txt = load_file('test/data/file2.txt')
Zip.default_compression = ::Zlib::BEST_COMPRESSION Zip.default_compression = ::Zlib::BEST_COMPRESSION
deflate(txt, BEST_COMP_FILE) deflate(txt, BEST_COMP_FILE)
@ -38,22 +38,22 @@ class DeflaterTest < MiniTest::Test
def load_file(fileName) def load_file(fileName)
txt = nil txt = nil
File.open(fileName, "rb") { |f| txt = f.read } File.open(fileName, 'rb') { |f| txt = f.read }
end end
def deflate(data, fileName) def deflate(data, fileName)
File.open(fileName, "wb") do |file| File.open(fileName, 'wb') do |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 end
def inflate(fileName) def inflate(fileName)
txt = nil txt = nil
File.open(fileName, "rb") do |file| File.open(fileName, 'rb') do |file|
inflater = ::Zip::Inflater.new(file) inflater = ::Zip::Inflater.new(file)
txt = inflater.sysread txt = inflater.sysread
end end

View File

@ -26,7 +26,7 @@ class EncryptionTest < MiniTest::Test
end end
end end
@output.unpack("C*").each_with_index do |c, i| @output.unpack('C*').each_with_index do |c, i|
assert_equal test_file[i].ord, c assert_equal test_file[i].ord, c
end end
end end

View File

@ -2,12 +2,12 @@ require 'test_helper'
class ZipEntrySetTest < MiniTest::Test class ZipEntrySetTest < MiniTest::Test
ZIP_ENTRIES = [ ZIP_ENTRIES = [
::Zip::Entry.new("zipfile.zip", "name1", "comment1"), ::Zip::Entry.new('zipfile.zip', 'name1', 'comment1'),
::Zip::Entry.new("zipfile.zip", "name3", "comment1"), ::Zip::Entry.new('zipfile.zip', 'name3', 'comment1'),
::Zip::Entry.new("zipfile.zip", "name2", "comment1"), ::Zip::Entry.new('zipfile.zip', 'name2', 'comment1'),
::Zip::Entry.new("zipfile.zip", "name4", "comment1"), ::Zip::Entry.new('zipfile.zip', 'name4', 'comment1'),
::Zip::Entry.new("zipfile.zip", "name5", "comment1"), ::Zip::Entry.new('zipfile.zip', 'name5', 'comment1'),
::Zip::Entry.new("zipfile.zip", "name6", "comment1") ::Zip::Entry.new('zipfile.zip', 'name6', 'comment1')
] ]
def setup def setup
@ -20,20 +20,20 @@ class ZipEntrySetTest < MiniTest::Test
def test_include def test_include
assert(@zipEntrySet.include?(ZIP_ENTRIES.first)) assert(@zipEntrySet.include?(ZIP_ENTRIES.first))
assert(!@zipEntrySet.include?(::Zip::Entry.new("different.zip", "different", "aComment"))) assert(!@zipEntrySet.include?(::Zip::Entry.new('different.zip', 'different', 'aComment')))
end end
def test_size def test_size
assert_equal(ZIP_ENTRIES.size, @zipEntrySet.size) assert_equal(ZIP_ENTRIES.size, @zipEntrySet.size)
assert_equal(ZIP_ENTRIES.size, @zipEntrySet.length) assert_equal(ZIP_ENTRIES.size, @zipEntrySet.length)
@zipEntrySet << ::Zip::Entry.new("a", "b", "c") @zipEntrySet << ::Zip::Entry.new('a', 'b', 'c')
assert_equal(ZIP_ENTRIES.size + 1, @zipEntrySet.length) assert_equal(ZIP_ENTRIES.size + 1, @zipEntrySet.length)
end end
def test_add def test_add
zes = ::Zip::EntrySet.new zes = ::Zip::EntrySet.new
entry1 = ::Zip::Entry.new("zf.zip", "name1") entry1 = ::Zip::Entry.new('zf.zip', 'name1')
entry2 = ::Zip::Entry.new("zf.zip", "name2") entry2 = ::Zip::Entry.new('zf.zip', 'name2')
zes << entry1 zes << entry1
assert(zes.include?(entry1)) assert(zes.include?(entry1))
zes.push(entry2) zes.push(entry2)
@ -88,7 +88,7 @@ class ZipEntrySetTest < MiniTest::Test
end end
def test_compound def test_compound
newEntry = ::Zip::Entry.new("zf.zip", "new entry", "new entry's comment") newEntry = ::Zip::Entry.new('zf.zip', 'new entry', "new entry's comment")
assert_equal(ZIP_ENTRIES.size, @zipEntrySet.size) assert_equal(ZIP_ENTRIES.size, @zipEntrySet.size)
@zipEntrySet << newEntry @zipEntrySet << newEntry
assert_equal(ZIP_ENTRIES.size + 1, @zipEntrySet.size) assert_equal(ZIP_ENTRIES.size + 1, @zipEntrySet.size)
@ -103,15 +103,15 @@ class ZipEntrySetTest < MiniTest::Test
assert_equal(@zipEntrySet, copy) assert_equal(@zipEntrySet, copy)
# demonstrate that this is a deep copy # demonstrate that this is a deep copy
copy.entries[0].name = "a totally different name" copy.entries[0].name = 'a totally different name'
assert(@zipEntrySet != copy) assert(@zipEntrySet != copy)
end end
def test_parent def test_parent
entries = [ entries = [
::Zip::Entry.new("zf.zip", "a/"), ::Zip::Entry.new('zf.zip', 'a/'),
::Zip::Entry.new("zf.zip", "a/b/"), ::Zip::Entry.new('zf.zip', 'a/b/'),
::Zip::Entry.new("zf.zip", "a/b/c/") ::Zip::Entry.new('zf.zip', 'a/b/c/')
] ]
entrySet = ::Zip::EntrySet.new(entries) entrySet = ::Zip::EntrySet.new(entries)
@ -128,14 +128,14 @@ class ZipEntrySetTest < MiniTest::Test
def test_glob2 def test_glob2
entries = [ entries = [
::Zip::Entry.new("zf.zip", "a/"), ::Zip::Entry.new('zf.zip', 'a/'),
::Zip::Entry.new("zf.zip", "a/b/b1"), ::Zip::Entry.new('zf.zip', 'a/b/b1'),
::Zip::Entry.new("zf.zip", "a/b/c/"), ::Zip::Entry.new('zf.zip', 'a/b/c/'),
::Zip::Entry.new("zf.zip", "a/b/c/c1") ::Zip::Entry.new('zf.zip', 'a/b/c/c1')
] ]
entrySet = ::Zip::EntrySet.new(entries) entrySet = ::Zip::EntrySet.new(entries)
assert_equal(entries[0, 1], entrySet.glob("*")) assert_equal(entries[0, 1], entrySet.glob('*'))
# assert_equal(entries[FIXME], entrySet.glob("**")) # assert_equal(entries[FIXME], entrySet.glob("**"))
# res = entrySet.glob('a*') # res = entrySet.glob('a*')
# assert_equal(entries.size, res.size) # assert_equal(entries.size, res.size)

View File

@ -1,13 +1,13 @@
require 'test_helper' require 'test_helper'
class ZipEntryTest < MiniTest::Test class ZipEntryTest < MiniTest::Test
TEST_ZIPFILE = "someZipFile.zip" TEST_ZIPFILE = 'someZipFile.zip'
TEST_COMMENT = "a comment" TEST_COMMENT = 'a comment'
TEST_COMPRESSED_SIZE = 1234 TEST_COMPRESSED_SIZE = 1234
TEST_CRC = 325324 TEST_CRC = 325324
TEST_EXTRA = "Some data here" TEST_EXTRA = 'Some data here'
TEST_COMPRESSIONMETHOD = ::Zip::Entry::DEFLATED TEST_COMPRESSIONMETHOD = ::Zip::Entry::DEFLATED
TEST_NAME = "entry name" TEST_NAME = 'entry name'
TEST_SIZE = 8432 TEST_SIZE = 8432
TEST_ISDIRECTORY = false TEST_ISDIRECTORY = false
TEST_TIME = Time.now TEST_TIME = Time.now
@ -34,43 +34,43 @@ class ZipEntryTest < MiniTest::Test
end end
def test_is_directoryAndIsFile def test_is_directoryAndIsFile
assert(::Zip::Entry.new(TEST_ZIPFILE, "hello").file?) assert(::Zip::Entry.new(TEST_ZIPFILE, 'hello').file?)
assert(!::Zip::Entry.new(TEST_ZIPFILE, "hello").directory?) assert(!::Zip::Entry.new(TEST_ZIPFILE, 'hello').directory?)
assert(::Zip::Entry.new(TEST_ZIPFILE, "dir/hello").file?) assert(::Zip::Entry.new(TEST_ZIPFILE, 'dir/hello').file?)
assert(!::Zip::Entry.new(TEST_ZIPFILE, "dir/hello").directory?) assert(!::Zip::Entry.new(TEST_ZIPFILE, 'dir/hello').directory?)
assert(::Zip::Entry.new(TEST_ZIPFILE, "hello/").directory?) assert(::Zip::Entry.new(TEST_ZIPFILE, 'hello/').directory?)
assert(!::Zip::Entry.new(TEST_ZIPFILE, "hello/").file?) assert(!::Zip::Entry.new(TEST_ZIPFILE, 'hello/').file?)
assert(::Zip::Entry.new(TEST_ZIPFILE, "dir/hello/").directory?) assert(::Zip::Entry.new(TEST_ZIPFILE, 'dir/hello/').directory?)
assert(!::Zip::Entry.new(TEST_ZIPFILE, "dir/hello/").file?) assert(!::Zip::Entry.new(TEST_ZIPFILE, 'dir/hello/').file?)
end end
def test_equality def test_equality
entry1 = ::Zip::Entry.new("file.zip", "name", "isNotCompared", entry1 = ::Zip::Entry.new('file.zip', 'name', 'isNotCompared',
"something extra", 123, 1234, 'something extra', 123, 1234,
::Zip::Entry::DEFLATED, 10000) ::Zip::Entry::DEFLATED, 10000)
entry2 = ::Zip::Entry.new("file.zip", "name", "isNotComparedXXX", entry2 = ::Zip::Entry.new('file.zip', 'name', 'isNotComparedXXX',
"something extra", 123, 1234, 'something extra', 123, 1234,
::Zip::Entry::DEFLATED, 10000) ::Zip::Entry::DEFLATED, 10000)
entry3 = ::Zip::Entry.new("file.zip", "name2", "isNotComparedXXX", entry3 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
"something extra", 123, 1234, 'something extra', 123, 1234,
::Zip::Entry::DEFLATED, 10000) ::Zip::Entry::DEFLATED, 10000)
entry4 = ::Zip::Entry.new("file.zip", "name2", "isNotComparedXXX", entry4 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
"something extraXX", 123, 1234, 'something extraXX', 123, 1234,
::Zip::Entry::DEFLATED, 10000) ::Zip::Entry::DEFLATED, 10000)
entry5 = ::Zip::Entry.new("file.zip", "name2", "isNotComparedXXX", entry5 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
"something extraXX", 12, 1234, 'something extraXX', 12, 1234,
::Zip::Entry::DEFLATED, 10000) ::Zip::Entry::DEFLATED, 10000)
entry6 = ::Zip::Entry.new("file.zip", "name2", "isNotComparedXXX", entry6 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
"something extraXX", 12, 123, 'something extraXX', 12, 123,
::Zip::Entry::DEFLATED, 10000) ::Zip::Entry::DEFLATED, 10000)
entry7 = ::Zip::Entry.new("file.zip", "name2", "isNotComparedXXX", entry7 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
"something extraXX", 12, 123, 'something extraXX', 12, 123,
::Zip::Entry::STORED, 10000) ::Zip::Entry::STORED, 10000)
entry8 = ::Zip::Entry.new("file.zip", "name2", "isNotComparedXXX", entry8 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
"something extraXX", 12, 123, 'something extraXX', 12, 123,
::Zip::Entry::STORED, 100000) ::Zip::Entry::STORED, 100000)
assert_equal(entry1, entry1) assert_equal(entry1, entry1)
@ -83,51 +83,51 @@ class ZipEntryTest < MiniTest::Test
assert(entry6 != entry7) assert(entry6 != entry7)
assert(entry7 != entry8) assert(entry7 != entry8)
assert(entry7 != "hello") assert(entry7 != 'hello')
assert(entry7 != 12) assert(entry7 != 12)
end end
def test_compare def test_compare
assert_equal(0, (::Zip::Entry.new("zf.zip", "a") <=> ::Zip::Entry.new("zf.zip", "a"))) assert_equal(0, (::Zip::Entry.new('zf.zip', 'a') <=> ::Zip::Entry.new('zf.zip', 'a')))
assert_equal(1, (::Zip::Entry.new("zf.zip", "b") <=> ::Zip::Entry.new("zf.zip", "a"))) assert_equal(1, (::Zip::Entry.new('zf.zip', 'b') <=> ::Zip::Entry.new('zf.zip', 'a')))
assert_equal(-1, (::Zip::Entry.new("zf.zip", "a") <=> ::Zip::Entry.new("zf.zip", "b"))) assert_equal(-1, (::Zip::Entry.new('zf.zip', 'a') <=> ::Zip::Entry.new('zf.zip', 'b')))
entries = [ entries = [
::Zip::Entry.new("zf.zip", "5"), ::Zip::Entry.new('zf.zip', '5'),
::Zip::Entry.new("zf.zip", "1"), ::Zip::Entry.new('zf.zip', '1'),
::Zip::Entry.new("zf.zip", "3"), ::Zip::Entry.new('zf.zip', '3'),
::Zip::Entry.new("zf.zip", "4"), ::Zip::Entry.new('zf.zip', '4'),
::Zip::Entry.new("zf.zip", "0"), ::Zip::Entry.new('zf.zip', '0'),
::Zip::Entry.new("zf.zip", "2") ::Zip::Entry.new('zf.zip', '2')
] ]
entries.sort! entries.sort!
assert_equal("0", entries[0].to_s) assert_equal('0', entries[0].to_s)
assert_equal("1", entries[1].to_s) assert_equal('1', entries[1].to_s)
assert_equal("2", entries[2].to_s) assert_equal('2', entries[2].to_s)
assert_equal("3", entries[3].to_s) assert_equal('3', entries[3].to_s)
assert_equal("4", entries[4].to_s) assert_equal('4', entries[4].to_s)
assert_equal("5", entries[5].to_s) assert_equal('5', entries[5].to_s)
end end
def test_parentAsString def test_parentAsString
entry1 = ::Zip::Entry.new("zf.zip", "aa") entry1 = ::Zip::Entry.new('zf.zip', 'aa')
entry2 = ::Zip::Entry.new("zf.zip", "aa/") entry2 = ::Zip::Entry.new('zf.zip', 'aa/')
entry3 = ::Zip::Entry.new("zf.zip", "aa/bb") entry3 = ::Zip::Entry.new('zf.zip', 'aa/bb')
entry4 = ::Zip::Entry.new("zf.zip", "aa/bb/") entry4 = ::Zip::Entry.new('zf.zip', 'aa/bb/')
entry5 = ::Zip::Entry.new("zf.zip", "aa/bb/cc") entry5 = ::Zip::Entry.new('zf.zip', 'aa/bb/cc')
entry6 = ::Zip::Entry.new("zf.zip", "aa/bb/cc/") entry6 = ::Zip::Entry.new('zf.zip', 'aa/bb/cc/')
assert_equal(nil, entry1.parent_as_string) assert_equal(nil, entry1.parent_as_string)
assert_equal(nil, entry2.parent_as_string) assert_equal(nil, entry2.parent_as_string)
assert_equal("aa/", entry3.parent_as_string) assert_equal('aa/', entry3.parent_as_string)
assert_equal("aa/", entry4.parent_as_string) assert_equal('aa/', entry4.parent_as_string)
assert_equal("aa/bb/", entry5.parent_as_string) assert_equal('aa/bb/', entry5.parent_as_string)
assert_equal("aa/bb/", entry6.parent_as_string) assert_equal('aa/bb/', entry6.parent_as_string)
end end
def test_entry_name_cannot_start_with_slash def test_entry_name_cannot_start_with_slash
assert_raises(::Zip::EntryNameError) { ::Zip::Entry.new("zf.zip", "/hej/der") } assert_raises(::Zip::EntryNameError) { ::Zip::Entry.new('zf.zip', '/hej/der') }
end end
def test_store_file_without_compression def test_store_file_without_compression
@ -150,7 +150,7 @@ class ZipEntryTest < MiniTest::Test
zipfile.add(mimetype_entry, 'test/data/mimetype') zipfile.add(mimetype_entry, 'test/data/mimetype')
files.each do |file| files.each do |file|
zipfile.add(file.sub("test/data/globTest/", ''), file) zipfile.add(file.sub('test/data/globTest/', ''), file)
end end
zipfile.close zipfile.close

View File

@ -2,25 +2,25 @@ require 'test_helper'
class ZipExtraFieldTest < MiniTest::Test class ZipExtraFieldTest < MiniTest::Test
def test_new def test_new
extra_pure = ::Zip::ExtraField.new("") extra_pure = ::Zip::ExtraField.new('')
extra_withstr = ::Zip::ExtraField.new("foo") extra_withstr = ::Zip::ExtraField.new('foo')
assert_instance_of(::Zip::ExtraField, extra_pure) assert_instance_of(::Zip::ExtraField, extra_pure)
assert_instance_of(::Zip::ExtraField, extra_withstr) assert_instance_of(::Zip::ExtraField, extra_withstr)
end end
def test_unknownfield def test_unknownfield
extra = ::Zip::ExtraField.new("foo") extra = ::Zip::ExtraField.new('foo')
assert_equal(extra["Unknown"], "foo") assert_equal(extra['Unknown'], 'foo')
extra.merge("a") extra.merge('a')
assert_equal(extra["Unknown"], "fooa") assert_equal(extra['Unknown'], 'fooa')
extra.merge("barbaz") extra.merge('barbaz')
assert_equal(extra.to_s, "fooabarbaz") assert_equal(extra.to_s, 'fooabarbaz')
end end
def test_ntfs def test_ntfs
str = "\x0A\x00 \x00\x00\x00\x00\x00\x01\x00\x18\x00\xC0\x81\x17\xE8B\xCE\xCF\x01\xC0\x81\x17\xE8B\xCE\xCF\x01\xC0\x81\x17\xE8B\xCE\xCF\x01" str = "\x0A\x00 \x00\x00\x00\x00\x00\x01\x00\x18\x00\xC0\x81\x17\xE8B\xCE\xCF\x01\xC0\x81\x17\xE8B\xCE\xCF\x01\xC0\x81\x17\xE8B\xCE\xCF\x01"
extra = ::Zip::ExtraField.new(str) extra = ::Zip::ExtraField.new(str)
assert(extra.member?("NTFS")) assert(extra.member?('NTFS'))
t = ::Zip::DOSTime.at(1410496497.405178) t = ::Zip::DOSTime.at(1410496497.405178)
assert_equal(t, extra['NTFS'].mtime) assert_equal(t, extra['NTFS'].mtime)
assert_equal(t, extra['NTFS'].atime) assert_equal(t, extra['NTFS'].atime)
@ -29,12 +29,12 @@ class ZipExtraFieldTest < MiniTest::Test
def test_merge def test_merge
str = "UT\x5\0\x3\250$\r@Ux\0\0" str = "UT\x5\0\x3\250$\r@Ux\0\0"
extra1 = ::Zip::ExtraField.new("") extra1 = ::Zip::ExtraField.new('')
extra2 = ::Zip::ExtraField.new(str) extra2 = ::Zip::ExtraField.new(str)
assert(!extra1.member?("UniversalTime")) assert(!extra1.member?('UniversalTime'))
assert(extra2.member?("UniversalTime")) assert(extra2.member?('UniversalTime'))
extra1.merge(str) extra1.merge(str)
assert_equal(extra1["UniversalTime"].mtime, extra2["UniversalTime"].mtime) assert_equal(extra1['UniversalTime'].mtime, extra2['UniversalTime'].mtime)
end end
def test_length def test_length
@ -42,7 +42,7 @@ class ZipExtraFieldTest < MiniTest::Test
extra = ::Zip::ExtraField.new(str) extra = ::Zip::ExtraField.new(str)
assert_equal(extra.local_size, extra.to_local_bin.size) assert_equal(extra.local_size, extra.to_local_bin.size)
assert_equal(extra.c_dir_size, extra.to_c_dir_bin.size) assert_equal(extra.c_dir_size, extra.to_c_dir_bin.size)
extra.merge("foo") extra.merge('foo')
assert_equal(extra.local_size, extra.to_local_bin.size) assert_equal(extra.local_size, extra.to_local_bin.size)
assert_equal(extra.c_dir_size, extra.to_c_dir_bin.size) assert_equal(extra.c_dir_size, extra.to_c_dir_bin.size)
end end
@ -53,7 +53,7 @@ class ZipExtraFieldTest < MiniTest::Test
assert_instance_of(String, extra.to_s) assert_instance_of(String, extra.to_s)
s = extra.to_s s = extra.to_s
extra.merge("foo") extra.merge('foo')
assert_equal(s.length + 3, extra.to_s.length) assert_equal(s.length + 3, extra.to_s.length)
end end
@ -64,13 +64,13 @@ class ZipExtraFieldTest < MiniTest::Test
extra3 = ::Zip::ExtraField.new(str) extra3 = ::Zip::ExtraField.new(str)
assert_equal(extra1, extra2) assert_equal(extra1, extra2)
extra2["UniversalTime"].mtime = ::Zip::DOSTime.now extra2['UniversalTime'].mtime = ::Zip::DOSTime.now
assert(extra1 != extra2) assert(extra1 != extra2)
extra3.create("IUnix") extra3.create('IUnix')
assert(extra1 != extra3) assert(extra1 != extra3)
extra1.create("IUnix") extra1.create('IUnix')
assert_equal(extra1, extra3) assert_equal(extra1, extra3)
end end
end end

View File

@ -3,7 +3,7 @@ require 'test_helper'
class ZipFileExtractDirectoryTest < MiniTest::Test class ZipFileExtractDirectoryTest < MiniTest::Test
include CommonZipFileFixture include CommonZipFileFixture
TEST_OUT_NAME = "test/data/generated/emptyOutDir" TEST_OUT_NAME = 'test/data/generated/emptyOutDir'
def open_zip(&aProc) def open_zip(&aProc)
assert(aProc != nil) assert(aProc != nil)
@ -35,12 +35,12 @@ class ZipFileExtractDirectoryTest < MiniTest::Test
end end
def test_extractDirectoryExistsAsFile def test_extractDirectoryExistsAsFile
File.open(TEST_OUT_NAME, "w") { |f| f.puts "something" } File.open(TEST_OUT_NAME, 'w') { |f| f.puts 'something' }
assert_raises(::Zip::DestinationFileExistsError) { extract_test_dir } assert_raises(::Zip::DestinationFileExistsError) { extract_test_dir }
end end
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 do |entry, destPath| extract_test_dir do |entry, destPath|
gotCalled = true gotCalled = true

View File

@ -2,7 +2,7 @@ require 'test_helper'
class ZipFileExtractTest < MiniTest::Test class ZipFileExtractTest < MiniTest::Test
include CommonZipFileFixture include CommonZipFileFixture
EXTRACTED_FILENAME = "test/data/generated/extEntry" EXTRACTED_FILENAME = 'test/data/generated/extEntry'
ENTRY_TO_EXTRACT, *REMAINING_ENTRIES = TEST_ZIP.entry_names.reverse ENTRY_TO_EXTRACT, *REMAINING_ENTRIES = TEST_ZIP.entry_names.reverse
def setup def setup
@ -30,22 +30,22 @@ class ZipFileExtractTest < MiniTest::Test
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) do assert_raises(::Zip::DestinationFileExistsError) do
::Zip::File.open(TEST_ZIP.zip_name) do |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
end end
File.open(EXTRACTED_FILENAME, "r") do |f| File.open(EXTRACTED_FILENAME, 'r') do |f|
assert_equal(writtenText, f.read) assert_equal(writtenText, f.read)
end end
end end
def test_extractExistsOverwrite def test_extractExistsOverwrite
writtenText = "written text" writtenText = 'written text'
::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) do |zf| ::Zip::File.open(TEST_ZIP.zip_name) do |zf|
@ -57,23 +57,23 @@ class ZipFileExtractTest < MiniTest::Test
end end
assert(gotCalledCorrectly) assert(gotCalledCorrectly)
::File.open(EXTRACTED_FILENAME, "r") do |f| ::File.open(EXTRACTED_FILENAME, 'r') do |f|
assert(writtenText != f.read) assert(writtenText != f.read)
end end
end end
def test_extractNonEntry def test_extractNonEntry
zf = ::Zip::File.new(TEST_ZIP.zip_name) zf = ::Zip::File.new(TEST_ZIP.zip_name)
assert_raises(Errno::ENOENT) { zf.extract("nonExistingEntry", "nonExistingEntry") } assert_raises(Errno::ENOENT) { zf.extract('nonExistingEntry', 'nonExistingEntry') }
ensure ensure
zf.close if zf zf.close if zf
end end
def test_extractNonEntry2 def test_extractNonEntry2
outFile = "outfile" outFile = 'outfile'
assert_raises(Errno::ENOENT) do 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

View File

@ -2,9 +2,9 @@ require 'test_helper'
class ZipFileSplitTest < MiniTest::Test class ZipFileSplitTest < MiniTest::Test
TEST_ZIP = TestZipFile::TEST_ZIP2.clone TEST_ZIP = TestZipFile::TEST_ZIP2.clone
TEST_ZIP.zip_name = "large_zip_file.zip" TEST_ZIP.zip_name = 'large_zip_file.zip'
EXTRACTED_FILENAME = "test/data/generated/extEntrySplit" EXTRACTED_FILENAME = 'test/data/generated/extEntrySplit'
UNSPLITTED_FILENAME = "test/data/generated/unsplitted.zip" UNSPLITTED_FILENAME = 'test/data/generated/unsplitted.zip'
ENTRY_TO_EXTRACT = TEST_ZIP.entry_names.first ENTRY_TO_EXTRACT = TEST_ZIP.entry_names.first
def setup def setup
@ -21,7 +21,7 @@ class ZipFileSplitTest < MiniTest::Test
end end
def test_split_method_respond def test_split_method_respond
assert_respond_to ::Zip::File, :split, "Does not have split class method" assert_respond_to ::Zip::File, :split, 'Does not have split class method'
end end
def test_split def test_split

View File

@ -11,11 +11,11 @@ class ZipFileTest < MiniTest::Test
end end
def test_createFromScratchToBuffer def test_createFromScratchToBuffer
comment = "a short comment" comment = 'a short comment'
buffer = ::Zip::File.add_buffer do |zf| buffer = ::Zip::File.add_buffer do |zf|
zf.get_output_stream("myFile") { |os| os.write "myFile contains just this" } zf.get_output_stream('myFile') { |os| os.write 'myFile contains just this' }
zf.mkdir("dir1") zf.mkdir('dir1')
zf.comment = comment zf.comment = comment
end end
@ -27,11 +27,11 @@ class ZipFileTest < MiniTest::Test
end end
def test_createFromScratch def test_createFromScratch
comment = "a short comment" comment = 'a short comment'
zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE) zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
zf.get_output_stream("myFile") { |os| os.write "myFile contains just this" } zf.get_output_stream('myFile') { |os| os.write 'myFile contains just this' }
zf.mkdir("dir1") zf.mkdir('dir1')
zf.comment = comment zf.comment = comment
zf.close zf.close
@ -45,20 +45,20 @@ class ZipFileTest < MiniTest::Test
::Zip::File.open(TEST_ZIP.zip_name) do |zf| ::Zip::File.open(TEST_ZIP.zip_name) do |zf|
entryCount = zf.size entryCount = zf.size
zf.get_output_stream('newEntry.txt') do |os| zf.get_output_stream('newEntry.txt') do |os|
os.write "Putting stuff in newEntry.txt" os.write 'Putting stuff in newEntry.txt'
end 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')) do |os| zf.get_output_stream(zf.get_entry('test/data/generated/empty.txt')) do |os|
os.write "Putting stuff in data/generated/empty.txt" os.write 'Putting stuff in data/generated/empty.txt'
end 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) do |os| zf.get_output_stream('entry_with_custom_args.txt', nil, *custom_entry_args) do |os|
os.write "Some data" os.write 'Some data'
end 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')
@ -76,17 +76,17 @@ class ZipFileTest < MiniTest::Test
::Zip::File.open(TEST_ZIP.zip_name) do |zf| ::Zip::File.open(TEST_ZIP.zip_name) do |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 end
def test_cleans_up_tempfiles_after_close def test_cleans_up_tempfiles_after_close
zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE) zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
zf.get_output_stream("myFile") do |os| zf.get_output_stream('myFile') do |os|
@tempfile_path = os.path @tempfile_path = os.path
os.write "myFile contains just this" os.write 'myFile contains just this'
end end
assert_equal(true, File.exist?(@tempfile_path)) assert_equal(true, File.exist?(@tempfile_path))
@ -97,15 +97,15 @@ class ZipFileTest < MiniTest::Test
end end
def test_add def test_add
srcFile = "test/data/file2.txt" srcFile = 'test/data/file2.txt'
entryName = "newEntryName.rb" entryName = 'newEntryName.rb'
assert(::File.exist?(srcFile)) assert(::File.exist?(srcFile))
zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE) zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
zf.add(entryName, srcFile) zf.add(entryName, srcFile)
zf.close zf.close
zfRead = ::Zip::File.new(EMPTY_FILENAME) zfRead = ::Zip::File.new(EMPTY_FILENAME)
assert_equal("", zfRead.comment) assert_equal('', zfRead.comment)
assert_equal(1, zfRead.entries.length) assert_equal(1, zfRead.entries.length)
assert_equal(entryName, zfRead.entries.first.name) assert_equal(entryName, zfRead.entries.first.name)
AssertEntry.assert_contents(srcFile, AssertEntry.assert_contents(srcFile,
@ -115,8 +115,8 @@ class ZipFileTest < MiniTest::Test
def test_recover_permissions_after_add_files_to_archive def test_recover_permissions_after_add_files_to_archive
srcZip = TEST_ZIP.zip_name srcZip = TEST_ZIP.zip_name
::File.chmod(0664, srcZip) ::File.chmod(0664, srcZip)
srcFile = "test/data/file2.txt" srcFile = 'test/data/file2.txt'
entryName = "newEntryName.rb" entryName = 'newEntryName.rb'
assert_equal(::File.stat(srcZip).mode, 0100664) assert_equal(::File.stat(srcZip).mode, 0100664)
assert(::File.exist?(srcZip)) assert(::File.exist?(srcZip))
zf = ::Zip::File.new(srcZip, ::Zip::File::CREATE) zf = ::Zip::File.new(srcZip, ::Zip::File::CREATE)
@ -128,7 +128,7 @@ class ZipFileTest < MiniTest::Test
def test_addExistingEntryName def test_addExistingEntryName
assert_raises(::Zip::EntryExistsError) do assert_raises(::Zip::EntryExistsError) do
::Zip::File.open(TEST_ZIP.zip_name) do |zf| ::Zip::File.open(TEST_ZIP.zip_name) do |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
end end
@ -138,11 +138,11 @@ class ZipFileTest < MiniTest::Test
replacedEntry = nil replacedEntry = nil
::Zip::File.open(TEST_ZIP.zip_name) do |zf| ::Zip::File.open(TEST_ZIP.zip_name) do |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 end
assert(gotCalled) assert(gotCalled)
::Zip::File.open(TEST_ZIP.zip_name) do |zf| ::Zip::File.open(TEST_ZIP.zip_name) do |zf|
assert_contains(zf, replacedEntry, "test/data/file2.txt") assert_contains(zf, replacedEntry, 'test/data/file2.txt')
end end
end end
@ -151,7 +151,7 @@ class ZipFileTest < MiniTest::Test
zf.add(TestFiles::EMPTY_TEST_DIR, TestFiles::EMPTY_TEST_DIR) zf.add(TestFiles::EMPTY_TEST_DIR, TestFiles::EMPTY_TEST_DIR)
end end
::Zip::File.open(TEST_ZIP.zip_name) do |zf| ::Zip::File.open(TEST_ZIP.zip_name) do |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 end
@ -181,7 +181,7 @@ class ZipFileTest < MiniTest::Test
assert(zf.entries.map { |e| e.name }.include?(entryToRename)) assert(zf.entries.map { |e| e.name }.include?(entryToRename))
contents = zf.read(entryToRename) contents = zf.read(entryToRename)
newName = "changed entry name" newName = 'changed entry name'
assert(!zf.entries.map { |e| e.name }.include?(newName)) assert(!zf.entries.map { |e| e.name }.include?(newName))
zf.rename(entryToRename, newName) zf.rename(entryToRename, newName)
@ -217,7 +217,7 @@ class ZipFileTest < MiniTest::Test
zf = ::Zip::File.open(zf_name) zf = ::Zip::File.open(zf_name)
assert_equal(zf.entries.map(&:name), arr) assert_equal(zf.entries.map(&:name), arr)
zf.close zf.close
Zip::File.open(zf_name, "wb") do |z| Zip::File.open(zf_name, 'wb') do |z|
z.each do |f| z.each do |f|
z.rename(f, "Z#{f.name}") z.rename(f, "Z#{f.name}")
end end
@ -265,8 +265,8 @@ class ZipFileTest < MiniTest::Test
end end
def test_renameNonEntry def test_renameNonEntry
nonEntry = "bogusEntry" nonEntry = 'bogusEntry'
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) { zf.rename(nonEntry, target_entry) } assert_raises(Errno::ENOENT) { zf.rename(nonEntry, target_entry) }
@ -286,7 +286,7 @@ class ZipFileTest < MiniTest::Test
def test_replace def test_replace
entryToReplace = TEST_ZIP.entry_names[2] entryToReplace = TEST_ZIP.entry_names[2]
newEntrySrcFilename = "test/data/file2.txt" newEntrySrcFilename = 'test/data/file2.txt'
zf = ::Zip::File.new(TEST_ZIP.zip_name) zf = ::Zip::File.new(TEST_ZIP.zip_name)
zf.replace(entryToReplace, newEntrySrcFilename) zf.replace(entryToReplace, newEntrySrcFilename)
@ -304,14 +304,14 @@ class ZipFileTest < MiniTest::Test
end end
def test_replaceNonEntry def test_replaceNonEntry
entryToReplace = "nonExistingEntryname" entryToReplace = 'nonExistingEntryname'
::Zip::File.open(TEST_ZIP.zip_name) do |zf| ::Zip::File.open(TEST_ZIP.zip_name) do |zf|
assert_raises(Errno::ENOENT) { zf.replace(entryToReplace, "test/data/file2.txt") } assert_raises(Errno::ENOENT) { zf.replace(entryToReplace, 'test/data/file2.txt') }
end end
end end
def test_commit def test_commit
newName = "renamedFirst" newName = 'renamedFirst'
zf = ::Zip::File.new(TEST_ZIP.zip_name) zf = ::Zip::File.new(TEST_ZIP.zip_name)
oldName = zf.entries.first oldName = zf.entries.first
zf.rename(oldName, newName) zf.rename(oldName, newName)
@ -349,7 +349,7 @@ class ZipFileTest < MiniTest::Test
end end
def test_write_buffer def test_write_buffer
newName = "renamedFirst" newName = 'renamedFirst'
zf = ::Zip::File.new(TEST_ZIP.zip_name) zf = ::Zip::File.new(TEST_ZIP.zip_name)
oldName = zf.entries.first oldName = zf.entries.first
zf.rename(oldName, newName) zf.rename(oldName, newName)
@ -370,11 +370,11 @@ class ZipFileTest < MiniTest::Test
def test_commitUseZipEntry def test_commitUseZipEntry
FileUtils.cp(TestFiles::RANDOM_ASCII_FILE1, OK_DELETE_FILE) FileUtils.cp(TestFiles::RANDOM_ASCII_FILE1, OK_DELETE_FILE)
zf = ::Zip::File.open(TEST_ZIP.zip_name) zf = ::Zip::File.open(TEST_ZIP.zip_name)
zf.add("okToDelete.txt", OK_DELETE_FILE) zf.add('okToDelete.txt', OK_DELETE_FILE)
assert_contains(zf, "okToDelete.txt") assert_contains(zf, 'okToDelete.txt')
zf.commit zf.commit
File.rename(OK_DELETE_FILE, OK_DELETE_MOVED_FILE) File.rename(OK_DELETE_FILE, OK_DELETE_MOVED_FILE)
assert_contains(zf, "okToDelete.txt", OK_DELETE_MOVED_FILE) assert_contains(zf, 'okToDelete.txt', OK_DELETE_MOVED_FILE)
end end
# def test_close # def test_close
@ -386,7 +386,7 @@ class ZipFileTest < MiniTest::Test
# end # end
def test_compound1 def test_compound1
renamedName = "renamedName" renamedName = 'renamedName'
filename_to_remove = '' filename_to_remove = ''
begin begin
zf = ::Zip::File.new(TEST_ZIP.zip_name) zf = ::Zip::File.new(TEST_ZIP.zip_name)
@ -444,9 +444,9 @@ class ZipFileTest < MiniTest::Test
end 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')
assert_not_contains(zf, TestFiles::ASCII_TEST_FILES[0]) assert_not_contains(zf, TestFiles::ASCII_TEST_FILES[0])
assert_contains(zf, "newName") assert_contains(zf, 'newName')
ensure ensure
zf.close zf.close
end end
@ -458,7 +458,7 @@ class ZipFileTest < MiniTest::Test
assert_contains(zf, filename) assert_contains(zf, filename)
end end
assert_contains(zf, "newName") assert_contains(zf, 'newName')
ensure ensure
zfRead.close zfRead.close
end end
@ -466,20 +466,20 @@ class ZipFileTest < MiniTest::Test
def test_changeComment def test_changeComment
::Zip::File.open(TEST_ZIP.zip_name) do |zf| ::Zip::File.open(TEST_ZIP.zip_name) do |zf|
zf.comment = "my changed comment" zf.comment = 'my changed comment'
end end
zfRead = ::Zip::File.open(TEST_ZIP.zip_name) zfRead = ::Zip::File.open(TEST_ZIP.zip_name)
assert_equal("my changed comment", zfRead.comment) assert_equal('my changed comment', zfRead.comment)
end end
def test_preserve_file_order def test_preserve_file_order
entryNames = nil entryNames = nil
::Zip::File.open(TEST_ZIP.zip_name) do |zf| ::Zip::File.open(TEST_ZIP.zip_name) do |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 end
::Zip::File.open(TEST_ZIP.zip_name) do |zf| ::Zip::File.open(TEST_ZIP.zip_name) do |zf|
@ -487,7 +487,7 @@ class ZipFileTest < MiniTest::Test
entries = zf.entries.sort_by { |e| e.name }.reverse entries = zf.entries.sort_by { |e| e.name }.reverse
entries.each do |e| entries.each do |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 end
entryNames = entries.map { |e| e.to_s } entryNames = entries.map { |e| e.to_s }
end end
@ -497,8 +497,8 @@ class ZipFileTest < MiniTest::Test
end end
def test_streaming def test_streaming
fname = ::File.join(::File.expand_path(::File.dirname(__FILE__)), "../README.md") fname = ::File.join(::File.expand_path(::File.dirname(__FILE__)), '../README.md')
zname = "test/data/generated/README.zip" zname = 'test/data/generated/README.zip'
Zip::File.open(zname, Zip::File::CREATE) do |zipfile| Zip::File.open(zname, Zip::File::CREATE) do |zipfile|
zipfile.get_output_stream(File.basename(fname)) do |f| zipfile.get_output_stream(File.basename(fname)) do |f|
f.puts File.read(fname) f.puts File.read(fname)

View File

@ -10,19 +10,19 @@ class ZipFsDirIteratorTest < MiniTest::Test
def test_close def test_close
@dirIt.close @dirIt.close
assert_raises(IOError, "closed directory") do assert_raises(IOError, 'closed directory') do
@dirIt.each { |e| p e } @dirIt.each { |e| p e }
end end
assert_raises(IOError, "closed directory") do assert_raises(IOError, 'closed directory') do
@dirIt.read @dirIt.read
end end
assert_raises(IOError, "closed directory") do assert_raises(IOError, 'closed directory') do
@dirIt.rewind @dirIt.rewind
end end
assert_raises(IOError, "closed directory") do assert_raises(IOError, 'closed directory') do
@dirIt.seek(0) @dirIt.seek(0)
end end
assert_raises(IOError, "closed directory") do assert_raises(IOError, 'closed directory') do
@dirIt.tell @dirIt.tell
end end
end end

View File

@ -2,85 +2,85 @@ require 'test_helper'
require 'zip/filesystem' require 'zip/filesystem'
class ZipFsDirectoryTest < MiniTest::Test class ZipFsDirectoryTest < MiniTest::Test
TEST_ZIP = "test/data/generated/zipWithDirs_copy.zip" TEST_ZIP = 'test/data/generated/zipWithDirs_copy.zip'
def setup def setup
FileUtils.cp("test/data/zipWithDirs.zip", TEST_ZIP) FileUtils.cp('test/data/zipWithDirs.zip', TEST_ZIP)
end end
def test_delete def test_delete
::Zip::File.open(TEST_ZIP) do |zf| ::Zip::File.open(TEST_ZIP) do |zf|
assert_raises(Errno::ENOENT, "No such file or directory - NoSuchFile.txt") do assert_raises(Errno::ENOENT, 'No such file or directory - NoSuchFile.txt') do
zf.dir.delete("NoSuchFile.txt") zf.dir.delete('NoSuchFile.txt')
end end
assert_raises(Errno::EINVAL, "Invalid argument - file1") do assert_raises(Errno::EINVAL, 'Invalid argument - file1') do
zf.dir.delete("file1") zf.dir.delete('file1')
end 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 end
def test_mkdir def test_mkdir
::Zip::File.open(TEST_ZIP) do |zf| ::Zip::File.open(TEST_ZIP) do |zf|
assert_raises(Errno::EEXIST, "File exists - dir1") do assert_raises(Errno::EEXIST, 'File exists - dir1') do
zf.dir.mkdir("file1") zf.dir.mkdir('file1')
end end
assert_raises(Errno::EEXIST, "File exists - dir1") do assert_raises(Errno::EEXIST, 'File exists - dir1') do
zf.dir.mkdir("dir1") zf.dir.mkdir('dir1')
end 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 end
def test_pwd_chdir_entries def test_pwd_chdir_entries
::Zip::File.open(TEST_ZIP) do |zf| ::Zip::File.open(TEST_ZIP) do |zf|
assert_equal("/", zf.dir.pwd) assert_equal('/', zf.dir.pwd)
assert_raises(Errno::ENOENT, "No such file or directory - no such dir") do 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 end
assert_raises(Errno::EINVAL, "Invalid argument - file1") do assert_raises(Errno::EINVAL, 'Invalid argument - file1') do
zf.dir.chdir "file1" zf.dir.chdir 'file1'
end 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'
assert_equal("/dir1", zf.dir.pwd) assert_equal('/dir1', zf.dir.pwd)
assert_equal(%w(dir11 file11 file12), zf.dir.entries(".").sort) assert_equal(%w(dir11 file11 file12), zf.dir.entries('.').sort)
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 end
def test_foreach def test_foreach
::Zip::File.open(TEST_ZIP) do |zf| ::Zip::File.open(TEST_ZIP) do |zf|
blockCalled = false blockCalled = false
assert_raises(Errno::ENOENT, "No such file or directory - noSuchDir") do 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 end
assert(! blockCalled) assert(! blockCalled)
assert_raises(Errno::ENOTDIR, "Not a directory - file1") do assert_raises(Errno::ENOTDIR, 'Not a directory - file1') do
zf.dir.foreach("file1") { |_e| blockCalled = true } zf.dir.foreach('file1') { |_e| blockCalled = true }
end end
assert(! blockCalled) assert(! blockCalled)
entries = [] entries = []
zf.dir.foreach(".") { |e| entries << e } zf.dir.foreach('.') { |e| entries << e }
assert_equal(%w(dir1 dir2 file1).sort, entries.sort) assert_equal(%w(dir1 dir2 file1).sort, entries.sort)
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 end
@ -101,19 +101,19 @@ class ZipFsDirectoryTest < MiniTest::Test
def test_open_new def test_open_new
::Zip::File.open(TEST_ZIP) do |zf| ::Zip::File.open(TEST_ZIP) do |zf|
assert_raises(Errno::ENOTDIR, "Not a directory - file1") do assert_raises(Errno::ENOTDIR, 'Not a directory - file1') do
zf.dir.new("file1") zf.dir.new('file1')
end end
assert_raises(Errno::ENOENT, "No such file or directory - noSuchFile") do assert_raises(Errno::ENOENT, 'No such file or directory - noSuchFile') do
zf.dir.new("noSuchFile") zf.dir.new('noSuchFile')
end 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") do |dir| zf.dir.open('dir1') do |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

View File

@ -2,9 +2,9 @@ require 'test_helper'
require 'zip/filesystem' require 'zip/filesystem'
class ZipFsFileMutatingTest < MiniTest::Test class ZipFsFileMutatingTest < MiniTest::Test
TEST_ZIP = "test/data/generated/zipWithDirs_copy.zip" TEST_ZIP = 'test/data/generated/zipWithDirs_copy.zip'
def setup def setup
FileUtils.cp("test/data/zipWithDirs.zip", TEST_ZIP) FileUtils.cp('test/data/zipWithDirs.zip', TEST_ZIP)
end end
def teardown def teardown
@ -20,69 +20,69 @@ class ZipFsFileMutatingTest < MiniTest::Test
def test_open_write def test_open_write
::Zip::File.open(TEST_ZIP) do |zf| ::Zip::File.open(TEST_ZIP) do |zf|
zf.file.open("test_open_write_entry", "w") do |f| zf.file.open('test_open_write_entry', 'w') do |f|
f.write "This is what I'm writing" f.write "This is what I'm writing"
end 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") do |f| #also check that 'b' option is ignored zf.file.open('file1', 'wb') do |f| #also check that 'b' option is ignored
f.write "This is what I'm writing too" f.write "This is what I'm writing too"
end 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 end
def test_rename def test_rename
::Zip::File.open(TEST_ZIP) do |zf| ::Zip::File.open(TEST_ZIP) do |zf|
assert_raises(Errno::ENOENT, "") do assert_raises(Errno::ENOENT, '') do
zf.file.rename("NoSuchFile", "bimse") zf.file.rename('NoSuchFile', 'bimse')
end end
zf.file.rename("file1", "newNameForFile1") zf.file.rename('file1', 'newNameForFile1')
end end
::Zip::File.open(TEST_ZIP) do |zf| ::Zip::File.open(TEST_ZIP) do |zf|
assert(! zf.file.exists?("file1")) assert(! zf.file.exists?('file1'))
assert(zf.file.exists?("newNameForFile1")) assert(zf.file.exists?('newNameForFile1'))
end end
end end
def test_chmod def test_chmod
::Zip::File.open(TEST_ZIP) do |zf| ::Zip::File.open(TEST_ZIP) do |zf|
zf.file.chmod(0765, "file1") zf.file.chmod(0765, 'file1')
end end
::Zip::File.open(TEST_ZIP) do |zf| ::Zip::File.open(TEST_ZIP) do |zf|
assert_equal(0100765, zf.file.stat("file1").mode) assert_equal(0100765, zf.file.stat('file1').mode)
end end
end end
def do_test_delete_or_unlink(symbol) def do_test_delete_or_unlink(symbol)
::Zip::File.open(TEST_ZIP) do |zf| ::Zip::File.open(TEST_ZIP) do |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'))
assert(zf.file.exists?("dir1/file11")) assert(zf.file.exists?('dir1/file11'))
assert(zf.file.exists?("dir1/file12")) assert(zf.file.exists?('dir1/file12'))
zf.file.send(symbol, "dir1/file11", "dir1/file12") zf.file.send(symbol, 'dir1/file11', 'dir1/file12')
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_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 end
::Zip::File.open(TEST_ZIP) do |zf| ::Zip::File.open(TEST_ZIP) do |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 end

View File

@ -3,13 +3,13 @@ require 'zip/filesystem'
class ZipFsFileNonmutatingTest < MiniTest::Test class ZipFsFileNonmutatingTest < MiniTest::Test
def setup def setup
@zipsha = Digest::SHA1.file("test/data/zipWithDirs.zip") @zipsha = Digest::SHA1.file('test/data/zipWithDirs.zip')
@zip_file = ::Zip::File.new("test/data/zipWithDirs.zip") @zip_file = ::Zip::File.new('test/data/zipWithDirs.zip')
end end
def teardown def teardown
@zip_file.close if @zip_file @zip_file.close if @zip_file
assert_equal(@zipsha, Digest::SHA1.file("test/data/zipWithDirs.zip")) assert_equal(@zipsha, Digest::SHA1.file('test/data/zipWithDirs.zip'))
end end
def test_umask def test_umask
@ -18,21 +18,21 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
end end
def test_exists? def test_exists?
assert(! @zip_file.file.exists?("notAFile")) assert(! @zip_file.file.exists?('notAFile'))
assert(@zip_file.file.exists?("file1")) assert(@zip_file.file.exists?('file1'))
assert(@zip_file.file.exists?("dir1")) assert(@zip_file.file.exists?('dir1'))
assert(@zip_file.file.exists?("dir1/")) assert(@zip_file.file.exists?('dir1/'))
assert(@zip_file.file.exists?("dir1/file12")) assert(@zip_file.file.exists?('dir1/file12'))
assert(@zip_file.file.exist?("dir1/file12")) # notice, tests exist? alias of exists? ! assert(@zip_file.file.exist?('dir1/file12')) # notice, tests exist? alias of exists? !
@zip_file.dir.chdir "dir1/" @zip_file.dir.chdir 'dir1/'
assert(!@zip_file.file.exists?("file1")) assert(!@zip_file.file.exists?('file1'))
assert(@zip_file.file.exists?("file12")) assert(@zip_file.file.exists?('file12'))
end end
def test_open_read def test_open_read
blockCalled = false blockCalled = false
@zip_file.file.open("file1", "r") do |f| @zip_file.file.open('file1', 'r') do |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)
@ -40,7 +40,7 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
assert(blockCalled) assert(blockCalled)
blockCalled = false blockCalled = false
@zip_file.file.open("file1", "rb") do |f| # test binary flag is ignored @zip_file.file.open('file1', 'rb') do |f| # test binary flag is ignored
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)
@ -48,21 +48,21 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
assert(blockCalled) assert(blockCalled)
blockCalled = false blockCalled = false
@zip_file.dir.chdir "dir2" @zip_file.dir.chdir 'dir2'
@zip_file.file.open("file21", "r") do |f| @zip_file.file.open('file21', 'r') do |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 end
assert(blockCalled) assert(blockCalled)
@zip_file.dir.chdir "/" @zip_file.dir.chdir '/'
assert_raises(Errno::ENOENT) do assert_raises(Errno::ENOENT) do
@zip_file.file.open("noSuchEntry") @zip_file.file.open('noSuchEntry')
end end
begin begin
is = @zip_file.file.open("file1") is = @zip_file.file.open('file1')
assert_equal("this is the entry 'file1' in my test archive!", assert_equal("this is the entry 'file1' in my test archive!",
is.readline.chomp) is.readline.chomp)
ensure ensure
@ -72,15 +72,15 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
def test_new def test_new
begin begin
is = @zip_file.file.new("file1") is = @zip_file.file.new('file1')
assert_equal("this is the entry 'file1' in my test archive!", assert_equal("this is the entry 'file1' in my test archive!",
is.readline.chomp) is.readline.chomp)
ensure ensure
is.close if is is.close if is
end end
begin begin
is = @zip_file.file.new("file1") do is = @zip_file.file.new('file1') do
fail "should not call block" fail 'should not call block'
end end
ensure ensure
is.close if is is.close if is
@ -89,90 +89,90 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
def test_symlink def test_symlink
assert_raises(NotImplementedError) do assert_raises(NotImplementedError) do
@zip_file.file.symlink("file1", "aSymlink") @zip_file.file.symlink('file1', 'aSymlink')
end end
end end
def test_size def test_size
assert_raises(Errno::ENOENT) { @zip_file.file.size("notAFile") } assert_raises(Errno::ENOENT) { @zip_file.file.size('notAFile') }
assert_equal(72, @zip_file.file.size("file1")) assert_equal(72, @zip_file.file.size('file1'))
assert_equal(0, @zip_file.file.size("dir2/dir21")) assert_equal(0, @zip_file.file.size('dir2/dir21'))
assert_equal(72, @zip_file.file.stat("file1").size) assert_equal(72, @zip_file.file.stat('file1').size)
assert_equal(0, @zip_file.file.stat("dir2/dir21").size) assert_equal(0, @zip_file.file.stat('dir2/dir21').size)
end end
def test_size? def test_size?
assert_equal(nil, @zip_file.file.size?("notAFile")) assert_equal(nil, @zip_file.file.size?('notAFile'))
assert_equal(72, @zip_file.file.size?("file1")) assert_equal(72, @zip_file.file.size?('file1'))
assert_equal(nil, @zip_file.file.size?("dir2/dir21")) assert_equal(nil, @zip_file.file.size?('dir2/dir21'))
assert_equal(72, @zip_file.file.stat("file1").size?) assert_equal(72, @zip_file.file.stat('file1').size?)
assert_equal(nil, @zip_file.file.stat("dir2/dir21").size?) assert_equal(nil, @zip_file.file.stat('dir2/dir21').size?)
end end
def test_file? def test_file?
assert(@zip_file.file.file?("file1")) assert(@zip_file.file.file?('file1'))
assert(@zip_file.file.file?("dir2/file21")) assert(@zip_file.file.file?('dir2/file21'))
assert(! @zip_file.file.file?("dir1")) assert(! @zip_file.file.file?('dir1'))
assert(! @zip_file.file.file?("dir1/dir11")) assert(! @zip_file.file.file?('dir1/dir11'))
assert(@zip_file.file.stat("file1").file?) assert(@zip_file.file.stat('file1').file?)
assert(@zip_file.file.stat("dir2/file21").file?) assert(@zip_file.file.stat('dir2/file21').file?)
assert(! @zip_file.file.stat("dir1").file?) assert(! @zip_file.file.stat('dir1').file?)
assert(! @zip_file.file.stat("dir1/dir11").file?) assert(! @zip_file.file.stat('dir1/dir11').file?)
end end
include ExtraAssertions include ExtraAssertions
def test_dirname def test_dirname
assert_forwarded(File, :dirname, "retVal", "a/b/c/d") do 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 end
def test_basename def test_basename
assert_forwarded(File, :basename, "retVal", "a/b/c/d") do 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 end
def test_split def test_split
assert_forwarded(File, :split, "retVal", "a/b/c/d") do 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 end
def test_join def test_join
assert_equal("a/b/c", @zip_file.file.join("a/b", "c")) assert_equal('a/b/c', @zip_file.file.join('a/b', 'c'))
assert_equal("a/b/c/d", @zip_file.file.join("a/b", "c/d")) assert_equal('a/b/c/d', @zip_file.file.join('a/b', 'c/d'))
assert_equal("/c/d", @zip_file.file.join("", "c/d")) assert_equal('/c/d', @zip_file.file.join('', 'c/d'))
assert_equal("a/b/c/d", @zip_file.file.join("a", "b", "c", "d")) assert_equal('a/b/c/d', @zip_file.file.join('a', 'b', 'c', 'd'))
end end
def test_utime def test_utime
t_now = ::Zip::DOSTime.now t_now = ::Zip::DOSTime.now
t_bak = @zip_file.file.mtime("file1") t_bak = @zip_file.file.mtime('file1')
@zip_file.file.utime(t_now, "file1") @zip_file.file.utime(t_now, 'file1')
assert_equal(t_now, @zip_file.file.mtime("file1")) assert_equal(t_now, @zip_file.file.mtime('file1'))
@zip_file.file.utime(t_bak, "file1") @zip_file.file.utime(t_bak, 'file1')
assert_equal(t_bak, @zip_file.file.mtime("file1")) assert_equal(t_bak, @zip_file.file.mtime('file1'))
end end
def assert_always_false(operation) def assert_always_false(operation)
assert(! @zip_file.file.send(operation, "noSuchFile")) assert(! @zip_file.file.send(operation, 'noSuchFile'))
assert(! @zip_file.file.send(operation, "file1")) assert(! @zip_file.file.send(operation, 'file1'))
assert(! @zip_file.file.send(operation, "dir1")) assert(! @zip_file.file.send(operation, 'dir1'))
assert(! @zip_file.file.stat("file1").send(operation)) assert(! @zip_file.file.stat('file1').send(operation))
assert(! @zip_file.file.stat("dir1").send(operation)) assert(! @zip_file.file.stat('dir1').send(operation))
end end
def assert_true_if_entry_exists(operation) def assert_true_if_entry_exists(operation)
assert(! @zip_file.file.send(operation, "noSuchFile")) assert(! @zip_file.file.send(operation, 'noSuchFile'))
assert(@zip_file.file.send(operation, "file1")) assert(@zip_file.file.send(operation, 'file1'))
assert(@zip_file.file.send(operation, "dir1")) assert(@zip_file.file.send(operation, 'dir1'))
assert(@zip_file.file.stat("file1").send(operation)) assert(@zip_file.file.stat('file1').send(operation))
assert(@zip_file.file.stat("dir1").send(operation)) assert(@zip_file.file.stat('dir1').send(operation))
end end
def test_pipe? def test_pipe?
@ -196,12 +196,12 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
end end
def test_truncate def test_truncate
assert_raises(StandardError, "truncate not supported") do assert_raises(StandardError, 'truncate not supported') do
@zip_file.file.truncate("file1", 100) @zip_file.file.truncate('file1', 100)
end 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) do assert_raises(Errno::ENOENT) do
@zip_file.file.send(operation, *args) @zip_file.file.send(operation, *args)
end end
@ -209,151 +209,151 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
def test_ftype def test_ftype
assert_e_n_o_e_n_t(:ftype) assert_e_n_o_e_n_t(:ftype)
assert_equal("file", @zip_file.file.ftype("file1")) assert_equal('file', @zip_file.file.ftype('file1'))
assert_equal("directory", @zip_file.file.ftype("dir1/dir11")) assert_equal('directory', @zip_file.file.ftype('dir1/dir11'))
assert_equal("directory", @zip_file.file.ftype("dir1/dir11/")) assert_equal('directory', @zip_file.file.ftype('dir1/dir11/'))
end end
def test_link def test_link
assert_raises(NotImplementedError) do assert_raises(NotImplementedError) do
@zip_file.file.link("file1", "someOtherString") @zip_file.file.link('file1', 'someOtherString')
end end
end end
def test_directory? def test_directory?
assert(! @zip_file.file.directory?("notAFile")) assert(! @zip_file.file.directory?('notAFile'))
assert(! @zip_file.file.directory?("file1")) assert(! @zip_file.file.directory?('file1'))
assert(! @zip_file.file.directory?("dir1/file11")) assert(! @zip_file.file.directory?('dir1/file11'))
assert(@zip_file.file.directory?("dir1")) assert(@zip_file.file.directory?('dir1'))
assert(@zip_file.file.directory?("dir1/")) assert(@zip_file.file.directory?('dir1/'))
assert(@zip_file.file.directory?("dir2/dir21")) assert(@zip_file.file.directory?('dir2/dir21'))
assert(! @zip_file.file.stat("file1").directory?) assert(! @zip_file.file.stat('file1').directory?)
assert(! @zip_file.file.stat("dir1/file11").directory?) assert(! @zip_file.file.stat('dir1/file11').directory?)
assert(@zip_file.file.stat("dir1").directory?) assert(@zip_file.file.stat('dir1').directory?)
assert(@zip_file.file.stat("dir1/").directory?) assert(@zip_file.file.stat('dir1/').directory?)
assert(@zip_file.file.stat("dir2/dir21").directory?) assert(@zip_file.file.stat('dir2/dir21').directory?)
end end
def test_chown def test_chown
assert_equal(2, @zip_file.file.chown(1,2, "dir1", "file1")) assert_equal(2, @zip_file.file.chown(1,2, 'dir1', 'file1'))
assert_equal(1, @zip_file.file.stat("dir1").uid) assert_equal(1, @zip_file.file.stat('dir1').uid)
assert_equal(2, @zip_file.file.stat("dir1").gid) assert_equal(2, @zip_file.file.stat('dir1').gid)
assert_equal(2, @zip_file.file.chown(nil, nil, "dir1", "file1")) assert_equal(2, @zip_file.file.chown(nil, nil, 'dir1', 'file1'))
end end
def test_zero? def test_zero?
assert(! @zip_file.file.zero?("notAFile")) assert(! @zip_file.file.zero?('notAFile'))
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") do |zf| ::Zip::File.open('test/data/generated/5entry.zip') do |zf|
blockCalled = true blockCalled = true
assert(zf.file.zero?("test/data/generated/empty.txt")) assert(zf.file.zero?('test/data/generated/empty.txt'))
end 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") do |zf| ::Zip::File.open('test/data/generated/5entry.zip') do |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 end
assert(blockCalled) assert(blockCalled)
end end
def test_expand_path def test_expand_path
::Zip::File.open("test/data/zipWithDirs.zip") do |zf| ::Zip::File.open('test/data/zipWithDirs.zip') do |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 end
def test_mtime def test_mtime
assert_equal(::Zip::DOSTime.at(1027694306), assert_equal(::Zip::DOSTime.at(1027694306),
@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) do assert_raises(Errno::ENOENT) do
@zip_file.file.mtime("noSuchEntry") @zip_file.file.mtime('noSuchEntry')
end 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)
assert_equal(::Zip::DOSTime.at(1027690863), assert_equal(::Zip::DOSTime.at(1027690863),
@zip_file.file.stat("dir2/dir21").mtime) @zip_file.file.stat('dir2/dir21').mtime)
end end
def test_ctime def test_ctime
assert_nil(@zip_file.file.ctime("file1")) assert_nil(@zip_file.file.ctime('file1'))
assert_nil(@zip_file.file.stat("file1").ctime) assert_nil(@zip_file.file.stat('file1').ctime)
end end
def test_atime def test_atime
assert_nil(@zip_file.file.atime("file1")) assert_nil(@zip_file.file.atime('file1'))
assert_nil(@zip_file.file.stat("file1").atime) assert_nil(@zip_file.file.stat('file1').atime)
end end
def test_ntfs_time def test_ntfs_time
::Zip::File.open("test/data/ntfs.zip") do |zf| ::Zip::File.open('test/data/ntfs.zip') do |zf|
t = ::Zip::DOSTime.at(1410496497.405178) t = ::Zip::DOSTime.at(1410496497.405178)
assert_equal(zf.file.mtime("data.txt"), t) assert_equal(zf.file.mtime('data.txt'), t)
assert_equal(zf.file.atime("data.txt"), t) assert_equal(zf.file.atime('data.txt'), t)
assert_equal(zf.file.ctime("data.txt"), t) assert_equal(zf.file.ctime('data.txt'), t)
end end
end end
def test_readable? def test_readable?
assert(! @zip_file.file.readable?("noSuchFile")) assert(! @zip_file.file.readable?('noSuchFile'))
assert(@zip_file.file.readable?("file1")) assert(@zip_file.file.readable?('file1'))
assert(@zip_file.file.readable?("dir1")) assert(@zip_file.file.readable?('dir1'))
assert(@zip_file.file.stat("file1").readable?) assert(@zip_file.file.stat('file1').readable?)
assert(@zip_file.file.stat("dir1").readable?) assert(@zip_file.file.stat('dir1').readable?)
end end
def test_readable_real? def test_readable_real?
assert(! @zip_file.file.readable_real?("noSuchFile")) assert(! @zip_file.file.readable_real?('noSuchFile'))
assert(@zip_file.file.readable_real?("file1")) assert(@zip_file.file.readable_real?('file1'))
assert(@zip_file.file.readable_real?("dir1")) assert(@zip_file.file.readable_real?('dir1'))
assert(@zip_file.file.stat("file1").readable_real?) assert(@zip_file.file.stat('file1').readable_real?)
assert(@zip_file.file.stat("dir1").readable_real?) assert(@zip_file.file.stat('dir1').readable_real?)
end end
def test_writable? def test_writable?
assert(! @zip_file.file.writable?("noSuchFile")) assert(! @zip_file.file.writable?('noSuchFile'))
assert(@zip_file.file.writable?("file1")) assert(@zip_file.file.writable?('file1'))
assert(@zip_file.file.writable?("dir1")) assert(@zip_file.file.writable?('dir1'))
assert(@zip_file.file.stat("file1").writable?) assert(@zip_file.file.stat('file1').writable?)
assert(@zip_file.file.stat("dir1").writable?) assert(@zip_file.file.stat('dir1').writable?)
end end
def test_writable_real? def test_writable_real?
assert(! @zip_file.file.writable_real?("noSuchFile")) assert(! @zip_file.file.writable_real?('noSuchFile'))
assert(@zip_file.file.writable_real?("file1")) assert(@zip_file.file.writable_real?('file1'))
assert(@zip_file.file.writable_real?("dir1")) assert(@zip_file.file.writable_real?('dir1'))
assert(@zip_file.file.stat("file1").writable_real?) assert(@zip_file.file.stat('file1').writable_real?)
assert(@zip_file.file.stat("dir1").writable_real?) assert(@zip_file.file.stat('dir1').writable_real?)
end end
def test_executable? def test_executable?
assert(! @zip_file.file.executable?("noSuchFile")) assert(! @zip_file.file.executable?('noSuchFile'))
assert(! @zip_file.file.executable?("file1")) assert(! @zip_file.file.executable?('file1'))
assert(@zip_file.file.executable?("dir1")) assert(@zip_file.file.executable?('dir1'))
assert(! @zip_file.file.stat("file1").executable?) assert(! @zip_file.file.stat('file1').executable?)
assert(@zip_file.file.stat("dir1").executable?) assert(@zip_file.file.stat('dir1').executable?)
end end
def test_executable_real? def test_executable_real?
assert(! @zip_file.file.executable_real?("noSuchFile")) assert(! @zip_file.file.executable_real?('noSuchFile'))
assert(! @zip_file.file.executable_real?("file1")) assert(! @zip_file.file.executable_real?('file1'))
assert(@zip_file.file.executable_real?("dir1")) assert(@zip_file.file.executable_real?('dir1'))
assert(! @zip_file.file.stat("file1").executable_real?) assert(! @zip_file.file.stat('file1').executable_real?)
assert(@zip_file.file.stat("dir1").executable_real?) assert(@zip_file.file.stat('dir1').executable_real?)
end end
def test_owned? def test_owned?
@ -378,20 +378,20 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
def test_readlink def test_readlink
assert_raises(NotImplementedError) do assert_raises(NotImplementedError) do
@zip_file.file.readlink("someString") @zip_file.file.readlink('someString')
end 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") do assert_raises(Errno::ENOENT, 'No such file or directory - noSuchFile') do
@zip_file.file.stat("noSuchFile") @zip_file.file.stat('noSuchFile')
end end
end end
def test_lstat def test_lstat
assert(@zip_file.file.lstat("file1").file?) assert(@zip_file.file.lstat('file1').file?)
end end
def test_pipe def test_pipe
@ -401,12 +401,12 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
end end
def test_foreach def test_foreach
::Zip::File.open("test/data/generated/zipWithDir.zip") do |zf| ::Zip::File.open('test/data/generated/zipWithDir.zip') do |zf|
ref = [] ref = []
File.foreach("test/data/file1.txt") { |e| ref << e } File.foreach('test/data/file1.txt') { |e| ref << e }
index = 0 index = 0
zf.file.foreach("test/data/file1.txt") do |l| zf.file.foreach('test/data/file1.txt') do |l|
#Ruby replaces \n with \r\n automatically on windows #Ruby replaces \n with \r\n automatically on windows
newline = Zip::RUNNING_ON_WINDOWS ? l.gsub(/\r\n/, "\n") : l newline = Zip::RUNNING_ON_WINDOWS ? l.gsub(/\r\n/, "\n") : l
assert_equal(ref[index], newline) assert_equal(ref[index], newline)
@ -415,12 +415,12 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
assert_equal(ref.size, index) assert_equal(ref.size, index)
end end
::Zip::File.open("test/data/generated/zipWithDir.zip") do |zf| ::Zip::File.open('test/data/generated/zipWithDir.zip') do |zf|
ref = [] ref = []
File.foreach("test/data/file1.txt", " ") { |e| ref << e } File.foreach('test/data/file1.txt', ' ') { |e| ref << e }
index = 0 index = 0
zf.file.foreach("test/data/file1.txt", " ") do |l| zf.file.foreach('test/data/file1.txt', ' ') do |l|
#Ruby replaces \n with \r\n automatically on windows #Ruby replaces \n with \r\n automatically on windows
newline = Zip::RUNNING_ON_WINDOWS ? l.gsub(/\r\n/, "\n") : l newline = Zip::RUNNING_ON_WINDOWS ? l.gsub(/\r\n/, "\n") : l
assert_equal(ref[index], newline) assert_equal(ref[index], newline)
@ -481,9 +481,9 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
# end # end
def test_readlines def test_readlines
::Zip::File.open("test/data/generated/zipWithDir.zip") do |zf| ::Zip::File.open('test/data/generated/zipWithDir.zip') do |zf|
orig_file = ::File.readlines("test/data/file1.txt") orig_file = ::File.readlines('test/data/file1.txt')
zip_file = zf.file.readlines("test/data/file1.txt") zip_file = zf.file.readlines('test/data/file1.txt')
#Ruby replaces \n with \r\n automatically on windows #Ruby replaces \n with \r\n automatically on windows
zip_file.each { |l| l.gsub!(/\r\n/, "\n") } if Zip::RUNNING_ON_WINDOWS zip_file.each { |l| l.gsub!(/\r\n/, "\n") } if Zip::RUNNING_ON_WINDOWS
@ -493,12 +493,12 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
end end
def test_read def test_read
::Zip::File.open("test/data/generated/zipWithDir.zip") do |zf| ::Zip::File.open('test/data/generated/zipWithDir.zip') do |zf|
orig_file = ::File.read("test/data/file1.txt") orig_file = ::File.read('test/data/file1.txt')
#Ruby replaces \n with \r\n automatically on windows #Ruby replaces \n with \r\n automatically on windows
zip_file = Zip::RUNNING_ON_WINDOWS ? \ zip_file = Zip::RUNNING_ON_WINDOWS ? \
zf.file.read("test/data/file1.txt").gsub(/\r\n/, "\n") : zf.file.read("test/data/file1.txt") zf.file.read('test/data/file1.txt').gsub(/\r\n/, "\n") : zf.file.read('test/data/file1.txt')
assert_equal(orig_file, zip_file) assert_equal(orig_file, zip_file)
end end
end end

View File

@ -3,7 +3,7 @@ require 'zip/filesystem'
class ZipFsFileStatTest < MiniTest::Test class ZipFsFileStatTest < MiniTest::Test
def setup def setup
@zip_file = ::Zip::File.new("test/data/zipWithDirs.zip") @zip_file = ::Zip::File.new('test/data/zipWithDirs.zip')
end end
def teardown def teardown
@ -11,54 +11,54 @@ class ZipFsFileStatTest < MiniTest::Test
end end
def test_blocks def test_blocks
assert_equal(nil, @zip_file.file.stat("file1").blocks) assert_equal(nil, @zip_file.file.stat('file1').blocks)
end end
def test_ino def test_ino
assert_equal(0, @zip_file.file.stat("file1").ino) assert_equal(0, @zip_file.file.stat('file1').ino)
end end
def test_uid def test_uid
assert_equal(0, @zip_file.file.stat("file1").uid) assert_equal(0, @zip_file.file.stat('file1').uid)
end end
def test_gid def test_gid
assert_equal(0, @zip_file.file.stat("file1").gid) assert_equal(0, @zip_file.file.stat('file1').gid)
end end
def test_ftype def test_ftype
assert_equal("file", @zip_file.file.stat("file1").ftype) assert_equal('file', @zip_file.file.stat('file1').ftype)
assert_equal("directory", @zip_file.file.stat("dir1").ftype) assert_equal('directory', @zip_file.file.stat('dir1').ftype)
end end
def test_mode def test_mode
assert_equal(0600, @zip_file.file.stat("file1").mode & 0777) assert_equal(0600, @zip_file.file.stat('file1').mode & 0777)
assert_equal(0600, @zip_file.file.stat("file1").mode & 0777) assert_equal(0600, @zip_file.file.stat('file1').mode & 0777)
assert_equal(0755, @zip_file.file.stat("dir1").mode & 0777) assert_equal(0755, @zip_file.file.stat('dir1').mode & 0777)
assert_equal(0755, @zip_file.file.stat("dir1").mode & 0777) assert_equal(0755, @zip_file.file.stat('dir1').mode & 0777)
end end
def test_dev def test_dev
assert_equal(0, @zip_file.file.stat("file1").dev) assert_equal(0, @zip_file.file.stat('file1').dev)
end end
def test_rdev def test_rdev
assert_equal(0, @zip_file.file.stat("file1").rdev) assert_equal(0, @zip_file.file.stat('file1').rdev)
end end
def test_rdev_major def test_rdev_major
assert_equal(0, @zip_file.file.stat("file1").rdev_major) assert_equal(0, @zip_file.file.stat('file1').rdev_major)
end end
def test_rdev_minor def test_rdev_minor
assert_equal(0, @zip_file.file.stat("file1").rdev_minor) assert_equal(0, @zip_file.file.stat('file1').rdev_minor)
end end
def test_nlink def test_nlink
assert_equal(1, @zip_file.file.stat("file1").nlink) assert_equal(1, @zip_file.file.stat('file1').nlink)
end end
def test_blksize def test_blksize
assert_nil(@zip_file.file.stat("file1").blksize) assert_nil(@zip_file.file.stat('file1').blksize)
end end
end end

View File

@ -3,13 +3,13 @@
$VERBOSE = true $VERBOSE = true
class TestFiles class TestFiles
RANDOM_ASCII_FILE1 = "test/data/generated/randomAscii1.txt" RANDOM_ASCII_FILE1 = 'test/data/generated/randomAscii1.txt'
RANDOM_ASCII_FILE2 = "test/data/generated/randomAscii2.txt" RANDOM_ASCII_FILE2 = 'test/data/generated/randomAscii2.txt'
RANDOM_ASCII_FILE3 = "test/data/generated/randomAscii3.txt" RANDOM_ASCII_FILE3 = 'test/data/generated/randomAscii3.txt'
RANDOM_BINARY_FILE1 = "test/data/generated/randomBinary1.bin" RANDOM_BINARY_FILE1 = 'test/data/generated/randomBinary1.bin'
RANDOM_BINARY_FILE2 = "test/data/generated/randomBinary2.bin" RANDOM_BINARY_FILE2 = 'test/data/generated/randomBinary2.bin'
EMPTY_TEST_DIR = "test/data/generated/emptytestdir" EMPTY_TEST_DIR = 'test/data/generated/emptytestdir'
ASCII_TEST_FILES = [RANDOM_ASCII_FILE1, RANDOM_ASCII_FILE2, RANDOM_ASCII_FILE3] ASCII_TEST_FILES = [RANDOM_ASCII_FILE1, RANDOM_ASCII_FILE2, RANDOM_ASCII_FILE3]
BINARY_TEST_FILES = [RANDOM_BINARY_FILE1, RANDOM_BINARY_FILE2] BINARY_TEST_FILES = [RANDOM_BINARY_FILE1, RANDOM_BINARY_FILE2]
@ -18,7 +18,7 @@ class TestFiles
class << self class << self
def create_test_files def create_test_files
Dir.mkdir "test/data/generated" unless Dir.exist?('test/data/generated') Dir.mkdir 'test/data/generated' unless Dir.exist?('test/data/generated')
ASCII_TEST_FILES.each_with_index do |filename, index| ASCII_TEST_FILES.each_with_index do |filename, index|
create_random_ascii(filename, 1E4 * (index+1)) create_random_ascii(filename, 1E4 * (index+1))
@ -34,14 +34,14 @@ class TestFiles
private private
def create_random_ascii(filename, size) def create_random_ascii(filename, size)
File.open(filename, "wb") do |file| File.open(filename, 'wb') do |file|
file << rand while (file.tell < size) file << rand while (file.tell < size)
end end
end end
def create_random_binary(filename, size) def create_random_binary(filename, size)
File.open(filename, "wb") do |file| File.open(filename, 'wb') do |file|
file << [rand].pack("V") while (file.tell < size) file << [rand].pack('V') while (file.tell < size)
end end
end end
@ -60,7 +60,7 @@ end
class TestZipFile class TestZipFile
attr_accessor :zip_name, :entry_names, :comment attr_accessor :zip_name, :entry_names, :comment
def initialize(zip_name, entry_names, comment = "") def initialize(zip_name, entry_names, comment = '')
@zip_name=zip_name @zip_name=zip_name
@entry_names=entry_names @entry_names=entry_names
@comment = comment @comment = comment
@ -70,22 +70,22 @@ class TestZipFile
raise "failed to create test zip '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP1.zip_name} test/data/file2.txt") raise "failed to create test zip '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP1.zip_name} test/data/file2.txt")
raise "failed to remove entry from '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP1.zip_name} -d test/data/file2.txt") raise "failed to remove entry from '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP1.zip_name} -d test/data/file2.txt")
File.open("test/data/generated/empty.txt", "w") {} File.open('test/data/generated/empty.txt', 'w') {}
File.open("test/data/generated/empty_chmod640.txt", "w") {} File.open('test/data/generated/empty_chmod640.txt', 'w') {}
::File.chmod(0640, "test/data/generated/empty_chmod640.txt") ::File.chmod(0640, 'test/data/generated/empty_chmod640.txt')
File.open("test/data/generated/short.txt", "w") { |file| file << "ABCDEF" } File.open('test/data/generated/short.txt', 'w') { |file| file << 'ABCDEF' }
ziptestTxt="" ziptestTxt=''
File.open("test/data/file2.txt") { |file| ziptestTxt=file.read } File.open('test/data/file2.txt') { |file| ziptestTxt=file.read }
File.open("test/data/generated/longAscii.txt", "w") do |file| File.open('test/data/generated/longAscii.txt', 'w') do |file|
file << ziptestTxt while (file.tell < 1E5) file << ziptestTxt while (file.tell < 1E5)
end end
testBinaryPattern="" testBinaryPattern=''
File.open("test/data/generated/empty.zip") { |file| testBinaryPattern=file.read } File.open('test/data/generated/empty.zip') { |file| testBinaryPattern=file.read }
testBinaryPattern *= 4 testBinaryPattern *= 4
File.open("test/data/generated/longBinary.bin", "wb") do |file| File.open('test/data/generated/longBinary.bin', 'wb') do |file|
file << testBinaryPattern << rand << "\0" while (file.tell < 6E5) file << testBinaryPattern << rand << "\0" while (file.tell < 6E5)
end end
@ -110,13 +110,13 @@ class TestZipFile
raise $!.to_s + raise $!.to_s +
"\n\nziptest.rb requires the Info-ZIP program 'zip' in the path\n" + "\n\nziptest.rb requires the Info-ZIP program 'zip' in the path\n" +
"to create test data. If you don't have it you can download\n" + "to create test data. If you don't have it you can download\n" +
"the necessary test files at http://sf.net/projects/rubyzip." 'the necessary test files at http://sf.net/projects/rubyzip.'
end end
TEST_ZIP1 = TestZipFile.new("test/data/generated/empty.zip", []) TEST_ZIP1 = TestZipFile.new('test/data/generated/empty.zip', [])
TEST_ZIP2 = TestZipFile.new("test/data/generated/5entry.zip", %w{ test/data/generated/longAscii.txt test/data/generated/empty.txt test/data/generated/empty_chmod640.txt test/data/generated/short.txt test/data/generated/longBinary.bin}, TEST_ZIP2 = TestZipFile.new('test/data/generated/5entry.zip', %w{ test/data/generated/longAscii.txt test/data/generated/empty.txt test/data/generated/empty_chmod640.txt test/data/generated/short.txt test/data/generated/longBinary.bin},
"my zip comment") 'my zip comment')
TEST_ZIP3 = TestZipFile.new("test/data/generated/test1.zip", %w{ test/data/file1.txt }) TEST_ZIP3 = TestZipFile.new('test/data/generated/test1.zip', %w{ test/data/file1.txt })
TEST_ZIP4 = TestZipFile.new("test/data/generated/zipWithDir.zip", ["test/data/file1.txt", TEST_ZIP4 = TestZipFile.new('test/data/generated/zipWithDir.zip', ['test/data/file1.txt',
TestFiles::EMPTY_TEST_DIR]) TestFiles::EMPTY_TEST_DIR])
end end

View File

@ -4,7 +4,7 @@ class InflaterTest < MiniTest::Test
def setup def setup
super super
@file = File.new("test/data/file1.txt.deflatedData", "rb") @file = File.new('test/data/file1.txt.deflatedData', 'rb')
@decompressor = ::Zip::Inflater.new(@file) @decompressor = ::Zip::Inflater.new(@file)
end end

View File

@ -19,12 +19,12 @@ class ZipInputStreamTest < MiniTest::Test
end end
def test_openWithoutBlock def test_openWithoutBlock
zis = ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, "rb")) zis = ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, 'rb'))
assert_stream_contents(zis, TestZipFile::TEST_ZIP2) assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
end end
def test_openBufferWithBlock def test_openBufferWithBlock
::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, "rb")) do |zis| ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, 'rb')) do |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
@ -120,19 +120,19 @@ class ZipInputStreamTest < MiniTest::Test
assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], e.name) assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], e.name)
# Do a little reading # Do a little reading
buf = "" buf = ''
buf << zis.read(100) buf << zis.read(100)
assert_equal(100, zis.pos) assert_equal(100, zis.pos)
buf << (zis.gets || "") buf << (zis.gets || '')
buf << (zis.gets || "") buf << (zis.gets || '')
assert_equal(false, zis.eof?) assert_equal(false, zis.eof?)
zis.rewind zis.rewind
buf2 = "" buf2 = ''
buf2 << zis.read(100) buf2 << zis.read(100)
buf2 << (zis.gets || "") buf2 << (zis.gets || '')
buf2 << (zis.gets || "") buf2 << (zis.gets || '')
assert_equal(buf, buf2) assert_equal(buf, buf2)
@ -148,11 +148,11 @@ class ZipInputStreamTest < MiniTest::Test
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do ::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)
assert_equal(false, zis.eof?) assert_equal(false, zis.eof?)
assert_equal("", zis.gets.chomp) assert_equal('', zis.gets.chomp)
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 end
@ -163,7 +163,7 @@ class ZipInputStreamTest < MiniTest::Test
first_line = zis.gets.chomp first_line = zis.gets.chomp
first_line.reverse.bytes.each { |b| zis.ungetc(b) } first_line.reverse.bytes.each { |b| zis.ungetc(b) }
assert_equal('#!/usr/bin/env ruby', zis.gets.chomp) assert_equal('#!/usr/bin/env ruby', zis.gets.chomp)
assert_equal("$VERBOSE =", zis.read(10)) assert_equal('$VERBOSE =', zis.read(10))
end end
end end
end end

View File

@ -6,7 +6,7 @@ class AbstractInputStreamTest < MiniTest::Test
TEST_LINES = ["Hello world#{$/}", TEST_LINES = ["Hello world#{$/}",
"this is the second line#{$/}", "this is the second line#{$/}",
"this is the last line"] 'this is the last line']
TEST_STRING = TEST_LINES.join TEST_STRING = TEST_LINES.join
class TestAbstractInputStream class TestAbstractInputStream
include ::Zip::IOExtras::AbstractInputStream include ::Zip::IOExtras::AbstractInputStream
@ -49,8 +49,8 @@ class AbstractInputStreamTest < MiniTest::Test
end end
def test_getsMultiCharSeperator def test_getsMultiCharSeperator
assert_equal("Hell", @io.gets("ll")) assert_equal('Hell', @io.gets('ll'))
assert_equal("o world#{$/}this is the second l", @io.gets("d l")) assert_equal("o world#{$/}this is the second l", @io.gets('d l'))
end end
LONG_LINES = [ LONG_LINES = [
@ -95,7 +95,7 @@ class AbstractInputStreamTest < MiniTest::Test
test_gets test_gets
begin begin
@io.readline @io.readline
fail "EOFError expected" fail 'EOFError expected'
rescue EOFError rescue EOFError
end end
end end

View File

@ -8,7 +8,7 @@ class AbstractOutputStreamTest < MiniTest::Test
attr_accessor :buffer attr_accessor :buffer
def initialize def initialize
@buffer = "" @buffer = ''
end end
def << (data) def << (data)
@ -30,77 +30,77 @@ class AbstractOutputStreamTest < MiniTest::Test
end end
def test_write def test_write
count = @output_stream.write("a little string") count = @output_stream.write('a little string')
assert_equal("a little string", @output_stream.buffer) assert_equal('a little string', @output_stream.buffer)
assert_equal("a little string".length, count) assert_equal('a little string'.length, count)
count = @output_stream.write(". a little more") count = @output_stream.write('. a little more')
assert_equal("a little string. a little more", @output_stream.buffer) assert_equal('a little string. a little more', @output_stream.buffer)
assert_equal(". a little more".length, count) assert_equal('. a little more'.length, count)
end end
def test_print def test_print
$\ = nil # record separator set to nil $\ = nil # record separator set to nil
@output_stream.print("hello") @output_stream.print('hello')
assert_equal("hello", @output_stream.buffer) assert_equal('hello', @output_stream.buffer)
@output_stream.print(" world.") @output_stream.print(' world.')
assert_equal("hello world.", @output_stream.buffer) assert_equal('hello world.', @output_stream.buffer)
@output_stream.print(" You ok ", "out ", "there?") @output_stream.print(' You ok ', 'out ', 'there?')
assert_equal("hello world. You ok out there?", @output_stream.buffer) assert_equal('hello world. You ok out there?', @output_stream.buffer)
$\ = "\n" $\ = "\n"
@output_stream.print @output_stream.print
assert_equal("hello world. You ok out there?\n", @output_stream.buffer) assert_equal("hello world. You ok out there?\n", @output_stream.buffer)
@output_stream.print("I sure hope so!") @output_stream.print('I sure hope so!')
assert_equal("hello world. You ok out there?\nI sure hope so!\n", @output_stream.buffer) assert_equal("hello world. You ok out there?\nI sure hope so!\n", @output_stream.buffer)
$, = "X" $, = 'X'
@output_stream.buffer = "" @output_stream.buffer = ''
@output_stream.print("monkey", "duck", "zebra") @output_stream.print('monkey', 'duck', 'zebra')
assert_equal("monkeyXduckXzebra\n", @output_stream.buffer) assert_equal("monkeyXduckXzebra\n", @output_stream.buffer)
$\ = nil $\ = nil
@output_stream.buffer = "" @output_stream.buffer = ''
@output_stream.print(20) @output_stream.print(20)
assert_equal("20", @output_stream.buffer) assert_equal('20', @output_stream.buffer)
end end
def test_printf def test_printf
@output_stream.printf("%d %04x", 123, 123) @output_stream.printf('%d %04x', 123, 123)
assert_equal("123 007b", @output_stream.buffer) assert_equal('123 007b', @output_stream.buffer)
end end
def test_putc def test_putc
@output_stream.putc("A") @output_stream.putc('A')
assert_equal("A", @output_stream.buffer) assert_equal('A', @output_stream.buffer)
@output_stream.putc(65) @output_stream.putc(65)
assert_equal("AA", @output_stream.buffer) assert_equal('AA', @output_stream.buffer)
end end
def test_puts def test_puts
@output_stream.puts @output_stream.puts
assert_equal("\n", @output_stream.buffer) assert_equal("\n", @output_stream.buffer)
@output_stream.puts("hello", "world") @output_stream.puts('hello', 'world')
assert_equal("\nhello\nworld\n", @output_stream.buffer) assert_equal("\nhello\nworld\n", @output_stream.buffer)
@output_stream.buffer = "" @output_stream.buffer = ''
@output_stream.puts("hello\n", "world\n") @output_stream.puts("hello\n", "world\n")
assert_equal("hello\nworld\n", @output_stream.buffer) assert_equal("hello\nworld\n", @output_stream.buffer)
@output_stream.buffer = "" @output_stream.buffer = ''
@output_stream.puts(["hello\n", "world\n"]) @output_stream.puts(["hello\n", "world\n"])
assert_equal("hello\nworld\n", @output_stream.buffer) assert_equal("hello\nworld\n", @output_stream.buffer)
@output_stream.buffer = "" @output_stream.buffer = ''
@output_stream.puts(["hello\n", "world\n"], "bingo") @output_stream.puts(["hello\n", "world\n"], 'bingo')
assert_equal("hello\nworld\nbingo\n", @output_stream.buffer) assert_equal("hello\nworld\nbingo\n", @output_stream.buffer)
@output_stream.buffer = "" @output_stream.buffer = ''
@output_stream.puts(16, 20, 50, "hello") @output_stream.puts(16, 20, 50, 'hello')
assert_equal("16\n20\n50\nhello\n", @output_stream.buffer) assert_equal("16\n20\n50\nhello\n", @output_stream.buffer)
end end
end end

View File

@ -9,7 +9,7 @@ class ZipLocalEntryTest < MiniTest::Test
end end
def test_read_local_entryHeaderOfFirstTestZipEntry def test_read_local_entryHeaderOfFirstTestZipEntry
::File.open(TestZipFile::TEST_ZIP3.zip_name, "rb") do |file| ::File.open(TestZipFile::TEST_ZIP3.zip_name, 'rb') do |file|
entry = ::Zip::Entry.read_local_entry(file) entry = ::Zip::Entry.read_local_entry(file)
assert_equal('', entry.comment) assert_equal('', entry.comment)
@ -27,34 +27,34 @@ class ZipLocalEntryTest < MiniTest::Test
end end
def test_readDateTime def test_readDateTime
::File.open("test/data/rubycode.zip", "rb") do ::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 end
def test_read_local_entryFromNonZipFile def test_read_local_entryFromNonZipFile
::File.open("test/data/file2.txt") do ::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 end
def test_read_local_entryFromTruncatedZipFile def test_read_local_entryFromTruncatedZipFile
zipFragment="" zipFragment=''
::File.open(TestZipFile::TEST_ZIP2.zip_name) { |f| zipFragment = f.read(12) } # local header is at least 30 bytes ::File.open(TestZipFile::TEST_ZIP2.zip_name) { |f| zipFragment = f.read(12) } # local header is at least 30 bytes
zipFragment.extend(IOizeString).reset zipFragment.extend(IOizeString).reset
entry = ::Zip::Entry.new entry = ::Zip::Entry.new
entry.read_local_entry(zipFragment) entry.read_local_entry(zipFragment)
fail "ZipError expected" fail 'ZipError expected'
rescue ::Zip::Error rescue ::Zip::Error
end end
def test_writeEntry def test_writeEntry
entry = ::Zip::Entry.new("file.zip", "entryName", "my little comment", entry = ::Zip::Entry.new('file.zip', 'entryName', 'my little comment',
"thisIsSomeExtraInformation", 100, 987654, 'thisIsSomeExtraInformation', 100, 987654,
::Zip::Entry::DEFLATED, 400) ::Zip::Entry::DEFLATED, 400)
write_to_file(LEH_FILE, CEH_FILE, entry) write_to_file(LEH_FILE, CEH_FILE, entry)
entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE) entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE)
@ -65,8 +65,8 @@ class ZipLocalEntryTest < MiniTest::Test
def test_writeEntryWithZip64 def test_writeEntryWithZip64
::Zip.write_zip64_support = true ::Zip.write_zip64_support = true
entry = ::Zip::Entry.new("file.zip", "entryName", "my little comment", entry = ::Zip::Entry.new('file.zip', 'entryName', 'my little comment',
"thisIsSomeExtraInformation", 100, 987654, 'thisIsSomeExtraInformation', 100, 987654,
::Zip::Entry::DEFLATED, 400) ::Zip::Entry::DEFLATED, 400)
write_to_file(LEH_FILE, CEH_FILE, entry) write_to_file(LEH_FILE, CEH_FILE, entry)
entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE) entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE)
@ -79,8 +79,8 @@ class ZipLocalEntryTest < MiniTest::Test
def test_write64Entry def test_write64Entry
::Zip.write_zip64_support = true ::Zip.write_zip64_support = true
entry = ::Zip::Entry.new("bigfile.zip", "entryName", "my little equine", entry = ::Zip::Entry.new('bigfile.zip', 'entryName', 'my little equine',
"malformed extra field because why not", 'malformed extra field because why not',
0x7766554433221100, 0xDEADBEEF, ::Zip::Entry::DEFLATED, 0x7766554433221100, 0xDEADBEEF, ::Zip::Entry::DEFLATED,
0x9988776655443322) 0x9988776655443322)
write_to_file(LEH_FILE, CEH_FILE, entry) write_to_file(LEH_FILE, CEH_FILE, entry)
@ -92,9 +92,9 @@ class ZipLocalEntryTest < MiniTest::Test
def test_rewriteLocalHeader64 def test_rewriteLocalHeader64
::Zip.write_zip64_support = true ::Zip.write_zip64_support = true
buf1 = StringIO.new buf1 = StringIO.new
entry = ::Zip::Entry.new("file.zip", "entryName") entry = ::Zip::Entry.new('file.zip', 'entryName')
entry.write_local_entry(buf1) entry.write_local_entry(buf1)
assert(entry.extra['Zip64'].nil?, "zip64 extra is unnecessarily present") assert(entry.extra['Zip64'].nil?, 'zip64 extra is unnecessarily present')
buf2 = StringIO.new buf2 = StringIO.new
entry.size = 0x123456789ABCDEF0 entry.size = 0x123456789ABCDEF0
@ -106,7 +106,7 @@ class ZipLocalEntryTest < MiniTest::Test
end end
def test_readLocalOffset def test_readLocalOffset
entry = ::Zip::Entry.new("file.zip", "entryName") entry = ::Zip::Entry.new('file.zip', 'entryName')
entry.local_header_offset = 12345 entry.local_header_offset = 12345
::File.open(CEH_FILE, 'wb') { |f| entry.write_c_dir_entry(f) } ::File.open(CEH_FILE, 'wb') { |f| entry.write_c_dir_entry(f) }
read_entry = nil read_entry = nil
@ -116,7 +116,7 @@ class ZipLocalEntryTest < MiniTest::Test
def test_read64LocalOffset def test_read64LocalOffset
::Zip.write_zip64_support = true ::Zip.write_zip64_support = true
entry = ::Zip::Entry.new("file.zip", "entryName") entry = ::Zip::Entry.new('file.zip', 'entryName')
entry.local_header_offset = 0x0123456789ABCDEF entry.local_header_offset = 0x0123456789ABCDEF
::File.open(CEH_FILE, 'wb') { |f| entry.write_c_dir_entry(f) } ::File.open(CEH_FILE, 'wb') { |f| entry.write_c_dir_entry(f) }
read_entry = nil read_entry = nil
@ -142,15 +142,15 @@ class ZipLocalEntryTest < MiniTest::Test
end end
def write_to_file(localFileName, centralFileName, entry) def write_to_file(localFileName, centralFileName, entry)
::File.open(localFileName, "wb") { |f| entry.write_local_entry(f) } ::File.open(localFileName, 'wb') { |f| entry.write_local_entry(f) }
::File.open(centralFileName, "wb") { |f| entry.write_c_dir_entry(f) } ::File.open(centralFileName, 'wb') { |f| entry.write_c_dir_entry(f) }
end end
def read_from_file(localFileName, centralFileName) def read_from_file(localFileName, centralFileName)
localEntry = nil localEntry = nil
cdirEntry = nil cdirEntry = nil
::File.open(localFileName, "rb") { |f| localEntry = ::Zip::Entry.read_local_entry(f) } ::File.open(localFileName, 'rb') { |f| localEntry = ::Zip::Entry.read_local_entry(f) }
::File.open(centralFileName, "rb") { |f| cdirEntry = ::Zip::Entry.read_c_dir_entry(f) } ::File.open(centralFileName, 'rb') { |f| cdirEntry = ::Zip::Entry.read_c_dir_entry(f) }
[localEntry, cdirEntry] [localEntry, cdirEntry]
end end
end end

View File

@ -4,7 +4,7 @@ class ZipOutputStreamTest < MiniTest::Test
include AssertEntry include AssertEntry
TEST_ZIP = TestZipFile::TEST_ZIP2.clone TEST_ZIP = TestZipFile::TEST_ZIP2.clone
TEST_ZIP.zip_name = "test/data/generated/output.zip" TEST_ZIP.zip_name = 'test/data/generated/output.zip'
def test_new def test_new
zos = ::Zip::OutputStream.new(TEST_ZIP.zip_name) zos = ::Zip::OutputStream.new(TEST_ZIP.zip_name)
@ -48,9 +48,9 @@ class ZipOutputStreamTest < MiniTest::Test
end end
def test_writingToClosedStream def test_writingToClosedStream
assert_i_o_error_in_closed_stream { |zos| zos << "hello world" } assert_i_o_error_in_closed_stream { |zos| zos << 'hello world' }
assert_i_o_error_in_closed_stream { |zos| zos.puts "hello world" } assert_i_o_error_in_closed_stream { |zos| zos.puts 'hello world' }
assert_i_o_error_in_closed_stream { |zos| zos.write "hello world" } assert_i_o_error_in_closed_stream { |zos| zos.write 'hello world' }
end end
def test_cannotOpenFile def test_cannotOpenFile
@ -66,9 +66,9 @@ class ZipOutputStreamTest < MiniTest::Test
end end
def test_put_next_entry def test_put_next_entry
stored_text = "hello world in stored text" stored_text = 'hello world in stored text'
entry_name = "file1" entry_name = 'file1'
comment = "my comment" comment = 'my comment'
::Zip::OutputStream.open(TEST_ZIP.zip_name) do |zos| ::Zip::OutputStream.open(TEST_ZIP.zip_name) do |zos|
zos.put_next_entry(entry_name, comment, nil, ::Zip::Entry::STORED) zos.put_next_entry(entry_name, comment, nil, ::Zip::Entry::STORED)
zos << stored_text zos << stored_text
@ -81,9 +81,9 @@ class ZipOutputStreamTest < MiniTest::Test
end end
def test_put_next_entry_using_zip_entry_creates_entries_with_correct_timestamps def test_put_next_entry_using_zip_entry_creates_entries_with_correct_timestamps
file = ::File.open("test/data/file2.txt", "rb") file = ::File.open('test/data/file2.txt', 'rb')
::Zip::OutputStream.open(TEST_ZIP.zip_name) do |zos| ::Zip::OutputStream.open(TEST_ZIP.zip_name) do |zos|
zip_entry = ::Zip::Entry.new(zos, file.path, "", "", 0, 0, ::Zip::Entry::DEFLATED, 0, ::Zip::DOSTime.at(file.mtime)) zip_entry = ::Zip::Entry.new(zos, file.path, '', '', 0, 0, ::Zip::Entry::DEFLATED, 0, ::Zip::DOSTime.at(file.mtime))
zos.put_next_entry(zip_entry) zos.put_next_entry(zip_entry)
zos << file.read zos << file.read
end end
@ -96,10 +96,10 @@ class ZipOutputStreamTest < MiniTest::Test
end end
def test_chained_put_into_next_entry def test_chained_put_into_next_entry
stored_text = "hello world in stored text" stored_text = 'hello world in stored text'
stored_text2 = "with chain" stored_text2 = 'with chain'
entry_name = "file1" entry_name = 'file1'
comment = "my comment" comment = 'my comment'
::Zip::OutputStream.open(TEST_ZIP.zip_name) do |zos| ::Zip::OutputStream.open(TEST_ZIP.zip_name) do |zos|
zos.put_next_entry(entry_name, comment, nil, ::Zip::Entry::STORED) zos.put_next_entry(entry_name, comment, nil, ::Zip::Entry::STORED)
zos << stored_text << stored_text2 zos << stored_text << stored_text2
@ -113,7 +113,7 @@ class ZipOutputStreamTest < MiniTest::Test
def assert_i_o_error_in_closed_stream def assert_i_o_error_in_closed_stream
assert_raises(IOError) do 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
@ -122,7 +122,7 @@ class ZipOutputStreamTest < MiniTest::Test
def write_test_zip(zos) def write_test_zip(zos)
TEST_ZIP.entry_names.each do |entryName| TEST_ZIP.entry_names.each do |entryName|
zos.put_next_entry(entryName) zos.put_next_entry(entryName)
File.open(entryName, "rb") { |f| zos.write(f.read) } File.open(entryName, 'rb') { |f| zos.write(f.read) }
end end
end end
end end

View File

@ -4,14 +4,14 @@ class PassThruCompressorTest < MiniTest::Test
include CrcTest include CrcTest
def test_size def test_size
File.open("test/data/generated/dummy.txt", "wb") do |file| File.open('test/data/generated/dummy.txt', 'wb') do |file|
compressor = ::Zip::PassThruCompressor.new(file) compressor = ::Zip::PassThruCompressor.new(file)
assert_equal(0, compressor.size) assert_equal(0, compressor.size)
t1 = "hello world" t1 = 'hello world'
t2 = "" t2 = ''
t3 = "bingo" t3 = 'bingo'
compressor << t1 compressor << t1
assert_equal(compressor.size, t1.size) assert_equal(compressor.size, t1.size)

View File

@ -4,7 +4,7 @@ class ZipSettingsTest < MiniTest::Test
# TODO Refactor out into common test module # TODO Refactor out into common test module
include CommonZipFileFixture include CommonZipFileFixture
TEST_OUT_NAME = "test/data/generated/emptyOutDir" TEST_OUT_NAME = 'test/data/generated/emptyOutDir'
def setup def setup
super super
@ -30,14 +30,14 @@ class ZipSettingsTest < MiniTest::Test
def test_true_on_exists_proc def test_true_on_exists_proc
Zip.on_exists_proc = true Zip.on_exists_proc = true
File.open(TEST_OUT_NAME, "w") { |f| f.puts "something" } File.open(TEST_OUT_NAME, 'w') { |f| f.puts 'something' }
extract_test_dir extract_test_dir
assert(File.directory?(TEST_OUT_NAME)) assert(File.directory?(TEST_OUT_NAME))
end end
def test_false_on_exists_proc def test_false_on_exists_proc
Zip.on_exists_proc = false Zip.on_exists_proc = false
File.open(TEST_OUT_NAME, "w") { |f| f.puts "something" } File.open(TEST_OUT_NAME, 'w') { |f| f.puts 'something' }
assert_raises(Zip::DestinationFileExistsError) { extract_test_dir } assert_raises(Zip::DestinationFileExistsError) { extract_test_dir }
end end
@ -46,7 +46,7 @@ class ZipSettingsTest < MiniTest::Test
assert_raises(::Zip::EntryExistsError) do assert_raises(::Zip::EntryExistsError) do
::Zip::File.open(TEST_ZIP.zip_name) do |zf| ::Zip::File.open(TEST_ZIP.zip_name) do |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
end end
@ -58,11 +58,11 @@ class ZipSettingsTest < MiniTest::Test
::Zip::File.open(TEST_ZIP.zip_name) do |zf| ::Zip::File.open(TEST_ZIP.zip_name) do |zf|
replacedEntry = zf.entries.first.name replacedEntry = zf.entries.first.name
zf.add(replacedEntry, "test/data/file2.txt") zf.add(replacedEntry, 'test/data/file2.txt')
end end
::Zip::File.open(TEST_ZIP.zip_name) do |zf| ::Zip::File.open(TEST_ZIP.zip_name) do |zf|
assert_contains(zf, replacedEntry, "test/data/file2.txt") assert_contains(zf, replacedEntry, 'test/data/file2.txt')
end end
end end

View File

@ -34,7 +34,7 @@ module IOizeString
when IO::SEEK_CUR when IO::SEEK_CUR
newPos = @tell + index newPos = @tell + index
else else
raise "Error in test method IOizeString::seek" raise 'Error in test method IOizeString::seek'
end end
if (newPos < 0 || newPos >= size) if (newPos < 0 || newPos >= size)
raise Errno::EINVAL raise Errno::EINVAL
@ -51,7 +51,7 @@ end
module DecompressorTests module DecompressorTests
# expects @refText, @refLines and @decompressor # expects @refText, @refLines and @decompressor
TEST_FILE = "test/data/file1.txt" TEST_FILE = 'test/data/file1.txt'
def setup def setup
@refText = '' @refText = ''
@ -95,13 +95,13 @@ module AssertEntry
end end
def assert_entryContentsForStream(filename, zis, entryName) def assert_entryContentsForStream(filename, zis, entryName)
File.open(filename, "rb") do |file| File.open(filename, 'rb') do |file|
expected = file.read expected = file.read
actual = zis.read actual = zis.read
if (expected != actual) if (expected != actual)
if ((expected && actual) && (expected.length > 400 || actual.length > 400)) if ((expected && actual) && (expected.length > 400 || actual.length > 400))
zipEntryFilename=entryName+".zipEntry" zipEntryFilename=entryName+'.zipEntry'
File.open(zipEntryFilename, "wb") { |entryfile| entryfile << actual } File.open(zipEntryFilename, 'wb') { |entryfile| entryfile << actual }
fail("File '#{filename}' is different from '#{zipEntryFilename}'") fail("File '#{filename}' is different from '#{zipEntryFilename}'")
else else
assert_equal(expected, actual) assert_equal(expected, actual)
@ -111,12 +111,12 @@ module AssertEntry
end end
def AssertEntry.assert_contents(filename, aString) def AssertEntry.assert_contents(filename, aString)
fileContents = "" fileContents = ''
File.open(filename, "rb") { |f| fileContents = f.read } File.open(filename, 'rb') { |f| fileContents = f.read }
if (fileContents != aString) if (fileContents != aString)
if (fileContents.length > 400 || aString.length > 400) if (fileContents.length > 400 || aString.length > 400)
stringFile = filename + ".other" stringFile = filename + '.other'
File.open(stringFile, "wb") { |f| f << aString } File.open(stringFile, 'wb') { |f| f << aString }
fail("File '#{filename}' is different from contents of string stored in '#{stringFile}'") fail("File '#{filename}' is different from contents of string stored in '#{stringFile}'")
else else
assert_equal(fileContents, aString) assert_equal(fileContents, aString)
@ -153,7 +153,7 @@ module CrcTest
attr_accessor :buffer attr_accessor :buffer
def initialize def initialize
@buffer = "" @buffer = ''
end end
def << (data) def << (data)
@ -185,10 +185,10 @@ end
module CommonZipFileFixture module CommonZipFileFixture
include AssertEntry include AssertEntry
EMPTY_FILENAME = "emptyZipFile.zip" EMPTY_FILENAME = 'emptyZipFile.zip'
TEST_ZIP = TestZipFile::TEST_ZIP2.clone TEST_ZIP = TestZipFile::TEST_ZIP2.clone
TEST_ZIP.zip_name = "test/data/generated/5entry_copy.zip" TEST_ZIP.zip_name = 'test/data/generated/5entry_copy.zip'
def setup def setup
File.delete(EMPTY_FILENAME) if File.exist?(EMPTY_FILENAME) File.delete(EMPTY_FILENAME) if File.exist?(EMPTY_FILENAME)

View File

@ -3,11 +3,11 @@
require 'test_helper' require 'test_helper'
class ZipUnicodeFileNamesAndComments < MiniTest::Test class ZipUnicodeFileNamesAndComments < MiniTest::Test
FILENAME = File.join(File.dirname(__FILE__), "test1.zip") FILENAME = File.join(File.dirname(__FILE__), 'test1.zip')
def test_unicode_file_name def test_unicode_file_name
file_entrys = ["текстовыйфайл.txt", "Résumé.txt", "슬레이어스휘.txt"] file_entrys = ['текстовыйфайл.txt', 'Résumé.txt', '슬레이어스휘.txt']
directory_entrys = ["папка/текстовыйфайл.txt", "Résumé/Résumé.txt", "슬레이어스휘/슬레이어스휘.txt"] directory_entrys = ['папка/текстовыйфайл.txt', 'Résumé/Résumé.txt', '슬레이어스휘/슬레이어스휘.txt']
stream = ::Zip::OutputStream.open(FILENAME) do |io| stream = ::Zip::OutputStream.open(FILENAME) do |io|
file_entrys.each do |filename| file_entrys.each do |filename|
io.put_next_entry(filename) io.put_next_entry(filename)
@ -23,13 +23,13 @@ class ZipUnicodeFileNamesAndComments < MiniTest::Test
file_entrys.each do |filename| file_entrys.each do |filename|
entry = io.get_next_entry entry = io.get_next_entry
entry_name = entry.name entry_name = entry.name
entry_name = entry_name.force_encoding("UTF-8") entry_name = entry_name.force_encoding('UTF-8')
assert(filename == entry_name) assert(filename == entry_name)
end end
directory_entrys.each do |filepath| directory_entrys.each do |filepath|
entry = io.get_next_entry entry = io.get_next_entry
entry_name = entry.name entry_name = entry.name
entry_name = entry_name.force_encoding("UTF-8") entry_name = entry_name.force_encoding('UTF-8')
assert(filepath == entry_name) assert(filepath == entry_name)
end end
end end

View File

@ -44,7 +44,7 @@ if ENV['FULL_ZIP64_TEST']
# note: if this fails, be sure you have UnZip version 6.0 or newer # note: if this fails, be sure you have UnZip version 6.0 or newer
# as this is the first version to support zip64 extensions # as this is the first version to support zip64 extensions
# but some OSes (*cough* OSX) still bundle a 5.xx release # but some OSes (*cough* OSX) still bundle a 5.xx release
assert system("unzip -t #{test_filename}"), "third-party zip validation failed" assert system("unzip -t #{test_filename}"), 'third-party zip validation failed'
end end
end end