diff options
author | Marc-Andre Lafortune <[email protected]> | 2020-12-08 21:20:37 -0500 |
---|---|---|
committer | Marc-André Lafortune <[email protected]> | 2020-12-15 12:54:45 -0500 |
commit | d5f0d338c7b5d3d64929b51d29061d369550e8c4 (patch) | |
tree | df9905cc1d66eda457942bceecfde4f66c4a5944 /test/ruby/test_enum.rb | |
parent | a039dc018ccf34e217f767eac500b9400c58f069 (diff) |
Optimize `Enumerable#grep{_v}`
[Bug #17030]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3868
Diffstat (limited to 'test/ruby/test_enum.rb')
-rw-r--r-- | test/ruby/test_enum.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index 8d30b343a8..aa93b95c2a 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -63,6 +63,27 @@ class TestEnumerable < Test::Unit::TestCase assert_equal([[2, 1], [2, 4]], a) end + def test_grep_optimization + bug17030 = '[ruby-core:99156]' + 'set last match' =~ /set last (.*)/ + assert_equal([:a, 'b', :c], [:a, 'b', 'z', :c, 42, nil].grep(/[a-d]/)) + assert_equal(['z', 42, nil], [:a, 'b', 'z', :c, 42, nil].grep_v(/[a-d]/)) + assert_equal('match', $1) + + regexp = Regexp.new('x') + assert_equal([], @obj.grep(regexp)) # sanity check + def regexp.===(other) + true + end + assert_equal([1, 2, 3, 1, 2], @obj.grep(regexp)) + + o = Object.new + def o.to_str + 'hello' + end + assert_same(o, [o].grep(/ll/).first) + end + def test_count assert_equal(5, @obj.count) assert_equal(2, @obj.count(1)) |