1 module ut.runtime;
2 
3 
4 import ut;
5 
6 
7 @("nodefaults.void")
8 @safe pure unittest {
9 
10     static struct Foo { string value; }
11     static struct Bar { string value; }
12     static struct Baz { string value; }
13 
14     static void funImpl(in Foo foo, in Bar bar, in Baz baz) {
15         foo.value.should == "foo";
16         bar.value.should == "bar";
17         baz.value.should == "baz";
18     }
19 
20     alias fun = kwargify!funImpl;
21 
22     fun(Foo("foo"), Bar("bar"), Baz("baz"));
23     fun(Bar("bar"), Foo("foo"), Baz("baz"));
24     fun(Baz("baz"), Bar("bar"), Foo("foo"));
25 
26     static assert(!__traits(compiles, fun()));
27 
28     fun(Foo(), Bar(), Baz()).shouldThrow!UnitTestException;
29 }
30 
31 
32 @("nodefaults.int")
33 @safe pure unittest {
34 
35     static struct Foo { string value; }
36     static struct Bar { string value; }
37     static struct Baz { string value; }
38 
39     static size_t funImpl(in Foo foo, in Bar bar, in Baz baz) {
40         return foo.value.length + bar.value.length + baz.value.length;
41     }
42 
43     alias fun = kwargify!funImpl;
44 
45     fun(Foo("foo"), Bar("bar"), Baz("baz")).should == 9;
46     fun(Bar("bar"), Foo("foo"), Baz("quux")).should == 10;
47     fun(Baz(), Bar(), Foo()).should == 0;
48 }
49 
50 
51 @("defaults")
52 @safe pure unittest {
53 
54     static struct Foo { string value; }
55     static struct Bar { string value; }
56     static struct Baz { string value; }
57 
58     static size_t funImpl(in Foo foo, in Bar bar = Bar("lebar"), in Baz baz = Baz("lebaz")) {
59         return foo.value.length + bar.value.length + baz.value.length;
60     }
61 
62     alias fun = kwargify!funImpl;
63 
64     fun(Foo()).should == 10;
65     fun(Bar("b"), Foo("fo")).should == 8;
66     fun(Bar("b"), Baz("ba"), Foo("foo")).should == 6;
67 
68     static assert(!__traits(compiles, fun()));
69     static assert(!__traits(compiles, fun(Bar())));
70     static assert(!__traits(compiles, fun(Foo(), 3)));
71     static assert(!__traits(compiles, fun(Foo(), Bar(), Bar())));
72 }
73 
74 
75 @("unique")
76 @safe pure unittest {
77     // won't allow wrapping a function with repeated types
78 
79     static void fun(string, string) {}
80 
81     static assert(!__traits(compiles, kwargify!fun));
82 }
83 
84 
85 @("nocopy")
86 @safe pure unittest {
87 
88     static struct Foo {
89         int[1024] ints;
90         @disable this(this);
91     }
92 
93     void funImpl(Foo foo) {}
94     funImpl(Foo());
95 
96     alias fun = kwargify!funImpl;
97 
98     fun(Foo());
99 }