1 module gherkin.scenario;
2 
3 import std.json : JSONValue, parseJSON;
4 import std.range : empty;
5 import std.typecons : Nullable;
6 
7 import asdf : serializationIgnoreOutIf, serializationTransformOut, serializeToJson;
8 import gherkin.base : Base;
9 import gherkin.datatable : TableRow;
10 import gherkin.feature : Feature;
11 import gherkin.location : Location;
12 import gherkin.step : Step;
13 import gherkin.tag : Tag;
14 
15 alias Background = Scenario;
16 
17 ///
18 class Scenario : Base
19 {
20     ///
21     Feature parent;
22     ///
23     bool isBackground;
24     ///
25     Nullable!string id;
26     ///
27     Step[] steps;
28     ///
29     Nullable!string description;
30     ///
31     Examples[] examples;
32     ///
33     Tag[] tags;
34     ///
35     bool isScenarioOutline;
36 
37     ///
38     this(string keyword, string name, Location location, Feature parent, bool isBackground)
39     {
40         super(keyword, name, location);
41         this.parent = parent;
42         this.isBackground = isBackground;
43     }
44 
45     ///
46     override JSONValue toJSON() const
47     {
48         auto json = super.toJSON;
49 
50         if (!id.isNull)
51         {
52             json["id"] = JSONValue(id.get);
53         }
54         if (!steps.empty)
55         {
56             json["steps"] = parseJSON(serializeToJson(steps));
57         }
58         if (!description.isNull)
59         {
60             json["description"] = parseJSON(serializeToJson(description.get));
61         }
62         if (!examples.empty)
63         {
64             json["examples"] = parseJSON(serializeToJson(examples));
65         }
66         if (!tags.empty)
67         {
68             json["tags"] = parseJSON(serializeToJson(tags));
69         }
70 
71         return json;
72     }
73 }
74 
75 ///
76 struct Examples
77 {
78     ///
79     string keyword;
80     ///
81     @serializationIgnoreOutIf!`a.empty` string name;
82     ///
83     Location location;
84     ///
85     @serializationIgnoreOutIf!`a.isNull`@serializationTransformOut!`a.get` Nullable!TableRow tableHeader;
86     ///
87     @serializationIgnoreOutIf!`a.empty` TableRow[] tableBody;
88     ///
89     @serializationIgnoreOutIf!`a.isNull`@serializationTransformOut!`a.get` Nullable!string description;
90     ///
91     @serializationIgnoreOutIf!`a.empty` Tag[] tags;
92 }