And if so, please help me understand how I can best use it for what I would like to do.
Sincerely,Grant Freder--
-- Rules --
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Aslak,Thank you for helping me get started. I am very happy to hear that this is what I was looking for. Thanks for providing me with starter code...StringBuilder json = new StringBuilder();JSONFormatter formatter = new JSONFormatter(json);Parser parser = new Parser(formatter);Lexer lexer = new En(parser);lexer.scan(theGherkinSource);FYI: I am using the 2.12.0/ jar. I am running into some issues with the scan method. It, according to the javadoc, "Lexes the source." and takes as an input, "source a string containing Gherkin source".Knowing that "Single Gherkin source file contains a description of a single feature. Source files have .feature extension.", I was a bit confused on what the method was looking for. Forgive me if I am making a easy mistake, but could you help me understand how to use this method? Clearly, it isn't designed for a file path (which would be a little too convenient, ha). I tried converting my .feature file into a String with lines separated by newline characters (\n) and fed the method.
However, I kept getting...Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.ArrayList.elementData(ArrayList.java:371)
at java.util.ArrayList.get(ArrayList.java:384)
at gherkin.parser.Parser.machine(Parser.java:173)
at gherkin.parser.Parser.event(Parser.java:159)
at gherkin.parser.Parser.feature(Parser.java:96)
at gherkin.lexer.En.scan(En.java:749)
at bddUImain.Test.main(Test.java:81)
I don't believe this has to do with the errors described here....but I may be wrong.
I have tried looking for a java example of parsing and json output, but only found your response to someone's request for a ruby method similar tojson_feature = awesome_method(::Rails.root + 'path/to/my.feature')In your response, you included nice example code...If you would be wiling to provide me with a similar example in java of parsing a gherkin file and saving the json result, or perhaps a little more detailed explanation of the code you provided me, it would be greatly appreciated.
package bddUImain;import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import gherkin.formatter.JSONFormatter;
import gherkin.parser.Parser;
import gherkin.util.FixJava;
public class Test {
public static void main(String[] args) throws IOException {
{
String path = ....
String gherkin = FixJava.readReader(new InputStreamReader(
new FileInputStream(path), "UTF-8"));
System.out.println("gherkin...\n" + gherkin);
StringBuilder json = new StringBuilder();
System.out.println("json: '" + json + "'");
JSONFormatter formatter = new JSONFormatter(json);
System.out.println("formatter: "+formatter.toString());
Parser parser = new Parser(formatter);
System.out.println("parser: " + parser.toString());
parser.parse(gherkin, path, 0);
System.out.println("json: '" + json + "'"); // Gherkin source as JSON
}
}
}
The resulting output is this...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~gherkin...
| n1 | n2 | result |
| 30 | 5 | 6 |
| 0 | 100 | 0 |
| 12 | 0 | Cannot divide by zero |
| 10.2 | 1 | 10 |
json: ''
formatter: gherkin.formatter.JSONFormatter@15a3d6b
parser: gherkin.parser.Parser@1efb836
json: ''
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I am unsure of what to make of this. Everything seems to be in order, but obviously no json string is being saved.