From 3f6c0a6d74209b03d0ec54b98b5e1ece40d649f0 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Thu, 17 Sep 2020 11:42:26 +0200 Subject: Update to ruby/spec@e829fb0 --- spec/ruby/core/complex/to_c_spec.rb | 12 ++++++ spec/ruby/core/hash/except_spec.rb | 33 +++++++++++++++ spec/ruby/core/nil/case_compare_spec.rb | 13 ++++++ spec/ruby/core/numeric/clone_spec.rb | 25 ++++++++++++ spec/ruby/core/numeric/dup_spec.rb | 16 ++++++++ spec/ruby/core/string/end_with_spec.rb | 52 +----------------------- spec/ruby/core/string/start_with_spec.rb | 70 +------------------------------- spec/ruby/core/string/uminus_spec.rb | 7 ++++ spec/ruby/core/symbol/end_with_spec.rb | 10 +++++ spec/ruby/core/symbol/start_with_spec.rb | 10 +++++ spec/ruby/core/true/case_compare_spec.rb | 13 ++++++ 11 files changed, 143 insertions(+), 118 deletions(-) create mode 100644 spec/ruby/core/complex/to_c_spec.rb create mode 100644 spec/ruby/core/hash/except_spec.rb create mode 100644 spec/ruby/core/nil/case_compare_spec.rb create mode 100644 spec/ruby/core/numeric/clone_spec.rb create mode 100644 spec/ruby/core/numeric/dup_spec.rb create mode 100644 spec/ruby/core/symbol/end_with_spec.rb create mode 100644 spec/ruby/core/symbol/start_with_spec.rb create mode 100644 spec/ruby/core/true/case_compare_spec.rb (limited to 'spec/ruby/core') diff --git a/spec/ruby/core/complex/to_c_spec.rb b/spec/ruby/core/complex/to_c_spec.rb new file mode 100644 index 0000000000..5ce01d9d4e --- /dev/null +++ b/spec/ruby/core/complex/to_c_spec.rb @@ -0,0 +1,12 @@ +require_relative '../../spec_helper' + +describe "Complex#to_c" do + it "returns self" do + value = Complex(1, 5) + value.to_c.should equal(value) + end + + it 'returns the same value' do + Complex(1, 5).to_c.should == Complex(1, 5) + end +end diff --git a/spec/ruby/core/hash/except_spec.rb b/spec/ruby/core/hash/except_spec.rb new file mode 100644 index 0000000000..cef99b6284 --- /dev/null +++ b/spec/ruby/core/hash/except_spec.rb @@ -0,0 +1,33 @@ +require_relative '../../spec_helper' + +ruby_version_is "3.0" do + describe "Hash#except" do + before :each do + @hash = { a: 1, b: 2, c: 3 } + end + + it "returns a new duplicate hash without arguments" do + ret = @hash.except + ret.should_not equal(@hash) + ret.should == @hash + end + + it "returns a hash without the requested subset" do + @hash.except(:c, :a).should == { b: 2 } + end + + it "ignores keys not present in the original hash" do + @hash.except(:a, :chunky_bacon).should == { b: 2, c: 3 } + end + + it "returns an instance of a subclass" do + klass = Class.new(Hash) + h = klass.new + h[:bar] = 12 + h[:foo] = 42 + r = h.except(:foo) + r.should == {bar: 12} + r.class.should == klass + end + end +end diff --git a/spec/ruby/core/nil/case_compare_spec.rb b/spec/ruby/core/nil/case_compare_spec.rb new file mode 100644 index 0000000000..142560c6f5 --- /dev/null +++ b/spec/ruby/core/nil/case_compare_spec.rb @@ -0,0 +1,13 @@ +require_relative '../../spec_helper' + +describe "NilClass#===" do + it "returns true for nil" do + (nil === nil).should == true + end + + it "returns false for non-nil object" do + (nil === 1).should == false + (nil === "").should == false + (nil === Object).should == false + end +end diff --git a/spec/ruby/core/numeric/clone_spec.rb b/spec/ruby/core/numeric/clone_spec.rb new file mode 100644 index 0000000000..e3bf0a9e7c --- /dev/null +++ b/spec/ruby/core/numeric/clone_spec.rb @@ -0,0 +1,25 @@ +require_relative '../../spec_helper' + +describe "Numeric#clone" do + it "returns self" do + value = 1 + value.clone.should equal(value) + + subclass = Class.new(Numeric) + value = subclass.new + value.clone.should equal(value) + end + + it "does not change frozen status" do + 1.clone.frozen?.should == true + end + + it "accepts optonal keyword argument :freeze" do + value = 1 + value.clone(freeze: true).should equal(value) + end + + it "raises ArgumentError if passed freeze: false" do + -> { 1.clone(freeze: false) }.should raise_error(ArgumentError, /can't unfreeze/) + end +end diff --git a/spec/ruby/core/numeric/dup_spec.rb b/spec/ruby/core/numeric/dup_spec.rb new file mode 100644 index 0000000000..189a7ef44d --- /dev/null +++ b/spec/ruby/core/numeric/dup_spec.rb @@ -0,0 +1,16 @@ +require_relative '../../spec_helper' + +describe "Numeric#dup" do + it "returns self" do + value = 1 + value.dup.should equal(value) + + subclass = Class.new(Numeric) + value = subclass.new + value.dup.should equal(value) + end + + it "does not change frozen status" do + 1.dup.frozen?.should == true + end +end diff --git a/spec/ruby/core/string/end_with_spec.rb b/spec/ruby/core/string/end_with_spec.rb index 9ced0ca3d2..ac4fff72ad 100644 --- a/spec/ruby/core/string/end_with_spec.rb +++ b/spec/ruby/core/string/end_with_spec.rb @@ -1,56 +1,8 @@ # -*- encoding: utf-8 -*- require_relative '../../spec_helper' require_relative 'fixtures/classes' +require_relative '../../shared/string/end_with' describe "String#end_with?" do - it "returns true only if ends match" do - s = "hello" - s.should.end_with?('o') - s.should.end_with?('llo') - end - - it 'returns false if the end does not match' do - s = 'hello' - s.should_not.end_with?('ll') - end - - it "returns true if the search string is empty" do - "hello".should.end_with?("") - "".should.end_with?("") - end - - it "returns true only if any ending match" do - "hello".should.end_with?('x', 'y', 'llo', 'z') - end - - it "converts its argument using :to_str" do - s = "hello" - find = mock('o') - find.should_receive(:to_str).and_return("o") - s.should.end_with?(find) - end - - it "ignores arguments not convertible to string" do - "hello".should_not.end_with?() - -> { "hello".end_with?(1) }.should raise_error(TypeError) - -> { "hello".end_with?(["o"]) }.should raise_error(TypeError) - -> { "hello".end_with?(1, nil, "o") }.should raise_error(TypeError) - end - - it "uses only the needed arguments" do - find = mock('h') - find.should_not_receive(:to_str) - "hello".should.end_with?("o",find) - end - - it "works for multibyte strings" do - "céréale".should.end_with?("réale") - end - - it "raises an Encoding::CompatibilityError if the encodings are incompatible" do - pat = "ア".encode Encoding::EUC_JP - -> do - "あれ".end_with?(pat) - end.should raise_error(Encoding::CompatibilityError) - end + it_behaves_like :end_with, :to_s end diff --git a/spec/ruby/core/string/start_with_spec.rb b/spec/ruby/core/string/start_with_spec.rb index 11c8041925..aaed197ff3 100644 --- a/spec/ruby/core/string/start_with_spec.rb +++ b/spec/ruby/core/string/start_with_spec.rb @@ -1,74 +1,8 @@ # -*- encoding: utf-8 -*- require_relative '../../spec_helper' require_relative 'fixtures/classes' +require_relative '../../shared/string/start_with' describe "String#start_with?" do - it "returns true only if beginning match" do - s = "hello" - s.should.start_with?('h') - s.should.start_with?('hel') - s.should_not.start_with?('el') - end - - it "returns true only if any beginning match" do - "hello".should.start_with?('x', 'y', 'he', 'z') - end - - it "returns true if the search string is empty" do - "hello".should.start_with?("") - "".should.start_with?("") - end - - it "converts its argument using :to_str" do - s = "hello" - find = mock('h') - find.should_receive(:to_str).and_return("h") - s.should.start_with?(find) - end - - it "ignores arguments not convertible to string" do - "hello".should_not.start_with?() - -> { "hello".start_with?(1) }.should raise_error(TypeError) - -> { "hello".start_with?(["h"]) }.should raise_error(TypeError) - -> { "hello".start_with?(1, nil, "h") }.should raise_error(TypeError) - end - - it "uses only the needed arguments" do - find = mock('h') - find.should_not_receive(:to_str) - "hello".should.start_with?("h",find) - end - - it "works for multibyte strings" do - "céréale".should.start_with?("cér") - end - - it "supports regexps" do - regexp = /[h1]/ - "hello".should.start_with?(regexp) - "1337".should.start_with?(regexp) - "foxes are 1337".should_not.start_with?(regexp) - "chunky\n12bacon".should_not.start_with?(/12/) - end - - it "supports regexps with ^ and $ modifiers" do - regexp1 = /^\d{2}/ - regexp2 = /\d{2}$/ - "12test".should.start_with?(regexp1) - "test12".should_not.start_with?(regexp1) - "12test".should_not.start_with?(regexp2) - "test12".should_not.start_with?(regexp2) - end - - it "sets Regexp.last_match if it returns true" do - regexp = /test-(\d+)/ - "test-1337".start_with?(regexp).should be_true - Regexp.last_match.should_not be_nil - Regexp.last_match[1].should == "1337" - $1.should == "1337" - - "test-asdf".start_with?(regexp).should be_false - Regexp.last_match.should be_nil - $1.should be_nil - end + it_behaves_like :start_with, :to_s end diff --git a/spec/ruby/core/string/uminus_spec.rb b/spec/ruby/core/string/uminus_spec.rb index 91f91fdb1e..3a81b64126 100644 --- a/spec/ruby/core/string/uminus_spec.rb +++ b/spec/ruby/core/string/uminus_spec.rb @@ -69,4 +69,11 @@ describe 'String#-@' do (-dynamic).should equal(-"this string is frozen".freeze) end end + + ruby_version_is "3.0" do + it "interns the provided string if it is frozen" do + dynamic = "this string is unique and frozen #{rand}".freeze + (-dynamic).should equal(dynamic) + end + end end diff --git a/spec/ruby/core/symbol/end_with_spec.rb b/spec/ruby/core/symbol/end_with_spec.rb new file mode 100644 index 0000000000..77dc4caf71 --- /dev/null +++ b/spec/ruby/core/symbol/end_with_spec.rb @@ -0,0 +1,10 @@ +# -*- encoding: utf-8 -*- + +require_relative '../../spec_helper' +require_relative '../../shared/string/end_with' + +ruby_version_is "2.7" do + describe "Symbol#end_with?" do + it_behaves_like :end_with, :to_sym + end +end diff --git a/spec/ruby/core/symbol/start_with_spec.rb b/spec/ruby/core/symbol/start_with_spec.rb new file mode 100644 index 0000000000..f54b3e499e --- /dev/null +++ b/spec/ruby/core/symbol/start_with_spec.rb @@ -0,0 +1,10 @@ +# -*- encoding: utf-8 -*- +require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require_relative '../../shared/string/start_with' + +ruby_version_is "2.7" do + describe "Symbol#start_with?" do + it_behaves_like :start_with, :to_sym + end +end diff --git a/spec/ruby/core/true/case_compare_spec.rb b/spec/ruby/core/true/case_compare_spec.rb new file mode 100644 index 0000000000..dee6dd0227 --- /dev/null +++ b/spec/ruby/core/true/case_compare_spec.rb @@ -0,0 +1,13 @@ +require_relative '../../spec_helper' + +describe "TrueClass#===" do + it "returns true for true" do + (true === true).should == true + end + + it "returns false for non-true object" do + (true === 1).should == false + (true === "").should == false + (true === Object).should == false + end +end -- cgit v1.2.3