From c6ddf2a7ab0da9b5d9af529f9e6eb51c523e763b Mon Sep 17 00:00:00 2001 From: AlessandroMinali Date: Fri, 6 Oct 2017 18:27:59 -0400 Subject: [PATCH 1/4] spec for String#casecmp? --- core/string/casecmp_spec.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/core/string/casecmp_spec.rb b/core/string/casecmp_spec.rb index fdb888ff2b..649ba06ae6 100644 --- a/core/string/casecmp_spec.rb +++ b/core/string/casecmp_spec.rb @@ -117,4 +117,36 @@ "B".casecmp(a).should == 1 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 + + describe 'for UNICODE characters' do + 'äöü'.casecmp?('ÄÖÜ').should == true + 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 + end + end end From d2d1efb0c7f3eaca6179d1de1391a8b3fd848d24 Mon Sep 17 00:00:00 2001 From: AlessandroMinali Date: Fri, 6 Oct 2017 18:34:52 -0400 Subject: [PATCH 2/4] more specs --- core/string/casecmp_spec.rb | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/core/string/casecmp_spec.rb b/core/string/casecmp_spec.rb index 649ba06ae6..a52a7bbc3a 100644 --- a/core/string/casecmp_spec.rb +++ b/core/string/casecmp_spec.rb @@ -130,8 +130,17 @@ '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 - 'äöü'.casecmp?('ÄÖÜ').should == true + it 'returns true when downcase(:fold) on unicode' do + 'äöü'.casecmp?('ÄÖÜ').should == true + end end describe "when comparing a subclass instance" do @@ -147,6 +156,26 @@ '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 == false + @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 end From 24dfde2fcde97634ba7e999e62914b28b8b55fa3 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sat, 7 Oct 2017 11:13:05 +0200 Subject: [PATCH 3/4] Change encoding of the String#casecmp spec file to UTF-8 --- core/string/casecmp_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/string/casecmp_spec.rb b/core/string/casecmp_spec.rb index a52a7bbc3a..5c36df0598 100644 --- a/core/string/casecmp_spec.rb +++ b/core/string/casecmp_spec.rb @@ -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__) @@ -167,7 +167,7 @@ end it "returns false when numerically not equal to other" do - @upper_a_tilde.casecmp?(@lower_a_tilde).should == false + @upper_a_tilde.casecmp?(@lower_a_tilde).should == true # TODO @upper_a_tilde.casecmp?(@upper_a_umlaut).should == false end From ed684b10bb15a4ff295e2c6d93d2e7048e831d66 Mon Sep 17 00:00:00 2001 From: AlessandroMinali Date: Sat, 7 Oct 2017 12:07:58 -0400 Subject: [PATCH 4/4] use utf-8 chars and unnest casemcmp? specs --- core/string/casecmp_spec.rb | 98 ++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/core/string/casecmp_spec.rb b/core/string/casecmp_spec.rb index 5c36df0598..8076f37dd4 100644 --- a/core/string/casecmp_spec.rb +++ b/core/string/casecmp_spec.rb @@ -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 @@ -117,63 +117,63 @@ "B".casecmp(a).should == 1 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 +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 '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") + 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 - "abc".casecmp?(other).should == true + describe 'for UNICODE characters' do + it 'returns true when downcase(:fold) on unicode' do + 'äöü'.casecmp?('ÄÖÜ').should == true end + end - describe 'for UNICODE characters' do - it 'returns true when downcase(:fold) on unicode' do - 'äöü'.casecmp?('ÄÖÜ').should == true - 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 "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 + 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 not equal to other' do - b = StringSpecs::MyString.new "a" - 'b'.casecmp?(b).should == false - 'B'.casecmp?(b).should == false + 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 - 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 + it "returns true when numerically equal to other" do + @upper_a_tilde.casecmp?(@upper_a_tilde).should == true end end end