catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Use locale-independent toLower
- Commit
6a5075bf73273ecb83fca61efdfde2fa1a2690bf- Author
- Martin Hořeňovský ·
- Parents
15db9be53067
Changes
src/catch2/internal/catch_string_manip.cpp | 4 - src/catch2/internal/catch_string_manip.hpp | 7 +- tests/SelfTest/Baselines/automake.sw.approved.txt | 1 + .../Baselines/automake.sw.multi.approved.txt | 1 + tests/SelfTest/Baselines/compact.sw.approved.txt | 19 +++- .../Baselines/compact.sw.multi.approved.txt | 19 +++- tests/SelfTest/Baselines/console.std.approved.txt | 4 +- tests/SelfTest/Baselines/console.sw.approved.txt | 105 +++++++++++++++++- .../Baselines/console.sw.multi.approved.txt | 105 +++++++++++++++++- tests/SelfTest/Baselines/junit.sw.approved.txt | 7 +- .../SelfTest/Baselines/junit.sw.multi.approved.txt | 7 +- tests/SelfTest/Baselines/sonarqube.sw.approved.txt | 5 + .../Baselines/sonarqube.sw.multi.approved.txt | 5 + tests/SelfTest/Baselines/tap.sw.approved.txt | 32 +++++- tests/SelfTest/Baselines/tap.sw.multi.approved.txt | 32 +++++- tests/SelfTest/Baselines/teamcity.sw.approved.txt | 2 + .../Baselines/teamcity.sw.multi.approved.txt | 2 + tests/SelfTest/Baselines/xml.sw.approved.txt | 123 ++++++++++++++++++++- tests/SelfTest/Baselines/xml.sw.multi.approved.txt | 123 ++++++++++++++++++++- .../IntrospectiveTests/StringManip.tests.cpp | 32 ++++++ 20 files changed, 612 insertions(+), 23 deletions(-) diff --git a/src/catch2/internal/catch_string_manip.cpp b/src/catch2/internal/catch_string_manip.cpp index 68983787..ac88be2e 100644 --- a/src/catch2/internal/catch_string_manip.cpp +++ b/src/catch2/internal/catch_string_manip.cpp @@ -11,7 +11,6 @@ #include <ostream> #include <cstring> -#include <cctype> #include <vector> namespace Catch { @@ -41,9 +40,6 @@ namespace Catch { toLowerInPlace( lc ); return lc; } - char toLower(char c) { - return static_cast<char>(std::tolower(static_cast<unsigned char>(c))); - } std::string trim( std::string const& str ) { static char const* whitespaceChars = "\n\r\t "; diff --git a/src/catch2/internal/catch_string_manip.hpp b/src/catch2/internal/catch_string_manip.hpp index 4251f83d..ce317c60 100644 --- a/src/catch2/internal/catch_string_manip.hpp +++ b/src/catch2/internal/catch_string_manip.hpp @@ -25,7 +25,12 @@ namespace Catch { bool contains( std::string const& s, std::string const& infix ); void toLowerInPlace( std::string& s ); std::string toLower( std::string const& s ); - char toLower( char c ); + //! ASCII only. + constexpr char toLower( char c ) { + const uint32_t as_number = static_cast<unsigned char>( c ); + const bool isUpper = ( as_number - static_cast<uint32_t>( 'A' ) ) < 26u; + return static_cast<char>( as_number | ( isUpper << 5 ) ); + } //! Returns a new string without whitespace at the start/end std::string trim( std::string const& str ); //! Returns a substring of the original ref without whitespace. Beware lifetimes! diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index a25bc52a..e8f822df 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -438,6 +438,7 @@ b1! :test-result: PASS tags with dots in later positions are not parsed as hidden :test-result: SKIP tests can be skipped dynamically at runtime :test-result: FAIL thrown std::strings are translated +:test-result: PASS toLower( char ) :test-result: PASS toString on const wchar_t const pointer returns the string contents :test-result: PASS toString on const wchar_t pointer returns the string contents :test-result: PASS toString on wchar_t const pointer returns the string contents diff --git a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt index 3f846b7b..738c6faf 100644 --- a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt @@ -427,6 +427,7 @@ :test-result: PASS tags with dots in later positions are not parsed as hidden :test-result: SKIP tests can be skipped dynamically at runtime :test-result: FAIL thrown std::strings are translated +:test-result: PASS toLower( char ) :test-result: PASS toString on const wchar_t const pointer returns the string contents :test-result: PASS toString on const wchar_t pointer returns the string contents :test-result: PASS toString on wchar_t const pointer returns the string contents diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 09c0bc61..643854bc 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -2918,6 +2918,21 @@ Tag.tests.cpp:<line number>: passed: testcase.tags.size() == 1 for: 1 == 1 Tag.tests.cpp:<line number>: passed: testcase.tags[0].original == "magic.tag"_catch_sr for: magic.tag == magic.tag Skip.tests.cpp:<line number>: skipped: Exception.tests.cpp:<line number>: failed: unexpected exception with message: 'Why would you throw a std::string?' +StringManip.tests.cpp:<line number>: passed: toLower( 'A' ) == 'a' for: 'a' == 'a' +StringManip.tests.cpp:<line number>: passed: toLower( 'Z' ) == 'z' for: 'z' == 'z' +StringManip.tests.cpp:<line number>: passed: toLower( 'a' ) == 'a' for: 'a' == 'a' +StringManip.tests.cpp:<line number>: passed: toLower( 'z' ) == 'z' for: 'z' == 'z' +StringManip.tests.cpp:<line number>: passed: toLower( '@' ) == '@' for: '@' == '@' +StringManip.tests.cpp:<line number>: passed: toLower( '[' ) == '[' for: '[' == '[' +StringManip.tests.cpp:<line number>: passed: toLower( '`' ) == '`' for: '`' == '`' +StringManip.tests.cpp:<line number>: passed: toLower( '{' ) == '{' for: '{' == '{' +StringManip.tests.cpp:<line number>: passed: toLower( '0' ) == '0' for: '0' == '0' +StringManip.tests.cpp:<line number>: passed: toLower( ' ' ) == ' ' for: ' ' == ' ' +StringManip.tests.cpp:<line number>: passed: toLower( '\0' ) == '\0' for: 0 == 0 +StringManip.tests.cpp:<line number>: passed: toLower( static_cast<char>( 0x<hex digits> ) ) == static_cast<char>( 0x<hex digits> ) for: '�' == '�' +StringManip.tests.cpp:<line number>: passed: toLower( static_cast<char>( 0x<hex digits> ) ) == static_cast<char>( 0x<hex digits> ) for: '�' == '�' +StringManip.tests.cpp:<line number>: passed: with 1 message: 'toLower( 'A' ) == 'a'' +StringManip.tests.cpp:<line number>: passed: with 1 message: 'toLower( '0' ) == '0'' Misc.tests.cpp:<line number>: passed: result == "\"wide load\"" for: ""wide load"" == ""wide load"" Misc.tests.cpp:<line number>: passed: result == "\"wide load\"" for: ""wide load"" == ""wide load"" Misc.tests.cpp:<line number>: passed: result == "\"wide load\"" for: ""wide load"" == ""wide load"" @@ -3015,7 +3030,7 @@ InternalBenchmark.tests.cpp:<line number>: passed: med == 18. for: 18.0 == 18.0 InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0 Misc.tests.cpp:<line number>: passed: Misc.tests.cpp:<line number>: passed: -test cases: 454 | 334 passed | 96 failed | 6 skipped | 18 failed as expected -assertions: 2423 | 2222 passed | 158 failed | 43 failed as expected +test cases: 455 | 335 passed | 96 failed | 6 skipped | 18 failed as expected +assertions: 2438 | 2237 passed | 158 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt index 5a2a6e03..324ffee2 100644 --- a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt @@ -2907,6 +2907,21 @@ Tag.tests.cpp:<line number>: passed: testcase.tags.size() == 1 for: 1 == 1 Tag.tests.cpp:<line number>: passed: testcase.tags[0].original == "magic.tag"_catch_sr for: magic.tag == magic.tag Skip.tests.cpp:<line number>: skipped: Exception.tests.cpp:<line number>: failed: unexpected exception with message: 'Why would you throw a std::string?' +StringManip.tests.cpp:<line number>: passed: toLower( 'A' ) == 'a' for: 'a' == 'a' +StringManip.tests.cpp:<line number>: passed: toLower( 'Z' ) == 'z' for: 'z' == 'z' +StringManip.tests.cpp:<line number>: passed: toLower( 'a' ) == 'a' for: 'a' == 'a' +StringManip.tests.cpp:<line number>: passed: toLower( 'z' ) == 'z' for: 'z' == 'z' +StringManip.tests.cpp:<line number>: passed: toLower( '@' ) == '@' for: '@' == '@' +StringManip.tests.cpp:<line number>: passed: toLower( '[' ) == '[' for: '[' == '[' +StringManip.tests.cpp:<line number>: passed: toLower( '`' ) == '`' for: '`' == '`' +StringManip.tests.cpp:<line number>: passed: toLower( '{' ) == '{' for: '{' == '{' +StringManip.tests.cpp:<line number>: passed: toLower( '0' ) == '0' for: '0' == '0' +StringManip.tests.cpp:<line number>: passed: toLower( ' ' ) == ' ' for: ' ' == ' ' +StringManip.tests.cpp:<line number>: passed: toLower( '\0' ) == '\0' for: 0 == 0 +StringManip.tests.cpp:<line number>: passed: toLower( static_cast<char>( 0x<hex digits> ) ) == static_cast<char>( 0x<hex digits> ) for: '�' == '�' +StringManip.tests.cpp:<line number>: passed: toLower( static_cast<char>( 0x<hex digits> ) ) == static_cast<char>( 0x<hex digits> ) for: '�' == '�' +StringManip.tests.cpp:<line number>: passed: with 1 message: 'toLower( 'A' ) == 'a'' +StringManip.tests.cpp:<line number>: passed: with 1 message: 'toLower( '0' ) == '0'' Misc.tests.cpp:<line number>: passed: result == "\"wide load\"" for: ""wide load"" == ""wide load"" Misc.tests.cpp:<line number>: passed: result == "\"wide load\"" for: ""wide load"" == ""wide load"" Misc.tests.cpp:<line number>: passed: result == "\"wide load\"" for: ""wide load"" == ""wide load"" @@ -3004,7 +3019,7 @@ InternalBenchmark.tests.cpp:<line number>: passed: med == 18. for: 18.0 == 18.0 InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0 Misc.tests.cpp:<line number>: passed: Misc.tests.cpp:<line number>: passed: -test cases: 454 | 334 passed | 96 failed | 6 skipped | 18 failed as expected -assertions: 2423 | 2222 passed | 158 failed | 43 failed as expected +test cases: 455 | 335 passed | 96 failed | 6 skipped | 18 failed as expected +assertions: 2438 | 2237 passed | 158 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index 344c5b03..f6b88d30 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1743,6 +1743,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 454 | 352 passed | 76 failed | 7 skipped | 19 failed as expected -assertions: 2401 | 2222 passed | 136 failed | 43 failed as expected +test cases: 455 | 353 passed | 76 failed | 7 skipped | 19 failed as expected +assertions: 2416 | 2237 passed | 136 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index f5324947..311dde19 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -19513,6 +19513,107 @@ Exception.tests.cpp:<line number>: FAILED: due to unexpected exception with message: Why would you throw a std::string? +------------------------------------------------------------------------------- +toLower( char ) + ASCII letters are lowercased +------------------------------------------------------------------------------- +StringManip.tests.cpp:<line number> +............................................................................... + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( 'A' ) == 'a' ) +with expansion: + 'a' == 'a' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( 'Z' ) == 'z' ) +with expansion: + 'z' == 'z' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( 'a' ) == 'a' ) +with expansion: + 'a' == 'a' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( 'z' ) == 'z' ) +with expansion: + 'z' == 'z' + +------------------------------------------------------------------------------- +toLower( char ) + Chars outside 'A'-'Z' are left alone +------------------------------------------------------------------------------- +StringManip.tests.cpp:<line number> +............................................................................... + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( '@' ) == '@' ) +with expansion: + '@' == '@' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( '[' ) == '[' ) +with expansion: + '[' == '[' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( '`' ) == '`' ) +with expansion: + '`' == '`' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( '{' ) == '{' ) +with expansion: + '{' == '{' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( '0' ) == '0' ) +with expansion: + '0' == '0' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( ' ' ) == ' ' ) +with expansion: + ' ' == ' ' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( '\0' ) == '\0' ) +with expansion: + 0 == 0 + +------------------------------------------------------------------------------- +toLower( char ) + Non-ASCII chars are left alone +------------------------------------------------------------------------------- +StringManip.tests.cpp:<line number> +............................................................................... + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( static_cast<char>( 0x<hex digits> ) ) == static_cast<char>( 0x<hex digits> ) ) +with expansion: + '�' == '�' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( static_cast<char>( 0x<hex digits> ) ) == static_cast<char>( 0x<hex digits> ) ) +with expansion: + 'm' == 'm' + +------------------------------------------------------------------------------- +toLower( char ) + Is usable in constant expressions +------------------------------------------------------------------------------- +StringManip.tests.cpp:<line number> +............................................................................... + +StringManip.tests.cpp:<line number>: PASSED: +with message: + toLower( 'A' ) == 'a' + +StringManip.tests.cpp:<line number>: PASSED: +with message: + toLower( '0' ) == '0' + ------------------------------------------------------------------------------- toString on const wchar_t const pointer returns the string contents ------------------------------------------------------------------------------- @@ -20226,6 +20327,6 @@ Misc.tests.cpp:<line number> Misc.tests.cpp:<line number>: PASSED: =============================================================================== -test cases: 454 | 334 passed | 96 failed | 6 skipped | 18 failed as expected -assertions: 2423 | 2222 passed | 158 failed | 43 failed as expected +test cases: 455 | 335 passed | 96 failed | 6 skipped | 18 failed as expected +assertions: 2438 | 2237 passed | 158 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.multi.approved.txt b/tests/SelfTest/Baselines/console.sw.multi.approved.txt index 9dba6123..6ddafb08 100644 --- a/tests/SelfTest/Baselines/console.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.multi.approved.txt @@ -19502,6 +19502,107 @@ Exception.tests.cpp:<line number>: FAILED: due to unexpected exception with message: Why would you throw a std::string? +------------------------------------------------------------------------------- +toLower( char ) + ASCII letters are lowercased +------------------------------------------------------------------------------- +StringManip.tests.cpp:<line number> +............................................................................... + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( 'A' ) == 'a' ) +with expansion: + 'a' == 'a' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( 'Z' ) == 'z' ) +with expansion: + 'z' == 'z' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( 'a' ) == 'a' ) +with expansion: + 'a' == 'a' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( 'z' ) == 'z' ) +with expansion: + 'z' == 'z' + +------------------------------------------------------------------------------- +toLower( char ) + Chars outside 'A'-'Z' are left alone +------------------------------------------------------------------------------- +StringManip.tests.cpp:<line number> +............................................................................... + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( '@' ) == '@' ) +with expansion: + '@' == '@' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( '[' ) == '[' ) +with expansion: + '[' == '[' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( '`' ) == '`' ) +with expansion: + '`' == '`' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( '{' ) == '{' ) +with expansion: + '{' == '{' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( '0' ) == '0' ) +with expansion: + '0' == '0' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( ' ' ) == ' ' ) +with expansion: + ' ' == ' ' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( '\0' ) == '\0' ) +with expansion: + 0 == 0 + +------------------------------------------------------------------------------- +toLower( char ) + Non-ASCII chars are left alone +------------------------------------------------------------------------------- +StringManip.tests.cpp:<line number> +............................................................................... + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( static_cast<char>( 0x<hex digits> ) ) == static_cast<char>( 0x<hex digits> ) ) +with expansion: + '�' == '�' + +StringManip.tests.cpp:<line number>: PASSED: + CHECK( toLower( static_cast<char>( 0x<hex digits> ) ) == static_cast<char>( 0x<hex digits> ) ) +with expansion: + 'm' == 'm' + +------------------------------------------------------------------------------- +toLower( char ) + Is usable in constant expressions +------------------------------------------------------------------------------- +StringManip.tests.cpp:<line number> +............................................................................... + +StringManip.tests.cpp:<line number>: PASSED: +with message: + toLower( 'A' ) == 'a' + +StringManip.tests.cpp:<line number>: PASSED: +with message: + toLower( '0' ) == '0' + ------------------------------------------------------------------------------- toString on const wchar_t const pointer returns the string contents ------------------------------------------------------------------------------- @@ -20215,6 +20316,6 @@ Misc.tests.cpp:<line number> Misc.tests.cpp:<line number>: PASSED: =============================================================================== -test cases: 454 | 334 passed | 96 failed | 6 skipped | 18 failed as expected -assertions: 2423 | 2222 passed | 158 failed | 43 failed as expected +test cases: 455 | 335 passed | 96 failed | 6 skipped | 18 failed as expected +assertions: 2438 | 2237 passed | 158 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index f58412b6..967646c6 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <testsuitesloose text artifact > - <testsuite name="<exe-name>" errors="17" failures="141" skipped="12" tests="2435" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> + <testsuite name="<exe-name>" errors="17" failures="141" skipped="12" tests="2450" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <properties> <property name="random-seed" value="1"/> <property name="filters" value=""*" ~[!nonportable] ~[!benchmark] ~[approvals]"/> @@ -1885,6 +1885,11 @@ Why would you throw a std::string? at Exception.tests.cpp:<line number> </error> </testcase> + <testcase classname="<exe-name>.global" name="toLower( char )" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="toLower( char )/ASCII letters are lowercased" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="toLower( char )/Chars outside 'A'-'Z' are left alone" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="toLower( char )/Non-ASCII chars are left alone" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="toLower( char )/Is usable in constant expressions" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="toString on const wchar_t const pointer returns the string contents" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="toString on const wchar_t pointer returns the string contents" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="toString on wchar_t const pointer returns the string contents" time="{duration}" status="run"/> diff --git a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt index c80e5855..291df00e 100644 --- a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <testsuites> - <testsuite name="<exe-name>" errors="17" failures="141" skipped="12" tests="2435" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> + <testsuite name="<exe-name>" errors="17" failures="141" skipped="12" tests="2450" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <properties> <property name="random-seed" value="1"/> <property name="filters" value=""*" ~[!nonportable] ~[!benchmark] ~[approvals]"/> @@ -1884,6 +1884,11 @@ Why would you throw a std::string? at Exception.tests.cpp:<line number> </error> </testcase> + <testcase classname="<exe-name>.global" name="toLower( char )" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="toLower( char )/ASCII letters are lowercased" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="toLower( char )/Chars outside 'A'-'Z' are left alone" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="toLower( char )/Non-ASCII chars are left alone" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="toLower( char )/Is usable in constant expressions" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="toString on const wchar_t const pointer returns the string contents" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="toString on const wchar_t pointer returns the string contents" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="toString on wchar_t const pointer returns the string contents" time="{duration}" status="run"/> diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index 17c26f36..9beaed2c 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -400,6 +400,11 @@ at AssertionHandler.tests.cpp:<line number> <testCase name="replaceInPlace/escape '" duration="{duration}"/> <testCase name="splitString" duration="{duration}"/> <testCase name="startsWith" duration="{duration}"/> + <testCase name="toLower( char )" duration="{duration}"/> + <testCase name="toLower( char )/ASCII letters are lowercased" duration="{duration}"/> + <testCase name="toLower( char )/Chars outside 'A'-'Z' are left alone" duration="{duration}"/> + <testCase name="toLower( char )/Non-ASCII chars are left alone" duration="{duration}"/> + <testCase name="toLower( char )/Is usable in constant expressions" duration="{duration}"/> </file> <file path="tests/<exe-name>/IntrospectiveTests/Tag.tests.cpp"> <testCase name="Tag alias can be registered against tag patterns" duration="{duration}"/> diff --git a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt index 4c113189..25194b72 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt @@ -399,6 +399,11 @@ at AssertionHandler.tests.cpp:<line number> <testCase name="replaceInPlace/escape '" duration="{duration}"/> <testCase name="splitString" duration="{duration}"/> <testCase name="startsWith" duration="{duration}"/> + <testCase name="toLower( char )" duration="{duration}"/> + <testCase name="toLower( char )/ASCII letters are lowercased" duration="{duration}"/> + <testCase name="toLower( char )/Chars outside 'A'-'Z' are left alone" duration="{duration}"/> + <testCase name="toLower( char )/Non-ASCII chars are left alone" duration="{duration}"/> + <testCase name="toLower( char )/Is usable in constant expressions" duration="{duration}"/> </file> <file path="tests/<exe-name>/IntrospectiveTests/Tag.tests.cpp"> <testCase name="Tag alias can be registered against tag patterns" duration="{duration}"/> diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 6fa5949e..84482410 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -4691,6 +4691,36 @@ ok {test-number} - testcase.tags[0].original == "magic.tag"_catch_sr for: magic. ok {test-number} - # SKIP # thrown std::strings are translated not ok {test-number} - unexpected exception with message: 'Why would you throw a std::string?' +# toLower( char ) +ok {test-number} - toLower( 'A' ) == 'a' for: 'a' == 'a' +# toLower( char ) +ok {test-number} - toLower( 'Z' ) == 'z' for: 'z' == 'z' +# toLower( char ) +ok {test-number} - toLower( 'a' ) == 'a' for: 'a' == 'a' +# toLower( char ) +ok {test-number} - toLower( 'z' ) == 'z' for: 'z' == 'z' +# toLower( char ) +ok {test-number} - toLower( '@' ) == '@' for: '@' == '@' +# toLower( char ) +ok {test-number} - toLower( '[' ) == '[' for: '[' == '[' +# toLower( char ) +ok {test-number} - toLower( '`' ) == '`' for: '`' == '`' +# toLower( char ) +ok {test-number} - toLower( '{' ) == '{' for: '{' == '{' +# toLower( char ) +ok {test-number} - toLower( '0' ) == '0' for: '0' == '0' +# toLower( char ) +ok {test-number} - toLower( ' ' ) == ' ' for: ' ' == ' ' +# toLower( char ) +ok {test-number} - toLower( '\0' ) == '\0' for: 0 == 0 +# toLower( char ) +ok {test-number} - toLower( static_cast<char>( 0x<hex digits> ) ) == static_cast<char>( 0x<hex digits> ) for: '�' == '�' +# toLower( char ) +ok {test-number} - toLower( static_cast<char>( 0x<hex digits> ) ) == static_cast<char>( 0x<hex digits> ) for: '�' == '�' +# toLower( char ) +ok {test-number} - with 1 message: 'toLower( 'A' ) == 'a'' +# toLower( char ) +ok {test-number} - with 1 message: 'toLower( '0' ) == '0'' # toString on const wchar_t const pointer returns the string contents ok {test-number} - result == "\"wide load\"" for: ""wide load"" == ""wide load"" # toString on const wchar_t pointer returns the string contents @@ -4865,5 +4895,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2435 +1..2450 diff --git a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt index 0a7d381a..bdfa3bf5 100644 --- a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt @@ -4680,6 +4680,36 @@ ok {test-number} - testcase.tags[0].original == "magic.tag"_catch_sr for: magic. ok {test-number} - # SKIP # thrown std::strings are translated not ok {test-number} - unexpected exception with message: 'Why would you throw a std::string?' +# toLower( char ) +ok {test-number} - toLower( 'A' ) == 'a' for: 'a' == 'a' +# toLower( char ) +ok {test-number} - toLower( 'Z' ) == 'z' for: 'z' == 'z' +# toLower( char ) +ok {test-number} - toLower( 'a' ) == 'a' for: 'a' == 'a' +# toLower( char ) +ok {test-number} - toLower( 'z' ) == 'z' for: 'z' == 'z' +# toLower( char ) +ok {test-number} - toLower( '@' ) == '@' for: '@' == '@' +# toLower( char ) +ok {test-number} - toLower( '[' ) == '[' for: '[' == '[' +# toLower( char ) +ok {test-number} - toLower( '`' ) == '`' for: '`' == '`' +# toLower( char ) +ok {test-number} - toLower( '{' ) == '{' for: '{' == '{' +# toLower( char ) +ok {test-number} - toLower( '0' ) == '0' for: '0' == '0' +# toLower( char ) +ok {test-number} - toLower( ' ' ) == ' ' for: ' ' == ' ' +# toLower( char ) +ok {test-number} - toLower( '\0' ) == '\0' for: 0 == 0 +# toLower( char ) +ok {test-number} - toLower( static_cast<char>( 0x<hex digits> ) ) == static_cast<char>( 0x<hex digits> ) for: '�' == '�' +# toLower( char ) +ok {test-number} - toLower( static_cast<char>( 0x<hex digits> ) ) == static_cast<char>( 0x<hex digits> ) for: '�' == '�' +# toLower( char ) +ok {test-number} - with 1 message: 'toLower( 'A' ) == 'a'' +# toLower( char ) +ok {test-number} - with 1 message: 'toLower( '0' ) == '0'' # toString on const wchar_t const pointer returns the string contents ok {test-number} - result == "\"wide load\"" for: ""wide load"" == ""wide load"" # toString on const wchar_t pointer returns the string contents @@ -4854,5 +4884,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2435 +1..2450 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index 16fe73f9..9768478b 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -1055,6 +1055,8 @@ loose text artifact ##teamcity[testStarted name='thrown std::strings are translated'] ##teamcity[testFailed name='thrown std::strings are translated' message='Exception.tests.cpp:<line number>|n...............................................................................|n|nException.tests.cpp:<line number>|nunexpected exception with message:|n "Why would you throw a std::string?"'] ##teamcity[testFinished name='thrown std::strings are translated' duration="{duration}"] +##teamcity[testStarted name='toLower( char )'] +##teamcity[testFinished name='toLower( char )' duration="{duration}"] ##teamcity[testStarted name='toString on const wchar_t const pointer returns the string contents'] ##teamcity[testFinished name='toString on const wchar_t const pointer returns the string contents' duration="{duration}"] ##teamcity[testStarted name='toString on const wchar_t pointer returns the string contents'] diff --git a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt index acc777f2..a0b1754c 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt @@ -1054,6 +1054,8 @@ ##teamcity[testStarted name='thrown std::strings are translated'] ##teamcity[testFailed name='thrown std::strings are translated' message='Exception.tests.cpp:<line number>|n...............................................................................|n|nException.tests.cpp:<line number>|nunexpected exception with message:|n "Why would you throw a std::string?"'] ##teamcity[testFinished name='thrown std::strings are translated' duration="{duration}"] +##teamcity[testStarted name='toLower( char )'] +##teamcity[testFinished name='toLower( char )' duration="{duration}"] ##teamcity[testStarted name='toString on const wchar_t const pointer returns the string contents'] ##teamcity[testFinished name='toString on const wchar_t const pointer returns the string contents' duration="{duration}"] ##teamcity[testStarted name='toString on const wchar_t pointer returns the string contents'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index 81df5a53..50527e7c 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -22663,6 +22663,125 @@ Approx( -1.95996398454005449 ) </Exception> <OverallResult success="false" skips="0"/> </TestCase> + <TestCase name="toLower( char )" tags="[string-manip]" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Section name="ASCII letters are lowercased" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( 'A' ) == 'a' + </Original> + <Expanded> + 'a' == 'a' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( 'Z' ) == 'z' + </Original> + <Expanded> + 'z' == 'z' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( 'a' ) == 'a' + </Original> + <Expanded> + 'a' == 'a' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( 'z' ) == 'z' + </Original> + <Expanded> + 'z' == 'z' + </Expanded> + </Expression> + <OverallResults successes="4" failures="0" expectedFailures="0" skipped="false"/> + </Section> + <Section name="Chars outside 'A'-'Z' are left alone" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( '@' ) == '@' + </Original> + <Expanded> + '@' == '@' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( '[' ) == '[' + </Original> + <Expanded> + '[' == '[' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( '`' ) == '`' + </Original> + <Expanded> + '`' == '`' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( '{' ) == '{' + </Original> + <Expanded> + '{' == '{' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( '0' ) == '0' + </Original> + <Expanded> + '0' == '0' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( ' ' ) == ' ' + </Original> + <Expanded> + ' ' == ' ' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( '\0' ) == '\0' + </Original> + <Expanded> + 0 == 0 + </Expanded> + </Expression> + <OverallResults successes="7" failures="0" expectedFailures="0" skipped="false"/> + </Section> + <Section name="Non-ASCII chars are left alone" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( static_cast<char>( 0x<hex digits> ) ) == static_cast<char>( 0x<hex digits> ) + </Original> + <Expanded> + '\xC4' == '\xC4' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( static_cast<char>( 0x<hex digits> ) ) == static_cast<char>( 0x<hex digits> ) + </Original> + <Expanded> + '\xFF' == '\xFF' + </Expanded> + </Expression> + <OverallResults successes="2" failures="0" expectedFailures="0" skipped="false"/> + </Section> + <Section name="Is usable in constant expressions" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <OverallResults successes="2" failures="0" expectedFailures="0" skipped="false"/> + </Section> + <OverallResult success="true" skips="0"/> + </TestCase> <TestCase name="toString on const wchar_t const pointer returns the string contents" tags="[toString]" filename="tests/<exe-name>/UsageTests/Misc.tests.cpp" > <Expression success="true" type="CHECK" filename="tests/<exe-name>/UsageTests/Misc.tests.cpp" > <Original> @@ -23476,6 +23595,6 @@ Approx( -1.95996398454005449 ) </Section> <OverallResult success="true" skips="0"/> </TestCase> - <OverallResults successes="2222" failures="158" expectedFailures="43" skips="12"/> - <OverallResultsCases successes="334" failures="96" expectedFailures="18" skips="6"/> + <OverallResults successes="2237" failures="158" expectedFailures="43" skips="12"/> + <OverallResultsCases successes="335" failures="96" expectedFailures="18" skips="6"/> </Catch2TestRun> diff --git a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt index 5888529c..4b7234a4 100644 --- a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt @@ -22662,6 +22662,125 @@ Approx( -1.95996398454005449 ) </Exception> <OverallResult success="false" skips="0"/> </TestCase> + <TestCase name="toLower( char )" tags="[string-manip]" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Section name="ASCII letters are lowercased" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( 'A' ) == 'a' + </Original> + <Expanded> + 'a' == 'a' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( 'Z' ) == 'z' + </Original> + <Expanded> + 'z' == 'z' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( 'a' ) == 'a' + </Original> + <Expanded> + 'a' == 'a' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( 'z' ) == 'z' + </Original> + <Expanded> + 'z' == 'z' + </Expanded> + </Expression> + <OverallResults successes="4" failures="0" expectedFailures="0" skipped="false"/> + </Section> + <Section name="Chars outside 'A'-'Z' are left alone" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( '@' ) == '@' + </Original> + <Expanded> + '@' == '@' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( '[' ) == '[' + </Original> + <Expanded> + '[' == '[' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( '`' ) == '`' + </Original> + <Expanded> + '`' == '`' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( '{' ) == '{' + </Original> + <Expanded> + '{' == '{' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( '0' ) == '0' + </Original> + <Expanded> + '0' == '0' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( ' ' ) == ' ' + </Original> + <Expanded> + ' ' == ' ' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( '\0' ) == '\0' + </Original> + <Expanded> + 0 == 0 + </Expanded> + </Expression> + <OverallResults successes="7" failures="0" expectedFailures="0" skipped="false"/> + </Section> + <Section name="Non-ASCII chars are left alone" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( static_cast<char>( 0x<hex digits> ) ) == static_cast<char>( 0x<hex digits> ) + </Original> + <Expanded> + '\xC4' == '\xC4' + </Expanded> + </Expression> + <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + toLower( static_cast<char>( 0x<hex digits> ) ) == static_cast<char>( 0x<hex digits> ) + </Original> + <Expanded> + '\xFF' == '\xFF' + </Expanded> + </Expression> + <OverallResults successes="2" failures="0" expectedFailures="0" skipped="false"/> + </Section> + <Section name="Is usable in constant expressions" filename="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <OverallResults successes="2" failures="0" expectedFailures="0" skipped="false"/> + </Section> + <OverallResult success="true" skips="0"/> + </TestCase> <TestCase name="toString on const wchar_t const pointer returns the string contents" tags="[toString]" filename="tests/<exe-name>/UsageTests/Misc.tests.cpp" > <Expression success="true" type="CHECK" filename="tests/<exe-name>/UsageTests/Misc.tests.cpp" > <Original> @@ -23475,6 +23594,6 @@ Approx( -1.95996398454005449 ) </Section> <OverallResult success="true" skips="0"/> </TestCase> - <OverallResults successes="2222" failures="158" expectedFailures="43" skips="12"/> - <OverallResultsCases successes="334" failures="96" expectedFailures="18" skips="6"/> + <OverallResults successes="2237" failures="158" expectedFailures="43" skips="12"/> + <OverallResultsCases successes="335" failures="96" expectedFailures="18" skips="6"/> </Catch2TestRun> 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' ); + } +}