1 module cucumber.formatter.progress;
2 
3 import std.stdio : write, writeln;
4 
5 import cucumber.formatter.base : Formatter;
6 import cucumber.formatter.color : colors, noColors;
7 import cucumber.result : Result, RunResult, ScenarioResult, StepResult;
8 import gherkin : Feature, Scenario, Step, Examples, TableRow, Comment;
9 
10 ///
11 class Progress : Formatter
12 {
13     private bool noColor;
14     private bool noSnippets;
15     private bool noSource;
16 
17     ///
18     this(bool noColor, bool noSnippets, bool noSource)
19     {
20         this.noColor = noColor;
21         this.noSnippets = noSnippets;
22         this.noSource = noSource;
23     }
24 
25     ///
26     override string color(string result)
27     {
28         return noColor ? noColors[result] : colors[result];
29     }
30 
31     ///
32     override void feature(Feature feature)
33     {
34         // do nothing
35     }
36 
37     ///
38     override void scenario(ref Scenario scenario)
39     {
40         // do nothing
41     }
42 
43     ///
44     override void examples(Examples examples)
45     {
46         // do nothing
47     }
48 
49     ///
50     override void tableRow(TableRow tableRow, ref TableRow[] table, string color)
51     {
52         // do nothing
53     }
54 
55     ///
56     override void tableRow(TableRow tableRow, ref TableRow[] table, ScenarioResult scenarioResult)
57     {
58         // do nothing
59     }
60 
61     ///
62     override void step(Step step, StepResult stepResult)
63     {
64         write(color(stepResult.result), progressSymbol(stepResult.result), color("reset"));
65     }
66 
67     ///
68     override void comment(Comment comment)
69     {
70         // do nothing
71     }
72 
73     ///
74     override void summarizeResult(RunResult result)
75     {
76         writeln("\n");
77         runResult(result, noSource);
78     }
79 
80 private:
81     string progressSymbol(string result)
82     {
83         immutable auto progressSymbols = [
84             "failed" : `F`, "skipped" : `-`, "undefined" : `U`, "passed" : `.`
85         ];
86         return progressSymbols[result];
87     }
88 }