diff options
Diffstat (limited to 'spec/ruby/library/stringio')
25 files changed, 233 insertions, 357 deletions
diff --git a/spec/ruby/library/stringio/append_spec.rb b/spec/ruby/library/stringio/append_spec.rb index 5383e3e795..d0cf5550cd 100644 --- a/spec/ruby/library/stringio/append_spec.rb +++ b/spec/ruby/library/stringio/append_spec.rb @@ -29,6 +29,20 @@ describe "StringIO#<< when passed [Object]" do @io.string.should == "example\000\000\000\000\000\000\000\000just testing" end + ruby_version_is ""..."2.7" do + it "taints self's String when the passed argument is tainted" do + (@io << "test".taint) + @io.string.tainted?.should be_true + end + end + + ruby_version_is ""..."3.0" do + it "does not taint self when the passed argument is tainted" do + (@io << "test".taint) + @io.tainted?.should be_false + end + end + it "updates self's position" do @io << "test" @io.pos.should eql(4) diff --git a/spec/ruby/library/stringio/bytes_spec.rb b/spec/ruby/library/stringio/bytes_spec.rb new file mode 100644 index 0000000000..4ef7a490a5 --- /dev/null +++ b/spec/ruby/library/stringio/bytes_spec.rb @@ -0,0 +1,29 @@ +require_relative '../../spec_helper' +require 'stringio' +require_relative 'shared/each_byte' + +ruby_version_is ''...'3.0' do + describe "StringIO#bytes" do + before :each do + @verbose, $VERBOSE = $VERBOSE, nil + end + + after :each do + $VERBOSE = @verbose + end + + it_behaves_like :stringio_each_byte, :bytes + end + + describe "StringIO#bytes when self is not readable" do + before :each do + @verbose, $VERBOSE = $VERBOSE, nil + end + + after :each do + $VERBOSE = @verbose + end + + it_behaves_like :stringio_each_byte_not_readable, :bytes + end +end diff --git a/spec/ruby/library/stringio/chars_spec.rb b/spec/ruby/library/stringio/chars_spec.rb new file mode 100644 index 0000000000..58cba77634 --- /dev/null +++ b/spec/ruby/library/stringio/chars_spec.rb @@ -0,0 +1,29 @@ +require_relative '../../spec_helper' +require 'stringio' +require_relative 'shared/each_char' + +ruby_version_is ''...'3.0' do + describe "StringIO#chars" do + before :each do + @verbose, $VERBOSE = $VERBOSE, nil + end + + after :each do + $VERBOSE = @verbose + end + + it_behaves_like :stringio_each_char, :chars + end + + describe "StringIO#chars when self is not readable" do + before :each do + @verbose, $VERBOSE = $VERBOSE, nil + end + + after :each do + $VERBOSE = @verbose + end + + it_behaves_like :stringio_each_char_not_readable, :chars + end +end diff --git a/spec/ruby/library/stringio/codepoints_spec.rb b/spec/ruby/library/stringio/codepoints_spec.rb new file mode 100644 index 0000000000..ceaadefc32 --- /dev/null +++ b/spec/ruby/library/stringio/codepoints_spec.rb @@ -0,0 +1,19 @@ +# -*- encoding: utf-8 -*- +require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require_relative 'shared/codepoints' + +ruby_version_is ''...'3.0' do + # See redmine #1667 + describe "StringIO#codepoints" do + before :each do + @verbose, $VERBOSE = $VERBOSE, nil + end + + after :each do + $VERBOSE = @verbose + end + + it_behaves_like :stringio_codepoints, :codepoints + end +end diff --git a/spec/ruby/library/stringio/each_line_spec.rb b/spec/ruby/library/stringio/each_line_spec.rb index c68f7dae82..1389408399 100644 --- a/spec/ruby/library/stringio/each_line_spec.rb +++ b/spec/ruby/library/stringio/each_line_spec.rb @@ -17,7 +17,3 @@ end describe "StringIO#each_line when passed chomp" do it_behaves_like :stringio_each_chomp, :each_line end - -describe "StringIO#each_line when passed limit" do - it_behaves_like :stringio_each_limit, :each_line -end diff --git a/spec/ruby/library/stringio/each_spec.rb b/spec/ruby/library/stringio/each_spec.rb index 2c30ed5cda..a76460049b 100644 --- a/spec/ruby/library/stringio/each_spec.rb +++ b/spec/ruby/library/stringio/each_spec.rb @@ -17,11 +17,3 @@ end describe "StringIO#each when passed chomp" do it_behaves_like :stringio_each_chomp, :each end - -describe "StringIO#each when passed chomp" do - it_behaves_like :stringio_each_separator_and_chomp, :each -end - -describe "StringIO#each when passed limit" do - it_behaves_like :stringio_each_limit, :each -end diff --git a/spec/ruby/library/stringio/gets_spec.rb b/spec/ruby/library/stringio/gets_spec.rb index d597ec0e45..97429e6a29 100644 --- a/spec/ruby/library/stringio/gets_spec.rb +++ b/spec/ruby/library/stringio/gets_spec.rb @@ -171,10 +171,6 @@ describe "StringIO#gets when passed [limit]" do it "returns a blank string when passed a limit of 0" do @io.gets(0).should == "" end - - it "ignores it when passed a negative limit" do - @io.gets(-4).should == "this>is>an>example" - end end describe "StringIO#gets when passed [separator] and [limit]" do diff --git a/spec/ruby/library/stringio/initialize_spec.rb b/spec/ruby/library/stringio/initialize_spec.rb index 158c08488b..1e8096e3bb 100644 --- a/spec/ruby/library/stringio/initialize_spec.rb +++ b/spec/ruby/library/stringio/initialize_spec.rb @@ -163,91 +163,6 @@ describe "StringIO#initialize when passed [Object]" do end end -# NOTE: Synchronise with core/io/new_spec.rb (core/io/shared/new.rb) -describe "StringIO#initialize when passed keyword arguments" do - it "sets the mode based on the passed :mode option" do - io = StringIO.new("example", "r") - io.closed_read?.should be_false - io.closed_write?.should be_true - end - - it "accepts a mode argument set to nil with a valid :mode option" do - @io = StringIO.new('', nil, mode: "w") - @io.write("foo").should == 3 - end - - it "accepts a mode argument with a :mode option set to nil" do - @io = StringIO.new('', "w", mode: nil) - @io.write("foo").should == 3 - end - - it "sets binmode from :binmode option" do - @io = StringIO.new('', 'w', binmode: true) - @io.external_encoding.to_s.should == "ASCII-8BIT" # #binmode? isn't implemented in StringIO - end - - it "does not set binmode from false :binmode" do - @io = StringIO.new('', 'w', binmode: false) - @io.external_encoding.to_s.should == "UTF-8" # #binmode? isn't implemented in StringIO - end -end - -# NOTE: Synchronise with core/io/new_spec.rb (core/io/shared/new.rb) -describe "StringIO#initialize when passed keyword arguments and error happens" do - it "raises an error if passed encodings two ways" do - -> { - @io = StringIO.new('', 'w:ISO-8859-1', encoding: 'ISO-8859-1') - }.should raise_error(ArgumentError) - -> { - @io = StringIO.new('', 'w:ISO-8859-1', external_encoding: 'ISO-8859-1') - }.should raise_error(ArgumentError) - -> { - @io = StringIO.new('', 'w:ISO-8859-1:UTF-8', internal_encoding: 'ISO-8859-1') - }.should raise_error(ArgumentError) - end - - it "raises an error if passed matching binary/text mode two ways" do - -> { - @io = StringIO.new('', "wb", binmode: true) - }.should raise_error(ArgumentError) - -> { - @io = StringIO.new('', "wt", textmode: true) - }.should raise_error(ArgumentError) - - -> { - @io = StringIO.new('', "wb", textmode: false) - }.should raise_error(ArgumentError) - -> { - @io = StringIO.new('', "wt", binmode: false) - }.should raise_error(ArgumentError) - end - - it "raises an error if passed conflicting binary/text mode two ways" do - -> { - @io = StringIO.new('', "wb", binmode: false) - }.should raise_error(ArgumentError) - -> { - @io = StringIO.new('', "wt", textmode: false) - }.should raise_error(ArgumentError) - - -> { - @io = StringIO.new('', "wb", textmode: true) - }.should raise_error(ArgumentError) - -> { - @io = StringIO.new('', "wt", binmode: true) - }.should raise_error(ArgumentError) - end - - it "raises an error when trying to set both binmode and textmode" do - -> { - @io = StringIO.new('', "w", textmode: true, binmode: true) - }.should raise_error(ArgumentError) - -> { - @io = StringIO.new('', File::Constants::WRONLY, textmode: true, binmode: true) - }.should raise_error(ArgumentError) - end -end - describe "StringIO#initialize when passed no arguments" do before :each do @io = StringIO.allocate @@ -294,9 +209,14 @@ describe "StringIO#initialize sets" do io.string.encoding.should == Encoding::EUC_JP end - it "the #external_encoding to the encoding of the String when passed a String" do - s = ''.force_encoding(Encoding::EUC_JP) - io = StringIO.new(s) - io.external_encoding.should == Encoding::EUC_JP + guard_not -> { # [Bug #16497] + stringio_version = StringIO.const_defined?(:VERSION) ? StringIO::VERSION : "0.0.2" + version_is(stringio_version, "0.0.3"..."0.1.1") + } do + it "the #external_encoding to the encoding of the String when passed a String" do + s = ''.force_encoding(Encoding::EUC_JP) + io = StringIO.new(s) + io.external_encoding.should == Encoding::EUC_JP + end end end diff --git a/spec/ruby/library/stringio/lines_spec.rb b/spec/ruby/library/stringio/lines_spec.rb new file mode 100644 index 0000000000..42d11772ae --- /dev/null +++ b/spec/ruby/library/stringio/lines_spec.rb @@ -0,0 +1,53 @@ +require_relative '../../spec_helper' +require 'stringio' +require_relative 'shared/each' + +ruby_version_is ''...'3.0' do + describe "StringIO#lines when passed a separator" do + before :each do + @verbose, $VERBOSE = $VERBOSE, nil + end + + after :each do + $VERBOSE = @verbose + end + + it_behaves_like :stringio_each_separator, :lines + end + + describe "StringIO#lines when passed no arguments" do + before :each do + @verbose, $VERBOSE = $VERBOSE, nil + end + + after :each do + $VERBOSE = @verbose + end + + it_behaves_like :stringio_each_no_arguments, :lines + end + + describe "StringIO#lines when self is not readable" do + before :each do + @verbose, $VERBOSE = $VERBOSE, nil + end + + after :each do + $VERBOSE = @verbose + end + + it_behaves_like :stringio_each_not_readable, :lines + end + + describe "StringIO#lines when passed chomp" do + before :each do + @verbose, $VERBOSE = $VERBOSE, nil + end + + after :each do + $VERBOSE = @verbose + end + + it_behaves_like :stringio_each_chomp, :lines + end +end diff --git a/spec/ruby/library/stringio/new_spec.rb b/spec/ruby/library/stringio/new_spec.rb deleted file mode 100644 index 328455134e..0000000000 --- a/spec/ruby/library/stringio/new_spec.rb +++ /dev/null @@ -1,8 +0,0 @@ -require_relative '../../spec_helper' -require 'stringio' - -describe "StringIO.new" do - it "warns when called with a block" do - -> { eval("StringIO.new {}") }.should complain(/StringIO::new\(\) does not take block; use StringIO::open\(\) instead/) - end -end diff --git a/spec/ruby/library/stringio/open_spec.rb b/spec/ruby/library/stringio/open_spec.rb index 3068e19435..acab6e9056 100644 --- a/spec/ruby/library/stringio/open_spec.rb +++ b/spec/ruby/library/stringio/open_spec.rb @@ -167,14 +167,10 @@ describe "StringIO.open when passed [Object]" do io.should equal(ret) end - it "sets the mode to read-write (r+)" do + it "sets the mode to read-write" do io = StringIO.open("example") io.closed_read?.should be_false io.closed_write?.should be_false - - io = StringIO.new("example") - io.printf("%d", 123) - io.string.should == "123mple" end it "tries to convert the passed Object to a String using #to_str" do @@ -199,14 +195,10 @@ describe "StringIO.open when passed no arguments" do io.should equal(ret) end - it "sets the mode to read-write (r+)" do + it "sets the mode to read-write" do io = StringIO.open io.closed_read?.should be_false io.closed_write?.should be_false - - io = StringIO.new("example") - io.printf("%d", 123) - io.string.should == "123mple" end it "uses an empty String as the StringIO backend" do diff --git a/spec/ruby/library/stringio/printf_spec.rb b/spec/ruby/library/stringio/printf_spec.rb index f3f669a185..9dd1a3b410 100644 --- a/spec/ruby/library/stringio/printf_spec.rb +++ b/spec/ruby/library/stringio/printf_spec.rb @@ -4,7 +4,7 @@ require_relative '../../core/kernel/shared/sprintf' describe "StringIO#printf" do before :each do - @io = StringIO.new() + @io = StringIO.new('example') end it "returns nil" do @@ -12,9 +12,9 @@ describe "StringIO#printf" do end it "pads self with \\000 when the current position is after the end" do - @io.pos = 3 + @io.pos = 10 @io.printf("%d", 123) - @io.string.should == "\000\000\000123" + @io.string.should == "example\000\000\000123" end it "performs format conversion" do @@ -39,27 +39,6 @@ describe "StringIO#printf" do end end -describe "StringIO#printf when in read-write mode" do - before :each do - @io = StringIO.new("example", "r+") - end - - it "starts from the beginning" do - @io.printf("%s", "abcdefghijk") - @io.string.should == "abcdefghijk" - end - - it "does not truncate existing string" do - @io.printf("%s", "abc") - @io.string.should == "abcmple" - end - - it "correctly updates self's position" do - @io.printf("%s", "abc") - @io.pos.should eql(3) - end -end - describe "StringIO#printf when in append mode" do before :each do @io = StringIO.new("example", "a") diff --git a/spec/ruby/library/stringio/putc_spec.rb b/spec/ruby/library/stringio/putc_spec.rb index 1ce53b7ef2..223b3523e5 100644 --- a/spec/ruby/library/stringio/putc_spec.rb +++ b/spec/ruby/library/stringio/putc_spec.rb @@ -35,21 +35,6 @@ describe "StringIO#putc when passed [String]" do @io.putc("t") @io.pos.should == 3 end - - it "handles concurrent writes correctly" do - @io = StringIO.new - n = 8 - go = false - threads = n.times.map { |i| - Thread.new { - Thread.pass until go - @io.putc i.to_s - } - } - go = true - threads.each(&:join) - @io.string.size.should == n - end end describe "StringIO#putc when passed [Object]" do diff --git a/spec/ruby/library/stringio/puts_spec.rb b/spec/ruby/library/stringio/puts_spec.rb index 9c890262dd..a9f289a5a5 100644 --- a/spec/ruby/library/stringio/puts_spec.rb +++ b/spec/ruby/library/stringio/puts_spec.rb @@ -101,20 +101,6 @@ describe "StringIO#puts when passed 1 or more objects" do @io.puts '' @io.string.should == "\n" end - - it "handles concurrent writes correctly" do - n = 8 - go = false - threads = n.times.map { |i| - Thread.new { - Thread.pass until go - @io.puts i - } - } - go = true - threads.each(&:join) - @io.string.size.should == n.times.map { |i| "#{i}\n" }.join.size - end end describe "StringIO#puts when passed no arguments" do diff --git a/spec/ruby/library/stringio/read_nonblock_spec.rb b/spec/ruby/library/stringio/read_nonblock_spec.rb index d4ec56d9aa..2a8f926bd0 100644 --- a/spec/ruby/library/stringio/read_nonblock_spec.rb +++ b/spec/ruby/library/stringio/read_nonblock_spec.rb @@ -5,21 +5,10 @@ require_relative 'shared/sysread' describe "StringIO#read_nonblock when passed length, buffer" do it_behaves_like :stringio_read, :read_nonblock - - it "accepts :exception option" do - io = StringIO.new("example") - io.read_nonblock(3, buffer = "", exception: true) - buffer.should == "exa" - end end describe "StringIO#read_nonblock when passed length" do it_behaves_like :stringio_read_length, :read_nonblock - - it "accepts :exception option" do - io = StringIO.new("example") - io.read_nonblock(3, exception: true).should == "exa" - end end describe "StringIO#read_nonblock when passed nil" do diff --git a/spec/ruby/library/stringio/readline_spec.rb b/spec/ruby/library/stringio/readline_spec.rb index b794e5fade..94b67bc92d 100644 --- a/spec/ruby/library/stringio/readline_spec.rb +++ b/spec/ruby/library/stringio/readline_spec.rb @@ -128,23 +128,3 @@ describe "StringIO#readline when passed [chomp]" do io.readline(chomp: true).should == "this>is>an>example" end end - -describe "StringIO#readline when passed [limit]" do - before :each do - @io = StringIO.new("this>is>an>example") - end - - it "returns the data read until the limit is met" do - io = StringIO.new("this>is>an>example\n") - io.readline(3).should == "thi" - end - - it "returns a blank string when passed a limit of 0" do - @io.readline(0).should == "" - end - - it "ignores it when the limit is negative" do - seen = [] - @io.readline(-4).should == "this>is>an>example" - end -end diff --git a/spec/ruby/library/stringio/readlines_spec.rb b/spec/ruby/library/stringio/readlines_spec.rb index c471d0fd73..4b007787e2 100644 --- a/spec/ruby/library/stringio/readlines_spec.rb +++ b/spec/ruby/library/stringio/readlines_spec.rb @@ -98,21 +98,3 @@ describe "StringIO#readlines when passed [chomp]" do io.readlines(chomp: true).should == ["this>is", "an>example"] end end - -describe "StringIO#readlines when passed [limit]" do - before :each do - @io = StringIO.new("a b c d e\n1 2 3 4 5") - end - - it "returns the data read until the limit is met" do - @io.readlines(4).should == ["a b ", "c d ", "e\n", "1 2 ", "3 4 ", "5"] - end - - it "raises ArgumentError when limit is 0" do - -> { @io.readlines(0) }.should raise_error(ArgumentError) - end - - it "ignores it when the limit is negative" do - @io.readlines(-4).should == ["a b c d e\n", "1 2 3 4 5"] - end -end diff --git a/spec/ruby/library/stringio/reopen_spec.rb b/spec/ruby/library/stringio/reopen_spec.rb index 9851c5b706..6752cf9970 100644 --- a/spec/ruby/library/stringio/reopen_spec.rb +++ b/spec/ruby/library/stringio/reopen_spec.rb @@ -23,6 +23,17 @@ describe "StringIO#reopen when passed [Object, Integer]" do @io.string.should == "reopened, another time" end + ruby_version_is ""..."3.0" do + # NOTE: WEIRD! + it "does not taint self when the passed Object was tainted" do + @io.reopen("reopened".taint, IO::RDONLY) + @io.tainted?.should be_false + + @io.reopen("reopened".taint, IO::WRONLY) + @io.tainted?.should be_false + end + end + it "tries to convert the passed Object to a String using #to_str" do obj = mock("to_str") obj.should_receive(:to_str).and_return("to_str") @@ -81,6 +92,17 @@ describe "StringIO#reopen when passed [Object, Object]" do str.should == "" end + ruby_version_is ""..."3.0" do + # NOTE: WEIRD! + it "does not taint self when the passed Object was tainted" do + @io.reopen("reopened".taint, "r") + @io.tainted?.should be_false + + @io.reopen("reopened".taint, "w") + @io.tainted?.should be_false + end + end + it "tries to convert the passed Object to a String using #to_str" do obj = mock("to_str") obj.should_receive(:to_str).and_return("to_str") @@ -142,6 +164,14 @@ describe "StringIO#reopen when passed [String]" do @io.string.should == "reopened" end + ruby_version_is ""..."3.0" do + # NOTE: WEIRD! + it "does not taint self when the passed Object was tainted" do + @io.reopen("reopened".taint) + @io.tainted?.should be_false + end + end + it "resets self's position to 0" do @io.read(5) @io.reopen("reopened") @@ -176,6 +206,14 @@ describe "StringIO#reopen when passed [Object]" do @io.reopen(obj) @io.string.should == "to_strio" end + + # NOTE: WEIRD! + ruby_version_is ""..."2.7" do + it "taints self when the passed Object was tainted" do + @io.reopen(StringIO.new("reopened").taint) + @io.tainted?.should be_true + end + end end describe "StringIO#reopen when passed no arguments" do @@ -240,6 +278,15 @@ describe "StringIO#reopen" do str.should == '' end + ruby_version_is ""..."2.7" do + it "taints self if the provided StringIO argument is tainted" do + new_io = StringIO.new("tainted") + new_io.taint + @io.reopen(new_io) + @io.should.tainted? + end + end + it "does not truncate the content even when the StringIO argument is in the truncate mode" do orig_io = StringIO.new("Original StringIO", IO::RDWR|IO::TRUNC) orig_io.write("BLAH") # make sure the content is not empty diff --git a/spec/ruby/library/stringio/set_encoding_spec.rb b/spec/ruby/library/stringio/set_encoding_spec.rb index 19ca0875bf..21d45750f3 100644 --- a/spec/ruby/library/stringio/set_encoding_spec.rb +++ b/spec/ruby/library/stringio/set_encoding_spec.rb @@ -17,12 +17,4 @@ describe "StringIO#set_encoding" do io.set_encoding Encoding::UTF_8 io.string.encoding.should == Encoding::US_ASCII end - - it "accepts a String" do - str = "".encode(Encoding::US_ASCII) - io = StringIO.new(str) - io.set_encoding("ASCII-8BIT") - io.external_encoding.should == Encoding::BINARY - str.encoding.should == Encoding::BINARY - end end diff --git a/spec/ruby/library/stringio/shared/each.rb b/spec/ruby/library/stringio/shared/each.rb index acd8d22c14..14b0a013b3 100644 --- a/spec/ruby/library/stringio/shared/each.rb +++ b/spec/ruby/library/stringio/shared/each.rb @@ -36,22 +36,11 @@ describe :stringio_each_separator, shared: true do seen.should == ["2 1 2 1 2"] end - version_is StringIO::VERSION, ""..."3.0.4" do #ruby_version_is ""..."3.2" do - it "yields each paragraph with two separation characters when passed an empty String as separator" do - seen = [] - io = StringIO.new("para1\n\npara2\n\n\npara3") - io.send(@method, "") {|s| seen << s} - seen.should == ["para1\n\n", "para2\n\n", "para3"] - end - end - - version_is StringIO::VERSION, "3.0.4" do #ruby_version_is "3.2" do - it "yields each paragraph with all separation characters when passed an empty String as separator" do - seen = [] - io = StringIO.new("para1\n\npara2\n\n\npara3") - io.send(@method, "") {|s| seen << s} - seen.should == ["para1\n\n", "para2\n\n\n", "para3"] - end + it "yields each paragraph when passed an empty String as separator" do + seen = [] + io = StringIO.new("para1\n\npara2\n\n\npara3") + io.send(@method, "") {|s| seen << s} + seen.should == ["para1\n\n", "para2\n\n", "para3"] end end @@ -123,41 +112,4 @@ describe :stringio_each_chomp, shared: true do io.send(@method, chomp: true) {|s| seen << s } seen.should == ["a b \rc d e", "1 2 3 4 5", "the end"] end - - it "returns each line with removed newline characters when called without block" do - seen = [] - io = StringIO.new("a b \rc d e\n1 2 3 4 5\r\nthe end") - enum = io.send(@method, chomp: true) - enum.each {|s| seen << s } - seen.should == ["a b \rc d e", "1 2 3 4 5", "the end"] - end -end - -describe :stringio_each_separator_and_chomp, shared: true do - it "yields each line with removed separator to the passed block" do - seen = [] - io = StringIO.new("a b \nc d e|1 2 3 4 5\n|the end") - io.send(@method, "|", chomp: true) {|s| seen << s } - seen.should == ["a b \nc d e", "1 2 3 4 5\n", "the end"] - end - - it "returns each line with removed separator when called without block" do - seen = [] - io = StringIO.new("a b \nc d e|1 2 3 4 5\n|the end") - enum = io.send(@method, "|", chomp: true) - enum.each {|s| seen << s } - seen.should == ["a b \nc d e", "1 2 3 4 5\n", "the end"] - end -end - -describe :stringio_each_limit, shared: true do - before :each do - @io = StringIO.new("a b c d e\n1 2 3 4 5") - end - - it "returns the data read until the limit is met" do - seen = [] - @io.send(@method, 4) { |s| seen << s } - seen.should == ["a b ", "c d ", "e\n", "1 2 ", "3 4 ", "5"] - end end diff --git a/spec/ruby/library/stringio/shared/read.rb b/spec/ruby/library/stringio/shared/read.rb index 252a85d89d..c60677bba7 100644 --- a/spec/ruby/library/stringio/shared/read.rb +++ b/spec/ruby/library/stringio/shared/read.rb @@ -89,12 +89,6 @@ describe :stringio_read_no_arguments, shared: true do @io.send(@method) @io.pos.should eql(7) end - - it "correctly update the current position in bytes when multi-byte characters are used" do - @io.print("example\u03A3") # Overwrite the original string with 8 characters containing 9 bytes. - @io.send(@method) - @io.pos.should eql(9) - end end describe :stringio_read_nil, shared: true do diff --git a/spec/ruby/library/stringio/shared/sysread.rb b/spec/ruby/library/stringio/shared/sysread.rb index 937bac705c..3376bd9907 100644 --- a/spec/ruby/library/stringio/shared/sysread.rb +++ b/spec/ruby/library/stringio/shared/sysread.rb @@ -1,4 +1,4 @@ -describe :stringio_sysread_length, shared: true do +describe :stringio_sysread_length, :shared => true do before :each do @io = StringIO.new("example") end diff --git a/spec/ruby/library/stringio/shared/write.rb b/spec/ruby/library/stringio/shared/write.rb index aa67bb73c7..080729217b 100644 --- a/spec/ruby/library/stringio/shared/write.rb +++ b/spec/ruby/library/stringio/shared/write.rb @@ -45,62 +45,18 @@ describe :stringio_write_string, shared: true do @io.pos.should eql(4) end - it "handles concurrent writes correctly" do - @io = StringIO.new - n = 8 - go = false - threads = n.times.map { |i| - Thread.new { - Thread.pass until go - @io.write i.to_s - } - } - go = true - threads.each(&:join) - @io.string.size.should == n.times.map(&:to_s).join.size - end - - it "handles writing non-ASCII UTF-8 after seek" do - @io.binmode - @io << "\x80" - @io.pos = 0 - @io << "\x81" - @io.string.should == "\x812345".b - end - - it "handles writing with position < buffer size" do - @io.pos = 2 - @io.write "abc" - @io.string.should == "12abc" - - @io.pos = 2 - @io.write "de" - @io.string.should == "12dec" - - @io.pos = 2 - @io.write "fghi" - @io.string.should == "12fghi" - end - - it "transcodes the given string when the external encoding is set and neither is BINARY" do - utf8_str = "hello" - io = StringIO.new.set_encoding(Encoding::UTF_16BE) - io.external_encoding.should == Encoding::UTF_16BE - - io.send(@method, utf8_str) - - expected = [0, 104, 0, 101, 0, 108, 0, 108, 0, 111] # UTF-16BE bytes for "hello" - io.string.bytes.should == expected - end - - it "does not transcode the given string when the external encoding is set and the string encoding is BINARY" do - str = "été".b - io = StringIO.new.set_encoding(Encoding::UTF_16BE) - io.external_encoding.should == Encoding::UTF_16BE - - io.send(@method, str) - - io.string.bytes.should == str.bytes + ruby_version_is ""..."2.7" do + it "taints self's String when the passed argument is tainted" do + @io.send(@method, "test".taint) + @io.string.tainted?.should be_true + end + end + + ruby_version_is ""..."3.0" do + it "does not taint self when the passed argument is tainted" do + @io.send(@method, "test".taint) + @io.tainted?.should be_false + end end end diff --git a/spec/ruby/library/stringio/truncate_spec.rb b/spec/ruby/library/stringio/truncate_spec.rb index e8d7f1a15d..ba910ee98c 100644 --- a/spec/ruby/library/stringio/truncate_spec.rb +++ b/spec/ruby/library/stringio/truncate_spec.rb @@ -6,8 +6,10 @@ describe "StringIO#truncate when passed [length]" do @io = StringIO.new('123456789') end - it "returns an Integer" do - @io.truncate(4).should be_kind_of(Integer) + # TODO: Report to Ruby-Core: The RDoc says it always returns 0 + it "returns the passed length" do + @io.truncate(4).should eql(4) + @io.truncate(10).should eql(10) end it "truncated the underlying string down to the passed length" do @@ -45,6 +47,12 @@ describe "StringIO#truncate when passed [length]" do @io.string.should == "1234" end + it "returns the passed length Object, NOT the result of #to_int" do + obj = mock("to_int") + obj.should_receive(:to_int).and_return(4) + @io.truncate(obj).should equal(obj) + end + it "raises a TypeError when the passed length can't be converted to an Integer" do -> { @io.truncate(Object.new) }.should raise_error(TypeError) end diff --git a/spec/ruby/library/stringio/write_nonblock_spec.rb b/spec/ruby/library/stringio/write_nonblock_spec.rb index a457b97667..4f4c5039fe 100644 --- a/spec/ruby/library/stringio/write_nonblock_spec.rb +++ b/spec/ruby/library/stringio/write_nonblock_spec.rb @@ -8,12 +8,6 @@ end describe "StringIO#write_nonblock when passed [String]" do it_behaves_like :stringio_write_string, :write_nonblock - - it "accepts :exception option" do - io = StringIO.new("12345", "a") - io.write_nonblock("67890", exception: true) - io.string.should == "1234567890" - end end describe "StringIO#write_nonblock when self is not writable" do |
