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

Add tests for sf::String #2466

Merged
merged 3 commits into from
Apr 4, 2023
Merged

Conversation

ChrisThrasher
Copy link
Member

Description

These tests don't bother covering all edge or corner case behavior. Their intent is to test all the simple cases of sf::String and lay the groundwork for more sophisticated tests which may come later. I'm not experienced with wide strings or UTF-32 strings so I'm not even sure how to tackle testing the more complicated uses.

Copy link
Member

@Bromeon Bromeon left a comment

Choose a reason for hiding this comment

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

Great work, thanks a lot!

I think the tests may benefit from using some actual wide-char or UTF-32 characters where applicable, so we don't just have ASCII. See https://stackoverflow.com/q/6796157 for string literals 🙂

test/System/String.test.cpp Outdated Show resolved Hide resolved
test/System/String.test.cpp Outdated Show resolved Hide resolved
@ChrisThrasher
Copy link
Member Author

ChrisThrasher commented Mar 23, 2023

I wonder why there's no code coverage comment on this PR

EDIT: It's working now

@codecov
Copy link

codecov bot commented Mar 25, 2023

Codecov Report

Merging #2466 (e9963d3) into master (741fe21) will increase coverage by 1.32%.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2466      +/-   ##
==========================================
+ Coverage   22.72%   24.04%   +1.32%     
==========================================
  Files         226      226              
  Lines       19388    19409      +21     
  Branches     4705     4714       +9     
==========================================
+ Hits         4406     4667     +261     
+ Misses      14469    14240     -229     
+ Partials      513      502      -11     
Impacted Files Coverage Δ
include/SFML/System/String.hpp 100.00% <ø> (ø)
include/SFML/System/Utf.inl 80.72% <ø> (+44.01%) ⬆️
src/SFML/System/String.cpp 99.50% <ø> (+85.00%) ⬆️

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 741fe21...e9963d3. Read the comment docs.

@ChrisThrasher
Copy link
Member Author

ChrisThrasher commented Mar 25, 2023

Oh joy. It appears that many of the tests fail on Windows. Is this a bug in my tests or is this simply the reality of the implementation-defined behavior of wide strings? Is it a locale issue? If we're dealing with implementation-defined behavior then I'm not sure whether we can test most of these things to any meaningful degree.

@ChrisThrasher
Copy link
Member Author

ChrisThrasher commented Mar 29, 2023

I think I found a satisfactory way to handle the fact that wide string encoding different on a per-platform basis. I'm using the width of a wchar_t as a proxy for which encoding its using. Then I have this function that lets us specify both potential return values for a function and the correct one will get returned.

 // Return either argument depending on whether wchar_t is 16 or 32 bits
// Lets us write tests that work on both Windows where wchar_t is 16 bits
// and elsewhere where it is 32. Otherwise the tests would only work on
// one OS or the other.
template <typename T>
T select(const T& t16, const T& t32)
{
    assert(t16 != t32);
    if constexpr (sizeof(wchar_t) == 2)
        return t16;
    else
        return t32;
}

A better function name probably exists but I kept it simple to begin with.

@ChrisThrasher
Copy link
Member Author

I had to make sf::String::InvalidPos not constexpr to fix some MinGW linker errors. Not sure why MinGW doesn't agree with every other implementation but it's a small price to pay. Reminds me of the woes we had with the sf::Vector constants that we couldn't make constexpr.

@ChrisThrasher ChrisThrasher force-pushed the test_string branch 11 times, most recently from fe10093 to 0e29e98 Compare March 29, 2023 06:24
@ChrisThrasher
Copy link
Member Author

I think it's all good now

@ChrisThrasher ChrisThrasher force-pushed the test_string branch 2 times, most recently from 3bdf737 to 47a8124 Compare April 1, 2023 22:38
Copy link
Member

@eXpl0it3r eXpl0it3r left a comment

Choose a reason for hiding this comment

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

Some minor questions and I think we should "document" getSize when clearing, erasing or adding.

test/System/String.test.cpp Show resolved Hide resolved
test/System/String.test.cpp Show resolved Hide resolved
test/System/String.test.cpp Show resolved Hide resolved
@ChrisThrasher
Copy link
Member Author

ChrisThrasher commented Apr 3, 2023

I believe I addressed all the comments

This fails to link on MinGW. Until that can be resolved we can go
back to a normal constant. Because this is just an integer it doesn't
matter all that much whether it's const or constexpr.
Dates back to 2009 when 78247bd was written. I'm going to assume
the situation has improved in the last 14 years. There are SFML
users who weren't even alive in 2009...
@ChrisThrasher
Copy link
Member Author

ChrisThrasher commented Apr 3, 2023

I added more comments to clarify what's going on with these doctest::StringMaker specializations

@ChrisThrasher ChrisThrasher merged commit ebe4b3c into SFML:master Apr 4, 2023
@ChrisThrasher ChrisThrasher deleted the test_string branch April 4, 2023 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants