Skip to content

Conversation

@vbreuss
Copy link
Contributor

@vbreuss vbreuss commented Sep 10, 2023

Refactor the StringValidator to favor composition over inheritance (see this comment):
Instead of subclassing the abstract StringValidator class, this class now accepts an interface IStringMismatchValidator which provides the necessary implementation details.
If this PR is merged, it should simplify implementing #2050.

IMPORTANT

  • If the PR touches the public API, the changes have been approved in a separate issue with the "api-approved" label.
  • The code complies with the Coding Guidelines for C#.
  • The changes are covered by unit tests which follow the Arrange-Act-Assert syntax and the naming conventions such as is used in these tests.
  • If the PR adds a feature or fixes a bug, please update the release notes with a functional description that explains what the change means to consumers of this library, which are published on the website.
  • If the PR changes the public API the changes needs to be included by running AcceptApiChanges.ps1 or AcceptApiChanges.sh.
  • If the PR affects the documentation, please include your changes in this pull request so the documentation will appear on the website.
    • Please also run ./build.sh --target spellcheck or .\build.ps1 --target spellcheck before pushing and check the good outcome

@vbreuss vbreuss marked this pull request as ready for review September 10, 2023 14:33
@github-actions
Copy link

github-actions bot commented Sep 10, 2023

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 changed the title refactor: avoid inheritance in StringValidator Refactor StringValidator to avoid inheritance Sep 11, 2023
@IT-VBFK
Copy link
Contributor

IT-VBFK commented Sep 13, 2023

Something to rethink either: I think it is odd to have a StringStartStrategy and a seperate NegatedStringStartStrategy but do not have this pattern in the other ...Strategys.

What about aligning them either use into Xxx and NegatedXxx files or handle it like the StringWildcardStrategy?

If we agree to the latter: Should then Negated and IgnoreCase go into the contract IStringComparisonStrategy?

@vbreuss
Copy link
Contributor Author

vbreuss commented Sep 14, 2023

Something to rethink either: I think it is odd to have a StringStartStrategy and a seperate NegatedStringStartStrategy but do not have this pattern in the other ...Strategys.

What about aligning them either use into Xxx and NegatedXxx files or handle it like the StringWildcardStrategy?

If we agree to the latter: Should then Negated and IgnoreCase go into the contract IStringComparisonStrategy?

The StringStartStrategy and NegatedStringStartStrategy are implemented very differently and differ in the explicit failure messages for different scenarios.
I don't think it a good idea to also change the behavior as part of a "refactor"-PR and would rather adapt this in a separate pull request.

@dennisdoomen
Copy link
Member

I believe that enough work is done and there's no need to increase the scope. Moreover, the involved classes are all internal and thus easy to change later on

@dennisdoomen dennisdoomen requested a review from jnyrup September 14, 2023 19:47
Copy link
Member

@jnyrup jnyrup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's some nice untangling of this unnecessary class hierarchy 🧹

@dennisdoomen dennisdoomen merged commit bb50da5 into fluentassertions:develop Sep 16, 2023
@vbreuss vbreuss deleted the topic/refactor-string-validator branch September 16, 2023 17:56
cmeeren pushed a commit to cmeeren/fluentassertions that referenced this pull request Sep 18, 2023
vbreuss added a commit to vbreuss/fluentassertions that referenced this pull request Jan 17, 2025
dennisdoomen pushed a commit that referenced this pull request Jan 17, 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)
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants