mirror of
https://github.com/catchorg/Catch2.git
synced 2025-05-22 20:58:47 +00:00
StringRef conversions to/ from std::string
This commit is contained in:
parent
1aab791d67
commit
c659e0fd3d
3 changed files with 54 additions and 3 deletions
|
@ -150,4 +150,46 @@ TEST_CASE( "StringRef", "[Strings]" ) {
|
|||
REQUIRE( data( copied ) == originalPointer );
|
||||
}
|
||||
}
|
||||
|
||||
SECTION( "from std::string" ) {
|
||||
std::string stdStr = "a standard string";
|
||||
|
||||
SECTION( "implicitly constructed" ) {
|
||||
StringRef sr = stdStr;
|
||||
REQUIRE( sr == "a standard string" );
|
||||
REQUIRE( sr.size() == stdStr.size() );
|
||||
}
|
||||
SECTION( "explicitly constructed" ) {
|
||||
StringRef sr( stdStr );
|
||||
REQUIRE( sr == "a standard string" );
|
||||
REQUIRE( sr.size() == stdStr.size() );
|
||||
}
|
||||
SECTION( "assigned" ) {
|
||||
StringRef sr;
|
||||
sr = stdStr;
|
||||
REQUIRE( sr == "a standard string" );
|
||||
REQUIRE( sr.size() == stdStr.size() );
|
||||
}
|
||||
}
|
||||
|
||||
SECTION( "to std::string" ) {
|
||||
StringRef sr = "a stringref";
|
||||
|
||||
SECTION( "implicitly constructed" ) {
|
||||
std::string stdStr = sr;
|
||||
REQUIRE( stdStr == "a stringref" );
|
||||
REQUIRE( stdStr.size() == sr.size() );
|
||||
}
|
||||
SECTION( "explicitly constructed" ) {
|
||||
std::string stdStr( sr );
|
||||
REQUIRE( stdStr == "a stringref" );
|
||||
REQUIRE( stdStr.size() == sr.size() );
|
||||
}
|
||||
SECTION( "assigned" ) {
|
||||
std::string stdStr;
|
||||
stdStr = sr;
|
||||
REQUIRE( stdStr == "a stringref" );
|
||||
REQUIRE( stdStr.size() == sr.size() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue