Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/projects/SelfTest/StringRef.tests.cpp
diff options
context:
space:
mode:
authorPhil Nash2017-08-14 08:39:14 +0100
committerPhil Nash2017-08-14 08:39:14 +0100
commitc659e0fd3dadd397dfed17e59a624fb693d77646 (patch)
tree32eb94110b2383c3d986e3e8b3d8415d715717ba /projects/SelfTest/StringRef.tests.cpp
parent1aab791d67a8a4072156db22d80c1a863dcdb593 (diff)
downloadcatch3-c659e0fd3dadd397dfed17e59a624fb693d77646.tar.gz
StringRef conversions to/ from std::string
Diffstat (limited to 'projects/SelfTest/StringRef.tests.cpp')
-rw-r--r--projects/SelfTest/StringRef.tests.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/projects/SelfTest/StringRef.tests.cpp b/projects/SelfTest/StringRef.tests.cpp
index 4ebaa878..6ebbdb13 100644
--- a/projects/SelfTest/StringRef.tests.cpp
+++ b/projects/SelfTest/StringRef.tests.cpp
@@ -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() );
+ }
+ }
}