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