diff options
Diffstat (limited to 'spec/ruby/core/string/casecmp_spec.rb')
| -rw-r--r-- | spec/ruby/core/string/casecmp_spec.rb | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/spec/ruby/core/string/casecmp_spec.rb b/spec/ruby/core/string/casecmp_spec.rb index 01b22e8f13..90577aaac0 100644 --- a/spec/ruby/core/string/casecmp_spec.rb +++ b/spec/ruby/core/string/casecmp_spec.rb @@ -25,20 +25,12 @@ describe "String#casecmp independent of case" do "abc".casecmp(other).should == 0 end - ruby_version_is ""..."2.5" do - it "raises a TypeError if other can't be converted to a string" do - -> { "abc".casecmp(mock('abc')) }.should raise_error(TypeError) - end - end - - ruby_version_is "2.5" do - it "returns nil if other can't be converted to a string" do - "abc".casecmp(mock('abc')).should be_nil - end + it "returns nil if other can't be converted to a string" do + "abc".casecmp(mock('abc')).should == nil end it "returns nil if incompatible encodings" do - "あれ".casecmp("れ".encode(Encoding::EUC_JP)).should be_nil + "あれ".casecmp("れ".encode(Encoding::EUC_JP)).should == nil end describe "in UTF-8 mode" do @@ -125,6 +117,11 @@ describe "String#casecmp independent of case" do "B".casecmp(a).should == 1 end end + + it "returns 0 for empty strings in different encodings" do + ''.b.casecmp('').should == 0 + ''.b.casecmp(''.encode("UTF-32LE")).should == 0 + end end describe 'String#casecmp? independent of case' do @@ -146,7 +143,7 @@ describe 'String#casecmp? independent of case' do end it "returns nil if incompatible encodings" do - "あれ".casecmp?("れ".encode(Encoding::EUC_JP)).should be_nil + "あれ".casecmp?("れ".encode(Encoding::EUC_JP)).should == nil end describe 'for UNICODE characters' do @@ -193,18 +190,15 @@ describe 'String#casecmp? independent of case' do end it "case folds" do - "ß".casecmp?("ss").should be_true + "ß".casecmp?("ss").should == true end - ruby_version_is "2.4"..."2.5" do - it "raises a TypeError if other can't be converted to a string" do - -> { "abc".casecmp?(mock('abc')) }.should raise_error(TypeError) - end + it "returns nil if other can't be converted to a string" do + "abc".casecmp?(mock('abc')).should == nil end - ruby_version_is "2.5" do - it "returns nil if other can't be converted to a string" do - "abc".casecmp?(mock('abc')).should be_nil - end + it "returns true for empty strings in different encodings" do + ''.b.should.casecmp?('') + ''.b.should.casecmp?(''.encode("UTF-32LE")) end end |
