1 /** 2 Copyright: 2017 © LLC CERERIS 3 License: MIT 4 Authors: LLC CERERIS 5 */ 6 7 module checkit.bdd; 8 9 import checkit.block; 10 import checkit.blockmanager; 11 12 /** Used for SCENARIO block BDD 13 14 Params: 15 name = Name of scenario. 16 tags = Array tags for scenario. 17 expression = Tested block. 18 V = BlockManagerInterface for collecting blocks 19 20 Examples: 21 --- 22 scenario!("Test scenario", ["test"]) 23 ({ 24 writeln("TEST"); 25 }); 26 --- 27 */ 28 void scenario(string name, string[] tags, T, V: BlockManagerInterface = BlockManager)(lazy T expression) 29 { 30 immutable TestCallback callback = delegate void(){expression()();}; 31 auto block = new ScenarioBlock(callback, name, tags); 32 V.addBlock(block); 33 } 34 35 /** Used for GIVEN block BDD 36 37 Params: 38 name = Name of scenario. 39 expression = Tested block. 40 V = BlockManagerInterface for collecting blocks 41 42 Examples: 43 --- 44 given!"Test given" 45 ({ 46 writeln("TEST"); 47 }); 48 --- 49 */ 50 void given(string name, T, V: BlockManagerInterface = BlockManager)(lazy T expression) 51 { 52 immutable TestCallback callback = delegate void(){expression()();}; 53 auto block = new GivenBlock(callback, name); 54 V.addBlock(block); 55 } 56 57 /** Used for WHEN block BDD 58 59 Params: 60 name = Name of scenario. 61 expression = Tested block. 62 V = BlockManagerInterface for collecting blocks 63 64 Examples: 65 --- 66 when!"Test when" 67 ({ 68 writeln("TEST"); 69 }); 70 --- 71 */ 72 void when(string name, T, V: BlockManagerInterface = BlockManager)(lazy T expression) 73 { 74 immutable TestCallback callback = delegate void(){expression()();}; 75 auto block = new WhenBlock(callback, name); 76 V.addBlock(block); 77 } 78 79 /** Used for THEN block BDD 80 81 Params: 82 name = Name of scenario. 83 expression = Tested block. 84 V = BlockManagerInterface for collecting blocks 85 86 Examples: 87 --- 88 then!"Test then" 89 ({ 90 writeln("TEST"); 91 }); 92 --- 93 */ 94 void then(string name, T, V: BlockManagerInterface = BlockManager)(lazy T expression) 95 { 96 immutable TestCallback callback = delegate void(){expression()();}; 97 auto block = new ThenBlock(callback, name); 98 V.addBlock(block); 99 }