diff options
author | Kenichi Kamiya <kachick1@gmail.com> | 2021-03-28 09:14:57 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-28 09:14:57 +0900 |
commit | 31e0382723bfb35cffe3ca485dd0577668cafa07 (patch) | |
tree | 09d09fa724f0a0ea6f47b7d13328c00c18b5bc97 /test | |
parent | e398a0e53a7207152fb2139f1e4485968a07f9de (diff) |
Keep non evaluated keys in `Hash#transform_keys!` [Bug #17735]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4294
Merged-By: nobu <nobu@ruby-lang.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_hash.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index bd94b408bb..23df2410d7 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -1765,6 +1765,10 @@ class TestHash < Test::Unit::TestCase x.transform_keys! {|k| -k } assert_equal([-1, :a, 1, :b], x.flatten) + x = @cls[a: 1, b: 2, c: 3] + x.transform_keys! { |k| k == :b && break } + assert_equal({false => 1, b: 2, c: 3}, x) + x = @cls[true => :a, false => :b] x.transform_keys! {|k| !k } assert_equal([false, :a, true, :b], x.flatten) @@ -1801,6 +1805,10 @@ class TestHash < Test::Unit::TestCase assert_same(x, y) x = @cls[a: 1, b: 2, c: 3] + x.transform_values! { |v| v == 2 && break } + assert_equal({a: false, b: 2, c: 3}, x) + + x = @cls[a: 1, b: 2, c: 3] y = x.transform_values!.with_index {|v, i| "#{v}.#{i}" } assert_equal(%w(1.0 2.1 3.2), y.values_at(:a, :b, :c)) |