diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 1bf29002..3a141606 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -500,6 +500,22 @@ namespace etl cleanup(); } + //********************************************************************* + /// Resizes the string and overwrites to data using the operation. + //********************************************************************* + template + void resize_and_overwrite(size_type new_size, TOperation operation) + { + if (new_size > CAPACITY) + { + ETL_ASSERT_FAIL(ETL_ERROR(string_out_of_bounds)); + } + + current_size = operation(p_buffer, new_size); + p_buffer[current_size] = '\0'; + cleanup(); + } + //********************************************************************* /// Resizes the string, but doesn't initialise the free space /// except for a terminator null. @@ -702,6 +718,36 @@ namespace etl assign(other, other + length_); } + //********************************************************************* + /// Assigns values to the string from a view. + //********************************************************************* + template + void assign(const etl::basic_string_view& view) + { + assign(view.begin(), view.end()); + } + + //********************************************************************* + /// Assigns values to the string. + /// Truncates if the string does not have enough free space. + ///\param other The other string. + //********************************************************************* + void assign(const_pointer other) + { + assign(other, other + etl::strlen(other)); + } + + //********************************************************************* + /// Assigns values to the string. + /// Truncates if the string does not have enough free space. + ///\param other The other string. + ///\param length The length to copy. + //********************************************************************* + void assign(const_pointer other, size_type length_) + { + assign(other, other + length_); + } + //********************************************************************* /// Assigns values to the string from a view. //********************************************************************* @@ -876,26 +922,13 @@ namespace etl /// Appends to the string. ///\param view An etl::string_view. //********************************************************************* - template - ibasic_string& append(const etl::basic_string_view& view) + template + ibasic_string& append(const etl::basic_string_view& view) { insert(end(), view.begin(), view.end()); return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Appends to the string. - ///\param view A std::string_view. - //********************************************************************* - template - ibasic_string& append(const std::basic_string_view& view) - { - insert(end(), view.begin(), view.end()); - return *this; - } -#endif - //********************************************************************* /// Inserts a value to the string. ///\param position The position to insert before. @@ -1132,26 +1165,12 @@ namespace etl ///\param position The position to insert before. ///\param view The view element to add. //********************************************************************* - template - iterator insert(const_iterator position, const etl::basic_string_view& view) + template + iterator insert(const_iterator position, const etl::basic_string_view& view) { return insert(position, view.begin(), view.end()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Inserts a view to the string. - /// If asserts or exceptions are enabled, emits string_full if the string does not have enough free space. - ///\param position The position to insert before. - ///\param view The view element to add. - //********************************************************************* - template - iterator insert(const_iterator position, const std::basic_string_view& view) - { - return insert(position, view.begin(), view.end()); - } -#endif - //********************************************************************* /// Inserts a string at the specified position. ///\param position The position to insert before. @@ -1177,6 +1196,21 @@ namespace etl return *this; } + //********************************************************************* + /// Inserts a string at the specified position. + ///\param position The position to insert before. + ///\param view The view to insert. + //********************************************************************* + template + etl::ibasic_string& insert(size_type position, const etl::basic_string_view& view) + { + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + + insert(begin() + position, view.cbegin(), view.cend()); + + return *this; + } + //********************************************************************* /// Inserts a string at the specified position from subposition for sublength. ///\param position The position to insert before. @@ -1186,7 +1220,7 @@ namespace etl //********************************************************************* etl::ibasic_string& insert(size_type position, const etl::ibasic_string& str, size_type subposition, size_type sublength) { - ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds)); if ((sublength == npos) || (subposition + sublength > str.size())) @@ -1210,6 +1244,29 @@ namespace etl return *this; } + //********************************************************************* + /// Inserts a view at the specified position from subposition for sublength. + ///\param position The position to insert before. + ///\param view The view to insert. + ///\param subposition The subposition to start from. + ///\param sublength The number of characters to insert. + //********************************************************************* + template + etl::ibasic_string& insert(size_type position, const etl::basic_string_view& view, size_type subposition, size_type sublength) + { + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); + + if ((sublength == npos) || (subposition + sublength > view.size())) + { + sublength = view.size() - subposition; + } + + insert(begin() + position, view.cbegin() + subposition, view.cbegin() + subposition + sublength); + + return *this; + } + //********************************************************************* /// Inserts a string at the specified position from pointer. ///\param position The position to insert before. @@ -1370,6 +1427,17 @@ namespace etl return find_impl(str.begin(), str.end(), str.size(), pos); } + //********************************************************************* + /// Find content within the string + ///\param view The content to find + ///\param pos The position to start searching from. + //********************************************************************* + template + size_type find(const etl::basic_string_view& view, size_type pos = 0) const + { + return find_impl(view.begin(), view.end(), view.size(), pos); + } + //********************************************************************* /// Find content within the string ///\param view The content to find @@ -1448,6 +1516,17 @@ namespace etl return rfind_impl(str.rbegin(), str.rend(), str.size(), position); } + //********************************************************************* + /// Find content within the string + ///\param view The content to find + ///\param pos The position to start searching from. + //********************************************************************* + template + size_type rfind(const etl::basic_string_view& view, size_type pos = 0) const + { + return rfind_impl(view.rbegin(), view.rend(), view.size(), pos); + } + //********************************************************************* /// Find content within the string ///\param view The content to find @@ -1526,6 +1605,124 @@ namespace etl } } + //********************************************************************* + /// Checks that the string is within this string + //********************************************************************* + bool contains(const etl::ibasic_string& str) const + { + return find(str) != npos; + } + + //********************************************************************* + /// Checks that the view is within this string + //********************************************************************* + template + bool contains(const etl::basic_string_view& view) const + { + return find(view) != npos; + } + + //********************************************************************* + /// Checks that text is within this string + //********************************************************************* + bool contains(const_pointer s) const + { + return find(s) != npos; + } + + //********************************************************************* + /// Checks that character is within this string + //********************************************************************* + bool contains(value_type c) const + { + return find(c) != npos; + } + + //********************************************************************* + /// Checks that the string is the start of this string + //********************************************************************* + bool starts_with(const etl::ibasic_string& str) const + { + return compare(0, str.size(), str) == 0; + } + + //********************************************************************* + /// Checks that the view is the start of this string + //********************************************************************* + template + bool starts_with(const etl::basic_string_view& view) const + { + return compare(0, view.size(), view) == 0; + } + + //********************************************************************* + /// Checks that the string is the start of this string + //********************************************************************* + bool starts_with(const_pointer s) const + { + size_t len = etl::strlen(s); + + return compare(0, len, s, len) == 0; + } + + //********************************************************************* + /// Checks that the character is the start of this string + //********************************************************************* + bool starts_with(value_type c) const + { + return !empty() && (front() == c); + } + + //********************************************************************* + /// Checks that the string is the end of this string + //********************************************************************* + bool ends_with(const etl::ibasic_string& str) const + { + if (str.size() > size()) + { + return false; + } + + return compare(size() - str.size(), str.size(), str) == 0; + } + + //********************************************************************* + /// Checks that the view is the end of this string + //********************************************************************* + template + bool ends_with(const etl::basic_string_view& view) const + { + if (view.size() > size()) + { + return false; + } + + return compare(size() - view.size(), view.size(), view) == 0; + } + + //********************************************************************* + /// Checks that the string is the end of this string + //********************************************************************* + bool ends_with(const_pointer s) const + { + size_t len = etl::strlen(s); + + if (len > size()) + { + return false; + } + + return compare(size() - len, len, s, len) == 0; + } + + //********************************************************************* + /// Checks that the character is the end of this string + //********************************************************************* + bool ends_with(value_type c) const + { + return !empty() && (back() == c); + } + //********************************************************************* /// Replace 'length' characters from 'position' with 'str'. ///\param position The position to start from. @@ -1554,8 +1751,8 @@ namespace etl ///\param length The number of characters to replace. ///\param view The string to replace it with. //********************************************************************* - template - ibasic_string& replace(size_type position, size_type length_, const etl::basic_string_view& view) + template + ibasic_string& replace(size_type position, size_type length_, const etl::basic_string_view& view) { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); @@ -1571,31 +1768,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Replace 'length' characters from 'position' with 'view'. - ///\param position The position to start from. - ///\param length The number of characters to replace. - ///\param view The string to replace it with. - //********************************************************************* - template - ibasic_string& replace(size_type position, size_type length_, const std::basic_string_view& view) - { - ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); - - // Limit the length. - length_ = etl::min(length_, size() - position); - - // Erase the bit we want to replace. - erase(position, length_); - - // Insert the new stuff. - insert(position, view); - - return *this; - } -#endif - //********************************************************************* /// Replace characters from 'first' to one before 'last' with 'str'. ///\param first The position to start from. @@ -1634,8 +1806,8 @@ namespace etl ///\param last The one after the position to end at. ///\param view The string view to replace it with. //********************************************************************* - template - ibasic_string& replace(const_iterator first, const_iterator last, const etl::basic_string_view& view) + template + ibasic_string& replace(const_iterator first, const_iterator last, const etl::basic_string_view& view) { // Quick hack, as iterators are pointers. iterator first_ = to_iterator(first); @@ -1650,30 +1822,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Replace characters from 'first' to one before 'last' with 'view'. - ///\param first The position to start from. - ///\param last The one after the position to end at. - ///\param view The string view to replace it with. - //********************************************************************* - template - ibasic_string& replace(const_iterator first, const_iterator last, const std::basic_string_view& view) - { - // Quick hack, as iterators are pointers. - iterator first_ = to_iterator(first); - iterator last_ = to_iterator(last); - - // Erase the bit we want to replace. - erase(first_, last_); - - // Insert the new stuff. - insert(first_, view.begin(), view.end()); - - return *this; - } -#endif - //********************************************************************* /// Replace characters from 'position' of 'length' with 'str' from 'subposition' of 'sublength'. //********************************************************************* @@ -1709,8 +1857,8 @@ namespace etl //********************************************************************* /// Replace characters from 'position' of 'length' with 'view' from 'subposition' of 'sublength'. //********************************************************************* - template - ibasic_string& replace(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) + template + ibasic_string& replace(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); @@ -1728,30 +1876,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Replace characters from 'position' of 'length' with 'view' from 'subposition' of 'sublength'. - //********************************************************************* - template - ibasic_string& replace(size_type position, size_type length_, const std::basic_string_view& view, size_type subposition, size_type sublength) - { - ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); - ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); - - // Limit the lengths. - length_ = etl::min(length_, size() - position); - sublength = etl::min(sublength, view.size() - subposition); - - // Erase the bit we want to replace. - erase(position, length_); - - // Insert the new stuff. - insert(position, view, subposition, sublength); - - return *this; - } -#endif - //********************************************************************* /// Replace characters from 'position' of 'length' with pointed to string. //********************************************************************* @@ -1896,29 +2020,15 @@ namespace etl //************************************************************************* /// Compare with etl::basic_string_view. //************************************************************************* - template - int compare(const etl::basic_string_view& view) const + template + int compare(const etl::basic_string_view& view) const { return compare(p_buffer, - p_buffer + view.size(), + p_buffer + size(), view.data(), - view.size()); + view.data() + view.size()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// Compare with std::basic_string_view. - //************************************************************************* - template - int compare(const std::basic_string_view& view) const - { - return compare(p_buffer, - p_buffer + view.size(), - view.data(), - view.size()); - } -#endif - //************************************************************************* /// Compare position / length with string. //************************************************************************* @@ -1938,29 +2048,15 @@ namespace etl //************************************************************************* /// Compare position / length with etl::basic_string_view. //************************************************************************* - template - int compare(size_type position, size_type length_, const etl::basic_string_view& view) const + template + int compare(size_type position, size_type length_, const etl::basic_string_view& view) const { return compare(p_buffer + position, p_buffer + position + length_, - view.p_buffer, - view.p_buffer + view.size()); + view.data(), + view.data() + view.size()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// Compare position / length with std::basic_string_view. - //************************************************************************* - template - int compare(size_type position, size_type length_, const std::basic_string_view& view) const - { - return compare(p_buffer + position, - p_buffer + position + length_, - view.p_buffer, - view.p_buffer + view.size()); - } -#endif - //************************************************************************* /// Compare position / length with string / subposition / sublength. //************************************************************************* @@ -1982,8 +2078,8 @@ namespace etl //************************************************************************* /// Compare position / length with etl::basic_string_view. / subposition / sublength. //************************************************************************* - template - int compare(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) const + template + int compare(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) const { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); @@ -1994,31 +2090,10 @@ namespace etl return compare(p_buffer + position, p_buffer + position + length_, - view.p_buffer + subposition, - view.p_buffer + subposition + sublength); + view.data() + subposition, + view.data() + subposition + sublength); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// Compare position / length with std::basic_string_view. / subposition / sublength. - //************************************************************************* - template - int compare(size_type position, size_type length_, const std::basic_string_view& view, size_type subposition, size_type sublength) const - { - ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); - ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); - - // Limit the lengths. - length_ = etl::min(length_, size() - position); - sublength = etl::min(sublength, view.size() - subposition); - - return compare(p_buffer + position, - p_buffer + position + length_, - view.p_buffer + subposition, - view.p_buffer + subposition + sublength); - } -#endif - //************************************************************************* /// Compare with C string //************************************************************************* @@ -2077,25 +2152,12 @@ namespace etl ///\param view The content to find ///\param pos The position to start searching from. //********************************************************************* - template - size_type find_first_of(const etl::basic_string_view& view, size_type position = 0) const + template + size_type find_first_of(const etl::basic_string_view& view, size_type position = 0) const { return find_first_of(view.data(), position, view.size()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Find first of any of content within the string - ///\param view The content to find - ///\param pos The position to start searching from. - //********************************************************************* - template - size_type find_first_of(const std::basic_string_view& view, size_type position = 0) const - { - return find_first_of(view.data(), position, view.size()); - } -#endif - //********************************************************************* /// Find first of any of content within the string ///\param s Pointer to the content to find @@ -2167,25 +2229,12 @@ namespace etl ///\param view The content to find ///\param pos The position to start searching from. //********************************************************************* - template - size_type find_last_of(const etl::basic_string_view& view, size_type position = 0) const + template + size_type find_last_of(const etl::basic_string_view& view, size_type position = npos) const { return find_last_of(view.data(), position, view.size()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Find last of any of content within the string - ///\param view The content to find - ///\param pos The position to start searching from. - //********************************************************************* - template - size_type find_last_of(const std::basic_string_view& view, size_type position = 0) const - { - return find_last_of(view.data(), position, view.size()); - } -#endif - //********************************************************************* /// Find last of any of content within the string ///\param s Pointer to the content to find @@ -2275,25 +2324,12 @@ namespace etl ///\param view The content to find ///\param pos The position to start searching from. //********************************************************************* - template - size_type find_first_not_of(const etl::basic_string_view& view, size_type position = 0) const + template + size_type find_first_not_of(const etl::basic_string_view& view, size_type position = 0) const { return find_first_not_of(view.data(), position, view.size()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Find first not of any of content within the string - ///\param view The content to find - ///\param pos The position to start searching from. - //********************************************************************* - template - size_type find_first_not_of(const std::basic_string_view& view, size_type position = 0) const - { - return find_first_not_of(view.data(), position, view.size()); - } -#endif - //********************************************************************* /// Find first not of any of content within the string ///\param s Pointer to the content to not find @@ -2372,25 +2408,12 @@ namespace etl ///\param view The content to find ///\param pos The position to start searching from. //********************************************************************* - template - size_type find_last_not_of(const etl::basic_string_view& view, size_type position = 0) const + template + size_type find_last_not_of(const etl::basic_string_view& view, size_type position = npos) const { return find_last_not_of(view.data(), position, view.size()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Find last not of any of content within the string - ///\param view The content to find - ///\param pos The position to start searching from. - //********************************************************************* - template - size_type find_last_not_of(const std::basic_string_view& view, size_type position = 0) const - { - return find_last_not_of(view.data(), position, view.size()); - } -#endif - //********************************************************************* /// Find last not of any of content within the string ///\param s The pointer to the content to find @@ -2483,6 +2506,17 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + template + ibasic_string& operator = (const etl::basic_string_view& view) + { + assign(view); + + return *this; + } + //************************************************************************* /// += operator. //************************************************************************* @@ -2496,27 +2530,14 @@ namespace etl //************************************************************************* /// += operator. //************************************************************************* - template - ibasic_string& operator += (const etl::basic_string_view& rhs) + template + ibasic_string& operator += (const etl::basic_string_view& rhs) { append(rhs); return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// += operator. - //************************************************************************* - template - ibasic_string& operator += (const std::basic_string_view& rhs) - { - append(rhs); - - return *this; - } -#endif - //************************************************************************* /// += operator. //************************************************************************* @@ -2607,7 +2628,7 @@ namespace etl //************************************************************************* /// Compare helper function //************************************************************************* - int compare(const_pointer first1, const_pointer last1, const_pointer first2, const_pointer last2) const + int compare(const_pointer first1, const_pointer last1, const_pointer first2, const_pointer last2) const { while ((first1 != last1) && (first2 != last2)) { diff --git a/include/etl/multi_span.h b/include/etl/multi_span.h index 8e974ee3..4d93df42 100644 --- a/include/etl/multi_span.h +++ b/include/etl/multi_span.h @@ -134,7 +134,7 @@ namespace etl //************************************************************************* pointer operator ->() { - return &operator*(); + return p_value; } //************************************************************************* @@ -142,7 +142,7 @@ namespace etl //************************************************************************* const_pointer operator ->() const { - return &operator*(); + return p_value; } //************************************************************************* diff --git a/include/etl/string.h b/include/etl/string.h index 50b3bf62..891815ad 100644 --- a/include/etl/string.h +++ b/include/etl/string.h @@ -244,6 +244,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string& operator = (const etl::string_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* @@ -362,6 +372,16 @@ namespace etl this->resize(count, c); } + //************************************************************************* + /// From string_view. + ///\param view The string_view. + //************************************************************************* + explicit string_ext(const etl::string_view& view, value_type* buffer, size_type buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->assign(view.begin(), view.end()); + } + //************************************************************************* /// Constructor, from an iterator range. ///\tparam TIterator The iterator type. @@ -386,16 +406,6 @@ namespace etl } #endif - //************************************************************************* - /// From string_view. - ///\param view The string_view. - //************************************************************************* - explicit string_ext(const etl::string_view& view, value_type* buffer, size_type buffer_size) - : istring(buffer, buffer_size - 1U) - { - this->assign(view.begin(), view.end()); - } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -409,7 +419,6 @@ namespace etl return *this; } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -433,6 +442,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string_ext& operator = (const etl::string_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/string_view.h b/include/etl/string_view.h index 7ddce503..7b60d839 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -43,6 +43,10 @@ SOFTWARE. #include "algorithm.h" #include "private/minmax_push.h" +#if ETL_USING_STL && ETL_USING_CPP17 + #include +#endif + #include namespace etl @@ -96,9 +100,9 @@ namespace etl { public: - typedef T value_type; - typedef TTraits traits_type; - typedef size_t size_type; + typedef T value_type; + typedef TTraits traits_type; + typedef size_t size_type; typedef const T& const_reference; typedef const T* const_pointer; typedef const T* const_iterator; @@ -163,6 +167,18 @@ namespace etl { } +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// Constructor from std::basic string_view + //************************************************************************* + template + explicit ETL_CONSTEXPR basic_string_view(const std::basic_string_view& other) ETL_NOEXCEPT + : mbegin(other.data()) + , mend(other.data() + other.size()) + { + } +#endif + //************************************************************************* /// Returns a const reference to the first element. //************************************************************************* @@ -747,6 +763,30 @@ namespace etl return find_last_not_of(etl::basic_string_view(text), position); } + //********************************************************************* + /// Checks that the view is within this string + //********************************************************************* + bool contains(const etl::basic_string_view& view) const + { + return find(view) != npos; + } + + //********************************************************************* + /// Checks that text is within this string + //********************************************************************* + bool contains(const_pointer s) const + { + return find(s) != npos; + } + + //********************************************************************* + /// Checks that character is within this string + //********************************************************************* + bool contains(value_type c) const + { + return find(c) != npos; + } + //************************************************************************* /// Equality for string_view. //************************************************************************* diff --git a/include/etl/u16string.h b/include/etl/u16string.h index c0fea3a2..69eb25bc 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -227,6 +227,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u16string& operator = (const etl::u16string_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* @@ -366,8 +376,8 @@ namespace etl #endif //************************************************************************* - /// From u16string_view. - ///\param view The u16string_view. + /// From string_view. + ///\param view The string_view. //************************************************************************* explicit u16string_ext(const etl::u16string_view& view, value_type* buffer, size_type buffer_size) : iu16string(buffer, buffer_size - 1U) @@ -388,7 +398,6 @@ namespace etl return *this; } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -412,6 +421,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u16string_ext& operator = (const etl::u16string_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/u32string.h b/include/etl/u32string.h index 766a0cbc..029748aa 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -227,6 +227,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u32string& operator = (const etl::u32string_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* @@ -366,8 +376,8 @@ namespace etl #endif //************************************************************************* - /// From u32string_view. - ///\param view The u32string_view. + /// From string_view. + ///\param view The string_view. //************************************************************************* explicit u32string_ext(const etl::u32string_view& view, value_type* buffer, size_type buffer_size) : iu32string(buffer, buffer_size - 1U) @@ -388,7 +398,6 @@ namespace etl return *this; } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -412,6 +421,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u32string_ext& operator = (const etl::u32string_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/u8string.h b/include/etl/u8string.h index 015ef3c1..7510c4f6 100644 --- a/include/etl/u8string.h +++ b/include/etl/u8string.h @@ -244,6 +244,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u8string& operator = (const etl::u8string_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* @@ -409,7 +419,6 @@ namespace etl return *this; } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -433,6 +442,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u8string_ext& operator = (const etl::u8string_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/wstring.h b/include/etl/wstring.h index 683359de..7107c7d8 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -227,6 +227,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + wstring& operator = (const etl::wstring_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* @@ -366,8 +376,8 @@ namespace etl #endif //************************************************************************* - /// From wstring_view. - ///\param view The wstring_view. + /// From string_view. + ///\param view The string_view. //************************************************************************* explicit wstring_ext(const etl::wstring_view& view, value_type* buffer, size_type buffer_size) : iwstring(buffer, buffer_size - 1U) @@ -388,7 +398,6 @@ namespace etl return *this; } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -412,6 +421,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + wstring_ext& operator = (const etl::wstring_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/test/run-tests.sh b/test/run-tests.sh index cb5a9d12..4b45ba3b 100644 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -154,9 +154,9 @@ fi # Set the sanitizer enable. Default OFF #****************************************************************************** if [ "$4" = "S" ]; then - sanitize="ON" + sanitize="On" else - sanitize="OFF" + sanitize="Off" fi #****************************************************************************** diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index b49e8814..7c118ff8 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -33,6 +33,7 @@ SOFTWARE. #include #include "etl/string.h" +#include "etl/string_view.h" #include "etl/fnv_1.h" #undef STR @@ -51,21 +52,22 @@ namespace { static const size_t SIZE = 11UL; - using Text = etl::string; - using IText = etl::istring; - using CompareText = std::string; - using value_t = Text::value_type; - using TextL = etl::string<52>; - using TextS = etl::string<4>; + using Text = etl::string; + using IText = etl::istring; + using TextSTD = std::string; + using value_t = Text::value_type; + using TextL = etl::string<52>; + using TextS = etl::string<4>; + using View = etl::string_view; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; const value_t* pinitial_text = STR("Hello World"); @@ -127,7 +129,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE); CHECK(text.size() == INITIAL_SIZE); @@ -155,7 +157,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); @@ -171,7 +173,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(longer_text.c_str()); @@ -187,7 +189,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE, STR('A')); @@ -203,7 +205,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE + 1, STR('A')); @@ -219,7 +221,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); Text text(initial_text.c_str(), initial_text.size() / 2); @@ -235,7 +237,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); Text text(longer_text.c_str(), longer_text.size()); @@ -251,7 +253,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(compare_text.begin(), compare_text.end()); @@ -288,9 +290,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::string_view view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -347,8 +349,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); Text text(initial_text.c_str()); Text text2(text, 2, 4); @@ -363,8 +365,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextL textl(longer_text.c_str()); Text text2(textl, 2, 12); @@ -380,7 +382,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; Text text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; bool is_equal = Equal(compare_text, text); @@ -393,7 +395,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), @@ -524,7 +526,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -538,7 +540,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -553,7 +555,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -568,13 +570,27 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_view) + { + Text text; + + text = View(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { @@ -709,7 +725,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK_EQUAL(NEW_SIZE, text.size()); } //************************************************************************* @@ -722,7 +738,7 @@ namespace text.uninitialized_resize(NEW_SIZE); - CHECK_EQUAL(text.size(), SIZE); + CHECK_EQUAL(SIZE, text.size()); } //************************************************************************* @@ -750,7 +766,65 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK_EQUAL(NEW_SIZE, text.size()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + Text text(initial_text.c_str(), initial_text.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); } //************************************************************************* @@ -842,7 +916,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -858,7 +932,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -874,7 +948,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -892,7 +966,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -910,7 +984,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -922,7 +996,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -934,7 +1008,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -946,7 +1020,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -958,7 +1032,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(compare_text.begin(), compare_text.end()); @@ -975,7 +1049,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); const Text text(compare_text.begin(), compare_text.end()); @@ -992,10 +1066,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1008,13 +1082,33 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_view) + { + TextSTD compare_input(initial_text.c_str()); + Text input(initial_text.c_str()); + View view(input); + + TextSTD compare_text; + Text text; + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextL input(longer_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1030,7 +1124,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str()); @@ -1045,7 +1139,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(longer_text.c_str()); @@ -1060,7 +1154,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str(), initial_text.size()); @@ -1075,7 +1169,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); Text text; text.assign(longer_text.c_str(), longer_text.size()); @@ -1092,7 +1186,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; @@ -1164,7 +1258,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1190,7 +1284,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1221,7 +1315,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); compare_text.pop_back(); @@ -1245,7 +1339,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1265,7 +1359,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); const value_t INITIAL_VALUE = STR('A'); @@ -1310,7 +1404,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INITIAL_SIZE = 5UL; @@ -1336,7 +1430,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INSERT_SIZE = 4UL; @@ -1409,7 +1503,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); @@ -1432,7 +1526,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; Text text; size_t offset = 0UL; @@ -1490,7 +1584,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); text.insert(text.cbegin() + offset, text.cbegin() + 5, text.cbegin() + 10); @@ -1509,7 +1603,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); Text insert(insert_text.cbegin(), insert_text.cend()); @@ -1525,12 +1619,33 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + View view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); Text text(initial_text.cbegin(), initial_text.cend()); Text insert(insert_text.cbegin(), insert_text.cend()); @@ -1551,7 +1666,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); Text insert(longer_text.cbegin(), longer_text.cend()); insert.erase(insert.cbegin(), insert.cend()); @@ -1572,7 +1687,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); Text insert(insert_text.cbegin(), insert_text.cend()); @@ -1618,7 +1733,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1648,6 +1763,39 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_view) + { + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + View view(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1668,7 +1816,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1699,12 +1847,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); // Whole string. - compare_text.append(insert_text, 0, std::string::npos); + compare_text.append(insert_text, 0, TextSTD::npos); text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); @@ -1763,7 +1911,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Whole string. @@ -1795,7 +1943,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1827,7 +1975,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1860,10 +2008,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -1877,7 +2025,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -1891,7 +2039,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -1905,7 +2053,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -1919,7 +2067,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -1933,7 +2081,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -1947,7 +2095,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -1958,14 +2106,116 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) + { + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); @@ -1979,7 +2229,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -1993,7 +2243,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); @@ -2007,7 +2257,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2018,14 +2268,74 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")), 1, 5); @@ -2039,7 +2349,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2053,7 +2363,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2067,7 +2377,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2081,7 +2391,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")), 1, 5); @@ -2095,7 +2405,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2109,7 +2419,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2123,7 +2433,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2134,14 +2444,130 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")).c_str()); @@ -2155,7 +2581,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); @@ -2169,7 +2595,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); @@ -2183,7 +2609,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); @@ -2197,7 +2623,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")).c_str()); @@ -2211,7 +2637,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); @@ -2225,7 +2651,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); @@ -2239,7 +2665,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); @@ -2254,10 +2680,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); @@ -2271,7 +2697,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); @@ -2285,7 +2711,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); @@ -2299,7 +2725,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); @@ -2314,10 +2740,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); @@ -2331,7 +2757,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); @@ -2345,7 +2771,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2359,7 +2785,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); @@ -2373,7 +2799,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); @@ -2387,7 +2813,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); @@ -2401,7 +2827,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2415,7 +2841,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); @@ -2430,10 +2856,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); @@ -2449,7 +2875,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2465,7 +2891,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); @@ -2481,7 +2907,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2498,7 +2924,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, 7, STR('A')); @@ -2515,7 +2941,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2543,7 +2969,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2571,7 +2997,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2599,7 +3025,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2614,7 +3040,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); @@ -2674,11 +3100,11 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -2736,10 +3162,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.begin() + 2); Text::iterator ditr = text.erase(text.begin() + 2); CHECK(*citr == *ditr); @@ -2753,10 +3179,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2); Text::iterator ditr = text.erase(text.cbegin() + 2); CHECK(*citr == *ditr); @@ -2770,10 +3196,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); CHECK(*citr == *ditr); @@ -2799,7 +3225,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); @@ -2812,7 +3238,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); @@ -2825,7 +3251,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); @@ -2838,7 +3264,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); @@ -3025,7 +3451,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3066,13 +3492,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3092,7 +3518,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3120,11 +3546,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_needle(STR("needle")); - etl::string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -3138,11 +3564,42 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.find(pin); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); + View needle_view(needle); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(Text::npos, position2); + + View pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3152,8 +3609,8 @@ namespace const value_t* needle = STR("needle"); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -3167,11 +3624,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t *pin = STR("pin"); position2 = haystack.find(pin); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3181,8 +3638,8 @@ namespace const value_t* needle = STR("needle"); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -3196,11 +3653,137 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1, 3); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text needle(STR("needle")); + Text pin(STR("pin")); + Text excess(STR("A really gigantic pin or needle that's really really big")); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + CHECK_FALSE(haystack.contains(View(STR("A really gigantic pin or needle that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + CHECK_FALSE(haystack.contains(STR("A really gigantic pin or needle that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text start(STR("A haystack")); + Text not_start(STR("a needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text end(STR("else")); + Text not_end(STR("needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); } //************************************************************************* @@ -3208,14 +3791,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_needle(STR("needle")); - etl::string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3225,9 +3808,37 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); + View needle_view(needle); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + View pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3235,13 +3846,13 @@ namespace { const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3251,9 +3862,9 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3261,13 +3872,13 @@ namespace { const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); position2 = haystack.rfind(needle, position2, 3); @@ -3278,7 +3889,7 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3286,11 +3897,11 @@ namespace { const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - etl::istring::size_type position1 = etl::istring::npos; - size_t position2 = etl::string<50>::npos; + etl::istring::size_type position1 = TextL::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3301,16 +3912,16 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_substr) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText compare_result; + TextSTD compare_result; Text result; // Equal. @@ -3345,112 +3956,217 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_view) + { + TextSTD compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; @@ -3485,7 +4201,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3520,7 +4236,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3555,36 +4271,65 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(Text(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(Text(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(Text(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(Text(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF")); @@ -3613,7 +4358,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); @@ -3647,7 +4392,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR('C')); @@ -3686,41 +4431,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(Text(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(Text(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(Text(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(Text(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(Text(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("ZCXE")); @@ -3759,7 +4538,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); @@ -3796,7 +4575,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_of(STR('C')); @@ -3835,41 +4614,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(Text(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(Text(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(Text(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); @@ -3903,7 +4716,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); @@ -3942,7 +4755,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR('A')); @@ -3981,41 +4794,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(Text(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(Text(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(Text(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(Text(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(Text(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); @@ -4049,7 +4896,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); @@ -4081,7 +4928,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_not_of(STR('F')); diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index d934dafe..3eb26da5 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -33,6 +33,7 @@ SOFTWARE. #include #include "etl/string.h" +#include "etl/string_view.h" #include "etl/fnv_1.h" #undef STR @@ -53,24 +54,26 @@ namespace static constexpr size_t SIZE_L = 52UL; static constexpr size_t SIZE_S = 4UL; - using Text = etl::string_ext; - using IText = etl::istring; - using TextL = etl::string; - using CompareText = std::string; - using value_t = Text::value_type; + using Text = etl::string_ext; + using IText = etl::istring; + using TextL = etl::string; + using TextSTD = std::string; + using value_t = Text::value_type; using TextBuffer = std::array; using TextBufferL = std::array; using TextBufferS = std::array; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + using View = etl::string_view; + + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; const value_t* pinitial_text = STR("Hello World"); @@ -201,7 +204,7 @@ namespace const value_t INITIAL_VALUE = STR('A'); TextBuffer buffer{0}; - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE, buffer.data(), buffer.size()); CHECK(text.size() == INITIAL_SIZE); @@ -231,7 +234,7 @@ namespace TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { TextBuffer buffer{0}; - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -247,7 +250,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); @@ -264,7 +267,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE, STR('A'), buffer.data(), buffer.size()); @@ -281,7 +284,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE + 1, STR('A'), buffer.data(), buffer.size()); @@ -298,7 +301,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); TextBuffer buffer{0}; Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); @@ -315,7 +318,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); TextBuffer buffer{0}; Text text(longer_text.c_str(), longer_text.size(), buffer.data(), buffer.size()); @@ -332,7 +335,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -372,10 +375,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::string_view view(initial_text.data(), initial_text.size()); - + View view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -448,8 +450,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -467,8 +469,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextBufferL bufferl{0}; Text textl(longer_text.c_str(), bufferl.data(), bufferl.size()); @@ -487,7 +489,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; std::initializer_list il = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; TextBuffer buffer{0}; @@ -503,7 +505,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; std::initializer_list il = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), @@ -656,7 +658,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -671,7 +673,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -687,7 +689,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -703,13 +705,28 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text = View(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { @@ -902,6 +919,67 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), initial_text.size(), buffer.data(), buffer.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_full) { @@ -981,7 +1059,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -999,7 +1077,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1017,7 +1095,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1037,7 +1115,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1057,7 +1135,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1071,7 +1149,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1085,7 +1163,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1099,7 +1177,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1113,7 +1191,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1131,7 +1209,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1149,12 +1227,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer2{0}; Text text(buffer2.data(), buffer2.size()); @@ -1169,15 +1247,37 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_view) + { + TextSTD compare_input(initial_text.c_str()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + View view(input); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBufferL bufferl{0}; Text input(longer_text.c_str(), bufferl.data(), bufferl.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1195,7 +1295,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1211,7 +1311,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1227,7 +1327,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1243,7 +1343,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1261,7 +1361,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1337,7 +1437,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1365,7 +1465,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1398,7 +1498,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1424,7 +1524,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1446,7 +1546,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1492,7 +1592,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1519,7 +1619,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1593,7 +1693,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1617,7 +1717,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1676,7 +1776,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl{0}; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); @@ -1697,8 +1797,8 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer{0}; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1717,12 +1817,35 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer{0}; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + View view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1747,7 +1870,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1773,7 +1896,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1823,7 +1946,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1857,6 +1980,40 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_view) + { + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + View view(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1880,7 +2037,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1913,7 +2070,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1922,7 +2079,7 @@ namespace Text append(insert_text.c_str(), buffer2.data(), buffer2.size()); // Whole string. - compare_text.append(insert_text, 0, std::string::npos); + compare_text.append(insert_text, 0, TextSTD::npos); text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); @@ -1984,7 +2141,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2018,7 +2175,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2052,7 +2209,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2089,12 +2246,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -2108,7 +2265,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -2122,7 +2279,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2136,7 +2293,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2150,7 +2307,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -2164,7 +2321,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2178,7 +2335,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2189,16 +2346,119 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) + { + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); @@ -2212,7 +2472,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2226,7 +2486,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); @@ -2240,7 +2500,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2251,16 +2511,77 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")), 1, 5); @@ -2274,7 +2595,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2288,7 +2609,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2302,7 +2623,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2316,7 +2637,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")), 1, 5); @@ -2330,7 +2651,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2344,7 +2665,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2358,7 +2679,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2369,16 +2690,133 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")).c_str()); @@ -2392,7 +2830,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); @@ -2406,7 +2844,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); @@ -2420,7 +2858,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); @@ -2434,7 +2872,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")).c_str()); @@ -2448,7 +2886,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); @@ -2462,7 +2900,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); @@ -2476,7 +2914,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); @@ -2491,12 +2929,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); @@ -2510,7 +2948,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); @@ -2524,7 +2962,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); @@ -2538,7 +2976,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); @@ -2553,12 +2991,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); @@ -2572,7 +3010,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); @@ -2586,7 +3024,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2600,7 +3038,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); @@ -2614,7 +3052,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); @@ -2628,7 +3066,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); @@ -2642,7 +3080,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2656,7 +3094,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); @@ -2671,12 +3109,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); @@ -2692,7 +3130,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2708,7 +3146,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); @@ -2724,7 +3162,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2741,7 +3179,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2760,7 +3198,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2788,7 +3226,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2816,7 +3254,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2844,7 +3282,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2859,7 +3297,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2921,13 +3359,13 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -2985,7 +3423,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3003,7 +3441,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3035,7 +3473,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3050,7 +3488,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3065,7 +3503,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3080,7 +3518,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3299,7 +3737,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3343,7 +3781,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3351,7 +3789,7 @@ namespace value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3371,7 +3809,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3401,12 +3839,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBuffer buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); @@ -3423,13 +3861,44 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::string<50> pin(STR("pin")); + Text pin(STR("pin"), buffer.data(), buffer.size()); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(TextL::npos, position2); + + View pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) { @@ -3437,7 +3906,7 @@ namespace const value_t* needle = STR("needle"); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3468,7 +3937,7 @@ namespace const value_t* needle = STR("needle"); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3492,23 +3961,168 @@ namespace CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text needle(STR("needle"), buffer2.data(), buffer2.size()); + Text pin(STR("pin"), buffer3.data(), buffer3.size()); + Text excess(STR("A really gigantic pin or needle that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text start(STR("A haystack"), buffer2.data(), buffer2.size()); + Text not_start(STR("a needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text end(STR("else"), buffer2.data(), buffer2.size()); + Text not_end(STR("needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBufferL buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3524,20 +4138,47 @@ namespace CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + View pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) { const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3558,14 +4199,14 @@ namespace { const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; @@ -3586,13 +4227,13 @@ namespace { const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3609,7 +4250,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3618,35 +4259,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3655,35 +4332,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3692,35 +4405,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, TextL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3757,7 +4506,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3794,7 +4543,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3831,38 +4580,68 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(TextL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(TextL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(TextL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(TextL(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3893,7 +4672,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3929,7 +4708,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3970,43 +4749,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(TextL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(TextL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(TextL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(TextL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(TextL(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4047,7 +4861,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4088,7 +4902,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4129,43 +4943,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(TextL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4201,7 +5050,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4242,7 +5091,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4283,43 +5132,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(TextL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(TextL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4355,7 +5239,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4389,7 +5273,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index 7d529521..37465e2a 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -66,21 +66,22 @@ namespace { static const size_t SIZE = 11; - using Text = etl::u16string; - using IText = etl::iu16string; - using CompareText = std::u16string; - using value_t = Text::value_type; - using TextL = etl::u16string<52>; - using TextS = etl::u16string<4>; + using Text = etl::u16string; + using IText = etl::iu16string; + using TextSTD = std::u16string; + using value_t = Text::value_type; + using TextL = etl::u16string<52>; + using TextS = etl::u16string<4>; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; + using View = etl::u16string_view; const value_t* pinitial_text = STR("Hello World"); @@ -143,7 +144,7 @@ namespace const size_t INITIAL_SIZE = 5; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE); CHECK(text.size() == INITIAL_SIZE); @@ -171,7 +172,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); @@ -187,7 +188,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(longer_text.c_str()); @@ -203,7 +204,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE, STR('A')); @@ -219,7 +220,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE + 1, STR('A')); @@ -235,7 +236,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); Text text(initial_text.c_str(), initial_text.size() / 2); @@ -251,7 +252,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); Text text(longer_text.c_str(), longer_text.size()); @@ -267,7 +268,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(compare_text.begin(), compare_text.end()); @@ -304,9 +305,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::u16string_view view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -363,8 +364,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); Text text(initial_text.c_str()); Text text2(text, 2, 4); @@ -379,8 +380,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextL textl(longer_text.c_str()); Text text2(textl, 2, 12); @@ -396,7 +397,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; Text text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; bool is_equal = Equal(compare_text, text); @@ -409,7 +410,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), @@ -540,7 +541,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u16string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -554,7 +555,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u16string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -569,7 +570,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u16string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -584,13 +585,27 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u16string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_view) + { + Text text; + + text = View(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { @@ -768,6 +783,64 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + Text text(initial_text.c_str(), initial_text.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_fill) { @@ -857,7 +930,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -873,7 +946,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -889,7 +962,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -907,7 +980,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -925,7 +998,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -937,7 +1010,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -949,7 +1022,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -961,7 +1034,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -973,7 +1046,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(compare_text.begin(), compare_text.end()); @@ -990,7 +1063,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); const Text text(compare_text.begin(), compare_text.end()); @@ -1007,10 +1080,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1023,13 +1096,33 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_view) + { + TextSTD compare_input(initial_text.c_str()); + Text input(initial_text.c_str()); + View view(input); + + TextSTD compare_text; + Text text; + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextL input(longer_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1045,7 +1138,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str()); @@ -1060,7 +1153,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(longer_text.c_str()); @@ -1075,7 +1168,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str(), initial_text.size()); @@ -1090,7 +1183,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); Text text; text.assign(longer_text.c_str(), longer_text.size()); @@ -1107,7 +1200,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; @@ -1179,7 +1272,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1205,7 +1298,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1236,7 +1329,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); compare_text.pop_back(); @@ -1260,7 +1353,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1280,7 +1373,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); const value_t INITIAL_VALUE = STR('A'); @@ -1325,7 +1418,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INITIAL_SIZE = 5; @@ -1351,7 +1444,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INSERT_SIZE = 4; @@ -1424,7 +1517,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1447,7 +1540,7 @@ namespace const size_t INITIAL_SIZE = 5; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; Text text; size_t offset = 0; @@ -1505,7 +1598,7 @@ namespace for (size_t offset = 10; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); @@ -1524,7 +1617,7 @@ namespace { for (size_t offset = 0; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1540,12 +1633,33 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + View view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { for (size_t offset = 0; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1566,7 +1680,7 @@ namespace { for (size_t offset = 0; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(longer_text.begin(), longer_text.end()); insert.erase(insert.begin(), insert.end()); @@ -1587,7 +1701,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1633,7 +1747,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1663,6 +1777,39 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_view) + { + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + View view(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1683,7 +1830,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1714,12 +1861,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); // Whole string. - compare_text.append(insert_text, 0, std::u16string::npos); + compare_text.append(insert_text, 0, TextSTD::npos); text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); @@ -1778,7 +1925,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Whole string. @@ -1810,7 +1957,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1842,7 +1989,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1875,10 +2022,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -1892,7 +2039,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -1906,7 +2053,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -1920,7 +2067,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -1934,7 +2081,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -1948,7 +2095,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -1962,7 +2109,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -1973,14 +2120,116 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) + { + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); @@ -1994,7 +2243,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2008,7 +2257,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); @@ -2022,7 +2271,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2033,14 +2282,74 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")), 1, 5); @@ -2054,7 +2363,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2068,7 +2377,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2082,7 +2391,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2096,7 +2405,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")), 1, 5); @@ -2110,7 +2419,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2124,7 +2433,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2138,7 +2447,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2149,11 +2458,127 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, STR("Replace")); @@ -2170,7 +2595,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace")); @@ -2198,7 +2623,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text")); @@ -2226,7 +2651,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace")); @@ -2254,7 +2679,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text")); @@ -2269,7 +2694,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); @@ -2329,7 +2754,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, STR("Replace"), 5); @@ -2346,7 +2771,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace"), 5); @@ -2374,7 +2799,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text"), 15); @@ -2402,7 +2827,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace"), 5); @@ -2430,7 +2855,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text"), 15); @@ -2445,7 +2870,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); @@ -2513,7 +2938,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, 7, STR('A')); @@ -2530,7 +2955,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2558,7 +2983,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2586,7 +3011,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2614,7 +3039,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2629,7 +3054,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); @@ -2689,11 +3114,11 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -2751,10 +3176,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.begin() + 2); Text::iterator ditr = text.erase(text.begin() + 2); CHECK(*citr == *ditr); @@ -2768,10 +3193,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2); Text::iterator ditr = text.erase(text.cbegin() + 2); CHECK(*citr == *ditr); @@ -2785,10 +3210,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); CHECK(*citr == *ditr); @@ -2814,7 +3239,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); @@ -2827,7 +3252,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); @@ -2840,7 +3265,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); @@ -2853,7 +3278,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); @@ -3040,7 +3465,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3081,13 +3506,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3107,7 +3532,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3135,11 +3560,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_needle(STR("needle")); - etl::u16string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -3153,11 +3578,42 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u16string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u16string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); + View needle_view(needle); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(Text::npos, position2); + + View pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3167,8 +3623,8 @@ namespace const value_t* needle = STR("needle"); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -3182,11 +3638,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t* pin = STR("pin"); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3196,8 +3652,8 @@ namespace const value_t* needle = STR("needle"); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -3211,11 +3667,137 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1, 3); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t* pin = STR("pin"); position2 = haystack.find(pin, 0, 3); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text needle(STR("needle")); + Text pin(STR("pin")); + Text excess(STR("A really gigantic pin or needle that's really really big")); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + CHECK_FALSE(haystack.contains(View(STR("A really gigantic pin or needle that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + CHECK_FALSE(haystack.contains(STR("A really gigantic pin or needle that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text start(STR("A haystack")); + Text not_start(STR("a needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text end(STR("else")); + Text not_end(STR("needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); } //************************************************************************* @@ -3223,14 +3805,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_needle(STR("needle")); - etl::u16string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3240,9 +3822,37 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u16string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); + View needle_view(needle); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + View pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3250,13 +3860,13 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3266,9 +3876,9 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u16string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3276,13 +3886,13 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); position2 = haystack.rfind(needle, position2, 3); @@ -3293,7 +3903,7 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3301,11 +3911,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3316,16 +3926,16 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_substr) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText compare_result; + TextSTD compare_result; Text result; // Equal. @@ -3360,112 +3970,217 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_view) + { + TextSTD compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; @@ -3500,7 +4215,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3535,7 +4250,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3570,36 +4285,65 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(Text(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(Text(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(Text(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(Text(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF")); @@ -3628,7 +4372,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); @@ -3662,7 +4406,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR('C')); @@ -3701,41 +4445,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(Text(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(Text(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(Text(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(Text(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(Text(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("ZCXE")); @@ -3774,7 +4552,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); @@ -3811,7 +4589,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_of(STR('C')); @@ -3850,41 +4628,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(Text(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(Text(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(Text(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); @@ -3918,7 +4730,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); @@ -3957,7 +4769,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR('A')); @@ -3996,41 +4808,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(Text(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(Text(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(Text(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(Text(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(Text(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); @@ -4064,7 +4910,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); @@ -4096,7 +4942,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_not_of(STR('F')); diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index 8e271ad6..c94fdad0 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -72,20 +72,22 @@ namespace using Text = etl::u16string_ext; using IText = etl::iu16string; using TextL = etl::u16string; - using CompareText = std::u16string; + using TextSTD = std::u16string; using value_t = Text::value_type; using TextBuffer = std::array; using TextBufferL = std::array; using TextBufferS = std::array; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + using View = etl::u16string_view; + + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; const value_t* pinitial_text = STR("Hello World"); @@ -200,9 +202,9 @@ namespace TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -212,11 +214,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); TextBuffer buffer{0}; - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE, buffer.data(), buffer.size()); CHECK(text.size() == INITIAL_SIZE); @@ -246,7 +248,7 @@ namespace TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { TextBuffer buffer{0}; - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -262,7 +264,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); @@ -279,7 +281,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE, STR('A'), buffer.data(), buffer.size()); @@ -296,7 +298,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE + 1, STR('A'), buffer.data(), buffer.size()); @@ -313,7 +315,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); TextBuffer buffer{0}; Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); @@ -330,7 +332,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); TextBuffer buffer{0}; Text text(longer_text.c_str(), longer_text.size(), buffer.data(), buffer.size()); @@ -347,7 +349,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -387,10 +389,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::u16string_view view(initial_text.data(), initial_text.size()); - + View view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -463,8 +464,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -482,8 +483,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextBufferL bufferl{0}; Text textl(longer_text.c_str(), bufferl.data(), bufferl.size()); @@ -502,7 +503,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; std::initializer_list il = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; TextBuffer buffer{0}; @@ -518,12 +519,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; std::initializer_list il = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), - STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; TextBuffer buffer{0}; Text text(il, buffer.data(), buffer.size()); @@ -671,7 +672,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u16string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -686,7 +687,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u16string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -702,7 +703,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u16string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -718,13 +719,28 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u16string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text = View(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { @@ -847,7 +863,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 8; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -891,7 +907,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 2; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -918,21 +934,38 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_fill) + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) { - TextBuffer buffer1{ 0 }; - TextBuffer buffer2{ 0 }; - Text text(11, STR('A'), buffer1.data(), buffer1.size()); - Text expected(11, STR('B'), buffer2.data(), buffer2.size()); + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; - text.fill(STR('B')); + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); - bool is_equal = Equal(expected, text); - CHECK(is_equal); + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), initial_text.size(), buffer.data(), buffer.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); } //************************************************************************* @@ -1014,7 +1047,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1032,7 +1065,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1050,7 +1083,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1070,7 +1103,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1090,7 +1123,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1104,7 +1137,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1118,7 +1151,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1132,7 +1165,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1146,7 +1179,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1164,7 +1197,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1182,12 +1215,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer2{0}; Text text(buffer2.data(), buffer2.size()); @@ -1202,15 +1235,37 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_view) + { + TextSTD compare_input(initial_text.c_str()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + View view(input); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBufferL bufferl{0}; Text input(longer_text.c_str(), bufferl.data(), bufferl.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1228,7 +1283,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1244,7 +1299,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1260,7 +1315,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1276,7 +1331,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1294,7 +1349,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1370,7 +1425,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1398,7 +1453,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1431,7 +1486,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1453,11 +1508,11 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1479,7 +1534,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1525,7 +1580,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1552,7 +1607,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1626,7 +1681,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1650,7 +1705,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1709,7 +1764,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl{0}; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); @@ -1728,18 +1783,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - size_t s = short_text.size(); - (void)s; - - assert(s <= 5); - - for (size_t offset = s; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer{0}; + buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - TextBuffer buffer2{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + TextBuffer buffer2{0}; Text insert(insert_text.begin(), insert_text.end(), buffer2.data(), buffer2.size()); text.insert(offset, insert); @@ -1755,23 +1806,39 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_2) + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer{0}; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + View view(insert_text.data(), insert_text.size()); + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } } - //************************************************************************* + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { -#include "etl/private/diagnostic_array_bounds_push.h" for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); - TextBuffer buffer{ 0 }; + TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); - TextBuffer buffer2{ 0 }; + TextBuffer buffer2{0}; Text insert(insert_text.begin(), insert_text.end(), buffer2.data(), buffer2.size()); text.insert(offset, insert); @@ -1784,7 +1851,6 @@ namespace CHECK(text.is_truncated()); #endif } -#include "etl/private/diagnostic_pop.h" } //************************************************************************* @@ -1792,7 +1858,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1818,7 +1884,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1868,7 +1934,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1902,6 +1968,40 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_view) + { + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + View view(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1925,7 +2025,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1958,7 +2058,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1967,7 +2067,7 @@ namespace Text append(insert_text.c_str(), buffer2.data(), buffer2.size()); // Whole string. - compare_text.append(insert_text, 0, std::u16string::npos); + compare_text.append(insert_text, 0, TextSTD::npos); text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); @@ -2029,7 +2129,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2063,7 +2163,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2097,7 +2197,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2134,12 +2234,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -2153,7 +2253,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -2167,7 +2267,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2181,7 +2281,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2195,7 +2295,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -2209,7 +2309,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2223,7 +2323,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2234,16 +2334,119 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) + { + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); @@ -2257,7 +2460,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2271,7 +2474,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); @@ -2285,7 +2488,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2296,16 +2499,77 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")), 1, 5); @@ -2319,7 +2583,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2333,7 +2597,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2347,7 +2611,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2361,7 +2625,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")), 1, 5); @@ -2375,7 +2639,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2389,7 +2653,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2403,7 +2667,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2414,18 +2678,135 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + text.replace(2, 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2437,9 +2818,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2451,9 +2832,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2465,9 +2846,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2479,9 +2860,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace")); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + text.replace(2, 7, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2493,9 +2874,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2507,9 +2888,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2521,9 +2902,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2536,14 +2917,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2555,9 +2936,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2569,9 +2950,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2583,9 +2964,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2598,14 +2979,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2617,9 +2998,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2631,9 +3012,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2645,9 +3026,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2659,9 +3040,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace"), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2673,9 +3054,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2687,9 +3068,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2701,9 +3082,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2716,14 +3097,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2737,9 +3118,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2753,9 +3134,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2769,9 +3150,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2786,7 +3167,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2805,7 +3186,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2833,7 +3214,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2861,7 +3242,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2889,7 +3270,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2904,7 +3285,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2966,13 +3347,13 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -3028,33 +3409,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_iterator) + TEST_FIXTURE(SetupFixture, test_erase_single) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); - Text::iterator ditr = text.erase(text.begin() + 2); - CHECK(*citr == *ditr); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) - { - CompareText compare_text(initial_text.c_str()); - TextBuffer buffer{0}; - Text text(initial_text.c_str(), buffer.data(), buffer.size()); - - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); - Text::iterator ditr = text.erase(text.cbegin() + 2); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2); + text.erase(text.begin() + 2); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3066,13 +3429,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); - Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); + + text.erase(text.begin() + 2, text.begin() + 4); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3097,7 +3461,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3112,7 +3476,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3127,7 +3491,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3142,7 +3506,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3208,7 +3572,7 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); TextBuffer buffer3; @@ -3225,17 +3589,17 @@ namespace CHECK((initial < initial) == (initial_text < initial_text)); // String-Pointer Pointer-String - CHECK((less < pinitial_text) == (less_text < pinitial_text)); - CHECK((pinitial_text < less) == (pinitial_text < less_text)); + CHECK((less < pinitial_text) == (less_text < pinitial_text)); + CHECK((pinitial_text < less) == (pinitial_text < less_text)); - CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); - CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); + CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); + CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); - CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); - CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); + CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); + CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); - CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); - CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -3248,8 +3612,8 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); TextBuffer buffer3; const Text greater(greater_text.c_str(), buffer3.data(), buffer3.size()); @@ -3265,17 +3629,17 @@ namespace CHECK((initial <= initial) == (initial_text <= initial_text)); // String-Pointer Pointer-String - CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); - CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); + CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); + CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); - CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); - CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); + CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); + CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); - CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); - CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); + CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); + CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); - CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); - CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -3305,17 +3669,17 @@ namespace CHECK((initial > initial) == (initial_text > initial_text)); // String-Pointer Pointer-String - CHECK((less > pinitial_text) == (less_text > pinitial_text)); - CHECK((pinitial_text > less) == (pinitial_text > less_text)); + CHECK((less > pinitial_text) == (less_text > pinitial_text)); + CHECK((pinitial_text > less) == (pinitial_text > less_text)); - CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); - CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); + CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); + CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); - CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); - CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); + CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); + CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); - CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); - CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3328,8 +3692,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end(), buffer2.data(), buffer2.size()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); TextBuffer buffer3; const Text greater(greater_text.begin(), greater_text.end(), buffer3.data(), buffer3.size()); @@ -3345,24 +3709,24 @@ namespace CHECK((initial >= initial) == (initial_text >= initial_text)); // String-Pointer Pointer-String - CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); - CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); + CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); + CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); - CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); - CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); + CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); + CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); - CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); - CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); + CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); + CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); - CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); - CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); - + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3381,8 +3745,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3405,7 +3769,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3413,7 +3777,7 @@ namespace value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3425,15 +3789,15 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3453,8 +3817,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3463,12 +3827,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBuffer buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u16string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); @@ -3485,13 +3849,44 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u16string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u16string<50> pin(STR("pin")); + Text pin(STR("pin"), buffer.data(), buffer.size()); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(TextL::npos, position2); + + View pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) { @@ -3499,7 +3894,7 @@ namespace const value_t* needle = STR("needle"); - std::u16string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3518,7 +3913,7 @@ namespace position2 = haystack.find(needle, position2 + 1); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } @@ -3530,7 +3925,7 @@ namespace const value_t* needle = STR("needle"); - std::u16string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3549,28 +3944,173 @@ namespace position2 = haystack.find(needle, position2 + 1, 3); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text needle(STR("needle"), buffer2.data(), buffer2.size()); + Text pin(STR("pin"), buffer3.data(), buffer3.size()); + Text excess(STR("A really gigantic pin or needle that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text start(STR("A haystack"), buffer2.data(), buffer2.size()); + Text not_start(STR("a needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text end(STR("else"), buffer2.data(), buffer2.size()); + Text not_end(STR("needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBufferL buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u16string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3587,19 +4127,46 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_pointer) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_haystack(the_haystack); + TextSTD compare_needle(STR("needle")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + View pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_pointer) + { + const value_t*the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3618,16 +4185,16 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u16string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; @@ -3646,15 +4213,15 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_c_position) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3671,7 +4238,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3680,35 +4247,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3717,35 +4320,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3754,35 +4393,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, TextL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3819,7 +4494,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3856,7 +4531,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3893,38 +4568,68 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(TextL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(TextL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(TextL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(TextL(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3955,7 +4660,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3991,7 +4696,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4032,43 +4737,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(TextL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(TextL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(TextL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(TextL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(TextL(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4109,7 +4849,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4139,16 +4879,18 @@ namespace CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(STR("ZCXE"), 100, 4); position2 = text.find_last_of(STR("ZCXE"), 100, 4); CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" } //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4189,43 +4931,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(TextL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4261,7 +5038,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4302,7 +5079,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4343,43 +5120,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(TextL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(TextL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4415,7 +5227,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4449,7 +5261,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index fa1c199c..b72ef01e 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -66,21 +66,22 @@ namespace { static const size_t SIZE = 11; - using Text = etl::u32string; - using IText = etl::iu32string; - using CompareText = std::u32string; - using value_t = Text::value_type; - using TextL = etl::u32string<52>; - using TextS = etl::u32string<4>; + using Text = etl::u32string; + using IText = etl::iu32string; + using TextSTD = std::u32string; + using value_t = Text::value_type; + using TextL = etl::u32string<52>; + using TextS = etl::u32string<4>; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; + using View = etl::u32string_view; const value_t* pinitial_text = STR("Hello World"); @@ -96,15 +97,15 @@ namespace { SetupFixture() { - initial_text = STR("Hello World"); - initial_text = STR("Hello World"); - insert_text = STR("Insert"); - less_text = STR("Hello Vorld"); - greater_text = STR("Hello Xorld"); - shorter_text = STR("Hello Worl"); + initial_text = STR("Hello World"); + initial_text = STR("Hello World"); + insert_text = STR("Insert"); + less_text = STR("Hello Vorld"); + greater_text = STR("Hello Xorld"); + shorter_text = STR("Hello Worl"); different_text = STR("Byee Planet"); - longer_text = STR("Hello World There"); - short_text = STR("Hello"); + longer_text = STR("Hello World There"); + short_text = STR("Hello"); } }; @@ -143,7 +144,7 @@ namespace const size_t INITIAL_SIZE = 5; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE); CHECK(text.size() == INITIAL_SIZE); @@ -171,7 +172,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); @@ -187,7 +188,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(longer_text.c_str()); @@ -203,7 +204,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE, STR('A')); @@ -219,7 +220,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE + 1, STR('A')); @@ -235,7 +236,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); Text text(initial_text.c_str(), initial_text.size() / 2); @@ -251,7 +252,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); Text text(longer_text.c_str(), longer_text.size()); @@ -267,7 +268,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(compare_text.begin(), compare_text.end()); @@ -304,9 +305,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::u32string_view view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -363,8 +364,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); Text text(initial_text.c_str()); Text text2(text, 2, 4); @@ -379,8 +380,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextL textl(longer_text.c_str()); Text text2(textl, 2, 12); @@ -396,7 +397,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; Text text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; bool is_equal = Equal(compare_text, text); @@ -409,11 +410,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), - STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -540,7 +541,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u32string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -554,7 +555,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u32string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -569,7 +570,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u32string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -584,20 +585,34 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u32string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_view) + { + Text text; + + text = View(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { Text text(initial_text.c_str()); - const Text constText(initial_text.c_str()); + const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[0], text.begin()); + CHECK_EQUAL(&text[0], text.begin()); CHECK_EQUAL(&constText[0], constText.begin()); } @@ -607,7 +622,7 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); + CHECK_EQUAL(&text[initial_text.size()], text.end()); CHECK_EQUAL(&constText[initial_text.size()], constText.end()); } @@ -768,6 +783,64 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + Text text(initial_text.c_str(), initial_text.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_fill) { @@ -857,7 +930,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -873,7 +946,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -889,7 +962,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -907,7 +980,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -925,7 +998,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -937,7 +1010,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -949,7 +1022,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -961,7 +1034,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -973,7 +1046,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(compare_text.begin(), compare_text.end()); @@ -990,7 +1063,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); const Text text(compare_text.begin(), compare_text.end()); @@ -1007,10 +1080,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1023,13 +1096,33 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_view) + { + TextSTD compare_input(initial_text.c_str()); + Text input(initial_text.c_str()); + View view(input); + + TextSTD compare_text; + Text text; + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextL input(longer_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1045,7 +1138,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str()); @@ -1060,7 +1153,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(longer_text.c_str()); @@ -1075,7 +1168,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str(), initial_text.size()); @@ -1090,7 +1183,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); Text text; text.assign(longer_text.c_str(), longer_text.size()); @@ -1107,7 +1200,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; @@ -1179,7 +1272,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1205,7 +1298,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1236,7 +1329,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); compare_text.pop_back(); @@ -1260,7 +1353,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1280,7 +1373,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); const value_t INITIAL_VALUE = STR('A'); @@ -1325,7 +1418,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INITIAL_SIZE = 5; @@ -1351,7 +1444,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INSERT_SIZE = 4; @@ -1424,7 +1517,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1447,7 +1540,7 @@ namespace const size_t INITIAL_SIZE = 5; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; Text text; size_t offset = 0; @@ -1505,7 +1598,7 @@ namespace for (size_t offset = 10; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); @@ -1524,7 +1617,7 @@ namespace { for (size_t offset = 0; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1540,12 +1633,33 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + View view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { for (size_t offset = 0; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1566,7 +1680,7 @@ namespace { for (size_t offset = 0; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(longer_text.begin(), longer_text.end()); insert.erase(insert.begin(), insert.end()); @@ -1587,7 +1701,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1633,7 +1747,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1663,6 +1777,39 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_view) + { + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + View view(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1683,7 +1830,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1714,7 +1861,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1778,7 +1925,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Whole string. @@ -1810,7 +1957,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1842,7 +1989,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1875,10 +2022,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -1892,7 +2039,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -1906,7 +2053,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -1920,7 +2067,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -1934,7 +2081,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -1948,7 +2095,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -1962,7 +2109,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -1973,14 +2120,116 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) + { + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); @@ -1994,7 +2243,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2008,7 +2257,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); @@ -2022,7 +2271,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2033,14 +2282,74 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")), 1, 5); @@ -2054,7 +2363,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2068,7 +2377,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2082,7 +2391,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2096,7 +2405,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")), 1, 5); @@ -2110,7 +2419,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2124,7 +2433,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2138,7 +2447,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2149,11 +2458,127 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, STR("Replace")); @@ -2170,7 +2595,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace")); @@ -2198,7 +2623,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text")); @@ -2226,7 +2651,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace")); @@ -2254,7 +2679,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text")); @@ -2269,7 +2694,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); @@ -2329,7 +2754,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, STR("Replace"), 5); @@ -2346,7 +2771,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace"), 5); @@ -2374,7 +2799,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text"), 15); @@ -2402,7 +2827,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace"), 5); @@ -2430,7 +2855,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text"), 15); @@ -2445,7 +2870,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); @@ -2513,7 +2938,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, 7, STR('A')); @@ -2530,7 +2955,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2558,7 +2983,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2586,7 +3011,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2614,7 +3039,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2629,7 +3054,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); @@ -2689,11 +3114,11 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -2751,10 +3176,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.begin() + 2); Text::iterator ditr = text.erase(text.begin() + 2); CHECK(*citr == *ditr); @@ -2768,10 +3193,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2); Text::iterator ditr = text.erase(text.cbegin() + 2); CHECK(*citr == *ditr); @@ -2785,10 +3210,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); CHECK(*citr == *ditr); @@ -2814,7 +3239,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); @@ -2827,7 +3252,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); @@ -2840,7 +3265,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); @@ -2853,7 +3278,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); @@ -3040,7 +3465,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3058,8 +3483,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3081,13 +3506,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3099,15 +3524,15 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3125,8 +3550,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3135,11 +3560,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_needle(STR("needle")); - etl::u32string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -3153,11 +3578,42 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u32string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u32string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); + View needle_view(needle); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(Text::npos, position2); + + View pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3167,8 +3623,8 @@ namespace const value_t* needle = STR("needle"); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -3182,11 +3638,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t* pin = STR("pin"); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3196,8 +3652,8 @@ namespace const value_t* needle = STR("needle"); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -3211,11 +3667,137 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1, 3); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t* pin = STR("pin"); position2 = haystack.find(pin, 0, 3); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text needle(STR("needle")); + Text pin(STR("pin")); + Text excess(STR("A really gigantic pin or needle that's really really big")); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + CHECK_FALSE(haystack.contains(View(STR("A really gigantic pin or needle that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + CHECK_FALSE(haystack.contains(STR("A really gigantic pin or needle that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text start(STR("A haystack")); + Text not_start(STR("a needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text end(STR("else")); + Text not_end(STR("needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); } //************************************************************************* @@ -3223,14 +3805,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_needle(STR("needle")); - etl::u32string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3240,9 +3822,37 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u32string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); + View needle_view(needle); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = std::u32string::npos; + size_t position2 = Text::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + View pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3250,13 +3860,13 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3266,9 +3876,9 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u32string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3276,13 +3886,13 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); position2 = haystack.rfind(needle, position2, 3); @@ -3293,7 +3903,7 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3301,11 +3911,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3316,16 +3926,16 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_substr) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText compare_result; + TextSTD compare_result; Text result; // Equal. @@ -3360,112 +3970,217 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_view) + { + TextSTD compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; @@ -3500,7 +4215,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3535,7 +4250,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3570,36 +4285,65 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(Text(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(Text(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(Text(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(Text(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF")); @@ -3628,7 +4372,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); @@ -3662,7 +4406,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR('C')); @@ -3701,41 +4445,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(Text(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(Text(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(Text(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(Text(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(Text(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("ZCXE")); @@ -3774,7 +4552,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); @@ -3811,7 +4589,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_of(STR('C')); @@ -3850,41 +4628,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(Text(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(Text(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(Text(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); @@ -3918,7 +4730,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); @@ -3957,7 +4769,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR('A')); @@ -3996,41 +4808,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(Text(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(Text(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(Text(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(Text(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(Text(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); @@ -4064,7 +4910,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); @@ -4096,7 +4942,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_not_of(STR('F')); diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index 96650015..f5e25510 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -72,20 +72,22 @@ namespace using Text = etl::u32string_ext; using IText = etl::iu32string; using TextL = etl::u32string; - using CompareText = std::u32string; + using TextSTD = std::u32string; using value_t = Text::value_type; using TextBuffer = std::array; using TextBufferL = std::array; using TextBufferS = std::array; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + using View = etl::u32string_view; + + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; const value_t* pinitial_text = STR("Hello World"); @@ -200,9 +202,9 @@ namespace TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -212,11 +214,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); TextBuffer buffer{0}; - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE, buffer.data(), buffer.size()); CHECK(text.size() == INITIAL_SIZE); @@ -246,7 +248,7 @@ namespace TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { TextBuffer buffer{0}; - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -262,7 +264,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); @@ -279,7 +281,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE, STR('A'), buffer.data(), buffer.size()); @@ -296,7 +298,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE + 1, STR('A'), buffer.data(), buffer.size()); @@ -313,7 +315,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); TextBuffer buffer{0}; Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); @@ -330,7 +332,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); TextBuffer buffer{0}; Text text(longer_text.c_str(), longer_text.size(), buffer.data(), buffer.size()); @@ -347,7 +349,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -387,10 +389,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::u32string_view view(initial_text.data(), initial_text.size()); - + View view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -463,8 +464,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -482,8 +483,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextBufferL bufferl{0}; Text textl(longer_text.c_str(), bufferl.data(), bufferl.size()); @@ -502,7 +503,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; std::initializer_list il = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; TextBuffer buffer{0}; @@ -518,12 +519,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; std::initializer_list il = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), - STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; TextBuffer buffer{0}; Text text(il, buffer.data(), buffer.size()); @@ -671,7 +672,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u32string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -686,7 +687,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u32string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -702,7 +703,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u32string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -718,13 +719,28 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u32string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text = View(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { @@ -738,6 +754,7 @@ namespace CHECK_EQUAL(&constText[0], constText.begin()); } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_end) { @@ -846,7 +863,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 8; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -890,7 +907,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 2; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -917,21 +934,38 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_fill) + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) { - TextBuffer buffer1{ 0 }; - TextBuffer buffer2{ 0 }; - Text text(11, STR('A'), buffer1.data(), buffer1.size()); - Text expected(11, STR('B'), buffer2.data(), buffer2.size()); + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; - text.fill(STR('B')); + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); - bool is_equal = Equal(expected, text); - CHECK(is_equal); + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), initial_text.size(), buffer.data(), buffer.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); } //************************************************************************* @@ -1013,7 +1047,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1031,7 +1065,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1049,7 +1083,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1069,7 +1103,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1089,7 +1123,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1103,7 +1137,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1117,7 +1151,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1131,7 +1165,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1145,7 +1179,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1163,7 +1197,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1181,12 +1215,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer2{0}; Text text(buffer2.data(), buffer2.size()); @@ -1201,15 +1235,37 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_view) + { + TextSTD compare_input(initial_text.c_str()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + View view(input); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBufferL bufferl{0}; Text input(longer_text.c_str(), bufferl.data(), bufferl.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1227,7 +1283,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1243,7 +1299,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1259,7 +1315,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1275,7 +1331,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1293,7 +1349,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1369,7 +1425,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1397,7 +1453,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1430,7 +1486,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1452,11 +1508,11 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1478,7 +1534,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1524,7 +1580,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1551,7 +1607,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1625,7 +1681,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1649,7 +1705,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1708,7 +1764,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl{0}; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); @@ -1729,13 +1785,12 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer{0}; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - TextBuffer buffer2; - buffer2.fill(0); + TextBuffer buffer2{0}; Text insert(insert_text.begin(), insert_text.end(), buffer2.data(), buffer2.size()); text.insert(offset, insert); @@ -1750,12 +1805,35 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer{0}; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + View view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1780,7 +1858,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1806,7 +1884,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1856,7 +1934,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1890,6 +1968,40 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_view) + { + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + View view(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1913,7 +2025,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1946,7 +2058,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1955,7 +2067,7 @@ namespace Text append(insert_text.c_str(), buffer2.data(), buffer2.size()); // Whole string. - compare_text.append(insert_text, 0, std::u32string::npos); + compare_text.append(insert_text, 0, TextSTD::npos); text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); @@ -2017,7 +2129,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2051,7 +2163,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2085,7 +2197,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2122,12 +2234,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -2141,7 +2253,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -2155,7 +2267,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2169,7 +2281,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2183,7 +2295,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -2197,7 +2309,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2211,7 +2323,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2222,16 +2334,119 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) + { + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); @@ -2245,7 +2460,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2259,7 +2474,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); @@ -2273,7 +2488,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2284,16 +2499,77 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")), 1, 5); @@ -2307,7 +2583,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2321,7 +2597,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2335,7 +2611,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2349,7 +2625,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")), 1, 5); @@ -2363,7 +2639,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2377,7 +2653,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2391,7 +2667,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2402,18 +2678,135 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + text.replace(2, 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2425,9 +2818,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2439,9 +2832,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2453,9 +2846,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2467,9 +2860,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace")); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + text.replace(2, 7, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2481,9 +2874,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2495,9 +2888,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2509,9 +2902,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2524,14 +2917,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2543,9 +2936,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2557,9 +2950,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2571,9 +2964,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2586,14 +2979,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2605,9 +2998,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2619,9 +3012,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2633,9 +3026,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2647,9 +3040,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace"), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2661,9 +3054,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2675,9 +3068,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2689,9 +3082,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2704,14 +3097,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2725,9 +3118,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2741,9 +3134,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2757,9 +3150,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2774,7 +3167,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2793,7 +3186,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2821,7 +3214,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2849,7 +3242,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2877,7 +3270,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2892,7 +3285,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2954,13 +3347,13 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -3016,33 +3409,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_iterator) + TEST_FIXTURE(SetupFixture, test_erase_single) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); - Text::iterator ditr = text.erase(text.begin() + 2); - CHECK(*citr == *ditr); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) - { - CompareText compare_text(initial_text.c_str()); - TextBuffer buffer{0}; - Text text(initial_text.c_str(), buffer.data(), buffer.size()); - - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); - Text::iterator ditr = text.erase(text.cbegin() + 2); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2); + text.erase(text.begin() + 2); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3054,13 +3429,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); - Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); + + text.erase(text.begin() + 2, text.begin() + 4); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3085,7 +3461,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3100,7 +3476,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3115,7 +3491,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3130,7 +3506,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3196,7 +3572,7 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); TextBuffer buffer3; @@ -3213,17 +3589,17 @@ namespace CHECK((initial < initial) == (initial_text < initial_text)); // String-Pointer Pointer-String - CHECK((less < pinitial_text) == (less_text < pinitial_text)); - CHECK((pinitial_text < less) == (pinitial_text < less_text)); + CHECK((less < pinitial_text) == (less_text < pinitial_text)); + CHECK((pinitial_text < less) == (pinitial_text < less_text)); - CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); - CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); + CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); + CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); - CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); - CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); + CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); + CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); - CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); - CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -3236,8 +3612,8 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); TextBuffer buffer3; const Text greater(greater_text.c_str(), buffer3.data(), buffer3.size()); @@ -3253,17 +3629,17 @@ namespace CHECK((initial <= initial) == (initial_text <= initial_text)); // String-Pointer Pointer-String - CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); - CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); + CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); + CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); - CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); - CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); + CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); + CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); - CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); - CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); + CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); + CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); - CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); - CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -3293,17 +3669,17 @@ namespace CHECK((initial > initial) == (initial_text > initial_text)); // String-Pointer Pointer-String - CHECK((less > pinitial_text) == (less_text > pinitial_text)); - CHECK((pinitial_text > less) == (pinitial_text > less_text)); + CHECK((less > pinitial_text) == (less_text > pinitial_text)); + CHECK((pinitial_text > less) == (pinitial_text > less_text)); - CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); - CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); + CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); + CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); - CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); - CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); + CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); + CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); - CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); - CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3316,8 +3692,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end(), buffer2.data(), buffer2.size()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); TextBuffer buffer3; const Text greater(greater_text.begin(), greater_text.end(), buffer3.data(), buffer3.size()); @@ -3333,24 +3709,24 @@ namespace CHECK((initial >= initial) == (initial_text >= initial_text)); // String-Pointer Pointer-String - CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); - CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); + CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); + CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); - CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); - CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); + CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); + CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); - CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); - CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); + CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); + CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); - CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); - CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); - + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3369,8 +3745,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3393,7 +3769,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3401,7 +3777,7 @@ namespace value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3413,15 +3789,15 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3441,8 +3817,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3451,12 +3827,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBuffer buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u32string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); @@ -3473,13 +3849,44 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u32string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u32string<50> pin(STR("pin")); + Text pin(STR("pin"), buffer.data(), buffer.size()); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(TextL::npos, position2); + + View pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) { @@ -3487,7 +3894,7 @@ namespace const value_t* needle = STR("needle"); - std::u32string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3506,7 +3913,7 @@ namespace position2 = haystack.find(needle, position2 + 1); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } @@ -3518,7 +3925,7 @@ namespace const value_t* needle = STR("needle"); - std::u32string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3537,28 +3944,173 @@ namespace position2 = haystack.find(needle, position2 + 1, 3); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text needle(STR("needle"), buffer2.data(), buffer2.size()); + Text pin(STR("pin"), buffer3.data(), buffer3.size()); + Text excess(STR("A really gigantic pin or needle that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text start(STR("A haystack"), buffer2.data(), buffer2.size()); + Text not_start(STR("a needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text end(STR("else"), buffer2.data(), buffer2.size()); + Text not_end(STR("needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBufferL buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u32string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); - size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3575,19 +4127,46 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_pointer) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_haystack(the_haystack); + TextSTD compare_needle(STR("needle")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + View pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_pointer) + { + const value_t*the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3606,16 +4185,16 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u32string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; @@ -3634,15 +4213,15 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_c_position) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); - size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3659,7 +4238,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3668,35 +4247,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3705,35 +4320,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3742,35 +4393,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, TextL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3807,7 +4494,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3844,7 +4531,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3881,38 +4568,68 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(TextL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(TextL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(TextL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(TextL(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3943,7 +4660,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3979,7 +4696,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4020,43 +4737,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(TextL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(TextL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(TextL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(TextL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(TextL(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4097,7 +4849,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4127,16 +4879,18 @@ namespace CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(STR("ZCXE"), 100, 4); position2 = text.find_last_of(STR("ZCXE"), 100, 4); CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" } //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4177,43 +4931,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(TextL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4249,7 +5038,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4290,7 +5079,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4331,43 +5120,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(TextL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(TextL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4403,7 +5227,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4437,7 +5261,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4712,6 +5536,23 @@ namespace CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_secure_after_clear) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.set_secure(); + text.assign(STR("ABCDEF")); + + Text::pointer pb = text.begin(); + Text::pointer pe = text.end(); + + text.clear(); + + // Check there no non-zero values in the remainder of the string. + CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_secure_flag_after_copy) { diff --git a/test/test_string_u8.cpp b/test/test_string_u8.cpp index 2165231f..e3d5c1fa 100644 --- a/test/test_string_u8.cpp +++ b/test/test_string_u8.cpp @@ -69,21 +69,22 @@ namespace { static const size_t SIZE = 11; - using Text = etl::u8string; - using IText = etl::iu8string; - using CompareText = std::u8string; - using value_t = Text::value_type; - using TextL = etl::u8string<52>; - using TextS = etl::u8string<4>; + using Text = etl::u8string; + using IText = etl::iu8string; + using TextSTD = std::u8string; + using value_t = Text::value_type; + using TextL = etl::u8string<52>; + using TextS = etl::u8string<4>; + using View = etl::u8string_view; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; const value_t* pinitial_text = STR("Hello World"); @@ -146,7 +147,7 @@ namespace const size_t INITIAL_SIZE = 5; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE); CHECK(text.size() == INITIAL_SIZE); @@ -174,7 +175,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); @@ -190,7 +191,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(longer_text.c_str()); @@ -206,7 +207,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE, STR('A')); @@ -222,7 +223,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE + 1, STR('A')); @@ -238,7 +239,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); Text text(initial_text.c_str(), initial_text.size() / 2); @@ -254,7 +255,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); Text text(longer_text.c_str(), longer_text.size()); @@ -270,7 +271,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(compare_text.begin(), compare_text.end()); @@ -307,9 +308,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::u8string_view view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -366,8 +367,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); Text text(initial_text.c_str()); Text text2(text, 2, 4); @@ -382,8 +383,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextL textl(longer_text.c_str()); Text text2(textl, 2, 12); @@ -399,7 +400,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; Text text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; bool is_equal = Equal(compare_text, text); @@ -412,7 +413,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), @@ -543,7 +544,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u8string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -557,7 +558,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u8string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -572,7 +573,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u8string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -587,13 +588,27 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u8string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_view) + { + Text text; + + text = View(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { @@ -771,6 +786,64 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + Text text(initial_text.c_str(), initial_text.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_fill) { @@ -860,7 +933,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -876,7 +949,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -892,7 +965,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -910,7 +983,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -928,7 +1001,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -940,7 +1013,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -952,7 +1025,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -964,7 +1037,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -976,7 +1049,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(compare_text.begin(), compare_text.end()); @@ -993,7 +1066,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); const Text text(compare_text.begin(), compare_text.end()); @@ -1010,10 +1083,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1026,13 +1099,33 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_view) + { + TextSTD compare_input(initial_text.c_str()); + Text input(initial_text.c_str()); + View view(input); + + TextSTD compare_text; + Text text; + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextL input(longer_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1048,7 +1141,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str()); @@ -1063,7 +1156,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(longer_text.c_str()); @@ -1078,7 +1171,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str(), initial_text.size()); @@ -1093,7 +1186,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); Text text; text.assign(longer_text.c_str(), longer_text.size()); @@ -1110,7 +1203,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; @@ -1182,7 +1275,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1208,7 +1301,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1239,7 +1332,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); compare_text.pop_back(); @@ -1263,7 +1356,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1283,7 +1376,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); const value_t INITIAL_VALUE = STR('A'); @@ -1328,7 +1421,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INITIAL_SIZE = 5; @@ -1354,7 +1447,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INSERT_SIZE = 4; @@ -1427,7 +1520,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1450,7 +1543,7 @@ namespace const size_t INITIAL_SIZE = 5; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; Text text; size_t offset = 0; @@ -1508,7 +1601,7 @@ namespace for (size_t offset = 10; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); @@ -1527,7 +1620,7 @@ namespace { for (size_t offset = 0; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1543,12 +1636,33 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + View view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { for (size_t offset = 0; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1569,7 +1683,7 @@ namespace { for (size_t offset = 0; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(longer_text.begin(), longer_text.end()); insert.erase(insert.begin(), insert.end()); @@ -1590,7 +1704,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1636,7 +1750,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1666,6 +1780,39 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_view) + { + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + View view(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1686,7 +1833,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1717,7 +1864,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1781,7 +1928,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Whole string. @@ -1813,7 +1960,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1845,7 +1992,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1878,10 +2025,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -1895,7 +2042,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -1909,7 +2056,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -1923,7 +2070,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -1937,7 +2084,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -1951,7 +2098,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -1965,7 +2112,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -1976,14 +2123,116 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) + { + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); @@ -1997,7 +2246,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2011,7 +2260,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); @@ -2025,7 +2274,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2036,14 +2285,74 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")), 1, 5); @@ -2057,7 +2366,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2071,7 +2380,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2085,7 +2394,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2099,7 +2408,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")), 1, 5); @@ -2113,7 +2422,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2127,7 +2436,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2141,7 +2450,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2152,14 +2461,130 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")).c_str()); @@ -2173,7 +2598,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); @@ -2187,7 +2612,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); @@ -2201,7 +2626,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); @@ -2215,7 +2640,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")).c_str()); @@ -2229,7 +2654,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); @@ -2243,7 +2668,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); @@ -2257,7 +2682,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); @@ -2272,10 +2697,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); @@ -2289,7 +2714,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); @@ -2303,7 +2728,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); @@ -2317,7 +2742,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); @@ -2332,10 +2757,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); @@ -2349,7 +2774,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); @@ -2363,7 +2788,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2377,7 +2802,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); @@ -2391,7 +2816,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); @@ -2405,7 +2830,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); @@ -2419,7 +2844,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2433,7 +2858,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); @@ -2448,10 +2873,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); @@ -2467,7 +2892,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2483,7 +2908,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); @@ -2499,7 +2924,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2516,7 +2941,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, 7, STR('A')); @@ -2533,7 +2958,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2561,7 +2986,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2589,7 +3014,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2617,7 +3042,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2632,7 +3057,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); @@ -2692,11 +3117,11 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -2754,10 +3179,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.begin() + 2); Text::iterator ditr = text.erase(text.begin() + 2); CHECK(*citr == *ditr); @@ -2771,10 +3196,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2); Text::iterator ditr = text.erase(text.cbegin() + 2); CHECK(*citr == *ditr); @@ -2788,10 +3213,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); CHECK(*citr == *ditr); @@ -2817,7 +3242,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); @@ -2830,7 +3255,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); @@ -2843,7 +3268,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); @@ -2856,7 +3281,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); @@ -3043,7 +3468,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3084,13 +3509,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3110,7 +3535,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3138,11 +3563,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_needle(STR("needle")); - etl::u8string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -3156,11 +3581,42 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u8string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u8string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); + View needle_view(needle); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(Text::npos, position2); + + View pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3170,8 +3626,8 @@ namespace const value_t* needle = STR("needle"); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -3185,11 +3641,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t* pin = STR("pin"); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3199,8 +3655,8 @@ namespace const value_t* needle = STR("needle"); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -3214,11 +3670,137 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1, 3); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t* pin = STR("pin"); position2 = haystack.find(pin, 0, 3); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text needle(STR("needle")); + Text pin(STR("pin")); + Text excess(STR("A really gigantic pin or needle that's really really big")); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + CHECK_FALSE(haystack.contains(View(STR("A really gigantic pin or needle that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + CHECK_FALSE(haystack.contains(STR("A really gigantic pin or needle that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text start(STR("A haystack")); + Text not_start(STR("a needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text end(STR("else")); + Text not_end(STR("needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); } //************************************************************************* @@ -3226,14 +3808,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_needle(STR("needle")); - etl::u8string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3243,9 +3825,37 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u8string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); + View needle_view(needle); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = std::u8string::npos; + size_t position2 = Text::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + View pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3253,13 +3863,13 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3269,9 +3879,9 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u8string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3279,13 +3889,13 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); position2 = haystack.rfind(needle, position2, 3); @@ -3296,7 +3906,7 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3304,11 +3914,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3319,16 +3929,16 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_substr) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText compare_result; + TextSTD compare_result; Text result; // Equal. @@ -3363,112 +3973,217 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_view) + { + TextSTD compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; @@ -3503,7 +4218,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3538,7 +4253,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3573,36 +4288,65 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(Text(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(Text(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(Text(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(Text(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF")); @@ -3631,7 +4375,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); @@ -3665,7 +4409,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR('C')); @@ -3704,41 +4448,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(Text(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(Text(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(Text(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(Text(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(Text(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("ZCXE")); @@ -3777,7 +4555,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); @@ -3814,7 +4592,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_of(STR('C')); @@ -3853,41 +4631,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(Text(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(Text(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(Text(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); @@ -3921,7 +4733,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); @@ -3960,7 +4772,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR('A')); @@ -3999,41 +4811,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(Text(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(Text(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(Text(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(Text(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(Text(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); @@ -4067,7 +4913,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); @@ -4099,7 +4945,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_not_of(STR('F')); diff --git a/test/test_string_u8_external_buffer.cpp b/test/test_string_u8_external_buffer.cpp index bc2caaaf..5f64fb37 100644 --- a/test/test_string_u8_external_buffer.cpp +++ b/test/test_string_u8_external_buffer.cpp @@ -75,20 +75,22 @@ namespace using Text = etl::u8string_ext; using IText = etl::iu8string; using TextL = etl::u8string; - using CompareText = std::u8string; + using TextSTD = std::u8string; using value_t = Text::value_type; using TextBuffer = std::array; using TextBufferL = std::array; using TextBufferS = std::array; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + using View = etl::u8string_view; + + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; const value_t* pinitial_text = STR("Hello World"); @@ -203,9 +205,9 @@ namespace TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -215,11 +217,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); TextBuffer buffer{0}; - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE, buffer.data(), buffer.size()); CHECK(text.size() == INITIAL_SIZE); @@ -249,7 +251,7 @@ namespace TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { TextBuffer buffer{0}; - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -265,7 +267,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); @@ -282,7 +284,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE, STR('A'), buffer.data(), buffer.size()); @@ -299,7 +301,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE + 1, STR('A'), buffer.data(), buffer.size()); @@ -316,7 +318,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); TextBuffer buffer{0}; Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); @@ -333,7 +335,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); TextBuffer buffer{0}; Text text(longer_text.c_str(), longer_text.size(), buffer.data(), buffer.size()); @@ -350,7 +352,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -390,10 +392,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::u8string_view view(initial_text.data(), initial_text.size()); - + View view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -466,8 +467,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -485,8 +486,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextBufferL bufferl{0}; Text textl(longer_text.c_str(), bufferl.data(), bufferl.size()); @@ -505,7 +506,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; std::initializer_list il = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; TextBuffer buffer{0}; @@ -521,12 +522,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; std::initializer_list il = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), - STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; TextBuffer buffer{0}; Text text(il, buffer.data(), buffer.size()); @@ -674,7 +675,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u8string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -689,7 +690,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u8string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -705,7 +706,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u8string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -721,13 +722,28 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u8string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text = View(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { @@ -850,7 +866,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 8; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -894,7 +910,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 2; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -921,21 +937,64 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_fill) + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) { - TextBuffer buffer1{ 0 }; - TextBuffer buffer2{ 0 }; - Text text(11, STR('A'), buffer1.data(), buffer1.size()); - Text expected(11, STR('B'), buffer2.data(), buffer2.size()); + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; - text.fill(STR('B')); + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); - bool is_equal = Equal(expected, text); - CHECK(is_equal); + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), initial_text.size(), buffer.data(), buffer.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); } //************************************************************************* @@ -1017,7 +1076,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1035,7 +1094,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1053,7 +1112,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1073,7 +1132,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1093,7 +1152,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1107,7 +1166,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1121,7 +1180,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1135,7 +1194,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1149,7 +1208,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1167,7 +1226,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1185,12 +1244,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer2{0}; Text text(buffer2.data(), buffer2.size()); @@ -1205,15 +1264,37 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_view) + { + TextSTD compare_input(initial_text.c_str()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + View view(input); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBufferL bufferl{0}; Text input(longer_text.c_str(), bufferl.data(), bufferl.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1231,7 +1312,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1247,7 +1328,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1263,7 +1344,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1279,7 +1360,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1297,7 +1378,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1373,7 +1454,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1401,7 +1482,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1434,7 +1515,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1456,11 +1537,11 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1482,7 +1563,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1528,7 +1609,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1555,7 +1636,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1629,7 +1710,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1653,7 +1734,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1712,7 +1793,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl{0}; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); @@ -1731,18 +1812,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - size_t s = short_text.size(); - (void)s; - - assert(s <= 5); - - for (size_t offset = s; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer{0}; + buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - TextBuffer buffer2{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + TextBuffer buffer2{0}; Text insert(insert_text.begin(), insert_text.end(), buffer2.data(), buffer2.size()); text.insert(offset, insert); @@ -1758,23 +1835,39 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_2) + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer{0}; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + View view(insert_text.data(), insert_text.size()); + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } } - //************************************************************************* + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { -#include "etl/private/diagnostic_array_bounds_push.h" for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); - TextBuffer buffer{ 0 }; + TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); - TextBuffer buffer2{ 0 }; + TextBuffer buffer2{0}; Text insert(insert_text.begin(), insert_text.end(), buffer2.data(), buffer2.size()); text.insert(offset, insert); @@ -1787,7 +1880,6 @@ namespace CHECK(text.is_truncated()); #endif } -#include "etl/private/diagnostic_pop.h" } //************************************************************************* @@ -1795,7 +1887,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1821,7 +1913,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1871,7 +1963,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1905,6 +1997,40 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_view) + { + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + View view(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1928,7 +2054,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1961,7 +2087,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1970,7 +2096,7 @@ namespace Text append(insert_text.c_str(), buffer2.data(), buffer2.size()); // Whole string. - compare_text.append(insert_text, 0, std::u8string::npos); + compare_text.append(insert_text, 0, TextSTD::npos); text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); @@ -2032,7 +2158,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2066,7 +2192,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2100,7 +2226,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2137,12 +2263,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -2156,7 +2282,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -2170,7 +2296,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2184,7 +2310,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2198,7 +2324,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -2212,7 +2338,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2226,7 +2352,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2237,16 +2363,119 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) + { + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); @@ -2260,7 +2489,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2274,7 +2503,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); @@ -2288,7 +2517,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2299,16 +2528,77 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")), 1, 5); @@ -2322,7 +2612,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2336,7 +2626,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2350,7 +2640,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2364,7 +2654,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")), 1, 5); @@ -2378,7 +2668,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2392,7 +2682,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2406,7 +2696,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2417,16 +2707,133 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")).c_str()); @@ -2440,7 +2847,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); @@ -2454,7 +2861,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); @@ -2468,7 +2875,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); @@ -2482,7 +2889,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")).c_str()); @@ -2496,7 +2903,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); @@ -2510,7 +2917,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); @@ -2524,7 +2931,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); @@ -2539,12 +2946,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); @@ -2558,7 +2965,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); @@ -2572,7 +2979,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); @@ -2586,7 +2993,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); @@ -2601,12 +3008,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); @@ -2620,7 +3027,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); @@ -2634,7 +3041,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2648,7 +3055,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); @@ -2662,7 +3069,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); @@ -2676,7 +3083,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); @@ -2690,7 +3097,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2704,7 +3111,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); @@ -2719,12 +3126,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); @@ -2740,7 +3147,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2756,7 +3163,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); @@ -2772,7 +3179,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2789,7 +3196,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2808,7 +3215,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2836,7 +3243,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2864,7 +3271,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2892,7 +3299,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2907,7 +3314,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2969,13 +3376,13 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -3031,33 +3438,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_iterator) + TEST_FIXTURE(SetupFixture, test_erase_single) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); - Text::iterator ditr = text.erase(text.begin() + 2); - CHECK(*citr == *ditr); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) - { - CompareText compare_text(initial_text.c_str()); - TextBuffer buffer{0}; - Text text(initial_text.c_str(), buffer.data(), buffer.size()); - - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); - Text::iterator ditr = text.erase(text.cbegin() + 2); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2); + text.erase(text.begin() + 2); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3069,13 +3458,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); - Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); + + text.erase(text.begin() + 2, text.begin() + 4); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3100,7 +3490,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3115,7 +3505,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3130,7 +3520,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3145,7 +3535,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3211,7 +3601,7 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); TextBuffer buffer3; @@ -3228,17 +3618,17 @@ namespace CHECK((initial < initial) == (initial_text < initial_text)); // String-Pointer Pointer-String - CHECK((less < pinitial_text) == (less_text < pinitial_text)); - CHECK((pinitial_text < less) == (pinitial_text < less_text)); + CHECK((less < pinitial_text) == (less_text < pinitial_text)); + CHECK((pinitial_text < less) == (pinitial_text < less_text)); - CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); - CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); + CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); + CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); - CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); - CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); + CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); + CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); - CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); - CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -3251,8 +3641,8 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); TextBuffer buffer3; const Text greater(greater_text.c_str(), buffer3.data(), buffer3.size()); @@ -3268,17 +3658,17 @@ namespace CHECK((initial <= initial) == (initial_text <= initial_text)); // String-Pointer Pointer-String - CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); - CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); + CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); + CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); - CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); - CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); + CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); + CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); - CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); - CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); + CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); + CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); - CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); - CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -3308,17 +3698,17 @@ namespace CHECK((initial > initial) == (initial_text > initial_text)); // String-Pointer Pointer-String - CHECK((less > pinitial_text) == (less_text > pinitial_text)); - CHECK((pinitial_text > less) == (pinitial_text > less_text)); + CHECK((less > pinitial_text) == (less_text > pinitial_text)); + CHECK((pinitial_text > less) == (pinitial_text > less_text)); - CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); - CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); + CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); + CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); - CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); - CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); + CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); + CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); - CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); - CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3331,8 +3721,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end(), buffer2.data(), buffer2.size()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); TextBuffer buffer3; const Text greater(greater_text.begin(), greater_text.end(), buffer3.data(), buffer3.size()); @@ -3348,24 +3738,24 @@ namespace CHECK((initial >= initial) == (initial_text >= initial_text)); // String-Pointer Pointer-String - CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); - CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); + CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); + CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); - CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); - CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); + CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); + CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); - CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); - CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); + CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); + CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); - CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); - CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); - + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3384,8 +3774,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3408,7 +3798,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3416,7 +3806,7 @@ namespace value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3428,15 +3818,15 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3456,8 +3846,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3466,12 +3856,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBuffer buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u8string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); @@ -3488,13 +3878,44 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u8string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u8string<50> pin(STR("pin")); + Text pin(STR("pin"), buffer.data(), buffer.size()); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(TextL::npos, position2); + + View pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) { @@ -3502,7 +3923,7 @@ namespace const value_t* needle = STR("needle"); - std::u8string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3521,11 +3942,156 @@ namespace position2 = haystack.find(needle, position2 + 1); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text needle(STR("needle"), buffer2.data(), buffer2.size()); + Text pin(STR("pin"), buffer3.data(), buffer3.size()); + Text excess(STR("A really gigantic pin or needle that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text start(STR("A haystack"), buffer2.data(), buffer2.size()); + Text not_start(STR("a needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text end(STR("else"), buffer2.data(), buffer2.size()); + Text not_end(STR("needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_char_pointer_n) { @@ -3533,7 +4099,7 @@ namespace const value_t* needle = STR("needle"); - std::u8string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3552,7 +4118,7 @@ namespace position2 = haystack.find(needle, position2 + 1, 3); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); CHECK_EQUAL(IText::npos, position2); } @@ -3562,18 +4128,18 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBufferL buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u8string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); - size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3590,19 +4156,46 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_pointer) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_haystack(the_haystack); + TextSTD compare_needle(STR("needle")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + View pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_pointer) + { + const value_t*the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3621,16 +4214,16 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u8string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; @@ -3649,15 +4242,15 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_c_position) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); - size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3674,7 +4267,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3683,35 +4276,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3720,35 +4349,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3757,35 +4422,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, TextL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3822,7 +4523,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3859,7 +4560,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3896,38 +4597,68 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(TextL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(TextL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(TextL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(TextL(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3958,7 +4689,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3994,7 +4725,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4035,43 +4766,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(TextL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(TextL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(TextL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(TextL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(TextL(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4112,7 +4878,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4142,16 +4908,18 @@ namespace CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(STR("ZCXE"), 100, 4); position2 = text.find_last_of(STR("ZCXE"), 100, 4); CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" } //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4192,43 +4960,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(TextL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4264,7 +5067,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4305,7 +5108,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4346,43 +5149,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(TextL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(TextL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4418,7 +5256,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4452,7 +5290,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); diff --git a/test/test_string_view.cpp b/test/test_string_view.cpp index 08c28a55..bc9404e6 100644 --- a/test/test_string_view.cpp +++ b/test/test_string_view.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include "etl/string_view.h" #include "etl/string.h" #include "etl/wstring.h" +#include "etl/u8string.h" #include "etl/u16string.h" #include "etl/u32string.h" #include "etl/hash.h" @@ -45,12 +46,18 @@ namespace { using View = etl::string_view; using WView = etl::wstring_view; +#if ETL_USING_CPP20 + using U8View = etl::u8string_view; +#endif using U16View = etl::u16string_view; using U32View = etl::u32string_view; etl::string<11> etltext = "Hello World"; std::string text = "Hello World"; std::wstring wtext = L"Hello World"; +#if ETL_USING_CPP20 + std::u8string u8text = u8"Hello World"; +#endif std::u16string u16text = u"Hello World"; std::u32string u32text = U"Hello World"; std::string text_smaller = "Hello Worlc"; @@ -162,6 +169,86 @@ namespace CHECK(isEqual); } +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST(test_constructor_from_std_string_view) + { + std::string_view stdview(text.data(), text.size()); + + View view(stdview); + + CHECK(stdview.size() == view.size()); + CHECK(stdview.size() == view.max_size()); + + bool isEqual = std::equal(view.begin(), view.end(), stdview.begin()); + CHECK(isEqual); + } +#endif + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST(test_constructor_from_std_wstring_view) + { + std::wstring_view stdview(wtext.data(), wtext.size()); + + WView view(stdview); + + CHECK(stdview.size() == view.size()); + CHECK(stdview.size() == view.max_size()); + + bool isEqual = std::equal(view.begin(), view.end(), stdview.begin()); + CHECK(isEqual); + } +#endif + +#if ETL_USING_STL && ETL_USING_CPP20 + //************************************************************************* + TEST(test_constructor_from_std_u8string_view) + { + std::u8string_view stdview(u8text.begin(), u8text.end()); + + U8View view(stdview); + + CHECK(stdview.size() == view.size()); + CHECK(stdview.size() == view.max_size()); + + bool isEqual = std::equal(view.begin(), view.end(), stdview.begin()); + CHECK(isEqual); + } +#endif + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST(test_constructor_from_std_u16string_view) + { + std::u16string_view stdview(u16text.data(), u16text.size()); + + U16View view(stdview); + + CHECK(stdview.size() == view.size()); + CHECK(stdview.size() == view.max_size()); + + bool isEqual = std::equal(view.begin(), view.end(), stdview.begin()); + CHECK(isEqual); + } +#endif + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST(test_constructor_from_std_u32string_view) + { + std::u32string_view stdview(u32text.data(), u32text.size()); + + U32View view(stdview); + + CHECK(stdview.size() == view.size()); + CHECK(stdview.size() == view.max_size()); + + bool isEqual = std::equal(view.begin(), view.end(), stdview.begin()); + CHECK(isEqual); + } +#endif + //************************************************************************* TEST(test_constructor_pointer_size) { @@ -735,6 +822,39 @@ namespace CHECK(!view.ends_with("Hello Worldxxxxxx")); } + //************************************************************************* + TEST(test_contains) + { + const char* s1 = "Hello"; + const char* s2 = "llo Wor"; + const char* s3 = "World"; + const char* s4 = "Xorld"; + const char* s5 = "Hello Worldxxxxxx"; + + View view(text.c_str()); + View v1(s1); + View v2(s2); + View v3(s3); + View v4(s4); + View v5(s5); + + CHECK_TRUE(view.contains(v1)); + CHECK_TRUE(view.contains(v2)); + CHECK_TRUE(view.contains(v3)); + CHECK_FALSE(view.contains(v4)); + CHECK_FALSE(view.contains(v5)); + + CHECK_TRUE(view.contains('H')); + CHECK_TRUE(view.contains('l')); + CHECK_FALSE(view.contains('X')); + + CHECK_TRUE(view.contains(s1)); + CHECK_TRUE(view.contains(s2)); + CHECK_TRUE(view.contains(s3)); + CHECK_FALSE(view.contains(s4)); + CHECK_FALSE(view.contains(s5)); + } + //************************************************************************* TEST(test_find) { diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index f3e852b7..81b2d8bb 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -66,23 +66,25 @@ namespace { static const size_t SIZE = 11; - using Text = etl::wstring; - using IText = etl::iwstring; - using CompareText = std::wstring; - using value_t = Text::value_type; - using TextL = etl::wstring<52>; - using TextS = etl::wstring<4>; + using Text = etl::wstring; + using IText = etl::iwstring; + using TextSTD = std::wstring; + using value_t = Text::value_type; + using TextL = etl::wstring<52>; + using TextS = etl::wstring<4>; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText short_text; - CompareText longer_text; + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; - const Text::value_type* pinitial_text = STR("Hello World"); + using View = etl::wstring_view; + + const value_t* pinitial_text = STR("Hello World"); //************************************************************************* template @@ -143,7 +145,7 @@ namespace const size_t INITIAL_SIZE = 5; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE); CHECK(text.size() == INITIAL_SIZE); @@ -171,7 +173,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); @@ -187,7 +189,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(longer_text.c_str()); @@ -203,7 +205,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE, STR('A')); @@ -219,7 +221,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE + 1, STR('A')); @@ -235,7 +237,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); Text text(initial_text.c_str(), initial_text.size() / 2); @@ -251,7 +253,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); Text text(longer_text.c_str(), longer_text.size()); @@ -267,7 +269,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(compare_text.begin(), compare_text.end()); @@ -304,9 +306,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::wstring_view view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -363,8 +365,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); Text text(initial_text.c_str()); Text text2(text, 2, 4); @@ -379,8 +381,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextL textl(longer_text.c_str()); Text text2(textl, 2, 12); @@ -396,7 +398,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; Text text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; bool is_equal = Equal(compare_text, text); @@ -409,11 +411,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), - STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -540,7 +542,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::wstring(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -554,7 +556,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::wstring(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -569,7 +571,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::wstring(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -584,20 +586,34 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::wstring(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_view) + { + Text text; + + text = View(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - - CHECK_EQUAL(&text[0], text.begin()); + + CHECK_EQUAL(&text[0], text.begin()); CHECK_EQUAL(&constText[0], constText.begin()); } @@ -607,7 +623,7 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); + CHECK_EQUAL(&text[initial_text.size()], text.end()); CHECK_EQUAL(&constText[initial_text.size()], constText.end()); } @@ -768,6 +784,64 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + Text text(initial_text.c_str(), initial_text.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_fill) { @@ -857,7 +931,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -873,7 +947,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -889,7 +963,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -907,7 +981,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -925,7 +999,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -937,7 +1011,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -949,7 +1023,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -961,7 +1035,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -973,7 +1047,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(compare_text.begin(), compare_text.end()); @@ -990,7 +1064,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); const Text text(compare_text.begin(), compare_text.end()); @@ -1007,10 +1081,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1023,13 +1097,33 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_view) + { + TextSTD compare_input(initial_text.c_str()); + Text input(initial_text.c_str()); + View view(input); + + TextSTD compare_text; + Text text; + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextL input(longer_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1045,7 +1139,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str()); @@ -1060,7 +1154,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(longer_text.c_str()); @@ -1075,7 +1169,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str(), initial_text.size()); @@ -1090,7 +1184,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); Text text; text.assign(longer_text.c_str(), longer_text.size()); @@ -1107,7 +1201,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; @@ -1179,7 +1273,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1205,7 +1299,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1236,7 +1330,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); compare_text.pop_back(); @@ -1260,7 +1354,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1280,7 +1374,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); const value_t INITIAL_VALUE = STR('A'); @@ -1325,7 +1419,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INITIAL_SIZE = 5; @@ -1351,7 +1445,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INSERT_SIZE = 4; @@ -1424,7 +1518,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1447,7 +1541,7 @@ namespace const size_t INITIAL_SIZE = 5; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; Text text; size_t offset = 0; @@ -1505,7 +1599,7 @@ namespace for (size_t offset = 10; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); @@ -1524,7 +1618,7 @@ namespace { for (size_t offset = 0; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1540,12 +1634,33 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + View view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { for (size_t offset = 0; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1566,7 +1681,7 @@ namespace { for (size_t offset = 0; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(longer_text.begin(), longer_text.end()); insert.erase(insert.begin(), insert.end()); @@ -1587,7 +1702,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1633,7 +1748,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1663,6 +1778,39 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_view) + { + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + View view(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1683,7 +1831,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1714,7 +1862,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1778,7 +1926,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Whole string. @@ -1810,7 +1958,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1842,7 +1990,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1875,10 +2023,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -1892,7 +2040,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -1906,7 +2054,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -1920,7 +2068,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -1934,7 +2082,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -1948,7 +2096,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -1962,7 +2110,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -1973,14 +2121,116 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) + { + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); @@ -1994,7 +2244,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2008,7 +2258,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); @@ -2022,7 +2272,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2033,14 +2283,74 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")), 1, 5); @@ -2054,7 +2364,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2068,7 +2378,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2082,7 +2392,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2096,7 +2406,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")), 1, 5); @@ -2110,7 +2420,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2124,7 +2434,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2138,7 +2448,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2149,11 +2459,127 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, STR("Replace")); @@ -2170,7 +2596,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace")); @@ -2198,7 +2624,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text")); @@ -2226,7 +2652,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace")); @@ -2254,7 +2680,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text")); @@ -2269,7 +2695,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); @@ -2329,7 +2755,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, STR("Replace"), 5); @@ -2346,7 +2772,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace"), 5); @@ -2374,7 +2800,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text"), 15); @@ -2402,7 +2828,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace"), 5); @@ -2430,7 +2856,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text"), 15); @@ -2445,7 +2871,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); @@ -2513,7 +2939,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, 7, STR('A')); @@ -2530,7 +2956,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2558,7 +2984,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2586,7 +3012,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2614,7 +3040,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2629,7 +3055,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); @@ -2689,11 +3115,11 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -2751,10 +3177,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.begin() + 2); Text::iterator ditr = text.erase(text.begin() + 2); CHECK(*citr == *ditr); @@ -2768,10 +3194,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2); Text::iterator ditr = text.erase(text.cbegin() + 2); CHECK(*citr == *ditr); @@ -2785,10 +3211,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); CHECK(*citr == *ditr); @@ -2814,7 +3240,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); @@ -2827,7 +3253,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); @@ -2840,7 +3266,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); @@ -2853,7 +3279,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); @@ -3040,7 +3466,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3058,8 +3484,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3081,13 +3507,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3099,15 +3525,15 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3125,8 +3551,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3135,11 +3561,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_needle(STR("needle")); - etl::wstring<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -3153,11 +3579,42 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::wstring<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::wstring<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); + View needle_view(needle); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(Text::npos, position2); + + View pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3167,8 +3624,8 @@ namespace const value_t* needle = STR("needle"); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -3182,11 +3639,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t* pin = STR("pin"); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3196,8 +3653,8 @@ namespace const value_t* needle = STR("needle"); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -3211,11 +3668,137 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1, 3); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t* pin = STR("pin"); position2 = haystack.find(pin, 0, 3); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text needle(STR("needle")); + Text pin(STR("pin")); + Text excess(STR("A really gigantic pin or needle that's really really big")); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + CHECK_FALSE(haystack.contains(View(STR("A really gigantic pin or needle that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + CHECK_FALSE(haystack.contains(STR("A really gigantic pin or needle that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text start(STR("A haystack")); + Text not_start(STR("a needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text end(STR("else")); + Text not_end(STR("needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); } //************************************************************************* @@ -3223,14 +3806,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_needle(STR("needle")); - etl::wstring<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3240,9 +3823,37 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::wstring<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); + View needle_view(needle); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = std::wstring::npos; + size_t position2 = Text::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + View pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3250,13 +3861,13 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3266,9 +3877,9 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::wstring<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3276,13 +3887,13 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); position2 = haystack.rfind(needle, position2, 3); @@ -3293,7 +3904,7 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3301,11 +3912,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3316,16 +3927,16 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_substr) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText compare_result; + TextSTD compare_result; Text result; // Equal. @@ -3360,112 +3971,217 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_view) + { + TextSTD compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; @@ -3500,7 +4216,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3535,7 +4251,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3570,36 +4286,65 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(Text(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(Text(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(Text(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(Text(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF")); @@ -3628,7 +4373,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); @@ -3662,7 +4407,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR('C')); @@ -3701,41 +4446,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(Text(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(Text(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(Text(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(Text(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(Text(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("ZCXE")); @@ -3774,7 +4553,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); @@ -3811,7 +4590,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_of(STR('C')); @@ -3850,41 +4629,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(Text(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(Text(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(Text(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); @@ -3918,7 +4731,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); @@ -3957,7 +4770,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR('A')); @@ -3996,41 +4809,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(Text(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(Text(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(Text(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(Text(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(Text(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); @@ -4064,7 +4911,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); @@ -4096,7 +4943,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_not_of(STR('F')); diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index a30dc63f..886c7b70 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -69,24 +69,28 @@ namespace static constexpr size_t SIZE_L = 52; static constexpr size_t SIZE_S = 4; - using Text = etl::wstring_ext; - using IText = etl::iwstring; - using TextL = etl::wstring; - using CompareText = std::wstring; - using value_t = Text::value_type; + using Text = etl::wstring_ext; + using IText = etl::iwstring; + using TextL = etl::wstring; + using TextSTD = std::wstring; + using value_t = Text::value_type; + + using View = etl::wstring_view; using TextBuffer = std::array; using TextBufferL = std::array; using TextBufferS = std::array; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + using View = etl::wstring_view; + + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; const value_t* pinitial_text = STR("Hello World"); @@ -201,9 +205,9 @@ namespace TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -213,11 +217,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); TextBuffer buffer{0}; - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE, buffer.data(), buffer.size()); CHECK(text.size() == INITIAL_SIZE); @@ -247,7 +251,7 @@ namespace TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { TextBuffer buffer{0}; - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -263,7 +267,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); @@ -280,7 +284,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE, STR('A'), buffer.data(), buffer.size()); @@ -297,7 +301,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE + 1, STR('A'), buffer.data(), buffer.size()); @@ -314,7 +318,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); TextBuffer buffer{0}; Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); @@ -331,7 +335,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); TextBuffer buffer{0}; Text text(longer_text.c_str(), longer_text.size(), buffer.data(), buffer.size()); @@ -348,7 +352,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -388,10 +392,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::wstring_view view(initial_text.data(), initial_text.size()); - + View view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -464,8 +467,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -483,8 +486,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextBufferL bufferl{0}; Text textl(longer_text.c_str(), bufferl.data(), bufferl.size()); @@ -503,7 +506,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; std::initializer_list il = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; TextBuffer buffer{0}; @@ -519,12 +522,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; std::initializer_list il = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), - STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; TextBuffer buffer{0}; Text text(il, buffer.data(), buffer.size()); @@ -672,7 +675,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::wstring(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -687,7 +690,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::wstring(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -703,7 +706,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::wstring(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -719,13 +722,28 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::wstring(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text = View(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { @@ -734,7 +752,7 @@ namespace TextBuffer buffer2{0}; const Text constText(initial_text.c_str(), buffer2.data(), buffer2.size()); - + CHECK_EQUAL(&text[0], text.begin()); CHECK_EQUAL(&constText[0], constText.begin()); } @@ -848,7 +866,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 8; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -892,7 +910,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 2; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -919,21 +937,38 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_fill) + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) { - TextBuffer buffer1{ 0 }; - TextBuffer buffer2{ 0 }; - Text text(11, STR('A'), buffer1.data(), buffer1.size()); - Text expected(11, STR('B'), buffer2.data(), buffer2.size()); + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; - text.fill(STR('B')); + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); - bool is_equal = Equal(expected, text); - CHECK(is_equal); + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), initial_text.size(), buffer.data(), buffer.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); } //************************************************************************* @@ -1015,7 +1050,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1033,7 +1068,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1051,7 +1086,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1071,7 +1106,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1091,7 +1126,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1105,7 +1140,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1119,7 +1154,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1133,7 +1168,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1147,7 +1182,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1165,7 +1200,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1183,12 +1218,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer2{0}; Text text(buffer2.data(), buffer2.size()); @@ -1203,15 +1238,37 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_view) + { + TextSTD compare_input(initial_text.c_str()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + View view(input); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBufferL bufferl{0}; Text input(longer_text.c_str(), bufferl.data(), bufferl.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1229,7 +1286,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1245,7 +1302,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1261,7 +1318,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1277,7 +1334,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1295,7 +1352,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1371,7 +1428,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1399,7 +1456,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1432,7 +1489,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1454,11 +1511,11 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1480,7 +1537,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1526,7 +1583,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1553,7 +1610,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1627,7 +1684,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1651,7 +1708,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1710,7 +1767,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl{0}; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); @@ -1731,8 +1788,9 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; + buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); TextBuffer buffer2{0}; @@ -1750,12 +1808,35 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer{0}; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + View view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1780,7 +1861,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1806,7 +1887,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1856,7 +1937,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1890,6 +1971,40 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_view) + { + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + View view(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1913,7 +2028,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1946,7 +2061,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1955,7 +2070,7 @@ namespace Text append(insert_text.c_str(), buffer2.data(), buffer2.size()); // Whole string. - compare_text.append(insert_text, 0, std::wstring::npos); + compare_text.append(insert_text, 0, TextSTD::npos); text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); @@ -2017,7 +2132,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2051,7 +2166,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2085,7 +2200,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2122,12 +2237,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -2141,7 +2256,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -2155,7 +2270,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2169,7 +2284,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2183,7 +2298,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -2197,7 +2312,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2211,7 +2326,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2222,16 +2337,119 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) + { + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); @@ -2245,7 +2463,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2259,7 +2477,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); @@ -2273,7 +2491,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2284,16 +2502,77 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")), 1, 5); @@ -2307,7 +2586,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2321,7 +2600,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2335,7 +2614,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2349,7 +2628,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")), 1, 5); @@ -2363,7 +2642,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2377,7 +2656,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2391,7 +2670,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2402,18 +2681,135 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, View(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + text.replace(2, 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2425,9 +2821,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2439,9 +2835,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2453,9 +2849,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2467,9 +2863,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace")); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + text.replace(2, 7, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2481,9 +2877,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2495,9 +2891,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2509,9 +2905,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2524,14 +2920,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2543,9 +2939,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2557,9 +2953,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2571,9 +2967,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2586,14 +2982,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2605,9 +3001,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2619,9 +3015,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2633,9 +3029,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2647,9 +3043,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace"), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2661,9 +3057,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2675,9 +3071,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2689,9 +3085,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2704,14 +3100,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2725,9 +3121,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2741,9 +3137,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2757,9 +3153,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2774,7 +3170,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2793,7 +3189,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2821,7 +3217,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2849,7 +3245,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2877,7 +3273,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2892,7 +3288,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2954,13 +3350,13 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -3016,33 +3412,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_iterator) + TEST_FIXTURE(SetupFixture, test_erase_single) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); - Text::iterator ditr = text.erase(text.begin() + 2); - CHECK(*citr == *ditr); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) - { - CompareText compare_text(initial_text.c_str()); - TextBuffer buffer{0}; - Text text(initial_text.c_str(), buffer.data(), buffer.size()); - - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); - Text::iterator ditr = text.erase(text.cbegin() + 2); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2); + text.erase(text.begin() + 2); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3054,13 +3432,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); - Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); + + text.erase(text.begin() + 2, text.begin() + 4); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3085,7 +3464,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3100,7 +3479,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3115,7 +3494,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3130,7 +3509,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3196,7 +3575,7 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); TextBuffer buffer3; @@ -3213,17 +3592,17 @@ namespace CHECK((initial < initial) == (initial_text < initial_text)); // String-Pointer Pointer-String - CHECK((less < pinitial_text) == (less_text < pinitial_text)); - CHECK((pinitial_text < less) == (pinitial_text < less_text)); + CHECK((less < pinitial_text) == (less_text < pinitial_text)); + CHECK((pinitial_text < less) == (pinitial_text < less_text)); - CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); - CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); + CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); + CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); - CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); - CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); + CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); + CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); - CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); - CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -3236,8 +3615,8 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); TextBuffer buffer3; const Text greater(greater_text.c_str(), buffer3.data(), buffer3.size()); @@ -3253,17 +3632,17 @@ namespace CHECK((initial <= initial) == (initial_text <= initial_text)); // String-Pointer Pointer-String - CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); - CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); + CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); + CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); - CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); - CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); + CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); + CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); - CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); - CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); + CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); + CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); - CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); - CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -3293,17 +3672,17 @@ namespace CHECK((initial > initial) == (initial_text > initial_text)); // String-Pointer Pointer-String - CHECK((less > pinitial_text) == (less_text > pinitial_text)); - CHECK((pinitial_text > less) == (pinitial_text > less_text)); + CHECK((less > pinitial_text) == (less_text > pinitial_text)); + CHECK((pinitial_text > less) == (pinitial_text > less_text)); - CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); - CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); + CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); + CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); - CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); - CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); + CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); + CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); - CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); - CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3316,8 +3695,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end(), buffer2.data(), buffer2.size()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); TextBuffer buffer3; const Text greater(greater_text.begin(), greater_text.end(), buffer3.data(), buffer3.size()); @@ -3333,24 +3712,24 @@ namespace CHECK((initial >= initial) == (initial_text >= initial_text)); // String-Pointer Pointer-String - CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); - CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); + CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); + CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); - CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); - CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); + CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); + CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); - CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); - CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); + CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); + CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); - CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); - CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); - + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3369,8 +3748,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3393,7 +3772,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3401,7 +3780,7 @@ namespace value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3413,15 +3792,15 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3441,8 +3820,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3451,12 +3830,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBuffer buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::wstring compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); @@ -3473,13 +3852,44 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::wstring<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::wstring<50> pin(STR("pin")); + Text pin(STR("pin"), buffer.data(), buffer.size()); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(TextL::npos, position2); + + View pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) { @@ -3487,7 +3897,7 @@ namespace const value_t* needle = STR("needle"); - std::wstring compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3506,7 +3916,7 @@ namespace position2 = haystack.find(needle, position2 + 1); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } @@ -3518,7 +3928,7 @@ namespace const value_t* needle = STR("needle"); - std::wstring compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3537,28 +3947,173 @@ namespace position2 = haystack.find(needle, position2 + 1, 3); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text needle(STR("needle"), buffer2.data(), buffer2.size()); + Text pin(STR("pin"), buffer3.data(), buffer3.size()); + Text excess(STR("A really gigantic pin or needle that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text start(STR("A haystack"), buffer2.data(), buffer2.size()); + Text not_start(STR("a needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text end(STR("else"), buffer2.data(), buffer2.size()); + Text not_end(STR("needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBufferL buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::wstring compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); - size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3575,19 +4130,46 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_pointer) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_haystack(the_haystack); + TextSTD compare_needle(STR("needle")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + View pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_pointer) + { + const value_t*the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3606,16 +4188,16 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::wstring::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; @@ -3634,15 +4216,15 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_c_position) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); - size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3659,7 +4241,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3668,35 +4250,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3705,35 +4323,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3742,35 +4396,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, TextL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); + CHECK(compares_agree(compare_result, result)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3807,7 +4497,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3844,7 +4534,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3881,38 +4571,68 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(TextL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(TextL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(TextL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(TextL(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3943,7 +4663,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3979,7 +4699,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4020,43 +4740,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(TextL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(TextL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(TextL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(TextL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(TextL(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4097,7 +4852,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4127,16 +4882,18 @@ namespace CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(STR("ZCXE"), 100, 4); position2 = text.find_last_of(STR("ZCXE"), 100, 4); CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" } //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4177,43 +4934,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(TextL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4249,7 +5041,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4290,7 +5082,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4331,43 +5123,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(TextL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(TextL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4403,7 +5230,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4437,7 +5264,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4712,6 +5539,23 @@ namespace CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_secure_after_clear) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.set_secure(); + text.assign(STR("ABCDEF")); + + Text::pointer pb = text.begin(); + Text::pointer pe = text.end(); + + text.clear(); + + // Check there no non-zero values in the remainder of the string. + CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_secure_flag_after_copy) {