diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-15 17:44:37 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-15 17:44:37 +0000 |
commit | 30ed82e7724093bb3c2015a818c28c3592134bba (patch) | |
tree | 5445b9e26d9ee173fa3735007f3e2b42791d2ec5 /spec/ruby/library/set | |
parent | f941bdf263dcc16ea4e6b4576341882b89567c0b (diff) | |
download | ruby-30ed82e7724093bb3c2015a818c28c3592134bba.tar.gz |
Update to ruby/spec@595645f
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/library/set')
-rw-r--r-- | spec/ruby/library/set/case_compare_spec.rb | 15 | ||||
-rw-r--r-- | spec/ruby/library/set/inspect_spec.rb | 15 | ||||
-rw-r--r-- | spec/ruby/library/set/shared/include.rb | 22 | ||||
-rw-r--r-- | spec/ruby/library/set/shared/inspect.rb | 15 | ||||
-rw-r--r-- | spec/ruby/library/set/to_s_spec.rb | 13 |
5 files changed, 67 insertions, 13 deletions
diff --git a/spec/ruby/library/set/case_compare_spec.rb b/spec/ruby/library/set/case_compare_spec.rb new file mode 100644 index 0000000000..f47e4e20c2 --- /dev/null +++ b/spec/ruby/library/set/case_compare_spec.rb @@ -0,0 +1,15 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/include', __FILE__) +require 'set' + +ruby_version_is "2.5" do + describe "Set#===" do + it_behaves_like :set_include, :=== + + it "is an alias for include?" do + set = Set.new + set.method(:===).should == set.method(:include?) + end + end +end + diff --git a/spec/ruby/library/set/inspect_spec.rb b/spec/ruby/library/set/inspect_spec.rb index 8a6c565c2e..ef91b11645 100644 --- a/spec/ruby/library/set/inspect_spec.rb +++ b/spec/ruby/library/set/inspect_spec.rb @@ -1,18 +1,7 @@ require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/inspect', __FILE__) require 'set' describe "Set#inspect" do - it "returns a String representation of self" do - Set[].inspect.should be_kind_of(String) - Set[nil, false, true].inspect.should be_kind_of(String) - Set[1, 2, 3].inspect.should be_kind_of(String) - Set["1", "2", "3"].inspect.should be_kind_of(String) - Set[:a, "b", Set[?c]].inspect.should be_kind_of(String) - end - - it "correctly handles self-references" do - (set = Set[]) << set - set.inspect.should be_kind_of(String) - set.inspect.should include("#<Set: {...}>") - end + it_behaves_like :set_inspect, :inspect end diff --git a/spec/ruby/library/set/shared/include.rb b/spec/ruby/library/set/shared/include.rb index d41f8f4102..b4d95cde24 100644 --- a/spec/ruby/library/set/shared/include.rb +++ b/spec/ruby/library/set/shared/include.rb @@ -4,4 +4,26 @@ describe :set_include, shared: true do set.send(@method, :a).should be_true set.send(@method, :e).should be_false end + + describe "member equality" do + it "is checked using both #hash and #eql?" do + obj = Object.new + obj_another = Object.new + + def obj.hash; 42 end + def obj_another.hash; 42 end + def obj_another.eql?(o) hash == o.hash end + + set = Set["a", "b", "c", obj] + set.send(@method, obj_another).should == true + end + + it "is not checked using #==" do + obj = Object.new + set = Set["a", "b", "c"] + + obj.should_not_receive(:==) + set.send(@method, obj) + end + end end diff --git a/spec/ruby/library/set/shared/inspect.rb b/spec/ruby/library/set/shared/inspect.rb new file mode 100644 index 0000000000..69fbdd12f6 --- /dev/null +++ b/spec/ruby/library/set/shared/inspect.rb @@ -0,0 +1,15 @@ +describe "set_inspect", shared: true do + it "returns a String representation of self" do + Set[].send(@method).should be_kind_of(String) + Set[nil, false, true].send(@method).should be_kind_of(String) + Set[1, 2, 3].send(@method).should be_kind_of(String) + Set["1", "2", "3"].send(@method).should be_kind_of(String) + Set[:a, "b", Set[?c]].send(@method).should be_kind_of(String) + end + + it "correctly handles self-references" do + (set = Set[]) << set + set.send(@method).should be_kind_of(String) + set.send(@method).should include("#<Set: {...}>") + end +end diff --git a/spec/ruby/library/set/to_s_spec.rb b/spec/ruby/library/set/to_s_spec.rb new file mode 100644 index 0000000000..f4c361f74f --- /dev/null +++ b/spec/ruby/library/set/to_s_spec.rb @@ -0,0 +1,13 @@ +require File.expand_path('../shared/inspect', __FILE__) +require 'set' + +ruby_version_is "2.5" do + describe "Set#to_s" do + it_behaves_like :set_inspect, :to_s + + it "is an alias of inspect" do + set = Set.new + set.method(:to_s).should == set.method(:inspect) + end + end +end |