diff options
author | Hiroya Fujinami <make.just.on@gmail.com> | 2023-10-30 13:10:42 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-30 13:10:42 +0900 |
commit | 34cb174800e1e41323807c99386641b688927adc (patch) | |
tree | 62a1ac23fa566aff85a18042655bebbd2bd750ab /test/ruby/test_regexp.rb | |
parent | 13c9cbe09ef310c7ddf055d57ebf4586e9f9a111 (diff) |
Optimize regexp matching for look-around and atomic groups (#7931)
Diffstat (limited to 'test/ruby/test_regexp.rb')
-rw-r--r-- | test/ruby/test_regexp.rb | 64 |
1 files changed, 59 insertions, 5 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index a0025b53ce..74c6ba2897 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -1826,7 +1826,6 @@ class TestRegexp < Test::Unit::TestCase timeout = #{ EnvUtil.apply_timeout_scale(10).inspect } begin; Regexp.timeout = timeout - assert_nil(/^(a*)*$/ =~ "a" * 1000000 + "x") end; end @@ -1836,7 +1835,6 @@ class TestRegexp < Test::Unit::TestCase timeout = #{ EnvUtil.apply_timeout_scale(10).inspect } begin; Regexp.timeout = timeout - assert_nil(/^a*b?a*$/ =~ "a" * 1000000 + "x") end; end @@ -1846,8 +1844,61 @@ class TestRegexp < Test::Unit::TestCase timeout = #{ EnvUtil.apply_timeout_scale(10).inspect } begin; Regexp.timeout = timeout + assert_nil(/^a*?(?>a*a*)$/ =~ "a" * 1000000 + "x") + end; + end - assert_nil(/^(?>a?a?)(a|a)*$/ =~ "a" * 1000000 + "x") + def test_match_cache_atomic_complex + assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}") + timeout = #{ EnvUtil.apply_timeout_scale(10).inspect } + begin; + Regexp.timeout = timeout + assert_nil(/a*(?>a*)ab/ =~ "a" * 1000000 + "b") + end; + end + + def test_match_cache_positive_look_ahead + assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}") + timeout = #{ EnvUtil.apply_timeout_scale(10).inspect } + begin; + Regexp.timeout = timeout + assert_nil(/^a*?(?=a*a*)$/ =~ "a" * 1000000 + "x") + end; + end + + def test_match_cache_positive_look_ahead_complex + assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}") + timeout = #{ EnvUtil.apply_timeout_scale(10).inspect } + begin; + Regexp.timeout = timeout + assert_equal(/(?:(?=a*)a)*/ =~ "a" * 1000000, 0) + end; + end + + def test_match_cache_negative_look_ahead + assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}") + timeout = #{ EnvUtil.apply_timeout_scale(10).inspect } + begin; + Regexp.timeout = timeout + assert_nil(/^a*?(?!a*a*)$/ =~ "a" * 1000000 + "x") + end; + end + + def test_match_cache_positive_look_behind + assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}") + timeout = #{ EnvUtil.apply_timeout_scale(10).inspect } + begin; + Regexp.timeout = timeout + assert_nil(/(?<=abc|def)(a|a)*$/ =~ "abc" + "a" * 1000000 + "x") + end; + end + + def test_match_cache_negative_look_behind + assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}") + timeout = #{ EnvUtil.apply_timeout_scale(10).inspect } + begin; + Regexp.timeout = timeout + assert_nil(/(?<!x)(a|a)*$/ =~ "a" * 1000000 + "x") end; end @@ -1864,7 +1915,7 @@ class TestRegexp < Test::Unit::TestCase assert_equal("10:0:0".match(pattern)[0], "10:0:0") end - def test_bug_19467 + def test_bug_19467 # [Bug #19467] assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}") timeout = #{ EnvUtil.apply_timeout_scale(10).inspect } begin; @@ -1879,7 +1930,7 @@ class TestRegexp < Test::Unit::TestCase assert_equal("123456789".match(/(?:x?\dx?){2,}/)[0], "123456789") end - def test_bug_19537 + def test_bug_19537 # [Bug #19537] str = 'aac' re = '^([ab]{1,3})(a?)*$' 100.times do @@ -1894,6 +1945,9 @@ class TestRegexp < Test::Unit::TestCase assert_not_send [Regexp, :linear_time?, /(a)\1/] assert_not_send [Regexp, :linear_time?, "(a)\\1"] + assert_not_send [Regexp, :linear_time?, /(?=(a))/] + assert_not_send [Regexp, :linear_time?, /(?!(a))/] + assert_raise(TypeError) {Regexp.linear_time?(nil)} assert_raise(TypeError) {Regexp.linear_time?(Regexp.allocate)} end |