ruby-changes:72254
From: Nobuyoshi <ko1@a...>
Date: Mon, 20 Jun 2022 19:35:27 +0900 (JST)
Subject: [ruby-changes:72254] 39dc455b51 (master): Spec update for warnning suspicious flag to `Regexp.new`
https://git.ruby-lang.org/ruby.git/commit/?id=39dc455b51 From 39dc455b511614ee8a1911c0ba6445a0307d5e4f Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 19 Jun 2022 15:41:24 +0900 Subject: Spec update for warnning suspicious flag to `Regexp.new` --- spec/ruby/core/regexp/shared/new.rb | 37 +++++++++++++++++++++++++++++++------ 1 file 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/regexp/shared/new.rb#L58 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/regexp/shared/new.rb#L97 (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 -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/