Skip to content

Commit 0855c55

Browse files
authored
Merge pull request #142 from botandrose/fix_data_table_location_lines
Fix DataTable's Location to be aware of all of its lines
2 parents ffe17a6 + eca5299 commit 0855c55

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/cucumber/core/gherkin/ast_builder.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,12 @@ def result
373373
def rows
374374
attributes[:rows] = attributes[:rows].map { |r| r[:cells].map { |c| c[:value] } }
375375
end
376+
377+
def location
378+
first_line = attributes[:location][:line]
379+
last_line = first_line + attributes[:rows].length - 1
380+
Ast::Location.new(file, first_line..last_line)
381+
end
376382
end
377383

378384
class DocStringBuilder < Builder

spec/cucumber/core/test/filters/locations_filter_spec.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ module Cucumber::Core
9696
Given a table
9797
| a | b |
9898
| 1 | 2 |
99+
| 3 | 4 |
100+
99101
END
100102
end
101103

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

195-
it "matches a location on the first table row" do
197+
it "matches a location at the start of the table" do
196198
location = Ast::Location.new(file, 23)
197199
expect( test_case.match_locations?([location]) ).to be_truthy
198200
end
201+
202+
it "matches a location in the middle of the table" do
203+
location = Ast::Location.new(file, 24)
204+
expect( test_case.match_locations?([location]) ).to be_truthy
205+
end
206+
207+
it "matches a location at the end of the table" do
208+
location = Ast::Location.new(file, 25)
209+
expect( test_case.match_locations?([location]) ).to be_truthy
210+
end
211+
212+
it "does not match a location after the table" do
213+
location = Ast::Location.new(file, 26)
214+
expect( test_case.match_locations?([location]) ).to be_falsey
215+
end
199216
end
200217

201218
context "with duplicate locations in the filter" do

0 commit comments

Comments
 (0)