rubyzip 1.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +89 -43
  3. data/Rakefile +3 -0
  4. data/lib/zip.rb +14 -3
  5. data/lib/zip/central_directory.rb +12 -8
  6. data/lib/zip/compressor.rb +1 -2
  7. data/lib/zip/constants.rb +55 -3
  8. data/lib/zip/crypto/decrypted_io.rb +40 -0
  9. data/lib/zip/crypto/null_encryption.rb +2 -4
  10. data/lib/zip/crypto/traditional_encryption.rb +9 -9
  11. data/lib/zip/decompressor.rb +20 -2
  12. data/lib/zip/dos_time.rb +13 -8
  13. data/lib/zip/entry.rb +115 -80
  14. data/lib/zip/entry_set.rb +6 -4
  15. data/lib/zip/errors.rb +2 -0
  16. data/lib/zip/extra_field.rb +12 -10
  17. data/lib/zip/extra_field/generic.rb +10 -9
  18. data/lib/zip/extra_field/ntfs.rb +4 -0
  19. data/lib/zip/extra_field/old_unix.rb +3 -1
  20. data/lib/zip/extra_field/universal_time.rb +42 -12
  21. data/lib/zip/extra_field/unix.rb +3 -1
  22. data/lib/zip/extra_field/zip64.rb +4 -2
  23. data/lib/zip/extra_field/zip64_placeholder.rb +1 -2
  24. data/lib/zip/file.rb +136 -100
  25. data/lib/zip/filesystem.rb +199 -179
  26. data/lib/zip/inflater.rb +24 -36
  27. data/lib/zip/input_stream.rb +37 -27
  28. data/lib/zip/ioextras.rb +1 -1
  29. data/lib/zip/ioextras/abstract_input_stream.rb +20 -9
  30. data/lib/zip/ioextras/abstract_output_stream.rb +4 -4
  31. data/lib/zip/null_decompressor.rb +1 -9
  32. data/lib/zip/output_stream.rb +19 -10
  33. data/lib/zip/pass_thru_compressor.rb +2 -2
  34. data/lib/zip/pass_thru_decompressor.rb +14 -23
  35. data/lib/zip/streamable_directory.rb +3 -3
  36. data/lib/zip/streamable_stream.rb +6 -10
  37. data/lib/zip/version.rb +1 -1
  38. data/samples/example.rb +2 -2
  39. data/samples/example_filesystem.rb +1 -1
  40. data/samples/example_recursive.rb +15 -18
  41. data/samples/gtk_ruby_zip.rb +20 -20
  42. data/samples/qtzip.rb +7 -7
  43. data/samples/write_simple.rb +2 -4
  44. data/samples/zipfind.rb +23 -22
  45. metadata +41 -130
  46. data/test/basic_zip_file_test.rb +0 -60
  47. data/test/case_sensitivity_test.rb +0 -69
  48. data/test/central_directory_entry_test.rb +0 -69
  49. data/test/central_directory_test.rb +0 -100
  50. data/test/crypto/null_encryption_test.rb +0 -53
  51. data/test/crypto/traditional_encryption_test.rb +0 -80
  52. data/test/data/WarnInvalidDate.zip +0 -0
  53. data/test/data/file1.txt +0 -46
  54. data/test/data/file1.txt.deflatedData +0 -0
  55. data/test/data/file2.txt +0 -1504
  56. data/test/data/globTest.zip +0 -0
  57. data/test/data/globTest/foo.txt +0 -0
  58. data/test/data/globTest/foo/bar/baz/foo.txt +0 -0
  59. data/test/data/globTest/food.txt +0 -0
  60. data/test/data/mimetype +0 -1
  61. data/test/data/notzippedruby.rb +0 -7
  62. data/test/data/ntfs.zip +0 -0
  63. data/test/data/oddExtraField.zip +0 -0
  64. data/test/data/rubycode.zip +0 -0
  65. data/test/data/rubycode2.zip +0 -0
  66. data/test/data/test.xls +0 -0
  67. data/test/data/testDirectory.bin +0 -0
  68. data/test/data/zip64-sample.zip +0 -0
  69. data/test/data/zipWithDirs.zip +0 -0
  70. data/test/data/zipWithEncryption.zip +0 -0
  71. data/test/deflater_test.rb +0 -65
  72. data/test/encryption_test.rb +0 -42
  73. data/test/entry_set_test.rb +0 -152
  74. data/test/entry_test.rb +0 -163
  75. data/test/errors_test.rb +0 -34
  76. data/test/extra_field_test.rb +0 -76
  77. data/test/file_extract_directory_test.rb +0 -54
  78. data/test/file_extract_test.rb +0 -83
  79. data/test/file_permissions_test.rb +0 -69
  80. data/test/file_split_test.rb +0 -57
  81. data/test/file_test.rb +0 -563
  82. data/test/filesystem/dir_iterator_test.rb +0 -58
  83. data/test/filesystem/directory_test.rb +0 -121
  84. data/test/filesystem/file_mutating_test.rb +0 -88
  85. data/test/filesystem/file_nonmutating_test.rb +0 -508
  86. data/test/filesystem/file_stat_test.rb +0 -64
  87. data/test/gentestfiles.rb +0 -122
  88. data/test/inflater_test.rb +0 -14
  89. data/test/input_stream_test.rb +0 -182
  90. data/test/ioextras/abstract_input_stream_test.rb +0 -102
  91. data/test/ioextras/abstract_output_stream_test.rb +0 -106
  92. data/test/ioextras/fake_io_test.rb +0 -18
  93. data/test/local_entry_test.rb +0 -154
  94. data/test/output_stream_test.rb +0 -128
  95. data/test/pass_thru_compressor_test.rb +0 -30
  96. data/test/pass_thru_decompressor_test.rb +0 -14
  97. data/test/samples/example_recursive_test.rb +0 -37
  98. data/test/settings_test.rb +0 -95
  99. data/test/test_helper.rb +0 -221
  100. data/test/unicode_file_names_and_comments_test.rb +0 -50
  101. data/test/zip64_full_test.rb +0 -51
  102. data/test/zip64_support_test.rb +0 -14
@@ -1,64 +0,0 @@
1
- require 'test_helper'
2
- require 'zip/filesystem'
3
-
4
- class ZipFsFileStatTest < MiniTest::Test
5
- def setup
6
- @zip_file = ::Zip::File.new('test/data/zipWithDirs.zip')
7
- end
8
-
9
- def teardown
10
- @zip_file.close if @zip_file
11
- end
12
-
13
- def test_blocks
14
- assert_equal(nil, @zip_file.file.stat('file1').blocks)
15
- end
16
-
17
- def test_ino
18
- assert_equal(0, @zip_file.file.stat('file1').ino)
19
- end
20
-
21
- def test_uid
22
- assert_equal(0, @zip_file.file.stat('file1').uid)
23
- end
24
-
25
- def test_gid
26
- assert_equal(0, @zip_file.file.stat('file1').gid)
27
- end
28
-
29
- def test_ftype
30
- assert_equal('file', @zip_file.file.stat('file1').ftype)
31
- assert_equal('directory', @zip_file.file.stat('dir1').ftype)
32
- end
33
-
34
- def test_mode
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)
39
- end
40
-
41
- def test_dev
42
- assert_equal(0, @zip_file.file.stat('file1').dev)
43
- end
44
-
45
- def test_rdev
46
- assert_equal(0, @zip_file.file.stat('file1').rdev)
47
- end
48
-
49
- def test_rdev_major
50
- assert_equal(0, @zip_file.file.stat('file1').rdev_major)
51
- end
52
-
53
- def test_rdev_minor
54
- assert_equal(0, @zip_file.file.stat('file1').rdev_minor)
55
- end
56
-
57
- def test_nlink
58
- assert_equal(1, @zip_file.file.stat('file1').nlink)
59
- end
60
-
61
- def test_blksize
62
- assert_nil(@zip_file.file.stat('file1').blksize)
63
- end
64
- end
@@ -1,122 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $VERBOSE = true
4
-
5
- class TestFiles
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
-
12
- EMPTY_TEST_DIR = 'test/data/generated/emptytestdir'
13
-
14
- ASCII_TEST_FILES = [RANDOM_ASCII_FILE1, RANDOM_ASCII_FILE2, RANDOM_ASCII_FILE3]
15
- BINARY_TEST_FILES = [RANDOM_BINARY_FILE1, RANDOM_BINARY_FILE2]
16
- TEST_DIRECTORIES = [EMPTY_TEST_DIR]
17
- TEST_FILES = [ASCII_TEST_FILES, BINARY_TEST_FILES, EMPTY_TEST_DIR].flatten!
18
-
19
- class << self
20
- def create_test_files
21
- Dir.mkdir 'test/data/generated' unless Dir.exist?('test/data/generated')
22
-
23
- ASCII_TEST_FILES.each_with_index do |filename, index|
24
- create_random_ascii(filename, 1E4 * (index + 1))
25
- end
26
-
27
- BINARY_TEST_FILES.each_with_index do |filename, index|
28
- create_random_binary(filename, 1E4 * (index + 1))
29
- end
30
-
31
- ensure_dir(EMPTY_TEST_DIR)
32
- end
33
-
34
- private
35
-
36
- def create_random_ascii(filename, size)
37
- File.open(filename, 'wb') do |file|
38
- file << rand while file.tell < size
39
- end
40
- end
41
-
42
- def create_random_binary(filename, size)
43
- File.open(filename, 'wb') do |file|
44
- file << [rand].pack('V') while file.tell < size
45
- end
46
- end
47
-
48
- def ensure_dir(name)
49
- if File.exist?(name)
50
- return if File.stat(name).directory?
51
- File.delete(name)
52
- end
53
- Dir.mkdir(name)
54
- end
55
- end
56
- end
57
-
58
- # For representation and creation of
59
- # test data
60
- class TestZipFile
61
- attr_accessor :zip_name, :entry_names, :comment
62
-
63
- def initialize(zip_name, entry_names, comment = '')
64
- @zip_name = zip_name
65
- @entry_names = entry_names
66
- @comment = comment
67
- end
68
-
69
- def self.create_test_zips
70
- raise "failed to create test zip '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP1.zip_name} test/data/file2.txt")
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")
72
-
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')
76
-
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
82
- end
83
-
84
- testBinaryPattern = ''
85
- File.open('test/data/generated/empty.zip') { |file| testBinaryPattern = file.read }
86
- testBinaryPattern *= 4
87
-
88
- File.open('test/data/generated/longBinary.bin', 'wb') do |file|
89
- file << testBinaryPattern << rand << "\0" while file.tell < 6E5
90
- end
91
-
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(' ')}")
93
-
94
- if RUBY_PLATFORM =~ /mswin|mingw|cygwin/
95
- raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless system("echo #{TEST_ZIP2.comment}| /usr/bin/zip -z #{TEST_ZIP2.zip_name}\"")
96
- else
97
- # without bash system interprets everything after echo as parameters to
98
- # echo including | zip -z ...
99
- raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless system("bash -c \"echo #{TEST_ZIP2.comment} | /usr/bin/zip -z #{TEST_ZIP2.zip_name}\"")
100
- end
101
-
102
- raise "failed to create test zip '#{TEST_ZIP3.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP3.zip_name} #{TEST_ZIP3.entry_names.join(' ')}")
103
-
104
- raise "failed to create test zip '#{TEST_ZIP4.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP4.zip_name} #{TEST_ZIP4.entry_names.join(' ')}")
105
- rescue
106
- # If there are any Windows developers wanting to use a command line zip.exe
107
- # to help create the following files, there's a free one available from
108
- # http://stahlworks.com/dev/index.php?tool=zipunzip
109
- # that works with the above code
110
- raise $!.to_s +
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.'
114
- end
115
-
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])
122
- end
@@ -1,14 +0,0 @@
1
- require 'test_helper'
2
- class InflaterTest < MiniTest::Test
3
- include DecompressorTests
4
-
5
- def setup
6
- super
7
- @file = File.new('test/data/file1.txt.deflatedData', 'rb')
8
- @decompressor = ::Zip::Inflater.new(@file)
9
- end
10
-
11
- def teardown
12
- @file.close
13
- end
14
- end
@@ -1,182 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ZipInputStreamTest < MiniTest::Test
4
- include AssertEntry
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
-
16
- def test_new
17
- zis = ::Zip::InputStream.new(TestZipFile::TEST_ZIP2.zip_name)
18
- assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
19
- assert_equal(true, zis.eof?)
20
- zis.close
21
- end
22
-
23
- def test_open_with_block
24
- ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
25
- assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
26
- assert_equal(true, zis.eof?)
27
- end
28
- end
29
-
30
- def test_open_without_block
31
- zis = ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, 'rb'))
32
- assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
33
- end
34
-
35
- def test_open_buffer_with_block
36
- ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, 'rb')) do |zis|
37
- assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
38
- assert_equal(true, zis.eof?)
39
- end
40
- end
41
-
42
- def test_open_string_io_without_block
43
- string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
44
- zis = ::Zip::InputStream.open(string_io)
45
- assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
46
- end
47
-
48
- def test_open_string_io_with_block
49
- string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
50
- ::Zip::InputStream.open(string_io) do |zis|
51
- assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
52
- assert_equal(true, zis.eof?)
53
- end
54
- end
55
-
56
- def test_open_buffer_without_block
57
- zis = ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
58
- assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
59
- end
60
-
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|
70
- entry = zis.get_next_entry # longAscii.txt
71
- assert_equal(false, zis.eof?)
72
- assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name)
73
- assert zis.gets.length > 0
74
- assert_equal(false, zis.eof?)
75
- entry = zis.get_next_entry # empty.txt
76
- assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
77
- assert_equal(0, entry.size)
78
- assert_equal(nil, zis.gets)
79
- assert_equal(true, zis.eof?)
80
- entry = zis.get_next_entry # empty_chmod640.txt
81
- assert_equal(TestZipFile::TEST_ZIP2.entry_names[2], entry.name)
82
- assert_equal(0, entry.size)
83
- assert_equal(nil, zis.gets)
84
- assert_equal(true, zis.eof?)
85
- entry = zis.get_next_entry # short.txt
86
- assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
87
- assert zis.gets.length > 0
88
- entry = zis.get_next_entry # longBinary.bin
89
- assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
90
- assert zis.gets.length > 0
91
- end
92
- end
93
-
94
- def test_incomplete_reads_from_string_io
95
- string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
96
- ::Zip::InputStream.open(string_io) do |zis|
97
- entry = zis.get_next_entry # longAscii.txt
98
- assert_equal(false, zis.eof?)
99
- assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name)
100
- assert zis.gets.length > 0
101
- assert_equal(false, zis.eof?)
102
- entry = zis.get_next_entry # empty.txt
103
- assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
104
- assert_equal(0, entry.size)
105
- assert_equal(nil, zis.gets)
106
- assert_equal(true, zis.eof?)
107
- entry = zis.get_next_entry # empty_chmod640.txt
108
- assert_equal(TestZipFile::TEST_ZIP2.entry_names[2], entry.name)
109
- assert_equal(0, entry.size)
110
- assert_equal(nil, zis.gets)
111
- assert_equal(true, zis.eof?)
112
- entry = zis.get_next_entry # short.txt
113
- assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
114
- assert zis.gets.length > 0
115
- entry = zis.get_next_entry # longBinary.bin
116
- assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
117
- assert zis.gets.length > 0
118
- end
119
- end
120
-
121
- def test_read_with_number_of_bytes_returns_nil_at_eof
122
- ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
123
- entry = zis.get_next_entry # longAscii.txt
124
- zis.read(entry.size)
125
- assert_equal(true, zis.eof?)
126
- assert_nil(zis.read(1))
127
- assert_nil(zis.read(1))
128
- end
129
- end
130
-
131
- def test_rewind
132
- ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
133
- e = zis.get_next_entry
134
- assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], e.name)
135
-
136
- # Do a little reading
137
- buf = ''
138
- buf << zis.read(100)
139
- assert_equal(100, zis.pos)
140
- buf << (zis.gets || '')
141
- buf << (zis.gets || '')
142
- assert_equal(false, zis.eof?)
143
-
144
- zis.rewind
145
-
146
- buf2 = ''
147
- buf2 << zis.read(100)
148
- buf2 << (zis.gets || '')
149
- buf2 << (zis.gets || '')
150
-
151
- assert_equal(buf, buf2)
152
-
153
- zis.rewind
154
- assert_equal(false, zis.eof?)
155
- assert_equal(0, zis.pos)
156
-
157
- assert_entry(e.name, zis, e.name)
158
- end
159
- end
160
-
161
- def test_mix_read_and_gets
162
- ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
163
- zis.get_next_entry
164
- assert_equal('#!/usr/bin/env ruby', zis.gets.chomp)
165
- assert_equal(false, zis.eof?)
166
- assert_equal('', zis.gets.chomp)
167
- assert_equal(false, zis.eof?)
168
- assert_equal('$VERBOSE =', zis.read(10))
169
- assert_equal(false, zis.eof?)
170
- end
171
- end
172
-
173
- def test_ungetc
174
- ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
175
- zis.get_next_entry
176
- first_line = zis.gets.chomp
177
- first_line.reverse.bytes.each { |b| zis.ungetc(b) }
178
- assert_equal('#!/usr/bin/env ruby', zis.gets.chomp)
179
- assert_equal('$VERBOSE =', zis.read(10))
180
- end
181
- end
182
- end
@@ -1,102 +0,0 @@
1
- require 'test_helper'
2
- require 'zip/ioextras'
3
-
4
- class AbstractInputStreamTest < MiniTest::Test
5
- # AbstractInputStream subclass that provides a read method
6
-
7
- TEST_LINES = ["Hello world#{$/}",
8
- "this is the second line#{$/}",
9
- 'this is the last line']
10
- TEST_STRING = TEST_LINES.join
11
- class TestAbstractInputStream
12
- include ::Zip::IOExtras::AbstractInputStream
13
-
14
- def initialize(aString)
15
- super()
16
- @contents = aString
17
- @readPointer = 0
18
- end
19
-
20
- def sysread(charsToRead, _buf = nil)
21
- retVal = @contents[@readPointer, charsToRead]
22
- @readPointer += charsToRead
23
- retVal
24
- end
25
-
26
- def produce_input
27
- sysread(100)
28
- end
29
-
30
- def input_finished?
31
- @contents[@readPointer].nil?
32
- end
33
- end
34
-
35
- def setup
36
- @io = TestAbstractInputStream.new(TEST_STRING)
37
- end
38
-
39
- def test_gets
40
- assert_equal(TEST_LINES[0], @io.gets)
41
- assert_equal(1, @io.lineno)
42
- assert_equal(TEST_LINES[0].length, @io.pos)
43
- assert_equal(TEST_LINES[1], @io.gets)
44
- assert_equal(2, @io.lineno)
45
- assert_equal(TEST_LINES[2], @io.gets)
46
- assert_equal(3, @io.lineno)
47
- assert_equal(nil, @io.gets)
48
- assert_equal(4, @io.lineno)
49
- end
50
-
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
- end
55
-
56
- LONG_LINES = [
57
- 'x' * 48 + "\r\n",
58
- 'y' * 49 + "\r\n",
59
- 'rest'
60
- ]
61
-
62
- def test_gets_mulit_char_seperator_split
63
- io = TestAbstractInputStream.new(LONG_LINES.join)
64
- assert_equal(LONG_LINES[0], io.gets("\r\n"))
65
- assert_equal(LONG_LINES[1], io.gets("\r\n"))
66
- assert_equal(LONG_LINES[2], io.gets("\r\n"))
67
- end
68
-
69
- def test_gets_with_sep_and_index
70
- io = TestAbstractInputStream.new(LONG_LINES.join)
71
- assert_equal('x', io.gets("\r\n", 1))
72
- assert_equal('x' * 47 + "\r", io.gets("\r\n", 48))
73
- assert_equal("\n", io.gets(nil, 1))
74
- assert_equal('yy', io.gets(nil, 2))
75
- end
76
-
77
- def test_gets_with_index
78
- assert_equal(TEST_LINES[0], @io.gets(100))
79
- assert_equal('this', @io.gets(4))
80
- end
81
-
82
- def test_each_line
83
- lineNumber = 0
84
- @io.each_line do |line|
85
- assert_equal(TEST_LINES[lineNumber], line)
86
- lineNumber += 1
87
- end
88
- end
89
-
90
- def test_readlines
91
- assert_equal(TEST_LINES, @io.readlines)
92
- end
93
-
94
- def test_readline
95
- test_gets
96
- begin
97
- @io.readline
98
- fail 'EOFError expected'
99
- rescue EOFError
100
- end
101
- end
102
- end