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