summaryrefslogtreecommitdiff
path: root/test/ruby/test_regexp.rb
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2022-03-24 17:00:51 +0900
committerYusuke Endoh <mame@ruby-lang.org>2022-03-30 16:50:46 +0900
commitce87bb8bd64869c0d04026d6bca41dc6bd312a73 (patch)
tree69c047a29b1ccafb94b62afc5cd76830d2294dc8 /test/ruby/test_regexp.rb
parentffc3b37f969a779f93b8f8a5b3591b4ef7de1538 (diff)
re.c: Add `timeout` keyword for Regexp.new and Regexp#timeout
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5703
Diffstat (limited to 'test/ruby/test_regexp.rb')
-rw-r--r--test/ruby/test_regexp.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index 7bcddc6e07..63572cf84a 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -1474,4 +1474,21 @@ class TestRegexp < Test::Unit::TestCase
assert_in_delta(0.2, t, 0.1)
end;
end
+
+ def test_timeout
+ assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}")
+ begin;
+ Regexp.timeout = 3 # This should be ignored
+
+ re = Regexp.new("^a*b?a*$", timeout: 0.2)
+
+ t = Time.now
+ assert_raise_with_message(RuntimeError, "regexp match timeout") do
+ re =~ "a" * 1000000 + "x"
+ end
+ t = Time.now - t
+
+ assert_in_delta(0.2, t, 0.1)
+ end;
+ end
end