diff options
Diffstat (limited to 'spec/ruby/language/regexp_spec.rb')
| -rw-r--r-- | spec/ruby/language/regexp_spec.rb | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/spec/ruby/language/regexp_spec.rb b/spec/ruby/language/regexp_spec.rb index d4b0c81128..1452b01935 100644 --- a/spec/ruby/language/regexp_spec.rb +++ b/spec/ruby/language/regexp_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) +require_relative '../spec_helper' +require_relative 'fixtures/classes' describe "Literal Regexps" do it "matches against $_ (last input) in a conditional if no explicit matchee provided" do @@ -15,7 +15,11 @@ describe "Literal Regexps" do end it "yields a Regexp" do - /Hello/.should be_kind_of(Regexp) + /Hello/.should.is_a?(Regexp) + end + + it "is frozen" do + /Hello/.should.frozen? end it "caches the Regexp object" do @@ -23,11 +27,11 @@ describe "Literal Regexps" do 2.times do |i| rs << /foo/ end - rs[0].should equal(rs[1]) + rs[0].should.equal?(rs[1]) end it "throws SyntaxError for malformed literals" do - lambda { eval('/(/') }.should raise_error(SyntaxError) + -> { eval('/(/') }.should.raise(SyntaxError) end ############################################################################# @@ -54,22 +58,22 @@ describe "Literal Regexps" do it "disallows first part of paired delimiters to be used as non-paired delimiters" do LanguageSpecs.paired_delimiters.each do |p0, p1| - lambda { eval("%r#{p0} foo #{p0}") }.should raise_error(SyntaxError) + -> { eval("%r#{p0} foo #{p0}") }.should.raise(SyntaxError) end end - it "supports non-paired delimiters delimiters with %r" do + it "supports non-paired delimiters with %r" do LanguageSpecs.non_paired_delimiters.each do |c| eval("%r#{c} foo #{c}").should == / foo / end end it "disallows alphabets as non-paired delimiter with %r" do - lambda { eval('%ra foo a') }.should raise_error(SyntaxError) + -> { eval('%ra foo a') }.should.raise(SyntaxError) end it "disallows spaces after %r and delimiter" do - lambda { eval('%r !foo!') }.should raise_error(SyntaxError) + -> { eval('%r !foo!') }.should.raise(SyntaxError) end it "allows unescaped / to be used with %r" do @@ -85,19 +89,18 @@ describe "Literal Regexps" do # Basic matching /./.match("foo").to_a.should == ["f"] # Basic non-matching - /./.match("").should be_nil - /./.match("\n").should be_nil + /./.match("").should == nil + /./.match("\n").should == nil /./.match("\0").to_a.should == ["\0"] end - it "supports | (alternations)" do /a|b/.match("a").to_a.should == ["a"] end it "supports (?> ) (embedded subexpression)" do /(?>foo)(?>bar)/.match("foobar").to_a.should == ["foobar"] - /(?>foo*)obar/.match("foooooooobar").should be_nil # it is possesive + /(?>foo*)obar/.match("foooooooobar").should == nil # it is possessive end it "supports (?# )" do @@ -109,6 +112,13 @@ describe "Literal Regexps" do /foo.(?<=\d)/.match("fooA foo1").to_a.should == ["foo1"] end + ruby_bug "#13671", ""..."4.0" do # https://bugs.ruby-lang.org/issues/13671 + it "handles a lookbehind with ss characters" do + r = Regexp.new("(?<!dss)", Regexp::IGNORECASE) + r.should =~ "✨" + end + end + it "supports (?<! ) (negative lookbehind)" do /foo.(?<!\d)/.match("foo1 fooA").to_a.should == ["fooA"] end @@ -125,9 +135,9 @@ describe "Literal Regexps" do it "supports possessive quantifiers" do /fooA++bar/.match("fooAAAbar").to_a.should == ["fooAAAbar"] - /fooA++Abar/.match("fooAAAbar").should be_nil - /fooA?+Abar/.match("fooAAAbar").should be_nil - /fooA*+Abar/.match("fooAAAbar").should be_nil + /fooA++Abar/.match("fooAAAbar").should == nil + /fooA?+Abar/.match("fooAAAbar").should == nil + /fooA*+Abar/.match("fooAAAbar").should == nil end it "supports conditional regular expressions with positional capture groups" do @@ -147,4 +157,11 @@ describe "Literal Regexps" do pattern.should_not =~ 'fooF' pattern.should_not =~ 'T' end + + it "support handling unicode 9.0 characters with POSIX bracket expressions" do + char_lowercase = "\u{104D8}" # OSAGE SMALL LETTER A + /[[:lower:]]/.match(char_lowercase).to_s.should == char_lowercase + char_uppercase = "\u{104B0}" # OSAGE CAPITAL LETTER A + /[[:upper:]]/.match(char_uppercase).to_s.should == char_uppercase + end end |
