Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add table diff support to prettyformatter. Release 2.4.15.

  • Loading branch information...
commit 2f61ea253f6d26dbc1bbc142116672d2bfb62409 1 parent b609e1c
@aslakhellesoy aslakhellesoy authored
View
6 Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- gherkin (2.4.14)
+ gherkin (2.4.15)
json (>= 1.4.6)
GEM
@@ -31,7 +31,7 @@ GEM
diff-lcs (~> 1.1.2)
rspec-mocks (2.6.0)
term-ansicolor (1.0.6)
- therubyracer (0.9.3)
+ therubyracer (0.9.4)
libv8 (~> 3.3.10)
yard (0.7.2)
@@ -49,5 +49,5 @@ DEPENDENCIES
rdiscount (>= 1.6.8)
rspec (>= 2.6.0)
term-ansicolor (>= 1.0.6)
- therubyracer (>= 0.9.3)
+ therubyracer (>= 0.9.4)
yard (>= 0.7.2)
View
6 History.md
@@ -1,3 +1,9 @@
+## [2.4.15](https://github.com/cucumber/gherkin/compare/v2.4.14...v2.4.15)
+
+### New Features
+
+* [Java] Pretty formatter knows how to print deleted (-) or inserted (+) table rows. (Aslak Hellesøy)
+
## [2.4.14](https://github.com/cucumber/gherkin/compare/v2.4.13...v2.4.14)
### New Features
View
4 gherkin.gemspec
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = "gherkin"
- s.version = "2.4.14"
+ s.version = "2.4.15"
s.authors = ["Mike Sassak", "Gregory Hnatiuk", "Aslak Hellesøy"]
s.description = "A fast Gherkin lexer/parser based on the Ragel State Machine Compiler."
s.summary = "#{s.name}-#{s.version}"
@@ -50,7 +50,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('rspec', '>= 2.6.0')
unless ENV['RUBY_CC_VERSION'] || defined?(JRUBY_VERSION)
- s.add_development_dependency('therubyracer', '>= 0.9.3') if ENV['GHERKIN_JS']
+ s.add_development_dependency('therubyracer', '>= 0.9.4') if ENV['GHERKIN_JS']
# For Documentation:
s.add_development_dependency('yard', '>= 0.7.2')
s.add_development_dependency('rdiscount', '>= 1.6.8')
View
4 ikvm/Gherkin/Gherkin.csproj
@@ -43,9 +43,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\release\IKVM.OpenJDK.Text.dll</HintPath>
</Reference>
- <Reference Include="gherkin-2.4.14, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
+ <Reference Include="gherkin-2.4.15, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\release\gherkin-2.4.14.dll</HintPath>
+ <HintPath>..\..\release\gherkin-2.4.15.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
View
2  java/pom.xml
@@ -6,7 +6,7 @@
<groupId>gherkin</groupId>
<artifactId>gherkin</artifactId>
- <version>2.4.14</version>
+ <version>2.4.15</version>
<packaging>jar</packaging>
<name>Gherkin</name>
View
4 java/src/main/java/gherkin/I18n.java
@@ -124,7 +124,7 @@ public String getKeywordTable() {
List<Row> table = new ArrayList<Row>();
for (String key : KEYWORD_KEYS) {
List<String> cells = Arrays.asList(key, join(map(keywords(key), QUOTE_MAPPER), ", "));
- table.add(new Row(Collections.<Comment>emptyList(), cells, -1));
+ table.add(new Row(Collections.<Comment>emptyList(), cells, -1, Row.DiffType.NONE));
}
for (String key : STEP_KEYWORD_KEYS) {
List<String> codeKeywordList = new ArrayList<String>(keywords.get(key));
@@ -132,7 +132,7 @@ public String getKeywordTable() {
String codeKeywords = join(map(map(codeKeywordList, CODE_KEYWORD_MAPPER), QUOTE_MAPPER), ", ");
List<String> cells = Arrays.asList(key + " (code)", codeKeywords);
- table.add(new Row(Collections.<Comment>emptyList(), cells, -1));
+ table.add(new Row(Collections.<Comment>emptyList(), cells, -1, Row.DiffType.NONE));
}
pf.table(table);
return writer.getBuffer().toString();
View
2  java/src/main/java/gherkin/JSONParser.java
@@ -93,7 +93,7 @@ private void step(JSONObject o) {
List<Row> rows = new ArrayList<Row>(o.size());
for (Object e : o) {
Map row = (Map) e;
- rows.add(new Row(comments(row), getList(row, "cells"), getInt(row, "line")));
+ rows.add(new Row(comments(row), getList(row, "cells"), getInt(row, "line"), Row.DiffType.NONE));
}
return rows;
}
View
2  java/src/main/java/gherkin/formatter/Mappable.java
@@ -43,7 +43,7 @@
Class c = getClass();
while (c != null) {
for (Field field : c.getDeclaredFields()) {
- if ((field.getModifiers() & Modifier.STATIC) == 0) {
+ if (!Modifier.isStatic(field.getModifiers()) && !Modifier.isVolatile(field.getModifiers())) {
fields.add(field);
}
}
View
27 java/src/main/java/gherkin/formatter/PrettyFormatter.java
@@ -113,7 +113,7 @@ private void printStatement() {
}
private String indentedLocation(String location, boolean proceed) {
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
int indentation = proceed ? indentations.remove(0) : indentations.get(0);
if(location == null) {
return "";
@@ -228,10 +228,31 @@ public void row(List<CellResult> cellResults) {
out.println(comment.getValue());
rowHeight++;
}
- out.append(" | ");
+ switch(row.getDiffType()) {
+ case NONE:
+ out.append(" | ");
+ break;
+ case DELETE:
+ out.append(" ").append(formats.get("skipped").text("-")).append(" | ");
+ break;
+ case INSERT:
+ out.append(" ").append(formats.get("comment").text("+")).append(" | ");
+ break;
+ }
for (int colIndex = 0; colIndex < maxLengths.length; colIndex++) {
String cellText = escapeCell(row.getCells().get(colIndex));
- String status = cellResults.get(colIndex).getStatus();
+ String status = null;
+ switch(row.getDiffType()) {
+ case NONE:
+ status = cellResults.get(colIndex).getStatus();
+ break;
+ case DELETE:
+ status = "skipped";
+ break;
+ case INSERT:
+ status = "comment";
+ break;
+ }
Format format = formats.get(status);
out.append(format.text(cellText));
int padding = maxLengths[colIndex] - cellLengths[rowIndex][colIndex];
View
14 java/src/main/java/gherkin/formatter/model/Row.java
@@ -6,11 +6,21 @@
import java.util.List;
public class Row extends Mappable implements CommentHolder {
+ public enum DiffType {
+ NONE, DELETE, INSERT
+ }
+
private final List<Comment> comments;
private final List<String> cells;
private final int line;
+ private volatile DiffType diffType;
public Row(List<Comment> comments, List<String> cells, int line) {
+ this(comments, cells, line, DiffType.NONE);
+ }
+
+ public Row(List<Comment> comments, List<String> cells, int line, DiffType diffType) {
+ this.diffType = diffType;
if (comments == null) {
throw new NullPointerException("comments");
}
@@ -33,6 +43,10 @@ public Row(List<Comment> comments, List<String> cells, int line) {
public int getLine() {
return line;
}
+
+ public DiffType getDiffType() {
+ return diffType;
+ }
public List<CellResult> createResults(String status) {
List<CellResult> results = new ArrayList<CellResult>();
View
2  java/src/main/java/gherkin/parser/FormatterListener.java
@@ -60,7 +60,7 @@ public void row(List<String> cells, int line) {
if (table == null) {
table = new ArrayList<Row>();
}
- table.add(new Row(grabComments(), cells, line));
+ table.add(new Row(grabComments(), cells, line, Row.DiffType.NONE));
}
public void docString(String string, int line) {
View
27 java/src/test/java/gherkin/formatter/PrettyFormatterTest.java
@@ -7,12 +7,19 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.List;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptyList;
public class PrettyFormatterTest {
+ private static final List<Comment> NO_COMMENTS = emptyList();
+ private static final List<Tag> NO_TAGS = Collections.<Tag>emptyList();
+
@Test
- public void testShouldPrintNiceColors() throws UnsupportedEncodingException, InterruptedException {
+ public void prints_nice_colors() throws UnsupportedEncodingException, InterruptedException {
PrettyFormatter f = new PrettyFormatter(System.out, false, false);
- f.scenario(new Scenario(Collections.<Comment>emptyList(), Collections.<Tag>emptyList(), "Scenario", "a scenario", "", 1));
+ f.scenario(new Scenario(NO_COMMENTS, NO_TAGS, "Scenario", "a scenario", "", 1));
f.step(new Step(new ArrayList<Comment>(), "Given ", "I have 6 cukes", 1));
Thread.sleep(1000);
f.match(new Match(Arrays.asList(new Argument(7, "6")), "somewhere.brainfuck"));
@@ -20,4 +27,20 @@ public void testShouldPrintNiceColors() throws UnsupportedEncodingException, Int
f.result(new Result("failed", 55L, "Something\nbad\nhappened"));
}
+ @Test
+ public void prints_table() throws UnsupportedEncodingException, InterruptedException {
+ PrettyFormatter f = new PrettyFormatter(System.out, false, false);
+ f.scenario(new Scenario(NO_COMMENTS, Collections.<Tag>emptyList(), "Scenario", "a scenario", "", 1));
+ Step step = new Step(new ArrayList<Comment>(), "Given ", "I have 6 cukes", 1);
+ step.setMultilineArg(new ArrayList<Row>() {{
+ add(new Row(NO_COMMENTS, asList("un", "deux"), 1, Row.DiffType.NONE));
+ add(new Row(NO_COMMENTS, asList("one", "two"), 1, Row.DiffType.DELETE));
+ add(new Row(NO_COMMENTS, asList("en", "to"), 1, Row.DiffType.INSERT));
+ }});
+ f.step(step);
+ Thread.sleep(1000);
+ f.match(new Match(Arrays.asList(new Argument(7, "6")), "somewhere.brainfuck"));
+ Thread.sleep(1000);
+ f.result(new Result("failed", 55L, "Something\nbad\nhappened"));
+ }
}
View
2  js/package.json
@@ -1,7 +1,7 @@
{ "name" : "gherkin"
, "description" : "A fast Gherkin lexer/parser based on the Ragel State Machine Compiler."
, "keywords" : [ "testing", "bdd", "cucumber", "gherkin", "tests" ]
-, "version" : "2.4.14"
+, "version" : "2.4.15"
, "homepage" : "http://github.com/cucumber/gherkin"
, "author" : "Aslak Hellesøy <aslak.hellesoy@gmail.com>"
, "contributors" : [ "Aslak Hellesøy <aslak.hellesoy@gmail.com>" ]
View
2  spec/gherkin/formatter/pretty_formatter_spec.rb
@@ -150,7 +150,7 @@ def assert_pretty(input, expected_output=input)
it "should escape backslashes and pipes" do
io = StringIO.new
f = Gherkin::Formatter::PrettyFormatter.new(io, true, false)
- f.__send__(:table, [Gherkin::Formatter::Model::Row.new([], ['|', '\\'], nil)])
+ f.__send__(:table, [Gherkin::Formatter::Model::Row.new([], ['|', '\\'], 1)])
io.string.should == ' | \\| | \\\\ |' + "\n"
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.