shouldly
shouldly copied to clipboard
Opposing Behavior for Strings, Case Sensitivity, and Equality vs. Contains
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 dofooShouldBe(bar, StringCompareShould.IgnoreCase); - Using
ShouldContain(), it is case insensitive by default. If you want to not ignore case, you dofoo.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.
- Lean on C# here: By default, all string comparisons (contains or equals) are case sensitive. Shouldly shouldn't deviate in either method, so
- Both of these methods should use the same flagset. Right now they have distinct ones (
StringCompareShouldandCase). Both probably should just useStringCompareShould- 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.