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

Fix DataTable's Location to be aware of all of its lines #142

Merged
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
6 changes: 6 additions & 0 deletions lib/cucumber/core/gherkin/ast_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,12 @@ def result
def rows
attributes[:rows] = attributes[:rows].map { |r| r[:cells].map { |c| c[:value] } }
end

def location
first_line = attributes[:location][:line]
last_line = first_line + attributes[:rows].length - 1
Ast::Location.new(file, first_line..last_line)
end
end

class DocStringBuilder < Builder
Expand Down
19 changes: 18 additions & 1 deletion spec/cucumber/core/test/filters/locations_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ module Cucumber::Core
Given a table
| a | b |
| 1 | 2 |
| 3 | 4 |

END
end

Expand Down Expand Up @@ -192,10 +194,25 @@ def test_case_named(name)
test_cases.find { |c| c.name == 'with a table' }
end

it "matches a location on the first table row" do
it "matches a location at the start of the table" do
location = Ast::Location.new(file, 23)
expect( test_case.match_locations?([location]) ).to be_truthy
end

it "matches a location in the middle of the table" do
location = Ast::Location.new(file, 24)
expect( test_case.match_locations?([location]) ).to be_truthy
end

it "matches a location at the end of the table" do
location = Ast::Location.new(file, 25)
expect( test_case.match_locations?([location]) ).to be_truthy
end

it "does not match a location after the table" do
location = Ast::Location.new(file, 26)
expect( test_case.match_locations?([location]) ).to be_falsey
end
end

context "with duplicate locations in the filter" do
Expand Down