2017-05-07 08:04:49 -04:00
|
|
|
require 'stringio'
|
2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "StringIO#set_encoding" do
|
2018-12-28 19:22:52 -05:00
|
|
|
it "sets the encoding of the underlying String if the String is not frozen" do
|
|
|
|
str = "".encode(Encoding::US_ASCII)
|
|
|
|
|
|
|
|
io = StringIO.new(str)
|
2017-05-07 08:04:49 -04:00
|
|
|
io.set_encoding Encoding::UTF_8
|
|
|
|
io.string.encoding.should == Encoding::UTF_8
|
|
|
|
end
|
2018-12-28 19:22:52 -05:00
|
|
|
|
|
|
|
it "does not set the encoding of the underlying String if the String is frozen" do
|
|
|
|
str = "".encode(Encoding::US_ASCII).freeze
|
|
|
|
|
|
|
|
io = StringIO.new(str)
|
|
|
|
io.set_encoding Encoding::UTF_8
|
|
|
|
io.string.encoding.should == Encoding::US_ASCII
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|