test/test_tar_reader.rb in minitar-0.7 vs test/test_tar_reader.rb in minitar-0.8
- old
+ new
@@ -2,10 +2,12 @@
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 += "\0" * 1024
@@ -19,17 +21,18 @@
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 += "\0" * 1024
- names = %w(lib/foo bar foo)
- prefixes = ['', 'baz', 'bar']
- modes = [0o10644, 0o644, 0o12345]
- sizes = [10, 0, 0]
- isdir = [false, false, true]
- isfile = [true, true, false]
+ 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|
i = 0
is.each_entry do |entry|
assert_kind_of(Minitar::Reader::EntryStream, entry)
assert_equal(names[i], entry.name)
@@ -49,28 +52,28 @@
end
end
def test_rewind_entry_works
content = ('a'..'z').to_a.join(' ')
- str = tar_file_header('lib/foo', '', 0o10644, content.size) + content +
- "\0" * (512 - content.size)
+ 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
entry.rewind
assert_equal(content, entry.read)
- assert_equal(content.size, entry.pos)
+ assert_equal(bytesize(content), entry.pos)
end
end
end
end
def test_rewind_works
content = ('a'..'z').to_a.join(' ')
- str = tar_file_header('lib/foo', '', 0o10644, content.size) + content +
- "\0" * (512 - content.size)
+ 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
i = 0
@@ -83,24 +86,24 @@
end
end
def test_read_works
contents = ('a'..'z').inject('') { |a, e| a << e * 100 }
- str = tar_file_header('lib/foo', '', 0o10644, contents.size) + contents
- str += "\0" * (512 - (str.size % 512))
+ 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 contents.size
+ data = entry.read(3000) # bigger than bytesize(contents)
assert_equal(contents, data)
assert_equal(true, entry.eof?)
end
end
Minitar::Reader.new(StringIO.new(str)) do |is|
is.each_entry do |entry|
assert_kind_of(Minitar::Reader::EntryStream, entry)
data = entry.read(100)
- (entry.size - data.size).times { data << entry.getc.chr }
+ (entry.size - bytesize(data)).times { data << entry.getc.chr }
assert_equal(contents, data)
assert_equal(nil, entry.read(10))
assert_equal(true, entry.eof?)
end
end