kotest icon indicating copy to clipboard operation
kotest copied to clipboard

Alex/custom matching of fields take0 (#4438)

Open AlexCue987 opened this issue 1 year ago • 0 comments

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
         }
      }

AlexCue987 avatar Oct 15 '24 15:10 AlexCue987