1 module test.dli.mock_menu;
2 
3 import dli.text_menu;
4 import dli.string_stream.input_string_stream;
5 import dli.string_stream.output_string_stream;
6 
7 ///
8 public class MockMenu : TextMenu!(shared InputStringStream, shared OutputStringStream, size_t)
9 {
10     private enum size_t exitMenuItemKey = size_t.max;
11 
12     /// Creates a MockMenu with its own input and output streams
13     this()
14     {
15         super(new shared InputStringStream(), new shared OutputStringStream());
16     }
17 
18     /// Creates a MockMenu that uses the input and output streams of the passed menu
19     this(MockMenu mockMenu)
20     {
21         super(mockMenu);
22     }
23 
24     /// Mocks the writing of a line into the input stream
25     public void mock_writeln(string s)
26     in
27     {
28         assert(s !is null);
29     }
30     body
31     {
32         inputStream.appendLine(s);
33     }
34 
35     /// Mocks the required writing to select the "exit menu" menu item
36     public void mock_writeExitRequest()
37     {
38         import std.conv : to;
39 
40         inputStream.appendLine(to!string(exitMenuItemKey));
41     }
42 
43     protected override void addExitMenuItem(MenuItem exitMenuItem)
44     {
45         menuItems[exitMenuItemKey] = exitMenuItem;
46     }
47 
48     protected override void removeExitMenuItem()
49     {
50         menuItems.remove(exitMenuItemKey);
51     }
52 }