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

BeLowerCased() results in failing tests with only lower case characters. #1768

Closed
MEmanuelsson opened this issue Jan 7, 2022 · 6 comments · Fixed by #1792
Closed

BeLowerCased() results in failing tests with only lower case characters. #1768

MEmanuelsson opened this issue Jan 7, 2022 · 6 comments · Fixed by #1792

Comments

@MEmanuelsson
Copy link
Contributor

MEmanuelsson commented Jan 7, 2022

Description

Just introduced using BeLowerCased() into one of our tests where we want to assert that a file path is lower case, but the result is not as expected. The response I get from the failing test is as follows:

Expected all characters in carFolderPath to be lower cased, but found "\files\f7f9de7c-90f4-46a3-9ceb-97af53f495e3\carfiles\abc123".

Perhaps the back slash is considered an upper case character in some way?

Complete minimal example reproducing the issue

// Arrange 
var input = @"\test\with\lower\cased\string";

// Assert
input.Should().BeLowerCased();

Expected behavior:

Test to pass

Actual behavior:

Test fails

Versions

Fluentassertions: 6.3.0
.NET 5

@MEmanuelsson MEmanuelsson changed the title BeLowerCased results in failing tests with only lower case characters. BeLowerCased() results in failing tests with only lower case characters. Jan 7, 2022
@dennisdoomen
Copy link
Member

Asserts that all characters in a string are in lower casing.

This is the description of the BeLowerCased method. So although you could debate that it could be smart enough to only check the letters in the string, it doesn't do that.

@MEmanuelsson
Copy link
Contributor Author

OK, yes I would argue that characters that have no upper or lower case definition would be excluded from the algorithm or approved, that's at least how I thought it would work. But if that's not the way it works, then that's not the way it works.

Maybe I'm the first who stumble across this problem but perhaps this can be made clearer in the description of the function, just a thought?

@dennisdoomen
Copy link
Member

Hmm, I see your point. Wondering what @jnyrup thinks about that.

@jnyrup
Copy link
Member

jnyrup commented Jan 9, 2022

I see that we did consider this in #1357 (comment)
The solution is to use NotBeUpperCased instead.

We probably should improve some documentation to stress that detail.

@MEmanuelsson
Copy link
Contributor Author

MEmanuelsson commented Jan 10, 2022

NotBeUpperCased does the trick in this case, however not completely clear by the description of the function that this is how it works.

I thought that anything that for instance had been ToLower:ed would also be asserted as ok by BeLowerCased. So for instance, a silly example:

var test = "ABC123".ToLower();
test.Should().BeLowerCased(); // ==> true

Thanks for pointing me in the right direction regarding NotBeUpperCased

@dennisdoomen
Copy link
Member

Let's keep it open so we update the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants