Use std::string_view

This commit is contained in:
Chris Thrasher
2025-09-21 18:05:21 -06:00
parent a5735af2f7
commit 8efee9b763
119 changed files with 913 additions and 3430 deletions

View File

@@ -4157,17 +4157,17 @@ ToString.tests.cpp:<line number>
ToString.tests.cpp:<line number>: PASSED:
CHECK( enumInfo->lookup(0) == "Value1" )
with expansion:
Value1 == "Value1"
"Value1" == "Value1"
ToString.tests.cpp:<line number>: PASSED:
CHECK( enumInfo->lookup(1) == "Value2" )
with expansion:
Value2 == "Value2"
"Value2" == "Value2"
ToString.tests.cpp:<line number>: PASSED:
CHECK( enumInfo->lookup(3) == "{** unexpected enum value **}" )
with expansion:
{** unexpected enum value **}
"{** unexpected enum value **}"
==
"{** unexpected enum value **}"
@@ -11458,419 +11458,6 @@ with expansion:
"this string contains 'abc' as a substring" ends with: " substring" (case
insensitive)
-------------------------------------------------------------------------------
StringRef
Empty string
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( empty.empty() )
with expansion:
true
String.tests.cpp:<line number>: PASSED:
REQUIRE( empty.size() == 0 )
with expansion:
0 == 0
String.tests.cpp:<line number>: PASSED:
REQUIRE( std::strcmp( empty.data(), "" ) == 0 )
with expansion:
0 == 0
-------------------------------------------------------------------------------
StringRef
From string literal
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( s.empty() == false )
with expansion:
false == false
String.tests.cpp:<line number>: PASSED:
REQUIRE( s.size() == 5 )
with expansion:
5 == 5
String.tests.cpp:<line number>: PASSED:
REQUIRE( std::strcmp( rawChars, "hello" ) == 0 )
with expansion:
0 == 0
String.tests.cpp:<line number>: PASSED:
REQUIRE( s.data() == rawChars )
with expansion:
"hello" == "hello"
-------------------------------------------------------------------------------
StringRef
From sub-string
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( original == "original" )
String.tests.cpp:<line number>: PASSED:
REQUIRE_NOTHROW( original.data() )
-------------------------------------------------------------------------------
StringRef
Copy construction is shallow
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( original.begin() == copy.begin() )
with expansion:
"original string" == "original string"
-------------------------------------------------------------------------------
StringRef
Copy assignment is shallow
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( original.begin() == copy.begin() )
with expansion:
"original string" == "original string"
-------------------------------------------------------------------------------
StringRef
Substrings
zero-based substring
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( ss.empty() == false )
with expansion:
false == false
String.tests.cpp:<line number>: PASSED:
REQUIRE( ss.size() == 5 )
with expansion:
5 == 5
String.tests.cpp:<line number>: PASSED:
REQUIRE( std::strncmp( ss.data(), "hello", 5 ) == 0 )
with expansion:
0 == 0
String.tests.cpp:<line number>: PASSED:
REQUIRE( ss == "hello" )
with expansion:
hello == "hello"
-------------------------------------------------------------------------------
StringRef
Substrings
non-zero-based substring
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( ss.size() == 6 )
with expansion:
6 == 6
String.tests.cpp:<line number>: PASSED:
REQUIRE( std::strcmp( ss.data(), "world!" ) == 0 )
with expansion:
0 == 0
-------------------------------------------------------------------------------
StringRef
Substrings
Pointer values of full refs should match
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( s.data() == s2.data() )
with expansion:
"hello world!" == "hello world!"
-------------------------------------------------------------------------------
StringRef
Substrings
Pointer values of substring refs should also match
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( s.data() == ss.data() )
with expansion:
"hello world!" == "hello world!"
-------------------------------------------------------------------------------
StringRef
Substrings
Past the end substring
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( s.substr(s.size() + 1, 123).empty() )
with expansion:
true
-------------------------------------------------------------------------------
StringRef
Substrings
Substring off the end are trimmed
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( std::strcmp(ss.data(), "world!") == 0 )
with expansion:
0 == 0
-------------------------------------------------------------------------------
StringRef
Substrings
substring start after the end is empty
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( s.substr(1'000'000, 1).empty() )
with expansion:
true
-------------------------------------------------------------------------------
StringRef
Comparisons are deep
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
CHECK( reinterpret_cast<char*>(buffer1) != reinterpret_cast<char*>(buffer2) )
with expansion:
"Hello" != "Hello"
String.tests.cpp:<line number>: PASSED:
REQUIRE( left == right )
with expansion:
Hello == Hello
String.tests.cpp:<line number>: PASSED:
REQUIRE( left != left.substr(0, 3) )
with expansion:
Hello != Hel
-------------------------------------------------------------------------------
StringRef
from std::string
implicitly constructed
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( sr == "a standard string" )
with expansion:
a standard string == "a standard string"
String.tests.cpp:<line number>: PASSED:
REQUIRE( sr.size() == stdStr.size() )
with expansion:
17 == 17
-------------------------------------------------------------------------------
StringRef
from std::string
explicitly constructed
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( sr == "a standard string" )
with expansion:
a standard string == "a standard string"
String.tests.cpp:<line number>: PASSED:
REQUIRE( sr.size() == stdStr.size() )
with expansion:
17 == 17
-------------------------------------------------------------------------------
StringRef
from std::string
assigned
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( sr == "a standard string" )
with expansion:
a standard string == "a standard string"
String.tests.cpp:<line number>: PASSED:
REQUIRE( sr.size() == stdStr.size() )
with expansion:
17 == 17
-------------------------------------------------------------------------------
StringRef
to std::string
explicitly constructed
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( stdStr == "a stringref" )
with expansion:
"a stringref" == "a stringref"
String.tests.cpp:<line number>: PASSED:
REQUIRE( stdStr.size() == sr.size() )
with expansion:
11 == 11
-------------------------------------------------------------------------------
StringRef
to std::string
assigned
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( stdStr == "a stringref" )
with expansion:
"a stringref" == "a stringref"
String.tests.cpp:<line number>: PASSED:
REQUIRE( stdStr.size() == sr.size() )
with expansion:
11 == 11
-------------------------------------------------------------------------------
StringRef
std::string += StringRef
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( lhs == "some string += the stringref contents" )
with expansion:
"some string += the stringref contents"
==
"some string += the stringref contents"
-------------------------------------------------------------------------------
StringRef
StringRef + StringRef
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( together == "abrakadabra" )
with expansion:
"abrakadabra" == "abrakadabra"
-------------------------------------------------------------------------------
StringRef at compilation time
Simple constructors
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
with message:
empty.size() == 0
String.tests.cpp:<line number>: PASSED:
with message:
empty.begin() == empty.end()
String.tests.cpp:<line number>: PASSED:
with message:
stringref.size() == 3
String.tests.cpp:<line number>: PASSED:
with message:
stringref.data() == abc
String.tests.cpp:<line number>: PASSED:
with message:
stringref.begin() == abc
String.tests.cpp:<line number>: PASSED:
with message:
stringref.begin() != stringref.end()
String.tests.cpp:<line number>: PASSED:
with message:
stringref.substr(10, 0).empty()
String.tests.cpp:<line number>: PASSED:
with message:
stringref.substr(2, 1).data() == abc + 2
String.tests.cpp:<line number>: PASSED:
with message:
stringref[1] == 'b'
String.tests.cpp:<line number>: PASSED:
with message:
shortened.size() == 2
String.tests.cpp:<line number>: PASSED:
with message:
shortened.data() == abc
String.tests.cpp:<line number>: PASSED:
with message:
shortened.begin() != shortened.end()
-------------------------------------------------------------------------------
StringRef at compilation time
UDL construction
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
with message:
!(sr1.empty())
String.tests.cpp:<line number>: PASSED:
with message:
sr1.size() == 3
String.tests.cpp:<line number>: PASSED:
with message:
sr2.empty()
String.tests.cpp:<line number>: PASSED:
with message:
sr2.size() == 0
-------------------------------------------------------------------------------
Stringifying char arrays with statically known sizes - char
-------------------------------------------------------------------------------
@@ -12058,7 +11645,7 @@ with expansion:
2 == 2
Tag.tests.cpp:<line number>: PASSED:
REQUIRE_THAT( testCase.tags, VectorContains( Tag( "tag with spaces" ) ) && VectorContains( Tag( "I said \"good day\" sir!"_catch_sr ) ) )
REQUIRE_THAT( testCase.tags, VectorContains( Tag( "tag with spaces" ) ) && VectorContains( Tag( "I said \"good day\" sir!" ) ) )
with expansion:
{ {?}, {?} } ( Contains: {?} and Contains: {?} )
@@ -14085,32 +13672,32 @@ with expansion:
"There is no extra whitespace here"
StringManip.tests.cpp:<line number>: PASSED:
REQUIRE( trim(StringRef(no_whitespace)) == StringRef(no_whitespace) )
REQUIRE( trim(std::string_view(no_whitespace)) == std::string_view(no_whitespace) )
with expansion:
There is no extra whitespace here
"There is no extra whitespace here"
==
There is no extra whitespace here
"There is no extra whitespace here"
StringManip.tests.cpp:<line number>: PASSED:
REQUIRE( trim(StringRef(leading_whitespace)) == StringRef(no_whitespace) )
REQUIRE( trim(std::string_view(leading_whitespace)) == std::string_view(no_whitespace) )
with expansion:
There is no extra whitespace here
"There is no extra whitespace here"
==
There is no extra whitespace here
"There is no extra whitespace here"
StringManip.tests.cpp:<line number>: PASSED:
REQUIRE( trim(StringRef(trailing_whitespace)) == StringRef(no_whitespace) )
REQUIRE( trim(std::string_view(trailing_whitespace)) == std::string_view(no_whitespace) )
with expansion:
There is no extra whitespace here
"There is no extra whitespace here"
==
There is no extra whitespace here
"There is no extra whitespace here"
StringManip.tests.cpp:<line number>: PASSED:
REQUIRE( trim(StringRef(whitespace_at_both_ends)) == StringRef(no_whitespace) )
REQUIRE( trim(std::string_view(whitespace_at_both_ends)) == std::string_view(no_whitespace) )
with expansion:
There is no extra whitespace here
"There is no extra whitespace here"
==
There is no extra whitespace here
"There is no extra whitespace here"
-------------------------------------------------------------------------------
Type conversions of RangeEquals and similar
@@ -17569,7 +17156,7 @@ ToString.tests.cpp:<line number>
...............................................................................
ToString.tests.cpp:<line number>: PASSED:
CHECK_THAT( parseEnums( "" ), Equals( std::vector<Catch::StringRef>{} ) )
CHECK_THAT( parseEnums( "" ), Equals( std::vector<std::string_view>{} ) )
with expansion:
{ } Equals: { }
@@ -17581,19 +17168,19 @@ ToString.tests.cpp:<line number>
...............................................................................
ToString.tests.cpp:<line number>: PASSED:
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1" ), Equals(std::vector<Catch::StringRef>{"Value1"} ) )
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1" ), Equals(std::vector<std::string_view>{"Value1"} ) )
with expansion:
{ Value1 } Equals: { Value1 }
{ "Value1" } Equals: { "Value1" }
ToString.tests.cpp:<line number>: PASSED:
CHECK_THAT( parseEnums( "Value1" ), Equals( std::vector<Catch::StringRef>{"Value1"} ) )
CHECK_THAT( parseEnums( "Value1" ), Equals( std::vector<std::string_view>{"Value1"} ) )
with expansion:
{ Value1 } Equals: { Value1 }
{ "Value1" } Equals: { "Value1" }
ToString.tests.cpp:<line number>: PASSED:
CHECK_THAT( parseEnums( "EnumName::Value1" ), Equals(std::vector<Catch::StringRef>{"Value1"} ) )
CHECK_THAT( parseEnums( "EnumName::Value1" ), Equals(std::vector<std::string_view>{"Value1"} ) )
with expansion:
{ Value1 } Equals: { Value1 }
{ "Value1" } Equals: { "Value1" }
-------------------------------------------------------------------------------
parseEnums
@@ -17603,19 +17190,19 @@ ToString.tests.cpp:<line number>
...............................................................................
ToString.tests.cpp:<line number>: PASSED:
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1, ClassName::EnumName::Value2" ), Equals( std::vector<Catch::StringRef>{"Value1", "Value2"} ) )
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1, ClassName::EnumName::Value2" ), Equals( std::vector<std::string_view>{"Value1", "Value2"} ) )
with expansion:
{ Value1, Value2 } Equals: { Value1, Value2 }
{ "Value1", "Value2" } Equals: { "Value1", "Value2" }
ToString.tests.cpp:<line number>: PASSED:
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1, ClassName::EnumName::Value2, ClassName::EnumName::Value3" ), Equals( std::vector<Catch::StringRef>{"Value1", "Value2", "Value3"} ) )
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1, ClassName::EnumName::Value2, ClassName::EnumName::Value3" ), Equals( std::vector<std::string_view>{"Value1", "Value2", "Value3"} ) )
with expansion:
{ Value1, Value2, Value3 } Equals: { Value1, Value2, Value3 }
{ "Value1", "Value2", "Value3" } Equals: { "Value1", "Value2", "Value3" }
ToString.tests.cpp:<line number>: PASSED:
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1,ClassName::EnumName::Value2 , ClassName::EnumName::Value3" ), Equals( std::vector<Catch::StringRef>{"Value1", "Value2", "Value3"} ) )
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1,ClassName::EnumName::Value2 , ClassName::EnumName::Value3" ), Equals( std::vector<std::string_view>{"Value1", "Value2", "Value3"} ) )
with expansion:
{ Value1, Value2, Value3 } Equals: { Value1, Value2, Value3 }
{ "Value1", "Value2", "Value3" } Equals: { "Value1", "Value2", "Value3" }
-------------------------------------------------------------------------------
pointer to class
@@ -18110,7 +17697,7 @@ Tag.tests.cpp:<line number>
...............................................................................
Tag.tests.cpp:<line number>: PASSED:
REQUIRE_THAT( testcase.tags, VectorContains( Tag( "magic-tag" ) ) && VectorContains( Tag( "."_catch_sr ) ) )
REQUIRE_THAT( testcase.tags, VectorContains( Tag( "magic-tag" ) ) && VectorContains( Tag( "." ) ) )
with expansion:
{ {?}, {?} } ( Contains: {?} and Contains: {?} )
@@ -18131,19 +17718,19 @@ StringManip.tests.cpp:<line number>
...............................................................................
StringManip.tests.cpp:<line number>: PASSED:
CHECK_THAT( splitStringRef("", ','), Equals(std::vector<StringRef>()) )
CHECK_THAT( splitStringRef("", ','), Equals(std::vector<std::string_view>()) )
with expansion:
{ } Equals: { }
StringManip.tests.cpp:<line number>: PASSED:
CHECK_THAT( splitStringRef("abc", ','), Equals(std::vector<StringRef>{"abc"}) )
CHECK_THAT( splitStringRef("abc", ','), Equals(std::vector<std::string_view>{"abc"}) )
with expansion:
{ abc } Equals: { abc }
{ "abc" } Equals: { "abc" }
StringManip.tests.cpp:<line number>: PASSED:
CHECK_THAT( splitStringRef("abc,def", ','), Equals(std::vector<StringRef>{"abc", "def"}) )
CHECK_THAT( splitStringRef("abc,def", ','), Equals(std::vector<std::string_view>{"abc", "def"}) )
with expansion:
{ abc, def } Equals: { abc, def }
{ "abc", "def" } Equals: { "abc", "def" }
-------------------------------------------------------------------------------
stacks unscoped info in loops
@@ -18184,7 +17771,7 @@ with expansion:
true
StringManip.tests.cpp:<line number>: PASSED:
CHECK( startsWith("def"_catch_sr, 'd') )
CHECK( startsWith("def", 'd') )
with expansion:
true
@@ -18560,9 +18147,9 @@ with expansion:
1 == 1
Tag.tests.cpp:<line number>: PASSED:
REQUIRE( testcase.tags[0].original == "magic.tag"_catch_sr )
REQUIRE( testcase.tags[0].original == "magic.tag" )
with expansion:
magic.tag == magic.tag
"magic.tag" == "magic.tag"
-------------------------------------------------------------------------------
tests can be skipped dynamically at runtime
@@ -19295,6 +18882,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:
===============================================================================
test cases: 435 | 317 passed | 95 failed | 6 skipped | 17 failed as expected
assertions: 2303 | 2105 passed | 157 failed | 41 failed as expected
test cases: 433 | 315 passed | 95 failed | 6 skipped | 17 failed as expected
assertions: 2250 | 2052 passed | 157 failed | 41 failed as expected