Skip to content

Conversation

@vbreuss
Copy link
Contributor

@vbreuss vbreuss commented Jan 17, 2025

Backport #2307 to v7:

When asserting that two strings are equal, and one of the strings is longer than 8 characters or contains a NewLine, instead of simply stating at which index the first difference occurs, this difference is made visible using arrows, e.g.

var subject = "this is a long text that differs in between";
var expected = "this was too short";
subject.Should().Be(expected, "because we use arrows now");

throws with message

Expected subject to be the same string because we use arrows now, but they differ at index 5:
        ↓ (actual)
  "this is a long text…"
  "this was too short"
        ↑ (expected)."

For multi-line strings, instead of only providing information about the index, the failure message also contains the line and column information, e.g. …but they differ on line 5 and column 1 (index 93):

For short single-line strings the behaviour remains unchanged!


Let's see, how open you are for community commits on v7, or if we should consider it dead...

vbreuss and others added 2 commits January 17, 2025 08:02
…ity (fluentassertions#2307)

* Draft improved failure message when checking for equality.

* Use line and column for multiline strings

* Fix failing tests

* Fix Qodana issues

* Fix further failing tests

* Also fix tests on MacOS (due to different newline)

* Calculate expected index

* Fix paranthesis

* Move specific methods from common StringExtensions to the `StringEqualityStrategy` class

* Fix review comments from @dennisdoomen and add tests for word boundary algorithm

* Improve tests by using [raw string literals](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/strings/#raw-string-literals)

* Update releases.md

* Implement review comments from @jnyrup

* Adapt due to survived mutants

* Adapt test names

---------

Co-authored-by: Valentin Breuß <v.breuss@tig.at>
(cherry picked from commit 6859575)
@coveralls
Copy link

Pull Request Test Coverage Report for Build 12824421774

Details

  • 192 of 194 (98.97%) changed or added relevant lines in 7 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 97.066%

Changes Missing Coverage Covered Lines Changed/Added Lines %
Src/FluentAssertions/Primitives/StringStartStrategy.cs 16 18 88.89%
Totals Coverage Status
Change from base Build 12823618627: 0.02%
Covered Lines: 13018
Relevant Lines: 13276

💛 - Coveralls

@github-actions
Copy link

Qodana for .NET

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

@dennisdoomen dennisdoomen merged commit 39cf1ad into fluentassertions:support-7.0 Jan 17, 2025
5 checks passed
ScarletKuro referenced this pull request in AwesomeAssertions/AwesomeAssertions Jan 18, 2025
… for equality" (#2972)

* Refactor `StringValidator` to avoid inheritance (#2296)

(cherry picked from commit bb50da5)

* Improve failure message for string assertions when checking for equality (#2307)

* Draft improved failure message when checking for equality.

* Use line and column for multiline strings

* Fix failing tests

* Fix Qodana issues

* Fix further failing tests

* Also fix tests on MacOS (due to different newline)

* Calculate expected index

* Fix paranthesis

* Move specific methods from common StringExtensions to the `StringEqualityStrategy` class

* Fix review comments from @dennisdoomen and add tests for word boundary algorithm

* Improve tests by using [raw string literals](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/strings/#raw-string-literals)

* Update releases.md

* Implement review comments from @jnyrup

* Adapt due to survived mutants

* Adapt test names

---------

Co-authored-by: Valentin Breuß <v.breuss@tig.at>
(cherry picked from commit 6859575)
@dennisdoomen dennisdoomen added this to the 7.2.0 milestone Jan 20, 2025
@dennisdoomen dennisdoomen changed the title Backport "Improve failure message for string assertions when checking for equality" Improve failure message for string assertions when checking for equality Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants