fix rubocop Style/MethodName cop
This commit is contained in:
parent
b1bfb1a216
commit
23cfcc73b5
|
@ -160,11 +160,6 @@ Style/IfUnlessModifier:
|
||||||
Style/InfiniteLoop:
|
Style/InfiniteLoop:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
# Offense count: 58
|
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
||||||
Style/MethodName:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
Style/ModuleFunction:
|
Style/ModuleFunction:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
|
@ -86,12 +86,12 @@ class ZipFileGenerator
|
||||||
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)
|
write_entries(entries, "", io)
|
||||||
io.close();
|
io.close();
|
||||||
end
|
end
|
||||||
# A helper method to make the recursion work.
|
# A helper method to make the recursion work.
|
||||||
private
|
private
|
||||||
def writeEntries(entries, path, io)
|
def write_entries(entries, path, io)
|
||||||
entries.each { |e|
|
entries.each { |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)
|
||||||
|
@ -99,7 +99,7 @@ class ZipFileGenerator
|
||||||
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)
|
write_entries(subdir, zipFilePath, io)
|
||||||
else
|
else
|
||||||
io.get_output_stream(zipFilePath) { |f| f.print(File.open(diskFilePath, "rb").read())}
|
io.get_output_stream(zipFilePath) { |f| f.print(File.open(diskFilePath, "rb").read())}
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,7 +24,7 @@ class ZipFileGenerator
|
||||||
entries.delete('..')
|
entries.delete('..')
|
||||||
io = Zip::File.open(@outputFile, Zip::File::CREATE)
|
io = Zip::File.open(@outputFile, Zip::File::CREATE)
|
||||||
|
|
||||||
writeEntries(entries, '', io)
|
write_entries(entries, '', io)
|
||||||
io.close
|
io.close
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class ZipFileGenerator
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def writeEntries(entries, path, io)
|
def write_entries(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)
|
||||||
|
@ -42,7 +42,7 @@ class ZipFileGenerator
|
||||||
subdir = Dir.entries(diskFilePath)
|
subdir = Dir.entries(diskFilePath)
|
||||||
subdir.delete('.')
|
subdir.delete('.')
|
||||||
subdir.delete('..')
|
subdir.delete('..')
|
||||||
writeEntries(subdir, zipFilePath, io)
|
write_entries(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
|
||||||
|
|
|
@ -49,12 +49,12 @@ class BasicZipFileTest < MiniTest::Test
|
||||||
assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_get_input_streamBlock
|
def test_get_input_stream_block
|
||||||
fileAndEntryName = @zip_file.entries.first.name
|
fileAndEntryName = @zip_file.entries.first.name
|
||||||
@zip_file.get_input_stream(fileAndEntryName) do |zis|
|
@zip_file.get_input_stream(fileAndEntryName) do |zis|
|
||||||
assert_entryContentsForStream(fileAndEntryName,
|
assert_entry_contents_for_stream(fileAndEntryName,
|
||||||
zis,
|
zis,
|
||||||
fileAndEntryName)
|
fileAndEntryName)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -65,6 +65,6 @@ class ZipFileTest < MiniTest::Test
|
||||||
private
|
private
|
||||||
def assert_contains(zf, entryName, filename = entryName)
|
def assert_contains(zf, entryName, filename = entryName)
|
||||||
assert(zf.entries.detect { |e| e.name == entryName } != nil, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}")
|
assert(zf.entries.detect { |e| e.name == entryName } != nil, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}")
|
||||||
assert_entryContents(zf, entryName, filename) if File.exist?(filename)
|
assert_entry_contents(zf, entryName, filename) if File.exist?(filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -57,7 +57,7 @@ class ZipCentralDirectoryEntryTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ReadEntryFromTruncatedZipFile
|
def test_read_entry_from_truncated_zip_file
|
||||||
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)
|
||||||
|
|
|
@ -17,7 +17,7 @@ class ZipCentralDirectoryTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_readFromInvalidStream
|
def test_read_from_invalid_stream
|
||||||
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)
|
||||||
|
@ -26,7 +26,7 @@ class ZipCentralDirectoryTest < MiniTest::Test
|
||||||
rescue ::Zip::Error
|
rescue ::Zip::Error
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ReadFromTruncatedZipFile
|
def test_read_from_truncated_zip_file
|
||||||
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
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
class NotZippedRuby
|
class NotZippedRuby
|
||||||
def returnTrue
|
def return_true
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,7 @@ class DeflaterTest < MiniTest::Test
|
||||||
DEFAULT_COMP_FILE = 'test/data/generated/compressiontest_default_compression.bin'
|
DEFAULT_COMP_FILE = 'test/data/generated/compressiontest_default_compression.bin'
|
||||||
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_output_operator
|
||||||
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)
|
||||||
|
|
|
@ -12,7 +12,7 @@ class ZipEntryTest < MiniTest::Test
|
||||||
TEST_ISDIRECTORY = false
|
TEST_ISDIRECTORY = false
|
||||||
TEST_TIME = Time.now
|
TEST_TIME = Time.now
|
||||||
|
|
||||||
def test_constructorAndGetters
|
def test_constructor_and_getters
|
||||||
entry = ::Zip::Entry.new(TEST_ZIPFILE,
|
entry = ::Zip::Entry.new(TEST_ZIPFILE,
|
||||||
TEST_NAME,
|
TEST_NAME,
|
||||||
TEST_COMMENT,
|
TEST_COMMENT,
|
||||||
|
@ -33,7 +33,7 @@ class ZipEntryTest < MiniTest::Test
|
||||||
assert_equal(TEST_TIME, entry.time)
|
assert_equal(TEST_TIME, entry.time)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_is_directoryAndIsFile
|
def test_is_directory_and_is_file
|
||||||
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?)
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ class ZipEntryTest < MiniTest::Test
|
||||||
assert_equal('5', entries[5].to_s)
|
assert_equal('5', entries[5].to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_parentAsString
|
def test_parent_as_string
|
||||||
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')
|
||||||
|
|
|
@ -23,23 +23,23 @@ class ZipFileExtractDirectoryTest < MiniTest::Test
|
||||||
File.delete(TEST_OUT_NAME) if File.exist? TEST_OUT_NAME
|
File.delete(TEST_OUT_NAME) if File.exist? TEST_OUT_NAME
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_extractDirectory
|
def test_extract_directory
|
||||||
extract_test_dir
|
extract_test_dir
|
||||||
assert(File.directory?(TEST_OUT_NAME))
|
assert(File.directory?(TEST_OUT_NAME))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_extractDirectoryExistsAsDir
|
def test_extract_directory_exists_as_dir
|
||||||
Dir.mkdir TEST_OUT_NAME
|
Dir.mkdir TEST_OUT_NAME
|
||||||
extract_test_dir
|
extract_test_dir
|
||||||
assert(File.directory?(TEST_OUT_NAME))
|
assert(File.directory?(TEST_OUT_NAME))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_extractDirectoryExistsAsFile
|
def test_extract_directory_exists_as_file
|
||||||
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_extract_directory_exists_as_file_overwrite
|
||||||
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|
|
||||||
|
|
|
@ -29,7 +29,7 @@ class ZipFileExtractTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_extractExists
|
def test_extract_exists
|
||||||
writtenText = 'written text'
|
writtenText = 'written text'
|
||||||
::File.open(EXTRACTED_FILENAME, 'w') { |f| f.write(writtenText) }
|
::File.open(EXTRACTED_FILENAME, 'w') { |f| f.write(writtenText) }
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class ZipFileExtractTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_extractExistsOverwrite
|
def test_extract_exists_overwrite
|
||||||
writtenText = 'written text'
|
writtenText = 'written text'
|
||||||
::File.open(EXTRACTED_FILENAME, 'w') { |f| f.write(writtenText) }
|
::File.open(EXTRACTED_FILENAME, 'w') { |f| f.write(writtenText) }
|
||||||
|
|
||||||
|
@ -62,14 +62,14 @@ class ZipFileExtractTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_extractNonEntry
|
def test_extract_non_entry
|
||||||
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_extract_non_entry_2
|
||||||
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)
|
||||||
|
|
|
@ -10,7 +10,7 @@ class ZipFileTest < MiniTest::Test
|
||||||
::Zip.write_zip64_support = false
|
::Zip.write_zip64_support = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_createFromScratchToBuffer
|
def test_create_from_scratch_to_buffer
|
||||||
comment = 'a short comment'
|
comment = 'a short comment'
|
||||||
|
|
||||||
buffer = ::Zip::File.add_buffer do |zf|
|
buffer = ::Zip::File.add_buffer do |zf|
|
||||||
|
@ -26,7 +26,7 @@ class ZipFileTest < MiniTest::Test
|
||||||
assert_equal(2, zfRead.entries.length)
|
assert_equal(2, zfRead.entries.length)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_createFromScratch
|
def test_create_from_scratch
|
||||||
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)
|
||||||
|
@ -125,7 +125,7 @@ class ZipFileTest < MiniTest::Test
|
||||||
assert_equal(::File.stat(srcZip).mode, 0100664)
|
assert_equal(::File.stat(srcZip).mode, 0100664)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_addExistingEntryName
|
def test_add_existing_entry_name
|
||||||
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')
|
||||||
|
@ -133,7 +133,7 @@ class ZipFileTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_addExistingEntryNameReplace
|
def test_add_existing_entry_name_replace
|
||||||
gotCalled = false
|
gotCalled = false
|
||||||
replacedEntry = nil
|
replacedEntry = nil
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
|
@ -146,7 +146,7 @@ class ZipFileTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_addDirectory
|
def test_add_directory
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
zf.add(TestFiles::EMPTY_TEST_DIR, TestFiles::EMPTY_TEST_DIR)
|
zf.add(TestFiles::EMPTY_TEST_DIR, TestFiles::EMPTY_TEST_DIR)
|
||||||
end
|
end
|
||||||
|
@ -230,7 +230,7 @@ class ZipFileTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_renameToExistingEntry
|
def test_rename_to_existing_entry
|
||||||
oldEntries = nil
|
oldEntries = nil
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) { |zf| oldEntries = zf.entries }
|
::Zip::File.open(TEST_ZIP.zip_name) { |zf| oldEntries = zf.entries }
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ class ZipFileTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_renameToExistingEntryOverwrite
|
def test_rename_to_existing_entry_overwrite
|
||||||
oldEntries = nil
|
oldEntries = nil
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) { |zf| oldEntries = zf.entries }
|
::Zip::File.open(TEST_ZIP.zip_name) { |zf| oldEntries = zf.entries }
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ class ZipFileTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_renameNonEntry
|
def test_rename_non_entry
|
||||||
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)
|
||||||
|
@ -276,7 +276,7 @@ class ZipFileTest < MiniTest::Test
|
||||||
zf.close
|
zf.close
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_renameEntryToExistingEntry
|
def test_rename_entry_to_existing_entry
|
||||||
entry1, entry2, * = TEST_ZIP.entry_names
|
entry1, entry2, * = TEST_ZIP.entry_names
|
||||||
zf = ::Zip::File.new(TEST_ZIP.zip_name)
|
zf = ::Zip::File.new(TEST_ZIP.zip_name)
|
||||||
assert_raises(::Zip::EntryExistsError) { zf.rename(entry1, entry2) }
|
assert_raises(::Zip::EntryExistsError) { zf.rename(entry1, entry2) }
|
||||||
|
@ -303,7 +303,7 @@ class ZipFileTest < MiniTest::Test
|
||||||
zfRead.close
|
zfRead.close
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_replaceNonEntry
|
def test_replace_non_entry
|
||||||
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') }
|
||||||
|
@ -367,7 +367,7 @@ class ZipFileTest < MiniTest::Test
|
||||||
# This test tests that after commit, you
|
# This test tests that after commit, you
|
||||||
# can delete the file you used to add the entry to the zip file
|
# can delete the file you used to add the entry to the zip file
|
||||||
# with
|
# with
|
||||||
def test_commitUseZipEntry
|
def test_commit_use_zip_entry
|
||||||
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)
|
||||||
|
@ -464,7 +464,7 @@ class ZipFileTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_changeComment
|
def test_change_comment
|
||||||
::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
|
||||||
|
@ -522,7 +522,7 @@ class ZipFileTest < MiniTest::Test
|
||||||
|
|
||||||
def assert_contains(zf, entryName, filename = entryName)
|
def assert_contains(zf, entryName, filename = entryName)
|
||||||
assert(zf.entries.detect { |e| e.name == entryName } != nil, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}")
|
assert(zf.entries.detect { |e| e.name == entryName } != nil, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}")
|
||||||
assert_entryContents(zf, entryName, filename) if File.exist?(filename)
|
assert_entry_contents(zf, entryName, filename) if File.exist?(filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_not_contains(zf, entryName)
|
def assert_not_contains(zf, entryName)
|
||||||
|
|
|
@ -10,19 +10,19 @@ class ZipInputStreamTest < MiniTest::Test
|
||||||
zis.close
|
zis.close
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_openWithBlock
|
def test_open_with_block
|
||||||
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) 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
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_openWithoutBlock
|
def test_open_without_block
|
||||||
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_open_buffer_with_block
|
||||||
::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?)
|
||||||
|
@ -43,12 +43,12 @@ class ZipInputStreamTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_openBufferWithoutBlock
|
def test_open_buffer_without_block
|
||||||
zis = ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
|
zis = ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
|
||||||
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_incompleteReads
|
def test_incomplete_reads
|
||||||
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
||||||
entry = zis.get_next_entry # longAscii.txt
|
entry = zis.get_next_entry # longAscii.txt
|
||||||
assert_equal(false, zis.eof?)
|
assert_equal(false, zis.eof?)
|
||||||
|
|
|
@ -48,7 +48,7 @@ class AbstractInputStreamTest < MiniTest::Test
|
||||||
assert_equal(4, @io.lineno)
|
assert_equal(4, @io.lineno)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_getsMultiCharSeperator
|
def test_gets_multi_char_seperator
|
||||||
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
|
||||||
|
@ -59,14 +59,14 @@ class AbstractInputStreamTest < MiniTest::Test
|
||||||
'rest'
|
'rest'
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_getsMulitCharSeperator_split
|
def test_gets_mulit_char_seperator_split
|
||||||
io = TestAbstractInputStream.new(LONG_LINES.join)
|
io = TestAbstractInputStream.new(LONG_LINES.join)
|
||||||
assert_equal(LONG_LINES[0], io.gets("\r\n"))
|
assert_equal(LONG_LINES[0], io.gets("\r\n"))
|
||||||
assert_equal(LONG_LINES[1], io.gets("\r\n"))
|
assert_equal(LONG_LINES[1], io.gets("\r\n"))
|
||||||
assert_equal(LONG_LINES[2], io.gets("\r\n"))
|
assert_equal(LONG_LINES[2], io.gets("\r\n"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_getsWithSepAndIndex
|
def test_gets_with_sep_and_index
|
||||||
io = TestAbstractInputStream.new(LONG_LINES.join)
|
io = TestAbstractInputStream.new(LONG_LINES.join)
|
||||||
assert_equal('x', io.gets("\r\n", 1))
|
assert_equal('x', io.gets("\r\n", 1))
|
||||||
assert_equal('x' * 47 + "\r", io.gets("\r\n", 48))
|
assert_equal('x' * 47 + "\r", io.gets("\r\n", 48))
|
||||||
|
@ -74,7 +74,7 @@ class AbstractInputStreamTest < MiniTest::Test
|
||||||
assert_equal('yy', io.gets(nil, 2))
|
assert_equal('yy', io.gets(nil, 2))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_getsWithIndex
|
def test_gets_with_index
|
||||||
assert_equal(TEST_LINES[0], @io.gets(100))
|
assert_equal(TEST_LINES[0], @io.gets(100))
|
||||||
assert_equal('this', @io.gets(4))
|
assert_equal('this', @io.gets(4))
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,7 @@ class ZipLocalEntryTest < MiniTest::Test
|
||||||
::Zip.write_zip64_support = false
|
::Zip.write_zip64_support = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_read_local_entryHeaderOfFirstTestZipEntry
|
def test_read_local_entry_header_of_first_test_zip_entry
|
||||||
::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)
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class ZipLocalEntryTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_readDateTime
|
def test_read_date_time
|
||||||
::File.open('test/data/rubycode.zip', 'rb') do |file|
|
::File.open('test/data/rubycode.zip', 'rb') do |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)
|
||||||
|
@ -34,13 +34,13 @@ class ZipLocalEntryTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_read_local_entryFromNonZipFile
|
def test_read_local_entry_from_non_zip_file
|
||||||
::File.open('test/data/file2.txt') do |file|
|
::File.open('test/data/file2.txt') do |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_entry_from_truncated_zip_file
|
||||||
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
|
||||||
|
@ -50,7 +50,7 @@ class ZipLocalEntryTest < MiniTest::Test
|
||||||
rescue ::Zip::Error
|
rescue ::Zip::Error
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_writeEntry
|
def test_write_entry
|
||||||
entry = ::Zip::Entry.new('file.zip', 'entryName', 'my little comment',
|
entry = ::Zip::Entry.new('file.zip', 'entryName', 'my little comment',
|
||||||
'thisIsSomeExtraInformation', 100, 987_654,
|
'thisIsSomeExtraInformation', 100, 987_654,
|
||||||
::Zip::Entry::DEFLATED, 400)
|
::Zip::Entry::DEFLATED, 400)
|
||||||
|
@ -61,7 +61,7 @@ class ZipLocalEntryTest < MiniTest::Test
|
||||||
compare_c_dir_entry_headers(entry, entryReadCentral)
|
compare_c_dir_entry_headers(entry, entryReadCentral)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_writeEntryWithZip64
|
def test_write_entry_with_zip64
|
||||||
::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, 987_654,
|
'thisIsSomeExtraInformation', 100, 987_654,
|
||||||
|
@ -75,7 +75,7 @@ class ZipLocalEntryTest < MiniTest::Test
|
||||||
compare_c_dir_entry_headers(entry, entryReadCentral)
|
compare_c_dir_entry_headers(entry, entryReadCentral)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_write64Entry
|
def test_write_64entry
|
||||||
::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',
|
||||||
|
@ -87,7 +87,7 @@ class ZipLocalEntryTest < MiniTest::Test
|
||||||
compare_c_dir_entry_headers(entry, entryReadCentral)
|
compare_c_dir_entry_headers(entry, entryReadCentral)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rewriteLocalHeader64
|
def test_rewrite_local_header64
|
||||||
::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')
|
||||||
|
@ -103,7 +103,7 @@ class ZipLocalEntryTest < MiniTest::Test
|
||||||
assert_equal(buf1.size, buf2.size) # it can't grow, or we'd clobber file data
|
assert_equal(buf1.size, buf2.size) # it can't grow, or we'd clobber file data
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_readLocalOffset
|
def test_read_local_offset
|
||||||
entry = ::Zip::Entry.new('file.zip', 'entryName')
|
entry = ::Zip::Entry.new('file.zip', 'entryName')
|
||||||
entry.local_header_offset = 12_345
|
entry.local_header_offset = 12_345
|
||||||
::File.open(CEH_FILE, 'wb') { |f| entry.write_c_dir_entry(f) }
|
::File.open(CEH_FILE, 'wb') { |f| entry.write_c_dir_entry(f) }
|
||||||
|
@ -112,7 +112,7 @@ class ZipLocalEntryTest < MiniTest::Test
|
||||||
compare_c_dir_entry_headers(entry, read_entry)
|
compare_c_dir_entry_headers(entry, read_entry)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_read64LocalOffset
|
def test_read64_local_offset
|
||||||
::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
|
||||||
|
|
|
@ -47,13 +47,13 @@ class ZipOutputStreamTest < MiniTest::Test
|
||||||
assert_test_zip_contents(TEST_ZIP)
|
assert_test_zip_contents(TEST_ZIP)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_writingToClosedStream
|
def test_writing_to_closed_stream
|
||||||
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_cannot_open_file
|
||||||
name = TestFiles::EMPTY_TEST_DIR
|
name = TestFiles::EMPTY_TEST_DIR
|
||||||
begin
|
begin
|
||||||
::Zip::OutputStream.open(name)
|
::Zip::OutputStream.open(name)
|
||||||
|
|
|
@ -86,6 +86,6 @@ class ZipSettingsTest < MiniTest::Test
|
||||||
|
|
||||||
def assert_contains(zf, entryName, filename = entryName)
|
def assert_contains(zf, entryName, filename = entryName)
|
||||||
assert(zf.entries.detect { |e| e.name == entryName } != nil, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}")
|
assert(zf.entries.detect { |e| e.name == entryName } != nil, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}")
|
||||||
assert_entryContents(zf, entryName, filename) if File.exist?(filename)
|
assert_entry_contents(zf, entryName, filename) if File.exist?(filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,11 +59,11 @@ module DecompressorTests
|
||||||
@refLines = @refText.split($/)
|
@refLines = @refText.split($/)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_readEverything
|
def test_read_everything
|
||||||
assert_equal(@refText, @decompressor.sysread)
|
assert_equal(@refText, @decompressor.sysread)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_readInChunks
|
def test_read_in_chunks
|
||||||
chunkSize = 5
|
chunkSize = 5
|
||||||
while (decompressedChunk = @decompressor.sysread(chunkSize))
|
while (decompressedChunk = @decompressor.sysread(chunkSize))
|
||||||
assert_equal(@refText.slice!(0, chunkSize), decompressedChunk)
|
assert_equal(@refText.slice!(0, chunkSize), decompressedChunk)
|
||||||
|
@ -71,7 +71,7 @@ module DecompressorTests
|
||||||
assert_equal(0, @refText.size)
|
assert_equal(0, @refText.size)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mixingReadsAndProduceInput
|
def test_mixing_reads_and_produce_input
|
||||||
# Just some preconditions to make sure we have enough data for this test
|
# Just some preconditions to make sure we have enough data for this test
|
||||||
assert(@refText.length > 1000)
|
assert(@refText.length > 1000)
|
||||||
assert(@refLines.length > 40)
|
assert(@refLines.length > 40)
|
||||||
|
@ -91,10 +91,10 @@ module AssertEntry
|
||||||
|
|
||||||
def assert_entry(filename, zis, entryName)
|
def assert_entry(filename, zis, entryName)
|
||||||
assert_equal(filename, entryName)
|
assert_equal(filename, entryName)
|
||||||
assert_entryContentsForStream(filename, zis, entryName)
|
assert_entry_contents_for_stream(filename, zis, entryName)
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_entryContentsForStream(filename, zis, entryName)
|
def assert_entry_contents_for_stream(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
|
||||||
|
@ -138,9 +138,9 @@ module AssertEntry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_entryContents(zipFile, entryName, filename = entryName.to_s)
|
def assert_entry_contents(zipFile, entryName, filename = entryName.to_s)
|
||||||
zis = zipFile.get_input_stream(entryName)
|
zis = zipFile.get_input_stream(entryName)
|
||||||
assert_entryContentsForStream(filename, zis, entryName)
|
assert_entry_contents_for_stream(filename, zis, entryName)
|
||||||
ensure
|
ensure
|
||||||
zis.close if zis
|
zis.close if zis
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,16 +12,16 @@ if ENV['FULL_ZIP64_TEST']
|
||||||
::Zip.reset!
|
::Zip.reset!
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepareTestFile(test_filename)
|
def prepare_test_file(test_filename)
|
||||||
::File.delete(test_filename) if ::File.exist?(test_filename)
|
::File.delete(test_filename) if ::File.exist?(test_filename)
|
||||||
test_filename
|
test_filename
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_largeZipFile
|
def test_large_zip_file
|
||||||
::Zip.write_zip64_support = true
|
::Zip.write_zip64_support = true
|
||||||
first_text = 'starting out small'
|
first_text = 'starting out small'
|
||||||
last_text = 'this tests files starting after 4GB in the archive'
|
last_text = 'this tests files starting after 4GB in the archive'
|
||||||
test_filename = prepareTestFile('huge.zip')
|
test_filename = prepare_test_file('huge.zip')
|
||||||
::Zip::OutputStream.open(test_filename) do |io|
|
::Zip::OutputStream.open(test_filename) do |io|
|
||||||
io.put_next_entry('first_file.txt')
|
io.put_next_entry('first_file.txt')
|
||||||
io.write(first_text)
|
io.write(first_text)
|
||||||
|
|
Loading…
Reference in New Issue