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

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMartin Hořeňovský2019-10-21 17:44:11 +0200
committerMartin Hořeňovský2019-10-25 13:57:52 +0200
commit50cc14c94c972fc743afca92b22ad7bdc63c429a (patch)
tree6654c82835e7784076b2ecd7b90d374968b5ac26
parent87b745da6625b7469e61de5910978a097caf8b74 (diff)
downloadcatch3-50cc14c94c972fc743afca92b22ad7bdc63c429a.tar.gz
Rework StringRef interface and internals
Now it no longer tries to be this weird hybrid between an owning and non-owning reference, and is only ever non-owning. This is also reflected in its interface, for example `StringRef::isNullTerminated` is now public, and `StringRef::c_str()` has the precondition that it is true. Overview of the changes: * The `StringRef::m_data` member has been completely removed, as it had no more uses. * `StringRef::isSubstring()` has been made public and renamed to `StringRef::isNullTerminated()`, so that the name reflects what the method actually does. * `StringRef::currentData()` has been renamed to `StringRef::data()`, to be in line with common C++ containers and container-alikes. * `StringRef::c_str()` will no longer silently make copies. It instead has a precondition that `isNullTerminated()` is true. * If the user needs a null-terminated string, they should use the `std::string` conversion operator and call `c_str()` on the resulting `std::string`. * Some small optimizations in various places. * Basic functionality is now `constexpr`.
-rw-r--r--include/internal/catch_stringref.cpp60
-rw-r--r--include/internal/catch_stringref.h88
-rw-r--r--projects/SelfTest/Baselines/compact.sw.approved.txt44
-rw-r--r--projects/SelfTest/Baselines/console.std.approved.txt4
-rw-r--r--projects/SelfTest/Baselines/console.sw.approved.txt186
-rw-r--r--projects/SelfTest/Baselines/junit.sw.approved.txt12
-rw-r--r--projects/SelfTest/Baselines/xml.sw.approved.txt213
-rw-r--r--projects/SelfTest/IntrospectiveTests/String.tests.cpp115
8 files changed, 311 insertions, 411 deletions
diff --git a/include/internal/catch_stringref.cpp b/include/internal/catch_stringref.cpp
index b46414ac..215feef3 100644
--- a/include/internal/catch_stringref.cpp
+++ b/include/internal/catch_stringref.cpp
@@ -5,14 +5,10 @@
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
-
-#if defined(__clang__)
-# pragma clang diagnostic push
-# pragma clang diagnostic ignored "-Wexit-time-destructors"
-#endif
-
+#include "catch_enforce.h"
#include "catch_stringref.h"
+#include <algorithm>
#include <ostream>
#include <cstring>
#include <cstdint>
@@ -22,63 +18,33 @@ namespace Catch {
: StringRef( rawChars, static_cast<StringRef::size_type>(std::strlen(rawChars) ) )
{}
- void StringRef::swap( StringRef& other ) noexcept {
- std::swap( m_start, other.m_start );
- std::swap( m_size, other.m_size );
- std::swap( m_data, other.m_data );
- }
-
auto StringRef::c_str() const -> char const* {
- if( !isSubstring() )
- return m_start;
-
- const_cast<StringRef *>( this )->takeOwnership();
- return m_data;
- }
- auto StringRef::currentData() const noexcept -> char const* {
+ CATCH_ENFORCE(isNullTerminated(), "Called StringRef::c_str() on a non-null-terminated instance");
return m_start;
}
-
- auto StringRef::isOwned() const noexcept -> bool {
- return m_data != nullptr;
- }
- auto StringRef::isSubstring() const noexcept -> bool {
- return m_start[m_size] != '\0';
+ auto StringRef::data() const noexcept -> char const* {
+ return m_start;
}
- void StringRef::takeOwnership() {
- if( !isOwned() ) {
- m_data = new char[m_size+1];
- memcpy( m_data, m_start, m_size );
- m_data[m_size] = '\0';
- }
- }
auto StringRef::substr( size_type start, size_type size ) const noexcept -> StringRef {
- if( start < m_size )
- return StringRef( m_start+start, size );
- else
+ if (start < m_size) {
+ return StringRef(m_start + start, (std::min)(m_size - start, size));
+ } else {
return StringRef();
+ }
}
auto StringRef::operator == ( StringRef const& other ) const noexcept -> bool {
- return
- size() == other.size() &&
- (std::strncmp( m_start, other.m_start, size() ) == 0);
- }
- auto StringRef::operator != ( StringRef const& other ) const noexcept -> bool {
- return !operator==( other );
+ return m_size == other.m_size
+ && (std::memcmp( m_start, other.m_start, m_size ) == 0);
}
auto operator << ( std::ostream& os, StringRef const& str ) -> std::ostream& {
- return os.write(str.currentData(), str.size());
+ return os.write(str.data(), str.size());
}
auto operator+=( std::string& lhs, StringRef const& rhs ) -> std::string& {
- lhs.append(rhs.currentData(), rhs.size());
+ lhs.append(rhs.data(), rhs.size());
return lhs;
}
} // namespace Catch
-
-#if defined(__clang__)
-# pragma clang diagnostic pop
-#endif
diff --git a/include/internal/catch_stringref.h b/include/internal/catch_stringref.h
index a45147da..dc2e748c 100644
--- a/include/internal/catch_stringref.h
+++ b/include/internal/catch_stringref.h
@@ -16,49 +16,24 @@ namespace Catch {
/// A non-owning string class (similar to the forthcoming std::string_view)
/// Note that, because a StringRef may be a substring of another string,
- /// it may not be null terminated. c_str() must return a null terminated
- /// string, however, and so the StringRef will internally take ownership
- /// (taking a copy), if necessary. In theory this ownership is not externally
- /// visible - but it does mean (substring) StringRefs should not be shared between
- /// threads.
+ /// it may not be null terminated.
class StringRef {
public:
using size_type = std::size_t;
using const_iterator = const char*;
private:
- friend struct StringRefTestAccess;
-
- char const* m_start;
- size_type m_size;
-
- char* m_data = nullptr;
-
- void takeOwnership();
-
static constexpr char const* const s_empty = "";
- public: // construction/ assignment
- StringRef() noexcept
- : StringRef( s_empty, 0 )
- {}
+ char const* m_start = s_empty;
+ size_type m_size = 0;
- StringRef( StringRef const& other ) noexcept
- : m_start( other.m_start ),
- m_size( other.m_size )
- {}
-
- StringRef( StringRef&& other ) noexcept
- : m_start( other.m_start ),
- m_size( other.m_size ),
- m_data( other.m_data )
- {
- other.m_data = nullptr;
- }
+ public: // construction
+ constexpr StringRef() noexcept = default;
StringRef( char const* rawChars ) noexcept;
- StringRef( char const* rawChars, size_type size ) noexcept
+ constexpr StringRef( char const* rawChars, size_type size ) noexcept
: m_start( rawChars ),
m_size( size )
{}
@@ -68,27 +43,15 @@ namespace Catch {
m_size( stdString.size() )
{}
- ~StringRef() noexcept {
- delete[] m_data;
- }
-
- auto operator = ( StringRef const &other ) noexcept -> StringRef& {
- delete[] m_data;
- m_data = nullptr;
- m_start = other.m_start;
- m_size = other.m_size;
- return *this;
- }
-
explicit operator std::string() const {
return std::string(m_start, m_size);
}
- void swap( StringRef& other ) noexcept;
-
public: // operators
auto operator == ( StringRef const& other ) const noexcept -> bool;
- auto operator != ( StringRef const& other ) const noexcept -> bool;
+ auto operator != (StringRef const& other) const noexcept -> bool {
+ return !(*this == other);
+ }
auto operator[] ( size_type index ) const noexcept -> char {
assert(index < m_size);
@@ -96,42 +59,45 @@ namespace Catch {
}
public: // named queries
- auto empty() const noexcept -> bool {
+ constexpr auto empty() const noexcept -> bool {
return m_size == 0;
}
- auto size() const noexcept -> size_type {
+ constexpr auto size() const noexcept -> size_type {
return m_size;
}
+ // Returns the current start pointer. If the StringRef is not
+ // null-terminated, throws std::domain_exception
auto c_str() const -> char const*;
public: // substrings and searches
- auto substr( size_type start, size_type size ) const noexcept -> StringRef;
+ // Returns a substring of [start, start + length).
+ // If start + length > size(), then the substring is [start, size()).
+ // If start > size(), then the substring is empty.
+ auto substr( size_type start, size_type length ) const noexcept -> StringRef;
- // Returns the current start pointer.
- // Note that the pointer can change when if the StringRef is a substring
- auto currentData() const noexcept -> char const*;
+ // Returns the current start pointer. May not be null-terminated.
+ auto data() const noexcept -> char const*;
- public: // iterators
- const_iterator begin() const { return m_start; }
- const_iterator end() const { return m_start + m_size; }
+ constexpr auto isNullTerminated() const noexcept -> bool {
+ return m_start[m_size] == '\0';
+ }
- private: // ownership queries - may not be consistent between calls
- auto isOwned() const noexcept -> bool;
- auto isSubstring() const noexcept -> bool;
+ public: // iterators
+ constexpr const_iterator begin() const { return m_start; }
+ constexpr const_iterator end() const { return m_start + m_size; }
};
auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&;
auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&;
- inline auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef {
+ constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef {
return StringRef( rawChars, size );
}
-
} // namespace Catch
-inline auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef {
+constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef {
return Catch::StringRef( rawChars, size );
}
diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt
index 311183bc..4090d70c 100644
--- a/projects/SelfTest/Baselines/compact.sw.approved.txt
+++ b/projects/SelfTest/Baselines/compact.sw.approved.txt
@@ -1095,37 +1095,32 @@ Matchers.tests.cpp:<line number>: passed: testStringForMatching(), EndsWith("sub
Matchers.tests.cpp:<line number>: passed: testStringForMatching(), EndsWith(" SuBsTrInG", Catch::CaseSensitive::No) for: "this string contains 'abc' as a substring" ends with: " substring" (case insensitive)
String.tests.cpp:<line number>: passed: empty.empty() for: true
String.tests.cpp:<line number>: passed: empty.size() == 0 for: 0 == 0
+String.tests.cpp:<line number>: passed: empty.isNullTerminated() for: true
String.tests.cpp:<line number>: passed: std::strcmp( empty.c_str(), "" ) == 0 for: 0 == 0
String.tests.cpp:<line number>: passed: s.empty() == false for: false == false
String.tests.cpp:<line number>: passed: s.size() == 5 for: 5 == 5
-String.tests.cpp:<line number>: passed: isSubstring( s ) == false for: false == false
+String.tests.cpp:<line number>: passed: s.isNullTerminated() for: true
String.tests.cpp:<line number>: passed: std::strcmp( rawChars, "hello" ) == 0 for: 0 == 0
-String.tests.cpp:<line number>: passed: isOwned( s ) == false for: false == false
+String.tests.cpp:<line number>: passed: s.c_str()
String.tests.cpp:<line number>: passed: s.c_str() == rawChars for: "hello" == "hello"
-String.tests.cpp:<line number>: passed: isOwned( s ) == false for: false == false
+String.tests.cpp:<line number>: passed: s.data() == rawChars for: "hello" == "hello"
String.tests.cpp:<line number>: passed: original == "original"
-String.tests.cpp:<line number>: passed: isSubstring( original ) for: true
-String.tests.cpp:<line number>: passed: isOwned( original ) == false for: false == false
-String.tests.cpp:<line number>: passed: isOwned( original ) for: true
+String.tests.cpp:<line number>: passed: !(original.isNullTerminated()) for: !false
+String.tests.cpp:<line number>: passed: original.c_str()
+String.tests.cpp:<line number>: passed: original.data()
String.tests.cpp:<line number>: passed: ss.empty() == false for: false == false
String.tests.cpp:<line number>: passed: ss.size() == 5 for: 5 == 5
-String.tests.cpp:<line number>: passed: std::strcmp( ss.c_str(), "hello" ) == 0 for: 0 == 0
+String.tests.cpp:<line number>: passed: std::strncmp( ss.data(), "hello", 5 ) == 0 for: 0 == 0
String.tests.cpp:<line number>: passed: ss == "hello" for: hello == "hello"
-String.tests.cpp:<line number>: passed: isSubstring( ss ) for: true
-String.tests.cpp:<line number>: passed: isOwned( ss ) == false for: false == false
-String.tests.cpp:<line number>: passed: rawChars == s.currentData() for: "hello world!" == "hello world!"
-String.tests.cpp:<line number>: passed: ss.c_str() != rawChars for: "hello" != "hello world!"
-String.tests.cpp:<line number>: passed: isOwned( ss ) for: true
-String.tests.cpp:<line number>: passed: isOwned(ss) == false for: false == false
-String.tests.cpp:<line number>: passed: ss == "hello" for: hello == "hello"
-String.tests.cpp:<line number>: passed: rawChars == ss.currentData() for: "hello world!" == "hello world!"
String.tests.cpp:<line number>: passed: ss.size() == 6 for: 6 == 6
String.tests.cpp:<line number>: passed: std::strcmp( ss.c_str(), "world!" ) == 0 for: 0 == 0
-String.tests.cpp:<line number>: passed: s.c_str() == s2.c_str() for: "hello world!" == "hello world!"
-String.tests.cpp:<line number>: passed: s.c_str() != ss.c_str() for: "hello world!" != "hello"
+String.tests.cpp:<line number>: passed: s.data() == s2.data() for: "hello world!" == "hello world!"
+String.tests.cpp:<line number>: passed: s.data() == ss.data() for: "hello world!" == "hello world!"
String.tests.cpp:<line number>: passed: s.substr(s.size() + 1, 123).empty() for: true
-String.tests.cpp:<line number>: passed: StringRef("hello") == StringRef("hello") for: hello == hello
-String.tests.cpp:<line number>: passed: StringRef("hello") != StringRef("cello") for: hello != cello
+String.tests.cpp:<line number>: passed: std::strcmp(ss.c_str(), "world!") == 0 for: 0 == 0
+String.tests.cpp:<line number>: passed: buffer1 != buffer2 for: "Hello" != "Hello"
+String.tests.cpp:<line number>: passed: left == right for: Hello == Hello
+String.tests.cpp:<line number>: passed: left != left.substr(0, 3) for: Hello != Hel
String.tests.cpp:<line number>: passed: sr == "a standard string" for: a standard string == "a standard string"
String.tests.cpp:<line number>: passed: sr.size() == stdStr.size() for: 17 == 17
String.tests.cpp:<line number>: passed: sr == "a standard string" for: a standard string == "a standard string"
@@ -1136,6 +1131,17 @@ String.tests.cpp:<line number>: passed: stdStr == "a stringref" for: "a stringre
String.tests.cpp:<line number>: passed: stdStr.size() == sr.size() for: 11 == 11
String.tests.cpp:<line number>: passed: stdStr == "a stringref" for: "a stringref" == "a stringref"
String.tests.cpp:<line number>: passed: stdStr.size() == sr.size() for: 11 == 11
+String.tests.cpp:<line number>: passed: with 1 message: 'StringRef{}.size() == 0'
+String.tests.cpp:<line number>: passed: with 1 message: 'StringRef{ "abc", 3 }.size() == 3'
+String.tests.cpp:<line number>: passed: with 1 message: 'StringRef{ "abc", 3 }.isNullTerminated()'
+String.tests.cpp:<line number>: passed: with 1 message: 'StringRef{ "abc", 2 }.size() == 2'
+String.tests.cpp:<line number>: passed: with 1 message: '!(StringRef{ "abc", 2 }.isNullTerminated())'
+String.tests.cpp:<line number>: passed: with 1 message: '!(sr1.empty())'
+String.tests.cpp:<line number>: passed: with 1 message: 'sr1.size() == 3'
+String.tests.cpp:<line number>: passed: with 1 message: 'sr1.isNullTerminated()'
+String.tests.cpp:<line number>: passed: with 1 message: 'sr2.empty()'
+String.tests.cpp:<line number>: passed: with 1 message: 'sr2.size() == 0'
+String.tests.cpp:<line number>: passed: with 1 message: 'sr2.isNullTerminated()'
ToStringChrono.tests.cpp:<line number>: passed: minute == seconds for: 1 m == 60 s
ToStringChrono.tests.cpp:<line number>: passed: hour != seconds for: 1 h != 60 s
ToStringChrono.tests.cpp:<line number>: passed: micro != milli for: 1 us != 1 ms
diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt
index fd405a84..f6f43449 100644
--- a/projects/SelfTest/Baselines/console.std.approved.txt
+++ b/projects/SelfTest/Baselines/console.std.approved.txt
@@ -1380,6 +1380,6 @@ due to unexpected exception with message:
Why would you throw a std::string?
===============================================================================
-test cases: 304 | 230 passed | 70 failed | 4 failed as expected
-assertions: 1621 | 1469 passed | 131 failed | 21 failed as expected
+test cases: 305 | 231 passed | 70 failed | 4 failed as expected
+assertions: 1627 | 1475 passed | 131 failed | 21 failed as expected
diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt
index f234f882..0e7f7162 100644
--- a/projects/SelfTest/Baselines/console.sw.approved.txt
+++ b/projects/SelfTest/Baselines/console.sw.approved.txt
@@ -7996,6 +7996,11 @@ with expansion:
0 == 0
String.tests.cpp:<line number>: PASSED:
+ REQUIRE( empty.isNullTerminated() )
+with expansion:
+ true
+
+String.tests.cpp:<line number>: PASSED:
REQUIRE( std::strcmp( empty.c_str(), "" ) == 0 )
with expansion:
0 == 0
@@ -8018,27 +8023,17 @@ with expansion:
5 == 5
String.tests.cpp:<line number>: PASSED:
- REQUIRE( isSubstring( s ) == false )
+ REQUIRE( s.isNullTerminated() )
with expansion:
- false == false
+ true
String.tests.cpp:<line number>: PASSED:
REQUIRE( std::strcmp( rawChars, "hello" ) == 0 )
with expansion:
0 == 0
--------------------------------------------------------------------------------
-StringRef
- From string literal
- c_str() does not cause copy
--------------------------------------------------------------------------------
-String.tests.cpp:<line number>
-...............................................................................
-
String.tests.cpp:<line number>: PASSED:
- REQUIRE( isOwned( s ) == false )
-with expansion:
- false == false
+ REQUIRE_NOTHROW( s.c_str() )
String.tests.cpp:<line number>: PASSED:
REQUIRE( s.c_str() == rawChars )
@@ -8046,9 +8041,9 @@ with expansion:
"hello" == "hello"
String.tests.cpp:<line number>: PASSED:
- REQUIRE( isOwned( s ) == false )
+ REQUIRE( s.data() == rawChars )
with expansion:
- false == false
+ "hello" == "hello"
-------------------------------------------------------------------------------
StringRef
@@ -8061,19 +8056,15 @@ String.tests.cpp:<line number>: PASSED:
REQUIRE( original == "original" )
String.tests.cpp:<line number>: PASSED:
- REQUIRE( isSubstring( original ) )
+ REQUIRE_FALSE( original.isNullTerminated() )
with expansion:
- true
+ !false
String.tests.cpp:<line number>: PASSED:
- REQUIRE( isOwned( original ) == false )
-with expansion:
- false == false
+ REQUIRE_THROWS( original.c_str() )
String.tests.cpp:<line number>: PASSED:
- REQUIRE( isOwned( original ) )
-with expansion:
- true
+ REQUIRE_NOTHROW( original.data() )
-------------------------------------------------------------------------------
StringRef
@@ -8094,7 +8085,7 @@ with expansion:
5 == 5
String.tests.cpp:<line number>: PASSED:
- REQUIRE( std::strcmp( ss.c_str(), "hello" ) == 0 )
+ REQUIRE( std::strncmp( ss.data(), "hello", 5 ) == 0 )
with expansion:
0 == 0
@@ -8106,133 +8097,94 @@ with expansion:
-------------------------------------------------------------------------------
StringRef
Substrings
- c_str() causes copy
+ non-zero-based substring
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
- REQUIRE( isSubstring( ss ) )
-with expansion:
- true
-
-String.tests.cpp:<line number>: PASSED:
- REQUIRE( isOwned( ss ) == false )
-with expansion:
- false == false
-
-String.tests.cpp:<line number>: PASSED:
- REQUIRE( rawChars == s.currentData() )
-with expansion:
- "hello world!" == "hello world!"
-
-String.tests.cpp:<line number>: PASSED:
- REQUIRE( ss.c_str() != rawChars )
+ REQUIRE( ss.size() == 6 )
with expansion:
- "hello" != "hello world!"
+ 6 == 6
String.tests.cpp:<line number>: PASSED:
- REQUIRE( isOwned( ss ) )
+ REQUIRE( std::strcmp( ss.c_str(), "world!" ) == 0 )
with expansion:
- true
+ 0 == 0
-------------------------------------------------------------------------------
StringRef
Substrings
- c_str() causes copy
- Self-assignment after substring
+ Pointer values of full refs should match
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
- REQUIRE( isOwned(ss) == false )
-with expansion:
- false == false
-
-String.tests.cpp:<line number>: PASSED:
- REQUIRE( ss == "hello" )
-with expansion:
- hello == "hello"
-
-String.tests.cpp:<line number>: PASSED:
- REQUIRE( rawChars == ss.currentData() )
+ REQUIRE( s.data() == s2.data() )
with expansion:
"hello world!" == "hello world!"
-------------------------------------------------------------------------------
StringRef
Substrings
- non-zero-based substring
+ Pointer values of substring refs should also match
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
- REQUIRE( ss.size() == 6 )
+ REQUIRE( s.data() == ss.data() )
with expansion:
- 6 == 6
-
-String.tests.cpp:<line number>: PASSED:
- REQUIRE( std::strcmp( ss.c_str(), "world!" ) == 0 )
-with expansion:
- 0 == 0
+ "hello world!" == "hello world!"
-------------------------------------------------------------------------------
StringRef
Substrings
- Pointer values of full refs should match
+ Past the end substring
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
- REQUIRE( s.c_str() == s2.c_str() )
+ REQUIRE( s.substr(s.size() + 1, 123).empty() )
with expansion:
- "hello world!" == "hello world!"
+ true
-------------------------------------------------------------------------------
StringRef
Substrings
- Pointer values of substring refs should not match
+ Substring off the end are trimmed
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
- REQUIRE( s.c_str() != ss.c_str() )
+ REQUIRE( std::strcmp(ss.c_str(), "world!") == 0 )
with expansion:
- "hello world!" != "hello"
+ 0 == 0
-------------------------------------------------------------------------------
StringRef
- Substrings
- Past the end substring
+ Comparisons are deep
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
- REQUIRE( s.substr(s.size() + 1, 123).empty() )
+ CHECK( buffer1 != buffer2 )
with expansion:
- true
-
--------------------------------------------------------------------------------
-StringRef
- Comparisons
--------------------------------------------------------------------------------
-String.tests.cpp:<line number>
-...............................................................................
+ "Hello" != "Hello"
String.tests.cpp:<line number>: PASSED:
- REQUIRE( StringRef("hello") == StringRef("hello") )
+ REQUIRE( left == right )
with expansion:
- hello == hello
+ Hello == Hello
String.tests.cpp:<line number>: PASSED:
- REQUIRE( StringRef("hello") != StringRef("cello") )
+ REQUIRE( left != left.substr(0, 3) )
with expansion:
- hello != cello
+ Hello != Hel
-------------------------------------------------------------------------------
StringRef
@@ -8325,6 +8277,64 @@ with expansion:
11 == 11
-------------------------------------------------------------------------------
+StringRef at compilation time
+ Simple constructors
+-------------------------------------------------------------------------------
+String.tests.cpp:<line number>
+...............................................................................
+
+String.tests.cpp:<line number>: PASSED:
+with message:
+ StringRef{}.size() == 0
+
+String.tests.cpp:<line number>: PASSED:
+with message:
+ StringRef{ "abc", 3 }.size() == 3
+
+String.tests.cpp:<line number>: PASSED:
+with message:
+ StringRef{ "abc", 3 }.isNullTerminated()
+
+String.tests.cpp:<line number>: PASSED:
+with message:
+ StringRef{ "abc", 2 }.size() == 2
+
+String.tests.cpp:<line number>: PASSED:
+with message:
+ !(StringRef{ "abc", 2 }.isNullTerminated())
+
+-------------------------------------------------------------------------------
+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:
+ sr1.isNullTerminated()
+
+String.tests.cpp:<line number>: PASSED:
+with message:
+ sr2.empty()
+
+String.tests.cpp:<line number>: PASSED:
+with message:
+ sr2.size() == 0
+
+String.tests.cpp:<line number>: PASSED:
+with message:
+ sr2.isNullTerminated()
+
+-------------------------------------------------------------------------------
Stringifying std::chrono::duration helpers
-------------------------------------------------------------------------------
ToStringChrono.tests.cpp:<line number>
@@ -12956,6 +12966,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:
===============================================================================
-test cases: 304 | 214 passed | 86 failed | 4 failed as expected
-assertions: 1638 | 1469 passed | 148 failed | 21 failed as expected
+test cases: 305 | 215 passed | 86 failed | 4 failed as expected
+assertions: 1644 | 1475 passed | 148 failed | 21 failed as expected
diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt
index bfacb033..61b364f3 100644
--- a/projects/SelfTest/Baselines/junit.sw.approved.txt
+++ b/projects/SelfTest/Baselines/junit.sw.approved.txt
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
- <testsuite name="<exe-name>" errors="17" failures="132" tests="1639" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+ <testsuite name="<exe-name>" errors="17" failures="132" tests="1645" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/>
<property name="random-seed" value="1"/>
@@ -726,21 +726,21 @@ Matchers.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="String matchers" time="{duration}"/>
<testcase classname="<exe-name>.global" name="StringRef/Empty string" time="{duration}"/>
<testcase classname="<exe-name>.global" name="StringRef/From string literal" time="{duration}"/>
- <testcase classname="<exe-name>.global" name="StringRef/From string literal/c_str() does not cause copy" time="{duration}"/>
<testcase classname="<exe-name>.global" name="StringRef/From sub-string" time="{duration}"/>
<testcase classname="<exe-name>.global" name="StringRef/Substrings/zero-based substring" time="{duration}"/>
- <testcase classname="<exe-name>.global" name="StringRef/Substrings/c_str() causes copy" time="{duration}"/>
- <testcase classname="<exe-name>.global" name="StringRef/Substrings/c_str() causes copy/Self-assignment after substring" time="{duration}"/>
<testcase classname="<exe-name>.global" name="StringRef/Substrings/non-zero-based substring" time="{duration}"/>
<testcase classname="<exe-name>.global" name="StringRef/Substrings/Pointer values of full refs should match" time="{duration}"/>
- <testcase classname="<exe-name>.global" name="StringRef/Substrings/Pointer values of substring refs should not match" time="{duration}"/>
+ <testcase classname="<exe-name>.global" name="StringRef/Substrings/Pointer values of substring refs should also match" time="{duration}"/>
<testcase classname="<exe-name>.global" name="StringRef/Substrings/Past the end substring" time="{duration}"/>
- <testcase classname="<exe-name>.global" name="StringRef/Comparisons" time="{duration}"/>
+ <testcase classname="<exe-name>.global" name="StringRef/Substrings/Substring off the end are trimmed" time="{duration}"/>
+ <testcase classname="<exe-name>.global" name="StringRef/Comparisons are deep" time="{duration}"/>
<testcase classname="<exe-name>.global" name="StringRef/from std::string/implicitly constructed" time="{duration}"/>
<testcase classname="<exe-name>.global" name="StringRef/from std::string/explicitly constructed" time="{duration}"/>
<testcase classname="<exe-name>.global" name="StringRef/from std::string/assigned" time="{duration}"/>
<testcase classname="<exe-name>.global" name="StringRef/to std::string/explicitly constructed" time="{duration}"/>
<testcase classname="<exe-name>.global" name="StringRef/to std::string/assigned" time="{duration}"/>
+ <testcase classname="<exe-name>.global" name="StringRef at compilation time/Simple constructors" time="{duration}"/>
+ <testcase classname="<exe-name>.global" name="StringRef at compilation time/UDL construction" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Stringifying std::chrono::duration helpers" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Stringifying std::chrono::duration with weird ratios" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Stringifying std::chrono::time_point&lt;system_clock>" time="{duration}"/>
diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt
index 6193dfb3..4b67b803 100644
--- a/projects/SelfTest/Baselines/xml.sw.approved.txt
+++ b/projects/SelfTest/Baselines/xml.sw.approved.txt
@@ -9848,13 +9848,21 @@ Message from section two
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" >
<Original>
+ empty.isNullTerminated()
+ </Original>
+ <Expanded>
+ true
+ </Expanded>
+ </Expression>
+ <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" >
+ <Original>
std::strcmp( empty.c_str(), "" ) == 0
</Original>
<Expanded>
0 == 0
</Expanded>
</Expression>
- <OverallResults successes="3" failures="0" expectedFailures="0"/>
+ <OverallResults successes="4" failures="0" expectedFailures="0"/>
</Section>
<Section name="From string literal" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" >
@@ -9875,10 +9883,10 @@ Message from section two
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" >
<Original>
- isSubstring( s ) == false
+ s.isNullTerminated()
</Original>
<Expanded>
- false == false
+ true
</