-
-
Notifications
You must be signed in to change notification settings - Fork 611
Closed
Labels
Description
Consider the following examples:
expect([1,2,3,4]).to(equal([1,2,3,4,5]))
// produces "expected to equal <[1, 2, 3, 4, 5]>, got <[1, 2, 3, 4]>"It is kinda readable, but the thing is that in my experience arrays could contain long strings and / or enums with associated values, and it makes it impossible to understand what actually went wrong.
In this particular case failure message could be "expected array to have 5 elements, but got 4".
Another case:
expect([1,2,3,4]).to(equal([1,4,3,4])
// produces "expected to equal <[1, 4, 3, 4]>, got <[1, 2, 3, 4]>"Which is again, readable but only if we operate with short values.
In this case message could be "expected to have "4" at index 1, got "2"".
Of course, one could resort to per-element comparison, but it does not feel right (or, maybe I'm just overthinking, please let me know)
guard array.count == 3 else {
fail("blabla")
}// we need to make sure that we don't overflow in per-index comparison
expect(array[0]) == x
expect(array[1]) == y
expect(array[2]) == zExact messages text could be reconsidered, but I hope you get the idea.