Skip to content

Commit

Permalink
[Gherkin / ruby] Do not trim spaces inside a table cell content (see #…
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-psarga committed Oct 23, 2019
1 parent 4ff82b1 commit fea8d71
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gherkin/ruby/lib/gherkin/gherkin_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def table_cells
cells = []

self.split_table_cells(@trimmed_line_text) do |item, column|
txt_trimmed_left = item.gsub(/^[ \t\n\v\f\r\u0085\u00A0]*/, '')
txt_trimmed = txt_trimmed_left.gsub(/[ \t\n\v\f\r\u0085\u00A0]*$/, '')
txt_trimmed_left = item.gsub(/\A[ \t\n\v\f\r\u0085\u00A0]*/, '')
txt_trimmed = txt_trimmed_left.gsub(/[ \t\n\v\f\r\u0085\u00A0]*\Z/, '')
cell_indent = item.length - txt_trimmed_left.length
span = Span.new(@indent + column + cell_indent, txt_trimmed)
cells.push(span)
Expand Down
20 changes: 20 additions & 0 deletions gherkin/ruby/spec/gherkin/gherkin_line_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'rspec'
require 'gherkin/gherkin_line'

describe Gherkin::GherkinLine do
context '#table_cell' do
def cells_text(line)
Gherkin::GherkinLine.new(line, 12).table_cells.map(&:text)
end

it 'correctly trims cells content' do
expect(cells_text("|spaces after |")).to eq(['spaces after'])
expect(cells_text("| \t spaces before|")).to eq(['spaces before'])
expect(cells_text("| \t spaces everywhere \t|")).to eq(['spaces everywhere'])
end

it 'does not drop white spaces inside a cell' do
expect(cells_text("| foo()\n bar\nbaz |")).to eq(["foo()\n bar\nbaz"])
end
end
end

0 comments on commit fea8d71

Please sign in to comment.