1 module tagion.behaviour.BehaviourUnittest;
2 
3 import tagion.behaviour.BehaviourFeature;
4 
5 /// This module is only use to support the unittest
6 version (unittest) {
7     import std.format;
8     import std.process;
9     import tagion.hibon.Document;
10     import tagion.hibon.HiBON;
11 
12     version (none) {
13         immutable(string) REPOROOT;
14         shared static this() {
15             REPOROOT = environment.get(REPOROOT.stringof, null);
16             if (REPOROOT is null) {
17 
18                 const gitrepo = execute(["git", "rev-parse", "--show-toplevel"]);
19                 REPOROOT = gitrepo.output;
20             }
21             assert(REPOROOT, format!"%s must be defined"(REPOROOT.stringof));
22         }
23     }
24     @safe
25     Document result(string test) {
26         auto h = new HiBON;
27         h["test"] = test;
28         return Document(h);
29     }
30 
31     enum feature = Feature("Some awesome feature should print some cash out of the blue");
32     // Behavioral examples
33     @safe
34     @Scenario("Some awesome money printer")
35     class Some_awesome_feature {
36         uint count;
37         @Given("the card is valid")
38         Document is_valid() {
39             count++;
40             return result(__FUNCTION__);
41         }
42 
43         @Given("the account is in credit")
44         Document in_credit() {
45             count++;
46             return result(__FUNCTION__);
47         }
48 
49         @Given("the dispenser contains cash")
50         Document contains_cash() {
51             count++;
52             return result(__FUNCTION__);
53         }
54 
55         @When("the Customer request cash")
56         Document request_cash() {
57             count++;
58             return result(__FUNCTION__);
59         }
60 
61         @Then("the account is debited")
62         Document is_debited() {
63             count++;
64             return result(__FUNCTION__);
65         }
66 
67         @Then("the cash is dispensed")
68         Document is_dispensed() {
69             count++;
70             return result(__FUNCTION__);
71         }
72 
73         @But("if the Customer does not take his card, then the card must be swollowed")
74         Document swollow_the_card() {
75             count++;
76             return result(__FUNCTION__);
77         }
78 
79         void helper_function() {
80         }
81     }
82 
83     @safe
84     @Scenario("Some money printer which is controlled by a bankster")
85     class Some_awesome_feature_bad_format_double_property {
86         @Given("the card is valid")
87         Document is_valid() {
88             return Document();
89         }
90 
91         @When("the Customer request cash")
92         Document request_cash() {
93             return Document();
94         }
95 
96         @Then("the account is debited")
97         Document is_debited() {
98             return Document();
99         }
100 
101         @Then("the cash is dispensed")
102         Document is_dispensed() {
103             return Document();
104         }
105     }
106 
107     @safe
108     @Scenario("Some money printer which has run out of paper")
109     class Some_awesome_feature_bad_format_missing_given {
110         @Then("the account is debited ")
111         Document is_debited_bad_one() {
112             import std.exception;
113 
114             throw new Exception("Bad debit");
115             return Document();
116         }
117 
118         @Then("the cash is dispensed")
119         Document is_dispensed() {
120             return Document();
121         }
122     }
123 
124     @safe
125     @Scenario("Some money printer which is gone wild and prints toilet paper")
126     class Some_awesome_feature_bad_format_missing_then {
127         @Given("the card is valid")
128         Document is_valid() {
129             assert(0);
130             return Document();
131         }
132     }
133 
134 }
135 
136 @safe
137 struct This_is_not_a_scenario {
138 }