Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace capturing groups with non-capturing in RbTransform#to_s #106

Merged
merged 1 commit into from
Sep 11, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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