summaryrefslogtreecommitdiff
path: root/test/ruby/test_regexp.rb
diff options
context:
space:
mode:
authorJeremy Evans <[email protected]>2022-12-20 12:44:11 -0800
committerJeremy Evans <[email protected]>2022-12-22 11:50:26 -0800
commit7e8fa06022a9e412e3f8e6c8b6f0ba1909f648d5 (patch)
treed677df86e4df121b3b005fa7d91c1a084e7734fc /test/ruby/test_regexp.rb
parent9dcee2d80ee995e11b0fd437d4a94930ccb6db67 (diff)
Always issue deprecation warning when calling Regexp.new with 3rd positional argument
Previously, only certain values of the 3rd argument triggered a deprecation warning. First step for fix for bug #18797. Support for the 3rd argument will be removed after the release of Ruby 3.2. Fix minor fallout discovered by the tests. Co-authored-by: Nobuyoshi Nakada <[email protected]>
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6976
Diffstat (limited to 'test/ruby/test_regexp.rb')
-rw-r--r--test/ruby/test_regexp.rb40
1 files changed, 32 insertions, 8 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index fb2176d889..40d3559c0b 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -42,14 +42,14 @@ class TestRegexp < Test::Unit::TestCase
def test_yoshidam_net_20041111_1
s = "[\xC2\xA0-\xC3\xBE]"
- r = assert_deprecated_warning(/ignored/) {Regexp.new(s, nil, "u")}
+ r = assert_deprecated_warning(/3\.3/) {Regexp.new(s, nil, "u")}
assert_match(r, "\xC3\xBE")
end
def test_yoshidam_net_20041111_2
assert_raise(RegexpError) do
s = "[\xFF-\xFF]".force_encoding("utf-8")
- assert_warning(/ignored/) {Regexp.new(s, nil, "u")}
+ assert_warning(/3\.3/) {Regexp.new(s, nil, "u")}
end
end
@@ -646,13 +646,37 @@ class TestRegexp < Test::Unit::TestCase
assert_equal(/foo/, assert_no_warning(/ignored/) {Regexp.new(/foo/)})
assert_equal(/foo/, assert_no_warning(/ignored/) {Regexp.new(/foo/, timeout: nil)})
- assert_equal(Encoding.find("US-ASCII"), Regexp.new("b..", nil, "n").encoding)
- assert_equal("bar", "foobarbaz"[Regexp.new("b..", nil, "n")])
- assert_equal(//n, Regexp.new("", nil, "n"))
+ arg_encoding_none = //n.options # ARG_ENCODING_NONE is implementation defined value
- arg_encoding_none = 32 # ARG_ENCODING_NONE is implementation defined value
- assert_equal(arg_encoding_none, Regexp.new("", nil, "n").options)
- assert_equal(arg_encoding_none, Regexp.new("", nil, "N").options)
+ assert_deprecated_warning('') do
+ assert_equal(Encoding.find("US-ASCII"), Regexp.new("b..", Regexp::NOENCODING).encoding)
+ assert_equal("bar", "foobarbaz"[Regexp.new("b..", Regexp::NOENCODING)])
+ assert_equal(//, Regexp.new(""))
+ assert_equal(//, Regexp.new("", timeout: 1))
+ assert_equal(//n, Regexp.new("", Regexp::NOENCODING))
+ assert_equal(//n, Regexp.new("", Regexp::NOENCODING, timeout: 1))
+
+ assert_equal(arg_encoding_none, Regexp.new("", Regexp::NOENCODING).options)
+ end
+
+ assert_deprecated_warning(/3\.3/) do
+ assert_equal(Encoding.find("US-ASCII"), Regexp.new("b..", nil, "n").encoding)
+ end
+ assert_deprecated_warning(/3\.3/) do
+ assert_equal(Encoding.find("US-ASCII"), Regexp.new("b..", nil, "n", timeout: 1).encoding)
+ end
+ assert_deprecated_warning(/3\.3/) do
+ assert_equal("bar", "foobarbaz"[Regexp.new("b..", nil, "n")])
+ end
+ assert_deprecated_warning(/3\.3/) do
+ assert_equal(//n, Regexp.new("", nil, "n"))
+ end
+ assert_deprecated_warning(/3\.3/) do
+ assert_equal(arg_encoding_none, Regexp.new("", nil, "n").options)
+ end
+ assert_deprecated_warning(/3\.3/) do
+ assert_equal(arg_encoding_none, Regexp.new("", nil, "N").options)
+ end
assert_raise(RegexpError) { Regexp.new(")(") }
assert_raise(RegexpError) { Regexp.new('[\\40000000000') }