summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-12-26 15:50:34 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-12-26 15:50:34 +0900
commitb25e27277dc39f25cfca4db8452d254f6cc8046e (patch)
treee1cbb6fe0b4768c06dc335a1ceb8719138473651 /test
parentdced0e57453ed4cf8703dee61454334baa5a034e (diff)
Transform hash keys by a hash [Feature #16274]
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_hash.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index ccc3355930..733bccd138 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -1638,6 +1638,9 @@ class TestHash < Test::Unit::TestCase
y = x.transform_keys.with_index {|k, i| "#{k}.#{i}" }
assert_equal(%w(a.0 b.1 c.2), y.keys)
+
+ assert_equal({A: 1, B: 2, c: 3}, x.transform_keys({a: :A, b: :B, d: :D}))
+ assert_equal({A: 1, B: 2, "c" => 3}, x.transform_keys({a: :A, b: :B, d: :D}, &:to_s))
end
def test_transform_keys_bang
@@ -1660,6 +1663,13 @@ class TestHash < Test::Unit::TestCase
x = @cls[true => :a, false => :b]
x.transform_keys! {|k| !k }
assert_equal([false, :a, true, :b], x.flatten)
+
+ x = @cls[a: 1, b: 2, c: 3]
+ x.transform_keys!({a: :A, b: :B, d: :D})
+ assert_equal({A: 1, B: 2, c: 3}, x)
+ x = @cls[a: 1, b: 2, c: 3]
+ x.transform_keys!({a: :A, b: :B, d: :D}, &:to_s)
+ assert_equal({A: 1, B: 2, "c" => 3}, x)
end
def test_transform_values