Skip to content

Commit

Permalink
Merge branch 'release/2.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
everzet committed Jul 1, 2012
2 parents c36d5a6 + cfb15e7 commit f022aaf
Show file tree
Hide file tree
Showing 49 changed files with 567 additions and 152 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
@@ -1,3 +1,10 @@
2.2.2 / 2012-07-01
==================

* Added ability to filter outline scenarios by line and range filters
* Synced Gherkin i18n
* Refactored table parser to read row line numbers too

2.2.1 / 2012-05-04
==================

Expand Down
2 changes: 1 addition & 1 deletion bin/release
Expand Up @@ -17,7 +17,7 @@
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/

require_once __DIR__.'/../vendor/.composer/autoload.php';
require_once __DIR__.'/../vendor/autoload.php';

if (!isset($argv[1])) {
throw new Exception('You must provide version.');
Expand Down
2 changes: 1 addition & 1 deletion bin/update_i18n
@@ -1,7 +1,7 @@
#!/usr/bin/env php
<?php

require_once __DIR__.'/../vendor/.composer/autoload.php';
require_once __DIR__.'/../vendor/autoload.php';

use Symfony\Component\Yaml\Yaml;

Expand Down
21 changes: 18 additions & 3 deletions i18n.php
Expand Up @@ -3,7 +3,7 @@
array (
'name' => 'English',
'native' => 'English',
'feature' => 'Feature',
'feature' => 'Feature|Business Need|Ability',
'background' => 'Background',
'scenario' => 'Scenario',
'scenario_outline' => 'Scenario Outline|Scenario Template',
Expand All @@ -29,6 +29,21 @@
'and' => 'و',
'but' => 'لكن',
),
'bm' =>
array (
'name' => 'Malay',
'native' => 'Bahasa Melayu',
'feature' => 'Fungsi',
'background' => 'Latar Belakang',
'scenario' => 'Senario',
'scenario_outline' => 'Menggariskan Senario',
'examples' => 'Contoh',
'given' => 'Bagi',
'when' => 'Apabila',
'then' => 'Kemudian',
'and' => 'Dan',
'but' => 'Tetapi',
),
'bg' =>
array (
'name' => 'Bulgarian',
Expand Down Expand Up @@ -468,13 +483,13 @@
array (
'name' => 'Polish',
'native' => 'polski',
'feature' => 'Właściwość',
'feature' => 'Właściwość|Funkcja|Aspekt|Potrzeba biznesowa',
'background' => 'Założenia',
'scenario' => 'Scenariusz',
'scenario_outline' => 'Szablon scenariusza',
'examples' => 'Przykłady',
'given' => 'Zakładając|Mając',
'when' => 'Jeżeli|Jeśli',
'when' => 'Jeżeli|Jeśli|Gdy|Kiedy',
'then' => 'Wtedy',
'and' => 'Oraz|I',
'but' => 'Ale',
Expand Down
6 changes: 3 additions & 3 deletions src/Behat/Gherkin/Cache/CacheInterface.php
Expand Up @@ -27,7 +27,7 @@ interface CacheInterface
*
* @return Boolean
*/
function isFresh($path, $timestamp);
public function isFresh($path, $timestamp);

/**
* Reads feature cache from path.
Expand All @@ -36,13 +36,13 @@ function isFresh($path, $timestamp);
*
* @return FeatureNode
*/
function read($path);
public function read($path);

/**
* Caches feature node.
*
* @param string $path Feature path
* @param FeatureNode $feature Feature instance
*/
function write($path, FeatureNode $feature);
public function write($path, FeatureNode $feature);
}
11 changes: 8 additions & 3 deletions src/Behat/Gherkin/Dumper/GherkinDumper.php
Expand Up @@ -115,6 +115,7 @@ public function dumpFeature(FeatureNode $feature)
foreach ($scenarios as $scenario) {
$content .= PHP_EOL . $this->dumpScenario($scenario);
}

return $content;
}

Expand All @@ -132,6 +133,7 @@ public function dumpKeyword($keyword, $text, $indent = 0)
if (preg_match('!(^.*)\|!', $keyword, $matches)) {
$keyword = $matches[1];
}

return $this->dumpIndent($indent) . $keyword . ':'
. ((strlen($text) > 0) ? ' ' . ltrim($this->dumpText($text, $indent + 1)) : '')
;
Expand Down Expand Up @@ -166,14 +168,15 @@ public function dumpScenario(ScenarioNode $scenario)
$examples = $scenario->getExamples();
$content .= $this->dumpTableNode($examples, 2);
}

return $content;
}

/**
* Dumps table node.
*
* @param TableNode $tableNode Table node
* @param integer $indent Indentation
* @param TableNode $tableNode Table node
* @param integer $indent Indentation
* @return string
*/
public function dumpTableNode(TableNode $tableNode, $indent = 0)
Expand All @@ -184,13 +187,14 @@ public function dumpTableNode(TableNode $tableNode, $indent = 0)
$content .= PHP_EOL . $this->dumpIndent($indent)
. $tableNode->getRowAsString($i);
}

return $content;
}

/**
* Dumps indentation.
*
* @param integer $indent Indentation
* @param integer $indent Indentation
*
* @return string
*/
Expand Down Expand Up @@ -262,6 +266,7 @@ public function dumpTags(array $tags, $indent = 0)
if (empty($tags)) {
return '';
}

return $this->dumpIndent($indent) . '@' . ltrim(implode(' @', $tags));
}

Expand Down
11 changes: 9 additions & 2 deletions src/Behat/Gherkin/Filter/FilterInterface.php
Expand Up @@ -27,7 +27,7 @@ interface FilterInterface
*
* @return Boolean
*/
function isFeatureMatch(FeatureNode $feature);
public function isFeatureMatch(FeatureNode $feature);

/**
* Checks if scenario or outline matches specified filter.
Expand All @@ -36,5 +36,12 @@ function isFeatureMatch(FeatureNode $feature);
*
* @return Boolean
*/
function isScenarioMatch(ScenarioNode $scenario);
public function isScenarioMatch(ScenarioNode $scenario);

/**
* Filters feature according to the filter.
*
* @param FeatureNode $feature
*/
public function filterFeature(FeatureNode $feature);
}
46 changes: 44 additions & 2 deletions src/Behat/Gherkin/Filter/LineFilter.php
Expand Up @@ -3,7 +3,8 @@
namespace Behat\Gherkin\Filter;

use Behat\Gherkin\Node\FeatureNode,
Behat\Gherkin\Node\ScenarioNode;
Behat\Gherkin\Node\ScenarioNode,
Behat\Gherkin\Node\OutlineNode;

/*
* This file is part of the Behat Gherkin.
Expand Down Expand Up @@ -53,6 +54,47 @@ public function isFeatureMatch(FeatureNode $feature)
*/
public function isScenarioMatch(ScenarioNode $scenario)
{
return $this->filterLine === $scenario->getLine();
if ($this->filterLine === $scenario->getLine()) {
return true;
}

if ($scenario instanceof OutlineNode && $scenario->hasExamples()) {
return $this->filterLine === $scenario->getLine()
|| in_array($this->filterLine, $scenario->getExamples()->getRowLines());
}

return false;
}

/**
* Filters feature according to the filter.
*
* @param FeatureNode $feature
*/
public function filterFeature(FeatureNode $feature)
{
$scenarios = $feature->getScenarios();
foreach ($scenarios as $i => $scenario) {
if (!$this->isScenarioMatch($scenario)) {
unset($scenarios[$i]);
continue;
}

if ($scenario instanceof OutlineNode && $scenario->hasExamples()) {
$lines = $scenario->getExamples()->getRowLines();
$rows = $scenario->getExamples()->getNumeratedRows();

if (current($lines) <= $this->filterLine && end($lines) >= $this->filterLine) {
$scenario->getExamples()->setRows(array());
$scenario->getExamples()->addRow($rows[$lines[0]], $lines[0]);

if ($lines[0] !== $this->filterLine) {
$scenario->getExamples()->addRow($rows[$this->filterLine], $this->filterLine);
}
}
}
}

$feature->setScenarios($scenarios);
}
}
52 changes: 49 additions & 3 deletions src/Behat/Gherkin/Filter/LineRangeFilter.php
Expand Up @@ -3,7 +3,8 @@
namespace Behat\Gherkin\Filter;

use Behat\Gherkin\Node\FeatureNode,
Behat\Gherkin\Node\ScenarioNode;
Behat\Gherkin\Node\ScenarioNode,
Behat\Gherkin\Node\OutlineNode;

/*
* This file is part of the Behat Gherkin.
Expand Down Expand Up @@ -60,7 +61,52 @@ public function isFeatureMatch(FeatureNode $feature)
*/
public function isScenarioMatch(ScenarioNode $scenario)
{
return $this->filterMinLine <= $scenario->getLine()
&& $this->filterMaxLine >= $scenario->getLine();
if ($this->filterMinLine <= $scenario->getLine()
&& $this->filterMaxLine >= $scenario->getLine()) {
return true;
}

if ($scenario instanceof OutlineNode && $scenario->hasExamples()) {
foreach ($scenario->getExamples()->getRowLines() as $line) {
if ($line >= $this->filterMinLine && $line <= $this->filterMaxLine) {
return true;
}
}
}

return false;
}

/**
* Filters feature according to the filter.
*
* @param FeatureNode $feature
*/
public function filterFeature(FeatureNode $feature)
{
$scenarios = $feature->getScenarios();
foreach ($scenarios as $i => $scenario) {
if (!$this->isScenarioMatch($scenario)) {
unset($scenarios[$i]);
continue;
}

if ($scenario instanceof OutlineNode && $scenario->hasExamples()) {
$lines = $scenario->getExamples()->getRowLines();
$rows = $scenario->getExamples()->getNumeratedRows();

$scenario->getExamples()->setRows(array());
$scenario->getExamples()->addRow($rows[$lines[0]], $lines[0]);
unset($rows[$lines[0]]);

foreach ($rows as $line => $row) {
if ($this->filterMinLine <= $line && $this->filterMaxLine >= $line) {
$scenario->getExamples()->addRow($row, $line);
}
}
}
}

$feature->setScenarios($scenarios);
}
}
4 changes: 2 additions & 2 deletions src/Behat/Gherkin/Filter/NameFilter.php
Expand Up @@ -18,14 +18,14 @@
*
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
class NameFilter implements FilterInterface
class NameFilter extends SimpleFilter
{
protected $filterString;

/**
* Initializes filter.
*
* @param string $filterStringString Name filter string
* @param string $filterString Name filter string
*/
public function __construct($filterString)
{
Expand Down
38 changes: 38 additions & 0 deletions src/Behat/Gherkin/Filter/SimpleFilter.php
@@ -0,0 +1,38 @@
<?php

namespace Behat\Gherkin\Filter;

use Behat\Gherkin\Node\FeatureNode;

/*
* This file is part of the Behat Gherkin.
* (c) 2011 Konstantin Kudryashov <ever.zet@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* Abstract filter class.
*
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
abstract class SimpleFilter implements FilterInterface
{
/**
* Filters feature according to the filter.
*
* @param FeatureNode $feature
*/
public function filterFeature(FeatureNode $feature)
{
$scenarios = $feature->getScenarios();
foreach ($scenarios as $i => $scenario) {
if (!$this->isScenarioMatch($scenario)) {
unset($scenarios[$i]);
}
}

$feature->setScenarios($scenarios);
}
}
6 changes: 4 additions & 2 deletions src/Behat/Gherkin/Filter/TagFilter.php
Expand Up @@ -19,14 +19,14 @@
*
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
class TagFilter implements FilterInterface
class TagFilter extends SimpleFilter
{
protected $filterString;

/**
* Initializes filter.
*
* @param string $filterStringString Name filter string
* @param string $filterString Name filter string
*/
public function __construct($filterString)
{
Expand Down Expand Up @@ -61,6 +61,8 @@ public function isScenarioMatch(ScenarioNode $scenario)
* Checks that node matches condition.
*
* @param AbstractNode $node Node to check
*
* @return Boolean
*/
protected function matchesCondition(AbstractNode $node)
{
Expand Down

0 comments on commit f022aaf

Please sign in to comment.