shouldly icon indicating copy to clipboard operation
shouldly copied to clipboard

Opposing Behavior for Strings, Case Sensitivity, and Equality vs. Contains

Open sdepouw opened this issue 1 year ago • 0 comments

Been exploring Shouldly lately, thanks to the falling out of FluentAssertions. Pretty simple to change over to!

I do have one discussion point to bring up: Case sensitivity.

  • Using ShouldBe(), it is case sensitive by default. If you want to ignore case, you do fooShouldBe(bar, StringCompareShould.IgnoreCase);
  • Using ShouldContain(), it is case insensitive by default. If you want to not ignore case, you do foo.ShouldContain(bar, Case.Sensitive);

My feedback:

  • The default behavior should be the same for both! Them being opposite is going to lead to strife / "oh right this is backwards" moments.
    • Lean on C# here: By default, all string comparisons (contains or equals) are case sensitive. Shouldly shouldn't deviate in either method, so ShouldContain() should be changed to be case-sensitive by default.
  • Both of these methods should use the same flagset. Right now they have distinct ones (StringCompareShould and Case). Both probably should just use StringCompareShould
    • I would love to also to just be able to use C#'s StringComparison so that it's congruent with string equality checking that most folks are used to. I know we have extra functionality here (with "ignore newline") but supporting the language's built-in functionality is always a plus.

sdepouw avatar Jan 31 '25 11:01 sdepouw