Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xunit: define codefixes for StringAsserts #145

Closed
10 tasks done
Tracked by #130
Meir017 opened this issue Jan 11, 2022 · 2 comments
Closed
10 tasks done
Tracked by #130

xunit: define codefixes for StringAsserts #145

Meir017 opened this issue Jan 11, 2022 · 2 comments

Comments

@Meir017
Copy link
Member

Meir017 commented Jan 11, 2022

The asserts defined in https://github.com/xunit/assert.xunit/blob/main/StringAsserts.cs

@Meir017
Copy link
Member Author

Meir017 commented Oct 10, 2023

@jnyrup / @dennisdoomen any idea about an equivalent for using StringComparison in fluentassertions? it's not exposed anywhere as an argument.

From what I was able to tell there are the following:

for Assert.Equal:

  • .Should().Be for StringComparison.Ordinal
  • .Should().BeEquivalentTo for StringComparison.OrdinalIgnoreCase

for Assert.Contains:

  • .Should().Contain for StringComparison.Ordinal
  • .Should().ContainEquivalentOf for StringComparison.OrdinalIgnoreCase

for Assert.NotContains:

  • .Should().NotContain for StringComparison.Ordinal
  • .Should().NotContainEquivalentOf for StringComparison.OrdinalIgnoreCase

for Assert.EndsWith:

  • .Should().EndWith for StringComparison.Ordinal
  • .Should().EndWithEquivalentOf for StringComparison.OrdinalIgnoreCase

for Assert.StartsWith:

  • .Should().StartWith for StringComparison.Ordinal
  • .Should().StartWithEquivalentOf for StringComparison.OrdinalIgnoreCase

so for constant values of using explicitly StringComparison.Ordinal and StringComparison.OrdinalIgnoreCase we should be able to hint at the correct usage.

What about

  • StringComparison.CurrentCulture
  • StringComparison.CurrentCultureIgnoreCase
  • StringComparison.InvariantCulture
  • StringComparison.InvariantCultureIgnoreCase

should each of these suggest to use StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase?

@jnyrup
Copy link
Member

jnyrup commented Oct 11, 2023

There's no idiomatic way to pass a StringComparison to the string assertions.

There are ugly ways

"someString".Should().Match(e => string.Equals(e, "SoMeStRiNg", StringComparison.OrdinalIgnoreCase));
"someString".As<object>().Should().Be("SoMeStRiNg", StringComparer.OrdinalIgnoreCase);

Note that in v6 the Equivalent APIs besides casing also ignore leading and trailing whitespace.

For v7 we're currently having discussing on how to improve on this
fluentassertions/fluentassertions#2339
fluentassertions/fluentassertions#2364

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

No branches or pull requests

2 participants