Skip to content

Commit

Permalink
Support alternative docstrings format (```) (#214)
Browse files Browse the repository at this point in the history
* Support alternative docstrings format (```)

* Ensure pystring delimiter is first thing on line after whitespace
  • Loading branch information
ciaranmcnulty authored Mar 9, 2021
1 parent 71a3158 commit a582f60
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/Behat/Gherkin/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Lexer
private $featureStarted = false;
private $allowMultilineArguments = false;
private $allowSteps = false;
private $pyStringDelimiter = null;

/**
* Initializes lexer.
Expand Down Expand Up @@ -435,13 +436,25 @@ protected function scanPyStringOp()
return null;
}

if (false === ($pos = mb_strpos($this->line, '"""', 0, 'utf8'))) {
if(!preg_match('/^\s*(?<delimiter>"""|```)/u', $this->line, $matches, PREG_OFFSET_CAPTURE)) {
return null;
}

['delimiter' => [0 => $delimiter, 1 => $indent]] = $matches;

if ($this->inPyString) {
if ($this->pyStringDelimiter !== $delimiter) {
return null;
}
$this->pyStringDelimiter = null;
}
else {
$this->pyStringDelimiter= $delimiter;
}

$this->inPyString = !$this->inPyString;
$token = $this->takeToken('PyStringOp');
$this->pyStringSwallow = $pos;
$this->pyStringSwallow = $indent;

$this->consumeLine();

Expand Down
1 change: 0 additions & 1 deletion tests/Behat/Gherkin/Cucumber/CompatibilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class CompatibilityTest extends TestCase
'complex_background.feature' => 'Rule keyword not supported',
'rule.feature' => 'Rule keyword not supported',
'descriptions.feature' => 'Examples table descriptions not supported',
'docstrings.feature' => 'Docstrings with ``` separators not supported',
'incomplete_scenario_outline.feature' => 'Scenario and Scenario outline not yet synonyms',
'padded_example.feature' => 'Scenario and Scenario outline not yet synonyms',
'scenario_outline.feature' => 'Scenario and Scenario outline not yet synonyms',
Expand Down

0 comments on commit a582f60

Please sign in to comment.