1 /** 2 Copyright: 2017 © LLC CERERIS 3 License: MIT 4 Authors: LLC CERERIS 5 */ 6 7 module checkit.block; 8 9 import std.uuid: randomUUID, UUID; 10 11 alias TestCallback = void delegate(); 12 13 /// Block of code as expression 14 class TestBlock 15 { 16 public: 17 /** Constructor 18 Params: 19 callback = Lazy expression for run block. 20 name = Name of block. 21 22 Examples: 23 --- 24 auto block = new TestBlock({}, "Test"); 25 --- 26 */ 27 this(TestCallback callback, string name) 28 { 29 _callback = callback; 30 _name = name; 31 _uuid = randomUUID(); 32 } 33 34 /** Get UUID of block 35 36 Returns: 37 return $(D UUID) of test code block 38 39 Examples: 40 --- 41 auto block = new TestBlock({}, "Test"); 42 block.getUUID(); 43 --- 44 */ 45 final UUID getUUID() 46 { 47 return _uuid; 48 } 49 50 /** Get name of block 51 52 Returns: 53 return name $(D string) of test code block 54 55 Examples: 56 --- 57 auto block = new TestBlock({}, "Test"); 58 assert(block.getName() == "Test"); 59 --- 60 */ 61 final string getName() 62 { 63 return _name; 64 } 65 66 /** Get callback of block for run expression 67 68 Returns: 69 return callback delegate $(D TestCallback) of test code block 70 71 Examples: 72 --- 73 auto block = new TestBlock({}, "Test"); 74 block.getCallback()(); 75 --- 76 */ 77 final TestCallback getCallback() 78 { 79 return _callback; 80 } 81 82 private: 83 /// Callback for run expression 84 TestCallback _callback; 85 /// UUID of block 86 UUID _uuid; 87 /// Name of block 88 string _name; 89 } 90 91 /// Scenario code Block 92 class ScenarioBlock: TestBlock 93 { 94 public: 95 /** Constructor 96 Params: 97 callback = Lazy expression for run block. 98 name = Name of block. 99 tags = string array of tags scenario. 100 101 Examples: 102 --- 103 auto block = new ScenarioBlock({}, "Test", ["test"]); 104 --- 105 */ 106 this(TestCallback callback, string name, string[] tags) 107 { 108 super(callback, name); 109 _tags = tags; 110 } 111 112 /** Get tags of scenario block 113 114 Returns: 115 return tags $(D string[]) of scenario block 116 117 Examples: 118 --- 119 auto block = new ScenarioBlock({}, "Test", ["test"]); 120 assert(block.getTags() == ["test"]); 121 --- 122 */ 123 final string[] getTags() 124 { 125 return _tags; 126 } 127 128 private: 129 string[] _tags; 130 } 131 132 /// Given code Block 133 final class GivenBlock: TestBlock 134 { 135 public: 136 /** Constructor 137 Params: 138 callback = Lazy expression for run block. 139 name = Name of block. 140 141 Examples: 142 --- 143 auto block = new GivenBlock({}, "Test"); 144 --- 145 */ 146 this(TestCallback callback, string name) 147 { 148 super(callback, name); 149 } 150 } 151 152 /// When code Block 153 final class WhenBlock: TestBlock 154 { 155 public: 156 this(TestCallback callback, string name) 157 { 158 super(callback, name); 159 } 160 } 161 162 /// Then code Block 163 final class ThenBlock: TestBlock 164 { 165 public: 166 this(TestCallback callback, string name) 167 { 168 super(callback, name); 169 } 170 }