test/test_tar_reader.rb in minitar-0.9 vs test/test_tar_reader.rb in minitar-0.12
- old
+ new
@@ -1,34 +1,34 @@
#!/usr/bin/env ruby
-require 'minitar'
-require 'minitest_helper'
+require "minitar"
+require "minitest_helper"
class TestTarReader < Minitest::Test
include Archive::Tar::Minitar::ByteSize
def test_open_no_block
- str = tar_file_header('lib/foo', '', 0o10644, 10) + "\0" * 512
- str += tar_file_header('bar', 'baz', 0o644, 0)
- str += tar_dir_header('foo', 'bar', 0o12345)
+ str = tar_file_header("lib/foo", "", 0o10644, 10) + "\0" * 512
+ str += tar_file_header("bar", "baz", 0o644, 0)
+ str += tar_dir_header("foo", "bar", 0o12345)
str += "\0" * 1024
reader = Minitar::Reader.open(StringIO.new(str))
refute reader.closed?
ensure
reader.close
refute reader.closed? # Reader doesn't actually close anything
end
def test_multiple_entries
- str = tar_file_header('lib/foo', '', 0o10644, 10) + "\0" * 512
- str += tar_file_header('bar', 'baz', 0o644, 0)
- str += tar_dir_header('foo', 'bar', 0o12345)
- str += tar_file_header('src/', '', 0o755, 0) # "file" with a trailing slash
+ str = tar_file_header("lib/foo", "", 0o10644, 10) + "\0" * 512
+ str += tar_file_header("bar", "baz", 0o644, 0)
+ str += tar_dir_header("foo", "bar", 0o12345)
+ str += tar_file_header("src/", "", 0o755, 0) # "file" with a trailing slash
str += "\0" * 1024
- names = %w(lib/foo bar foo src/)
- prefixes = ['', 'baz', 'bar', '']
+ names = %w[lib/foo bar foo src/]
+ prefixes = ["", "baz", "bar", ""]
modes = [0o10644, 0o644, 0o12345, 0o755]
sizes = [10, 0, 0, 0]
isdir = [false, false, true, true]
isfile = [true, true, false, false]
Minitar::Reader.new(StringIO.new(str)) do |is|
@@ -39,11 +39,11 @@
assert_equal(prefixes[i], entry.prefix)
assert_equal(sizes[i], entry.size)
assert_equal(modes[i], entry.mode)
assert_equal(isdir[i], entry.directory?)
assert_equal(isfile[i], entry.file?)
- if prefixes[i] != ''
+ if prefixes[i] != ""
assert_equal(File.join(prefixes[i], names[i]), entry.full_name)
else
assert_equal(names[i], entry.name)
end
i += 1
@@ -51,12 +51,12 @@
assert_equal(names.size, i)
end
end
def test_rewind_entry_works
- content = ('a'..'z').to_a.join(' ')
- str = tar_file_header('lib/foo', '', 0o10644, bytesize(content)) +
+ content = ("a".."z").to_a.join(" ")
+ str = tar_file_header("lib/foo", "", 0o10644, bytesize(content)) +
content + "\0" * (512 - bytesize(content))
str << "\0" * 1024
Minitar::Reader.new(StringIO.new(str)) do |is|
is.each_entry do |entry|
3.times do
@@ -67,12 +67,12 @@
end
end
end
def test_rewind_works
- content = ('a'..'z').to_a.join(' ')
- str = tar_file_header('lib/foo', '', 0o10644, bytesize(content)) +
+ content = ("a".."z").to_a.join(" ")
+ str = tar_file_header("lib/foo", "", 0o10644, bytesize(content)) +
content + "\0" * (512 - bytesize(content))
str << "\0" * 1024
Minitar::Reader.new(StringIO.new(str)) do |is|
3.times do
is.rewind
@@ -85,12 +85,12 @@
end
end
end
def test_read_works
- contents = ('a'..'z').inject('') { |a, e| a << e * 100 }
- str = tar_file_header('lib/foo', '', 0o10644, bytesize(contents)) + contents
+ contents = ("a".."z").inject("") { |a, e| a << e * 100 }
+ str = tar_file_header("lib/foo", "", 0o10644, bytesize(contents)) + contents
str += "\0" * (512 - (bytesize(str) % 512))
Minitar::Reader.new(StringIO.new(str)) do |is|
is.each_entry do |entry|
assert_kind_of(Minitar::Reader::EntryStream, entry)
data = entry.read(3000) # bigger than bytesize(contents)
@@ -120,11 +120,11 @@
end
end
end
def test_eof_works
- str = tar_file_header('bar', 'baz', 0o644, 0)
+ str = tar_file_header("bar", "baz", 0o644, 0)
Minitar::Reader.new(StringIO.new(str)) do |is|
is.each_entry do |entry|
assert_kind_of(Minitar::Reader::EntryStream, entry)
data = entry.read
assert_equal(nil, data)
@@ -132,11 +132,11 @@
assert_equal(nil, entry.read)
assert_equal(nil, entry.getc)
assert_equal(true, entry.eof?)
end
end
- str = tar_dir_header('foo', 'bar', 0o12345)
+ str = tar_dir_header("foo", "bar", 0o12345)
Minitar::Reader.new(StringIO.new(str)) do |is|
is.each_entry do |entry|
assert_kind_of(Minitar::Reader::EntryStream, entry)
data = entry.read
assert_equal(nil, data)
@@ -144,12 +144,12 @@
assert_equal(nil, entry.read)
assert_equal(nil, entry.getc)
assert_equal(true, entry.eof?)
end
end
- str = tar_dir_header('foo', 'bar', 0o12345)
- str += tar_file_header('bar', 'baz', 0o644, 0)
- str += tar_file_header('bar', 'baz', 0o644, 0)
+ str = tar_dir_header("foo", "bar", 0o12345)
+ str += tar_file_header("bar", "baz", 0o644, 0)
+ str += tar_file_header("bar", "baz", 0o644, 0)
Minitar::Reader.new(StringIO.new(str)) do |is|
is.each_entry do |entry|
assert_kind_of(Minitar::Reader::EntryStream, entry)
data = entry.read
assert_equal(nil, data)