summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-06-16 18:53:35 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-06-20 19:35:12 +0900
commit1e9939dae24db232d6f3693630fa37a382e1a6d7 (patch)
tree7bb1660444a068ce185c4ef636467861b40cae6c /test
parent39dc455b511614ee8a1911c0ba6445a0307d5e4f (diff)
[Feature #18788] Support options as `String` to `Regexp.new`
`Regexp.new` now supports passing the regexp flags not only as an `Integer`, but also as a `String. Unknown flags raise errors.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6039
Diffstat (limited to 'test')
-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 5ee6b1b03c..1d93d1a5b1 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -634,6 +634,23 @@ class TestRegexp < Test::Unit::TestCase
end
end
+ def test_initialize_option
+ assert_equal(//i, Regexp.new("", "i"))
+ assert_equal(//m, Regexp.new("", "m"))
+ assert_equal(//x, Regexp.new("", "x"))
+ assert_equal(//imx, Regexp.new("", "imx"))
+ assert_equal(//, Regexp.new("", ""))
+ assert_equal(//imx, Regexp.new("", "mimix"))
+
+ assert_raise(ArgumentError) { Regexp.new("", "e") }
+ assert_raise(ArgumentError) { Regexp.new("", "n") }
+ assert_raise(ArgumentError) { Regexp.new("", "s") }
+ assert_raise(ArgumentError) { Regexp.new("", "u") }
+ assert_raise(ArgumentError) { Regexp.new("", "o") }
+ assert_raise(ArgumentError) { Regexp.new("", "j") }
+ assert_raise(ArgumentError) { Regexp.new("", "xmen") }
+ end
+
def test_match_control_meta_escape
assert_equal(0, /\c\xFF/ =~ "\c\xFF")
assert_equal(0, /\c\M-\xFF/ =~ "\c\M-\xFF")