Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

WIP

  • Loading branch information...
commit c30048fee8c252754ea247bd1d57584c9bf81cd1 1 parent 04badc2
@aslakhellesoy aslakhellesoy authored
Showing with 404 additions and 98 deletions.
  1. +3 −3 java/src/main/java/gherkin/formatter/PrettyFormatter.java
  2. +10 −3 java/src/main/java/gherkin/formatter/model/Background.java
  3. +7 −0 java/src/main/java/gherkin/formatter/model/DataTableRow.java
  4. +7 −1 java/src/main/java/gherkin/formatter/model/DocString.java
  5. +21 −5 java/src/main/java/gherkin/formatter/model/Examples.java
  6. +74 −0 java/src/main/java/gherkin/formatter/model/ExamplesTableRow.java
  7. +6 −0 java/src/main/java/gherkin/formatter/model/Feature.java
  8. +1 −1  java/src/main/java/gherkin/formatter/model/Row.java
  9. +15 −5 java/src/main/java/gherkin/formatter/model/Scenario.java
  10. +17 −65 java/src/main/java/gherkin/formatter/model/ScenarioOutline.java
  11. +14 −6 java/src/main/java/gherkin/formatter/model/Step.java
  12. +3 −4 java/src/main/java/gherkin/formatter/model/StepContainer.java
  13. +7 −0 java/src/main/java/gherkin/formatter/model/Visitable.java
  14. +21 −0 java/src/main/java/gherkin/formatter/model/Visitor.java
  15. +31 −0 java/src/main/java/gherkin/formatter/visitors/Next.java
  16. +78 −0 java/src/main/java/gherkin/formatter/visitors/PrettyVisitor.java
  17. +2 −0  java/src/main/java/gherkin/lexer/Listener.java
  18. +5 −0 java/src/main/java/gherkin/parser/AstListener.java
  19. +23 −4 java/src/main/java/gherkin/parser/Parser.java
  20. +14 −0 java/src/main/java/gherkin/parser/StateMachineReader.java
  21. +44 −0 java/src/test/java/gherkin/visitors/PrettyVisitorTest.java
  22. BIN  tasks/yard/default/layout/html/bubble_32x32.png
  23. BIN  tasks/yard/default/layout/html/bubble_48x48.png
  24. +1 −1  tasks/yard/default/layout/html/logo.erb
View
6 java/src/main/java/gherkin/formatter/PrettyFormatter.java
@@ -255,7 +255,7 @@ private void printStep(String status, List<Argument> arguments, String location,
out.append(indentedLocation(location, proceed));
out.println();
- if (step.getRows() != null) {
+ if (!step.getRows().isEmpty()) {
table(step.getRows());
} else if (step.getDocString() != null) {
docString(step.getDocString());
@@ -448,14 +448,14 @@ private void printDescription(String description, String indentation, boolean ne
private static final Pattern START = Pattern.compile("^", Pattern.MULTILINE);
- private static String indent(String s, String indentation) {
+ public static String indent(String s, String indentation) {
return START.matcher(s).replaceAll(indentation);
}
private static final Pattern TRIPLE_QUOTES = Pattern.compile("\"\"\"", Pattern.MULTILINE);
private static final String ESCAPED_TRIPLE_QUOTES = "\\\\\"\\\\\"\\\\\"";
- private static String escapeTripleQuotes(String s) {
+ public static String escapeTripleQuotes(String s) {
return TRIPLE_QUOTES.matcher(s).replaceAll(ESCAPED_TRIPLE_QUOTES);
}
}
View
13 java/src/main/java/gherkin/formatter/model/Background.java
@@ -1,13 +1,14 @@
package gherkin.formatter.model;
import gherkin.formatter.Formatter;
+import gherkin.formatter.visitors.Next;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class Background extends DescribedStatement implements StepContainer {
+ @SuppressWarnings("unused")
private final String type = "background";
private List<Step> steps = new ArrayList<Step>();
@@ -30,12 +31,18 @@ public void addStep(Step step) {
}
@Override
- public void addScenario(ExamplesTableRow header, ExamplesTableRow row, List<Tag> tags) {
+ public List<Scenario> getScenarios() {
throw new UnsupportedOperationException();
}
@Override
- public Collection<Scenario> getScenarios() {
+ public void addExamples(Examples examples) {
throw new UnsupportedOperationException();
}
+
+ @Override
+ public void accept(Visitor visitor, Next next) throws Exception {
+ next.pushAll(steps);
+ visitor.visitBackground(this, next);
+ }
}
View
7 java/src/main/java/gherkin/formatter/model/DataTableRow.java
@@ -1,5 +1,7 @@
package gherkin.formatter.model;
+import gherkin.formatter.visitors.Next;
+
import java.util.List;
public class DataTableRow extends Row {
@@ -19,4 +21,9 @@ public DataTableRow(List<Comment> comments, List<String> cells, Integer line, Di
public DiffType getDiffType() {
return diffType;
}
+
+ @Override
+ public void accept(Visitor visitor, Next bakctrack) throws Exception {
+ visitor.visitDataTableRow(this, bakctrack);
+ }
}
View
8 java/src/main/java/gherkin/formatter/model/DocString.java
@@ -1,8 +1,9 @@
package gherkin.formatter.model;
import gherkin.formatter.Mappable;
+import gherkin.formatter.visitors.Next;
-public class DocString extends Mappable {
+public class DocString extends Mappable implements Visitable {
private static final long serialVersionUID = 1L;
private final String content_type;
@@ -31,4 +32,9 @@ public Range getLineRange() {
int lineCount = value.split("\r?\n").length;
return new Range(getLine(), getLine() + lineCount + 1);
}
+
+ @Override
+ public void accept(Visitor visitor, Next next) throws Exception {
+ visitor.visitDocString(this, next);
+ }
}
View
26 java/src/main/java/gherkin/formatter/model/Examples.java
@@ -1,15 +1,23 @@
package gherkin.formatter.model;
import gherkin.formatter.Formatter;
+import gherkin.formatter.visitors.Next;
import java.util.ArrayList;
import java.util.List;
-public class Examples extends TagStatement {
+public class Examples extends TagStatement implements Visitable {
private static final long serialVersionUID = 1L;
private List<ExamplesTableRow> rows;
+ public void accept(Visitor visitor, Next next) throws Exception {
+ visitor.visitExamples(this);
+ for (ExamplesTableRow row : rows) {
+ row.accept(visitor, next);
+ }
+ }
+
public static class ExamplesBuilder implements Builder {
private final List<Comment> comments;
private final List<Tag> tags;
@@ -18,7 +26,8 @@
private final String description;
private final Integer line;
private final String id;
- private List<ExamplesTableRow> rows = new ArrayList<ExamplesTableRow>();;
+ private List<ExamplesTableRow> rows = new ArrayList<ExamplesTableRow>();
+ ;
public ExamplesBuilder(List<Comment> comments, List<Tag> tags, String keyword, String name, String description, Integer line, String id) {
this.comments = comments;
@@ -40,9 +49,8 @@ public void replay(Formatter formatter) {
@Override
public void populateStepContainer(StepContainer stepContainer) {
- for (int i = 1; i < rows.size(); i++) {
- stepContainer.addScenario(rows.get(0), rows.get(i), tags);
- }
+ Examples examples = new Examples(comments, tags, keyword, name, description, line, id, rows);
+ stepContainer.addExamples(examples);
}
public void docString(DocString docString) {
@@ -67,4 +75,12 @@ public void replay(Formatter formatter) {
public void setRows(List<ExamplesTableRow> rows) {
this.rows = rows;
}
+
+ public List<Scenario> createScenarios(List<Step> outlineSteps, Background background) {
+ List<Scenario> scenarios = new ArrayList<Scenario>();
+ for (int i = 1; i < rows.size(); i++) {
+ scenarios.add(rows.get(i).createScenario(outlineSteps, rows.get(0), getTags(), getName(), getDescription(), background));
+ }
+ return scenarios;
+ }
}
View
74 java/src/main/java/gherkin/formatter/model/ExamplesTableRow.java
@@ -1,6 +1,11 @@
package gherkin.formatter.model;
+import gherkin.formatter.visitors.Next;
+
+import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
public class ExamplesTableRow extends Row {
private static final long serialVersionUID = 1L;
@@ -20,4 +25,73 @@ public DiffType getDiffType() {
public String getId() {
return id;
}
+
+ public Scenario createScenario(List<Step> outlineSteps, ExamplesTableRow headerRow, List<Tag> tags, String name, String description, Background background) {
+ Scenario scenario = new Scenario(getComments(), tags, "SOME KEYWORD", name, description, getLine(), getId(), background);
+ for (Step outlineStep : outlineSteps) {
+ scenario.addStep(createExampleStep(outlineStep, headerRow));
+ }
+ return scenario;
+ }
+
+ private Step createExampleStep(Step step, ExamplesTableRow headerRow) {
+ Set<Integer> matchedColumns = new HashSet<Integer>();
+ List<String> headerCells = headerRow.getCells();
+ List<String> exampleCells = getCells();
+
+ // Create a step with replaced tokens
+ String name = replaceTokens(matchedColumns, headerCells, exampleCells, step.getName());
+
+ return new Step(
+ step.getComments(),
+ step.getKeyword(),
+ name,
+ step.getLine(),
+ rowsWithTokensReplaced(step.getRows(), headerCells, exampleCells, matchedColumns),
+ docStringWithTokensReplaced(step.getDocString(), headerCells, exampleCells, matchedColumns)
+ );
+ }
+
+ private String replaceTokens(Set<Integer> matchedColumns, List<String> headerCells, List<String> exampleCells, String text) {
+ for (int i = 0; i < headerCells.size(); i++) {
+ String headerCell = headerCells.get(i);
+ String value = exampleCells.get(i);
+ String token = "<" + headerCell + ">";
+ if (text.contains(token)) {
+ text = text.replace(token, value);
+ matchedColumns.add(i);
+ }
+ }
+ return text;
+ }
+
+ private List<DataTableRow> rowsWithTokensReplaced(List<DataTableRow> rows, List<String> headerCells, List<String> exampleCells, Set<Integer> matchedColumns) {
+ if (rows != null) {
+ List<DataTableRow> newRows = new ArrayList<DataTableRow>(rows.size());
+ for (Row row : rows) {
+ List<String> newCells = new ArrayList<String>(row.getCells().size());
+ for (String cell : row.getCells()) {
+ newCells.add(replaceTokens(matchedColumns, headerCells, exampleCells, cell));
+ }
+ newRows.add(new DataTableRow(row.getComments(), newCells, row.getLine()));
+ }
+ return newRows;
+ } else {
+ return null;
+ }
+ }
+
+ private DocString docStringWithTokensReplaced(DocString docString, List<String> headerCells, List<String> exampleCells, Set<Integer> matchedColumns) {
+ if (docString != null) {
+ String docStringValue = replaceTokens(matchedColumns, headerCells, exampleCells, docString.getValue());
+ return new DocString(docString.getContentType(), docStringValue, docString.getLine());
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public void accept(Visitor visitor, Next bakctrack) {
+
+ }
}
View
6 java/src/main/java/gherkin/formatter/model/Feature.java
@@ -1,6 +1,7 @@
package gherkin.formatter.model;
import gherkin.formatter.Formatter;
+import gherkin.formatter.visitors.Next;
import java.util.ArrayList;
import java.util.Collections;
@@ -30,4 +31,9 @@ public void replay(Formatter formatter) {
public void addStepContainer(StepContainer stepContainer) {
stepContainers.add(stepContainer);
}
+
+ public void accept(final Visitor visitor, Next next) throws Exception {
+ next.pushAll(stepContainers);
+ visitor.visitFeature(this, next);
+ }
}
View
2  java/src/main/java/gherkin/formatter/model/Row.java
@@ -5,7 +5,7 @@
import java.util.ArrayList;
import java.util.List;
-public abstract class Row extends Mappable implements CommentHolder {
+public abstract class Row extends Mappable implements CommentHolder, Visitable {
public enum DiffType {
NONE, DELETE, INSERT
}
View
20 java/src/main/java/gherkin/formatter/model/Scenario.java
@@ -1,9 +1,9 @@
package gherkin.formatter.model;
import gherkin.formatter.Formatter;
+import gherkin.formatter.visitors.Next;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -12,8 +12,8 @@
@SuppressWarnings("unused") // it's in the JSON
private final String type = "scenario";
- private final List<Step> steps = new ArrayList<Step>();
private final Background background;
+ private final List<Step> steps = new ArrayList<Step>();
@SuppressWarnings("unused") // Legacy API
@Deprecated
@@ -47,12 +47,22 @@ public void addStep(Step step) {
}
@Override
- public void addScenario(ExamplesTableRow header, ExamplesTableRow row, List<Tag> tags) {
+ public List<Scenario> getScenarios() {
+ return Collections.singletonList(this);
+ }
+
+ @Override
+ public void addExamples(Examples examples) {
throw new UnsupportedOperationException();
}
@Override
- public Collection<Scenario> getScenarios() {
- return Collections.singletonList(this);
+ public void accept(Visitor visitor, Next next) throws Exception {
+ if (background != null) {
+ next.push(background);
+ }
+ next.pushAll(steps);
+ visitor.visitScenario(this, next);
+
}
}
View
82 java/src/main/java/gherkin/formatter/model/ScenarioOutline.java
@@ -1,22 +1,20 @@
package gherkin.formatter.model;
import gherkin.formatter.Formatter;
+import gherkin.formatter.visitors.Next;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
public class ScenarioOutline extends TagStatement implements StepContainer {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unused") // it's in the JSON
private final String type = "scenario_outline";
- private final List<Step> steps = new ArrayList<Step>();
private final Background background;
- private final List<Scenario> scenarios = new ArrayList<Scenario>();
+ private final List<Step> steps = new ArrayList<Step>();
+ private final List<Examples> examplesList = new ArrayList<Examples>();
@SuppressWarnings("unused") // Legacy API
@Deprecated
@@ -50,74 +48,28 @@ public void addStep(Step step) {
}
@Override
- public void addScenario(ExamplesTableRow header, ExamplesTableRow example, List<Tag> tags) {
- String idTODO = null; // TODO
- Scenario scenario = new Scenario(getComments(), getTags(), getKeyword(), getName(), getDescription(), example.getLine(), idTODO, background);
- for (Step outlineStep : steps) {
- scenario.addStep(createExampleStep(outlineStep, header, example));
+ public List<Scenario> getScenarios() {
+ List<Scenario> scenarios = new ArrayList<Scenario>();
+ for (Examples examples : examplesList) {
+ scenarios.addAll(examples.createScenarios(steps, background));
}
- scenarios.add(scenario);
- }
-
- @Override
- public Collection<Scenario> getScenarios() {
return scenarios;
}
- private Step createExampleStep(Step step, ExamplesTableRow headerRow, ExamplesTableRow exampleRow) {
- Set<Integer> matchedColumns = new HashSet<Integer>();
- List<String> headerCells = headerRow.getCells();
- List<String> exampleCells = exampleRow.getCells();
-
- // Create a step with replaced tokens
- String name = replaceTokens(matchedColumns, headerCells, exampleCells, step.getName());
-
- return new Step(
- step.getComments(),
- step.getKeyword(),
- name,
- step.getLine(),
- rowsWithTokensReplaced(step.getRows(), headerCells, exampleCells, matchedColumns),
- docStringWithTokensReplaced(step.getDocString(), headerCells, exampleCells, matchedColumns)
- );
- }
-
- private String replaceTokens(Set<Integer> matchedColumns, List<String> headerCells, List<String> exampleCells, String text) {
- for (int i = 0; i < headerCells.size(); i++) {
- String headerCell = headerCells.get(i);
- String value = exampleCells.get(i);
- String token = "<" + headerCell + ">";
- if (text.contains(token)) {
- text = text.replace(token, value);
- matchedColumns.add(i);
- }
- }
- return text;
+ @Override
+ public void addExamples(Examples examples) {
+ examplesList.add(examples);
}
- private List<DataTableRow> rowsWithTokensReplaced(List<DataTableRow> rows, List<String> headerCells, List<String> exampleCells, Set<Integer> matchedColumns) {
- if (rows != null) {
- List<DataTableRow> newRows = new ArrayList<DataTableRow>(rows.size());
- for (Row row : rows) {
- List<String> newCells = new ArrayList<String>(row.getCells().size());
- for (String cell : row.getCells()) {
- newCells.add(replaceTokens(matchedColumns, headerCells, exampleCells, cell));
- }
- newRows.add(new DataTableRow(row.getComments(), newCells, row.getLine()));
- }
- return newRows;
- } else {
- return null;
+ @Override
+ public void accept(Visitor visitor, Next next) throws Exception {
+ if (background != null) {
+ background.accept(visitor, next);
}
- }
- private DocString docStringWithTokensReplaced(DocString docString, List<String> headerCells, List<String> exampleCells, Set<Integer> matchedColumns) {
- if (docString != null) {
- String docStringValue = replaceTokens(matchedColumns, headerCells, exampleCells, docString.getValue());
- return new DocString(docString.getContentType(), docStringValue, docString.getLine());
- } else {
- return null;
- }
+ next.pushAll(steps);
+ next.pushAll(examplesList);
+ visitor.visitScenarioOutline(this, next);
}
}
View
20 java/src/main/java/gherkin/formatter/model/Step.java
@@ -2,6 +2,7 @@
import gherkin.formatter.Argument;
import gherkin.formatter.Formatter;
+import gherkin.formatter.visitors.Next;
import java.util.ArrayList;
import java.util.List;
@@ -9,7 +10,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-public class Step extends BasicStatement {
+public class Step extends BasicStatement implements Visitable {
private static final long serialVersionUID = 1L;
private final List<DataTableRow> rows;
@@ -20,7 +21,8 @@
private final String keyword;
private final String name;
private final Integer line;
- private List<DataTableRow> rows;
+ private List<DataTableRow> rows = new ArrayList<DataTableRow>();
+
private DocString doc_string;
public StepBuilder(List<Comment> comments, String keyword, String name, Integer line) {
@@ -31,9 +33,6 @@ public StepBuilder(List<Comment> comments, String keyword, String name, Integer
}
public void row(List<Comment> comments, List<String> cells, Integer line, String id) {
- if (rows == null) {
- rows = new ArrayList<DataTableRow>();
- }
rows.add(new DataTableRow(comments, cells, line));
}
@@ -60,7 +59,7 @@ public Step(List<Comment> comments, String keyword, String name, Integer line, L
@Override
public Range getLineRange() {
Range range = super.getLineRange();
- if (getRows() != null) {
+ if (!getRows().isEmpty()) {
range = new Range(range.getFirst(), getRows().get(getRows().size() - 1).getLine());
} else if (getDocString() != null) {
range = new Range(range.getFirst(), getDocString().getLineRange().getLast());
@@ -99,4 +98,13 @@ public DocString getDocString() {
public StackTraceElement getStackTraceElement(String path) {
return new StackTraceElement("", getKeyword() + getName(), path, getLine());
}
+
+ @Override
+ public void accept(Visitor visitor, Next next) throws Exception {
+ if (doc_string != null) {
+ next.push(doc_string);
+ }
+ next.pushAll(rows);
+ visitor.visitStep(this, next);
+ }
}
View
7 java/src/main/java/gherkin/formatter/model/StepContainer.java
@@ -1,14 +1,13 @@
package gherkin.formatter.model;
-import java.util.Collection;
import java.util.List;
-public interface StepContainer {
+public interface StepContainer extends Visitable {
List<Step> getSteps();
void addStep(Step step);
- void addScenario(ExamplesTableRow header, ExamplesTableRow row, List<Tag> tags);
+ List<Scenario> getScenarios();
- Collection<Scenario> getScenarios();
+ void addExamples(Examples examples);
}
View
7 java/src/main/java/gherkin/formatter/model/Visitable.java
@@ -0,0 +1,7 @@
+package gherkin.formatter.model;
+
+import gherkin.formatter.visitors.Next;
+
+public interface Visitable {
+ void accept(Visitor visitor, Next bakctrack) throws Exception;
+}
View
21 java/src/main/java/gherkin/formatter/model/Visitor.java
@@ -0,0 +1,21 @@
+package gherkin.formatter.model;
+
+import gherkin.formatter.visitors.Next;
+
+public interface Visitor {
+ void visitFeature(Feature feature, Next next) throws Exception;
+
+ void visitBackground(Background background, Next next) throws Exception;
+
+ void visitScenario(Scenario scenario, Next next) throws Exception;
+
+ void visitScenarioOutline(ScenarioOutline scenarioOutline, Next next) throws Exception;
+
+ void visitStep(Step step, Next next) throws Exception;
+
+ void visitDataTableRow(DataTableRow row, Next next) throws Exception;
+
+ void visitExamples(Examples examples) throws Exception;
+
+ void visitDocString(DocString docString, Next next) throws Exception;
+}
View
31 java/src/main/java/gherkin/formatter/visitors/Next.java
@@ -0,0 +1,31 @@
+package gherkin.formatter.visitors;
+
+import gherkin.formatter.model.Visitable;
+import gherkin.formatter.model.Visitor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Next {
+ private final List<Visitable> visitables = new ArrayList<Visitable>();
+ private final Visitor visitor;
+
+ public Next(Visitor visitor) {
+ this.visitor = visitor;
+ }
+
+ public void pushAll(List<? extends Visitable> visitables) {
+ this.visitables.addAll(visitables);
+ }
+
+ public void push(Visitable visitable) {
+ visitables.add(visitable);
+ }
+
+ public void next() throws Exception {
+ if (!visitables.isEmpty()) {
+ Visitable visitable = visitables.remove(0);
+ visitable.accept(visitor, this);
+ }
+ }
+}
View
78 java/src/main/java/gherkin/formatter/visitors/PrettyVisitor.java
@@ -0,0 +1,78 @@
+package gherkin.formatter.visitors;
+
+import gherkin.formatter.model.Background;
+import gherkin.formatter.model.DataTableRow;
+import gherkin.formatter.model.DocString;
+import gherkin.formatter.model.Examples;
+import gherkin.formatter.model.Feature;
+import gherkin.formatter.model.Scenario;
+import gherkin.formatter.model.ScenarioOutline;
+import gherkin.formatter.model.Step;
+import gherkin.formatter.model.Visitor;
+
+import static gherkin.formatter.PrettyFormatter.escapeTripleQuotes;
+import static gherkin.formatter.PrettyFormatter.indent;
+
+public class PrettyVisitor implements Visitor {
+ private static final CharSequence EOL = "\n";
+ private final Appendable out;
+
+ public PrettyVisitor(Appendable out) {
+ this.out = out;
+ }
+
+ @Override
+ public void visitFeature(Feature feature, Next next) throws Exception {
+ out.append(feature.getKeyword()).append(": ").append(feature.getName()).append(EOL);
+ next.next();
+ }
+
+ @Override
+ public void visitBackground(Background background, Next next) throws Exception {
+ out.append(" ").append(background.getKeyword()).append(": ").append(background.getName()).append(EOL);
+ next.next();
+ }
+
+ @Override
+ public void visitScenario(Scenario scenario, Next next) throws Exception {
+ out.append(" ").append(scenario.getKeyword()).append(": ").append(scenario.getName()).append(EOL);
+ next.next();
+ }
+
+ @Override
+ public void visitScenarioOutline(ScenarioOutline scenarioOutline, Next next) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void visitStep(Step step, Next next) throws Exception {
+ out.append(" ").append(step.getKeyword()).append(step.getName()).append(EOL);
+ next.next();
+ }
+
+ @Override
+ public void visitDataTableRow(DataTableRow row, Next next) throws Exception {
+ out.append(" |");
+ for (String cell : row.getCells()) {
+ out.append(" ").append(cell).append(" |");
+ }
+ out.append(EOL);
+ next.next();
+ }
+
+ @Override
+ public void visitExamples(Examples examples) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void visitDocString(DocString docString, Next next) throws Exception {
+ out.append(" \"\"\"").append(docString.getContentType()).append(EOL);
+ out.append(escapeTripleQuotes(indent(docString.getValue(), " ")));
+ out.append(EOL).append(" \"\"\"").append(docString.getContentType()).append(EOL);
+ }
+
+ public Next createNext() {
+ return new Next(this);
+ }
+}
View
2  java/src/main/java/gherkin/lexer/Listener.java
@@ -24,4 +24,6 @@
void docString(String contentType, String content, Integer line);
void eof();
+
+ void syntaxError(String state, String event, List<String> legalEvents, String featureURI, Integer line);
}
View
5 java/src/main/java/gherkin/parser/AstListener.java
@@ -96,6 +96,11 @@ public void eof() {
replayStepsOrExamples();
}
+ @Override
+ public void syntaxError(String state, String event, List<String> legalEvents, String featureURI, Integer line) {
+ throw new UnsupportedOperationException();
+ }
+
public Feature getFeature() {
return feature;
}
View
27 java/src/main/java/gherkin/parser/Parser.java
@@ -18,12 +18,24 @@
private final boolean throwOnError;
private final String machineName;
- private FormatterListener listener;
- private I18nLexer lexer;
+ private final Listener listener;
+ private final I18nLexer lexer;
private String featureURI;
private Integer lineOffset;
private final Formatter formatter;
+ public Parser(Listener listener) {
+ this(listener, true, "root");
+ }
+
+ public Parser(Listener listener, boolean throwOnError, String machineName) {
+ this.listener = listener;
+ this.throwOnError = throwOnError;
+ this.machineName = machineName;
+ this.formatter = null;
+ this.lexer = new I18nLexer(this);
+ }
+
public Parser(Formatter formatter) {
this(formatter, true);
}
@@ -42,7 +54,7 @@ public Parser(Formatter formatter, boolean throwOnError, String machineName, boo
this.listener = new FormatterListener(formatter);
this.throwOnError = throwOnError;
this.machineName = machineName;
- this.lexer = new I18nLexer(this, forceRubyDummy);
+ this.lexer = new I18nLexer(this);
}
/**
@@ -50,7 +62,9 @@ public Parser(Formatter formatter, boolean throwOnError, String machineName, boo
* @param lineOffset the line offset within the uri document the gherkin was taken from. Typically 0.
*/
public void parse(String gherkin, String featureURI, Integer lineOffset) {
- formatter.uri(featureURI);
+ if (formatter != null) {
+ formatter.uri(featureURI);
+ }
this.featureURI = featureURI;
this.lineOffset = lineOffset;
pushMachine(machineName);
@@ -150,6 +164,11 @@ public void eof() {
}
}
+ @Override
+ public void syntaxError(String state, String event, List<String> legalEvents, String featureURI, Integer line) {
+ listener.syntaxError(state, event, legalEvents, featureURI, line);
+ }
+
private boolean event(String event, Integer line) {
try {
machine().event(event, line);
View
14 java/src/main/java/gherkin/parser/StateMachineReader.java
@@ -23,36 +23,50 @@ public StateMachineReader(String name) {
return transitionTable;
}
+ @Override
public void tag(String tag, Integer line) {
}
+ @Override
public void comment(String comment, Integer line) {
}
+ @Override
public void feature(String keyword, String name, String description, Integer line) {
}
+ @Override
public void background(String keyword, String name, String description, Integer line) {
}
+ @Override
public void scenario(String keyword, String name, String description, Integer line) {
}
+ @Override
public void scenarioOutline(String keyword, String name, String description, Integer line) {
}
+ @Override
public void examples(String keyword, String name, String description, Integer line) {
}
+ @Override
public void step(String keyword, String name, Integer line) {
}
+ @Override
public void docString(String contentType, String content, Integer line) {
}
+ @Override
public void eof() {
}
+ @Override
+ public void syntaxError(String state, String event, List<String> legalEvents, String featureURI, Integer line) {
+ }
+
public void row(List<String> cells, Integer line) {
transitionTable.add(cells);
}
View
44 java/src/test/java/gherkin/visitors/PrettyVisitorTest.java
@@ -0,0 +1,44 @@
+package gherkin.visitors;
+
+import gherkin.formatter.model.Feature;
+import gherkin.formatter.visitors.PrettyVisitor;
+import gherkin.parser.AstListener;
+import gherkin.parser.Parser;
+import org.junit.Test;
+
+public class PrettyVisitorTest {
+ @Test
+ public void prints_pretty_features() throws Exception {
+ AstListener l = new AstListener();
+ l.feature("Feature", "Test", "Desc", 1);
+ l.scenario("Scenario", "Test", "Desc", 2);
+ l.step("Given ", "Test", 3);
+ l.eof();
+
+ Feature f = l.getFeature();
+ PrettyVisitor visitor = new PrettyVisitor(System.out);
+ f.accept(visitor, visitor.createNext());
+ }
+
+ @Test
+ public void prints_pretty_features_from_parser() throws Exception {
+ AstListener l = new AstListener();
+ Parser parser = new Parser(l);
+ String gherkin = "" +
+ "Feature: Test\n" +
+ " Scenario: Test\n" +
+ " Given DataTable\n" +
+ " | a | bb |\n" +
+ " | ccc | dddd |\n" +
+ " When DocString\n" +
+ " \"\"\"\n" +
+ " Le Doc String\n" +
+ " \"\"\"\n" +
+ "";
+ parser.parse(gherkin, "some.feature", 0);
+
+ Feature f = l.getFeature();
+ PrettyVisitor visitor = new PrettyVisitor(System.out);
+ f.accept(visitor, visitor.createNext());
+ }
+}
View
BIN  tasks/yard/default/layout/html/bubble_32x32.png
Deleted file not rendered
View
BIN  tasks/yard/default/layout/html/bubble_48x48.png
Deleted file not rendered
View
2  tasks/yard/default/layout/html/logo.erb
@@ -1 +1 @@
-<h3><img src="<%= url_for('images/bubble_32x32.png') %>"></img> Gherkin <%= GHERKIN_VERSION %></h3>
+<h3><img src="//cukes.info/images/logos/cucumber-32x32.png"></img> Gherkin <%= GHERKIN_VERSION %></h3>
Please sign in to comment.
Something went wrong with that request. Please try again.