kotest
kotest copied to clipboard
Alex/custom matching of fields take0 (#4438)
extend shouldBeEqualUsingFields, allow custom matching of fields, such as
- case-insensitive String
- numbers/temporals with tolernace
- Lists ignoring order
Example:
"basic example: match name ignoring case" {
val expected = SimpleDataClass("apple", 1.0, LocalDateTime.now())
val actual = expected.copy(name = "Apple")
shouldThrow<AssertionError> {
actual shouldBeEqualUsingFields expected
}.message.shouldContainInOrder(
"Fields that differ:",
"""- name => expected:<"apple"> but was:<"Apple">""",
)
actual shouldBeEqualUsingFields {
overrideMatchers = mapOf(
SimpleDataClass::name to matchStringsIgnoringCase
)
expected
}
}