-
Notifications
You must be signed in to change notification settings - Fork 18
Description
User Story
As a developer, I want ranges to be equal if they cover the same data, so that my tests that assert on them will pass if I have built a region covering the right data.
As a developer, I want to see clearly in logging or test assertion failures when a range contains a null character.
Description / Background
We'd like the Range class to be more useable for tests.
Sometimes in a test we might care about whether a range is canonicalised or not (e.g. when testing canonicalisation). It's more common that we want our test to pass if the range covers the right values.
Currently if a range over string values is canonicalised, this adds a null character to the end of the string. This results in misleading output from toString, as you can't see the null character.
Technical Notes / Implementation Details
Tests are currently the only place we check for equality on a Range.
We could add separate comparators for checking the values covered by a range vs the exact fields of the range. We can default to check the values covered by the range (e.g. by comparing the canonicalised versions of the ranges).
AssertJ also has an option to compare field by field:
We can adjust the toString method to render a null character more explicitly.
We'll need to find any tests that rely on checking by the exact fields of the range. For example, the tests for canonicalising a range will need to be updated to use the correct comparator.
We have a draft PR with an example of how you could compare by the values covered by the range: