1 module gherkin.feature;
2 
3 import std.algorithm : map;
4 import std.array : array;
5 import std.typecons : Nullable;
6 
7 import asdf : serializationIgnore, serializationIgnoreOutIf;
8 import gherkin.base : Base;
9 import gherkin.comment : Comment;
10 import gherkin.document : GherkinDocument;
11 import gherkin.location : Location;
12 import gherkin.scenario : Scenario;
13 import gherkin.tag : Tag;
14 
15 ///
16 class Feature : Base
17 {
18     ///
19     @serializationIgnore Scenario[] scenarios;
20     ///
21     @serializationIgnore Nullable!Scenario background;
22     ///
23     @serializationIgnoreOutIf!`a.empty` string description;
24     ///
25     @serializationIgnoreOutIf!`a.empty` Tag[] tags;
26     ///
27     @serializationIgnore Comment[] comments;
28     ///
29     string language = "en";
30     ///
31     @serializationIgnore string uri;
32 
33     ///
34     this(string keyword, string name, Location location, string uri, ref Comment[] comments)
35     {
36         super(keyword, name, location);
37         this.uri = uri;
38         this.comments = comments.dup;
39         comments = [];
40         this.description = "";
41     }
42 
43     ///
44     @property @serializationIgnoreOutIf!`a.empty` Child[] children()
45     {
46         Child[] result;
47         if (!background.isNull)
48         {
49             result ~= Child(background.get);
50         }
51         result ~= scenarios.map!(s => Child(s)).array;
52 
53         return result;
54     }
55 
56     private struct Child
57     {
58         @serializationIgnore Scenario child;
59 
60         @property @serializationIgnoreOutIf!`!a.isBackground` Scenario background()
61         {
62             return child;
63         }
64 
65         @property @serializationIgnoreOutIf!`a.isBackground` Scenario scenario()
66         {
67             return child;
68         }
69     }
70 }