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