1 module tests.pass.normal;
2 
3 import unit_threaded;
4 
5 @name("testEqual") unittest
6 {
7     1.shouldEqual(1);
8     shouldEqual(1.0, 1.0);
9     "foo".shouldEqual("foo");
10 }
11 
12 @name("testNotEqual") unittest
13 {
14     3.shouldNotEqual(4);
15     shouldNotEqual(5.0, 6.0);
16     "foo".shouldNotEqual("bar");
17 }
18 
19 
20 private class MyException: Exception
21 {
22     this()
23     {
24         super("MyException");
25     }
26 }
27 
28 @name("testThrown") unittest
29 {
30     void throwFunc()
31     {
32         throw new MyException;
33     }
34 
35     throwFunc.shouldThrow!MyException;
36 }
37 
38 @name("testNotThrown") unittest
39 {
40     void nothrowFunc() nothrow
41     {
42     }
43 
44     nothrowFunc.shouldNotThrow;
45 }
46 
47 @name("first_unit_test")
48 unittest
49 {
50     writelnUt("First unit test block\n");
51     assert(true); //unit test block that always passes
52 }
53 
54 @name("second_unit_test")
55 unittest
56 {
57     writelnUt("Second unit test block\n");
58     assert(true); //unit test block that always passes
59 }
60 
61 
62 private class MyClass
63 {
64     int i;
65     double d;
66     this(int i, double d)
67     {
68         this.i = i;
69         this.d = d;
70     }
71     override string toString() const
72     {
73         import std.conv;
74         return text("MyClass(", i, ", ", d, ")");
75     }
76 }
77 
78 @name("testEqualClass") unittest
79 {
80     const foo = new MyClass(2, 3.0);
81     const bar = new MyClass(2, 3.0);
82     const baz = new MyClass(3, 3.0);
83 
84     foo.shouldEqual(bar);
85     bar.shouldEqual(foo);
86     foo.shouldNotEqual(baz);
87     bar.shouldNotEqual(baz);
88     baz.shouldNotEqual(foo);
89     baz.shouldNotEqual(bar);
90 }
91 
92 
93 private struct Pair
94 {
95     string s;
96     int i;
97 }
98 
99 @name("testPairAA") unittest
100 {
101     auto map = [Pair("foo", 5): 105];
102     [Pair("foo", 5): 105].shouldEqual(map);
103     map.dup.shouldEqual(map);
104     auto pair = Pair("foo", 5);
105     auto othermap = [pair: 105];
106     map.shouldEqual(othermap);
107 }
108 
109 @name("range") unittest
110 {
111     import std.range: iota;
112     iota(3).shouldEqual([0, 1, 2]);
113 }