1 module unit_threaded.ut.issues; 2 3 import unit_threaded; 4 5 6 interface ICalcView { 7 @property string total() @safe pure; 8 @property void total(string t) @safe pure; 9 } 10 11 class CalcController { 12 private ICalcView view; 13 14 this(ICalcView view) @safe pure { 15 this.view = view; 16 } 17 18 void onClick(int number) @safe pure { 19 import std.conv: to; 20 view.total = number.to!string; 21 } 22 } 23 24 25 @("54") 26 @safe pure unittest { 27 auto m = mock!ICalcView; 28 m.expect!"total"("42"); 29 30 auto ctrl = new CalcController(m); 31 ctrl.onClick(42); 32 33 m.verify; 34 } 35 36 37 @("82") 38 @safe unittest { 39 40 import std.exception: assertThrown; 41 42 static class A { 43 string x; 44 45 override string toString() const { 46 return x; 47 } 48 } 49 50 class B : A {} 51 52 auto actual = new B; 53 auto expected = new B; 54 55 actual.x = "foo"; 56 expected.x = "bar"; 57 58 assertThrown(actual.shouldEqual(expected)); 59 } 60 61 62 @("124") 63 @safe pure unittest { 64 static struct Array { 65 66 alias opSlice this; 67 68 private int[] ints; 69 70 bool opCast(T)() const if(is(T == bool)) { 71 return ints.length != 0; 72 } 73 74 inout(int)[] opSlice() inout { 75 return ints; 76 } 77 } 78 79 { 80 auto arr = Array([1, 2, 3]); 81 arr.shouldEqual([1, 2, 3]); 82 } 83 84 { 85 const arr = Array([1, 2, 3]); 86 arr.shouldEqual([1, 2, 3]); 87 } 88 89 }