Skip to content

Commit

Permalink
Behat#117 simple merging function was implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
stukalin committed Nov 15, 2016
1 parent ffd34be commit 6f09f3d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
22 changes: 22 additions & 0 deletions src/Behat/Gherkin/Node/TableNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,28 @@ public function getIterator()
return new ArrayIterator($this->getHash());
}

/**
* Obtains and adds rows from another table to the current table.
* The second table should have the same structure as the current one.
* @param TableNode $node
*/
public function mergeRowsFromTable(TableNode $node)
{
// check structure
if ($this->getRow(0) !== $node->getRow(0)) {
throw new NodeException("Tables have different structure. Cannot merge one into another");
}

$firstLine = $node->getLine(0);
foreach ($node->getTable() as $line => $value) {
if ($line === $firstLine) {
continue;
}

$this->table[$line] = $value;
}
}

/**
* Pads string right.
*
Expand Down
10 changes: 9 additions & 1 deletion src/Behat/Gherkin/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ protected function parseOutline()
$title = trim($token['value']);
$tags = $this->popTags();
$keyword = $token['keyword'];

/** @var ExampleTableNode $examples */
$examples = null;
$line = $token['line'];

Expand All @@ -438,7 +440,13 @@ protected function parseOutline()
}

if ($node instanceof ExampleTableNode) {
$examples = $node;
if ($examples !== null) {
// we can have multiple examples
$examples->mergeRowsFromTable($node);
} else {
$examples = $node;
}

continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ feature:
text: the <role> exist in the system
line: 4
examples:
7: [ role ]
8: [ HUMAN RESOURCE ]
12: [ MANAGER ]
7: [ role, name ]
8: [ HUMAN RESOURCE, abc ]
12: [ MANAGER, cde ]
16: [ CEO, qqq ]
17: [ CTO, xxx ]
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
Feature: Unsubstituted argument placeholder

Scenario Outline: See Annual Leave Details (as Management & Human Resource)
Given the <role> exist in the system
Scenario Outline: See Annual Leave Details (as Management & Human Resource)
Given the <role> exist in the system

Examples:
| role |
| HUMAN RESOURCE |
Examples:
| role | name |
| HUMAN RESOURCE | abc |

Examples:
| role |
| MANAGER |
Examples:
| role | name |
| MANAGER | cde |

Examples:
| role | name |
| CEO | qqq |
| CTO | xxx |

0 comments on commit 6f09f3d

Please sign in to comment.