From 3772f69f0fbba0620df4c262b1925444a0567b37 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Mon, 14 Aug 2017 09:04:14 +0100 Subject: [PATCH] Removed String and StringBuilder --- CMakeLists.txt | 6 - include/internal/catch_string.cpp | 86 ----- include/internal/catch_string.h | 52 --- include/internal/catch_stringbuilder.cpp | 111 ------- include/internal/catch_stringbuilder.h | 74 ----- include/internal/catch_stringref.cpp | 40 +-- include/internal/catch_stringref.h | 10 +- .../Baselines/console.std.approved.txt | 4 +- .../Baselines/console.sw.approved.txt | 278 +--------------- .../SelfTest/Baselines/junit.sw.approved.txt | 13 +- .../SelfTest/Baselines/xml.sw.approved.txt | 314 +----------------- projects/SelfTest/String.tests.cpp | 22 -- projects/SelfTest/StringBuilder.tests.cpp | 76 ----- projects/SelfTest/StringRef.tests.cpp | 30 +- 14 files changed, 24 insertions(+), 1092 deletions(-) delete mode 100644 include/internal/catch_string.cpp delete mode 100644 include/internal/catch_string.h delete mode 100644 include/internal/catch_stringbuilder.cpp delete mode 100644 include/internal/catch_stringbuilder.h delete mode 100644 projects/SelfTest/String.tests.cpp delete mode 100644 projects/SelfTest/StringBuilder.tests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b63eb93..33ec5d1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,8 +76,6 @@ set(TEST_SOURCES ${SELF_TEST_DIR}/TrickyTests.cpp ${SELF_TEST_DIR}/VariadicMacrosTests.cpp ${SELF_TEST_DIR}/MatchersTests.cpp - ${SELF_TEST_DIR}/String.tests.cpp - ${SELF_TEST_DIR}/StringBuilder.tests.cpp ${SELF_TEST_DIR}/StringRef.tests.cpp ) CheckFileList(TEST_SOURCES ${SELF_TEST_DIR}) @@ -172,8 +170,6 @@ set(INTERNAL_HEADERS ${HEADER_DIR}/internal/catch_startup_exception_registry.h ${HEADER_DIR}/internal/catch_stream.h ${HEADER_DIR}/internal/catch_streambuf.h - ${HEADER_DIR}/internal/catch_string.h - ${HEADER_DIR}/internal/catch_stringbuilder.h ${HEADER_DIR}/internal/catch_stringdata.h ${HEADER_DIR}/internal/catch_stringref.h ${HEADER_DIR}/internal/catch_string_manip.h @@ -226,8 +222,6 @@ set(IMPL_SOURCES ${HEADER_DIR}/internal/catch_section_info.cpp ${HEADER_DIR}/internal/catch_startup_exception_registry.cpp ${HEADER_DIR}/internal/catch_stream.cpp - ${HEADER_DIR}/internal/catch_string.cpp - ${HEADER_DIR}/internal/catch_stringbuilder.cpp ${HEADER_DIR}/internal/catch_stringdata.cpp ${HEADER_DIR}/internal/catch_stringref.cpp ${HEADER_DIR}/internal/catch_string_manip.cpp diff --git a/include/internal/catch_string.cpp b/include/internal/catch_string.cpp deleted file mode 100644 index 73d9d77a..00000000 --- a/include/internal/catch_string.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2016 Two Blue Cubes Ltd. All rights reserved. - * - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ - -#include "catch_string.h" -#include "catch_stringref.h" -#include "catch_stringbuilder.h" - -#include "catch_stringdata.h" - -#include - -namespace Catch { - - String::String() - : m_data( StringData::getEmpty() ) - {} - - String::String( StringRef const& stringRef ) - : m_data( StringData::create( stringRef ) ) - {} - - String::String( char const* rawString ) - : String( StringRef( rawString ) ) - {} - - String::String( String const& other ) - : m_data( other.m_data ) - { - m_data->addRef(); - } - String::String( String&& other ) noexcept - : m_data( other.m_data ) - { - other.m_data = StringData::getEmpty(); - } - String::String( StringBuilder&& stringBuf ) - : m_data( stringBuf.m_data ) - { - // const_cast is ok here because we are taking ownership - const_cast( m_data )->size = stringBuf.size(); - stringBuf.m_data = StringData::getEmpty(); - stringBuf.m_size = 0; - } - - - String::~String() noexcept { - m_data->release(); - } - - auto String::operator = ( String const& other ) -> String& { - m_data = other.m_data; - m_data->addRef(); - return *this; - } - - - auto String::empty() const noexcept -> bool { - return m_data->size == 0; - } - auto String::size() const noexcept -> size_type { - return m_data->size; - } - auto String::numberOfCharacters() const noexcept -> size_type { - return StringRef( *this ).numberOfCharacters(); - } - auto String::c_str() const noexcept -> char const* { - return m_data->chars; - } - - auto String::operator == ( StringRef const& other ) const noexcept -> bool { - return other == StringRef( *this ); - } - auto String::operator == ( char const* other ) const noexcept -> bool { - return StringRef( other ) == StringRef( *this ); - } - - std::ostream& operator << ( std::ostream& os, String const& str ) { - os << str.c_str(); - return os; - } - -} // namespace Catch diff --git a/include/internal/catch_string.h b/include/internal/catch_string.h deleted file mode 100644 index 5691be8d..00000000 --- a/include/internal/catch_string.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2016 Two Blue Cubes Ltd. All rights reserved. - * - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ -#ifndef CATCH_STRING_H_INCLUDED -#define CATCH_STRING_H_INCLUDED - -#include - -namespace Catch { - - class StringData; - class StringRef; - class StringBuilder; - - /// An owning, ref-counted, immutable string type. - /// The ref count (not visible here as it is defined in StringData) is atomic - /// so instances should be safe to share across threads - class String { - friend class StringRef; - friend class StringBuilder; - - StringData const* m_data = nullptr; - public: - using size_type = size_t; - - String(); - String( StringRef const& stringRef ); - String( char const* rawString ); - String( String const& other ); - String( String&& other ) noexcept; - String( StringBuilder&& stringBuf ); - - ~String() noexcept; - - auto operator = ( String const& other ) -> String&; - - auto operator == ( StringRef const& other ) const noexcept -> bool; - auto operator == ( char const* other ) const noexcept -> bool; - - auto empty() const noexcept -> bool; - auto size() const noexcept -> size_type; - auto numberOfCharacters() const noexcept -> size_type; - - auto c_str() const noexcept -> char const*; - }; - -} // namespace Catch - -#endif // CATCH_STRING_H_INCLUDED diff --git a/include/internal/catch_stringbuilder.cpp b/include/internal/catch_stringbuilder.cpp deleted file mode 100644 index 80ba1bbd..00000000 --- a/include/internal/catch_stringbuilder.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2016 Two Blue Cubes Ltd. All rights reserved. - * - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ - -#include "catch_stringbuilder.h" -#include "catch_stringref.h" -#include "catch_stringdata.h" -#include "catch_string.h" - -#include -#include -#include -#include - -namespace Catch { - - static const StringBuilder::size_type s_minimumCapacity = 32; - - StringBuilder::StringBuilder() - : m_data( StringData::getEmpty() ) - {} - - StringBuilder::StringBuilder( size_type initialCapacity ) - : m_size( 0 ), - m_data( StringData::create( StringRef(), initialCapacity ) ) - {} - StringBuilder::StringBuilder( StringRef const& str, size_type initialCapacity ) - : m_size( str.size() ), - m_data( StringData::create( str, initialCapacity ) ) - {} - StringBuilder::StringBuilder( StringBuilder const& other, size_type initialCapacity ) - : StringBuilder( StringRef( other.m_data->chars, other.m_size ), initialCapacity ) - {} - StringBuilder::StringBuilder( StringBuilder&& other ) noexcept - : StringBuilder() - { - swap( other ); - } - StringBuilder::StringBuilder( String&& str ) - : m_size( str.size() ), - m_data( StringData::getEmpty() ) - { - if( str.m_data->isUniquelyOwned() ) - { - std::swap( m_data, const_cast( str.m_data ) ); - } - else - { - size_type initialCapacity = std::min( s_minimumCapacity, m_size ); - m_data = StringData::create( str, initialCapacity ); - } - } - StringBuilder::StringBuilder( String const& other ) - : StringBuilder( StringRef( other ), std::min( s_minimumCapacity, other.size() ) ) - {} - - StringBuilder::~StringBuilder() noexcept { - m_data->release(); - } - - auto StringBuilder::size() const noexcept -> size_type { - return m_size; - } - - void StringBuilder::swap( StringBuilder& other ) noexcept { - std::swap( m_size, other.m_size ); - std::swap( m_data, other.m_data ); - } - void StringBuilder::reserve( size_type minimumCapacity ) { - if( minimumCapacity > capacity() ) { - StringBuilder temp( *this, minimumCapacity ); - swap( temp ); - } - } - void StringBuilder::reserveExponential( size_type minimumCapacity ) { - if( minimumCapacity > capacity() ) { - size_type candidateCapacity = capacity() < s_minimumCapacity ? s_minimumCapacity : capacity()*2; - while( candidateCapacity < minimumCapacity ) - candidateCapacity = candidateCapacity * 3/2; // grow factor of 1.5 - StringBuilder temp( *this, candidateCapacity ); - swap( temp ); - } - } - auto StringBuilder::capacity() const noexcept -> size_type { - return m_data->size; - } - void StringBuilder::writeTo( size_type index, StringRef const& str ) { - assert( index + str.size() < capacity() ); - if( str.size() > 0 ) - std::memcpy( m_data->chars+index, str.data(), str.size() ); - } - void StringBuilder::append( StringRef const& str ) { - reserveExponential( m_size + str.size() + 1 ); - writeTo( m_size, str ); - m_size += str.size(); - m_data->chars[m_size] = '\0'; - } - - auto operator << ( StringBuilder& sb, StringRef sr ) -> StringBuilder& { - sb.append( sr ); - return sb; - } - auto operator << ( StringBuilder&& sb, StringRef sr ) -> StringBuilder&& { - sb.append( sr ); - return std::move( sb ); - } - -} // namespace Catch diff --git a/include/internal/catch_stringbuilder.h b/include/internal/catch_stringbuilder.h deleted file mode 100644 index 2f7d8a2d..00000000 --- a/include/internal/catch_stringbuilder.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2016 Two Blue Cubes Ltd. All rights reserved. - * - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ -#ifndef CATCH_STRINGBUILDER_H_INCLUDED -#define CATCH_STRINGBUILDER_H_INCLUDED - -#include "catch_stringref.h" - -#include - -namespace Catch { - - class String; - class StringData; - - /// A mutable container for string data - /// Use to build up strings before transferring to an immutable String. - /// Construct the String using the rvalue reference constructor (which - /// will usually involve std::move-ing the StringBuilder). This will transfer - /// The underlying buffer without any extra allocations or ref counts. - class StringBuilder { - friend class String; - public: - using size_type = size_t; - - StringBuilder(); - StringBuilder( size_type initialCapacity ); - StringBuilder( StringRef const& str, size_type initialCapacity ); - StringBuilder( StringBuilder const& other, size_type initialCapacity ); - StringBuilder( StringBuilder&& other ) noexcept; - StringBuilder( String&& other ); - StringBuilder( String const& other ); - ~StringBuilder() noexcept; - - void swap( StringBuilder& other ) noexcept; - - auto size() const noexcept -> size_type; - auto capacity() const noexcept -> size_type; - - /// Grows the buffer to exactly the capacity requested, or - /// does nothing if it is already at least as big - void reserve(size_type capacity); - - /// Grows the buffer exponentially (from a baseline of 32 bytes) - /// until it is at least as large as the requested capacity - - /// or does nothing if already large enough - void reserveExponential(size_type capacity); - - /// Writes the string at the current insertion point then moves - /// the insertion point forward by the string length. - /// If the buffer needs to grow to accomodate the string it does so - /// using the exponential strategy - void append( StringRef const& str ); - - friend auto operator << ( StringBuilder& sb, StringRef sr ) -> StringBuilder&; - friend auto operator << ( StringBuilder&& sb, StringRef sr ) -> StringBuilder&&; - - /// Writes the contents of the string ref into the buffer at - /// the indexed location. - /// The bounds are not checked! Use append() to just add to the - /// end of the buffer, extending it if the capacity is not enough. - void writeTo( size_type index, StringRef const& str ); - - private: - size_type m_size = 0; - StringData* m_data; - }; - -} // namespace Catch - -#endif // CATCH_STRINGBUILDER_H_INCLUDED diff --git a/include/internal/catch_stringref.cpp b/include/internal/catch_stringref.cpp index 7d117018..61e001bc 100644 --- a/include/internal/catch_stringref.cpp +++ b/include/internal/catch_stringref.cpp @@ -6,8 +6,6 @@ */ #include "catch_stringref.h" -#include "catch_stringbuilder.h" -#include "catch_string.h" #include "catch_stringdata.h" #include @@ -58,18 +56,6 @@ namespace Catch { m_size = rawSize; } - StringRef::StringRef( String const& other ) noexcept - : m_start( other.c_str() ), - m_size( other.size() ) - {} - - StringRef::StringRef( String&& str ) noexcept - : m_start( str.c_str() ), - m_size( str.size() ), - m_data( str.m_data ) - { - str.m_data = StringData::getEmpty(); - } StringRef::StringRef( std::string const& stdString ) noexcept : m_start( stdString.c_str() ), m_size( stdString.size() ) @@ -112,9 +98,9 @@ namespace Catch { void StringRef::takeOwnership() { if( !isOwned() ) { - StringRef temp = String( *this ); - swap( temp ); - } + m_data = StringData::create( *this ); + m_start = m_data->chars; + } } auto StringRef::substr( size_type start, size_type size ) const noexcept -> StringRef { if( start < m_size ) @@ -159,18 +145,18 @@ namespace Catch { return noChars; } - auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> String { - StringBuilder buf; - buf.reserve( lhs.size() + rhs.size() ); - buf.append( lhs ); - buf.append( rhs ); - return String( std::move( buf ) ); + auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> std::string { + std::string str; + str.reserve( lhs.size() + rhs.size() ); + str += lhs; + str += rhs; + return str; } - auto operator + ( StringRef const& lhs, const char* rhs ) -> String { - return lhs + StringRef( rhs ); + auto operator + ( StringRef const& lhs, const char* rhs ) -> std::string { + return std::string( lhs ) + std::string( rhs ); } - auto operator + ( char const* lhs, StringRef const& rhs ) -> String { - return StringRef( lhs ) + rhs; + auto operator + ( char const* lhs, StringRef const& rhs ) -> std::string { + return std::string( lhs ) + std::string( rhs ); } auto operator << ( std::ostream& os, StringRef const& str ) -> std::ostream& { diff --git a/include/internal/catch_stringref.h b/include/internal/catch_stringref.h index 1f8412de..b1f1c41e 100644 --- a/include/internal/catch_stringref.h +++ b/include/internal/catch_stringref.h @@ -13,7 +13,6 @@ namespace Catch { - class String; class StringData; /// A non-owning string class (similar to the forthcoming std::string_view) @@ -26,7 +25,6 @@ namespace Catch { class StringRef { friend struct StringRefTestAccess; friend class StringData; - friend class StringBuilder; using size_type = size_t; @@ -43,8 +41,6 @@ namespace Catch { StringRef( StringRef&& other ) noexcept; StringRef( char const* rawChars ) noexcept; StringRef( char const* rawChars, size_type size ) noexcept; - StringRef( String const& other ) noexcept; - StringRef( String&& other ) noexcept; StringRef( std::string const& stdString ) noexcept; ~StringRef() noexcept; @@ -74,9 +70,9 @@ namespace Catch { auto data() const noexcept -> char const*; }; - auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> String; - auto operator + ( StringRef const& lhs, char const* rhs ) -> String; - auto operator + ( char const* lhs, StringRef const& rhs ) -> String; + auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> std::string; + auto operator + ( StringRef const& lhs, char const* rhs ) -> std::string; + auto operator + ( char const* lhs, StringRef const& rhs ) -> std::string; auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 2618ba11..4bc5c454 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1020,6 +1020,6 @@ with expansion: "{?}" == "1" =============================================================================== -test cases: 183 | 132 passed | 47 failed | 4 failed as expected -assertions: 908 | 791 passed | 96 failed | 21 failed as expected +test cases: 181 | 130 passed | 47 failed | 4 failed as expected +assertions: 876 | 759 passed | 96 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 3cc191a6..17b876ea 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -4257,50 +4257,6 @@ MatchersTests.cpp:: FAILED: with expansion: "this string contains 'abc' as a substring" starts with: "string" -------------------------------------------------------------------------------- -String - empty string -------------------------------------------------------------------------------- -String.tests.cpp: -............................................................................... - -String.tests.cpp:: -PASSED: - REQUIRE( empty.empty() ) -with expansion: - true - -String.tests.cpp:: -PASSED: - REQUIRE( empty.size() == 0 ) -with expansion: - 0 == 0 - -String.tests.cpp:: -PASSED: - REQUIRE( std::strcmp( empty.c_str(), "" ) == 0 ) -with expansion: - 0 == 0 - -------------------------------------------------------------------------------- -String - from literal -------------------------------------------------------------------------------- -String.tests.cpp: -............................................................................... - -String.tests.cpp:: -PASSED: - REQUIRE( s.empty() == false ) -with expansion: - false == false - -String.tests.cpp:: -PASSED: - REQUIRE( s.size() == 5 ) -with expansion: - 5 == 5 - ------------------------------------------------------------------------------- String matchers ------------------------------------------------------------------------------- @@ -4331,172 +4287,6 @@ PASSED: with expansion: "this string contains 'abc' as a substring" ends with: "substring" -------------------------------------------------------------------------------- -StringBuilder - basic -------------------------------------------------------------------------------- -StringBuilder.tests.cpp: -............................................................................... - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( sb.capacity() == 0 ) -with expansion: - 0 == 0 - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( sb.size() == 0 ) -with expansion: - 0 == 0 - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( sb.capacity() == 32 ) -with expansion: - 32 == 32 - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( sb.size() == 0 ) -with expansion: - 0 == 0 - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( sb.capacity() == 32 ) -with expansion: - 32 == 32 - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( sb.size() == 5 ) -with expansion: - 5 == 5 - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( s == "hello" ) -with expansion: - hello == "hello" - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( s.size() == 5 ) -with expansion: - 5 == 5 - -------------------------------------------------------------------------------- -StringBuilder - concatenation -------------------------------------------------------------------------------- -StringBuilder.tests.cpp: -............................................................................... - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( s == "hello world" ) -with expansion: - hello world == "hello world" - -------------------------------------------------------------------------------- -StringBuilder - concat & move -------------------------------------------------------------------------------- -StringBuilder.tests.cpp: -............................................................................... - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( s == "hello world" ) -with expansion: - hello world == "hello world" - -------------------------------------------------------------------------------- -StringBuilder - reserved -------------------------------------------------------------------------------- -StringBuilder.tests.cpp: -............................................................................... - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( sb16.capacity() == 16 ) -with expansion: - 16 == 16 - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( sb16.capacity() == 16 ) -with expansion: - 16 == 16 - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( s == "hello world" ) -with expansion: - hello world == "hello world" - -------------------------------------------------------------------------------- -StringBuilder - from String - copy -------------------------------------------------------------------------------- -StringBuilder.tests.cpp: -............................................................................... - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( s2 == s ) -with expansion: - hello == hello - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( s2.c_str() != s.c_str() ) -with expansion: - "hello" != "hello" - -------------------------------------------------------------------------------- -StringBuilder - from String - move from uniquely owned string -------------------------------------------------------------------------------- -StringBuilder.tests.cpp: -............................................................................... - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( s2 == "hello" ) -with expansion: - hello == "hello" - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( s2.c_str() == originalPointer ) -with expansion: - "hello" == "hello" - -------------------------------------------------------------------------------- -StringBuilder - from String - move from shared string (copies) -------------------------------------------------------------------------------- -StringBuilder.tests.cpp: -............................................................................... - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( s2 == "hello" ) -with expansion: - hello == "hello" - -StringBuilder.tests.cpp:: -PASSED: - REQUIRE( s2.c_str() != originalPointer ) -with expansion: - "hello" != "hello" - ------------------------------------------------------------------------------- StringRef Empty string @@ -4744,70 +4534,6 @@ PASSED: with expansion: hello != cello -------------------------------------------------------------------------------- -StringRef - From string - Copied -------------------------------------------------------------------------------- -StringRef.tests.cpp: -............................................................................... - -StringRef.tests.cpp:: -PASSED: - REQUIRE( copied == "hot potato" ) -with expansion: - hot potato == "hot potato" - -StringRef.tests.cpp:: -PASSED: - REQUIRE( str == "hot potato" ) -with expansion: - hot potato == "hot potato" - -StringRef.tests.cpp:: -PASSED: - REQUIRE( isOwned( copied ) == false ) -with expansion: - false == false - -StringRef.tests.cpp:: -PASSED: - REQUIRE( data( copied ) == originalPointer ) -with expansion: - "hot potato" == "hot potato" - -------------------------------------------------------------------------------- -StringRef - From string - Moved -------------------------------------------------------------------------------- -StringRef.tests.cpp: -............................................................................... - -StringRef.tests.cpp:: -PASSED: - REQUIRE( copied == "hot potato" ) -with expansion: - hot potato == "hot potato" - -StringRef.tests.cpp:: -PASSED: - REQUIRE( isOwned( copied ) ) -with expansion: - true - -StringRef.tests.cpp:: -PASSED: - REQUIRE( str.empty() ) -with expansion: - true - -StringRef.tests.cpp:: -PASSED: - REQUIRE( data( copied ) == originalPointer ) -with expansion: - "hot potato" == "hot potato" - ------------------------------------------------------------------------------- StringRef from std::string @@ -7737,6 +7463,6 @@ MiscTests.cpp:: PASSED: =============================================================================== -test cases: 183 | 129 passed | 50 failed | 4 failed as expected -assertions: 910 | 787 passed | 102 failed | 21 failed as expected +test cases: 181 | 127 passed | 50 failed | 4 failed as expected +assertions: 878 | 755 passed | 102 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 8cd10426..88b20529 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -505,16 +505,7 @@ Message from section two MatchersTests.cpp: - - - - - - - - - @@ -529,8 +520,6 @@ StringRef.tests.cpp: - - diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 324fbf6b..21c9c9ca 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -4860,55 +4860,6 @@ Message from section two - -
- - - empty.empty() - - - true - - - - - empty.size() == 0 - - - 0 == 0 - - - - - std::strcmp( empty.c_str(), "" ) == 0 - - - 0 == 0 - - - -
-
- - - s.empty() == false - - - false == false - - - - - s.size() == 5 - - - 5 == 5 - - - -
- -
@@ -4944,191 +4895,6 @@ Message from section two - -
- - - sb.capacity() == 0 - - - 0 == 0 - - - - - sb.size() == 0 - - - 0 == 0 - - - - - sb.capacity() == 32 - - - 32 == 32 - - - - - sb.size() == 0 - - - 0 == 0 - - - - - sb.capacity() == 32 - - - 32 == 32 - - - - - sb.size() == 5 - - - 5 == 5 - - - - - s == "hello" - - - hello == "hello" - - - - - s.size() == 5 - - - 5 == 5 - - - -
-
- - - s == "hello world" - - - hello world == "hello world" - - - -
-
- - - s == "hello world" - - - hello world == "hello world" - - - -
-
- - - sb16.capacity() == 16 - - - 16 == 16 - - - - - sb16.capacity() == 16 - - - 16 == 16 - - - - - s == "hello world" - - - hello world == "hello world" - - - -
-
-
- - - s2 == s - - - hello == hello - - - - - s2.c_str() != s.c_str() - - - "hello" != "hello" - - - -
- -
-
-
- - - s2 == "hello" - - - hello == "hello" - - - - - s2.c_str() == originalPointer - - - "hello" == "hello" - - - -
- -
-
-
- - - s2 == "hello" - - - hello == "hello" - - - - - s2.c_str() != originalPointer - - - "hello" != "hello" - - - -
- -
- -
@@ -5407,82 +5173,6 @@ Message from section two
-
-
- - - copied == "hot potato" - - - hot potato == "hot potato" - - - - - str == "hot potato" - - - hot potato == "hot potato" - - - - - isOwned( copied ) == false - - - false == false - - - - - data( copied ) == originalPointer - - - "hot potato" == "hot potato" - - - -
- -
-
-
- - - copied == "hot potato" - - - hot potato == "hot potato" - - - - - isOwned( copied ) - - - true - - - - - str.empty() - - - true - - - - - data( copied ) == originalPointer - - - "hot potato" == "hot potato" - - - -
- -
@@ -8568,7 +8258,7 @@ loose text artifact
- + - + diff --git a/projects/SelfTest/String.tests.cpp b/projects/SelfTest/String.tests.cpp deleted file mode 100644 index c27b7508..00000000 --- a/projects/SelfTest/String.tests.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "../include/internal/catch_string.h" - -#include "catch.hpp" - -#include - -TEST_CASE( "String", "[Strings]" ) { - using Catch::String; - - SECTION( "empty string" ) { - String empty; - REQUIRE( empty.empty() ); - REQUIRE( empty.size() == 0 ); - REQUIRE( std::strcmp( empty.c_str(), "" ) == 0 ); - } - SECTION( "from literal" ) { - String s = "hello"; - REQUIRE( s.empty() == false ); - REQUIRE( s.size() == 5 ); - } - -} \ No newline at end of file diff --git a/projects/SelfTest/StringBuilder.tests.cpp b/projects/SelfTest/StringBuilder.tests.cpp deleted file mode 100644 index e91d450d..00000000 --- a/projects/SelfTest/StringBuilder.tests.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "internal/catch_stringbuilder.h" -#include "../include/internal/catch_stringref.h" -#include "../include/internal/catch_string.h" - -#include "catch.hpp" - -TEST_CASE( "StringBuilder", "[Strings]" ) { - - using Catch::StringBuilder; - using Catch::String; - - StringBuilder sb; - - SECTION( "basic" ) { - REQUIRE( sb.capacity() == 0 ); - REQUIRE( sb.size() == 0 ); - - sb.reserve( 32 ); - REQUIRE( sb.capacity() == 32 ); - REQUIRE( sb.size() == 0 ); - - sb.append( "hello" ); - REQUIRE( sb.capacity() == 32 ); - REQUIRE( sb.size() == 5 ); - - String s = std::move( sb ); - REQUIRE( s == "hello" ); - REQUIRE( s.size() == 5 ); - } - - SECTION( "concatenation" ) { - sb << "hello" << " " << "world"; - String s = std::move( sb ); - REQUIRE( s == "hello world" ); - } - - SECTION( "concat & move" ) { - String s = StringBuilder() << "hello" << " " << "world"; - REQUIRE( s == "hello world" ); - } - - SECTION( "reserved" ) { - StringBuilder sb16( 16 ); - REQUIRE( sb16.capacity() == 16 ); - sb16 << "hello" << " " << "world"; - REQUIRE( sb16.capacity() == 16 ); - String s = std::move( sb16 ); - REQUIRE( s == "hello world" ); - } - - SECTION( "from String" ) { - String s = "hello"; - - SECTION( "copy" ) { - StringBuilder sb2 = s; - String s2( std::move(sb2) ); - REQUIRE( s2 == s ); - REQUIRE( s2.c_str() != s.c_str() ); - } - SECTION( "move from uniquely owned string" ) { - auto originalPointer = s.c_str(); - StringBuilder sb2( std::move( s ) ); - String s2( std::move(sb2) ); - REQUIRE( s2 == "hello" ); - REQUIRE( s2.c_str() == originalPointer ); - } - SECTION( "move from shared string (copies)" ) { - auto originalPointer = s.c_str(); - String keepAlive = s; - StringBuilder sb2( std::move( s ) ); - String s2( std::move(sb2) ); - REQUIRE( s2 == "hello" ); - REQUIRE( s2.c_str() != originalPointer ); - } - } -} diff --git a/projects/SelfTest/StringRef.tests.cpp b/projects/SelfTest/StringRef.tests.cpp index 6ebbdb13..d12c79a3 100644 --- a/projects/SelfTest/StringRef.tests.cpp +++ b/projects/SelfTest/StringRef.tests.cpp @@ -1,5 +1,4 @@ #include "../include/internal/catch_stringref.h" -#include "../include/internal/catch_string.h" #include "catch.hpp" @@ -40,8 +39,7 @@ namespace Catch { TEST_CASE( "StringRef", "[Strings]" ) { using Catch::StringRef; - using Catch::String; - + SECTION( "Empty string" ) { StringRef empty; REQUIRE( empty.empty() ); @@ -124,32 +122,6 @@ TEST_CASE( "StringRef", "[Strings]" ) { REQUIRE( StringRef("hello") == StringRef("hello") ); REQUIRE( StringRef("hello") != StringRef("cello") ); } - - SECTION( "From string" ) { - String str = "hot potato"; - auto originalPointer = str.c_str(); - - SECTION( "Copied" ) { - // After a String is "copied" to a StringRef - // It has only copied the pointer and size - // - it does not take ownership - StringRef copied = str; - REQUIRE( copied == "hot potato" ); - REQUIRE( str == "hot potato" ); - REQUIRE( isOwned( copied ) == false ); - REQUIRE( data( copied ) == originalPointer ); - } - SECTION( "Moved" ) { - // After a String is *moved* to a StringRef - // The StringRef takes ownership of the underlying data - // and the String is left in an empty state - StringRef copied = std::move( str ); - REQUIRE( copied == "hot potato" ); - REQUIRE( isOwned( copied ) ); - REQUIRE( str.empty() ); - REQUIRE( data( copied ) == originalPointer ); - } - } SECTION( "from std::string" ) { std::string stdStr = "a standard string";