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

python: provide informative exception for trailing escapes in tables #241

Merged
merged 5 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ This project adheres to [Semantic Versioning](http://semver.org).
This document is formatted according to the principles of [Keep A CHANGELOG](http://keepachangelog.com).

## [Unreleased]
### Fixed
- [Python] Fix missing inconsistent cell count error with trailing escape ([#241](https://github.com/cucumber/gherkin/pull/241))

## [28.0.0] - 2024-02-15
### Added
Expand Down
2 changes: 1 addition & 1 deletion python/gherkin/gherkin_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def split_table_cells(self, row):
cell = ''
start_col = col + 1
elif char == '\\':
char = next(row)
char = next(row, "")
mpkorstanje marked this conversation as resolved.
Show resolved Hide resolved
col += 1
if char == 'n':
cell += '\n'
Expand Down
17 changes: 16 additions & 1 deletion python/test/gherkin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from gherkin.token_scanner import TokenScanner
from gherkin.token_matcher import TokenMatcher
from gherkin.parser import Parser
from gherkin.errors import ParserError
from gherkin.errors import CompositeParserException, ParserError
import pytest


Expand Down Expand Up @@ -89,3 +89,18 @@ def test_change_the_default_language():
}

assert expected == feature_file

@pytest.mark.parametrize("trailing_text", ["\\", "\\ "])
def test_inconsistent_cell_count_with_trailing_escape(trailing_text):
feature_text = """Feature:
Scenario:
Given I have a table
| Name | Value |
| A | """ + trailing_text
parser = Parser()

with pytest.raises(
CompositeParserException,
match="inconsistent cell count within the table",
mpkorstanje marked this conversation as resolved.
Show resolved Hide resolved
):
parser.parse(TokenScanner(feature_text))