From a1c2c274eebcc2a5275b677ebf94a8dbff380770 Mon Sep 17 00:00:00 2001 From: TSUYUSATO Kitsune Date: Wed, 19 Apr 2023 13:08:28 +0900 Subject: Refactor `Regexp#match` cache implementation (#7724) * Refactor Regexp#match cache implementation Improved variable and function names Fixed [Bug 19537] (Maybe fixed in https://github.com/ruby/ruby/pull/7694) * Add a comment of the glossary for "match cache" * Skip to reset match cache when no cache point on null check --- test/ruby/test_regexp.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'test/ruby') diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index d50e481d2d..83dcb69530 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -1733,7 +1733,7 @@ class TestRegexp < Test::Unit::TestCase end; end - def test_cache_optimization_exponential + def test_match_cache_exponential assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}") timeout = #{ EnvUtil.apply_timeout_scale(10).inspect } begin; @@ -1743,7 +1743,7 @@ class TestRegexp < Test::Unit::TestCase end; end - def test_cache_optimization_square + def test_match_cache_square assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}") timeout = #{ EnvUtil.apply_timeout_scale(10).inspect } begin; @@ -1753,7 +1753,7 @@ class TestRegexp < Test::Unit::TestCase end; end - def test_cache_index_initialize + def test_cache_opcodes_initialize str = 'test1-test2-test3-test4-test_5' re = '^([0-9a-zA-Z\-/]*){1,256}$' 100.times do @@ -1781,6 +1781,14 @@ class TestRegexp < Test::Unit::TestCase assert_equal("123456789".match(/(?:x?\dx?){2,}/)[0], "123456789") end + def test_bug_19537 + str = 'aac' + re = '^([ab]{1,3})(a?)*$' + 100.times do + assert !Regexp.new(re).match?(str) + end + end + def test_linear_time_p assert_send [Regexp, :linear_time?, /a/] assert_send [Regexp, :linear_time?, 'a'] -- cgit v1.2.3