1 module boilerplate;
2 
3 public import boilerplate.accessors;
4 
5 public import boilerplate.autostring;
6 
7 public import boilerplate.conditions;
8 
9 public import boilerplate.constructor;
10 
11 enum GenerateAll = GenerateThis ~ GenerateToString ~ GenerateFieldAccessors ~ GenerateInvariants;
12 
13 @("can use all four generators at once")
14 unittest
15 {
16     import core.exception : AssertError;
17     import std.conv : to;
18     import unit_threaded.should : shouldEqual, shouldThrow;
19 
20     class Class
21     {
22         @ConstRead @Write @NonInit
23         int i_;
24 
25         mixin(GenerateAll);
26     }
27 
28     auto obj = new Class(5);
29 
30     obj.i.shouldEqual(5);
31     obj.to!string.shouldEqual("Class(i=5)");
32     obj.i(0).shouldThrow!AssertError;
33 }
34 
35 // regression test for workaround for https://issues.dlang.org/show_bug.cgi?id=19731
36 @("accessor on field in struct with invariant and constructor")
37 unittest
38 {
39     import core.exception : AssertError;
40     import unit_threaded.should : shouldThrow;
41 
42     struct Struct
43     {
44         @NonNull
45         @ConstRead
46         Object constObject_;
47 
48         @NonNull
49         @Read
50         Object object_;
51 
52         mixin(GenerateAll);
53     }
54 
55     Struct().constObject.shouldThrow!AssertError;
56     Struct().object.shouldThrow!AssertError;
57 }
58 
59 @("field with reserved name")
60 unittest
61 {
62     struct Struct
63     {
64         int version_;
65 
66         mixin(GenerateAll);
67     }
68 
69     with (Struct.Builder())
70     {
71         version_ = 5;
72 
73         assert(value.version_ == 5);
74     }
75 }
76 
77 @("class with no members")
78 unittest
79 {
80     static class Class
81     {
82         mixin(GenerateAll);
83     }
84 
85     auto instance = Class.Builder().value;
86 }