diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-02-27 20:21:25 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-02-27 20:21:25 +0000 |
commit | 37ef87c12b6c496001d0f199e46b4ecbfac5d394 (patch) | |
tree | 063c277e6343b299f6d47200e5b38f3af7975301 /spec/ruby/core/encoding | |
parent | ecf03376ec25fbd1ced6c0d1de110c6761e959fd (diff) | |
download | ruby-37ef87c12b6c496001d0f199e46b4ecbfac5d394.tar.gz |
Update to ruby/spec@cbe855c
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/encoding')
-rw-r--r-- | spec/ruby/core/encoding/converter/last_error_spec.rb | 40 | ||||
-rw-r--r-- | spec/ruby/core/encoding/default_external_spec.rb | 31 | ||||
-rw-r--r-- | spec/ruby/core/encoding/default_internal_spec.rb | 17 |
3 files changed, 34 insertions, 54 deletions
diff --git a/spec/ruby/core/encoding/converter/last_error_spec.rb b/spec/ruby/core/encoding/converter/last_error_spec.rb index 8465935368..f8a2eeba69 100644 --- a/spec/ruby/core/encoding/converter/last_error_spec.rb +++ b/spec/ruby/core/encoding/converter/last_error_spec.rb @@ -55,14 +55,11 @@ with_feature :encoding do it "returns an Encoding::InvalidByteSequenceError when the last call to #convert produced one" do ec = Encoding::Converter.new("utf-8", "iso-8859-1") exception = nil - lambda do - begin - ec.convert("\xf1abcd") - rescue Encoding::InvalidByteSequenceError => e - exception = e - raise e - end - end.should raise_error(Encoding::InvalidByteSequenceError) + -> { + ec.convert("\xf1abcd") + }.should raise_error(Encoding::InvalidByteSequenceError) { |e| + exception = e + } ec.last_error.should be_an_instance_of(Encoding::InvalidByteSequenceError) ec.last_error.message.should == exception.message end @@ -70,16 +67,27 @@ with_feature :encoding do it "returns an Encoding::UndefinedConversionError when the last call to #convert produced one" do ec = Encoding::Converter.new("utf-8", "iso-8859-1") exception = nil - lambda do - begin - ec.convert("\u{9899}") - rescue Encoding::UndefinedConversionError => e - exception = e - raise e - end - end.should raise_error(Encoding::UndefinedConversionError) + -> { + ec.convert("\u{9899}") + }.should raise_error(Encoding::UndefinedConversionError) { |e| + exception = e + } ec.last_error.should be_an_instance_of(Encoding::UndefinedConversionError) ec.last_error.message.should == exception.message + ec.last_error.message.should include "from UTF-8 to ISO-8859-1" + end + + it "returns the last error of #convert with a message showing the transcoding path" do + ec = Encoding::Converter.new("iso-8859-1", "Big5") + exception = nil + -> { + ec.convert("\xE9") # é in ISO-8859-1 + }.should raise_error(Encoding::UndefinedConversionError) { |e| + exception = e + } + ec.last_error.should be_an_instance_of(Encoding::UndefinedConversionError) + ec.last_error.message.should == exception.message + ec.last_error.message.should include "from ISO-8859-1 to UTF-8 to Big5" end end end diff --git a/spec/ruby/core/encoding/default_external_spec.rb b/spec/ruby/core/encoding/default_external_spec.rb index 2b026c793f..a4e2a3a61e 100644 --- a/spec/ruby/core/encoding/default_external_spec.rb +++ b/spec/ruby/core/encoding/default_external_spec.rb @@ -15,25 +15,8 @@ with_feature :encoding do end it "returns the default external encoding" do - Encoding.default_external = Encoding::UTF_8 - Encoding.default_external.should == Encoding::UTF_8 - end - - describe "with command line options" do - it "is not changed by the -U option" do - result = ruby_exe("print Encoding.default_external", options: '-U') - result.should == Encoding.default_external.name - end - - it "returns the encoding specified by '-E external'" do - result = ruby_exe("print Encoding.default_external", options: '-E euc-jp') - result.should == "EUC-JP" - end - - it "returns the encoding specified by '-E external:'" do - result = ruby_exe("print Encoding.default_external", options: '-E Shift_JIS:') - result.should == "Shift_JIS" - end + Encoding.default_external = Encoding::SHIFT_JIS + Encoding.default_external.should == Encoding::SHIFT_JIS end end @@ -47,8 +30,14 @@ with_feature :encoding do end it "sets the default external encoding" do - Encoding.default_external = Encoding::UTF_8 - Encoding.default_external.should == Encoding::UTF_8 + Encoding.default_external = Encoding::SHIFT_JIS + Encoding.default_external.should == Encoding::SHIFT_JIS + Encoding.find('external').should == Encoding::SHIFT_JIS + end + + it "also sets the filesystem encoding" do + Encoding.default_external = Encoding::SHIFT_JIS + Encoding.find('filesystem').should == Encoding::SHIFT_JIS end it "can accept a name of an encoding as a String" do diff --git a/spec/ruby/core/encoding/default_internal_spec.rb b/spec/ruby/core/encoding/default_internal_spec.rb index 3234929eec..1e2b7e40c9 100644 --- a/spec/ruby/core/encoding/default_internal_spec.rb +++ b/spec/ruby/core/encoding/default_internal_spec.rb @@ -28,23 +28,6 @@ with_feature :encoding do Encoding.default_internal = Encoding::ASCII_8BIT Encoding.default_internal.should == Encoding::ASCII_8BIT end - - describe "with command line options" do - it "returns Encoding::UTF_8 if ruby was invoked with -U" do - ruby_exe("print Encoding.default_internal", options: '-U'). - should == 'UTF-8' - end - - it "uses the encoding specified when ruby is invoked with an '-E :internal' argument" do - ruby_exe("print Encoding.default_internal", options: '-E :SHIFT_JIS'). - should == 'Shift_JIS' - end - - it "uses the encoding specified when ruby is invoked with an '-E external:internal' argument" do - ruby_exe("print Encoding.default_internal", options: '-E UTF-8:SHIFT_JIS'). - should == 'Shift_JIS' - end - end end describe "Encoding.default_internal=" do |