Permalink
Browse files

Merge branch 'use_non_capturing_groups' of https://github.com/twalpol…

…e/cucumber into twalpole-use_non_capturing_groups
  • Loading branch information...
2 parents 9bcd1b6 + a1ae588 commit ee47e82fa486dd7c9bef5a8260734a26d9fff1fe @aslakhellesoy aslakhellesoy committed Sep 11, 2011
Showing with 11 additions and 4 deletions.
  1. +5 −2 lib/cucumber/rb_support/rb_transform.rb
  2. +6 −2 spec/cucumber/rb_support/rb_transform_spec.rb
@@ -34,11 +34,14 @@ def invoke(arg)
end
def to_s
- strip_captures(strip_anchors(@regexp.source))
+ convert_captures(strip_anchors(@regexp.source))
end
private
-
+ def convert_captures(regexp_source)
+ regexp_source.gsub(/(\()(?!\?:)/,'(?:')
+ end
+
def strip_captures(regexp_source)
regexp_source.
gsub(/(\()/, '').
@@ -8,8 +8,12 @@ def transform(regexp)
RbTransform.new(nil, regexp, lambda { |a| })
end
describe "#to_s" do
- it "removes the capture group parentheses" do
- transform(/(a)bc/).to_s.should == "abc"
+ it "converts captures groups to non-capture groups" do
+ transform(/(a|b)bc/).to_s.should == "(?:a|b)bc"
+ end
+
+ it "leaves non capture groups alone" do
+ transform(/(?:a|b)bc/).to_s.should == "(?:a|b)bc"
end
it "strips away anchors" do

0 comments on commit ee47e82

Please sign in to comment.