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

summaryrefslogtreecommitdiffhomepage
path: root/projects/SelfTest/IntrospectiveTests/String.tests.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2018-02-28 22:05:01 +0100
committerMartin Hořeňovský2018-02-28 22:49:00 +0100
commit05cd05743a75caeffbd6ad4c675ac68bc8e270f1 (patch)
tree8594799067c81c6efd0beabbb087cd9930143392 /projects/SelfTest/IntrospectiveTests/String.tests.cpp
parent950ccf4749dc3324543c0cba44f85ff81dd300af (diff)
downloadcatch3-05cd05743a75caeffbd6ad4c675ac68bc8e270f1.tar.gz
Provide a public method to get StringRef's underlying pointer
This allows reducing the amount of friends needed for its interface and some extra tricks later. The bad part is that the pointer can become invalidated via calls to other StringRef's public methods, but c'est la vie.
Diffstat (limited to 'projects/SelfTest/IntrospectiveTests/String.tests.cpp')
-rw-r--r--projects/SelfTest/IntrospectiveTests/String.tests.cpp17
1 files changed, 5 insertions, 12 deletions
diff --git a/projects/SelfTest/IntrospectiveTests/String.tests.cpp b/projects/SelfTest/IntrospectiveTests/String.tests.cpp
index 59f73b11..ee6e4c58 100644
--- a/projects/SelfTest/IntrospectiveTests/String.tests.cpp
+++ b/projects/SelfTest/IntrospectiveTests/String.tests.cpp
@@ -14,9 +14,6 @@ namespace Catch {
static auto isSubstring( StringRef const& stringRef ) -> bool {
return stringRef.isSubstring();
}
- static auto data( StringRef const& stringRef ) -> char const* {
- return stringRef.data();
- }
};
auto isOwned( StringRef const& stringRef ) -> bool {
@@ -25,14 +22,11 @@ namespace Catch {
auto isSubstring( StringRef const& stringRef ) -> bool {
return StringRefTestAccess::isSubstring( stringRef );
}
- auto data( StringRef const& stringRef ) -> char const* {
- return StringRefTestAccess::data( stringRef );
- }
} // namespace Catch2
namespace Catch {
inline auto toString( Catch::StringRef const& stringRef ) -> std::string {
- return std::string( data( stringRef ), stringRef.size() );
+ return std::string( stringRef.currentData(), stringRef.size() );
}
} // namespace Catch
@@ -53,7 +47,7 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
REQUIRE( s.size() == 5 );
REQUIRE( isSubstring( s ) == false );
- auto rawChars = data( s );
+ auto rawChars = s.currentData();
REQUIRE( std::strcmp( rawChars, "hello" ) == 0 );
SECTION( "c_str() does not cause copy" ) {
@@ -74,7 +68,6 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
REQUIRE( isSubstring( original ) == false );
REQUIRE( isOwned( original ) );
-
}
@@ -92,14 +85,14 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
REQUIRE( isSubstring( ss ) );
REQUIRE( isOwned( ss ) == false );
- auto rawChars = data( ss );
- REQUIRE( rawChars == data( s ) ); // same pointer value
+ auto rawChars = ss.currentData();
+ REQUIRE( rawChars == s.currentData() ); // same pointer value
REQUIRE( ss.c_str() != rawChars );
REQUIRE( isSubstring( ss ) == false );
REQUIRE( isOwned( ss ) );
- REQUIRE( data( ss ) != data( s ) ); // different pointer value
+ REQUIRE( ss.currentData() != s.currentData() ); // different pointer value
}
SECTION( "non-zero-based substring") {