mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@4ce9f41
This commit is contained in:
parent
267bed0cd9
commit
727c97da19
108 changed files with 1325 additions and 270 deletions
|
@ -47,7 +47,89 @@ describe "Regexps with back-references" do
|
|||
/(a\1?){2}/.match("aaaa").to_a.should == ["aa", "a"]
|
||||
end
|
||||
|
||||
it "does not reset enclosed capture groups" do
|
||||
/((a)|(b))+/.match("ab").captures.should == [ "b", "a", "b" ]
|
||||
end
|
||||
|
||||
it "can match an optional quote, followed by content, followed by a matching quote, as the whole string" do
|
||||
/^("|)(.*)\1$/.match('x').to_a.should == ["x", "", "x"]
|
||||
end
|
||||
|
||||
it "allows forward references" do
|
||||
/(?:(\2)|(.))+/.match("aa").to_a.should == [ "aa", "a", "a" ]
|
||||
end
|
||||
|
||||
it "disallows forward references >= 10" do
|
||||
(/\10()()()()()()()()()()/ =~ "\x08").should == 0
|
||||
end
|
||||
|
||||
it "ignores backreferences > 1000" do
|
||||
/\99999/.match("99999")[0].should == "99999"
|
||||
end
|
||||
|
||||
it "0 is not a valid backreference" do
|
||||
-> { Regexp.new("\\k<0>") }.should raise_error(RegexpError)
|
||||
end
|
||||
|
||||
it "allows numeric conditional backreferences" do
|
||||
/(a)(?(1)a|b)/.match("aa").to_a.should == [ "aa", "a" ]
|
||||
/(a)(?(<1>)a|b)/.match("aa").to_a.should == [ "aa", "a" ]
|
||||
/(a)(?('1')a|b)/.match("aa").to_a.should == [ "aa", "a" ]
|
||||
end
|
||||
|
||||
it "allows either <> or '' in named conditional backreferences" do
|
||||
-> { Regexp.new("(?<a>a)(?(a)a|b)") }.should raise_error(RegexpError)
|
||||
/(?<a>a)(?(<a>)a|b)/.match("aa").to_a.should == [ "aa", "a" ]
|
||||
/(?<a>a)(?('a')a|b)/.match("aa").to_a.should == [ "aa", "a" ]
|
||||
end
|
||||
|
||||
it "allows negative numeric backreferences" do
|
||||
/(a)\k<-1>/.match("aa").to_a.should == [ "aa", "a" ]
|
||||
/(a)\g<-1>/.match("aa").to_a.should == [ "aa", "a" ]
|
||||
/(a)(?(<-1>)a|b)/.match("aa").to_a.should == [ "aa", "a" ]
|
||||
/(a)(?('-1')a|b)/.match("aa").to_a.should == [ "aa", "a" ]
|
||||
end
|
||||
|
||||
it "delimited numeric backreferences can start with 0" do
|
||||
/(a)\k<01>/.match("aa").to_a.should == [ "aa", "a" ]
|
||||
/(a)\g<01>/.match("aa").to_a.should == [ "aa", "a" ]
|
||||
/(a)(?(01)a|b)/.match("aa").to_a.should == [ "aa", "a" ]
|
||||
/(a)(?(<01>)a|b)/.match("aa").to_a.should == [ "aa", "a" ]
|
||||
/(a)(?('01')a|b)/.match("aa").to_a.should == [ "aa", "a" ]
|
||||
end
|
||||
|
||||
it "regular numeric backreferences cannot start with 0" do
|
||||
/(a)\01/.match("aa").should == nil
|
||||
/(a)\01/.match("a\x01").to_a.should == [ "a\x01", "a" ]
|
||||
end
|
||||
|
||||
it "named capture groups invalidate numeric backreferences" do
|
||||
-> { Regexp.new("(?<a>a)\\1") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(?<a>a)\\k<1>") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(a)(?<a>a)\\1") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(a)(?<a>a)\\k<1>") }.should raise_error(RegexpError)
|
||||
end
|
||||
|
||||
it "treats + or - as the beginning of a level specifier in \\k<> backreferences and (?(...)...|...) conditional backreferences" do
|
||||
-> { Regexp.new("(?<a+>a)\\k<a+>") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(?<a+b>a)\\k<a+b>") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(?<a+1>a)\\k<a+1>") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(?<a->a)\\k<a->") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(?<a-b>a)\\k<a-b>") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(?<a-1>a)\\k<a-1>") }.should raise_error(RegexpError)
|
||||
|
||||
-> { Regexp.new("(?<a+>a)(?(<a+>)a|b)") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(?<a+b>a)(?(<a+b>)a|b)") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(?<a+1>a)(?(<a+1>)a|b)") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(?<a->a)(?(<a->)a|b)") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(?<a-b>a)(?(<a-b>)a|b)") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(?<a-1>a)(?(<a-1>)a|b)") }.should raise_error(RegexpError)
|
||||
|
||||
-> { Regexp.new("(?<a+>a)(?('a+')a|b)") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(?<a+b>a)(?('a+b')a|b)") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(?<a+1>a)(?('a+1')a|b)") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(?<a->a)(?('a-')a|b)") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(?<a-b>a)(?('a-b')a|b)") }.should raise_error(RegexpError)
|
||||
-> { Regexp.new("(?<a-1>a)(?('a-1')a|b)") }.should raise_error(RegexpError)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue