mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[Feature #18788] Spec for options as String
to Regexp.new
Co-Authored-By: Janosch Müller <janosch.mueller@betterplace.org>
This commit is contained in:
parent
1e9939dae2
commit
883d13dc41
Notes:
git
2022-06-20 19:35:33 +09:00
1 changed files with 39 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue