diff options
| author | Martin Hořeňovský | 2026-09-06 23:23:23 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2026-09-11 11:15:58 +0200 |
| commit | 6a5075bf73273ecb83fca61efdfde2fa1a2690bf (patch) | |
| tree | 6b5f8e4a6c02d653caf57b0059bc25d2d5306d2a /tests/SelfTest/IntrospectiveTests/StringManip.tests.cpp | |
| parent | 15db9be53067d66ecd11a7ddd3097d412047130a (diff) | |
| download | catch3-6a5075bf73273ecb83fca61efdfde2fa1a2690bf.tar.gz | |
Use locale-independent toLower
We generally do not even try to pretend to support more than plain ASCII,
because doing unicode in old C++ standards is a pain and a half. For
`toLower`, we used to wrap `std::tolower` with multiple casts to avoid UB,
but calling into it is relatively slow, and it tries to handle different
locales, which could cause unexpected results.
In addition, the new implementation is significantly faster, which helps
speed up the initial process bring up (as comparing tags, and thus test
cases is now faster).
Diffstat (limited to 'tests/SelfTest/IntrospectiveTests/StringManip.tests.cpp')
| -rw-r--r-- | tests/SelfTest/IntrospectiveTests/StringManip.tests.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/StringManip.tests.cpp b/tests/SelfTest/IntrospectiveTests/StringManip.tests.cpp index f30573cc..56d90f24 100644 --- a/tests/SelfTest/IntrospectiveTests/StringManip.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/StringManip.tests.cpp @@ -92,3 +92,35 @@ TEST_CASE("startsWith", "[string-manip]") { CHECK(startsWith(std::string("abc"), 'a')); CHECK(startsWith("def"_catch_sr, 'd')); } + +TEST_CASE( "toLower( char )", "[string-manip]" ) { + using Catch::toLower; + + SECTION( "ASCII letters are lowercased" ) { + CHECK( toLower( 'A' ) == 'a' ); + CHECK( toLower( 'Z' ) == 'z' ); + CHECK( toLower( 'a' ) == 'a' ); + CHECK( toLower( 'z' ) == 'z' ); + } + SECTION( "Chars outside 'A'-'Z' are left alone" ) { + CHECK( toLower( '@' ) == '@' ); + CHECK( toLower( '[' ) == '[' ); + CHECK( toLower( '`' ) == '`' ); + CHECK( toLower( '{' ) == '{' ); + CHECK( toLower( '0' ) == '0' ); + CHECK( toLower( ' ' ) == ' ' ); + CHECK( toLower( '\0' ) == '\0' ); + } + SECTION( "Non-ASCII chars are left alone" ) { + // toLower is deliberately ASCII-only, so that Catch2's handling of + // test names and tags does not depend on the current locale. + CHECK( toLower( static_cast<char>( 0xC4 ) ) == + static_cast<char>( 0xC4 ) ); + CHECK( toLower( static_cast<char>( 0xFF ) ) == + static_cast<char>( 0xFF ) ); + } + SECTION( "Is usable in constant expressions" ) { + STATIC_CHECK( toLower( 'A' ) == 'a' ); + STATIC_CHECK( toLower( '0' ) == '0' ); + } +} |