Skip to content

Commit ed5da28

Browse files
trinistreregon
authored andcommitted
Add more tests for Regexp.linear_time?
> The cache-based optimization now supports lookarounds and atomic groupings. That is, match for Regexp containing these extensions can now also be performed in linear time to the length of the input string. However, these cannot contain captures and cannot be nested. [Feature #19725]
1 parent a16dbca commit ed5da28

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

core/regexp/linear_time_spec.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,27 @@
2525
}.should complain(/warning: flags ignored/)
2626
end
2727

28-
it "returns true for positive lookarounds" do
29-
Regexp.linear_time?(/(?:(?=a*)a)*/).should == true
28+
it "returns true for positive lookahead" do
29+
Regexp.linear_time?(/a*(?:(?=a*)a)*b/).should == true
30+
end
31+
32+
it "returns true for positive lookbehind" do
33+
Regexp.linear_time?(/a*(?:(?<=a)a*)*b/).should == true
34+
end
35+
36+
it "returns true for negative lookahead" do
37+
Regexp.linear_time?(/a*(?:(?!a*)a*)*b/).should == true
38+
end
39+
40+
it "returns true for negative lookbehind" do
41+
Regexp.linear_time?(/a*(?:(?<!a)a*)*b/).should == true
42+
end
43+
44+
it "returns true for atomic groups" do
45+
Regexp.linear_time?(/a*(?:(?>a)a*)*b/).should == true
46+
end
47+
48+
it "returns true for possessive quantifiers" do
49+
Regexp.linear_time?(/a*(?:(?:a)?+a*)*b/).should == true
3050
end
3151
end

0 commit comments

Comments
 (0)