rubyzip 1.1.7 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubyzip might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +69 -32
- data/Rakefile +3 -4
- data/lib/zip.rb +3 -5
- data/lib/zip/central_directory.rb +7 -7
- data/lib/zip/compressor.rb +0 -0
- data/lib/zip/constants.rb +2 -2
- data/lib/zip/crypto/null_encryption.rb +3 -3
- data/lib/zip/crypto/traditional_encryption.rb +5 -5
- data/lib/zip/decompressor.rb +2 -2
- data/lib/zip/deflater.rb +8 -6
- data/lib/zip/dos_time.rb +4 -5
- data/lib/zip/entry.rb +68 -80
- data/lib/zip/entry_set.rb +11 -11
- data/lib/zip/errors.rb +1 -0
- data/lib/zip/extra_field.rb +6 -6
- data/lib/zip/extra_field/generic.rb +7 -7
- data/lib/zip/extra_field/ntfs.rb +14 -16
- data/lib/zip/extra_field/old_unix.rb +9 -10
- data/lib/zip/extra_field/universal_time.rb +14 -14
- data/lib/zip/extra_field/unix.rb +8 -9
- data/lib/zip/extra_field/zip64.rb +12 -11
- data/lib/zip/extra_field/zip64_placeholder.rb +1 -1
- data/lib/zip/file.rb +45 -49
- data/lib/zip/filesystem.rb +132 -135
- data/lib/zip/inflater.rb +3 -3
- data/lib/zip/input_stream.rb +13 -7
- data/lib/zip/ioextras.rb +1 -3
- data/lib/zip/ioextras/abstract_input_stream.rb +5 -9
- data/lib/zip/ioextras/abstract_output_stream.rb +0 -2
- data/lib/zip/null_compressor.rb +2 -2
- data/lib/zip/null_decompressor.rb +3 -3
- data/lib/zip/null_input_stream.rb +0 -0
- data/lib/zip/output_stream.rb +8 -9
- data/lib/zip/pass_thru_compressor.rb +4 -4
- data/lib/zip/pass_thru_decompressor.rb +2 -3
- data/lib/zip/streamable_directory.rb +2 -2
- data/lib/zip/streamable_stream.rb +2 -2
- data/lib/zip/version.rb +1 -1
- data/samples/example.rb +29 -39
- data/samples/example_filesystem.rb +16 -18
- data/samples/example_recursive.rb +33 -24
- data/samples/{gtkRubyzip.rb → gtk_ruby_zip.rb} +23 -25
- data/samples/qtzip.rb +17 -26
- data/samples/write_simple.rb +12 -13
- data/samples/zipfind.rb +24 -32
- data/test/basic_zip_file_test.rb +11 -15
- data/test/case_sensitivity_test.rb +69 -0
- data/test/central_directory_entry_test.rb +31 -35
- data/test/central_directory_test.rb +46 -50
- data/test/crypto/null_encryption_test.rb +2 -2
- data/test/crypto/traditional_encryption_test.rb +5 -5
- data/test/data/notzippedruby.rb +1 -1
- data/test/data/oddExtraField.zip +0 -0
- data/test/data/test.xls +0 -0
- data/test/deflater_test.rb +10 -12
- data/test/encryption_test.rb +2 -2
- data/test/entry_set_test.rb +38 -24
- data/test/entry_test.rb +76 -78
- data/test/errors_test.rb +0 -2
- data/test/extra_field_test.rb +19 -21
- data/test/file_extract_directory_test.rb +12 -14
- data/test/file_extract_test.rb +33 -40
- data/test/file_permissions_test.rb +69 -0
- data/test/file_split_test.rb +24 -27
- data/test/file_test.rb +174 -170
- data/test/filesystem/dir_iterator_test.rb +13 -17
- data/test/filesystem/directory_test.rb +80 -90
- data/test/filesystem/file_mutating_test.rb +51 -63
- data/test/filesystem/file_nonmutating_test.rb +222 -228
- data/test/filesystem/file_stat_test.rb +17 -19
- data/test/gentestfiles.rb +43 -55
- data/test/inflater_test.rb +1 -1
- data/test/input_stream_test.rb +42 -30
- data/test/ioextras/abstract_input_stream_test.rb +21 -22
- data/test/ioextras/abstract_output_stream_test.rb +32 -32
- data/test/local_entry_test.rb +35 -37
- data/test/output_stream_test.rb +20 -21
- data/test/pass_thru_compressor_test.rb +5 -6
- data/test/pass_thru_decompressor_test.rb +0 -1
- data/test/samples/example_recursive_test.rb +37 -0
- data/test/settings_test.rb +18 -15
- data/test/test_helper.rb +37 -44
- data/test/unicode_file_names_and_comments_test.rb +5 -7
- data/test/zip64_full_test.rb +9 -11
- data/test/zip64_support_test.rb +0 -1
- metadata +14 -32
@@ -2,9 +2,8 @@ require 'test_helper'
|
|
2
2
|
require 'zip/filesystem'
|
3
3
|
|
4
4
|
class ZipFsFileStatTest < MiniTest::Test
|
5
|
-
|
6
5
|
def setup
|
7
|
-
@zip_file = ::Zip::File.new(
|
6
|
+
@zip_file = ::Zip::File.new('test/data/zipWithDirs.zip')
|
8
7
|
end
|
9
8
|
|
10
9
|
def teardown
|
@@ -12,55 +11,54 @@ class ZipFsFileStatTest < MiniTest::Test
|
|
12
11
|
end
|
13
12
|
|
14
13
|
def test_blocks
|
15
|
-
assert_equal(nil, @zip_file.file.stat(
|
14
|
+
assert_equal(nil, @zip_file.file.stat('file1').blocks)
|
16
15
|
end
|
17
16
|
|
18
17
|
def test_ino
|
19
|
-
assert_equal(0, @zip_file.file.stat(
|
18
|
+
assert_equal(0, @zip_file.file.stat('file1').ino)
|
20
19
|
end
|
21
20
|
|
22
21
|
def test_uid
|
23
|
-
assert_equal(0, @zip_file.file.stat(
|
22
|
+
assert_equal(0, @zip_file.file.stat('file1').uid)
|
24
23
|
end
|
25
24
|
|
26
25
|
def test_gid
|
27
|
-
assert_equal(0, @zip_file.file.stat(
|
26
|
+
assert_equal(0, @zip_file.file.stat('file1').gid)
|
28
27
|
end
|
29
28
|
|
30
29
|
def test_ftype
|
31
|
-
assert_equal(
|
32
|
-
assert_equal(
|
30
|
+
assert_equal('file', @zip_file.file.stat('file1').ftype)
|
31
|
+
assert_equal('directory', @zip_file.file.stat('dir1').ftype)
|
33
32
|
end
|
34
33
|
|
35
34
|
def test_mode
|
36
|
-
assert_equal(0600, @zip_file.file.stat(
|
37
|
-
assert_equal(0600, @zip_file.file.stat(
|
38
|
-
assert_equal(0755, @zip_file.file.stat(
|
39
|
-
assert_equal(0755, @zip_file.file.stat(
|
35
|
+
assert_equal(0600, @zip_file.file.stat('file1').mode & 0777)
|
36
|
+
assert_equal(0600, @zip_file.file.stat('file1').mode & 0777)
|
37
|
+
assert_equal(0755, @zip_file.file.stat('dir1').mode & 0777)
|
38
|
+
assert_equal(0755, @zip_file.file.stat('dir1').mode & 0777)
|
40
39
|
end
|
41
40
|
|
42
41
|
def test_dev
|
43
|
-
assert_equal(0, @zip_file.file.stat(
|
42
|
+
assert_equal(0, @zip_file.file.stat('file1').dev)
|
44
43
|
end
|
45
44
|
|
46
45
|
def test_rdev
|
47
|
-
assert_equal(0, @zip_file.file.stat(
|
46
|
+
assert_equal(0, @zip_file.file.stat('file1').rdev)
|
48
47
|
end
|
49
48
|
|
50
49
|
def test_rdev_major
|
51
|
-
assert_equal(0, @zip_file.file.stat(
|
50
|
+
assert_equal(0, @zip_file.file.stat('file1').rdev_major)
|
52
51
|
end
|
53
52
|
|
54
53
|
def test_rdev_minor
|
55
|
-
assert_equal(0, @zip_file.file.stat(
|
54
|
+
assert_equal(0, @zip_file.file.stat('file1').rdev_minor)
|
56
55
|
end
|
57
56
|
|
58
57
|
def test_nlink
|
59
|
-
assert_equal(1, @zip_file.file.stat(
|
58
|
+
assert_equal(1, @zip_file.file.stat('file1').nlink)
|
60
59
|
end
|
61
60
|
|
62
61
|
def test_blksize
|
63
|
-
assert_nil(@zip_file.file.stat(
|
62
|
+
assert_nil(@zip_file.file.stat('file1').blksize)
|
64
63
|
end
|
65
|
-
|
66
64
|
end
|
data/test/gentestfiles.rb
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
$VERBOSE = true
|
4
4
|
|
5
5
|
class TestFiles
|
6
|
-
RANDOM_ASCII_FILE1 =
|
7
|
-
RANDOM_ASCII_FILE2 =
|
8
|
-
RANDOM_ASCII_FILE3 =
|
9
|
-
RANDOM_BINARY_FILE1 =
|
10
|
-
RANDOM_BINARY_FILE2 =
|
6
|
+
RANDOM_ASCII_FILE1 = 'test/data/generated/randomAscii1.txt'
|
7
|
+
RANDOM_ASCII_FILE2 = 'test/data/generated/randomAscii2.txt'
|
8
|
+
RANDOM_ASCII_FILE3 = 'test/data/generated/randomAscii3.txt'
|
9
|
+
RANDOM_BINARY_FILE1 = 'test/data/generated/randomBinary1.bin'
|
10
|
+
RANDOM_BINARY_FILE2 = 'test/data/generated/randomBinary2.bin'
|
11
11
|
|
12
|
-
EMPTY_TEST_DIR =
|
12
|
+
EMPTY_TEST_DIR = 'test/data/generated/emptytestdir'
|
13
13
|
|
14
14
|
ASCII_TEST_FILES = [RANDOM_ASCII_FILE1, RANDOM_ASCII_FILE2, RANDOM_ASCII_FILE3]
|
15
15
|
BINARY_TEST_FILES = [RANDOM_BINARY_FILE1, RANDOM_BINARY_FILE2]
|
@@ -18,34 +18,30 @@ class TestFiles
|
|
18
18
|
|
19
19
|
class << self
|
20
20
|
def create_test_files
|
21
|
-
|
21
|
+
Dir.mkdir 'test/data/generated' unless Dir.exist?('test/data/generated')
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
ASCII_TEST_FILES.each_with_index do |filename, index|
|
24
|
+
create_random_ascii(filename, 1E4 * (index + 1))
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
BINARY_TEST_FILES.each_with_index do |filename, index|
|
28
|
+
create_random_binary(filename, 1E4 * (index + 1))
|
29
|
+
end
|
30
30
|
|
31
|
-
|
31
|
+
ensure_dir(EMPTY_TEST_DIR)
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
35
35
|
|
36
36
|
def create_random_ascii(filename, size)
|
37
|
-
File.open(filename,
|
38
|
-
while
|
39
|
-
file << rand
|
40
|
-
end
|
37
|
+
File.open(filename, 'wb') do |file|
|
38
|
+
file << rand while file.tell < size
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
44
42
|
def create_random_binary(filename, size)
|
45
|
-
File.open(filename,
|
46
|
-
while
|
47
|
-
file << [rand].pack("V")
|
48
|
-
end
|
43
|
+
File.open(filename, 'wb') do |file|
|
44
|
+
file << [rand].pack('V') while file.tell < size
|
49
45
|
end
|
50
46
|
end
|
51
47
|
|
@@ -56,47 +52,41 @@ class TestFiles
|
|
56
52
|
end
|
57
53
|
Dir.mkdir(name)
|
58
54
|
end
|
59
|
-
|
60
55
|
end
|
61
56
|
end
|
62
57
|
|
63
|
-
|
64
58
|
# For representation and creation of
|
65
59
|
# test data
|
66
60
|
class TestZipFile
|
67
61
|
attr_accessor :zip_name, :entry_names, :comment
|
68
62
|
|
69
|
-
def initialize(zip_name, entry_names, comment =
|
70
|
-
@zip_name=zip_name
|
71
|
-
@entry_names=entry_names
|
63
|
+
def initialize(zip_name, entry_names, comment = '')
|
64
|
+
@zip_name = zip_name
|
65
|
+
@entry_names = entry_names
|
72
66
|
@comment = comment
|
73
67
|
end
|
74
68
|
|
75
|
-
def
|
69
|
+
def self.create_test_zips
|
76
70
|
raise "failed to create test zip '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP1.zip_name} test/data/file2.txt")
|
77
71
|
raise "failed to remove entry from '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP1.zip_name} -d test/data/file2.txt")
|
78
72
|
|
79
|
-
File.open(
|
80
|
-
File.open(
|
81
|
-
::File.chmod(0640,
|
73
|
+
File.open('test/data/generated/empty.txt', 'w') {}
|
74
|
+
File.open('test/data/generated/empty_chmod640.txt', 'w') {}
|
75
|
+
::File.chmod(0640, 'test/data/generated/empty_chmod640.txt')
|
82
76
|
|
83
|
-
File.open(
|
84
|
-
ziptestTxt=
|
85
|
-
File.open(
|
86
|
-
File.open(
|
87
|
-
while
|
88
|
-
file << ziptestTxt
|
89
|
-
end
|
77
|
+
File.open('test/data/generated/short.txt', 'w') { |file| file << 'ABCDEF' }
|
78
|
+
ziptestTxt = ''
|
79
|
+
File.open('test/data/file2.txt') { |file| ziptestTxt = file.read }
|
80
|
+
File.open('test/data/generated/longAscii.txt', 'w') do |file|
|
81
|
+
file << ziptestTxt while file.tell < 1E5
|
90
82
|
end
|
91
83
|
|
92
|
-
testBinaryPattern=
|
93
|
-
File.open(
|
84
|
+
testBinaryPattern = ''
|
85
|
+
File.open('test/data/generated/empty.zip') { |file| testBinaryPattern = file.read }
|
94
86
|
testBinaryPattern *= 4
|
95
87
|
|
96
|
-
File.open(
|
97
|
-
while
|
98
|
-
file << testBinaryPattern << rand << "\0"
|
99
|
-
end
|
88
|
+
File.open('test/data/generated/longBinary.bin', 'wb') do |file|
|
89
|
+
file << testBinaryPattern << rand << "\0" while file.tell < 6E5
|
100
90
|
end
|
101
91
|
|
102
92
|
raise "failed to create test zip '#{TEST_ZIP2.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP2.zip_name} #{TEST_ZIP2.entry_names.join(' ')}")
|
@@ -118,17 +108,15 @@ class TestZipFile
|
|
118
108
|
# http://stahlworks.com/dev/index.php?tool=zipunzip
|
119
109
|
# that works with the above code
|
120
110
|
raise $!.to_s +
|
121
|
-
|
122
|
-
|
123
|
-
|
111
|
+
"\n\nziptest.rb requires the Info-ZIP program 'zip' in the path\n" \
|
112
|
+
"to create test data. If you don't have it you can download\n" \
|
113
|
+
'the necessary test files at http://sf.net/projects/rubyzip.'
|
124
114
|
end
|
125
115
|
|
126
|
-
TEST_ZIP1 = TestZipFile.new(
|
127
|
-
TEST_ZIP2 = TestZipFile.new(
|
128
|
-
|
129
|
-
TEST_ZIP3 = TestZipFile.new(
|
130
|
-
TEST_ZIP4 = TestZipFile.new(
|
131
|
-
|
116
|
+
TEST_ZIP1 = TestZipFile.new('test/data/generated/empty.zip', [])
|
117
|
+
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),
|
118
|
+
'my zip comment')
|
119
|
+
TEST_ZIP3 = TestZipFile.new('test/data/generated/test1.zip', %w(test/data/file1.txt))
|
120
|
+
TEST_ZIP4 = TestZipFile.new('test/data/generated/zipWithDir.zip', ['test/data/file1.txt',
|
121
|
+
TestFiles::EMPTY_TEST_DIR])
|
132
122
|
end
|
133
|
-
|
134
|
-
|
data/test/inflater_test.rb
CHANGED
data/test/input_stream_test.rb
CHANGED
@@ -3,6 +3,16 @@ require 'test_helper'
|
|
3
3
|
class ZipInputStreamTest < MiniTest::Test
|
4
4
|
include AssertEntry
|
5
5
|
|
6
|
+
class IOLike
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def initialize(path, mode)
|
10
|
+
@file = File.new(path, mode)
|
11
|
+
end
|
12
|
+
|
13
|
+
delegate ::Zip::File::IO_METHODS => :@file
|
14
|
+
end
|
15
|
+
|
6
16
|
def test_new
|
7
17
|
zis = ::Zip::InputStream.new(TestZipFile::TEST_ZIP2.zip_name)
|
8
18
|
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
@@ -10,21 +20,20 @@ class ZipInputStreamTest < MiniTest::Test
|
|
10
20
|
zis.close
|
11
21
|
end
|
12
22
|
|
13
|
-
def
|
14
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
|
15
|
-
|zis|
|
23
|
+
def test_open_with_block
|
24
|
+
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
16
25
|
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
17
26
|
assert_equal(true, zis.eof?)
|
18
|
-
|
27
|
+
end
|
19
28
|
end
|
20
29
|
|
21
|
-
def
|
22
|
-
zis = ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name,
|
30
|
+
def test_open_without_block
|
31
|
+
zis = ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, 'rb'))
|
23
32
|
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
24
33
|
end
|
25
34
|
|
26
|
-
def
|
27
|
-
::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name,
|
35
|
+
def test_open_buffer_with_block
|
36
|
+
::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, 'rb')) do |zis|
|
28
37
|
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
29
38
|
assert_equal(true, zis.eof?)
|
30
39
|
end
|
@@ -44,14 +53,20 @@ class ZipInputStreamTest < MiniTest::Test
|
|
44
53
|
end
|
45
54
|
end
|
46
55
|
|
47
|
-
def
|
56
|
+
def test_open_buffer_without_block
|
48
57
|
zis = ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
|
49
58
|
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
50
59
|
end
|
51
60
|
|
52
|
-
def
|
53
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
|
54
|
-
|
61
|
+
def test_open_io_like_with_block
|
62
|
+
::Zip::InputStream.open(IOLike.new(TestZipFile::TEST_ZIP2.zip_name, 'rb')) do |zis|
|
63
|
+
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
64
|
+
assert_equal(true, zis.eof?)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_incomplete_reads
|
69
|
+
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
55
70
|
entry = zis.get_next_entry # longAscii.txt
|
56
71
|
assert_equal(false, zis.eof?)
|
57
72
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name)
|
@@ -73,7 +88,7 @@ class ZipInputStreamTest < MiniTest::Test
|
|
73
88
|
entry = zis.get_next_entry # longBinary.bin
|
74
89
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
|
75
90
|
assert zis.gets.length > 0
|
76
|
-
|
91
|
+
end
|
77
92
|
end
|
78
93
|
|
79
94
|
def test_incomplete_reads_from_string_io
|
@@ -114,25 +129,24 @@ class ZipInputStreamTest < MiniTest::Test
|
|
114
129
|
end
|
115
130
|
|
116
131
|
def test_rewind
|
117
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
|
118
|
-
|zis|
|
132
|
+
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
119
133
|
e = zis.get_next_entry
|
120
134
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], e.name)
|
121
135
|
|
122
136
|
# Do a little reading
|
123
|
-
buf =
|
137
|
+
buf = ''
|
124
138
|
buf << zis.read(100)
|
125
139
|
assert_equal(100, zis.pos)
|
126
|
-
buf << (zis.gets ||
|
127
|
-
buf << (zis.gets ||
|
140
|
+
buf << (zis.gets || '')
|
141
|
+
buf << (zis.gets || '')
|
128
142
|
assert_equal(false, zis.eof?)
|
129
143
|
|
130
144
|
zis.rewind
|
131
145
|
|
132
|
-
buf2 =
|
146
|
+
buf2 = ''
|
133
147
|
buf2 << zis.read(100)
|
134
|
-
buf2 << (zis.gets ||
|
135
|
-
buf2 << (zis.gets ||
|
148
|
+
buf2 << (zis.gets || '')
|
149
|
+
buf2 << (zis.gets || '')
|
136
150
|
|
137
151
|
assert_equal(buf, buf2)
|
138
152
|
|
@@ -141,20 +155,19 @@ class ZipInputStreamTest < MiniTest::Test
|
|
141
155
|
assert_equal(0, zis.pos)
|
142
156
|
|
143
157
|
assert_entry(e.name, zis, e.name)
|
144
|
-
|
158
|
+
end
|
145
159
|
end
|
146
160
|
|
147
161
|
def test_mix_read_and_gets
|
148
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
|
149
|
-
|zis|
|
162
|
+
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
150
163
|
zis.get_next_entry
|
151
|
-
assert_equal(
|
164
|
+
assert_equal('#!/usr/bin/env ruby', zis.gets.chomp)
|
152
165
|
assert_equal(false, zis.eof?)
|
153
|
-
assert_equal(
|
166
|
+
assert_equal('', zis.gets.chomp)
|
154
167
|
assert_equal(false, zis.eof?)
|
155
|
-
assert_equal(
|
168
|
+
assert_equal('$VERBOSE =', zis.read(10))
|
156
169
|
assert_equal(false, zis.eof?)
|
157
|
-
|
170
|
+
end
|
158
171
|
end
|
159
172
|
|
160
173
|
def test_ungetc
|
@@ -163,8 +176,7 @@ class ZipInputStreamTest < MiniTest::Test
|
|
163
176
|
first_line = zis.gets.chomp
|
164
177
|
first_line.reverse.bytes.each { |b| zis.ungetc(b) }
|
165
178
|
assert_equal('#!/usr/bin/env ruby', zis.gets.chomp)
|
166
|
-
assert_equal(
|
179
|
+
assert_equal('$VERBOSE =', zis.read(10))
|
167
180
|
end
|
168
181
|
end
|
169
|
-
|
170
182
|
end
|
@@ -6,7 +6,7 @@ class AbstractInputStreamTest < MiniTest::Test
|
|
6
6
|
|
7
7
|
TEST_LINES = ["Hello world#{$/}",
|
8
8
|
"this is the second line#{$/}",
|
9
|
-
|
9
|
+
'this is the last line']
|
10
10
|
TEST_STRING = TEST_LINES.join
|
11
11
|
class TestAbstractInputStream
|
12
12
|
include ::Zip::IOExtras::AbstractInputStream
|
@@ -17,10 +17,10 @@ class AbstractInputStreamTest < MiniTest::Test
|
|
17
17
|
@readPointer = 0
|
18
18
|
end
|
19
19
|
|
20
|
-
def sysread(charsToRead,
|
21
|
-
retVal
|
22
|
-
@readPointer+=charsToRead
|
23
|
-
|
20
|
+
def sysread(charsToRead, _buf = nil)
|
21
|
+
retVal = @contents[@readPointer, charsToRead]
|
22
|
+
@readPointer += charsToRead
|
23
|
+
retVal
|
24
24
|
end
|
25
25
|
|
26
26
|
def produce_input
|
@@ -28,7 +28,7 @@ class AbstractInputStreamTest < MiniTest::Test
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def input_finished?
|
31
|
-
@contents[@readPointer]
|
31
|
+
@contents[@readPointer].nil?
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -48,44 +48,43 @@ class AbstractInputStreamTest < MiniTest::Test
|
|
48
48
|
assert_equal(4, @io.lineno)
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
52
|
-
assert_equal(
|
53
|
-
assert_equal("o world#{$/}this is the second l", @io.gets(
|
51
|
+
def test_gets_multi_char_seperator
|
52
|
+
assert_equal('Hell', @io.gets('ll'))
|
53
|
+
assert_equal("o world#{$/}this is the second l", @io.gets('d l'))
|
54
54
|
end
|
55
55
|
|
56
56
|
LONG_LINES = [
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
'x' * 48 + "\r\n",
|
58
|
+
'y' * 49 + "\r\n",
|
59
|
+
'rest'
|
60
60
|
]
|
61
61
|
|
62
|
-
def
|
62
|
+
def test_gets_mulit_char_seperator_split
|
63
63
|
io = TestAbstractInputStream.new(LONG_LINES.join)
|
64
64
|
assert_equal(LONG_LINES[0], io.gets("\r\n"))
|
65
65
|
assert_equal(LONG_LINES[1], io.gets("\r\n"))
|
66
66
|
assert_equal(LONG_LINES[2], io.gets("\r\n"))
|
67
67
|
end
|
68
68
|
|
69
|
-
def
|
69
|
+
def test_gets_with_sep_and_index
|
70
70
|
io = TestAbstractInputStream.new(LONG_LINES.join)
|
71
71
|
assert_equal('x', io.gets("\r\n", 1))
|
72
|
-
assert_equal('x'*47 + "\r", io.gets("\r\n", 48))
|
72
|
+
assert_equal('x' * 47 + "\r", io.gets("\r\n", 48))
|
73
73
|
assert_equal("\n", io.gets(nil, 1))
|
74
74
|
assert_equal('yy', io.gets(nil, 2))
|
75
75
|
end
|
76
76
|
|
77
|
-
def
|
77
|
+
def test_gets_with_index
|
78
78
|
assert_equal(TEST_LINES[0], @io.gets(100))
|
79
79
|
assert_equal('this', @io.gets(4))
|
80
80
|
end
|
81
81
|
|
82
82
|
def test_each_line
|
83
|
-
lineNumber=0
|
84
|
-
@io.each_line
|
85
|
-
|line|
|
83
|
+
lineNumber = 0
|
84
|
+
@io.each_line do |line|
|
86
85
|
assert_equal(TEST_LINES[lineNumber], line)
|
87
|
-
lineNumber+=1
|
88
|
-
|
86
|
+
lineNumber += 1
|
87
|
+
end
|
89
88
|
end
|
90
89
|
|
91
90
|
def test_readlines
|
@@ -96,7 +95,7 @@ class AbstractInputStreamTest < MiniTest::Test
|
|
96
95
|
test_gets
|
97
96
|
begin
|
98
97
|
@io.readline
|
99
|
-
fail
|
98
|
+
fail 'EOFError expected'
|
100
99
|
rescue EOFError
|
101
100
|
end
|
102
101
|
end
|