Skip to content

Commit

Permalink
TagExpression.eval() now takes a list of Tag
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Feb 17, 2012
1 parent dcf67ac commit 45335f7
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 84 deletions.
4 changes: 4 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [2.8.0](https://github.com/cucumber/gherkin/compare/v2.7.7...v2.8.0)

* [Ruby/Java] TagExpression.eval() now takes a list of Tag instead of a list of String. This slightly breaks the API (bump), but helps fix some bugs in Cucumber-JVM. (Aslak Hellesøy)

## [2.7.7](https://github.com/cucumber/gherkin/compare/v2.7.6...v2.7.7)

* [C] Allow compilation with clang (datanoise)
Expand Down
100 changes: 50 additions & 50 deletions features/.cucumber/stepdefs.json
Original file line number Diff line number Diff line change
@@ -1,227 +1,227 @@
[
{
"flags": "",
"source": "^they have arrived$",
"flags": "",
"steps": [
{
"name": "they have arrived",
"args": [

],
"name": "they have arrived"
]
}
]
},
{
"flags": "",
"source": "^a \"(ruby|native)\" \"([^\\\"]*)\" parser$",
"flags": "",
"steps": [

]
},
{
"flags": "",
"source": "^the\\ following\\ text\\ is\\ parsed:$",
"flags": "",
"steps": [
{
"name": "the following text is parsed:",
"args": [

],
"name": "the following text is parsed:"
]
}
]
},
{
"flags": "",
"source": "^there\\ should\\ be\\ no\\ parse\\ errors$",
"flags": "",
"steps": [
{
"name": "there should be no parse errors",
"args": [

],
"name": "there should be no parse errors"
]
}
]
},
{
"flags": "",
"source": "^there should be a parse error on (line \\d+)$",
"flags": "",
"steps": [
{
"name": "there should be a parse error on line 1",
"args": [
{
"offset": 33,
"val": "line 1"
}
],
"name": "there should be a parse error on line 1"
]
}
]
},
{
"flags": "",
"source": "^there should be parse errors on (lines .*)$",
"flags": "",
"steps": [
{
"name": "there should be parse errors on lines 1 and 2",
"args": [
{
"offset": 32,
"val": "lines 1 and 2"
}
],
"name": "there should be parse errors on lines 1 and 2"
]
},
{
"name": "there should be parse errors on lines 1 through 3",
"args": [
{
"offset": 32,
"val": "lines 1 through 3"
}
],
"name": "there should be parse errors on lines 1 through 3"
]
},
{
"name": "there should be parse errors on lines 10 and 17",
"args": [
{
"offset": 32,
"val": "lines 10 and 17"
}
],
"name": "there should be parse errors on lines 10 and 17"
]
},
{
"name": "there should be parse errors on lines 3 and 5",
"args": [
{
"offset": 32,
"val": "lines 3 and 5"
}
],
"name": "there should be parse errors on lines 3 and 5"
]
},
{
"name": "there should be parse errors on lines 5, 10 and 12",
"args": [
{
"offset": 32,
"val": "lines 5, 10 and 12"
}
],
"name": "there should be parse errors on lines 5, 10 and 12"
]
}
]
},
{
"flags": "",
"source": "^a JSON formatter$",
"flags": "",
"steps": [

]
},
{
"flags": "",
"source": "^the outputted JSON should be:$",
"flags": "",
"steps": [
{
"name": "the outputted JSON should be:",
"args": [

],
"name": "the outputted JSON should be:"
]
}
]
},
{
"flags": "",
"source": "^a PrettyFormatter$",
"flags": "",
"steps": [

]
},
{
"flags": "",
"source": "^a JSON lexer$",
"flags": "",
"steps": [

]
},
{
"flags": "",
"source": "^the following JSON is parsed:$",
"flags": "",
"steps": [
{
"name": "the following JSON is parsed:",
"args": [

],
"name": "the following JSON is parsed:"
]
}
]
},
{
"flags": "",
"source": "^the outputted text should be:$",
"flags": "",
"steps": [
{
"name": "the outputted text should be:",
"args": [

],
"name": "the outputted text should be:"
]
}
]
},
{
"flags": "",
"source": "^I have Cucumber's source code next to Gherkin's$",
"flags": "",
"steps": [
{
"name": "I have Cucumber's source code next to Gherkin's",
"args": [

],
"name": "I have Cucumber's source code next to Gherkin's"
]
}
]
},
{
"flags": "",
"source": "^I find all of the \\.feature files$",
"flags": "",
"steps": [
{
"name": "I find all of the .feature files",
"args": [

],
"name": "I find all of the .feature files"
]
}
]
},
{
"flags": "",
"source": "^I send each prettified original through the \"([^\"]*)\" machinery$",
"flags": "",
"steps": [
{
"name": "I send each prettified original through the \"json\" machinery",
"args": [
{
"offset": 45,
"val": "json"
}
],
"name": "I send each prettified original through the \"json\" machinery"
]
},
{
"name": "I send each prettified original through the \"pretty\" machinery",
"args": [
{
"offset": 45,
"val": "pretty"
}
],
"name": "I send each prettified original through the \"pretty\" machinery"
]
}
]
},
{
"flags": "",
"source": "^the machinery output should be identical to the prettified original$",
"flags": "",
"steps": [
{
"name": "the machinery output should be identical to the prettified original",
"args": [

],
"name": "the machinery output should be identical to the prettified original"
]
}
]
}
Expand Down
26 changes: 14 additions & 12 deletions java/src/main/java/gherkin/TagExpression.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gherkin;

import gherkin.formatter.model.Tag;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -16,7 +18,7 @@ public TagExpression(List<String> tagExpressions) {
}
}

public boolean eval(Collection<String> tags) {
public boolean eval(Collection<Tag> tags) {
return and.isEmpty() || and.eval(tags);
}

Expand Down Expand Up @@ -46,16 +48,16 @@ private void add(String[] tags) {
}

if (negation) {
or.add(new Not(new Tag(tag)));
or.add(new Not(new TagExp(tag)));
} else {
or.add(new Tag(tag));
or.add(new TagExp(tag));
}
}
and.add(or);
}

private interface Expression {
boolean eval(Collection<String> tags);
boolean eval(Collection<Tag> tags);
}

private class Not implements Expression {
Expand All @@ -65,7 +67,7 @@ public Not(Expression expression) {
this.expression = expression;
}

public boolean eval(Collection<String> tags) {
public boolean eval(Collection<Tag> tags) {
return !expression.eval(tags);
}
}
Expand All @@ -77,7 +79,7 @@ public void add(Expression expression) {
expressions.add(expression);
}

public boolean eval(Collection<String> tags) {
public boolean eval(Collection<Tag> tags) {
boolean result = true;
for (Expression expression : expressions) {
result = expression.eval(tags);
Expand All @@ -98,7 +100,7 @@ public void add(Expression expression) {
expressions.add(expression);
}

public boolean eval(Collection<String> tags) {
public boolean eval(Collection<Tag> tags) {
boolean result = false;
for (Expression expression : expressions) {
result = expression.eval(tags);
Expand All @@ -108,19 +110,19 @@ public boolean eval(Collection<String> tags) {
}
}

private class Tag implements Expression {
private class TagExp implements Expression {
private final String tagName;

public Tag(String tagName) {
public TagExp(String tagName) {
if (!tagName.startsWith("@")) {
throw new BadTagException(tagName);
}
this.tagName = tagName;
}

public boolean eval(Collection<String> tags) {
for (String tag : tags) {
if (tagName.equals(tag)) {
public boolean eval(Collection<Tag> tags) {
for (Tag tag : tags) {
if (tagName.equals(tag.getName())) {
return true;
}
}
Expand Down
7 changes: 1 addition & 6 deletions java/src/main/java/gherkin/formatter/TagFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import gherkin.formatter.model.Range;
import gherkin.formatter.model.Tag;

import java.util.ArrayList;
import java.util.List;

public class TagFilter implements Filter {
Expand All @@ -16,11 +15,7 @@ public TagFilter(List<String> tags) {
}

public boolean eval(List<Tag> tags, List<String> names, List<Range> ranges) {
List<String> tagNames = new ArrayList<String>();
for (Tag tag : tags) {
tagNames.add(tag.getName());
}
return tagExpression.eval(tagNames);
return tagExpression.eval(tags);
}

public List<ExamplesTableRow> filterTableBodyRows(List<ExamplesTableRow> examplesRows) {
Expand Down
Loading

0 comments on commit 45335f7

Please sign in to comment.