Faithlife / FaithlifeTesting

Helpers for unit testing
https://faithlife.github.io/FaithlifeTesting
MIT License
2 stars 9 forks source link

Extend `==` operator in expressions to use NUnit's `Assert.AreEqual` semantics for collections #7

Open michael-sterling opened 3 years ago

michael-sterling commented 3 years ago

https://docs.nunit.org/articles/nunit/writing-tests/assertions/classic-assertions/Assert.AreEqual.html

NUnit is able to compare single-dimensioned arrays, multi-dimensioned arrays, nested arrays (arrays of arrays) and collections. Two arrays or collections are considered equal if they have the same dimensions and if each pair of corresponding elements is equal.

michael-sterling commented 3 years ago

OK, this is turning out to be a lot less trivial than I anticipated. Gonna punt on this for now, though I still very much want it.

NUnit code which handles this: https://github.com/nunit/nunit/blob/master/src/NUnitFramework/framework/Constraints/EqualConstraint.cs

In addition to the definition of equality, I would hope to be able to take advantage of NUnit's "here's how they are different" analysis. Perhaps each equality failure gets some context describing why it failed?

I think the V1 of this feature at least wants to: (1) Take advantage of the EqualConstraint directly rather than re-implementing it, and (2) modify the GetDebugExpresssion logic in the DebugValueExpressionVisitor to some sort of "replacement expression" or "display expression" notion, rewriting the expression tree to use the new defintion of equality when compiled but output the old operator when displayed.