Skip to content

Commit

Permalink
replace capturing groups with non-capturing in RbTransform#to_s
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Jul 13, 2011
1 parent a514db1 commit a1ae588
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/cucumber/rb_support/rb_transform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(/(\()/, '').
Expand Down
8 changes: 6 additions & 2 deletions spec/cucumber/rb_support/rb_transform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a1ae588

Please sign in to comment.