Skip to content

Commit

Permalink
gherkin: Merge master, ref #292
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Feb 10, 2018
2 parents 9e00594 + ec7a9eb commit 02200f9
Show file tree
Hide file tree
Showing 76 changed files with 441 additions and 34 deletions.
3 changes: 2 additions & 1 deletion gherkin/c/include/pickle_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ extern "C" {
typedef struct PickleString {
PickleArgumentType type;
PickleLocation location;
wchar_t* content_type;
wchar_t* content;
} PickleString;

const PickleString* PickleString_new(const wchar_t* content, int line, int column);
const PickleString* PickleString_new(const wchar_t* content, int line, int column, const wchar_t* content_type);

void PickleString_delete(const PickleString* pickle_string);

Expand Down
11 changes: 9 additions & 2 deletions gherkin/c/src/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,19 @@ static const PickleArgument* create_pickle_argument(const StepArgument* step_arg
else if (step_argument->type == Gherkin_DocString) {
const DocString* doc_string = (DocString*)step_argument;
if (!example_header) {
argument = (const PickleArgument*)PickleString_new(doc_string->content, doc_string->location.line, doc_string->location.column);
argument = (const PickleArgument*)PickleString_new(doc_string->content, doc_string->location.line, doc_string->location.column, doc_string->content_type);
}
else {
const wchar_t* expanded_text = create_expanded_text(doc_string->content, example_header, body_row);
argument = (const PickleArgument*)PickleString_new(expanded_text, doc_string->location.line, doc_string->location.column);
const wchar_t* expanded_content_type = 0;
if(doc_string->content_type){
expanded_content_type = create_expanded_text(doc_string->content_type, example_header, body_row);
}
argument = (const PickleArgument*)PickleString_new(expanded_text, doc_string->location.line, doc_string->location.column, expanded_content_type);
free((void*)expanded_text);
if(expanded_content_type != 0){
free((void*)expanded_content_type);
}
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion gherkin/c/src/pickle_printer.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ static void print_pickle_string(FILE* file, const PickleString* pickle_string) {
if (pickle_string->content) {
PrintUtilities_print_json_string(file, pickle_string->content);
}
fprintf(file, "\"}");
fprintf(file, "\"");
if(pickle_string->content_type) {
fprintf(file, ",\"contentType\":\"");
PrintUtilities_print_json_string(file, pickle_string->content_type);
fprintf(file, "\"");
}
fprintf(file, "}");
}

static void print_tag(FILE* file, const PickleTag* tag) {
Expand Down
9 changes: 8 additions & 1 deletion gherkin/c/src/pickle_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "string_utilities.h"
#include <stdlib.h>

const PickleString* PickleString_new(const wchar_t* content, int line, int column) {
const PickleString* PickleString_new(const wchar_t* content, int line, int column, const wchar_t* content_type) {
PickleString* pickle_string = (PickleString*)malloc(sizeof(PickleString));
pickle_string->type = Argument_String;
pickle_string->location.line = line;
Expand All @@ -11,6 +11,10 @@ const PickleString* PickleString_new(const wchar_t* content, int line, int colum
if (content) {
pickle_string->content = StringUtilities_copy_string(content);
}
pickle_string->content_type = 0;
if (content_type && wcslen(content_type) > 0) {
pickle_string->content_type = StringUtilities_copy_string(content_type);
}
return pickle_string;
}

Expand All @@ -21,5 +25,8 @@ void PickleString_delete(const PickleString* pickle_string) {
if (pickle_string->content) {
free((void*)pickle_string->content);
}
if (pickle_string->content_type) {
free((void*)pickle_string->content_type);
}
free((void*)pickle_string);
}
2 changes: 1 addition & 1 deletion gherkin/c/testdata/good/docstrings.feature.pickles.ndjson
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"pickle":{"language":"en","locations":[{"column":3,"line":3}],"name":"minimalistic","steps":[{"arguments":[{"content":"first line (no indent)\n second line (indented with two spaces)\n\nthird line was empty","location":{"column":7,"line":5}}],"locations":[{"column":11,"line":4}],"text":"a simple DocString"},{"arguments":[{"content":"<foo>\n <bar />\n</foo>","location":{"column":7,"line":12}}],"locations":[{"column":11,"line":11}],"text":"a DocString with content type"},{"arguments":[{"content":"wrongly indented line","location":{"column":7,"line":18}}],"locations":[{"column":9,"line":17}],"text":"a DocString with wrong indentation"},{"arguments":[{"content":"first line\nsecond line","location":{"column":7,"line":22}}],"locations":[{"column":9,"line":21}],"text":"a DocString with alternative separator"},{"arguments":[{"content":"first line\n\"\"\"\nthird line","location":{"column":7,"line":27}}],"locations":[{"column":9,"line":26}],"text":"a DocString with normal separator inside"},{"arguments":[{"content":"first line\n```\nthird line","location":{"column":7,"line":33}}],"locations":[{"column":9,"line":32}],"text":"a DocString with alternative separator inside"},{"arguments":[{"content":"first line\n\"\"\"\nthird line","location":{"column":7,"line":39}}],"locations":[{"column":9,"line":38}],"text":"a DocString with escaped separator inside"}],"tags":[]},"type":"pickle","uri":"testdata/good/docstrings.feature"}
{"pickle":{"language":"en","locations":[{"column":3,"line":3}],"name":"minimalistic","steps":[{"arguments":[{"content":"first line (no indent)\n second line (indented with two spaces)\n\nthird line was empty","location":{"column":7,"line":5}}],"locations":[{"column":11,"line":4}],"text":"a simple DocString"},{"arguments":[{"content":"<foo>\n <bar />\n</foo>","contentType":"xml","location":{"column":7,"line":12}}],"locations":[{"column":11,"line":11}],"text":"a DocString with content type"},{"arguments":[{"content":"wrongly indented line","location":{"column":7,"line":18}}],"locations":[{"column":9,"line":17}],"text":"a DocString with wrong indentation"},{"arguments":[{"content":"first line\nsecond line","location":{"column":7,"line":22}}],"locations":[{"column":9,"line":21}],"text":"a DocString with alternative separator"},{"arguments":[{"content":"first line\n\"\"\"\nthird line","location":{"column":7,"line":27}}],"locations":[{"column":9,"line":26}],"text":"a DocString with normal separator inside"},{"arguments":[{"content":"first line\n```\nthird line","location":{"column":7,"line":33}}],"locations":[{"column":9,"line":32}],"text":"a DocString with alternative separator inside"},{"arguments":[{"content":"first line\n\"\"\"\nthird line","location":{"column":7,"line":39}}],"locations":[{"column":9,"line":38}],"text":"a DocString with escaped separator inside"}],"tags":[]},"type":"pickle","uri":"testdata/good/docstrings.feature"}
12 changes: 12 additions & 0 deletions gherkin/c/testdata/good/scenario_outline_with_docstring.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: Scenario Outline with a docstring

Scenario Outline: Greetings come in many forms
Given this file:
"""<type>
Greeting:<content>
"""

Examples:
| type | content |
| en | Hello |
| fr | Bonjour |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"document":{"comments":[],"feature":{"children":[{"examples":[{"keyword":"Examples","location":{"column":1,"line":9},"name":"","tableBody":[{"cells":[{"location":{"column":5,"line":11},"type":"TableCell","value":"en"},{"location":{"column":13,"line":11},"type":"TableCell","value":"Hello"}],"location":{"column":3,"line":11},"type":"TableRow"},{"cells":[{"location":{"column":5,"line":12},"type":"TableCell","value":"fr"},{"location":{"column":13,"line":12},"type":"TableCell","value":"Bonjour"}],"location":{"column":3,"line":12},"type":"TableRow"}],"tableHeader":{"cells":[{"location":{"column":5,"line":10},"type":"TableCell","value":"type"},{"location":{"column":13,"line":10},"type":"TableCell","value":"content"}],"location":{"column":3,"line":10},"type":"TableRow"},"tags":[],"type":"Examples"}],"keyword":"Scenario Outline","location":{"column":1,"line":3},"name":"Greetings come in many forms","steps":[{"argument":{"content":"Greeting:<content>","contentType":"<type>","location":{"column":5,"line":5},"type":"DocString"},"keyword":"Given ","location":{"column":5,"line":4},"text":"this file:","type":"Step"}],"tags":[],"type":"ScenarioOutline"}],"keyword":"Feature","language":"en","location":{"column":1,"line":1},"name":"Scenario Outline with a docstring","tags":[],"type":"Feature"},"type":"GherkinDocument"},"type":"gherkin-document","uri":"testdata/good/scenario_outline_with_docstring.feature"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"pickle":{"language":"en","locations":[{"column":3,"line":11},{"column":1,"line":3}],"name":"Greetings come in many forms","steps":[{"arguments":[{"content":"Greeting:Hello","contentType":"en","location":{"column":5,"line":5}}],"locations":[{"column":3,"line":11},{"column":11,"line":4}],"text":"this file:"}],"tags":[]},"type":"pickle","uri":"testdata/good/scenario_outline_with_docstring.feature"}
{"pickle":{"language":"en","locations":[{"column":3,"line":12},{"column":1,"line":3}],"name":"Greetings come in many forms","steps":[{"arguments":[{"content":"Greeting:Bonjour","contentType":"fr","location":{"column":5,"line":5}}],"locations":[{"column":3,"line":12},{"column":11,"line":4}],"text":"this file:"}],"tags":[]},"type":"pickle","uri":"testdata/good/scenario_outline_with_docstring.feature"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"data":"Feature: Scenario Outline with a docstring\n\nScenario Outline: Greetings come in many forms\n Given this file:\n \"\"\"<type>\n Greeting:<content>\n \"\"\"\n\nExamples:\n | type | content |\n | en | Hello |\n | fr | Bonjour |\n","media":{"encoding":"utf-8","type":"text/x.cucumber.gherkin+plain"},"type":"source","uri":"testdata/good/scenario_outline_with_docstring.feature"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(1:1)FeatureLine:Feature/Scenario Outline with a docstring/
(2:1)Empty://
(3:1)ScenarioOutlineLine:Scenario Outline/Greetings come in many forms/
(4:5)StepLine:Given /this file:/
(5:5)DocStringSeparator:/<type>/
(6:1)Other:/Greeting:<content>/
(7:5)DocStringSeparator://
(8:1)Empty://
(9:1)ExamplesLine:Examples//
(10:3)TableRow://5:type,13:content
(11:3)TableRow://5:en,13:Hello
(12:3)TableRow://5:fr,13:Bonjour
EOF
3 changes: 2 additions & 1 deletion gherkin/dotnet/Gherkin/Pickles/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ protected virtual List<Argument> CreatePickleArguments(StepArgument argument, IE
result.Add(
new PickleString(
PickleLocation(ds.Location),
Interpolate(ds.Content, variableCells, valueCells)
Interpolate(ds.Content, variableCells, valueCells),
ds.ContentType == null ? null : Interpolate(ds.ContentType, variableCells, valueCells)
)
);
} else {
Expand Down
5 changes: 4 additions & 1 deletion gherkin/dotnet/Gherkin/Pickles/PickleString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ public override PickleLocation Location
}

public string Content { get; private set; }

public string ContentType { get; private set; }

public PickleString(PickleLocation location, string content)
public PickleString(PickleLocation location, string content, string contentType = null)
{
this.location = location;
Content = content;
ContentType = contentType;
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"pickle":{"language":"en","locations":[{"column":3,"line":3}],"name":"minimalistic","steps":[{"arguments":[{"content":"first line (no indent)\n second line (indented with two spaces)\n\nthird line was empty","location":{"column":7,"line":5}}],"locations":[{"column":11,"line":4}],"text":"a simple DocString"},{"arguments":[{"content":"<foo>\n <bar />\n</foo>","location":{"column":7,"line":12}}],"locations":[{"column":11,"line":11}],"text":"a DocString with content type"},{"arguments":[{"content":"wrongly indented line","location":{"column":7,"line":18}}],"locations":[{"column":9,"line":17}],"text":"a DocString with wrong indentation"},{"arguments":[{"content":"first line\nsecond line","location":{"column":7,"line":22}}],"locations":[{"column":9,"line":21}],"text":"a DocString with alternative separator"},{"arguments":[{"content":"first line\n\"\"\"\nthird line","location":{"column":7,"line":27}}],"locations":[{"column":9,"line":26}],"text":"a DocString with normal separator inside"},{"arguments":[{"content":"first line\n```\nthird line","location":{"column":7,"line":33}}],"locations":[{"column":9,"line":32}],"text":"a DocString with alternative separator inside"},{"arguments":[{"content":"first line\n\"\"\"\nthird line","location":{"column":7,"line":39}}],"locations":[{"column":9,"line":38}],"text":"a DocString with escaped separator inside"}],"tags":[]},"type":"pickle","uri":"testdata/good/docstrings.feature"}
{"pickle":{"language":"en","locations":[{"column":3,"line":3}],"name":"minimalistic","steps":[{"arguments":[{"content":"first line (no indent)\n second line (indented with two spaces)\n\nthird line was empty","location":{"column":7,"line":5}}],"locations":[{"column":11,"line":4}],"text":"a simple DocString"},{"arguments":[{"content":"<foo>\n <bar />\n</foo>","contentType":"xml","location":{"column":7,"line":12}}],"locations":[{"column":11,"line":11}],"text":"a DocString with content type"},{"arguments":[{"content":"wrongly indented line","location":{"column":7,"line":18}}],"locations":[{"column":9,"line":17}],"text":"a DocString with wrong indentation"},{"arguments":[{"content":"first line\nsecond line","location":{"column":7,"line":22}}],"locations":[{"column":9,"line":21}],"text":"a DocString with alternative separator"},{"arguments":[{"content":"first line\n\"\"\"\nthird line","location":{"column":7,"line":27}}],"locations":[{"column":9,"line":26}],"text":"a DocString with normal separator inside"},{"arguments":[{"content":"first line\n```\nthird line","location":{"column":7,"line":33}}],"locations":[{"column":9,"line":32}],"text":"a DocString with alternative separator inside"},{"arguments":[{"content":"first line\n\"\"\"\nthird line","location":{"column":7,"line":39}}],"locations":[{"column":9,"line":38}],"text":"a DocString with escaped separator inside"}],"tags":[]},"type":"pickle","uri":"testdata/good/docstrings.feature"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: Scenario Outline with a docstring

Scenario Outline: Greetings come in many forms
Given this file:
"""<type>
Greeting:<content>
"""

Examples:
| type | content |
| en | Hello |
| fr | Bonjour |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"document":{"comments":[],"feature":{"children":[{"examples":[{"keyword":"Examples","location":{"column":1,"line":9},"name":"","tableBody":[{"cells":[{"location":{"column":5,"line":11},"type":"TableCell","value":"en"},{"location":{"column":13,"line":11},"type":"TableCell","value":"Hello"}],"location":{"column":3,"line":11},"type":"TableRow"},{"cells":[{"location":{"column":5,"line":12},"type":"TableCell","value":"fr"},{"location":{"column":13,"line":12},"type":"TableCell","value":"Bonjour"}],"location":{"column":3,"line":12},"type":"TableRow"}],"tableHeader":{"cells":[{"location":{"column":5,"line":10},"type":"TableCell","value":"type"},{"location":{"column":13,"line":10},"type":"TableCell","value":"content"}],"location":{"column":3,"line":10},"type":"TableRow"},"tags":[],"type":"Examples"}],"keyword":"Scenario Outline","location":{"column":1,"line":3},"name":"Greetings come in many forms","steps":[{"argument":{"content":"Greeting:<content>","contentType":"<type>","location":{"column":5,"line":5},"type":"DocString"},"keyword":"Given ","location":{"column":5,"line":4},"text":"this file:","type":"Step"}],"tags":[],"type":"ScenarioOutline"}],"keyword":"Feature","language":"en","location":{"column":1,"line":1},"name":"Scenario Outline with a docstring","tags":[],"type":"Feature"},"type":"GherkinDocument"},"type":"gherkin-document","uri":"testdata/good/scenario_outline_with_docstring.feature"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"pickle":{"language":"en","locations":[{"column":3,"line":11},{"column":1,"line":3}],"name":"Greetings come in many forms","steps":[{"arguments":[{"content":"Greeting:Hello","contentType":"en","location":{"column":5,"line":5}}],"locations":[{"column":3,"line":11},{"column":11,"line":4}],"text":"this file:"}],"tags":[]},"type":"pickle","uri":"testdata/good/scenario_outline_with_docstring.feature"}
{"pickle":{"language":"en","locations":[{"column":3,"line":12},{"column":1,"line":3}],"name":"Greetings come in many forms","steps":[{"arguments":[{"content":"Greeting:Bonjour","contentType":"fr","location":{"column":5,"line":5}}],"locations":[{"column":3,"line":12},{"column":11,"line":4}],"text":"this file:"}],"tags":[]},"type":"pickle","uri":"testdata/good/scenario_outline_with_docstring.feature"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"data":"Feature: Scenario Outline with a docstring\n\nScenario Outline: Greetings come in many forms\n Given this file:\n \"\"\"<type>\n Greeting:<content>\n \"\"\"\n\nExamples:\n | type | content |\n | en | Hello |\n | fr | Bonjour |\n","media":{"encoding":"utf-8","type":"text/x.cucumber.gherkin+plain"},"type":"source","uri":"testdata/good/scenario_outline_with_docstring.feature"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(1:1)FeatureLine:Feature/Scenario Outline with a docstring/
(2:1)Empty://
(3:1)ScenarioOutlineLine:Scenario Outline/Greetings come in many forms/
(4:5)StepLine:Given /this file:/
(5:5)DocStringSeparator:/<type>/
(6:1)Other:/Greeting:<content>/
(7:5)DocStringSeparator://
(8:1)Empty://
(9:1)ExamplesLine:Examples//
(10:3)TableRow://5:type,13:content
(11:3)TableRow://5:en,13:Hello
(12:3)TableRow://5:fr,13:Bonjour
EOF
10 changes: 6 additions & 4 deletions gherkin/go/pickles.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ type (
}

PickleString struct {
Location Location `json:"location"`
Content string `json:"content"`
Location Location `json:"location"`
ContentType string `json:"contentType,omitempty"`
Content string `json:"content"`
}

PickleCell struct {
Expand Down Expand Up @@ -171,8 +172,9 @@ func pickleArgument(arg interface{}, keys, vals []*TableCell) []Argument {
switch t := arg.(type) {
case *DocString:
args = append(args, &PickleString{
Location: *t.Location,
Content: trans(t.Content),
Location: *t.Location,
ContentType: trans(t.ContentType),
Content: trans(t.Content),
})
case *DataTable:
rows := make([]*PickleRow, len(t.Rows))
Expand Down

0 comments on commit 02200f9

Please sign in to comment.