Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 66 additions & 5 deletions core/string/casecmp_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- encoding: ascii-8bit -*-
# -*- encoding: utf-8 -*-
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes.rb', __FILE__)

Expand Down Expand Up @@ -40,10 +40,10 @@
describe "in UTF-8 mode" do
describe "for non-ASCII characters" do
before :each do
@upper_a_tilde = "\xc3\x83"
@lower_a_tilde = "\xc3\xa3"
@upper_a_umlaut = "\xc3\x84"
@lower_a_umlaut = "\xc3\xa4"
@upper_a_tilde = "Ã"
@lower_a_tilde = "ã"
@upper_a_umlaut = "Ä"
@lower_a_umlaut = "ä"
end

it "returns -1 when numerically less than other" do
Expand Down Expand Up @@ -118,3 +118,64 @@
end
end
end

ruby_version_is "2.4" do
describe 'String#casecmp? independent of case' do
it 'returns true when equal to other' do
'abc'.casecmp?('abc').should == true
'abc'.casecmp?('ABC').should == true
end

it 'returns false when not equal to other' do
'abc'.casecmp?('DEF').should == false
'abc'.casecmp?('def').should == false
end

it "tries to convert other to string using to_str" do
other = mock('x')
other.should_receive(:to_str).and_return("abc")

"abc".casecmp?(other).should == true
end

describe 'for UNICODE characters' do
it 'returns true when downcase(:fold) on unicode' do
'äöü'.casecmp?('ÄÖÜ').should == true
end
end

describe "when comparing a subclass instance" do
it 'returns true when equal to other' do
a = StringSpecs::MyString.new "a"
'a'.casecmp?(a).should == true
'A'.casecmp?(a).should == true
end

it 'returns false when not equal to other' do
b = StringSpecs::MyString.new "a"
'b'.casecmp?(b).should == false
'B'.casecmp?(b).should == false
end
end

describe "in UTF-8 mode" do
describe "for non-ASCII characters" do
before :each do
@upper_a_tilde = "\xc3\x83"
@lower_a_tilde = "\xc3\xa3"
@upper_a_umlaut = "\xc3\x84"
@lower_a_umlaut = "\xc3\xa4"
end

it "returns false when numerically not equal to other" do
@upper_a_tilde.casecmp?(@lower_a_tilde).should == true # TODO
@upper_a_tilde.casecmp?(@upper_a_umlaut).should == false
end

it "returns true when numerically equal to other" do
@upper_a_tilde.casecmp?(@upper_a_tilde).should == true
end
end
end
end
end