Skip to content

Commit

Permalink
Fix DataTable's Location to be aware of all of its lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
botandrose-machine committed Aug 18, 2017
1 parent ffe17a6 commit 09009a0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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
20 changes: 19 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,9 @@ module Cucumber::Core
Given a table
| a | b |
| 1 | 2 |
| 3 | 4 |
Scenario: empty
END
end

Expand Down Expand Up @@ -192,10 +195,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

0 comments on commit 09009a0

Please sign in to comment.