summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2021-04-15 10:11:19 +0900
committernagachika <nagachika@ruby-lang.org>2021-04-15 10:25:30 +0900
commit84d9a9afc0b49d095541acb9832f8b12fb506e19 (patch)
tree1f6b27559c103dfffbe0977f0fe014e20ac07537 /test
parentd5a34e1b142eccc54971494be2243a0c6ac01d94 (diff)
merge revision(s) 31e0382723bfb35cffe3ca485dd0577668cafa07,5e5fb72f99701dc27c66ab148471893f14e6d6f0,fb6ebe55d91187d9635e0183d47dbf38e95b1141,522d4cd32f7727886f4fcbc28ed29c08d361ee20: [Backport #17735]
Keep non evaluated keys in `Hash#transform_keys!` [Bug #17735] --- hash.c | 6 +++++- spec/ruby/core/hash/transform_keys_spec.rb | 12 +++++++++++- test/ruby/test_hash.rb | 8 ++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) Clear an intermediate hash [Bug #17735] --- hash.c | 1 + 1 file changed, 1 insertion(+) Hide an intermediate array --- hash.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) Force recycle intermediate collection in Hash#transform_keys! [Bug #17735] * Force recycle intermediate hash * Force recycle intermediate array too https://github.com/ruby/ruby/pull/4329#issuecomment-808840718 --- hash.c | 2 ++ 1 file changed, 2 insertions(+)
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_hash.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index 62d8b3f836..812b9e60ff 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -1674,6 +1674,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)
@@ -1710,6 +1714,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))
end