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

summaryrefslogtreecommitdiffhomepage
path: root/tests/SelfTest/IntrospectiveTests/String.tests.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2021-03-25 20:02:47 +0100
committerMartin Hořeňovský2021-03-26 21:11:44 +0100
commitf1d7a10e06f0f26d02e86c340d93a482b2c50e17 (patch)
tree392c56310e6ff1015b6b4ad29bc9fd3405023795 /tests/SelfTest/IntrospectiveTests/String.tests.cpp
parente50e10ef8f06dbeac8f92daffc9344bb7621daf1 (diff)
downloadcatch3-f1d7a10e06f0f26d02e86c340d93a482b2c50e17.tar.gz
Remove StringRef::isNullTerminated and StringRef::c_str
Both of them were fundamentally unsafe to use and shouldn't be used at all.
Diffstat (limited to 'tests/SelfTest/IntrospectiveTests/String.tests.cpp')
-rw-r--r--tests/SelfTest/IntrospectiveTests/String.tests.cpp17
1 files changed, 3 insertions, 14 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/String.tests.cpp b/tests/SelfTest/IntrospectiveTests/String.tests.cpp
index dbc8190b..4b9cc0e3 100644
--- a/tests/SelfTest/IntrospectiveTests/String.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/String.tests.cpp
@@ -10,29 +10,23 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
StringRef empty;
REQUIRE( empty.empty() );
REQUIRE( empty.size() == 0 );
- REQUIRE( empty.isNullTerminated() );
- REQUIRE( std::strcmp( empty.c_str(), "" ) == 0 );
+ REQUIRE( std::strcmp( empty.data(), "" ) == 0 );
}
SECTION( "From string literal" ) {
StringRef s = "hello";
REQUIRE( s.empty() == false );
REQUIRE( s.size() == 5 );
- REQUIRE( s.isNullTerminated() );
auto rawChars = s.data();
REQUIRE( std::strcmp( rawChars, "hello" ) == 0 );
- REQUIRE_NOTHROW(s.c_str());
- REQUIRE(s.c_str() == rawChars);
REQUIRE(s.data() == rawChars);
}
SECTION( "From sub-string" ) {
StringRef original = StringRef( "original string" ).substr(0, 8);
REQUIRE( original == "original" );
- REQUIRE_FALSE(original.isNullTerminated());
- REQUIRE_THROWS(original.c_str());
REQUIRE_NOTHROW(original.data());
}
@@ -51,7 +45,7 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
SECTION( "non-zero-based substring") {
ss = s.substr( 6, 6 );
REQUIRE( ss.size() == 6 );
- REQUIRE( std::strcmp( ss.c_str(), "world!" ) == 0 );
+ REQUIRE( std::strcmp( ss.data(), "world!" ) == 0 );
}
SECTION( "Pointer values of full refs should match" ) {
@@ -69,7 +63,7 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
SECTION("Substring off the end are trimmed") {
ss = s.substr(6, 123);
- REQUIRE(std::strcmp(ss.c_str(), "world!") == 0);
+ REQUIRE(std::strcmp(ss.data(), "world!") == 0);
}
SECTION("substring start after the end is empty") {
REQUIRE(s.substr(1'000'000, 1).empty());
@@ -147,7 +141,6 @@ TEST_CASE("StringRef at compilation time", "[Strings][StringRef][constexpr]") {
constexpr StringRef stringref(abc, 3);
STATIC_REQUIRE(stringref.size() == 3);
- STATIC_REQUIRE(stringref.isNullTerminated());
STATIC_REQUIRE(stringref.data() == abc);
STATIC_REQUIRE(stringref.begin() == abc);
STATIC_REQUIRE(stringref.begin() != stringref.end());
@@ -160,19 +153,15 @@ TEST_CASE("StringRef at compilation time", "[Strings][StringRef][constexpr]") {
STATIC_REQUIRE(shortened.size() == 2);
STATIC_REQUIRE(shortened.data() == abc);
STATIC_REQUIRE(shortened.begin() != shortened.end());
- STATIC_REQUIRE_FALSE(shortened.isNullTerminated());
- STATIC_REQUIRE_FALSE(shortened.substr(1, 3).isNullTerminated());
}
SECTION("UDL construction") {
constexpr auto sr1 = "abc"_catch_sr;
STATIC_REQUIRE_FALSE(sr1.empty());
STATIC_REQUIRE(sr1.size() == 3);
- STATIC_REQUIRE(sr1.isNullTerminated());
using Catch::operator"" _sr;
constexpr auto sr2 = ""_sr;
STATIC_REQUIRE(sr2.empty());
STATIC_REQUIRE(sr2.size() == 0);
- STATIC_REQUIRE(sr2.isNullTerminated());
}
}