summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-10 05:02:02 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-10 05:02:02 +0000
commitd68c3ecf98bf3b5802a6b0f9a6bcf7825addd9e5 (patch)
tree95a8b3e8116776990c19e5cacd5af0af59f898c7 /test/ruby
parentf11a85c72600026f6e26afe6dda2548c785ce1d3 (diff)
hash.c: compare methods
* hash.c (rb_hash_{le,lt,ge,gt}): new methods, Hash#<=, Hash#<, Hash#>=, Hash#>, to test if all elements of a hash are also included in another hash, and vice versa. [ruby-core:68561] [Feature #10984] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_hash.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index ee51c8ed7d..4f48d3b90c 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -1308,6 +1308,31 @@ class TestHash < Test::Unit::TestCase
assert_nil(h.dig(:c, 1))
end
+ def test_cmp
+ h1 = {a:1, b:2}
+ h2 = {a:1, b:2, c:3}
+
+ assert_operator(h1, :<=, h1)
+ assert_operator(h1, :<=, h2)
+ assert_not_operator(h2, :<=, h1)
+ assert_operator(h2, :<=, h2)
+
+ assert_operator(h1, :>=, h1)
+ assert_not_operator(h1, :>=, h2)
+ assert_operator(h2, :>=, h1)
+ assert_operator(h2, :>=, h2)
+
+ assert_not_operator(h1, :<, h1)
+ assert_operator(h1, :<, h2)
+ assert_not_operator(h2, :<, h1)
+ assert_not_operator(h2, :<, h2)
+
+ assert_not_operator(h1, :>, h1)
+ assert_not_operator(h1, :>, h2)
+ assert_operator(h2, :>, h1)
+ assert_not_operator(h2, :>, h2)
+ end
+
class TestSubHash < TestHash
class SubHash < Hash
def reject(*)