diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2026-01-15 20:32:20 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2026-01-15 20:32:20 +0900 |
| commit | 11edc286d837f66b37433e7d51c8b8f500e1be84 (patch) | |
| tree | e5afcfa53807e17814da4b70b442515e0cf6fada /test/ruby | |
| parent | 6afac93c5c7178c4d836e0ec2b4b3092373ca121 (diff) | |
Make `Array#map` and `Array#select` more tolerant
Only when YJIT is enabled, the redefinition of `Array#<<` affects
these methods.
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_array.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index d93b86e795..04e15b6d87 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -1336,6 +1336,28 @@ class TestArray < Test::Unit::TestCase assert_equal(@cls[@cls[1,2], nil, 'dog', 'cat'], a.prepend(@cls[1, 2])) end + def test_tolerant_to_redefinition + *code = __FILE__, __LINE__+1, "#{<<-"{#"}\n#{<<-'};'}" + {# + module M + def <<(a) + super(a * 2) + end + end + class Array; prepend M; end + ary = [*1..10] + mapped = ary.map {|i| i} + selected = ary.select {true} + module M + remove_method :<< + end + assert_equal(ary, mapped) + assert_equal(ary, selected) + }; + assert_separately(%w[--disable-yjit], *code) + assert_separately(%w[--enable-yjit], *code) + end + def test_push a = @cls[1, 2, 3] assert_equal(@cls[1, 2, 3, 4, 5], a.push(4, 5)) |
