You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/fluentasserts/operations/equality/equal.d
+38Lines changed: 38 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -969,3 +969,41 @@ class EqualThing {
969
969
returnthis.x == b.x;
970
970
}
971
971
}
972
+
973
+
classThing {
974
+
int x;
975
+
this(int x) {
976
+
this.x = x;
977
+
}
978
+
979
+
override boolopEquals(Object o) {
980
+
if (typeid(this) !=typeid(o)) {
981
+
returnfalse;
982
+
}
983
+
auto b = cast(typeof(this)) o;
984
+
returnthis.x == b.x;
985
+
}
986
+
}
987
+
988
+
@("opEquals honored for class objects with same field value")
989
+
unittest {
990
+
auto a1 = new Thing(1);
991
+
auto b1 = new Thing(1);
992
+
993
+
assert(a1 == b1, "D's == operator should use opEquals");
994
+
995
+
auto evaluation = ({
996
+
a1.should.equal(b1);
997
+
}).recordEvaluation;
998
+
999
+
assert(evaluation.result.expected.length ==0, "opEquals should return true for objects with same x value, but got expected: "~ evaluation.result.expected[]);
1000
+
}
1001
+
1002
+
@("opEquals honored for class objects with different field values")
1003
+
unittest {
1004
+
auto a1 = new Thing(1);
1005
+
auto a2 = new Thing(2);
1006
+
1007
+
assert(a1 != a2, "D's != operator should use opEquals");
0 commit comments