Skip to content

Commit

Permalink
Add documentation for IComparer<T> overload (#2220)
Browse files Browse the repository at this point in the history
Add documentation for culture aware string comparison
  • Loading branch information
ITaluone committed Jun 13, 2023
1 parent c6f94ea commit 343e80f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/_pages/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ collection.Should().NotBeInAscendingOrder();
collection.Should().NotBeInDescendingOrder();
```

Since **6.9.0** there is a slight change in how culture is taken into comparison. Now by default `StringComparer.Ordinal` is used to compare strings.
If you want to overrule this behavior use the `IComparer<T>` overload. The use case is e.g. if you get data from a database ordered by culture aware sort order.

```csharp
collection.Should().BeInAscendingOrder(item => item.SomeProp, StringComparer.CurrentCulture);
collection.Should().BeInDescendingOrder(item => item.SomeProp, StringComparer.CurrentCulture);
collection.Should().NotBeInAscendingOrder(item => item.SomeProp, StringComparer.CurrentCulture);
collection.Should().NotBeInDescendingOrder(item => item.SomeProp, StringComparer.CurrentCulture);
```

For `String` collections there are specific methods to assert the items. For the `ContainMatch` and `NotContainMatch` methods we support wildcards.

The pattern can be a combination of literal and wildcard characters, but it doesn't support regular expressions.
Expand Down

0 comments on commit 343e80f

Please sign in to comment.