fluent-asserts
fluent-asserts copied to clipboard
opEquals() is not honoured with 0.14 alpha 8
with Version 0.14.0.alpha8 opEquals()
is not honoured anymore when asserting equality. It worked prior version 0.14. See the following MWE:
import std.stdio;
import fluent.asserts;
void main() {}
class Thing {
int x;
this(int x) { this.x = x; }
override bool opEquals(Object o) {
if(typeid(this) != typeid(o)) return false;
alias a = this;
auto b = cast(typeof(this)) o;
return a.x == b.x;
}
}
unittest {
auto a1 = new Thing(1);
auto b1 = new Thing(1);
auto a2 = new Thing(2);
assert(a1 == b1); // works
assert(a1 != a2); // works
a1.should.equal(b1); // a1 should equal Thing(132421593017436). Thing(132421593017402) is not equal to Thing(132421593017436)
a1.should.not.equal(a2); // works
}
It's interesting that you have all of these edge cases... I guess you have some complex tests. Those asserts are fixed now on 0.14.0.alpha9
Please let me know how it works for you.
Thanks for your quick response. I still have to test the new release in the "big" project, but for now, it seems I still have some edge cases up my sleeve https://gitlab.com/Skruppy/csg-fitter/-/jobs/1601647959 , sorry :smile:. Some of the assertion fails are from my project not fully ported to the newest dmd release, but some unfortunately are probably still fluent assers problems.
I'm super sorry, but I found an other edge case. With alpha.9, the upper examples works, but by changing the variables to arrays it will fail again:
assert([a1] == [b1]); // works
assert([a1] != [a2]); // works
[a1].should.equal([b1]); // [a1] should equal [Thing(132599446648072)]
[a1].should.not.equal([a2]); // works
No worries! Unfortunately, I don't have much time for developing this library, so thanks for finding those use cases. Comparing object using opEqual is enabled just for the equal
operation. I will reserve some time to do it for the others as well... maybe next weekend. I hope you don't need those right away.