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#external_encoding" do
|
|
|
|
it "gets the encoding of the underlying String" do
|
|
|
|
io = StringIO.new
|
|
|
|
io.set_encoding Encoding::EUC_JP
|
|
|
|
io.external_encoding.should == Encoding::EUC_JP
|
|
|
|
end
|
|
|
|
|
2018-09-25 06:41:16 -04:00
|
|
|
it "changes to match string if string's encoding is changed" do
|
|
|
|
io = StringIO.new
|
|
|
|
io.string.force_encoding(Encoding::EUC_JP)
|
|
|
|
io.external_encoding.should == Encoding::EUC_JP
|
|
|
|
end
|
|
|
|
|
2018-04-28 15:50:06 -04:00
|
|
|
it "does not set the encoding of its buffer string if the string is frozen" do
|
|
|
|
str = "foo".freeze
|
|
|
|
enc = str.encoding
|
|
|
|
io = StringIO.new(str)
|
|
|
|
io.set_encoding Encoding::EUC_JP
|
|
|
|
io.external_encoding.should == Encoding::EUC_JP
|
|
|
|
str.encoding.should == enc
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|