mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
9694bb8cac
* test/rubygems*: ditto. * common.mk (prelude): Updated for RubyGems 2.0 source rearrangement. * tool/change_maker.rb: Allow invalid UTF-8 characters in source files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
78 lines
1.7 KiB
Ruby
78 lines
1.7 KiB
Ruby
require 'rubygems/package/tar_test_case'
|
|
require 'rubygems/package'
|
|
|
|
class TestGemPackageTarReader < Gem::Package::TarTestCase
|
|
|
|
def test_each_entry
|
|
tar = tar_dir_header "foo", "bar", 0
|
|
tar << tar_file_header("bar", "baz", 0, 0)
|
|
|
|
io = TempIO.new tar
|
|
|
|
entries = 0
|
|
|
|
Gem::Package::TarReader.new io do |tar_reader|
|
|
tar_reader.each_entry do |entry|
|
|
assert_kind_of Gem::Package::TarReader::Entry, entry
|
|
|
|
entries += 1
|
|
end
|
|
end
|
|
|
|
assert_equal 2, entries
|
|
end
|
|
|
|
def test_rewind
|
|
content = ('a'..'z').to_a.join(" ")
|
|
|
|
str = tar_file_header("lib/foo", "", 010644, content.size) + content +
|
|
"\0" * (512 - content.size)
|
|
str << "\0" * 1024
|
|
|
|
Gem::Package::TarReader.new(TempIO.new(str)) do |tar_reader|
|
|
3.times do
|
|
tar_reader.rewind
|
|
i = 0
|
|
tar_reader.each_entry do |entry|
|
|
assert_equal(content, entry.read)
|
|
i += 1
|
|
end
|
|
assert_equal(1, i)
|
|
end
|
|
end
|
|
end
|
|
|
|
def test_seek
|
|
tar = tar_dir_header "foo", "bar", 0
|
|
tar << tar_file_header("bar", "baz", 0, 0)
|
|
|
|
io = TempIO.new tar
|
|
|
|
Gem::Package::TarReader.new io do |tar_reader|
|
|
tar_reader.seek 'baz/bar' do |entry|
|
|
assert_kind_of Gem::Package::TarReader::Entry, entry
|
|
|
|
assert_equal 'baz/bar', entry.full_name
|
|
end
|
|
|
|
assert_equal 0, io.pos
|
|
end
|
|
end
|
|
|
|
def test_seek_missing
|
|
tar = tar_dir_header "foo", "bar", 0
|
|
tar << tar_file_header("bar", "baz", 0, 0)
|
|
|
|
io = TempIO.new tar
|
|
|
|
Gem::Package::TarReader.new io do |tar_reader|
|
|
tar_reader.seek 'nonexistent' do |entry|
|
|
flunk 'entry missing but entry-found block was run'
|
|
end
|
|
|
|
assert_equal 0, io.pos
|
|
end
|
|
end
|
|
|
|
end
|
|
|