aboutsummaryrefslogtreecommitdiffstats
path: root/spec/rubyspec/library
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubyspec/library')
-rw-r--r--spec/rubyspec/library/bigdecimal/gt_spec.rb15
-rw-r--r--spec/rubyspec/library/bigdecimal/gte_spec.rb15
-rw-r--r--spec/rubyspec/library/bigdecimal/lt_spec.rb15
-rw-r--r--spec/rubyspec/library/bigdecimal/lte_spec.rb15
-rw-r--r--spec/rubyspec/library/date/shared/jd.rb2
-rw-r--r--spec/rubyspec/library/matrix/regular_spec.rb14
-rw-r--r--spec/rubyspec/library/matrix/singular_spec.rb14
-rw-r--r--spec/rubyspec/library/net/ftp/fixtures/server.rb5
-rw-r--r--spec/rubyspec/library/rexml/element/add_attribute_spec.rb2
-rw-r--r--spec/rubyspec/library/rexml/text/wrap_spec.rb2
-rw-r--r--spec/rubyspec/library/securerandom/random_number_spec.rb48
-rw-r--r--spec/rubyspec/library/socket/basicsocket/getsockname_spec.rb2
-rw-r--r--spec/rubyspec/library/socket/socket/connect_nonblock_spec.rb1
-rw-r--r--spec/rubyspec/library/stringio/printf_spec.rb2
-rw-r--r--spec/rubyspec/library/stringscanner/shared/matched_size.rb2
-rw-r--r--spec/rubyspec/library/zlib/deflate/params_spec.rb17
-rw-r--r--spec/rubyspec/library/zlib/gzipreader/gets_spec.rb21
-rw-r--r--spec/rubyspec/library/zlib/gzipreader/readpartial_spec.rb17
-rw-r--r--spec/rubyspec/library/zlib/gzipreader/ungetbyte_spec.rb122
-rw-r--r--spec/rubyspec/library/zlib/gzipreader/ungetc_spec.rb291
-rw-r--r--spec/rubyspec/library/zlib/gzipwriter/mtime_spec.rb13
21 files changed, 595 insertions, 40 deletions
diff --git a/spec/rubyspec/library/bigdecimal/gt_spec.rb b/spec/rubyspec/library/bigdecimal/gt_spec.rb
index effd3ea35f..2f9ea4fd68 100644
--- a/spec/rubyspec/library/bigdecimal/gt_spec.rb
+++ b/spec/rubyspec/library/bigdecimal/gt_spec.rb
@@ -28,6 +28,10 @@ describe "BigDecimal#>" do
@infinity = BigDecimal("Infinity")
@infinity_neg = BigDecimal("-Infinity")
+
+ @float_infinity = Float::INFINITY
+ @float_infinity_neg = -Float::INFINITY
+
@nan = BigDecimal("NaN")
end
@@ -64,6 +68,17 @@ describe "BigDecimal#>" do
(@infinity_neg > @infinity).should == false
end
+ ruby_bug "#13674", ""..."2.4" do
+ it "properly handles Float infinity values" do
+ @values.each { |val|
+ (val > @float_infinity).should == false
+ (@float_infinity > val).should == true
+ (val > @float_infinity_neg).should == true
+ (@float_infinity_neg > val).should == false
+ }
+ end
+ end
+
it "properly handles NaN values" do
@values += [@infinity, @infinity_neg, @nan]
@values.each { |val|
diff --git a/spec/rubyspec/library/bigdecimal/gte_spec.rb b/spec/rubyspec/library/bigdecimal/gte_spec.rb
index 28e84690ad..aab5338ad6 100644
--- a/spec/rubyspec/library/bigdecimal/gte_spec.rb
+++ b/spec/rubyspec/library/bigdecimal/gte_spec.rb
@@ -28,6 +28,10 @@ describe "BigDecimal#>=" do
@infinity = BigDecimal("Infinity")
@infinity_neg = BigDecimal("-Infinity")
+
+ @float_infinity = Float::INFINITY
+ @float_infinity_neg = -Float::INFINITY
+
@nan = BigDecimal("NaN")
end
@@ -68,6 +72,17 @@ describe "BigDecimal#>=" do
(@infinity_neg >= @infinity).should == false
end
+ ruby_bug "#13674", ""..."2.4" do
+ it "properly handles Float infinity values" do
+ @values.each { |val|
+ (val >= @float_infinity).should == false
+ (@float_infinity >= val).should == true
+ (val >= @float_infinity_neg).should == true
+ (@float_infinity_neg >= val).should == false
+ }
+ end
+ end
+
it "properly handles NaN values" do
@values += [@infinity, @infinity_neg, @nan]
@values.each { |val|
diff --git a/spec/rubyspec/library/bigdecimal/lt_spec.rb b/spec/rubyspec/library/bigdecimal/lt_spec.rb
index 67811c5db4..089e7aef73 100644
--- a/spec/rubyspec/library/bigdecimal/lt_spec.rb
+++ b/spec/rubyspec/library/bigdecimal/lt_spec.rb
@@ -28,6 +28,10 @@ describe "BigDecimal#<" do
@infinity = BigDecimal("Infinity")
@infinity_neg = BigDecimal("-Infinity")
+
+ @float_infinity = Float::INFINITY
+ @float_infinity_neg = -Float::INFINITY
+
@nan = BigDecimal("NaN")
end
@@ -62,6 +66,17 @@ describe "BigDecimal#<" do
(@infinity_neg < @infinity).should == true
end
+ ruby_bug "#13674", ""..."2.4" do
+ it "properly handles Float infinity values" do
+ @values.each { |val|
+ (val < @float_infinity).should == true
+ (@float_infinity < val).should == false
+ (val < @float_infinity_neg).should == false
+ (@float_infinity_neg < val).should == true
+ }
+ end
+ end
+
it "properly handles NaN values" do
@values += [@infinity, @infinity_neg, @nan]
@values.each { |val|
diff --git a/spec/rubyspec/library/bigdecimal/lte_spec.rb b/spec/rubyspec/library/bigdecimal/lte_spec.rb
index 61fb676245..5cda9842bd 100644
--- a/spec/rubyspec/library/bigdecimal/lte_spec.rb
+++ b/spec/rubyspec/library/bigdecimal/lte_spec.rb
@@ -28,6 +28,10 @@ describe "BigDecimal#<=" do
@infinity = BigDecimal("Infinity")
@infinity_neg = BigDecimal("-Infinity")
+
+ @float_infinity = Float::INFINITY
+ @float_infinity_neg = -Float::INFINITY
+
@nan = BigDecimal("NaN")
end
@@ -68,6 +72,17 @@ describe "BigDecimal#<=" do
(@infinity_neg <= @infinity).should == true
end
+ ruby_bug "#13674", ""..."2.4" do
+ it "properly handles Float infinity values" do
+ @values.each { |val|
+ (val <= @float_infinity).should == true
+ (@float_infinity <= val).should == false
+ (val <= @float_infinity_neg).should == false
+ (@float_infinity_neg <= val).should == true
+ }
+ end
+ end
+
it "properly handles NaN values" do
@values += [@infinity, @infinity_neg, @nan]
@values.each { |val|
diff --git a/spec/rubyspec/library/date/shared/jd.rb b/spec/rubyspec/library/date/shared/jd.rb
index e47dbae1b8..511557b4f7 100644
--- a/spec/rubyspec/library/date/shared/jd.rb
+++ b/spec/rubyspec/library/date/shared/jd.rb
@@ -3,7 +3,7 @@ describe :date_jd, shared: true do
Date.send(@method, 2454482).should == Date.civil(2008, 1, 16)
end
- it "returns a Date object representing Julian day 0 (-4712-01-01) if no arguments passed"do
+ it "returns a Date object representing Julian day 0 (-4712-01-01) if no arguments passed" do
Date.send(@method).should == Date.civil(-4712, 1, 1)
end
diff --git a/spec/rubyspec/library/matrix/regular_spec.rb b/spec/rubyspec/library/matrix/regular_spec.rb
index a62a200d6d..2f0af99c1e 100644
--- a/spec/rubyspec/library/matrix/regular_spec.rb
+++ b/spec/rubyspec/library/matrix/regular_spec.rb
@@ -20,12 +20,12 @@ describe "Matrix#regular?" do
end
it "raises an error for rectangular matrices" do
- lambda {
- Matrix[[1], [2], [3]].regular?
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ lambda {
+ Matrix[[1], [2], [3]].regular?
+ }.should raise_error(Matrix::ErrDimensionMismatch)
- lambda {
- Matrix.empty(3,0).regular?
- }.should raise_error(Matrix::ErrDimensionMismatch)
- end
+ lambda {
+ Matrix.empty(3,0).regular?
+ }.should raise_error(Matrix::ErrDimensionMismatch)
+ end
end
diff --git a/spec/rubyspec/library/matrix/singular_spec.rb b/spec/rubyspec/library/matrix/singular_spec.rb
index 480621998f..83914befbe 100644
--- a/spec/rubyspec/library/matrix/singular_spec.rb
+++ b/spec/rubyspec/library/matrix/singular_spec.rb
@@ -19,13 +19,13 @@ describe "Matrix#singular?" do
end
it "raises an error for rectangular matrices" do
- lambda {
- Matrix[[1], [2], [3]].singular?
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ lambda {
+ Matrix[[1], [2], [3]].singular?
+ }.should raise_error(Matrix::ErrDimensionMismatch)
- lambda {
- Matrix.empty(3,0).singular?
- }.should raise_error(Matrix::ErrDimensionMismatch)
- end
+ lambda {
+ Matrix.empty(3,0).singular?
+ }.should raise_error(Matrix::ErrDimensionMismatch)
+ end
end
diff --git a/spec/rubyspec/library/net/ftp/fixtures/server.rb b/spec/rubyspec/library/net/ftp/fixtures/server.rb
index 2129835883..a6741820ff 100644
--- a/spec/rubyspec/library/net/ftp/fixtures/server.rb
+++ b/spec/rubyspec/library/net/ftp/fixtures/server.rb
@@ -35,10 +35,7 @@ module NetFTPSpecs
response @connect_message || "220 Dummy FTP Server ready!"
begin
- loop do
- command = @socket.recv(1024)
- break if command.nil?
-
+ while command = @socket.recv(1024)
command, argument = command.chomp.split(" ", 2)
if command == "QUIT"
diff --git a/spec/rubyspec/library/rexml/element/add_attribute_spec.rb b/spec/rubyspec/library/rexml/element/add_attribute_spec.rb
index 74eceee99b..998f5d6251 100644
--- a/spec/rubyspec/library/rexml/element/add_attribute_spec.rb
+++ b/spec/rubyspec/library/rexml/element/add_attribute_spec.rb
@@ -34,7 +34,7 @@ describe "REXML::Element#add_attribute" do
@person.attributes["male"].should == "true"
end
- it "returns the attribute added" do
+ it "returns the attribute added" do
attr = REXML::Attribute.new("name", "Tony")
@person.add_attribute(attr).should == attr
end
diff --git a/spec/rubyspec/library/rexml/text/wrap_spec.rb b/spec/rubyspec/library/rexml/text/wrap_spec.rb
index 9491e47fc8..a56759b0f4 100644
--- a/spec/rubyspec/library/rexml/text/wrap_spec.rb
+++ b/spec/rubyspec/library/rexml/text/wrap_spec.rb
@@ -14,7 +14,7 @@ describe "REXML::Text#wrap" do
@t.wrap("abc def", 10, false).should == "abc def"
end
- it "takes a newline at the beginning option as the third parameter"do
+ it "takes a newline at the beginning option as the third parameter" do
@t.wrap("abc def", 3, true).should == "\nabc\ndef"
end
end
diff --git a/spec/rubyspec/library/securerandom/random_number_spec.rb b/spec/rubyspec/library/securerandom/random_number_spec.rb
index 296da51be2..a23a457df2 100644
--- a/spec/rubyspec/library/securerandom/random_number_spec.rb
+++ b/spec/rubyspec/library/securerandom/random_number_spec.rb
@@ -12,6 +12,16 @@ describe "SecureRandom.random_number" do
end
end
+ it "generates a random (potentially bignum) integer value for bignum argument" do
+ max = 12345678901234567890
+ 11.times do
+ num = SecureRandom.random_number max
+ num.should be_kind_of(Integer)
+ (0 <= num).should == true
+ (num < max).should == true
+ end
+ end
+
it "generates a random float number between 0.0 and 1.0 if no argument provided" do
64.times do
num = SecureRandom.random_number
@@ -21,6 +31,37 @@ describe "SecureRandom.random_number" do
end
end
+ ruby_version_is "2.3" do
+ it "generates a random value in given (integer) range limits" do
+ 64.times do
+ num = SecureRandom.random_number 11...13
+ num.should be_kind_of(Integer)
+ (11 <= num).should == true
+ (num < 13).should == true
+ end
+ end
+
+ it "generates a random value in given big (integer) range limits" do
+ lower = 12345678901234567890
+ upper = 12345678901234567890 + 5
+ 32.times do
+ num = SecureRandom.random_number lower..upper
+ num.should be_kind_of(Integer)
+ (lower <= num).should == true
+ (num <= upper).should == true
+ end
+ end
+
+ it "generates a random value in given (float) range limits" do
+ 64.times do
+ num = SecureRandom.random_number 0.6..0.9
+ num.should be_kind_of(Float)
+ (0.6 <= num).should == true
+ (num <= 0.9).should == true
+ end
+ end
+ end
+
it "generates a random float number between 0.0 and 1.0 if argument is negative" do
num = SecureRandom.random_number(-10)
num.should be_kind_of(Float)
@@ -28,6 +69,13 @@ describe "SecureRandom.random_number" do
(num < 1.0).should == true
end
+ it "generates a random float number between 0.0 and 1.0 if argument is negative float" do
+ num = SecureRandom.random_number(-11.1)
+ num.should be_kind_of(Float)
+ (0.0 <= num).should == true
+ (num < 1.0).should == true
+ end
+
it "generates different float numbers with subsequent invocations" do
# quick and dirty check, but good enough
values = []
diff --git a/spec/rubyspec/library/socket/basicsocket/getsockname_spec.rb b/spec/rubyspec/library/socket/basicsocket/getsockname_spec.rb
index 8f8616bd2b..cb3a45eb5f 100644
--- a/spec/rubyspec/library/socket/basicsocket/getsockname_spec.rb
+++ b/spec/rubyspec/library/socket/basicsocket/getsockname_spec.rb
@@ -11,7 +11,7 @@ describe "Socket::BasicSocket#getsockname" do
@socket = TCPServer.new("127.0.0.1", 0)
sockaddr = Socket.unpack_sockaddr_in(@socket.getsockname)
sockaddr.should == [@socket.addr[1], "127.0.0.1"]
- end
+ end
it "works on sockets listening in ipaddr_any" do
@socket = TCPServer.new(0)
diff --git a/spec/rubyspec/library/socket/socket/connect_nonblock_spec.rb b/spec/rubyspec/library/socket/socket/connect_nonblock_spec.rb
index fd92c0740c..26bceabb51 100644
--- a/spec/rubyspec/library/socket/socket/connect_nonblock_spec.rb
+++ b/spec/rubyspec/library/socket/socket/connect_nonblock_spec.rb
@@ -14,6 +14,7 @@ describe "Socket#connect_nonblock" do
after :each do
@socket.close
+ @server.close
@thread.join if @thread
end
diff --git a/spec/rubyspec/library/stringio/printf_spec.rb b/spec/rubyspec/library/stringio/printf_spec.rb
index 0309480a9a..5f811547bc 100644
--- a/spec/rubyspec/library/stringio/printf_spec.rb
+++ b/spec/rubyspec/library/stringio/printf_spec.rb
@@ -27,7 +27,7 @@ describe "StringIO#printf" do
@io.printf("%d %04x", 123, 123)
@io.pos.should eql(16)
- end
+ end
end
describe "StringIO#printf when in append mode" do
diff --git a/spec/rubyspec/library/stringscanner/shared/matched_size.rb b/spec/rubyspec/library/stringscanner/shared/matched_size.rb
index 0d783dc92b..92174733f7 100644
--- a/spec/rubyspec/library/stringscanner/shared/matched_size.rb
+++ b/spec/rubyspec/library/stringscanner/shared/matched_size.rb
@@ -3,7 +3,7 @@ describe :strscan_matched_size, shared: true do
@s = StringScanner.new("This is a test")
end
- it "returns the size of the most recent match" do
+ it "returns the size of the most recent match" do
@s.check(/This/)
@s.send(@method).should == 4
@s.send(@method).should == 4
diff --git a/spec/rubyspec/library/zlib/deflate/params_spec.rb b/spec/rubyspec/library/zlib/deflate/params_spec.rb
index bb2fd3ee7c..59b1353c07 100644
--- a/spec/rubyspec/library/zlib/deflate/params_spec.rb
+++ b/spec/rubyspec/library/zlib/deflate/params_spec.rb
@@ -2,17 +2,16 @@ require File.expand_path('../../../../spec_helper', __FILE__)
require 'zlib'
describe "Zlib::Deflate#params" do
-it "changes the deflate parameters" do
- data = 'abcdefghijklm'
+ it "changes the deflate parameters" do
+ data = 'abcdefghijklm'
- d = Zlib::Deflate.new Zlib::NO_COMPRESSION, Zlib::MAX_WBITS,
- Zlib::DEF_MEM_LEVEL, Zlib::DEFAULT_STRATEGY
+ d = Zlib::Deflate.new Zlib::NO_COMPRESSION, Zlib::MAX_WBITS,
+ Zlib::DEF_MEM_LEVEL, Zlib::DEFAULT_STRATEGY
- d << data.slice!(0..10)
- d.params Zlib::BEST_COMPRESSION, Zlib::DEFAULT_STRATEGY
- d << data
+ d << data.slice!(0..10)
+ d.params Zlib::BEST_COMPRESSION, Zlib::DEFAULT_STRATEGY
+ d << data
- Zlib::Inflate.inflate(d.finish).should == 'abcdefghijklm'
+ Zlib::Inflate.inflate(d.finish).should == 'abcdefghijklm'
end
end
-
diff --git a/spec/rubyspec/library/zlib/gzipreader/gets_spec.rb b/spec/rubyspec/library/zlib/gzipreader/gets_spec.rb
index 6a4c1dadb4..d49adc2850 100644
--- a/spec/rubyspec/library/zlib/gzipreader/gets_spec.rb
+++ b/spec/rubyspec/library/zlib/gzipreader/gets_spec.rb
@@ -1 +1,22 @@
require File.expand_path('../../../../spec_helper', __FILE__)
+require 'zlib'
+require 'stringio'
+
+describe 'GzipReader#gets' do
+ describe 'with "" separator' do
+ it 'reads paragraphs skipping newlines' do
+ # gz contains "\n\n\n\n\n123\n45\n\n\n\n\nabc\nde\n\n\n\n\n"
+ gz = Zlib::GzipReader.new(
+ StringIO.new(
+ [31, 139, 8, 0, 223, 152, 48, 89, 0, 3, 227, 226, 2, 2, 67, 35,
+ 99, 46, 19, 83, 16, 139, 43, 49, 41, 153, 43, 37, 21, 204, 4, 0,
+ 32, 119, 45, 184, 27, 0, 0, 0].pack('C*')
+ )
+ )
+
+ gz.gets('').should == "123\n45\n\n"
+ gz.gets('').should == "abc\nde\n\n"
+ gz.eof?.should be_true
+ end
+ end
+end
diff --git a/spec/rubyspec/library/zlib/gzipreader/readpartial_spec.rb b/spec/rubyspec/library/zlib/gzipreader/readpartial_spec.rb
new file mode 100644
index 0000000000..2cdef54fd1
--- /dev/null
+++ b/spec/rubyspec/library/zlib/gzipreader/readpartial_spec.rb
@@ -0,0 +1,17 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'stringio'
+require 'zlib'
+
+describe 'GzipReader#readpartial' do
+ before :each do
+ @data = '12345abcde'
+ @zip = [31, 139, 8, 0, 44, 220, 209, 71, 0, 3, 51, 52, 50, 54, 49, 77,
+ 76, 74, 78, 73, 5, 0, 157, 5, 0, 36, 10, 0, 0, 0].pack('C*')
+ @io = StringIO.new(@zip)
+ end
+
+ it 'accepts nil buffer' do
+ gz = Zlib::GzipReader.new(@io)
+ gz.readpartial(5, nil).should == '12345'
+ end
+end
diff --git a/spec/rubyspec/library/zlib/gzipreader/ungetbyte_spec.rb b/spec/rubyspec/library/zlib/gzipreader/ungetbyte_spec.rb
new file mode 100644
index 0000000000..16f1c12272
--- /dev/null
+++ b/spec/rubyspec/library/zlib/gzipreader/ungetbyte_spec.rb
@@ -0,0 +1,122 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'stringio'
+require 'zlib'
+
+describe 'GzipReader#ungetbyte' do
+ before :each do
+ @data = '12345abcde'
+ @zip = [31, 139, 8, 0, 44, 220, 209, 71, 0, 3, 51, 52, 50, 54, 49, 77,
+ 76, 74, 78, 73, 5, 0, 157, 5, 0, 36, 10, 0, 0, 0].pack('C*')
+ @io = StringIO.new @zip
+ end
+
+ describe 'at the start of the stream' do
+ before :each do
+ @gz = Zlib::GzipReader.new(@io)
+ end
+
+ describe 'with an integer' do
+ it 'prepends the byte to the stream' do
+ @gz.ungetbyte 0x21
+ @gz.read.should == '!12345abcde'
+ end
+
+ ruby_bug "#13616", ""..."2.6" do
+ it 'decrements pos' do
+ @gz.ungetbyte 0x21
+ @gz.pos.should == -1
+ end
+ end
+ end
+
+ quarantine! do # https://bugs.ruby-lang.org/issues/13675
+ describe 'with nil' do
+ it 'does not prepend anything to the stream' do
+ @gz.ungetbyte nil
+ @gz.read.should == '12345abcde'
+ end
+
+ it 'does not decrement pos' do
+ @gz.ungetbyte nil
+ @gz.pos.should == 0
+ end
+ end
+ end
+ end
+
+ describe 'in the middle of the stream' do
+ before :each do
+ @gz = Zlib::GzipReader.new(@io)
+ @gz.read 5
+ end
+
+ describe 'with an integer' do
+ it 'inserts the corresponding character into the stream' do
+ @gz.ungetbyte 0x21
+ @gz.read.should == '!abcde'
+ end
+
+ it 'decrements pos' do
+ @gz.ungetbyte 0x21
+ @gz.pos.should == 4
+ end
+ end
+
+ quarantine! do # https://bugs.ruby-lang.org/issues/13675
+ describe 'with nil' do
+ it 'does not insert anything into the stream' do
+ @gz.ungetbyte nil
+ @gz.read.should == 'abcde'
+ end
+
+ it 'does not decrement pos' do
+ @gz.ungetbyte nil
+ @gz.pos.should == 5
+ end
+ end
+ end
+ end
+
+ describe 'at the end of the stream' do
+ before :each do
+ @gz = Zlib::GzipReader.new(@io)
+ @gz.read
+ end
+
+ describe 'with an integer' do
+ it 'appends the corresponding character to the stream' do
+ @gz.ungetbyte 0x21
+ @gz.read.should == '!'
+ end
+
+ it 'decrements pos' do
+ @gz.ungetbyte 0x21
+ @gz.pos.should == 9
+ end
+
+ it 'makes eof? false' do
+ @gz.ungetbyte 0x21
+ @gz.eof?.should be_false
+ end
+ end
+
+ quarantine! do # https://bugs.ruby-lang.org/issues/13675
+ describe 'with nil' do
+ it 'does not append anything to the stream' do
+ @gz.ungetbyte nil
+ @gz.read.should == ''
+ end
+
+ it 'does not decrement pos' do
+ @gz.ungetbyte nil
+ @gz.pos.should == 10
+ end
+
+ it 'does not make eof? false' do
+ @gz.ungetbyte nil
+ @gz.eof?.should be_true
+ end
+ end
+ end
+ end
+end
diff --git a/spec/rubyspec/library/zlib/gzipreader/ungetc_spec.rb b/spec/rubyspec/library/zlib/gzipreader/ungetc_spec.rb
index 6a4c1dadb4..2d218e8d19 100644
--- a/spec/rubyspec/library/zlib/gzipreader/ungetc_spec.rb
+++ b/spec/rubyspec/library/zlib/gzipreader/ungetc_spec.rb
@@ -1 +1,292 @@
require File.expand_path('../../../../spec_helper', __FILE__)
+require 'stringio'
+require 'zlib'
+
+describe 'GzipReader#ungetc' do
+ before :each do
+ @data = '12345abcde'
+ @zip = [31, 139, 8, 0, 44, 220, 209, 71, 0, 3, 51, 52, 50, 54, 49, 77,
+ 76, 74, 78, 73, 5, 0, 157, 5, 0, 36, 10, 0, 0, 0].pack('C*')
+ @io = StringIO.new @zip
+ end
+
+ describe 'at the start of the stream' do
+ before :each do
+ @gz = Zlib::GzipReader.new(@io, external_encoding: Encoding::UTF_8)
+ end
+
+ describe 'with a single-byte character' do
+ it 'prepends the character to the stream' do
+ @gz.ungetc 'x'
+ @gz.read.should == 'x12345abcde'
+ end
+
+ ruby_bug "#13616", ""..."2.6" do
+ it 'decrements pos' do
+ @gz.ungetc 'x'
+ @gz.pos.should == -1
+ end
+ end
+ end
+
+ describe 'with a multi-byte character' do
+ it 'prepends the character to the stream' do
+ @gz.ungetc 'ŷ'
+ @gz.read.should == 'ŷ12345abcde'
+ end
+
+ ruby_bug "#13616", ""..."2.6" do
+ it 'decrements pos' do
+ @gz.ungetc 'ŷ'
+ @gz.pos.should == -2
+ end
+ end
+ end
+
+ describe 'with a multi-character string' do
+ it 'prepends the characters to the stream' do
+ @gz.ungetc 'xŷž'
+ @gz.read.should == 'xŷž12345abcde'
+ end
+
+ ruby_bug "#13616", ""..."2.6" do
+ it 'decrements pos' do
+ @gz.ungetc 'xŷž'
+ @gz.pos.should == -5
+ end
+ end
+ end
+
+ describe 'with an integer' do
+ it 'prepends the corresponding character to the stream' do
+ @gz.ungetc 0x21
+ @gz.read.should == '!12345abcde'
+ end
+
+ ruby_bug "#13616", ""..."2.6" do
+ it 'decrements pos' do
+ @gz.ungetc 0x21
+ @gz.pos.should == -1
+ end
+ end
+ end
+
+ describe 'with an empty string' do
+ it 'does not prepend anything to the stream' do
+ @gz.ungetc ''
+ @gz.read.should == '12345abcde'
+ end
+
+ it 'does not decrement pos' do
+ @gz.ungetc ''
+ @gz.pos.should == 0
+ end
+ end
+
+ quarantine! do # https://bugs.ruby-lang.org/issues/13675
+ describe 'with nil' do
+ it 'does not prepend anything to the stream' do
+ @gz.ungetc nil
+ @gz.read.should == '12345abcde'
+ end
+
+ it 'does not decrement pos' do
+ @gz.ungetc nil
+ @gz.pos.should == 0
+ end
+ end
+ end
+ end
+
+ describe 'in the middle of the stream' do
+ before :each do
+ @gz = Zlib::GzipReader.new(@io, external_encoding: Encoding::UTF_8)
+ @gz.read 5
+ end
+
+ describe 'with a single-byte character' do
+ it 'inserts the character into the stream' do
+ @gz.ungetc 'x'
+ @gz.read.should == 'xabcde'
+ end
+
+ it 'decrements pos' do
+ @gz.ungetc 'x'
+ @gz.pos.should == 4
+ end
+ end
+
+ describe 'with a multi-byte character' do
+ it 'inserts the character into the stream' do
+ @gz.ungetc 'ŷ'
+ @gz.read.should == 'ŷabcde'
+ end
+
+ it 'decrements pos' do
+ @gz.ungetc 'ŷ'
+ @gz.pos.should == 3
+ end
+ end
+
+ describe 'with a multi-character string' do
+ it 'inserts the characters into the stream' do
+ @gz.ungetc 'xŷž'
+ @gz.read.should == 'xŷžabcde'
+ end
+
+ it 'decrements pos' do
+ @gz.ungetc 'xŷž'
+ @gz.pos.should == 0
+ end
+ end
+
+ describe 'with an integer' do
+ it 'inserts the corresponding character into the stream' do
+ @gz.ungetc 0x21
+ @gz.read.should == '!abcde'
+ end
+
+ it 'decrements pos' do
+ @gz.ungetc 0x21
+ @gz.pos.should == 4
+ end
+ end
+
+ describe 'with an empty string' do
+ it 'does not insert anything into the stream' do
+ @gz.ungetc ''
+ @gz.read.should == 'abcde'
+ end
+
+ it 'does not decrement pos' do
+ @gz.ungetc ''
+ @gz.pos.should == 5
+ end
+ end
+
+ quarantine! do # https://bugs.ruby-lang.org/issues/13675
+ describe 'with nil' do
+ it 'does not insert anything into the stream' do
+ @gz.ungetc nil
+ @gz.read.should == 'abcde'
+ end
+
+ it 'does not decrement pos' do
+ @gz.ungetc nil
+ @gz.pos.should == 5
+ end
+ end
+ end
+ end
+
+ describe 'at the end of the stream' do
+ before :each do
+ @gz = Zlib::GzipReader.new(@io, external_encoding: Encoding::UTF_8)
+ @gz.read
+ end
+
+ describe 'with a single-byte character' do
+ it 'appends the character to the stream' do
+ @gz.ungetc 'x'
+ @gz.read.should == 'x'
+ end
+
+ it 'decrements pos' do
+ @gz.ungetc 'x'
+ @gz.pos.should == 9
+ end
+
+ it 'makes eof? false' do
+ @gz.ungetc 'x'
+ @gz.eof?.should be_false
+ end
+ end
+
+ describe 'with a multi-byte character' do
+ it 'appends the character to the stream' do
+ @gz.ungetc 'ŷ'
+ @gz.read.should == 'ŷ'
+ end
+
+ it 'decrements pos' do
+ @gz.ungetc 'ŷ'
+ @gz.pos.should == 8
+ end
+
+ it 'makes eof? false' do
+ @gz.ungetc 'ŷ'
+ @gz.eof?.should be_false
+ end
+ end
+
+ describe 'with a multi-character string' do
+ it 'appends the characters to the stream' do
+ @gz.ungetc 'xŷž'
+ @gz.read.should == 'xŷž'
+ end
+
+ it 'decrements pos' do
+ @gz.ungetc 'xŷž'
+ @gz.pos.should == 5
+ end
+
+ it 'makes eof? false' do
+ @gz.ungetc 'xŷž'
+ @gz.eof?.should be_false
+ end
+ end
+
+ describe 'with an integer' do
+ it 'appends the corresponding character to the stream' do
+ @gz.ungetc 0x21
+ @gz.read.should == '!'
+ end
+
+ it 'decrements pos' do
+ @gz.ungetc 0x21
+ @gz.pos.should == 9
+ end
+
+ it 'makes eof? false' do
+ @gz.ungetc 0x21
+ @gz.eof?.should be_false
+ end
+ end
+
+ describe 'with an empty string' do
+ it 'does not append anything to the stream' do
+ @gz.ungetc ''
+ @gz.read.should == ''
+ end
+
+ it 'does not decrement pos' do
+ @gz.ungetc ''
+ @gz.pos.should == 10
+ end
+
+ it 'does not make eof? false' do
+ @gz.ungetc ''
+ @gz.eof?.should be_true
+ end
+ end
+
+ quarantine! do # https://bugs.ruby-lang.org/issues/13675
+ describe 'with nil' do
+ it 'does not append anything to the stream' do
+ @gz.ungetc nil
+ @gz.read.should == ''
+ end
+
+ it 'does not decrement pos' do
+ @gz.ungetc nil
+ @gz.pos.should == 10
+ end
+
+ it 'does not make eof? false' do
+ @gz.ungetc nil
+ @gz.eof?.should be_true
+ end
+ end
+ end
+ end
+end
diff --git a/spec/rubyspec/library/zlib/gzipwriter/mtime_spec.rb b/spec/rubyspec/library/zlib/gzipwriter/mtime_spec.rb
index f73d6e3226..af7a4ac735 100644
--- a/spec/rubyspec/library/zlib/gzipwriter/mtime_spec.rb
+++ b/spec/rubyspec/library/zlib/gzipwriter/mtime_spec.rb
@@ -17,14 +17,14 @@ describe "Zlib::GzipWriter#mtime=" do
@io.string[4, 4].should == [1,0,0,0].pack('C*')
end
-it "sets mtime using Time" do
- Zlib::GzipWriter.wrap @io do |gzio|
- gzio.mtime = Time.at 1
+ it "sets mtime using Time" do
+ Zlib::GzipWriter.wrap @io do |gzio|
+ gzio.mtime = Time.at 1
- gzio.mtime.should == Time.at(1)
- end
+ gzio.mtime.should == Time.at(1)
+ end
- @io.string[4, 4].should == [1,0,0,0].pack('C*')
+ @io.string[4, 4].should == [1,0,0,0].pack('C*')
end
it "raises if the header was written" do
@@ -36,4 +36,3 @@ it "sets mtime using Time" do
end
end
end
-