2017-05-07 12:04:49 +00:00
|
|
|
require 'stringio'
|
2018-03-04 15:09:32 +00:00
|
|
|
require_relative '../../spec_helper'
|
2017-05-07 12:04:49 +00: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 10:41:16 +00: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 19:50:06 +00: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 12:04:49 +00:00
|
|
|
end
|
|
|
|
end
|