1 module tests.pass.mock;
2 
3 import unit_threaded;
4 
5 @safe pure unittest {
6     interface Foo {
7         int foo(int, string) @safe pure;
8         void bar() @safe pure;
9     }
10 
11     int fun(Foo f) {
12         return 2 * f.foo(5, "foobar");
13     }
14 
15     auto m = mock!Foo;
16     m.expect!"foo";
17     fun(m);
18 }
19 
20 
21 @safe pure unittest {
22     auto m = mockStruct;
23     m.expect!"foo"(2);
24     generic(m);
25     m.verify;
26 }
27 
28 @safe pure unittest {
29     auto m = mockStruct;
30     generic(m);
31     m.expectCalled!"foo"(2);
32 }
33 
34 void generic(T)(auto ref T thing) {
35     thing.foo(2);
36 }
37 
38 struct Namespace {
39     import std.datetime : Duration;
40     class HiddenTypes {
41         abstract Duration identity(Duration) pure @safe;
42     }
43 }
44 
45 @safe pure unittest {
46     auto m = mock!(Namespace.HiddenTypes);
47     {
48         import std.datetime : Duration;
49         m.expect!"identity"(Duration.init);
50         m.identity(Duration.init);
51         m.verify;
52     }
53 }
54 
55 @("private or protected members") @safe pure unittest {
56     interface InterfaceWithProtected {
57         bool result();
58         protected final void inner(int i) { }
59     }
60 
61     auto m = mock!InterfaceWithProtected;
62 }
63 
64 
65 struct Struct { }
66 
67 @("default params")
68 @safe pure unittest {
69     interface Interface {
70         void write(Struct stream, ulong nbytes = 0LU);
71     }
72 
73     auto m = mock!Interface;
74 }