diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-06-19 15:41:24 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-06-20 19:35:12 +0900 |
commit | 39dc455b511614ee8a1911c0ba6445a0307d5e4f (patch) | |
tree | 35b0076f8fedbcf72be56326fc83140511ce9111 /spec | |
parent | ab2a43265cfdda288d1baaa29936fd408c2a42bc (diff) |
Spec update for warnning suspicious flag to `Regexp.new`
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6039
Diffstat (limited to 'spec')
-rw-r--r-- | spec/ruby/core/regexp/shared/new.rb | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/spec/ruby/core/regexp/shared/new.rb b/spec/ruby/core/regexp/shared/new.rb index 9cbf89cd8b..876c29151c 100644 --- a/spec/ruby/core/regexp/shared/new.rb +++ b/spec/ruby/core/regexp/shared/new.rb @@ -58,6 +58,15 @@ describe :regexp_new_string, shared: true do end end + it "sets options from second argument if it is true" do + r = Regexp.send(@method, 'Hi', true) + (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 + end + it "sets options from second argument if it is one of the Integer option constants" do r = Regexp.send(@method, 'Hi', Regexp::IGNORECASE) (r.options & Regexp::IGNORECASE).should_not == 0 @@ -88,12 +97,28 @@ describe :regexp_new_string, shared: true do (r.options & Regexp::EXTENDED).should_not == 0 end - it "treats any non-Integer, non-nil, non-false second argument as IGNORECASE" do - r = Regexp.send(@method, 'Hi', Object.new) - (r.options & Regexp::IGNORECASE).should_not == 0 - (r.options & Regexp::MULTILINE).should == 0 - not_supported_on :opal do - (r.options & Regexp::EXTENDED).should == 0 + ruby_version_is ""..."3.2" do + it "treats any non-Integer, non-nil, non-false second argument as IGNORECASE" do + r = Regexp.send(@method, 'Hi', Object.new) + (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 + end + end + + ruby_version_is "3.2" do + it "warns any non-Integer, non-nil, non-false second argument" do + r = nil + -> { + r = Regexp.send(@method, 'Hi', Object.new) + }.should complain(/expected true or false as ignorecase/, {verbose: true}) + (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 end end |