Skip to content
This repository was archived by the owner on Nov 9, 2022. It is now read-only.

Commit e97a78d

Browse files
rjwittamsaslakhellesoy
authored andcommitted
Include interpolation of docstring content type.
Added a test for this. Updated other language implementations. The Obj-C implementation does not appear to support pickles so I didn't change it. There is a generated parser change in the javascript. Not sure why - if it was accidentally left out before, or is environmental ( different versions of something?)
1 parent 43f47a0 commit e97a78d

10 files changed

+56
-6
lines changed

include/pickle_string.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ extern "C" {
1313
typedef struct PickleString {
1414
PickleArgumentType type;
1515
PickleLocation location;
16+
wchar_t* content_type;
1617
wchar_t* content;
1718
} PickleString;
1819

19-
const PickleString* PickleString_new(const wchar_t* content, int line, int column);
20+
const PickleString* PickleString_new(const wchar_t* content, int line, int column, const wchar_t* content_type);
2021

2122
void PickleString_delete(const PickleString* pickle_string);
2223

src/compiler.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,19 @@ static const PickleArgument* create_pickle_argument(const StepArgument* step_arg
140140
else if (step_argument->type == Gherkin_DocString) {
141141
const DocString* doc_string = (DocString*)step_argument;
142142
if (!example_header) {
143-
argument = (const PickleArgument*)PickleString_new(doc_string->content, doc_string->location.line, doc_string->location.column);
143+
argument = (const PickleArgument*)PickleString_new(doc_string->content, doc_string->location.line, doc_string->location.column, doc_string->content_type);
144144
}
145145
else {
146146
const wchar_t* expanded_text = create_expanded_text(doc_string->content, example_header, body_row);
147-
argument = (const PickleArgument*)PickleString_new(expanded_text, doc_string->location.line, doc_string->location.column);
147+
const wchar_t* expanded_content_type = 0;
148+
if(doc_string->content_type){
149+
expanded_content_type = create_expanded_text(doc_string->content_type, example_header, body_row);
150+
}
151+
argument = (const PickleArgument*)PickleString_new(expanded_text, doc_string->location.line, doc_string->location.column, expanded_content_type);
148152
free((void*)expanded_text);
153+
if(expanded_content_type != 0){
154+
free((void*)expanded_content_type);
155+
}
149156
}
150157
}
151158
}

src/pickle_printer.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ static void print_pickle_string(FILE* file, const PickleString* pickle_string) {
6464
if (pickle_string->content) {
6565
PrintUtilities_print_json_string(file, pickle_string->content);
6666
}
67-
fprintf(file, "\"}");
67+
fprintf(file, "\"");
68+
if(pickle_string->content_type) {
69+
fprintf(file, ",\"contentType\":\"");
70+
PrintUtilities_print_json_string(file, pickle_string->content_type);
71+
fprintf(file, "\"");
72+
}
73+
fprintf(file, "}");
6874
}
6975

7076
static void print_tag(FILE* file, const PickleTag* tag) {

src/pickle_string.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "string_utilities.h"
33
#include <stdlib.h>
44

5-
const PickleString* PickleString_new(const wchar_t* content, int line, int column) {
5+
const PickleString* PickleString_new(const wchar_t* content, int line, int column, const wchar_t* content_type) {
66
PickleString* pickle_string = (PickleString*)malloc(sizeof(PickleString));
77
pickle_string->type = Argument_String;
88
pickle_string->location.line = line;
@@ -11,6 +11,10 @@ const PickleString* PickleString_new(const wchar_t* content, int line, int colum
1111
if (content) {
1212
pickle_string->content = StringUtilities_copy_string(content);
1313
}
14+
pickle_string->content_type = 0;
15+
if (content_type && wcslen(content_type) > 0) {
16+
pickle_string->content_type = StringUtilities_copy_string(content_type);
17+
}
1418
return pickle_string;
1519
}
1620

@@ -21,5 +25,8 @@ void PickleString_delete(const PickleString* pickle_string) {
2125
if (pickle_string->content) {
2226
free((void*)pickle_string->content);
2327
}
28+
if (pickle_string->content_type) {
29+
free((void*)pickle_string->content_type);
30+
}
2431
free((void*)pickle_string);
2532
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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"}
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>","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"}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Feature: Scenario Outline with a docstring
2+
3+
Scenario Outline: Greetings come in many forms
4+
Given this file:
5+
"""<type>
6+
Greeting:<content>
7+
"""
8+
9+
Examples:
10+
| type | content |
11+
| en | Hello |
12+
| fr | Bonjour |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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"}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{"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"}
2+
{"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"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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"}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(1:1)FeatureLine:Feature/Scenario Outline with a docstring/
2+
(2:1)Empty://
3+
(3:1)ScenarioOutlineLine:Scenario Outline/Greetings come in many forms/
4+
(4:5)StepLine:Given /this file:/
5+
(5:5)DocStringSeparator:/<type>/
6+
(6:1)Other:/Greeting:<content>/
7+
(7:5)DocStringSeparator://
8+
(8:1)Empty://
9+
(9:1)ExamplesLine:Examples//
10+
(10:3)TableRow://5:type,13:content
11+
(11:3)TableRow://5:en,13:Hello
12+
(12:3)TableRow://5:fr,13:Bonjour
13+
EOF

0 commit comments

Comments
 (0)