From 883d13dc4127b5fde617b584ebb89714eac19965 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 19 Jun 2022 15:43:27 +0900 Subject: [Feature #18788] Spec for options as `String` to `Regexp.new` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Janosch Mùˆller --- spec/ruby/core/regexp/shared/new.rb | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/spec/ruby/core/regexp/shared/new.rb b/spec/ruby/core/regexp/shared/new.rb index 876c29151c..a6d9c48112 100644 --- a/spec/ruby/core/regexp/shared/new.rb +++ b/spec/ruby/core/regexp/shared/new.rb @@ -120,6 +120,45 @@ describe :regexp_new_string, shared: true do (r.options & Regexp::EXTENDED).should == 0 end end + + it "accepts a String of supported flags as the second argument" do + r = Regexp.send(@method, 'Hi', 'i') + (r.options & Regexp::IGNORECASE).should_not == 0 + (r.options & Regexp::MULTILINE).should == 0 + not_supported_on :opal do + (r.options & Regexp::EXTENDED).should == 0 + end + + r = Regexp.send(@method, 'Hi', 'imx') + (r.options & Regexp::IGNORECASE).should_not == 0 + (r.options & Regexp::MULTILINE).should_not == 0 + not_supported_on :opal do + (r.options & Regexp::EXTENDED).should_not == 0 + end + + r = Regexp.send(@method, 'Hi', 'mimi') + (r.options & Regexp::IGNORECASE).should_not == 0 + (r.options & Regexp::MULTILINE).should_not == 0 + not_supported_on :opal do + (r.options & Regexp::EXTENDED).should == 0 + end + + r = Regexp.send(@method, 'Hi', '') + (r.options & Regexp::IGNORECASE).should == 0 + (r.options & Regexp::MULTILINE).should == 0 + not_supported_on :opal do + (r.options & Regexp::EXTENDED).should == 0 + end + end + + it "raises an Argument error if the second argument contains unsupported chars" do + -> { Regexp.send(@method, 'Hi', 'e') }.should raise_error(ArgumentError) + -> { Regexp.send(@method, 'Hi', 'n') }.should raise_error(ArgumentError) + -> { Regexp.send(@method, 'Hi', 's') }.should raise_error(ArgumentError) + -> { Regexp.send(@method, 'Hi', 'u') }.should raise_error(ArgumentError) + -> { Regexp.send(@method, 'Hi', 'j') }.should raise_error(ArgumentError) + -> { Regexp.send(@method, 'Hi', 'mjx') }.should raise_error(ArgumentError) + end end it "ignores the third argument if it is 'e' or 'euc' (case-insensitive)" do -- cgit v1.2.3