diff options
author | Nobuyoshi Nakada <[email protected]> | 2022-06-19 15:43:27 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2022-06-20 19:35:12 +0900 |
commit | 883d13dc4127b5fde617b584ebb89714eac19965 (patch) | |
tree | 909777cb00ade5d33fa515eb540ccc8bf80d2e8c /spec/ruby/core | |
parent | 1e9939dae24db232d6f3693630fa37a382e1a6d7 (diff) |
[Feature #18788] Spec for options as `String` to `Regexp.new`
Co-Authored-By: Janosch Mùˆller <[email protected]>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6039
Diffstat (limited to 'spec/ruby/core')
-rw-r--r-- | spec/ruby/core/regexp/shared/new.rb | 39 |
1 files changed, 39 insertions, 0 deletions
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 |