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