From 104a439f683ec2972e4f4196b1ae49b0e837525e Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Thu, 7 Nov 2019 10:10:30 -0500 Subject: [PATCH] Add copyright --- test/fixed_string.cpp | 4017 +++++++++++++++++++++-------------------- 1 file changed, 2009 insertions(+), 2008 deletions(-) diff --git a/test/fixed_string.cpp b/test/fixed_string.cpp index 2001957..c4d4038 100644 --- a/test/fixed_string.cpp +++ b/test/fixed_string.cpp @@ -1,21 +1,22 @@ -// -// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/boostorg/fixed_string -// - -// Test that header file is self-contained. -#include - -#include - -namespace boost { -namespace fixed_string { - - +// +// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) +// Copyright (c) 2019 Krystian Stasiowski (sdkrystian at gmail dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/boostorg/fixed_string +// + +// Test that header file is self-contained. +#include + +#include + +namespace boost { +namespace fixed_string { + + template bool testS(const S& s, typename S::size_type pos, typename S::size_type n) @@ -25,22 +26,22 @@ testS(const S& s, typename S::size_type pos, typename S::size_type n) typename S::string_view_type str = s.substr(pos, n); typename S::size_type rlen = (std::min)(n, s.size() - pos); return (S::traits_type::compare(s.data() + pos, str.data(), rlen) == 0); - } - else - { - BOOST_TEST_THROWS((s.substr(pos, n)), std::out_of_range); - return true; - } -} - + } + else + { + BOOST_TEST_THROWS((s.substr(pos, n)), std::out_of_range); + return true; + } +} + template bool testAS(S s, const typename S::value_type* str, typename S::size_type n, S expected) { s.assign(str, n); return s == expected; -} - +} + template bool testI(S s, typename S::size_type pos, const typename S::value_type* str, typename S::size_type n, S expected) @@ -57,8 +58,8 @@ testI(S s, typename S::size_type pos, const typename S::value_type* str, typenam BOOST_TEST_THROWS((s.insert(pos, str, n)), std::out_of_range); return true; } -} - +} + template bool testE(S s, typename S::size_type pos, typename S::size_type n, S expected) @@ -75,15 +76,15 @@ testE(S s, typename S::size_type pos, typename S::size_type n, S expected) BOOST_TEST_THROWS(s.erase(pos, n), std::out_of_range); return true; } -} - +} + template bool testA(S s, const typename S::value_type* str, typename S::size_type n, S expected) { return s.append(str, n) == expected; -} - +} + int sign(int x) { @@ -92,8 +93,8 @@ sign(int x) if (x < 0) return -1; return 1; -} - +} + template bool testC(const S& s, typename S::size_type pos, typename S::size_type n1, const typename S::value_type* str, typename S::size_type n2, int x) @@ -104,51 +105,51 @@ testC(const S& s, typename S::size_type pos, typename S::size_type n1, const typ { BOOST_TEST_THROWS(s.compare(pos, n1, str, n2), std::out_of_range); return true; - } -} - + } +} + template bool testF(const S& s, const typename S::value_type* str, typename S::size_type pos, typename S::size_type n, typename S::size_type x) { return s.find(str, pos, n) == x; -} - +} + template bool testRF(const S& s, const typename S::value_type* str, typename S::size_type pos, typename S::size_type n, typename S::size_type x) { return s.rfind(str, pos, n) == x; -} - +} + template bool testFF(const S& s, const typename S::value_type* str, typename S::size_type pos, typename S::size_type n, typename S::size_type x) { return s.find_first_of(str, pos, n) == x; -} - +} + template bool testFL(const S& s, const typename S::value_type* str, typename S::size_type pos, typename S::size_type n, typename S::size_type x) { return s.find_last_of(str, pos, n) == x; -} - +} + template bool testFFN(const S& s, const typename S::value_type* str, typename S::size_type pos, typename S::size_type n, typename S::size_type x) { return s.find_first_not_of(str, pos, n) == x; -} - +} + template bool testFLN(const S& s, const typename S::value_type* str, typename S::size_type pos, typename S::size_type n, typename S::size_type x) { return s.find_last_not_of(str, pos, n) == x; -} - +} + template bool testR(S s, typename S::size_type pos1, typename S::size_type n1, const typename S::value_type* str, S expected) @@ -157,8 +158,8 @@ testR(S s, typename S::size_type pos1, typename S::size_type n1, const typename typename S::const_iterator last = s.begin() + pos1 + n1; s.replace(first, last, str); return s == expected; -} - +} + template bool testR(S s, typename S::size_type pos, typename S::size_type n1, typename S::size_type n2, typename S::value_type c, S expected) @@ -175,8 +176,8 @@ testR(S s, typename S::size_type pos, typename S::size_type n1, typename S::size BOOST_TEST_THROWS((s.replace(pos, n1, n2, c)), std::out_of_range); return true; } -} - +} + template bool testR(S s, typename S::size_type pos, typename S::size_type n1, const typename S::value_type* str, typename S::size_type n2, S expected) @@ -193,378 +194,378 @@ testR(S s, typename S::size_type pos, typename S::size_type n1, const typename S BOOST_TEST_THROWS((s.replace(pos, n1, str, n2)), std::out_of_range); return true; } -} - -// dpne -static -void -testConstruct() -{ - { - fixed_string<1> s; - BOOST_TEST(s.empty()); - BOOST_TEST(s.size() == 0); - BOOST_TEST(s == ""); - BOOST_TEST(*s.end() == 0); - } - { - fixed_string<4> s1(3, 'x'); - BOOST_TEST(! s1.empty()); - BOOST_TEST(s1.size() == 3); - BOOST_TEST(s1 == "xxx"); - BOOST_TEST(*s1.end() == 0); - BOOST_TEST_THROWS( - (fixed_string<2>(3, 'x')), - std::length_error); - } - { - fixed_string<5> s1("12345"); - BOOST_TEST(*s1.end() == 0); - fixed_string<3> s2(s1, 2); - BOOST_TEST(s2 == "345"); - BOOST_TEST(*s2.end() == 0); - fixed_string<0> s3(s1, 5); - BOOST_TEST(s3.empty()); - BOOST_TEST(s3.front() == 0); - BOOST_TEST(*s3.end() == 0); - } - { - fixed_string<5> s1("12345"); - fixed_string<2> s2(s1, 1, 2); - BOOST_TEST(s2 == "23"); - BOOST_TEST(*s2.end() == 0); - fixed_string<0> s3(s1, 5, 1); - BOOST_TEST(s3.empty()); - BOOST_TEST(s3.front() == 0); - BOOST_TEST(*s3.end() == 0); - BOOST_TEST_THROWS( - (fixed_string<5>(s1, 6)), - std::out_of_range); - } - { - fixed_string<5> s1("UVXYZ", 3); - BOOST_TEST(s1 == "UVX"); - BOOST_TEST(*s1.end() == 0); - fixed_string<5> s2("X\0""Y\0""Z", 3); - BOOST_TEST(std::memcmp( - s2.data(), "X\0""Y", 3) == 0); - BOOST_TEST(*s2.end() == 0); - } - { - fixed_string<5> s1("12345"); - fixed_string<3> s2( - s1.begin() + 1, s1.begin() + 3); - BOOST_TEST(s2 == "23"); - BOOST_TEST(*s2.end() == 0); - } - { - fixed_string<5> s1("12345"); - fixed_string<5> s2(s1); - BOOST_TEST(s2 == "12345"); - BOOST_TEST(*s2.end() == 0); - fixed_string<6> s3(s1); - BOOST_TEST(s3 == "12345"); - BOOST_TEST(*s3.end() == 0); - BOOST_TEST_THROWS( - (fixed_string<4>(s1)), - std::length_error); - } - { - fixed_string<3> s1({'1', '2', '3'}); - BOOST_TEST(s1 == "123"); - BOOST_TEST(*s1.end() == 0); - BOOST_TEST( - fixed_string<0>({}) == fixed_string<0>()); - BOOST_TEST_THROWS( - (fixed_string<2>({'1', '2', '3'})), - std::length_error); - } - { - fixed_string<3> s1( - string_view("123")); - BOOST_TEST(s1 == "123"); - BOOST_TEST(*s1.end() == 0); - BOOST_TEST_THROWS( - (fixed_string<2>(string_view("123"))), - std::length_error); - } - { - fixed_string<5> s1( - std::string("12345"), 2, 2); - BOOST_TEST(s1 == "34"); - BOOST_TEST(*s1.end() == 0); - BOOST_TEST_THROWS( - (fixed_string<2>(std::string("12345"), 1, 3)), - std::length_error); - } - { - BOOST_TEST_THROWS(fixed_string<5>("12345678"), std::length_error); - } -} - -//done -static -void -testAssignment() -{ - // assign(size_type count, CharT ch) - BOOST_TEST(fixed_string<3>{}.assign(1, '*') == "*"); - BOOST_TEST(fixed_string<3>{}.assign(3, '*') == "***"); - BOOST_TEST(fixed_string<3>{"abc"}.assign(3, '*') == "***"); - BOOST_TEST_THROWS(fixed_string<1>{"a"}.assign(2, '*'), std::length_error); - - // assign(fixed_string const& s) noexcept - BOOST_TEST(fixed_string<3>{}.assign(fixed_string<3>{"abc"}) == "abc"); - BOOST_TEST(fixed_string<3>{"*"}.assign(fixed_string<3>{"abc"}) == "abc"); - BOOST_TEST(fixed_string<3>{"***"}.assign(fixed_string<3>{"abc"}) == "abc"); - - // assign(fixed_string const& s) - BOOST_TEST(fixed_string<3>{}.assign(fixed_string<5>{"abc"}) == "abc"); - BOOST_TEST(fixed_string<3>{"*"}.assign(fixed_string<5>{"abc"}) == "abc"); - BOOST_TEST(fixed_string<3>{"***"}.assign(fixed_string<5>{"abc"}) == "abc"); - { - fixed_string<3> s("***"); - BOOST_TEST(s.assign(s) == s); - } - BOOST_TEST_THROWS(fixed_string<3>{}.assign(fixed_string<5>{"abcde"}), std::length_error); - - // assign(fixed_string const& s, size_type pos, size_type count = npos) - BOOST_TEST(fixed_string<4>{}.assign(fixed_string<5>{"abcde"}, 1) == "bcde"); - BOOST_TEST(fixed_string<3>{}.assign(fixed_string<5>{"abcde"}, 1, 3) == "bcd"); - BOOST_TEST(fixed_string<3>{"*"}.assign(fixed_string<5>{"abcde"}, 1, 3) == "bcd"); - BOOST_TEST(fixed_string<3>{"***"}.assign(fixed_string<5>{"abcde"}, 1, 3) == "bcd"); - BOOST_TEST_THROWS(fixed_string<3>{}.assign(fixed_string<5>{"abcde"}, 0), std::length_error); - - // assign(CharT const* s, size_type count) - BOOST_TEST(fixed_string<3>{}.assign("abc", 3) == "abc"); - BOOST_TEST(fixed_string<3>{"*"}.assign("abc", 3) == "abc"); - BOOST_TEST_THROWS(fixed_string<1>{}.assign("abc", 3), std::length_error); - - // assign(CharT const* s) - BOOST_TEST(fixed_string<3>{}.assign("abc") == "abc"); - BOOST_TEST(fixed_string<3>{"*"}.assign("abc") == "abc"); - BOOST_TEST_THROWS(fixed_string<1>{}.assign("abc"), std::length_error); - - // assign(InputIt first, InputIt last) - { - fixed_string<4> const cs{"abcd"}; - fixed_string<4> s{"ad"}; - BOOST_TEST(fixed_string<4>{}.assign(cs.begin(), cs.end()) == "abcd"); - BOOST_TEST(fixed_string<4>{"*"}.assign(cs.begin(), cs.end()) == "abcd"); - BOOST_TEST_THROWS(fixed_string<2>{"*"}.assign(cs.begin(), cs.end()), std::length_error); - } - - // assign(std::initializer_list ilist) - BOOST_TEST(fixed_string<3>{}.assign({'a', 'b', 'c'}) == "abc"); - BOOST_TEST(fixed_string<3>{"*"}.assign({'a', 'b', 'c'}) == "abc"); - BOOST_TEST(fixed_string<3>{"***"}.assign({'a', 'b', 'c'}) == "abc"); - BOOST_TEST_THROWS(fixed_string<1>{}.assign({'a', 'b', 'c'}), std::length_error); - - // assign(T const& t) - { - struct T - { - operator string_view() const noexcept - { - return "abc"; - } - }; - BOOST_TEST(fixed_string<3>{}.assign(T{}) == "abc"); - BOOST_TEST(fixed_string<3>{"*"}.assign(T{}) == "abc"); - BOOST_TEST(fixed_string<3>{"***"}.assign(T{}) == "abc"); - BOOST_TEST_THROWS(fixed_string<2>{"**"}.assign(T{}), std::length_error); - } - - // assign(T const& t, size_type pos, size_type count = npos) - { - struct T - { - operator string_view() const noexcept - { - return "abcde"; - } - }; - BOOST_TEST(fixed_string<5>{}.assign(T{}, 0) == "abcde"); - BOOST_TEST(fixed_string<5>{}.assign(T{}, 0, 5) == "abcde"); - BOOST_TEST(fixed_string<5>{}.assign(T{}, 1, 3) == "bcd"); - BOOST_TEST(fixed_string<5>{"*"}.assign(T{}, 1) == "bcde"); - BOOST_TEST_THROWS(fixed_string<2>{"**"}.assign(T{}, 6, 3), std::out_of_range); - BOOST_TEST_THROWS(fixed_string<2>{"**"}.assign(T{}, 1, 3), std::length_error); - } - - //--- - - { - fixed_string<3> s1("123"); - fixed_string<3> s2; - s2 = s1; - BOOST_TEST(s2 == "123"); - BOOST_TEST(*s2.end() == 0); - } - { - fixed_string<3> s1("123"); - fixed_string<5> s2; - s2 = s1; - BOOST_TEST(s2 == "123"); - BOOST_TEST(*s2.end() == 0); - fixed_string<1> s3; - BOOST_TEST_THROWS( - s3 = s1, - std::length_error); - } - { - fixed_string<3> s1; - s1 = "123"; - BOOST_TEST(s1 == "123"); - BOOST_TEST(*s1.end() == 0); - fixed_string<1> s2; - BOOST_TEST_THROWS( - s2 = "123", - std::length_error); - } - { - fixed_string<1> s1; - s1 = 'x'; - BOOST_TEST(s1 == "x"); - BOOST_TEST(*s1.end() == 0); - fixed_string<0> s2; - BOOST_TEST_THROWS( - s2 = 'x', - std::length_error); - } - { - fixed_string<3> s1; - s1 = {'1', '2', '3'}; - BOOST_TEST(s1 == "123"); - BOOST_TEST(*s1.end() == 0); - fixed_string<1> s2; - BOOST_TEST_THROWS( - (s2 = {'1', '2', '3'}), - std::length_error); - } - { - fixed_string<3> s1; - s1 = string_view("123"); - BOOST_TEST(s1 == "123"); - BOOST_TEST(*s1.end() == 0); - fixed_string<1> s2; - BOOST_TEST_THROWS( - s2 = string_view("123"), - std::length_error); - } - - { - fixed_string<4> s1; - s1.assign(3, 'x'); - BOOST_TEST(s1 == "xxx"); - BOOST_TEST(*s1.end() == 0); - fixed_string<2> s2; - BOOST_TEST_THROWS( - s2.assign(3, 'x'), - std::length_error); - } - { - fixed_string<5> s1("12345"); - BOOST_TEST(*s1.end() == 0); - fixed_string<5> s2; - s2.assign(s1); - BOOST_TEST(s2 == "12345"); - BOOST_TEST(*s2.end() == 0); - } - { - fixed_string<5> s1("12345"); - BOOST_TEST(*s1.end() == 0); - fixed_string<7> s2; - s2.assign(s1); - BOOST_TEST(s2 == "12345"); - BOOST_TEST(*s2.end() == 0); - fixed_string<3> s3; - BOOST_TEST_THROWS( - s3.assign(s1), - std::length_error); - } - { - fixed_string<5> s1("12345"); - fixed_string<5> s2; - s2.assign(s1, 1); - BOOST_TEST(s2 == "2345"); - BOOST_TEST(*s2.end() == 0); - s2.assign(s1, 1, 2); - BOOST_TEST(s2 == "23"); - BOOST_TEST(*s2.end() == 0); - s2.assign(s1, 1, 100); - BOOST_TEST(s2 == "2345"); - BOOST_TEST(*s2.end() == 0); - BOOST_TEST_THROWS( - (s2.assign(s1, 6)), - std::out_of_range); - fixed_string<3> s3; - BOOST_TEST_THROWS( - s3.assign(s1, 1), - std::length_error); - } - { - fixed_string<5> s1; - s1.assign("12"); - BOOST_TEST(s1 == "12"); - BOOST_TEST(*s1.end() == 0); - s1.assign("12345"); - BOOST_TEST(s1 == "12345"); - BOOST_TEST(*s1.end() == 0); - } - { - fixed_string<5> s1; - s1.assign("12345", 3); - BOOST_TEST(s1 == "123"); - BOOST_TEST(*s1.end() == 0); - } - { - fixed_string<5> s1("12345"); - fixed_string<3> s2; - s2.assign(s1.begin(), s1.begin() + 2); - BOOST_TEST(s2 == "12"); - BOOST_TEST(*s2.end() == 0); - BOOST_TEST_THROWS( - (s2.assign(s1.begin(), s1.end())), - std::length_error); - } - { - fixed_string<5> s1; - s1.assign({'1', '2', '3'}); - BOOST_TEST(s1 == "123"); - BOOST_TEST(*s1.end() == 0); - fixed_string<1> s2; - BOOST_TEST_THROWS( - (s2.assign({'1', '2', '3'})), - std::length_error); - } - { - fixed_string<5> s1; - s1.assign(string_view("123")); - BOOST_TEST(s1 == "123"); - BOOST_TEST(*s1.end() == 0); - s1.assign(string_view("12345")); - BOOST_TEST(s1 == "12345"); - BOOST_TEST(*s1.end() == 0); - BOOST_TEST_THROWS( - s1.assign(string_view("1234567")), - std::length_error); - } - { - fixed_string<5> s1; - s1.assign(std::string("12345"), 2, 2); - BOOST_TEST(s1 == "34"); - BOOST_TEST(*s1.end() == 0); - s1.assign(std::string("12345"), 3); - BOOST_TEST(s1 == "45"); - BOOST_TEST(*s1.end() == 0); - fixed_string<2> s2; - BOOST_TEST_THROWS( - (s2.assign(std::string("12345"), 1, 3)), - std::length_error); - } - - using S = fixed_string<400>; +} + +// dpne +static +void +testConstruct() +{ + { + fixed_string<1> s; + BOOST_TEST(s.empty()); + BOOST_TEST(s.size() == 0); + BOOST_TEST(s == ""); + BOOST_TEST(*s.end() == 0); + } + { + fixed_string<4> s1(3, 'x'); + BOOST_TEST(! s1.empty()); + BOOST_TEST(s1.size() == 3); + BOOST_TEST(s1 == "xxx"); + BOOST_TEST(*s1.end() == 0); + BOOST_TEST_THROWS( + (fixed_string<2>(3, 'x')), + std::length_error); + } + { + fixed_string<5> s1("12345"); + BOOST_TEST(*s1.end() == 0); + fixed_string<3> s2(s1, 2); + BOOST_TEST(s2 == "345"); + BOOST_TEST(*s2.end() == 0); + fixed_string<0> s3(s1, 5); + BOOST_TEST(s3.empty()); + BOOST_TEST(s3.front() == 0); + BOOST_TEST(*s3.end() == 0); + } + { + fixed_string<5> s1("12345"); + fixed_string<2> s2(s1, 1, 2); + BOOST_TEST(s2 == "23"); + BOOST_TEST(*s2.end() == 0); + fixed_string<0> s3(s1, 5, 1); + BOOST_TEST(s3.empty()); + BOOST_TEST(s3.front() == 0); + BOOST_TEST(*s3.end() == 0); + BOOST_TEST_THROWS( + (fixed_string<5>(s1, 6)), + std::out_of_range); + } + { + fixed_string<5> s1("UVXYZ", 3); + BOOST_TEST(s1 == "UVX"); + BOOST_TEST(*s1.end() == 0); + fixed_string<5> s2("X\0""Y\0""Z", 3); + BOOST_TEST(std::memcmp( + s2.data(), "X\0""Y", 3) == 0); + BOOST_TEST(*s2.end() == 0); + } + { + fixed_string<5> s1("12345"); + fixed_string<3> s2( + s1.begin() + 1, s1.begin() + 3); + BOOST_TEST(s2 == "23"); + BOOST_TEST(*s2.end() == 0); + } + { + fixed_string<5> s1("12345"); + fixed_string<5> s2(s1); + BOOST_TEST(s2 == "12345"); + BOOST_TEST(*s2.end() == 0); + fixed_string<6> s3(s1); + BOOST_TEST(s3 == "12345"); + BOOST_TEST(*s3.end() == 0); + BOOST_TEST_THROWS( + (fixed_string<4>(s1)), + std::length_error); + } + { + fixed_string<3> s1({'1', '2', '3'}); + BOOST_TEST(s1 == "123"); + BOOST_TEST(*s1.end() == 0); + BOOST_TEST( + fixed_string<0>({}) == fixed_string<0>()); + BOOST_TEST_THROWS( + (fixed_string<2>({'1', '2', '3'})), + std::length_error); + } + { + fixed_string<3> s1( + string_view("123")); + BOOST_TEST(s1 == "123"); + BOOST_TEST(*s1.end() == 0); + BOOST_TEST_THROWS( + (fixed_string<2>(string_view("123"))), + std::length_error); + } + { + fixed_string<5> s1( + std::string("12345"), 2, 2); + BOOST_TEST(s1 == "34"); + BOOST_TEST(*s1.end() == 0); + BOOST_TEST_THROWS( + (fixed_string<2>(std::string("12345"), 1, 3)), + std::length_error); + } + { + BOOST_TEST_THROWS(fixed_string<5>("12345678"), std::length_error); + } +} + +//done +static +void +testAssignment() +{ + // assign(size_type count, CharT ch) + BOOST_TEST(fixed_string<3>{}.assign(1, '*') == "*"); + BOOST_TEST(fixed_string<3>{}.assign(3, '*') == "***"); + BOOST_TEST(fixed_string<3>{"abc"}.assign(3, '*') == "***"); + BOOST_TEST_THROWS(fixed_string<1>{"a"}.assign(2, '*'), std::length_error); + + // assign(fixed_string const& s) noexcept + BOOST_TEST(fixed_string<3>{}.assign(fixed_string<3>{"abc"}) == "abc"); + BOOST_TEST(fixed_string<3>{"*"}.assign(fixed_string<3>{"abc"}) == "abc"); + BOOST_TEST(fixed_string<3>{"***"}.assign(fixed_string<3>{"abc"}) == "abc"); + + // assign(fixed_string const& s) + BOOST_TEST(fixed_string<3>{}.assign(fixed_string<5>{"abc"}) == "abc"); + BOOST_TEST(fixed_string<3>{"*"}.assign(fixed_string<5>{"abc"}) == "abc"); + BOOST_TEST(fixed_string<3>{"***"}.assign(fixed_string<5>{"abc"}) == "abc"); + { + fixed_string<3> s("***"); + BOOST_TEST(s.assign(s) == s); + } + BOOST_TEST_THROWS(fixed_string<3>{}.assign(fixed_string<5>{"abcde"}), std::length_error); + + // assign(fixed_string const& s, size_type pos, size_type count = npos) + BOOST_TEST(fixed_string<4>{}.assign(fixed_string<5>{"abcde"}, 1) == "bcde"); + BOOST_TEST(fixed_string<3>{}.assign(fixed_string<5>{"abcde"}, 1, 3) == "bcd"); + BOOST_TEST(fixed_string<3>{"*"}.assign(fixed_string<5>{"abcde"}, 1, 3) == "bcd"); + BOOST_TEST(fixed_string<3>{"***"}.assign(fixed_string<5>{"abcde"}, 1, 3) == "bcd"); + BOOST_TEST_THROWS(fixed_string<3>{}.assign(fixed_string<5>{"abcde"}, 0), std::length_error); + + // assign(CharT const* s, size_type count) + BOOST_TEST(fixed_string<3>{}.assign("abc", 3) == "abc"); + BOOST_TEST(fixed_string<3>{"*"}.assign("abc", 3) == "abc"); + BOOST_TEST_THROWS(fixed_string<1>{}.assign("abc", 3), std::length_error); + + // assign(CharT const* s) + BOOST_TEST(fixed_string<3>{}.assign("abc") == "abc"); + BOOST_TEST(fixed_string<3>{"*"}.assign("abc") == "abc"); + BOOST_TEST_THROWS(fixed_string<1>{}.assign("abc"), std::length_error); + + // assign(InputIt first, InputIt last) + { + fixed_string<4> const cs{"abcd"}; + fixed_string<4> s{"ad"}; + BOOST_TEST(fixed_string<4>{}.assign(cs.begin(), cs.end()) == "abcd"); + BOOST_TEST(fixed_string<4>{"*"}.assign(cs.begin(), cs.end()) == "abcd"); + BOOST_TEST_THROWS(fixed_string<2>{"*"}.assign(cs.begin(), cs.end()), std::length_error); + } + + // assign(std::initializer_list ilist) + BOOST_TEST(fixed_string<3>{}.assign({'a', 'b', 'c'}) == "abc"); + BOOST_TEST(fixed_string<3>{"*"}.assign({'a', 'b', 'c'}) == "abc"); + BOOST_TEST(fixed_string<3>{"***"}.assign({'a', 'b', 'c'}) == "abc"); + BOOST_TEST_THROWS(fixed_string<1>{}.assign({'a', 'b', 'c'}), std::length_error); + + // assign(T const& t) + { + struct T + { + operator string_view() const noexcept + { + return "abc"; + } + }; + BOOST_TEST(fixed_string<3>{}.assign(T{}) == "abc"); + BOOST_TEST(fixed_string<3>{"*"}.assign(T{}) == "abc"); + BOOST_TEST(fixed_string<3>{"***"}.assign(T{}) == "abc"); + BOOST_TEST_THROWS(fixed_string<2>{"**"}.assign(T{}), std::length_error); + } + + // assign(T const& t, size_type pos, size_type count = npos) + { + struct T + { + operator string_view() const noexcept + { + return "abcde"; + } + }; + BOOST_TEST(fixed_string<5>{}.assign(T{}, 0) == "abcde"); + BOOST_TEST(fixed_string<5>{}.assign(T{}, 0, 5) == "abcde"); + BOOST_TEST(fixed_string<5>{}.assign(T{}, 1, 3) == "bcd"); + BOOST_TEST(fixed_string<5>{"*"}.assign(T{}, 1) == "bcde"); + BOOST_TEST_THROWS(fixed_string<2>{"**"}.assign(T{}, 6, 3), std::out_of_range); + BOOST_TEST_THROWS(fixed_string<2>{"**"}.assign(T{}, 1, 3), std::length_error); + } + + //--- + + { + fixed_string<3> s1("123"); + fixed_string<3> s2; + s2 = s1; + BOOST_TEST(s2 == "123"); + BOOST_TEST(*s2.end() == 0); + } + { + fixed_string<3> s1("123"); + fixed_string<5> s2; + s2 = s1; + BOOST_TEST(s2 == "123"); + BOOST_TEST(*s2.end() == 0); + fixed_string<1> s3; + BOOST_TEST_THROWS( + s3 = s1, + std::length_error); + } + { + fixed_string<3> s1; + s1 = "123"; + BOOST_TEST(s1 == "123"); + BOOST_TEST(*s1.end() == 0); + fixed_string<1> s2; + BOOST_TEST_THROWS( + s2 = "123", + std::length_error); + } + { + fixed_string<1> s1; + s1 = 'x'; + BOOST_TEST(s1 == "x"); + BOOST_TEST(*s1.end() == 0); + fixed_string<0> s2; + BOOST_TEST_THROWS( + s2 = 'x', + std::length_error); + } + { + fixed_string<3> s1; + s1 = {'1', '2', '3'}; + BOOST_TEST(s1 == "123"); + BOOST_TEST(*s1.end() == 0); + fixed_string<1> s2; + BOOST_TEST_THROWS( + (s2 = {'1', '2', '3'}), + std::length_error); + } + { + fixed_string<3> s1; + s1 = string_view("123"); + BOOST_TEST(s1 == "123"); + BOOST_TEST(*s1.end() == 0); + fixed_string<1> s2; + BOOST_TEST_THROWS( + s2 = string_view("123"), + std::length_error); + } + + { + fixed_string<4> s1; + s1.assign(3, 'x'); + BOOST_TEST(s1 == "xxx"); + BOOST_TEST(*s1.end() == 0); + fixed_string<2> s2; + BOOST_TEST_THROWS( + s2.assign(3, 'x'), + std::length_error); + } + { + fixed_string<5> s1("12345"); + BOOST_TEST(*s1.end() == 0); + fixed_string<5> s2; + s2.assign(s1); + BOOST_TEST(s2 == "12345"); + BOOST_TEST(*s2.end() == 0); + } + { + fixed_string<5> s1("12345"); + BOOST_TEST(*s1.end() == 0); + fixed_string<7> s2; + s2.assign(s1); + BOOST_TEST(s2 == "12345"); + BOOST_TEST(*s2.end() == 0); + fixed_string<3> s3; + BOOST_TEST_THROWS( + s3.assign(s1), + std::length_error); + } + { + fixed_string<5> s1("12345"); + fixed_string<5> s2; + s2.assign(s1, 1); + BOOST_TEST(s2 == "2345"); + BOOST_TEST(*s2.end() == 0); + s2.assign(s1, 1, 2); + BOOST_TEST(s2 == "23"); + BOOST_TEST(*s2.end() == 0); + s2.assign(s1, 1, 100); + BOOST_TEST(s2 == "2345"); + BOOST_TEST(*s2.end() == 0); + BOOST_TEST_THROWS( + (s2.assign(s1, 6)), + std::out_of_range); + fixed_string<3> s3; + BOOST_TEST_THROWS( + s3.assign(s1, 1), + std::length_error); + } + { + fixed_string<5> s1; + s1.assign("12"); + BOOST_TEST(s1 == "12"); + BOOST_TEST(*s1.end() == 0); + s1.assign("12345"); + BOOST_TEST(s1 == "12345"); + BOOST_TEST(*s1.end() == 0); + } + { + fixed_string<5> s1; + s1.assign("12345", 3); + BOOST_TEST(s1 == "123"); + BOOST_TEST(*s1.end() == 0); + } + { + fixed_string<5> s1("12345"); + fixed_string<3> s2; + s2.assign(s1.begin(), s1.begin() + 2); + BOOST_TEST(s2 == "12"); + BOOST_TEST(*s2.end() == 0); + BOOST_TEST_THROWS( + (s2.assign(s1.begin(), s1.end())), + std::length_error); + } + { + fixed_string<5> s1; + s1.assign({'1', '2', '3'}); + BOOST_TEST(s1 == "123"); + BOOST_TEST(*s1.end() == 0); + fixed_string<1> s2; + BOOST_TEST_THROWS( + (s2.assign({'1', '2', '3'})), + std::length_error); + } + { + fixed_string<5> s1; + s1.assign(string_view("123")); + BOOST_TEST(s1 == "123"); + BOOST_TEST(*s1.end() == 0); + s1.assign(string_view("12345")); + BOOST_TEST(s1 == "12345"); + BOOST_TEST(*s1.end() == 0); + BOOST_TEST_THROWS( + s1.assign(string_view("1234567")), + std::length_error); + } + { + fixed_string<5> s1; + s1.assign(std::string("12345"), 2, 2); + BOOST_TEST(s1 == "34"); + BOOST_TEST(*s1.end() == 0); + s1.assign(std::string("12345"), 3); + BOOST_TEST(s1 == "45"); + BOOST_TEST(*s1.end() == 0); + fixed_string<2> s2; + BOOST_TEST_THROWS( + (s2.assign(std::string("12345"), 1, 3)), + std::length_error); + } + + using S = fixed_string<400>; BOOST_TEST(testAS(S(), "", 0, S())); BOOST_TEST(testAS(S(), "12345", 3, S("123"))); BOOST_TEST(testAS(S(), "12345", 4, S("1234"))); @@ -610,502 +611,502 @@ testAssignment() BOOST_TEST(s_long == "Lorem ipsum dolor sit amet, consectetur/"); s_long.assign(s_long.data() + 2, 8); - BOOST_TEST(s_long == "rem ipsu"); -} - -// done -static -void -testElements() -{ - using cfs3 = fixed_string<3> const; - - // at(size_type pos) - BOOST_TEST(fixed_string<3>{"abc"}.at(0) == 'a'); - BOOST_TEST(fixed_string<3>{"abc"}.at(2) == 'c'); - BOOST_TEST_THROWS(fixed_string<3>{""}.at(0), std::out_of_range); - BOOST_TEST_THROWS(fixed_string<3>{"abc"}.at(4), std::out_of_range); - - // at(size_type pos) const - BOOST_TEST(cfs3{"abc"}.at(0) == 'a'); - BOOST_TEST(cfs3{"abc"}.at(2) == 'c'); - BOOST_TEST_THROWS(cfs3{""}.at(0), std::out_of_range); - BOOST_TEST_THROWS(cfs3{"abc"}.at(4), std::out_of_range); - - // operator[](size_type pos) - BOOST_TEST(fixed_string<3>{"abc"}[0] == 'a'); - BOOST_TEST(fixed_string<3>{"abc"}[2] == 'c'); - BOOST_TEST(fixed_string<3>{"abc"}[3] == 0); - BOOST_TEST(fixed_string<3>{""}[0] == 0); - - // operator[](size_type pos) const - BOOST_TEST(cfs3{"abc"}[0] == 'a'); - BOOST_TEST(cfs3{"abc"}[2] == 'c'); - BOOST_TEST(cfs3{"abc"}[3] == 0); - BOOST_TEST(cfs3{""}[0] == 0); - - // front() - BOOST_TEST(fixed_string<3>{"a"}.front() == 'a'); - BOOST_TEST(fixed_string<3>{"abc"}.front() == 'a'); - - // front() const - BOOST_TEST(cfs3{"a"}.front() == 'a'); - BOOST_TEST(cfs3{"abc"}.front() == 'a'); - - // back() - BOOST_TEST(fixed_string<3>{"a"}.back() == 'a'); - BOOST_TEST(fixed_string<3>{"abc"}.back() == 'c'); - - // back() const - BOOST_TEST(cfs3{"a"}.back() == 'a'); - BOOST_TEST(cfs3{"abc"}.back() == 'c'); - - // data() noexcept - // data() const noexcept - // c_str() const noexcept - // operator string_view_type() const noexcept - - //--- - - { - fixed_string<5> s("12345"); - BOOST_TEST(s.at(1) == '2'); - BOOST_TEST(s.at(4) == '5'); - BOOST_TEST_THROWS( - s.at(5) = 0, - std::out_of_range); - } - { - fixed_string<5> const s("12345"); - BOOST_TEST(s.at(1) == '2'); - BOOST_TEST(s.at(4) == '5'); - BOOST_TEST_THROWS( - s.at(5), - std::out_of_range); - } - { - fixed_string<5> s("12345"); - BOOST_TEST(s[1] == '2'); - BOOST_TEST(s[4] == '5'); - s[1] = '_'; - BOOST_TEST(s == "1_345"); - } - { - fixed_string<5> const s("12345"); - BOOST_TEST(s[1] == '2'); - BOOST_TEST(s[4] == '5'); - BOOST_TEST(s[5] == 0); - } - { - fixed_string<3> s("123"); - BOOST_TEST(s.front() == '1'); - BOOST_TEST(s.back() == '3'); - s.front() = '_'; - BOOST_TEST(s == "_23"); - s.back() = '_'; - BOOST_TEST(s == "_2_"); - } - { - fixed_string<3> const s("123"); - BOOST_TEST(s.front() == '1'); - BOOST_TEST(s.back() == '3'); - } - { - fixed_string<3> s("123"); - BOOST_TEST(std::memcmp( - s.data(), "123", 3) == 0); - } - { - fixed_string<3> const s("123"); - BOOST_TEST(std::memcmp( - s.data(), "123", 3) == 0); - } - { - fixed_string<3> s("123"); - BOOST_TEST(std::memcmp( - s.c_str(), "123\0", 4) == 0); - } - { - fixed_string<3> s("123"); - string_view sv = s; - BOOST_TEST(fixed_string<5>(sv) == "123"); - } -} - -// done -static -void -testIterators() -{ - { - fixed_string<3> s; - BOOST_TEST(std::distance(s.begin(), s.end()) == 0); - BOOST_TEST(std::distance(s.rbegin(), s.rend()) == 0); - s = "123"; - BOOST_TEST(std::distance(s.begin(), s.end()) == 3); - BOOST_TEST(std::distance(s.rbegin(), s.rend()) == 3); - } - { - fixed_string<3> const s("123"); - BOOST_TEST(std::distance(s.begin(), s.end()) == 3); - BOOST_TEST(std::distance(s.cbegin(), s.cend()) == 3); - BOOST_TEST(std::distance(s.rbegin(), s.rend()) == 3); - BOOST_TEST(std::distance(s.crbegin(), s.crend()) == 3); - } -} - -// done -static -void -testCapacity() -{ - // empty() - BOOST_TEST(fixed_string<0>{}.empty()); - BOOST_TEST(fixed_string<1>{}.empty()); - BOOST_TEST(! fixed_string<1>{"a"}.empty()); - BOOST_TEST(! fixed_string<3>{"abc"}.empty()); - - // size() - BOOST_TEST(fixed_string<0>{}.size() == 0); - BOOST_TEST(fixed_string<1>{}.size() == 0); - BOOST_TEST(fixed_string<1>{"a"}.size() == 1); - BOOST_TEST(fixed_string<3>{"abc"}.size() == 3); - BOOST_TEST(fixed_string<5>{"abc"}.size() == 3); - - // length() - BOOST_TEST(fixed_string<0>{}.length() == 0); - BOOST_TEST(fixed_string<1>{}.length() == 0); - BOOST_TEST(fixed_string<1>{"a"}.length() == 1); - BOOST_TEST(fixed_string<3>{"abc"}.length() == 3); - BOOST_TEST(fixed_string<5>{"abc"}.length() == 3); - - // max_size() - BOOST_TEST(fixed_string<0>{}.max_size() == 0); - BOOST_TEST(fixed_string<1>{}.max_size() == 1); - BOOST_TEST(fixed_string<1>{"a"}.max_size() == 1); - BOOST_TEST(fixed_string<3>{"abc"}.max_size() == 3); - BOOST_TEST(fixed_string<5>{"abc"}.max_size() == 5); - - // reserve(std::size_t n) - fixed_string<3>{}.reserve(0); - fixed_string<3>{}.reserve(1); - fixed_string<3>{}.reserve(3); - BOOST_TEST_THROWS(fixed_string<0>{}.reserve(1), std::length_error); - BOOST_TEST_THROWS(fixed_string<3>{}.reserve(4), std::length_error); - - // capacity() - BOOST_TEST(fixed_string<0>{}.capacity() == 0); - BOOST_TEST(fixed_string<1>{}.capacity() == 1); - BOOST_TEST(fixed_string<1>{"a"}.capacity() == 1); - BOOST_TEST(fixed_string<3>{"abc"}.capacity() == 3); - BOOST_TEST(fixed_string<5>{"abc"}.capacity() == 5); - - //--- - - fixed_string<3> s; - BOOST_TEST(s.empty()); - BOOST_TEST(s.size() == 0); - BOOST_TEST(s.length() == 0); - BOOST_TEST(s.max_size() == 3); - BOOST_TEST(s.capacity() == 3); - s = "123"; - BOOST_TEST(! s.empty()); - BOOST_TEST(s.size() == 3); - BOOST_TEST(s.length() == 3); - s.reserve(0); - s.reserve(3); - BOOST_TEST_THROWS( - s.reserve(4), - std::length_error); - s.shrink_to_fit(); - BOOST_TEST(! s.empty()); - BOOST_TEST(s.size() == 3); - BOOST_TEST(s.length() == 3); - BOOST_TEST(*s.end() == 0); -} - -// done -static -void -testClear() -{ - // clear() - fixed_string<3> s("123"); - s.clear(); - BOOST_TEST(s.empty()); - BOOST_TEST(*s.end() == 0); -} - -// done -static -void -testInsert() -{ - using sv = string_view; - using S = fixed_string<100>; - - // insert(size_type index, size_type count, CharT ch) - // The overload resolution is ambiguous - // here because 0 is also a pointer type - //BOOST_TEST(fixed_string<3>{"bc"}.insert(0, 1, 'a') == "abc"); - BOOST_TEST(fixed_string<3>{"bc"}.insert(std::size_t(0), 1, 'a') == "abc"); - BOOST_TEST(fixed_string<3>{"ac"}.insert(1, 1, 'b') == "abc"); - BOOST_TEST(fixed_string<3>{"ab"}.insert(2, 1, 'c') == "abc"); - BOOST_TEST_THROWS(fixed_string<4>{"abc"}.insert(4, 1, '*'), std::out_of_range); - BOOST_TEST_THROWS(fixed_string<3>{"abc"}.insert(1, 1, '*'), std::length_error); - - // insert(size_type index, CharT const* s) - BOOST_TEST(fixed_string<3>{"bc"}.insert(0, "a") == "abc"); - BOOST_TEST_THROWS(fixed_string<4>{"abc"}.insert(4, "*"), std::out_of_range); - BOOST_TEST_THROWS(fixed_string<3>{"abc"}.insert(1, "*"), std::length_error); - - // insert(size_type index, CharT const* s, size_type count) - BOOST_TEST(fixed_string<4>{"ad"}.insert(1, "bcd", 2) == "abcd"); - BOOST_TEST_THROWS(fixed_string<4>{"abc"}.insert(4, "*"), std::out_of_range); - BOOST_TEST_THROWS(fixed_string<3>{"abc"}.insert(1, "*"), std::length_error); - - // insert(size_type index, string_view_type sv) - BOOST_TEST(fixed_string<3>{"ac"}.insert(1, sv{"b"}) == "abc"); - BOOST_TEST_THROWS(fixed_string<4>{"abc"}.insert(4, sv{"*"}), std::out_of_range); - BOOST_TEST_THROWS(fixed_string<3>{"abc"}.insert(1, sv{"*"}), std::length_error); - - // insert(size_type index, string_view_type sv, size_type index_str, size_type count = npos) - BOOST_TEST(fixed_string<4>{"ad"}.insert(1, sv{"abcd"}, 1, 2) == "abcd"); - BOOST_TEST(fixed_string<4>{"ad"}.insert(1, sv{"abc"}, 1) == "abcd"); - BOOST_TEST_THROWS((fixed_string<4>{"ad"}.insert(1, sv{"bc"}, 3, 0)), std::out_of_range); - BOOST_TEST_THROWS((fixed_string<3>{"ad"}.insert(1, sv{"bc"}, 0, 2)), std::length_error); - - // insert(const_iterator pos, CharT ch) - { - fixed_string<3> s{"ac"}; - BOOST_TEST(s.insert(s.begin() + 1, 'b') == s.begin() + 1); - BOOST_TEST(s == "abc"); - BOOST_TEST_THROWS(s.insert(s.begin() + 1, '*'), std::length_error); - } - - // insert(const_iterator pos, size_type count, CharT ch) - { - fixed_string<4> s{"ac"}; - BOOST_TEST(s.insert(s.begin() + 1, 2, 'b') == s.begin() + 1); - BOOST_TEST(s == "abbc"); - BOOST_TEST_THROWS(s.insert(s.begin() + 1, 2, '*'), std::length_error); - } - - // insert(const_iterator pos, InputIt first, InputIt last) - { - fixed_string<4> const cs{"abcd"}; - fixed_string<4> s{"ad"}; - BOOST_TEST(s.insert(s.begin() + 1, cs.begin() + 1, cs.begin() + 3) == s.begin() + 1); - BOOST_TEST(s == "abcd"); - } - - // insert(const_iterator pos, std::initializer_list ilist) - { - fixed_string<4> s{"ad"}; - BOOST_TEST(s.insert(s.begin() + 1, {'b', 'c'}) == s.begin() + 1); - BOOST_TEST(s == "abcd"); - } - - // insert(size_type index, T const& t) - { - struct T - { - operator string_view() const noexcept - { - return "b"; - } - }; - BOOST_TEST(fixed_string<3>{"ac"}.insert(1, T{}) == "abc"); - BOOST_TEST_THROWS(fixed_string<4>{"abc"}.insert(4, T{}), std::out_of_range); - BOOST_TEST_THROWS(fixed_string<3>{"abc"}.insert(1, T{}), std::length_error); - } - - // insert(size_type index, T const& t, size_type index_str, size_type count = npos) - { - struct T - { - operator string_view() const noexcept - { - return "abcd"; - } - }; - BOOST_TEST(fixed_string<6>{"ae"}.insert(1, T{}, 1) == "abcde"); - BOOST_TEST(fixed_string<6>{"abe"}.insert(2, T{}, 2) == "abcde"); - BOOST_TEST(fixed_string<4>{"ac"}.insert(1, T{}, 1, 1) == "abc"); - BOOST_TEST(fixed_string<4>{"ad"}.insert(1, T{}, 1, 2) == "abcd"); - BOOST_TEST_THROWS(fixed_string<4>{"abc"}.insert(4, T{}), std::out_of_range); - BOOST_TEST_THROWS(fixed_string<3>{"abc"}.insert(1, T{}), std::length_error); - } - - //--- - - { - // Using 7 as the size causes a miscompile in MSVC14.2 x64 Release - fixed_string<8> s1("12345"); - s1.insert(2, 2, '_'); - BOOST_TEST(s1 == "12__345"); - BOOST_TEST(*s1.end() == 0); - fixed_string<6> s2("12345"); - BOOST_TEST_THROWS( - (s2.insert(2, 2, '_')), - std::length_error); - fixed_string<6> s3("12345"); - BOOST_TEST_THROWS( - (s3.insert(6, 2, '_')), - std::out_of_range); - } - { - fixed_string<7> s1("12345"); - s1.insert(2, "__"); - BOOST_TEST(s1 == "12__345"); - BOOST_TEST(*s1.end() == 0); - fixed_string<6> s2("12345"); - BOOST_TEST_THROWS( - (s2.insert(2, "__")), - std::length_error); - fixed_string<6> s3("12345"); - BOOST_TEST_THROWS( - (s2.insert(6, "__")), - std::out_of_range); - } - { - fixed_string<7> s1("12345"); - s1.insert(2, "TUV", 2); - BOOST_TEST(s1 == "12TU345"); - BOOST_TEST(*s1.end() == 0); - fixed_string<6> s2("12345"); - BOOST_TEST_THROWS( - (s2.insert(2, "TUV", 2)), - std::length_error); - fixed_string<6> s3("12345"); - BOOST_TEST_THROWS( - (s3.insert(6, "TUV", 2)), - std::out_of_range); - } - { - fixed_string<7> s1("12345"); - s1.insert(2, fixed_string<3>("TU")); - BOOST_TEST(s1 == "12TU345"); - BOOST_TEST(*s1.end() == 0); - fixed_string<6> s2("12345"); - BOOST_TEST_THROWS( - (s2.insert(2, fixed_string<3>("TUV"))), - std::length_error); - fixed_string<6> s3("12345"); - BOOST_TEST_THROWS( - (s3.insert(6, fixed_string<3>("TUV"))), - std::out_of_range); - } - { - fixed_string<7> s1("12345"); - s1.insert(2, fixed_string<3>("TUV"), 1); - BOOST_TEST(s1 == "12UV345"); - BOOST_TEST(*s1.end() == 0); - s1 = "12345"; - s1.insert(2, fixed_string<3>("TUV"), 1, 1); - BOOST_TEST(s1 == "12U345"); - BOOST_TEST(*s1.end() == 0); - fixed_string<6> s2("12345"); - BOOST_TEST_THROWS( - (s2.insert(2, fixed_string<3>("TUV"), 1, 2)), - std::length_error); - fixed_string<6> s3("12345"); - BOOST_TEST_THROWS( - (s3.insert(6, fixed_string<3>("TUV"), 1, 2)), - std::out_of_range); - } - { - fixed_string<4> s1("123"); - s1.insert(s1.begin() + 1, '_'); - BOOST_TEST(s1 == "1_23"); - BOOST_TEST(*s1.end() == 0); - fixed_string<3> s2("123"); - BOOST_TEST_THROWS( - (s2.insert(s2.begin() + 1, '_')), - std::length_error); - } - { - fixed_string<4> s1("12"); - s1.insert(s1.begin() + 1, 2, '_'); - BOOST_TEST(s1 == "1__2"); - BOOST_TEST(*s1.end() == 0); - fixed_string<4> s2("123"); - BOOST_TEST_THROWS( - (s2.insert(s2.begin() + 1, 2, ' ')), - std::length_error); - } - { - fixed_string<3> s1("123"); - fixed_string<5> s2("UV"); - s2.insert(s2.begin() + 1, s1.begin(), s1.end()); - BOOST_TEST(s2 == "U123V"); - BOOST_TEST(*s2.end() == 0); - fixed_string<4> s3("UV"); - BOOST_TEST_THROWS( - (s3.insert(s3.begin() + 1, s1.begin(), s1.end())), - std::length_error); - } - { - fixed_string<5> s1("123"); - s1.insert(1, string_view("UV")); - BOOST_TEST(s1 == "1UV23"); - BOOST_TEST(*s1.end() == 0); - fixed_string<4> s2("123"); - BOOST_TEST_THROWS( - (s2.insert(1, string_view("UV"))), - std::length_error); - fixed_string<5> s3("123"); - BOOST_TEST_THROWS( - (s3.insert(5, string_view("UV"))), - std::out_of_range); - } - { - fixed_string<5> s1("123"); - s1.insert(1, std::string("UV")); - BOOST_TEST(s1 == "1UV23"); - BOOST_TEST(*s1.end() == 0); - BOOST_TEST_THROWS( - (s1.insert(1, std::string("UV"))), - std::length_error); - } - { - fixed_string<6> s1("123"); - s1.insert(1, std::string("UVX"), 1); - BOOST_TEST(s1 == "1VX23"); - BOOST_TEST(*s1.end() == 0); - s1.insert(4, std::string("PQR"), 1, 1); - BOOST_TEST(s1 == "1VX2Q3"); - BOOST_TEST(*s1.end() == 0); - BOOST_TEST_THROWS( - (s1.insert(4, std::string("PQR"), 1, 1)), - std::length_error); - } - // test insert with source inside self - - { - fixed_string<30> fs1 = "0123456789"; - BOOST_TEST(fs1.insert(0, fs1.data(), 4) == "01230123456789"); - } - { - fixed_string<30> fs1 = "0123456789"; - BOOST_TEST(fs1.insert(5, fs1.data(), 4) == "01234012356789"); - } - { - fixed_string<30> fs1 = "0123456789"; - BOOST_TEST(fs1.insert(5, fs1.data(), 10) == "01234012345678956789"); - } - { - fixed_string<30> fs1 = "0123456789"; - BOOST_TEST(fs1.insert(5, fs1.data() + 6, 3) == "0123467856789"); - } - + BOOST_TEST(s_long == "rem ipsu"); +} + +// done +static +void +testElements() +{ + using cfs3 = fixed_string<3> const; + + // at(size_type pos) + BOOST_TEST(fixed_string<3>{"abc"}.at(0) == 'a'); + BOOST_TEST(fixed_string<3>{"abc"}.at(2) == 'c'); + BOOST_TEST_THROWS(fixed_string<3>{""}.at(0), std::out_of_range); + BOOST_TEST_THROWS(fixed_string<3>{"abc"}.at(4), std::out_of_range); + + // at(size_type pos) const + BOOST_TEST(cfs3{"abc"}.at(0) == 'a'); + BOOST_TEST(cfs3{"abc"}.at(2) == 'c'); + BOOST_TEST_THROWS(cfs3{""}.at(0), std::out_of_range); + BOOST_TEST_THROWS(cfs3{"abc"}.at(4), std::out_of_range); + + // operator[](size_type pos) + BOOST_TEST(fixed_string<3>{"abc"}[0] == 'a'); + BOOST_TEST(fixed_string<3>{"abc"}[2] == 'c'); + BOOST_TEST(fixed_string<3>{"abc"}[3] == 0); + BOOST_TEST(fixed_string<3>{""}[0] == 0); + + // operator[](size_type pos) const + BOOST_TEST(cfs3{"abc"}[0] == 'a'); + BOOST_TEST(cfs3{"abc"}[2] == 'c'); + BOOST_TEST(cfs3{"abc"}[3] == 0); + BOOST_TEST(cfs3{""}[0] == 0); + + // front() + BOOST_TEST(fixed_string<3>{"a"}.front() == 'a'); + BOOST_TEST(fixed_string<3>{"abc"}.front() == 'a'); + + // front() const + BOOST_TEST(cfs3{"a"}.front() == 'a'); + BOOST_TEST(cfs3{"abc"}.front() == 'a'); + + // back() + BOOST_TEST(fixed_string<3>{"a"}.back() == 'a'); + BOOST_TEST(fixed_string<3>{"abc"}.back() == 'c'); + + // back() const + BOOST_TEST(cfs3{"a"}.back() == 'a'); + BOOST_TEST(cfs3{"abc"}.back() == 'c'); + + // data() noexcept + // data() const noexcept + // c_str() const noexcept + // operator string_view_type() const noexcept + + //--- + + { + fixed_string<5> s("12345"); + BOOST_TEST(s.at(1) == '2'); + BOOST_TEST(s.at(4) == '5'); + BOOST_TEST_THROWS( + s.at(5) = 0, + std::out_of_range); + } + { + fixed_string<5> const s("12345"); + BOOST_TEST(s.at(1) == '2'); + BOOST_TEST(s.at(4) == '5'); + BOOST_TEST_THROWS( + s.at(5), + std::out_of_range); + } + { + fixed_string<5> s("12345"); + BOOST_TEST(s[1] == '2'); + BOOST_TEST(s[4] == '5'); + s[1] = '_'; + BOOST_TEST(s == "1_345"); + } + { + fixed_string<5> const s("12345"); + BOOST_TEST(s[1] == '2'); + BOOST_TEST(s[4] == '5'); + BOOST_TEST(s[5] == 0); + } + { + fixed_string<3> s("123"); + BOOST_TEST(s.front() == '1'); + BOOST_TEST(s.back() == '3'); + s.front() = '_'; + BOOST_TEST(s == "_23"); + s.back() = '_'; + BOOST_TEST(s == "_2_"); + } + { + fixed_string<3> const s("123"); + BOOST_TEST(s.front() == '1'); + BOOST_TEST(s.back() == '3'); + } + { + fixed_string<3> s("123"); + BOOST_TEST(std::memcmp( + s.data(), "123", 3) == 0); + } + { + fixed_string<3> const s("123"); + BOOST_TEST(std::memcmp( + s.data(), "123", 3) == 0); + } + { + fixed_string<3> s("123"); + BOOST_TEST(std::memcmp( + s.c_str(), "123\0", 4) == 0); + } + { + fixed_string<3> s("123"); + string_view sv = s; + BOOST_TEST(fixed_string<5>(sv) == "123"); + } +} + +// done +static +void +testIterators() +{ + { + fixed_string<3> s; + BOOST_TEST(std::distance(s.begin(), s.end()) == 0); + BOOST_TEST(std::distance(s.rbegin(), s.rend()) == 0); + s = "123"; + BOOST_TEST(std::distance(s.begin(), s.end()) == 3); + BOOST_TEST(std::distance(s.rbegin(), s.rend()) == 3); + } + { + fixed_string<3> const s("123"); + BOOST_TEST(std::distance(s.begin(), s.end()) == 3); + BOOST_TEST(std::distance(s.cbegin(), s.cend()) == 3); + BOOST_TEST(std::distance(s.rbegin(), s.rend()) == 3); + BOOST_TEST(std::distance(s.crbegin(), s.crend()) == 3); + } +} + +// done +static +void +testCapacity() +{ + // empty() + BOOST_TEST(fixed_string<0>{}.empty()); + BOOST_TEST(fixed_string<1>{}.empty()); + BOOST_TEST(! fixed_string<1>{"a"}.empty()); + BOOST_TEST(! fixed_string<3>{"abc"}.empty()); + + // size() + BOOST_TEST(fixed_string<0>{}.size() == 0); + BOOST_TEST(fixed_string<1>{}.size() == 0); + BOOST_TEST(fixed_string<1>{"a"}.size() == 1); + BOOST_TEST(fixed_string<3>{"abc"}.size() == 3); + BOOST_TEST(fixed_string<5>{"abc"}.size() == 3); + + // length() + BOOST_TEST(fixed_string<0>{}.length() == 0); + BOOST_TEST(fixed_string<1>{}.length() == 0); + BOOST_TEST(fixed_string<1>{"a"}.length() == 1); + BOOST_TEST(fixed_string<3>{"abc"}.length() == 3); + BOOST_TEST(fixed_string<5>{"abc"}.length() == 3); + + // max_size() + BOOST_TEST(fixed_string<0>{}.max_size() == 0); + BOOST_TEST(fixed_string<1>{}.max_size() == 1); + BOOST_TEST(fixed_string<1>{"a"}.max_size() == 1); + BOOST_TEST(fixed_string<3>{"abc"}.max_size() == 3); + BOOST_TEST(fixed_string<5>{"abc"}.max_size() == 5); + + // reserve(std::size_t n) + fixed_string<3>{}.reserve(0); + fixed_string<3>{}.reserve(1); + fixed_string<3>{}.reserve(3); + BOOST_TEST_THROWS(fixed_string<0>{}.reserve(1), std::length_error); + BOOST_TEST_THROWS(fixed_string<3>{}.reserve(4), std::length_error); + + // capacity() + BOOST_TEST(fixed_string<0>{}.capacity() == 0); + BOOST_TEST(fixed_string<1>{}.capacity() == 1); + BOOST_TEST(fixed_string<1>{"a"}.capacity() == 1); + BOOST_TEST(fixed_string<3>{"abc"}.capacity() == 3); + BOOST_TEST(fixed_string<5>{"abc"}.capacity() == 5); + + //--- + + fixed_string<3> s; + BOOST_TEST(s.empty()); + BOOST_TEST(s.size() == 0); + BOOST_TEST(s.length() == 0); + BOOST_TEST(s.max_size() == 3); + BOOST_TEST(s.capacity() == 3); + s = "123"; + BOOST_TEST(! s.empty()); + BOOST_TEST(s.size() == 3); + BOOST_TEST(s.length() == 3); + s.reserve(0); + s.reserve(3); + BOOST_TEST_THROWS( + s.reserve(4), + std::length_error); + s.shrink_to_fit(); + BOOST_TEST(! s.empty()); + BOOST_TEST(s.size() == 3); + BOOST_TEST(s.length() == 3); + BOOST_TEST(*s.end() == 0); +} + +// done +static +void +testClear() +{ + // clear() + fixed_string<3> s("123"); + s.clear(); + BOOST_TEST(s.empty()); + BOOST_TEST(*s.end() == 0); +} + +// done +static +void +testInsert() +{ + using sv = string_view; + using S = fixed_string<100>; + + // insert(size_type index, size_type count, CharT ch) + // The overload resolution is ambiguous + // here because 0 is also a pointer type + //BOOST_TEST(fixed_string<3>{"bc"}.insert(0, 1, 'a') == "abc"); + BOOST_TEST(fixed_string<3>{"bc"}.insert(std::size_t(0), 1, 'a') == "abc"); + BOOST_TEST(fixed_string<3>{"ac"}.insert(1, 1, 'b') == "abc"); + BOOST_TEST(fixed_string<3>{"ab"}.insert(2, 1, 'c') == "abc"); + BOOST_TEST_THROWS(fixed_string<4>{"abc"}.insert(4, 1, '*'), std::out_of_range); + BOOST_TEST_THROWS(fixed_string<3>{"abc"}.insert(1, 1, '*'), std::length_error); + + // insert(size_type index, CharT const* s) + BOOST_TEST(fixed_string<3>{"bc"}.insert(0, "a") == "abc"); + BOOST_TEST_THROWS(fixed_string<4>{"abc"}.insert(4, "*"), std::out_of_range); + BOOST_TEST_THROWS(fixed_string<3>{"abc"}.insert(1, "*"), std::length_error); + + // insert(size_type index, CharT const* s, size_type count) + BOOST_TEST(fixed_string<4>{"ad"}.insert(1, "bcd", 2) == "abcd"); + BOOST_TEST_THROWS(fixed_string<4>{"abc"}.insert(4, "*"), std::out_of_range); + BOOST_TEST_THROWS(fixed_string<3>{"abc"}.insert(1, "*"), std::length_error); + + // insert(size_type index, string_view_type sv) + BOOST_TEST(fixed_string<3>{"ac"}.insert(1, sv{"b"}) == "abc"); + BOOST_TEST_THROWS(fixed_string<4>{"abc"}.insert(4, sv{"*"}), std::out_of_range); + BOOST_TEST_THROWS(fixed_string<3>{"abc"}.insert(1, sv{"*"}), std::length_error); + + // insert(size_type index, string_view_type sv, size_type index_str, size_type count = npos) + BOOST_TEST(fixed_string<4>{"ad"}.insert(1, sv{"abcd"}, 1, 2) == "abcd"); + BOOST_TEST(fixed_string<4>{"ad"}.insert(1, sv{"abc"}, 1) == "abcd"); + BOOST_TEST_THROWS((fixed_string<4>{"ad"}.insert(1, sv{"bc"}, 3, 0)), std::out_of_range); + BOOST_TEST_THROWS((fixed_string<3>{"ad"}.insert(1, sv{"bc"}, 0, 2)), std::length_error); + + // insert(const_iterator pos, CharT ch) + { + fixed_string<3> s{"ac"}; + BOOST_TEST(s.insert(s.begin() + 1, 'b') == s.begin() + 1); + BOOST_TEST(s == "abc"); + BOOST_TEST_THROWS(s.insert(s.begin() + 1, '*'), std::length_error); + } + + // insert(const_iterator pos, size_type count, CharT ch) + { + fixed_string<4> s{"ac"}; + BOOST_TEST(s.insert(s.begin() + 1, 2, 'b') == s.begin() + 1); + BOOST_TEST(s == "abbc"); + BOOST_TEST_THROWS(s.insert(s.begin() + 1, 2, '*'), std::length_error); + } + + // insert(const_iterator pos, InputIt first, InputIt last) + { + fixed_string<4> const cs{"abcd"}; + fixed_string<4> s{"ad"}; + BOOST_TEST(s.insert(s.begin() + 1, cs.begin() + 1, cs.begin() + 3) == s.begin() + 1); + BOOST_TEST(s == "abcd"); + } + + // insert(const_iterator pos, std::initializer_list ilist) + { + fixed_string<4> s{"ad"}; + BOOST_TEST(s.insert(s.begin() + 1, {'b', 'c'}) == s.begin() + 1); + BOOST_TEST(s == "abcd"); + } + + // insert(size_type index, T const& t) + { + struct T + { + operator string_view() const noexcept + { + return "b"; + } + }; + BOOST_TEST(fixed_string<3>{"ac"}.insert(1, T{}) == "abc"); + BOOST_TEST_THROWS(fixed_string<4>{"abc"}.insert(4, T{}), std::out_of_range); + BOOST_TEST_THROWS(fixed_string<3>{"abc"}.insert(1, T{}), std::length_error); + } + + // insert(size_type index, T const& t, size_type index_str, size_type count = npos) + { + struct T + { + operator string_view() const noexcept + { + return "abcd"; + } + }; + BOOST_TEST(fixed_string<6>{"ae"}.insert(1, T{}, 1) == "abcde"); + BOOST_TEST(fixed_string<6>{"abe"}.insert(2, T{}, 2) == "abcde"); + BOOST_TEST(fixed_string<4>{"ac"}.insert(1, T{}, 1, 1) == "abc"); + BOOST_TEST(fixed_string<4>{"ad"}.insert(1, T{}, 1, 2) == "abcd"); + BOOST_TEST_THROWS(fixed_string<4>{"abc"}.insert(4, T{}), std::out_of_range); + BOOST_TEST_THROWS(fixed_string<3>{"abc"}.insert(1, T{}), std::length_error); + } + + //--- + + { + // Using 7 as the size causes a miscompile in MSVC14.2 x64 Release + fixed_string<8> s1("12345"); + s1.insert(2, 2, '_'); + BOOST_TEST(s1 == "12__345"); + BOOST_TEST(*s1.end() == 0); + fixed_string<6> s2("12345"); + BOOST_TEST_THROWS( + (s2.insert(2, 2, '_')), + std::length_error); + fixed_string<6> s3("12345"); + BOOST_TEST_THROWS( + (s3.insert(6, 2, '_')), + std::out_of_range); + } + { + fixed_string<7> s1("12345"); + s1.insert(2, "__"); + BOOST_TEST(s1 == "12__345"); + BOOST_TEST(*s1.end() == 0); + fixed_string<6> s2("12345"); + BOOST_TEST_THROWS( + (s2.insert(2, "__")), + std::length_error); + fixed_string<6> s3("12345"); + BOOST_TEST_THROWS( + (s2.insert(6, "__")), + std::out_of_range); + } + { + fixed_string<7> s1("12345"); + s1.insert(2, "TUV", 2); + BOOST_TEST(s1 == "12TU345"); + BOOST_TEST(*s1.end() == 0); + fixed_string<6> s2("12345"); + BOOST_TEST_THROWS( + (s2.insert(2, "TUV", 2)), + std::length_error); + fixed_string<6> s3("12345"); + BOOST_TEST_THROWS( + (s3.insert(6, "TUV", 2)), + std::out_of_range); + } + { + fixed_string<7> s1("12345"); + s1.insert(2, fixed_string<3>("TU")); + BOOST_TEST(s1 == "12TU345"); + BOOST_TEST(*s1.end() == 0); + fixed_string<6> s2("12345"); + BOOST_TEST_THROWS( + (s2.insert(2, fixed_string<3>("TUV"))), + std::length_error); + fixed_string<6> s3("12345"); + BOOST_TEST_THROWS( + (s3.insert(6, fixed_string<3>("TUV"))), + std::out_of_range); + } + { + fixed_string<7> s1("12345"); + s1.insert(2, fixed_string<3>("TUV"), 1); + BOOST_TEST(s1 == "12UV345"); + BOOST_TEST(*s1.end() == 0); + s1 = "12345"; + s1.insert(2, fixed_string<3>("TUV"), 1, 1); + BOOST_TEST(s1 == "12U345"); + BOOST_TEST(*s1.end() == 0); + fixed_string<6> s2("12345"); + BOOST_TEST_THROWS( + (s2.insert(2, fixed_string<3>("TUV"), 1, 2)), + std::length_error); + fixed_string<6> s3("12345"); + BOOST_TEST_THROWS( + (s3.insert(6, fixed_string<3>("TUV"), 1, 2)), + std::out_of_range); + } + { + fixed_string<4> s1("123"); + s1.insert(s1.begin() + 1, '_'); + BOOST_TEST(s1 == "1_23"); + BOOST_TEST(*s1.end() == 0); + fixed_string<3> s2("123"); + BOOST_TEST_THROWS( + (s2.insert(s2.begin() + 1, '_')), + std::length_error); + } + { + fixed_string<4> s1("12"); + s1.insert(s1.begin() + 1, 2, '_'); + BOOST_TEST(s1 == "1__2"); + BOOST_TEST(*s1.end() == 0); + fixed_string<4> s2("123"); + BOOST_TEST_THROWS( + (s2.insert(s2.begin() + 1, 2, ' ')), + std::length_error); + } + { + fixed_string<3> s1("123"); + fixed_string<5> s2("UV"); + s2.insert(s2.begin() + 1, s1.begin(), s1.end()); + BOOST_TEST(s2 == "U123V"); + BOOST_TEST(*s2.end() == 0); + fixed_string<4> s3("UV"); + BOOST_TEST_THROWS( + (s3.insert(s3.begin() + 1, s1.begin(), s1.end())), + std::length_error); + } + { + fixed_string<5> s1("123"); + s1.insert(1, string_view("UV")); + BOOST_TEST(s1 == "1UV23"); + BOOST_TEST(*s1.end() == 0); + fixed_string<4> s2("123"); + BOOST_TEST_THROWS( + (s2.insert(1, string_view("UV"))), + std::length_error); + fixed_string<5> s3("123"); + BOOST_TEST_THROWS( + (s3.insert(5, string_view("UV"))), + std::out_of_range); + } + { + fixed_string<5> s1("123"); + s1.insert(1, std::string("UV")); + BOOST_TEST(s1 == "1UV23"); + BOOST_TEST(*s1.end() == 0); + BOOST_TEST_THROWS( + (s1.insert(1, std::string("UV"))), + std::length_error); + } + { + fixed_string<6> s1("123"); + s1.insert(1, std::string("UVX"), 1); + BOOST_TEST(s1 == "1VX23"); + BOOST_TEST(*s1.end() == 0); + s1.insert(4, std::string("PQR"), 1, 1); + BOOST_TEST(s1 == "1VX2Q3"); + BOOST_TEST(*s1.end() == 0); + BOOST_TEST_THROWS( + (s1.insert(4, std::string("PQR"), 1, 1)), + std::length_error); + } + // test insert with source inside self + + { + fixed_string<30> fs1 = "0123456789"; + BOOST_TEST(fs1.insert(0, fs1.data(), 4) == "01230123456789"); + } + { + fixed_string<30> fs1 = "0123456789"; + BOOST_TEST(fs1.insert(5, fs1.data(), 4) == "01234012356789"); + } + { + fixed_string<30> fs1 = "0123456789"; + BOOST_TEST(fs1.insert(5, fs1.data(), 10) == "01234012345678956789"); + } + { + fixed_string<30> fs1 = "0123456789"; + BOOST_TEST(fs1.insert(5, fs1.data() + 6, 3) == "0123467856789"); + } + S s_short = "123/"; S s_long = "Lorem ipsum dolor sit amet, consectetur/"; BOOST_TEST(s_short.insert(0, s_short.data(), s_short.size()) == "123/123/"); BOOST_TEST(s_short.insert(0, s_short.data(), s_short.size()) == "123/123/123/123/"); BOOST_TEST(s_short.insert(0, s_short.data(), s_short.size()) == "123/123/123/123/123/123/123/123/"); - BOOST_TEST(s_long.insert(0, s_long.data(), s_long.size()) == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/"); + BOOST_TEST(s_long.insert(0, s_long.data(), s_long.size()) == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/"); BOOST_TEST(testI(S("abcde"), 6, "12345", 0, S("can't happen"))); BOOST_TEST(testI(S("abcde"), 6, "12345", 1, S("can't happen"))); @@ -1505,7 +1506,7 @@ testInsert() BOOST_TEST(testI(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", 1, S("abcdefghijklmnopqrst1"))); BOOST_TEST(testI(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", 10, S("abcdefghijklmnopqrst1234567890"))); BOOST_TEST(testI(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", 19, S("abcdefghijklmnopqrst1234567890123456789"))); - BOOST_TEST(testI(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", 20, S("abcdefghijklmnopqrst12345678901234567890"))); + BOOST_TEST(testI(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", 20, S("abcdefghijklmnopqrst12345678901234567890"))); BOOST_TEST(testI(S("abcde"), 6, "", 0, S("can't happen"))); BOOST_TEST(testI(S("abcde"), 6, "12345", 0, S("can't happen"))); BOOST_TEST(testI(S("abcde"), 6, "12345", 1, S("can't happen"))); @@ -1553,73 +1554,73 @@ testInsert() BOOST_TEST(testI(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 1, S("can't happen"))); BOOST_TEST(testI(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 10, S("can't happen"))); BOOST_TEST(testI(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 19, S("can't happen"))); - BOOST_TEST(testI(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 20, S("can't happen"))); -} - -// done -static -void -testErase() -{ - // erase(size_type index = 0, size_type count = npos) - BOOST_TEST(fixed_string<3>{"abc"}.erase() == ""); - BOOST_TEST(fixed_string<3>{"abc"}.erase(1) == "a"); - BOOST_TEST(fixed_string<3>{"abc"}.erase(2) == "ab"); - BOOST_TEST(fixed_string<3>{"abc"}.erase(1, 1) == "ac"); - BOOST_TEST(fixed_string<3>{"abc"}.erase(0, 2) == "c"); - BOOST_TEST(fixed_string<3>{"abc"}.erase(3, 0) == "abc"); - BOOST_TEST(fixed_string<3>{"abc"}.erase(3, 4) == "abc"); - BOOST_TEST_THROWS(fixed_string<3>{"abc"}.erase(4, 0), std::out_of_range); - - // erase(const_iterator pos) - { - fixed_string<3> s{"abc"}; - BOOST_TEST(s.erase(s.begin() + 1) == s.begin() + 1); - BOOST_TEST(s == "ac"); - } - { - fixed_string<3> s{"abc"}; - BOOST_TEST(s.erase(s.begin() + 3) == s.end()); - BOOST_TEST(s == "abc"); - } - - // erase(const_iterator first, const_iterator last) - { - fixed_string<4> s{"abcd"}; - BOOST_TEST(s.erase(s.begin() + 1, s.begin() + 3) == s.begin() + 1); - BOOST_TEST(s == "ad"); - } - - //--- - - { - fixed_string<9> s1("123456789"); - BOOST_TEST(s1.erase(1, 1) == "13456789"); - BOOST_TEST(s1 == "13456789"); - BOOST_TEST(*s1.end() == 0); - BOOST_TEST(s1.erase(5) == "13456"); - BOOST_TEST(s1 == "13456"); - BOOST_TEST(*s1.end() == 0); - BOOST_TEST_THROWS( - s1.erase(7), - std::out_of_range); - } - { - fixed_string<9> s1("123456789"); - BOOST_TEST(*s1.erase(s1.begin() + 5) == '7'); - BOOST_TEST(s1 == "12345789"); - BOOST_TEST(*s1.end() == 0); - } - { - fixed_string<9> s1("123456789"); - BOOST_TEST(*s1.erase( - s1.begin() + 5, s1.begin() + 7) == '8'); - BOOST_TEST(s1 == "1234589"); - BOOST_TEST(*s1.end() == 0); - } - - using S = fixed_string<400>; - + BOOST_TEST(testI(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 20, S("can't happen"))); +} + +// done +static +void +testErase() +{ + // erase(size_type index = 0, size_type count = npos) + BOOST_TEST(fixed_string<3>{"abc"}.erase() == ""); + BOOST_TEST(fixed_string<3>{"abc"}.erase(1) == "a"); + BOOST_TEST(fixed_string<3>{"abc"}.erase(2) == "ab"); + BOOST_TEST(fixed_string<3>{"abc"}.erase(1, 1) == "ac"); + BOOST_TEST(fixed_string<3>{"abc"}.erase(0, 2) == "c"); + BOOST_TEST(fixed_string<3>{"abc"}.erase(3, 0) == "abc"); + BOOST_TEST(fixed_string<3>{"abc"}.erase(3, 4) == "abc"); + BOOST_TEST_THROWS(fixed_string<3>{"abc"}.erase(4, 0), std::out_of_range); + + // erase(const_iterator pos) + { + fixed_string<3> s{"abc"}; + BOOST_TEST(s.erase(s.begin() + 1) == s.begin() + 1); + BOOST_TEST(s == "ac"); + } + { + fixed_string<3> s{"abc"}; + BOOST_TEST(s.erase(s.begin() + 3) == s.end()); + BOOST_TEST(s == "abc"); + } + + // erase(const_iterator first, const_iterator last) + { + fixed_string<4> s{"abcd"}; + BOOST_TEST(s.erase(s.begin() + 1, s.begin() + 3) == s.begin() + 1); + BOOST_TEST(s == "ad"); + } + + //--- + + { + fixed_string<9> s1("123456789"); + BOOST_TEST(s1.erase(1, 1) == "13456789"); + BOOST_TEST(s1 == "13456789"); + BOOST_TEST(*s1.end() == 0); + BOOST_TEST(s1.erase(5) == "13456"); + BOOST_TEST(s1 == "13456"); + BOOST_TEST(*s1.end() == 0); + BOOST_TEST_THROWS( + s1.erase(7), + std::out_of_range); + } + { + fixed_string<9> s1("123456789"); + BOOST_TEST(*s1.erase(s1.begin() + 5) == '7'); + BOOST_TEST(s1 == "12345789"); + BOOST_TEST(*s1.end() == 0); + } + { + fixed_string<9> s1("123456789"); + BOOST_TEST(*s1.erase( + s1.begin() + 5, s1.begin() + 7) == '8'); + BOOST_TEST(s1 == "1234589"); + BOOST_TEST(*s1.end() == 0); + } + + using S = fixed_string<400>; + BOOST_TEST(testE(S(""), 0, 0, S(""))); BOOST_TEST(testE(S(""), 0, 1, S(""))); BOOST_TEST(testE(S(""), 1, 0, S("can't happen"))); @@ -1768,259 +1769,259 @@ testErase() BOOST_TEST(testE(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrs"))); BOOST_TEST(testE(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"))); BOOST_TEST(testE(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"))); - BOOST_TEST(testE(S("abcdefghijklmnopqrst"), 21, 0, S("can't happen"))); -} - -// done -static -void -testPushBack() -{ - // push_back(CharT ch); - { - fixed_string<2> s; - s.push_back('a'); - BOOST_TEST(s == "a"); - s.push_back('b'); - BOOST_TEST(s == "ab"); - BOOST_TEST_THROWS(s.push_back('c'), std::length_error); - } - - //--- - - { - fixed_string<3> s1("12"); - s1.push_back('3'); - BOOST_TEST(s1 == "123"); - BOOST_TEST_THROWS( - s1.push_back('4'), - std::length_error); - fixed_string<0> s2; - BOOST_TEST_THROWS( - s2.push_back('_'), - std::length_error); - } -} - -// done -static -void -testPopBack() -{ - // pop_back() - { - fixed_string<3> s{"abc"}; - BOOST_TEST(*s.end() == 0); - s.pop_back(); - BOOST_TEST(s == "ab"); - BOOST_TEST(*s.end() == 0); - s.pop_back(); - BOOST_TEST(s == "a"); - BOOST_TEST(*s.end() == 0); - s.pop_back(); - BOOST_TEST(s.empty()); - BOOST_TEST(*s.end() == 0); - } - - //--- - - { - fixed_string<3> s1("123"); - s1.pop_back(); - BOOST_TEST(s1 == "12"); - BOOST_TEST(*s1.end() == 0); - s1.pop_back(); - BOOST_TEST(s1 == "1"); - BOOST_TEST(*s1.end() == 0); - s1.pop_back(); - BOOST_TEST(s1.empty()); - BOOST_TEST(*s1.end() == 0); - } -} - -// done -static -void -testAppend() -{ - using S = fixed_string<400>; - using sv = string_view; - - // append(size_type count, CharT ch) - BOOST_TEST(fixed_string<1>{}.append(1, 'a') == "a"); - BOOST_TEST(fixed_string<2>{}.append(2, 'a') == "aa"); - BOOST_TEST(fixed_string<2>{"a"}.append(1, 'b') == "ab"); - BOOST_TEST_THROWS(fixed_string<2>{"ab"}.append(1, 'c'), std::length_error); - - // append(string_view_type sv) - BOOST_TEST(fixed_string<3>{"a"}.append(sv{"bc"}) == "abc"); - BOOST_TEST(fixed_string<3>{"ab"}.append(sv{"c"}) == "abc"); - BOOST_TEST_THROWS(fixed_string<3>{"abc"}.append(sv{"*"}), std::length_error); - - // append(string_view_type sv, size_type pos, size_type count = npos) - BOOST_TEST(fixed_string<3>{"a"}.append(sv{"abc"}, 1) == "abc"); - BOOST_TEST(fixed_string<3>{"a"}.append(sv{"abc"}, 1, 2) == "abc"); - BOOST_TEST_THROWS(fixed_string<3>{"abc"}.append(sv{"a"}, 2, 1), std::out_of_range); - BOOST_TEST_THROWS(fixed_string<3>{"abc"}.append(sv{"abcd"}, 1, 2), std::length_error); - - // append(CharT const* s, size_type count) - BOOST_TEST(fixed_string<3>{"a"}.append("bc", 0) == "a"); - BOOST_TEST(fixed_string<3>{"a"}.append("bc", 2) == "abc"); - BOOST_TEST_THROWS(fixed_string<3>{"abc"}.append("bc", 2), std::length_error); - - // append(CharT const* s) - BOOST_TEST(fixed_string<3>{"a"}.append("bc") == "abc"); - BOOST_TEST_THROWS(fixed_string<3>{"abc"}.append("bc"), std::length_error); - - // append(InputIt first, InputIt last) - { - fixed_string<4> const cs{"abcd"}; - fixed_string<4> s{"ad"}; - BOOST_TEST(fixed_string<4>{"ab"}.append( - cs.begin() + 2, cs.begin() + 4) == "abcd"); - BOOST_TEST_THROWS(fixed_string<2>{"ab"}.append( - cs.begin() + 2, cs.begin() + 4), std::length_error); - } - - // append(std::initializer_list ilist) - BOOST_TEST(fixed_string<4>{"ab"}.append({'c', 'd'}) == "abcd"); - BOOST_TEST_THROWS(fixed_string<3>{"ab"}.append({'c', 'd'}), std::length_error); - - // append(T const& t) - { - struct T - { - operator string_view() const noexcept - { - return "c"; - } - }; - BOOST_TEST(fixed_string<3>{"ab"}.append(T{}) == "abc"); - BOOST_TEST_THROWS(fixed_string<3>{"abc"}.append(T{}), std::length_error); - } - - // append(T const& t, size_type pos, size_type count = npos) - { - struct T - { - operator string_view() const noexcept - { - return "abcd"; - } - }; - BOOST_TEST(fixed_string<4>{"ab"}.append(T{}, 2) == "abcd"); - BOOST_TEST(fixed_string<3>{"a"}.append(T{}, 1, 2) == "abc"); - BOOST_TEST_THROWS(fixed_string<4>{"abc"}.append(T{}, 5), std::out_of_range); - BOOST_TEST_THROWS(fixed_string<3>{"abc"}.append(T{}, 3, 1), std::length_error); - } - - //--- - - { - fixed_string<3> s1("1"); - s1.append(2, '_'); - BOOST_TEST(s1 == "1__"); - BOOST_TEST(*s1.end() == 0); - fixed_string<2> s2("1"); - BOOST_TEST_THROWS( - (s2.append(2, '_')), - std::length_error); - } - { - fixed_string<2> s1("__"); - fixed_string<3> s2("1"); - s2.append(s1); - BOOST_TEST(s2 == "1__"); - BOOST_TEST(*s2.end() == 0); - fixed_string<2> s3("1"); - BOOST_TEST_THROWS( - s3.append(s1), - std::length_error); - } - { - fixed_string<3> s1("XYZ"); - fixed_string<4> s2("12"); - s2.append(s1, 1); - BOOST_TEST(s2 == "12YZ"); - BOOST_TEST(*s2.end() == 0); - fixed_string<3> s3("12"); - s3.append(s1, 1, 1); - BOOST_TEST(s3 == "12Y"); - BOOST_TEST(*s3.end() == 0); - fixed_string<3> s4("12"); - BOOST_TEST_THROWS( - (s4.append(s1, 4)), - std::out_of_range); - fixed_string<3> s5("12"); - BOOST_TEST_THROWS( - (s5.append(s1, 1)), - std::length_error); - } - { - fixed_string<4> s1("12"); - s1.append("XYZ", 2); - BOOST_TEST(s1 == "12XY"); - BOOST_TEST(*s1.end() == 0); - fixed_string<3> s3("12"); - BOOST_TEST_THROWS( - (s3.append("XYZ", 2)), - std::length_error); - } - { - fixed_string<5> s1("12"); - s1.append("XYZ"); - BOOST_TEST(s1 == "12XYZ"); - BOOST_TEST(*s1.end() == 0); - fixed_string<4> s2("12"); - BOOST_TEST_THROWS( - s2.append("XYZ"), - std::length_error); - } - { - fixed_string<3> s1("XYZ"); - fixed_string<5> s2("12"); - s2.append(s1.begin(), s1.end()); - BOOST_TEST(s2 == "12XYZ"); - BOOST_TEST(*s2.end() == 0); - fixed_string<4> s3("12"); - BOOST_TEST_THROWS( - s3.append(s1.begin(), s1.end()), - std::length_error); - } - { - fixed_string<5> s1("123"); - s1.append({'X', 'Y'}); - BOOST_TEST(s1 == "123XY"); - BOOST_TEST(*s1.end() == 0); - fixed_string<4> s2("123"); - BOOST_TEST_THROWS( - s2.append({'X', 'Y'}), - std::length_error); - } - { - string_view s1("XYZ"); - fixed_string<5> s2("12"); - s2.append(s1); - BOOST_TEST(s2 == "12XYZ"); - BOOST_TEST(*s2.end() == 0); - fixed_string<4> s3("12"); - BOOST_TEST_THROWS( - s3.append(s1), - std::length_error); - } - { - fixed_string<6> s1("123"); - s1.append(std::string("UVX"), 1); - BOOST_TEST(s1 == "123VX"); - BOOST_TEST(*s1.end() == 0); - s1.append(std::string("PQR"), 1, 1); - BOOST_TEST(s1 == "123VXQ"); - BOOST_TEST(*s1.end() == 0); - fixed_string<3> s2("123"); - BOOST_TEST_THROWS( - (s2.append(std::string("PQR"), 1, 1)), - std::length_error); - } + BOOST_TEST(testE(S("abcdefghijklmnopqrst"), 21, 0, S("can't happen"))); +} + +// done +static +void +testPushBack() +{ + // push_back(CharT ch); + { + fixed_string<2> s; + s.push_back('a'); + BOOST_TEST(s == "a"); + s.push_back('b'); + BOOST_TEST(s == "ab"); + BOOST_TEST_THROWS(s.push_back('c'), std::length_error); + } + + //--- + + { + fixed_string<3> s1("12"); + s1.push_back('3'); + BOOST_TEST(s1 == "123"); + BOOST_TEST_THROWS( + s1.push_back('4'), + std::length_error); + fixed_string<0> s2; + BOOST_TEST_THROWS( + s2.push_back('_'), + std::length_error); + } +} + +// done +static +void +testPopBack() +{ + // pop_back() + { + fixed_string<3> s{"abc"}; + BOOST_TEST(*s.end() == 0); + s.pop_back(); + BOOST_TEST(s == "ab"); + BOOST_TEST(*s.end() == 0); + s.pop_back(); + BOOST_TEST(s == "a"); + BOOST_TEST(*s.end() == 0); + s.pop_back(); + BOOST_TEST(s.empty()); + BOOST_TEST(*s.end() == 0); + } + + //--- + + { + fixed_string<3> s1("123"); + s1.pop_back(); + BOOST_TEST(s1 == "12"); + BOOST_TEST(*s1.end() == 0); + s1.pop_back(); + BOOST_TEST(s1 == "1"); + BOOST_TEST(*s1.end() == 0); + s1.pop_back(); + BOOST_TEST(s1.empty()); + BOOST_TEST(*s1.end() == 0); + } +} + +// done +static +void +testAppend() +{ + using S = fixed_string<400>; + using sv = string_view; + + // append(size_type count, CharT ch) + BOOST_TEST(fixed_string<1>{}.append(1, 'a') == "a"); + BOOST_TEST(fixed_string<2>{}.append(2, 'a') == "aa"); + BOOST_TEST(fixed_string<2>{"a"}.append(1, 'b') == "ab"); + BOOST_TEST_THROWS(fixed_string<2>{"ab"}.append(1, 'c'), std::length_error); + + // append(string_view_type sv) + BOOST_TEST(fixed_string<3>{"a"}.append(sv{"bc"}) == "abc"); + BOOST_TEST(fixed_string<3>{"ab"}.append(sv{"c"}) == "abc"); + BOOST_TEST_THROWS(fixed_string<3>{"abc"}.append(sv{"*"}), std::length_error); + + // append(string_view_type sv, size_type pos, size_type count = npos) + BOOST_TEST(fixed_string<3>{"a"}.append(sv{"abc"}, 1) == "abc"); + BOOST_TEST(fixed_string<3>{"a"}.append(sv{"abc"}, 1, 2) == "abc"); + BOOST_TEST_THROWS(fixed_string<3>{"abc"}.append(sv{"a"}, 2, 1), std::out_of_range); + BOOST_TEST_THROWS(fixed_string<3>{"abc"}.append(sv{"abcd"}, 1, 2), std::length_error); + + // append(CharT const* s, size_type count) + BOOST_TEST(fixed_string<3>{"a"}.append("bc", 0) == "a"); + BOOST_TEST(fixed_string<3>{"a"}.append("bc", 2) == "abc"); + BOOST_TEST_THROWS(fixed_string<3>{"abc"}.append("bc", 2), std::length_error); + + // append(CharT const* s) + BOOST_TEST(fixed_string<3>{"a"}.append("bc") == "abc"); + BOOST_TEST_THROWS(fixed_string<3>{"abc"}.append("bc"), std::length_error); + + // append(InputIt first, InputIt last) + { + fixed_string<4> const cs{"abcd"}; + fixed_string<4> s{"ad"}; + BOOST_TEST(fixed_string<4>{"ab"}.append( + cs.begin() + 2, cs.begin() + 4) == "abcd"); + BOOST_TEST_THROWS(fixed_string<2>{"ab"}.append( + cs.begin() + 2, cs.begin() + 4), std::length_error); + } + + // append(std::initializer_list ilist) + BOOST_TEST(fixed_string<4>{"ab"}.append({'c', 'd'}) == "abcd"); + BOOST_TEST_THROWS(fixed_string<3>{"ab"}.append({'c', 'd'}), std::length_error); + + // append(T const& t) + { + struct T + { + operator string_view() const noexcept + { + return "c"; + } + }; + BOOST_TEST(fixed_string<3>{"ab"}.append(T{}) == "abc"); + BOOST_TEST_THROWS(fixed_string<3>{"abc"}.append(T{}), std::length_error); + } + + // append(T const& t, size_type pos, size_type count = npos) + { + struct T + { + operator string_view() const noexcept + { + return "abcd"; + } + }; + BOOST_TEST(fixed_string<4>{"ab"}.append(T{}, 2) == "abcd"); + BOOST_TEST(fixed_string<3>{"a"}.append(T{}, 1, 2) == "abc"); + BOOST_TEST_THROWS(fixed_string<4>{"abc"}.append(T{}, 5), std::out_of_range); + BOOST_TEST_THROWS(fixed_string<3>{"abc"}.append(T{}, 3, 1), std::length_error); + } + + //--- + + { + fixed_string<3> s1("1"); + s1.append(2, '_'); + BOOST_TEST(s1 == "1__"); + BOOST_TEST(*s1.end() == 0); + fixed_string<2> s2("1"); + BOOST_TEST_THROWS( + (s2.append(2, '_')), + std::length_error); + } + { + fixed_string<2> s1("__"); + fixed_string<3> s2("1"); + s2.append(s1); + BOOST_TEST(s2 == "1__"); + BOOST_TEST(*s2.end() == 0); + fixed_string<2> s3("1"); + BOOST_TEST_THROWS( + s3.append(s1), + std::length_error); + } + { + fixed_string<3> s1("XYZ"); + fixed_string<4> s2("12"); + s2.append(s1, 1); + BOOST_TEST(s2 == "12YZ"); + BOOST_TEST(*s2.end() == 0); + fixed_string<3> s3("12"); + s3.append(s1, 1, 1); + BOOST_TEST(s3 == "12Y"); + BOOST_TEST(*s3.end() == 0); + fixed_string<3> s4("12"); + BOOST_TEST_THROWS( + (s4.append(s1, 4)), + std::out_of_range); + fixed_string<3> s5("12"); + BOOST_TEST_THROWS( + (s5.append(s1, 1)), + std::length_error); + } + { + fixed_string<4> s1("12"); + s1.append("XYZ", 2); + BOOST_TEST(s1 == "12XY"); + BOOST_TEST(*s1.end() == 0); + fixed_string<3> s3("12"); + BOOST_TEST_THROWS( + (s3.append("XYZ", 2)), + std::length_error); + } + { + fixed_string<5> s1("12"); + s1.append("XYZ"); + BOOST_TEST(s1 == "12XYZ"); + BOOST_TEST(*s1.end() == 0); + fixed_string<4> s2("12"); + BOOST_TEST_THROWS( + s2.append("XYZ"), + std::length_error); + } + { + fixed_string<3> s1("XYZ"); + fixed_string<5> s2("12"); + s2.append(s1.begin(), s1.end()); + BOOST_TEST(s2 == "12XYZ"); + BOOST_TEST(*s2.end() == 0); + fixed_string<4> s3("12"); + BOOST_TEST_THROWS( + s3.append(s1.begin(), s1.end()), + std::length_error); + } + { + fixed_string<5> s1("123"); + s1.append({'X', 'Y'}); + BOOST_TEST(s1 == "123XY"); + BOOST_TEST(*s1.end() == 0); + fixed_string<4> s2("123"); + BOOST_TEST_THROWS( + s2.append({'X', 'Y'}), + std::length_error); + } + { + string_view s1("XYZ"); + fixed_string<5> s2("12"); + s2.append(s1); + BOOST_TEST(s2 == "12XYZ"); + BOOST_TEST(*s2.end() == 0); + fixed_string<4> s3("12"); + BOOST_TEST_THROWS( + s3.append(s1), + std::length_error); + } + { + fixed_string<6> s1("123"); + s1.append(std::string("UVX"), 1); + BOOST_TEST(s1 == "123VX"); + BOOST_TEST(*s1.end() == 0); + s1.append(std::string("PQR"), 1, 1); + BOOST_TEST(s1 == "123VXQ"); + BOOST_TEST(*s1.end() == 0); + fixed_string<3> s2("123"); + BOOST_TEST_THROWS( + (s2.append(std::string("PQR"), 1, 1)), + std::length_error); + } BOOST_TEST(testA(S(), "", 0, S())); BOOST_TEST(testA(S(), "12345", 3, S("123"))); BOOST_TEST(testA(S(), "12345", 4, S("1234"))); @@ -2036,8 +2037,8 @@ testAppend() BOOST_TEST(testA(S("12345678901234567890"), "", 0, S("12345678901234567890"))); BOOST_TEST(testA(S("12345678901234567890"), "12345", 5, S("1234567890123456789012345"))); BOOST_TEST(testA(S("12345678901234567890"), "12345678901234567890", 20, - S("1234567890123456789012345678901234567890"))); - + S("1234567890123456789012345678901234567890"))); + S s_short = "123/"; S s_long = "Lorem ipsum dolor sit amet, consectetur/"; @@ -2046,175 +2047,175 @@ testAppend() s_short.append(s_short.data(), s_short.size()); BOOST_TEST(s_short == "123/123/123/123/"); s_short.append(s_short.data(), s_short.size()); - BOOST_TEST(s_short == "123/123/123/123/123/123/123/123/"); -} - -// done -static -void -testPlusEquals() -{ - using sv = string_view; - - // operator+=(CharT ch) - BOOST_TEST((fixed_string<3>{"ab"} += 'c') == "abc"); - BOOST_TEST_THROWS((fixed_string<3>{"abc"} += '*'), std::length_error); - - // operator+=(CharT const* s) - BOOST_TEST((fixed_string<3>{"a"} += "bc") == "abc"); - BOOST_TEST_THROWS((fixed_string<3>{"abc"} += "*"), std::length_error); - - // operator+=(std::initializer_list init) - BOOST_TEST((fixed_string<3>{"a"} += {'b', 'c'}) == "abc"); - BOOST_TEST_THROWS((fixed_string<3>{"abc"} += {'*', '*'}), std::length_error); - - // operator+=(string_view_type const& s) - BOOST_TEST((fixed_string<3>{"a"} += sv{"bc"}) == "abc"); - BOOST_TEST_THROWS((fixed_string<3>{"abc"} += sv{"*"}), std::length_error); - - //--- - - { - fixed_string<2> s1("__"); - fixed_string<3> s2("1"); - s2 += s1; - BOOST_TEST(s2 == "1__"); - BOOST_TEST(*s2.end() == 0); - fixed_string<2> s3("1"); - BOOST_TEST_THROWS( - s3 += s1, - std::length_error); - } - { - fixed_string<3> s1("12"); - s1 += '3'; - BOOST_TEST(s1 == "123"); - BOOST_TEST_THROWS( - s1 += '4', - std::length_error); - } - { - fixed_string<4> s1("12"); - s1 += "34"; - BOOST_TEST(s1 == "1234"); - BOOST_TEST_THROWS( - s1 += "5", - std::length_error); - } - { - fixed_string<4> s1("12"); - s1 += {'3', '4'}; - BOOST_TEST(s1 == "1234"); - BOOST_TEST_THROWS( - (s1 += {'5'}), - std::length_error); - } - { - string_view s1("34"); - fixed_string<4> s2("12"); - s2 += s1; - BOOST_TEST(s2 == "1234"); - BOOST_TEST_THROWS( - s2 += s1, - std::length_error); - } -} - -// done -void -testCompare() -{ - using str1 = fixed_string<1>; - using str2 = fixed_string<2>; - { - str1 s1; - str2 s2; - s1 = "1"; - s2 = "22"; - BOOST_TEST(s1.compare(s2) < 0); - BOOST_TEST(s2.compare(s1) > 0); - BOOST_TEST(s1 < "10"); - BOOST_TEST(s2 > "1"); - BOOST_TEST("10" > s1); - BOOST_TEST("1" < s2); - BOOST_TEST(s1 < "20"); - BOOST_TEST(s2 > "1"); - BOOST_TEST(s2 > "2"); - } - { - str2 s1("x"); - str2 s2("x"); - BOOST_TEST(s1 == s2); - BOOST_TEST(s1 <= s2); - BOOST_TEST(s1 >= s2); - BOOST_TEST(! (s1 < s2)); - BOOST_TEST(! (s1 > s2)); - BOOST_TEST(! (s1 != s2)); - } - { - str1 s1("x"); - str2 s2("x"); - BOOST_TEST(s1 == s2); - BOOST_TEST(s1 <= s2); - BOOST_TEST(s1 >= s2); - BOOST_TEST(! (s1 < s2)); - BOOST_TEST(! (s1 > s2)); - BOOST_TEST(! (s1 != s2)); - } - { - str2 s("x"); - BOOST_TEST(s == "x"); - BOOST_TEST(s <= "x"); - BOOST_TEST(s >= "x"); - BOOST_TEST(! (s < "x")); - BOOST_TEST(! (s > "x")); - BOOST_TEST(! (s != "x")); - BOOST_TEST("x" == s); - BOOST_TEST("x" <= s); - BOOST_TEST("x" >= s); - BOOST_TEST(! ("x" < s)); - BOOST_TEST(! ("x" > s)); - BOOST_TEST(! ("x" != s)); - } - { - str2 s("x"); - BOOST_TEST(s <= "y"); - BOOST_TEST(s < "y"); - BOOST_TEST(s != "y"); - BOOST_TEST(! (s == "y")); - BOOST_TEST(! (s >= "y")); - BOOST_TEST(! (s > "x")); - BOOST_TEST("y" >= s); - BOOST_TEST("y" > s); - BOOST_TEST("y" != s); - BOOST_TEST(! ("y" == s)); - BOOST_TEST(! ("y" <= s)); - BOOST_TEST(! ("y" < s)); - } - { - str1 s1("x"); - str2 s2("y"); - BOOST_TEST(s1 <= s2); - BOOST_TEST(s1 < s2); - BOOST_TEST(s1 != s2); - BOOST_TEST(! (s1 == s2)); - BOOST_TEST(! (s1 >= s2)); - BOOST_TEST(! (s1 > s2)); - } - { - str1 s1("x"); - str2 s2("xx"); - BOOST_TEST(s1 < s2); - BOOST_TEST(s2 > s1); - } - { - str1 s1("x"); - str2 s2("yy"); - BOOST_TEST(s1 < s2); - BOOST_TEST(s2 > s1); - } - - using S = fixed_string<400>; + BOOST_TEST(s_short == "123/123/123/123/123/123/123/123/"); +} + +// done +static +void +testPlusEquals() +{ + using sv = string_view; + + // operator+=(CharT ch) + BOOST_TEST((fixed_string<3>{"ab"} += 'c') == "abc"); + BOOST_TEST_THROWS((fixed_string<3>{"abc"} += '*'), std::length_error); + + // operator+=(CharT const* s) + BOOST_TEST((fixed_string<3>{"a"} += "bc") == "abc"); + BOOST_TEST_THROWS((fixed_string<3>{"abc"} += "*"), std::length_error); + + // operator+=(std::initializer_list init) + BOOST_TEST((fixed_string<3>{"a"} += {'b', 'c'}) == "abc"); + BOOST_TEST_THROWS((fixed_string<3>{"abc"} += {'*', '*'}), std::length_error); + + // operator+=(string_view_type const& s) + BOOST_TEST((fixed_string<3>{"a"} += sv{"bc"}) == "abc"); + BOOST_TEST_THROWS((fixed_string<3>{"abc"} += sv{"*"}), std::length_error); + + //--- + + { + fixed_string<2> s1("__"); + fixed_string<3> s2("1"); + s2 += s1; + BOOST_TEST(s2 == "1__"); + BOOST_TEST(*s2.end() == 0); + fixed_string<2> s3("1"); + BOOST_TEST_THROWS( + s3 += s1, + std::length_error); + } + { + fixed_string<3> s1("12"); + s1 += '3'; + BOOST_TEST(s1 == "123"); + BOOST_TEST_THROWS( + s1 += '4', + std::length_error); + } + { + fixed_string<4> s1("12"); + s1 += "34"; + BOOST_TEST(s1 == "1234"); + BOOST_TEST_THROWS( + s1 += "5", + std::length_error); + } + { + fixed_string<4> s1("12"); + s1 += {'3', '4'}; + BOOST_TEST(s1 == "1234"); + BOOST_TEST_THROWS( + (s1 += {'5'}), + std::length_error); + } + { + string_view s1("34"); + fixed_string<4> s2("12"); + s2 += s1; + BOOST_TEST(s2 == "1234"); + BOOST_TEST_THROWS( + s2 += s1, + std::length_error); + } +} + +// done +void +testCompare() +{ + using str1 = fixed_string<1>; + using str2 = fixed_string<2>; + { + str1 s1; + str2 s2; + s1 = "1"; + s2 = "22"; + BOOST_TEST(s1.compare(s2) < 0); + BOOST_TEST(s2.compare(s1) > 0); + BOOST_TEST(s1 < "10"); + BOOST_TEST(s2 > "1"); + BOOST_TEST("10" > s1); + BOOST_TEST("1" < s2); + BOOST_TEST(s1 < "20"); + BOOST_TEST(s2 > "1"); + BOOST_TEST(s2 > "2"); + } + { + str2 s1("x"); + str2 s2("x"); + BOOST_TEST(s1 == s2); + BOOST_TEST(s1 <= s2); + BOOST_TEST(s1 >= s2); + BOOST_TEST(! (s1 < s2)); + BOOST_TEST(! (s1 > s2)); + BOOST_TEST(! (s1 != s2)); + } + { + str1 s1("x"); + str2 s2("x"); + BOOST_TEST(s1 == s2); + BOOST_TEST(s1 <= s2); + BOOST_TEST(s1 >= s2); + BOOST_TEST(! (s1 < s2)); + BOOST_TEST(! (s1 > s2)); + BOOST_TEST(! (s1 != s2)); + } + { + str2 s("x"); + BOOST_TEST(s == "x"); + BOOST_TEST(s <= "x"); + BOOST_TEST(s >= "x"); + BOOST_TEST(! (s < "x")); + BOOST_TEST(! (s > "x")); + BOOST_TEST(! (s != "x")); + BOOST_TEST("x" == s); + BOOST_TEST("x" <= s); + BOOST_TEST("x" >= s); + BOOST_TEST(! ("x" < s)); + BOOST_TEST(! ("x" > s)); + BOOST_TEST(! ("x" != s)); + } + { + str2 s("x"); + BOOST_TEST(s <= "y"); + BOOST_TEST(s < "y"); + BOOST_TEST(s != "y"); + BOOST_TEST(! (s == "y")); + BOOST_TEST(! (s >= "y")); + BOOST_TEST(! (s > "x")); + BOOST_TEST("y" >= s); + BOOST_TEST("y" > s); + BOOST_TEST("y" != s); + BOOST_TEST(! ("y" == s)); + BOOST_TEST(! ("y" <= s)); + BOOST_TEST(! ("y" < s)); + } + { + str1 s1("x"); + str2 s2("y"); + BOOST_TEST(s1 <= s2); + BOOST_TEST(s1 < s2); + BOOST_TEST(s1 != s2); + BOOST_TEST(! (s1 == s2)); + BOOST_TEST(! (s1 >= s2)); + BOOST_TEST(! (s1 > s2)); + } + { + str1 s1("x"); + str2 s2("xx"); + BOOST_TEST(s1 < s2); + BOOST_TEST(s2 > s1); + } + { + str1 s1("x"); + str2 s2("yy"); + BOOST_TEST(s1 < s2); + BOOST_TEST(s2 > s1); + } + + using S = fixed_string<400>; BOOST_TEST(testC(S(""), 0, 0, "", 0, 0)); BOOST_TEST(testC(S(""), 0, 0, "abcde", 0, 0)); BOOST_TEST(testC(S(""), 0, 0, "abcde", 1, -1)); @@ -3398,225 +3399,225 @@ testCompare() BOOST_TEST(testC(S("abcdefghijklmnopqrst"), 21, 0, "abcdefghijklmnopqrst", 1, 0)); BOOST_TEST(testC(S("abcdefghijklmnopqrst"), 21, 0, "abcdefghijklmnopqrst", 10, 0)); BOOST_TEST(testC(S("abcdefghijklmnopqrst"), 21, 0, "abcdefghijklmnopqrst", 19, 0)); - BOOST_TEST(testC(S("abcdefghijklmnopqrst"), 21, 0, "abcdefghijklmnopqrst", 20, 0)); -} - -// done -void -testSwap() -{ - { - fixed_string<3> s1("123"); - fixed_string<3> s2("XYZ"); - swap(s1, s2); - BOOST_TEST(s1 == "XYZ"); - BOOST_TEST(*s1.end() == 0); - BOOST_TEST(s2 == "123"); - BOOST_TEST(*s2.end() == 0); - fixed_string<3> s3("UV"); - swap(s2, s3); - BOOST_TEST(s2 == "UV"); - BOOST_TEST(*s2.end() == 0); - BOOST_TEST(s3 == "123"); - BOOST_TEST(*s3.end() == 0); - } - { - fixed_string<5> s1("123"); - fixed_string<7> s2("XYZ"); - swap(s1, s2); - BOOST_TEST(s1 == "XYZ"); - BOOST_TEST(*s1.end() == 0); - BOOST_TEST(s2 == "123"); - BOOST_TEST(*s2.end() == 0); - fixed_string<3> s3("UV"); - swap(s2, s3); - BOOST_TEST(s2 == "UV"); - BOOST_TEST(*s2.end() == 0); - BOOST_TEST(s3 == "123"); - BOOST_TEST(*s3.end() == 0); - { - fixed_string<5> s4("12345"); - fixed_string<3> s5("XYZ"); - BOOST_TEST_THROWS( - (swap(s4, s5)), - std::length_error); - } - { - fixed_string<3> s4("XYZ"); - fixed_string<5> s5("12345"); - BOOST_TEST_THROWS( - (swap(s4, s5)), - std::length_error); - } - } -} - -void -testGeneral() -{ - using str1 = fixed_string<1>; - using str2 = fixed_string<2>; - { - str1 s1; - BOOST_TEST(s1 == ""); - BOOST_TEST(s1.empty()); - BOOST_TEST(s1.size() == 0); - BOOST_TEST(s1.max_size() == 1); - BOOST_TEST(s1.capacity() == 1); - BOOST_TEST(s1.begin() == s1.end()); - BOOST_TEST(s1.cbegin() == s1.cend()); - BOOST_TEST(s1.rbegin() == s1.rend()); - BOOST_TEST(s1.crbegin() == s1.crend()); - BOOST_TEST_THROWS( - s1.at(0), - std::out_of_range); - BOOST_TEST(s1.data()[0] == 0); - BOOST_TEST(*s1.c_str() == 0); - BOOST_TEST(std::distance(s1.begin(), s1.end()) == 0); - BOOST_TEST(std::distance(s1.cbegin(), s1.cend()) == 0); - BOOST_TEST(std::distance(s1.rbegin(), s1.rend()) == 0); - BOOST_TEST(std::distance(s1.crbegin(), s1.crend()) == 0); - BOOST_TEST(s1.compare(s1) == 0); - } - { - str1 const s1; - BOOST_TEST(s1 == ""); - BOOST_TEST(s1.empty()); - BOOST_TEST(s1.size() == 0); - BOOST_TEST(s1.max_size() == 1); - BOOST_TEST(s1.capacity() == 1); - BOOST_TEST(s1.begin() == s1.end()); - BOOST_TEST(s1.cbegin() == s1.cend()); - BOOST_TEST(s1.rbegin() == s1.rend()); - BOOST_TEST(s1.crbegin() == s1.crend()); - BOOST_TEST_THROWS( - s1.at(0), - std::out_of_range); - BOOST_TEST(s1.data()[0] == 0); - BOOST_TEST(*s1.c_str() == 0); - BOOST_TEST(std::distance(s1.begin(), s1.end()) == 0); - BOOST_TEST(std::distance(s1.cbegin(), s1.cend()) == 0); - BOOST_TEST(std::distance(s1.rbegin(), s1.rend()) == 0); - BOOST_TEST(std::distance(s1.crbegin(), s1.crend()) == 0); - BOOST_TEST(s1.compare(s1) == 0); - } - { - str1 s1; - str1 s2("x"); - BOOST_TEST(s2 == "x"); - BOOST_TEST(s2[0] == 'x'); - BOOST_TEST(s2.at(0) == 'x'); - BOOST_TEST(s2.front() == 'x'); - BOOST_TEST(s2.back() == 'x'); - str1 const s3(s2); - BOOST_TEST(s3 == "x"); - BOOST_TEST(s3[0] == 'x'); - BOOST_TEST(s3.at(0) == 'x'); - BOOST_TEST(s3.front() == 'x'); - BOOST_TEST(s3.back() == 'x'); - s2 = "y"; - BOOST_TEST(s2 == "y"); - BOOST_TEST(s3 == "x"); - s1 = s2; - BOOST_TEST(s1 == "y"); - s1.clear(); - BOOST_TEST(s1.empty()); - BOOST_TEST(s1.size() == 0); - } - { - str2 s1("x"); - str1 s2(s1); - BOOST_TEST(s2 == "x"); - str1 s3; - s3 = s2; - BOOST_TEST(s3 == "x"); - s1 = "xy"; - BOOST_TEST(s1.size() == 2); - BOOST_TEST(s1[0] == 'x'); - BOOST_TEST(s1[1] == 'y'); - BOOST_TEST(s1.at(0) == 'x'); - BOOST_TEST(s1.at(1) == 'y'); - BOOST_TEST(s1.front() == 'x'); - BOOST_TEST(s1.back() == 'y'); - auto const s4 = s1; - BOOST_TEST(s4[0] == 'x'); - BOOST_TEST(s4[1] == 'y'); - BOOST_TEST(s4.at(0) == 'x'); - BOOST_TEST(s4.at(1) == 'y'); - BOOST_TEST(s4.front() == 'x'); - BOOST_TEST(s4.back() == 'y'); - BOOST_TEST_THROWS( - s3 = s1, - std::length_error); - BOOST_TEST_THROWS( - str1{s1}, - std::length_error); - } - { - str1 s1("x"); - str2 s2; - s2 = s1; - BOOST_TEST_THROWS( - s1.resize(2), - std::length_error); - } -} - -// done -void -testToStaticString() -{ - BOOST_TEST(to_fixed_string(0) == "0"); - BOOST_TEST(to_fixed_string(1) == "1"); - BOOST_TEST(to_fixed_string(0xffff) == "65535"); - BOOST_TEST(to_fixed_string(0x10000) == "65536"); - BOOST_TEST(to_fixed_string(0xffffffff) == "4294967295"); - - BOOST_TEST(to_fixed_string(-1) == "-1"); - BOOST_TEST(to_fixed_string(-65535) == "-65535"); - BOOST_TEST(to_fixed_string(-65536) == "-65536"); - BOOST_TEST(to_fixed_string(-4294967295ll) == "-4294967295"); - - BOOST_TEST(to_fixed_string(0) == "0"); - BOOST_TEST(to_fixed_string(1) == "1"); - BOOST_TEST(to_fixed_string(0xffff) == "65535"); - BOOST_TEST(to_fixed_string(0x10000) == "65536"); - BOOST_TEST(to_fixed_string(0xffffffff) == "4294967295"); -} - -// done -void -testFind() -{ - const char* cs1 = "12345"; - const char* cs2 = "2345"; - string_view v1 = cs1; - string_view v2 = cs2; - fixed_string<5> fs1 = cs1; - fixed_string<4> fs2 = cs2; - using S = fixed_string<400>; - - - // find - BOOST_TEST(fs1.find(v1) == 0); - BOOST_TEST(fs1.find(v2) == 1); - BOOST_TEST(fs1.find(fs1) == 0); - BOOST_TEST(fs1.find(fs2) == 1); - - BOOST_TEST(fs1.find(cs1) == 0); - BOOST_TEST(fs1.find(cs2) == 1); - - BOOST_TEST(fs1.find(cs1, 0) == 0); - BOOST_TEST(fs1.find(cs2, 0) == 1); - - BOOST_TEST(fs1.find(cs2, 0, 2) == 1); - - BOOST_TEST(fs1.find(cs1, 4) == -1); - BOOST_TEST(fs1.find(cs2, 4) == -1); - - BOOST_TEST(fs1.find('1') == 0); - BOOST_TEST(fs1.find('1', 4) == -1); - + BOOST_TEST(testC(S("abcdefghijklmnopqrst"), 21, 0, "abcdefghijklmnopqrst", 20, 0)); +} + +// done +void +testSwap() +{ + { + fixed_string<3> s1("123"); + fixed_string<3> s2("XYZ"); + swap(s1, s2); + BOOST_TEST(s1 == "XYZ"); + BOOST_TEST(*s1.end() == 0); + BOOST_TEST(s2 == "123"); + BOOST_TEST(*s2.end() == 0); + fixed_string<3> s3("UV"); + swap(s2, s3); + BOOST_TEST(s2 == "UV"); + BOOST_TEST(*s2.end() == 0); + BOOST_TEST(s3 == "123"); + BOOST_TEST(*s3.end() == 0); + } + { + fixed_string<5> s1("123"); + fixed_string<7> s2("XYZ"); + swap(s1, s2); + BOOST_TEST(s1 == "XYZ"); + BOOST_TEST(*s1.end() == 0); + BOOST_TEST(s2 == "123"); + BOOST_TEST(*s2.end() == 0); + fixed_string<3> s3("UV"); + swap(s2, s3); + BOOST_TEST(s2 == "UV"); + BOOST_TEST(*s2.end() == 0); + BOOST_TEST(s3 == "123"); + BOOST_TEST(*s3.end() == 0); + { + fixed_string<5> s4("12345"); + fixed_string<3> s5("XYZ"); + BOOST_TEST_THROWS( + (swap(s4, s5)), + std::length_error); + } + { + fixed_string<3> s4("XYZ"); + fixed_string<5> s5("12345"); + BOOST_TEST_THROWS( + (swap(s4, s5)), + std::length_error); + } + } +} + +void +testGeneral() +{ + using str1 = fixed_string<1>; + using str2 = fixed_string<2>; + { + str1 s1; + BOOST_TEST(s1 == ""); + BOOST_TEST(s1.empty()); + BOOST_TEST(s1.size() == 0); + BOOST_TEST(s1.max_size() == 1); + BOOST_TEST(s1.capacity() == 1); + BOOST_TEST(s1.begin() == s1.end()); + BOOST_TEST(s1.cbegin() == s1.cend()); + BOOST_TEST(s1.rbegin() == s1.rend()); + BOOST_TEST(s1.crbegin() == s1.crend()); + BOOST_TEST_THROWS( + s1.at(0), + std::out_of_range); + BOOST_TEST(s1.data()[0] == 0); + BOOST_TEST(*s1.c_str() == 0); + BOOST_TEST(std::distance(s1.begin(), s1.end()) == 0); + BOOST_TEST(std::distance(s1.cbegin(), s1.cend()) == 0); + BOOST_TEST(std::distance(s1.rbegin(), s1.rend()) == 0); + BOOST_TEST(std::distance(s1.crbegin(), s1.crend()) == 0); + BOOST_TEST(s1.compare(s1) == 0); + } + { + str1 const s1; + BOOST_TEST(s1 == ""); + BOOST_TEST(s1.empty()); + BOOST_TEST(s1.size() == 0); + BOOST_TEST(s1.max_size() == 1); + BOOST_TEST(s1.capacity() == 1); + BOOST_TEST(s1.begin() == s1.end()); + BOOST_TEST(s1.cbegin() == s1.cend()); + BOOST_TEST(s1.rbegin() == s1.rend()); + BOOST_TEST(s1.crbegin() == s1.crend()); + BOOST_TEST_THROWS( + s1.at(0), + std::out_of_range); + BOOST_TEST(s1.data()[0] == 0); + BOOST_TEST(*s1.c_str() == 0); + BOOST_TEST(std::distance(s1.begin(), s1.end()) == 0); + BOOST_TEST(std::distance(s1.cbegin(), s1.cend()) == 0); + BOOST_TEST(std::distance(s1.rbegin(), s1.rend()) == 0); + BOOST_TEST(std::distance(s1.crbegin(), s1.crend()) == 0); + BOOST_TEST(s1.compare(s1) == 0); + } + { + str1 s1; + str1 s2("x"); + BOOST_TEST(s2 == "x"); + BOOST_TEST(s2[0] == 'x'); + BOOST_TEST(s2.at(0) == 'x'); + BOOST_TEST(s2.front() == 'x'); + BOOST_TEST(s2.back() == 'x'); + str1 const s3(s2); + BOOST_TEST(s3 == "x"); + BOOST_TEST(s3[0] == 'x'); + BOOST_TEST(s3.at(0) == 'x'); + BOOST_TEST(s3.front() == 'x'); + BOOST_TEST(s3.back() == 'x'); + s2 = "y"; + BOOST_TEST(s2 == "y"); + BOOST_TEST(s3 == "x"); + s1 = s2; + BOOST_TEST(s1 == "y"); + s1.clear(); + BOOST_TEST(s1.empty()); + BOOST_TEST(s1.size() == 0); + } + { + str2 s1("x"); + str1 s2(s1); + BOOST_TEST(s2 == "x"); + str1 s3; + s3 = s2; + BOOST_TEST(s3 == "x"); + s1 = "xy"; + BOOST_TEST(s1.size() == 2); + BOOST_TEST(s1[0] == 'x'); + BOOST_TEST(s1[1] == 'y'); + BOOST_TEST(s1.at(0) == 'x'); + BOOST_TEST(s1.at(1) == 'y'); + BOOST_TEST(s1.front() == 'x'); + BOOST_TEST(s1.back() == 'y'); + auto const s4 = s1; + BOOST_TEST(s4[0] == 'x'); + BOOST_TEST(s4[1] == 'y'); + BOOST_TEST(s4.at(0) == 'x'); + BOOST_TEST(s4.at(1) == 'y'); + BOOST_TEST(s4.front() == 'x'); + BOOST_TEST(s4.back() == 'y'); + BOOST_TEST_THROWS( + s3 = s1, + std::length_error); + BOOST_TEST_THROWS( + str1{s1}, + std::length_error); + } + { + str1 s1("x"); + str2 s2; + s2 = s1; + BOOST_TEST_THROWS( + s1.resize(2), + std::length_error); + } +} + +// done +void +testToStaticString() +{ + BOOST_TEST(to_fixed_string(0) == "0"); + BOOST_TEST(to_fixed_string(1) == "1"); + BOOST_TEST(to_fixed_string(0xffff) == "65535"); + BOOST_TEST(to_fixed_string(0x10000) == "65536"); + BOOST_TEST(to_fixed_string(0xffffffff) == "4294967295"); + + BOOST_TEST(to_fixed_string(-1) == "-1"); + BOOST_TEST(to_fixed_string(-65535) == "-65535"); + BOOST_TEST(to_fixed_string(-65536) == "-65536"); + BOOST_TEST(to_fixed_string(-4294967295ll) == "-4294967295"); + + BOOST_TEST(to_fixed_string(0) == "0"); + BOOST_TEST(to_fixed_string(1) == "1"); + BOOST_TEST(to_fixed_string(0xffff) == "65535"); + BOOST_TEST(to_fixed_string(0x10000) == "65536"); + BOOST_TEST(to_fixed_string(0xffffffff) == "4294967295"); +} + +// done +void +testFind() +{ + const char* cs1 = "12345"; + const char* cs2 = "2345"; + string_view v1 = cs1; + string_view v2 = cs2; + fixed_string<5> fs1 = cs1; + fixed_string<4> fs2 = cs2; + using S = fixed_string<400>; + + + // find + BOOST_TEST(fs1.find(v1) == 0); + BOOST_TEST(fs1.find(v2) == 1); + BOOST_TEST(fs1.find(fs1) == 0); + BOOST_TEST(fs1.find(fs2) == 1); + + BOOST_TEST(fs1.find(cs1) == 0); + BOOST_TEST(fs1.find(cs2) == 1); + + BOOST_TEST(fs1.find(cs1, 0) == 0); + BOOST_TEST(fs1.find(cs2, 0) == 1); + + BOOST_TEST(fs1.find(cs2, 0, 2) == 1); + + BOOST_TEST(fs1.find(cs1, 4) == -1); + BOOST_TEST(fs1.find(cs2, 4) == -1); + + BOOST_TEST(fs1.find('1') == 0); + BOOST_TEST(fs1.find('1', 4) == -1); + BOOST_TEST(testF(S(""), "", 0, 0, 0)); BOOST_TEST(testF(S(""), "abcde", 0, 0, 0)); BOOST_TEST(testF(S(""), "abcde", 0, 1, S::npos)); @@ -3916,45 +3917,45 @@ testFind() BOOST_TEST(testF(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 5, S::npos)); BOOST_TEST(testF(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 9, S::npos)); BOOST_TEST(testF(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 10, S::npos)); - BOOST_TEST(testF(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 0, 20)); - - - - - - - - - - - - - - - - - - // rfind - - BOOST_TEST(fs1.rfind(v1) == 0); - BOOST_TEST(fs1.rfind(v2) == 1); - - BOOST_TEST(fs1.rfind(fs1) == 0); - BOOST_TEST(fs1.rfind(fs2) == 1); - - BOOST_TEST(fs1.rfind(cs1) == 0); - BOOST_TEST(fs1.rfind(cs2) == 1); - - BOOST_TEST(fs1.rfind(cs1, 0) == 0); - BOOST_TEST(fs1.rfind(cs2, 0) == -1); - - BOOST_TEST(fs1.rfind(cs2, 0, 2) == -1); - BOOST_TEST(fs1.rfind(cs1, 4) == 0); - - BOOST_TEST(fs1.rfind('1') == 0); - BOOST_TEST(fs1.rfind('1', 4) == 0); - - + BOOST_TEST(testF(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 0, 20)); + + + + + + + + + + + + + + + + + + // rfind + + BOOST_TEST(fs1.rfind(v1) == 0); + BOOST_TEST(fs1.rfind(v2) == 1); + + BOOST_TEST(fs1.rfind(fs1) == 0); + BOOST_TEST(fs1.rfind(fs2) == 1); + + BOOST_TEST(fs1.rfind(cs1) == 0); + BOOST_TEST(fs1.rfind(cs2) == 1); + + BOOST_TEST(fs1.rfind(cs1, 0) == 0); + BOOST_TEST(fs1.rfind(cs2, 0) == -1); + + BOOST_TEST(fs1.rfind(cs2, 0, 2) == -1); + BOOST_TEST(fs1.rfind(cs1, 4) == 0); + + BOOST_TEST(fs1.rfind('1') == 0); + BOOST_TEST(fs1.rfind('1', 4) == 0); + + BOOST_TEST(testRF(S(""), "", 0, 0, 0)); BOOST_TEST(testRF(S(""), "abcde", 0, 0, 0)); BOOST_TEST(testRF(S(""), "abcde", 0, 1, S::npos)); @@ -4254,38 +4255,38 @@ testFind() BOOST_TEST(testRF(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 5, 15)); BOOST_TEST(testRF(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 9, 10)); BOOST_TEST(testRF(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 10, 10)); - BOOST_TEST(testRF(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 0, 20)); - - - - - - - - - - - // find_first_of - - BOOST_TEST(fs1.find_first_of(v1) == 0); - BOOST_TEST(fs1.find_first_of(v2) == 1); - BOOST_TEST(fs1.find_first_of(fs1) == 0); - BOOST_TEST(fs1.find_first_of(fs2) == 1); - - BOOST_TEST(fs1.find_first_of(cs1) == 0); - BOOST_TEST(fs1.find_first_of(cs2) == 1); - - BOOST_TEST(fs1.find_first_of(cs1, 0) == 0); - BOOST_TEST(fs1.find_first_of(cs2, 0) == 1); - - BOOST_TEST(fs1.find_first_of(cs2, 0, 2) == 1); - - BOOST_TEST(fs1.find_first_of(cs1, 4) == 4); - BOOST_TEST(fs1.find_first_of(cs2, 4) == 4); - - BOOST_TEST(fs1.find_first_of('1') == 0); - BOOST_TEST(fs1.find_first_of('1', 4) == -1); - + BOOST_TEST(testRF(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 0, 20)); + + + + + + + + + + + // find_first_of + + BOOST_TEST(fs1.find_first_of(v1) == 0); + BOOST_TEST(fs1.find_first_of(v2) == 1); + BOOST_TEST(fs1.find_first_of(fs1) == 0); + BOOST_TEST(fs1.find_first_of(fs2) == 1); + + BOOST_TEST(fs1.find_first_of(cs1) == 0); + BOOST_TEST(fs1.find_first_of(cs2) == 1); + + BOOST_TEST(fs1.find_first_of(cs1, 0) == 0); + BOOST_TEST(fs1.find_first_of(cs2, 0) == 1); + + BOOST_TEST(fs1.find_first_of(cs2, 0, 2) == 1); + + BOOST_TEST(fs1.find_first_of(cs1, 4) == 4); + BOOST_TEST(fs1.find_first_of(cs2, 4) == 4); + + BOOST_TEST(fs1.find_first_of('1') == 0); + BOOST_TEST(fs1.find_first_of('1', 4) == -1); + BOOST_TEST(testFF(S(""), "", 0, 0, S::npos)); BOOST_TEST(testFF(S(""), "irkhs", 0, 0, S::npos)); BOOST_TEST(testFF(S(""), "kante", 0, 1, S::npos)); @@ -4585,36 +4586,36 @@ testFind() BOOST_TEST(testFF(S("rhqdspkmebiflcotnjga"), "acfhdenops", 20, 5, S::npos)); BOOST_TEST(testFF(S("rahdtmsckfboqlpniegj"), "jopdeamcrk", 20, 9, S::npos)); BOOST_TEST(testFF(S("fbkeiopclstmdqranjhg"), "trqncbkgmh", 20, 10, S::npos)); - BOOST_TEST(testFF(S("lifhpdgmbconstjeqark"), "tomglrkencbsfjqpihda", 20, 0, S::npos)); - - - - - - - - - // find_last_of - - BOOST_TEST(fs1.find_last_of(v1) == 4); - BOOST_TEST(fs1.find_last_of(v2) == 4); - BOOST_TEST(fs1.find_last_of(fs1) == 4); - BOOST_TEST(fs1.find_last_of(fs2) == 4); - - BOOST_TEST(fs1.find_last_of(cs1) == 4); - BOOST_TEST(fs1.find_last_of(cs2) == 4); - - BOOST_TEST(fs1.find_last_of(cs1, 0) == 0); - BOOST_TEST(fs1.find_last_of(cs2, 0) == -1); - - BOOST_TEST(fs1.find_last_of(cs2, 0, 2) == -1); - - BOOST_TEST(fs1.find_last_of(cs1, 4) == 4); - BOOST_TEST(fs1.find_last_of(cs2, 4) == 4); - - BOOST_TEST(fs1.find_last_of('1') == 0); - BOOST_TEST(fs1.find_last_of('5', 3) == -1); - + BOOST_TEST(testFF(S("lifhpdgmbconstjeqark"), "tomglrkencbsfjqpihda", 20, 0, S::npos)); + + + + + + + + + // find_last_of + + BOOST_TEST(fs1.find_last_of(v1) == 4); + BOOST_TEST(fs1.find_last_of(v2) == 4); + BOOST_TEST(fs1.find_last_of(fs1) == 4); + BOOST_TEST(fs1.find_last_of(fs2) == 4); + + BOOST_TEST(fs1.find_last_of(cs1) == 4); + BOOST_TEST(fs1.find_last_of(cs2) == 4); + + BOOST_TEST(fs1.find_last_of(cs1, 0) == 0); + BOOST_TEST(fs1.find_last_of(cs2, 0) == -1); + + BOOST_TEST(fs1.find_last_of(cs2, 0, 2) == -1); + + BOOST_TEST(fs1.find_last_of(cs1, 4) == 4); + BOOST_TEST(fs1.find_last_of(cs2, 4) == 4); + + BOOST_TEST(fs1.find_last_of('1') == 0); + BOOST_TEST(fs1.find_last_of('5', 3) == -1); + BOOST_TEST(testFL(S(""), "", 0, 0, S::npos)); BOOST_TEST(testFL(S(""), "irkhs", 0, 0, S::npos)); BOOST_TEST(testFL(S(""), "kante", 0, 1, S::npos)); @@ -4934,46 +4935,46 @@ testFind() BOOST_TEST(testFL(S("qjidealmtpskrbfhocng"), "ctpmdahebfqjgknloris", 21, 1, 17)); BOOST_TEST(testFL(S("qeindtagmokpfhsclrbj"), "apnkeqthrmlbfodiscgj", 21, 10, 17)); BOOST_TEST(testFL(S("kpfegbjhsrnodltqciam"), "jdgictpframeoqlsbknh", 21, 19, 19)); - BOOST_TEST(testFL(S("hnbrcplsjfgiktoedmaq"), "qprlsfojamgndekthibc", 21, 20, 19)); - - - - - - - - // find_first_not_of - - const char* cs3 = "12456"; - const char* cs4 = "2356"; - string_view v3 = cs3; - string_view v4 = cs4; - fixed_string<5> fs3 = cs3; - fixed_string<4> fs4 = cs4; - - BOOST_TEST(fs1.find_first_not_of(v3) == 2); - BOOST_TEST(fs1.find_first_not_of(v4) == 0); - BOOST_TEST(fs1.find_first_not_of(fs3) == 2); - BOOST_TEST(fs1.find_first_not_of(fs4) == 0); - - BOOST_TEST(fs1.find_first_not_of(cs3) == 2); - BOOST_TEST(fs1.find_first_not_of(cs4) == 0); - - BOOST_TEST(fs1.find_first_not_of(cs3, 0) == 2); - BOOST_TEST(fs1.find_first_not_of(cs4, 0) == 0); - - BOOST_TEST(fs1.find_first_not_of(cs4, 0, 2) == 0); - - BOOST_TEST(fs1.find_first_not_of(cs3, 4) == -1); - BOOST_TEST(fs1.find_first_not_of(cs4, 4) == -1); - - BOOST_TEST(fs1.find_first_not_of('1') == 1); - BOOST_TEST(fs1.find_first_not_of('1', 3) == 3); - - - - - + BOOST_TEST(testFL(S("hnbrcplsjfgiktoedmaq"), "qprlsfojamgndekthibc", 21, 20, 19)); + + + + + + + + // find_first_not_of + + const char* cs3 = "12456"; + const char* cs4 = "2356"; + string_view v3 = cs3; + string_view v4 = cs4; + fixed_string<5> fs3 = cs3; + fixed_string<4> fs4 = cs4; + + BOOST_TEST(fs1.find_first_not_of(v3) == 2); + BOOST_TEST(fs1.find_first_not_of(v4) == 0); + BOOST_TEST(fs1.find_first_not_of(fs3) == 2); + BOOST_TEST(fs1.find_first_not_of(fs4) == 0); + + BOOST_TEST(fs1.find_first_not_of(cs3) == 2); + BOOST_TEST(fs1.find_first_not_of(cs4) == 0); + + BOOST_TEST(fs1.find_first_not_of(cs3, 0) == 2); + BOOST_TEST(fs1.find_first_not_of(cs4, 0) == 0); + + BOOST_TEST(fs1.find_first_not_of(cs4, 0, 2) == 0); + + BOOST_TEST(fs1.find_first_not_of(cs3, 4) == -1); + BOOST_TEST(fs1.find_first_not_of(cs4, 4) == -1); + + BOOST_TEST(fs1.find_first_not_of('1') == 1); + BOOST_TEST(fs1.find_first_not_of('1', 3) == 3); + + + + + BOOST_TEST(testFFN(S(""), "", 0, 0, S::npos)); BOOST_TEST(testFFN(S(""), "irkhs", 0, 0, S::npos)); BOOST_TEST(testFFN(S(""), "kante", 0, 1, S::npos)); @@ -5293,30 +5294,30 @@ testFind() BOOST_TEST(testFFN(S("qjidealmtpskrbfhocng"), "ctpmdahebfqjgknloris", 21, 1, S::npos)); BOOST_TEST(testFFN(S("qeindtagmokpfhsclrbj"), "apnkeqthrmlbfodiscgj", 21, 10, S::npos)); BOOST_TEST(testFFN(S("kpfegbjhsrnodltqciam"), "jdgictpframeoqlsbknh", 21, 19, S::npos)); - BOOST_TEST(testFFN(S("hnbrcplsjfgiktoedmaq"), "qprlsfojamgndekthibc", 21, 20, S::npos)); - - // find_last_not_of - - BOOST_TEST(fs1.find_last_not_of(v3) == 2); - BOOST_TEST(fs1.find_last_not_of(v4) == 3); - BOOST_TEST(fs1.find_last_not_of(fs3) == 2); - BOOST_TEST(fs1.find_last_not_of(fs4) == 3); - - BOOST_TEST(fs1.find_last_not_of(cs3) == 2); - BOOST_TEST(fs1.find_last_not_of(cs4) == 3); - - BOOST_TEST(fs1.find_last_not_of(cs3, 0) == -1); - BOOST_TEST(fs1.find_last_not_of(cs4, 0) == 0); - - BOOST_TEST(fs1.find_last_not_of(cs4, 0, 2) == 0); - - BOOST_TEST(fs1.find_last_not_of(cs3, 4) == 2); - BOOST_TEST(fs1.find_last_not_of(cs4, 4) == 3); - - BOOST_TEST(fs1.find_last_not_of('1') == 4); - BOOST_TEST(fs1.find_last_not_of('1', 3) == 3); - - + BOOST_TEST(testFFN(S("hnbrcplsjfgiktoedmaq"), "qprlsfojamgndekthibc", 21, 20, S::npos)); + + // find_last_not_of + + BOOST_TEST(fs1.find_last_not_of(v3) == 2); + BOOST_TEST(fs1.find_last_not_of(v4) == 3); + BOOST_TEST(fs1.find_last_not_of(fs3) == 2); + BOOST_TEST(fs1.find_last_not_of(fs4) == 3); + + BOOST_TEST(fs1.find_last_not_of(cs3) == 2); + BOOST_TEST(fs1.find_last_not_of(cs4) == 3); + + BOOST_TEST(fs1.find_last_not_of(cs3, 0) == -1); + BOOST_TEST(fs1.find_last_not_of(cs4, 0) == 0); + + BOOST_TEST(fs1.find_last_not_of(cs4, 0, 2) == 0); + + BOOST_TEST(fs1.find_last_not_of(cs3, 4) == 2); + BOOST_TEST(fs1.find_last_not_of(cs4, 4) == 3); + + BOOST_TEST(fs1.find_last_not_of('1') == 4); + BOOST_TEST(fs1.find_last_not_of('1', 3) == 3); + + BOOST_TEST(testFLN(S(""), "", 0, 0, S::npos)); BOOST_TEST(testFLN(S(""), "irkhs", 0, 0, S::npos)); BOOST_TEST(testFLN(S(""), "kante", 0, 1, S::npos)); @@ -5636,145 +5637,145 @@ testFind() BOOST_TEST(testFLN(S("qjidealmtpskrbfhocng"), "ctpmdahebfqjgknloris", 21, 1, 19)); BOOST_TEST(testFLN(S("qeindtagmokpfhsclrbj"), "apnkeqthrmlbfodiscgj", 21, 10, 19)); BOOST_TEST(testFLN(S("kpfegbjhsrnodltqciam"), "jdgictpframeoqlsbknh", 21, 19, 7)); - BOOST_TEST(testFLN(S("hnbrcplsjfgiktoedmaq"), "qprlsfojamgndekthibc", 21, 20, S::npos)); -} - -// done -void -testReplace() -{ - // replace(size_type pos1, size_type n1, const charT* s, size_type n2); - { - fixed_string<20> fs1 = "helloworld"; - BOOST_TEST(fs1.replace(5, 2, fs1.data() + 1, 8) == "helloelloworlrld"); - } - { - fixed_string<20> fs1 = "helloworld"; - BOOST_TEST(fs1.replace(3, 2, fs1.data() + 2, 2) == "helllworld"); - } - { - fixed_string<20> fs2 = "0123456789"; - BOOST_TEST(fs2.replace(5, 2, fs2.data(), 2) == "0123401789"); - } - { - fixed_string<20> fs2 = "0123456789"; - BOOST_TEST(fs2.replace(1, 3, fs2.data() + 1, 5) == "012345456789"); - } - { - fixed_string<20> fs2 = "0123456789"; - BOOST_TEST(fs2.replace(0, 5, fs2.data(), 5) == "0123456789"); - } - { - fixed_string<20> fs2 = "0123456789"; - BOOST_TEST(fs2.replace(0, 5, fs2.data() + 5, 5) == "5678956789"); - } - { - fixed_string<20> fs2 = "0123456789"; - BOOST_TEST(fs2.replace(5, 2, fs2.data() + 3, 5) == "0123434567789"); - } - { - fixed_string<20> fs2 = "0123456789"; - BOOST_TEST(fs2.replace(5, 2, fs2.data() + 7, 3) == "01234789789"); - } - { - fixed_string<20> fs2 = "0123456789"; - BOOST_TEST(fs2.replace(3, 5, fs2.data() + 4, 2) == "0124589"); - } - { - fixed_string<20> fs2 = "0123456789"; - BOOST_TEST(fs2.replace(3, 5, fs2.data() + 1, 3) == "01212389"); - } - { - fixed_string<20> fs2 = "0123456789"; - BOOST_TEST(fs2.replace(0, 10, fs2.data(), 10) == "0123456789"); - } - { - fixed_string<20> fs2 = "0123456789"; - BOOST_TEST(fs2.replace(0, 10, fs2.data(), 5) == "01234"); - } - { - fixed_string<20> fs1 = "helloworld"; - BOOST_TEST(fs1.replace(4, 3, fs1.data() + 1, 3) == "hellellrld"); - } - { - fixed_string<20> fs1 = "helloworld"; - BOOST_TEST_EQ(fs1.replace(0, 1, fs1.data() + 4, 4), fixed_string<20>("oworelloworld")); - } - // replace(size_type pos1, size_type n1, const basic_string& str); - { - fixed_string<20> fs1 = "helloworld"; - BOOST_TEST(fs1.replace(0, fs1.size(), fs1) == "helloworld"); - } - // replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos); - { - fixed_string<20> fs1 = "helloworld"; - BOOST_TEST(fs1.replace(0, fs1.size(), fs1, 0, fs1.size()) == "helloworld"); - } - // replace(size_type pos1, size_type n1, const T& t); - { - fixed_string<20> fs1 = "helloworld"; - BOOST_TEST(fs1.replace(0, fs1.size(), string_view(fs1)) == "helloworld"); - } - // replace(size_type pos1, size_type n1, const T& t, size_type pos2, size_type n2 = npos); - { - fixed_string<20> fs1 = "helloworld"; - BOOST_TEST(fs1.replace(0, fs1.size(), string_view(fs1), 0, fs1.size()) == "helloworld"); - } - // replace(size_type pos, size_type n, const charT * s); - { - fixed_string<20> fs1 = "helloworld"; - BOOST_TEST(fs1.replace(0, fs1.size(), fs1.data()) == "helloworld"); - } - // replace(size_type pos1, size_type n1, size_type n2, charT c);] - { - fixed_string<20> fs1 = "helloworld"; - BOOST_TEST(fs1.replace(0, fs1.size(), fs1.size(), 'a') == "aaaaaaaaaa"); - } - // replace(const_iterator i1, const_iterator i2, const basic_string& str); - { - fixed_string<20> fs1 = "helloworld"; - BOOST_TEST(fs1.replace(fs1.begin(), fs1.end(), fs1) == "helloworld"); - } - // replace(const_iterator i1, const_iterator i2, const T& t); - { - fixed_string<20> fs1 = "helloworld"; - BOOST_TEST(fs1.replace(fs1.begin(), fs1.end(), string_view(fs1)) == "helloworld"); - } - // replace(const_iterator i1, const_iterator i2, const charT* s, size_type n); - { - fixed_string<20> fs1 = "helloworld"; - BOOST_TEST(fs1.replace(fs1.begin(), fs1.end(), fs1.data(), fs1.size()) == "helloworld"); - } - // replace(const_iterator i1, const_iterator i2, const charT* s); - { - fixed_string<20> fs1 = "helloworld"; - BOOST_TEST(fs1.replace(fs1.begin(), fs1.end(), fs1.data()) == "helloworld"); - } - // replace(const_iterator i1, const_iterator i2, size_type n, charT c); - { - fixed_string<20> fs1 = "helloworld"; - BOOST_TEST(fs1.replace(fs1.begin(), fs1.end(), fs1.size(), 'a') == "aaaaaaaaaa"); - } - // replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2); - { - fixed_string<20> fs1 = "helloworld"; - BOOST_TEST(fs1.replace(fs1.begin(), fs1.end(), fs1.begin(), fs1.end()) == "helloworld"); - } - // replace(const_iterator i1, const_iterator i2, initializer_list il); - { - fixed_string<20> fs1 = "helloworld"; - BOOST_TEST(fs1.replace(fs1.begin(), fs1.end(), {'h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd'}) == "helloworld"); - } - - using S = fixed_string<400>; + BOOST_TEST(testFLN(S("hnbrcplsjfgiktoedmaq"), "qprlsfojamgndekthibc", 21, 20, S::npos)); +} + +// done +void +testReplace() +{ + // replace(size_type pos1, size_type n1, const charT* s, size_type n2); + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST(fs1.replace(5, 2, fs1.data() + 1, 8) == "helloelloworlrld"); + } + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST(fs1.replace(3, 2, fs1.data() + 2, 2) == "helllworld"); + } + { + fixed_string<20> fs2 = "0123456789"; + BOOST_TEST(fs2.replace(5, 2, fs2.data(), 2) == "0123401789"); + } + { + fixed_string<20> fs2 = "0123456789"; + BOOST_TEST(fs2.replace(1, 3, fs2.data() + 1, 5) == "012345456789"); + } + { + fixed_string<20> fs2 = "0123456789"; + BOOST_TEST(fs2.replace(0, 5, fs2.data(), 5) == "0123456789"); + } + { + fixed_string<20> fs2 = "0123456789"; + BOOST_TEST(fs2.replace(0, 5, fs2.data() + 5, 5) == "5678956789"); + } + { + fixed_string<20> fs2 = "0123456789"; + BOOST_TEST(fs2.replace(5, 2, fs2.data() + 3, 5) == "0123434567789"); + } + { + fixed_string<20> fs2 = "0123456789"; + BOOST_TEST(fs2.replace(5, 2, fs2.data() + 7, 3) == "01234789789"); + } + { + fixed_string<20> fs2 = "0123456789"; + BOOST_TEST(fs2.replace(3, 5, fs2.data() + 4, 2) == "0124589"); + } + { + fixed_string<20> fs2 = "0123456789"; + BOOST_TEST(fs2.replace(3, 5, fs2.data() + 1, 3) == "01212389"); + } + { + fixed_string<20> fs2 = "0123456789"; + BOOST_TEST(fs2.replace(0, 10, fs2.data(), 10) == "0123456789"); + } + { + fixed_string<20> fs2 = "0123456789"; + BOOST_TEST(fs2.replace(0, 10, fs2.data(), 5) == "01234"); + } + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST(fs1.replace(4, 3, fs1.data() + 1, 3) == "hellellrld"); + } + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST_EQ(fs1.replace(0, 1, fs1.data() + 4, 4), fixed_string<20>("oworelloworld")); + } + // replace(size_type pos1, size_type n1, const basic_string& str); + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST(fs1.replace(0, fs1.size(), fs1) == "helloworld"); + } + // replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos); + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST(fs1.replace(0, fs1.size(), fs1, 0, fs1.size()) == "helloworld"); + } + // replace(size_type pos1, size_type n1, const T& t); + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST(fs1.replace(0, fs1.size(), string_view(fs1)) == "helloworld"); + } + // replace(size_type pos1, size_type n1, const T& t, size_type pos2, size_type n2 = npos); + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST(fs1.replace(0, fs1.size(), string_view(fs1), 0, fs1.size()) == "helloworld"); + } + // replace(size_type pos, size_type n, const charT * s); + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST(fs1.replace(0, fs1.size(), fs1.data()) == "helloworld"); + } + // replace(size_type pos1, size_type n1, size_type n2, charT c);] + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST(fs1.replace(0, fs1.size(), fs1.size(), 'a') == "aaaaaaaaaa"); + } + // replace(const_iterator i1, const_iterator i2, const basic_string& str); + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST(fs1.replace(fs1.begin(), fs1.end(), fs1) == "helloworld"); + } + // replace(const_iterator i1, const_iterator i2, const T& t); + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST(fs1.replace(fs1.begin(), fs1.end(), string_view(fs1)) == "helloworld"); + } + // replace(const_iterator i1, const_iterator i2, const charT* s, size_type n); + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST(fs1.replace(fs1.begin(), fs1.end(), fs1.data(), fs1.size()) == "helloworld"); + } + // replace(const_iterator i1, const_iterator i2, const charT* s); + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST(fs1.replace(fs1.begin(), fs1.end(), fs1.data()) == "helloworld"); + } + // replace(const_iterator i1, const_iterator i2, size_type n, charT c); + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST(fs1.replace(fs1.begin(), fs1.end(), fs1.size(), 'a') == "aaaaaaaaaa"); + } + // replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2); + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST(fs1.replace(fs1.begin(), fs1.end(), fs1.begin(), fs1.end()) == "helloworld"); + } + // replace(const_iterator i1, const_iterator i2, initializer_list il); + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST(fs1.replace(fs1.begin(), fs1.end(), {'h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd'}) == "helloworld"); + } + + using S = fixed_string<400>; S s_short = "123/"; S s_long = "Lorem ipsum dolor sit amet, consectetur/"; - BOOST_TEST(s_short.replace(s_short.begin(), s_short.begin(), s_short.begin(), s_short.end()) == "123/123/"); - BOOST_TEST(s_short.replace(s_short.begin(), s_short.begin(), s_short.begin(), s_short.end()) == "123/123/123/123/"); - BOOST_TEST(s_short.replace(s_short.begin(), s_short.begin(), s_short.begin(), s_short.end()) == "123/123/123/123/123/123/123/123/"); - BOOST_TEST(s_long.replace(s_long.begin(), s_long.begin(), s_long.begin(), s_long.end()) == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/"); - + BOOST_TEST(s_short.replace(s_short.begin(), s_short.begin(), s_short.begin(), s_short.end()) == "123/123/"); + BOOST_TEST(s_short.replace(s_short.begin(), s_short.begin(), s_short.begin(), s_short.end()) == "123/123/123/123/"); + BOOST_TEST(s_short.replace(s_short.begin(), s_short.begin(), s_short.begin(), s_short.end()) == "123/123/123/123/123/123/123/123/"); + BOOST_TEST(s_long.replace(s_long.begin(), s_long.begin(), s_long.begin(), s_long.end()) == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/"); + BOOST_TEST(testR(S(""), 0, 0, "", S(""))); BOOST_TEST(testR(S(""), 0, 0, "12345", S("12345"))); BOOST_TEST(testR(S(""), 0, 0, "1234567890", S("1234567890"))); @@ -5874,7 +5875,7 @@ testReplace() BOOST_TEST(testR(S("abcdefghij"), 1, 1, "", S("acdefghij"))); BOOST_TEST(testR(S("abcdefghij"), 1, 1, "12345", S("a12345cdefghij"))); BOOST_TEST(testR(S("abcdefghij"), 1, 1, "1234567890", S("a1234567890cdefghij"))); - BOOST_TEST(testR(S("abcdefghij"), 1, 1, "12345678901234567890", S("a12345678901234567890cdefghij"))); + BOOST_TEST(testR(S("abcdefghij"), 1, 1, "12345678901234567890", S("a12345678901234567890cdefghij"))); BOOST_TEST(testR(S(""), 0, 0, 0, '2', S(""))); BOOST_TEST(testR(S(""), 0, 0, 5, '2', S("22222"))); BOOST_TEST(testR(S(""), 0, 0, 10, '2', S("2222222222"))); @@ -5973,8 +5974,8 @@ testReplace() BOOST_TEST(testR(S("abcde"), 5, 1, 0, '2', S("abcde"))); BOOST_TEST(testR(S("abcde"), 5, 1, 5, '2', S("abcde22222"))); BOOST_TEST(testR(S("abcde"), 5, 1, 10, '2', S("abcde2222222222"))); - BOOST_TEST(testR(S("abcde"), 5, 1, 20, '2', S("abcde22222222222222222222"))); - + BOOST_TEST(testR(S("abcde"), 5, 1, 20, '2', S("abcde22222222222222222222"))); + BOOST_TEST(testR(S("abcde"), 0, 4, "12345", 4, S("1234e"))); BOOST_TEST(testR(S("abcde"), 0, 4, "12345", 5, S("12345e"))); BOOST_TEST(testR(S("abcde"), 0, 4, "1234567890", 0, S("e"))); @@ -6174,7 +6175,7 @@ testReplace() BOOST_TEST(testR(S("abcdefghij"), 5, 6, "1234567890", 5, S("abcde12345"))); BOOST_TEST(testR(S("abcdefghij"), 5, 6, "1234567890", 9, S("abcde123456789"))); BOOST_TEST(testR(S("abcdefghij"), 5, 6, "1234567890", 10, S("abcde1234567890"))); - BOOST_TEST(testR(S("abcdefghij"), 5, 6, "12345678901234567890", 0, S("abcde"))); + BOOST_TEST(testR(S("abcdefghij"), 5, 6, "12345678901234567890", 0, S("abcde"))); BOOST_TEST(testR(S("abcdefghijklmnopqrst"), 0, 0, "", 0, S("abcdefghijklmnopqrst"))); BOOST_TEST(testR(S("abcdefghijklmnopqrst"), 0, 0, "12345", 0, S("abcdefghijklmnopqrst"))); BOOST_TEST(testR(S("abcdefghijklmnopqrst"), 0, 0, "12345", 1, S("1abcdefghijklmnopqrst"))); @@ -6474,7 +6475,7 @@ testReplace() BOOST_TEST(testR(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 5, S("abcdefghijklmnopqrs12345t"))); BOOST_TEST(testR(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 9, S("abcdefghijklmnopqrs123456789t"))); BOOST_TEST(testR(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 10, S("abcdefghijklmnopqrs1234567890t"))); - BOOST_TEST(testR(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"))); + BOOST_TEST(testR(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"))); BOOST_TEST(testR(S(""), 1, 0, "12345", 0, S("can't happen"))); BOOST_TEST(testR(S(""), 1, 0, "12345", 1, S("can't happen"))); BOOST_TEST(testR(S(""), 1, 0, "12345", 2, S("can't happen"))); @@ -6605,14 +6606,14 @@ testReplace() BOOST_TEST(testR(S("abcdefghijklmnopqrst"), 20, 1, "12345678901234567890", 1, S("abcdefghijklmnopqrst1"))); BOOST_TEST(testR(S("abcdefghijklmnopqrst"), 20, 1, "12345678901234567890", 10, S("abcdefghijklmnopqrst1234567890"))); BOOST_TEST(testR(S("abcdefghijklmnopqrst"), 20, 1, "12345678901234567890", 19, S("abcdefghijklmnopqrst1234567890123456789"))); - BOOST_TEST(testR(S("abcdefghijklmnopqrst"), 20, 1, "12345678901234567890", 20, S("abcdefghijklmnopqrst12345678901234567890"))); -} - -// done -void -testSubstr() -{ - using S = fixed_string<400>; + BOOST_TEST(testR(S("abcdefghijklmnopqrst"), 20, 1, "12345678901234567890", 20, S("abcdefghijklmnopqrst12345678901234567890"))); +} + +// done +void +testSubstr() +{ + using S = fixed_string<400>; BOOST_TEST(testS(S(""), 0, 0)); BOOST_TEST(testS(S(""), 1, 0)); BOOST_TEST(testS(S("pniot"), 0, 0)); @@ -6728,69 +6729,69 @@ testSubstr() BOOST_TEST(testS(S("lgjqketopbfahrmnsicd"), 19, 0)); BOOST_TEST(testS(S("ktsrmnqagdecfhijpobl"), 19, 1)); BOOST_TEST(testS(S("lsaijeqhtrbgcdmpfkno"), 20, 0)); - BOOST_TEST(testS(S("dplqartnfgejichmoskb"), 21, 0)); -} - -// done -void -testStartsEnds() -{ - using S = fixed_string<400>; - BOOST_TEST(S("1234567890").starts_with('1')); - BOOST_TEST(S("1234567890").starts_with("123")); - BOOST_TEST(S("1234567890").starts_with("1234567890")); - BOOST_TEST(!S("1234567890").starts_with("234")); - BOOST_TEST(!S("1234567890").starts_with("12345678900")); - BOOST_TEST(S("1234567890").starts_with(string_view("1234567890"))); - - BOOST_TEST(S("1234567890").ends_with('0')); - BOOST_TEST(S("1234567890").ends_with("890")); - BOOST_TEST(S("1234567890").ends_with("1234567890")); - BOOST_TEST(!S("1234567890").ends_with("234")); - BOOST_TEST(!S("1234567890").ends_with("12345678900")); - BOOST_TEST(S("1234567890").ends_with(string_view("1234567890"))); -} - -int -runTests() -{ - testConstruct(); - - testAssignment(); - - testElements(); - - testIterators(); - - testCapacity(); - - testClear(); - testInsert(); - testErase(); - testPushBack(); - testPopBack(); - testAppend(); - testPlusEquals(); - - testCompare(); - testSwap(); - testGeneral(); - testToStaticString(); - - testFind(); - - testReplace(); - testSubstr(); - testStartsEnds(); - - return report_errors(); -} - -} // fixed_string -} // boost - -int -main() -{ - return boost::fixed_string::runTests(); -} \ No newline at end of file + BOOST_TEST(testS(S("dplqartnfgejichmoskb"), 21, 0)); +} + +// done +void +testStartsEnds() +{ + using S = fixed_string<400>; + BOOST_TEST(S("1234567890").starts_with('1')); + BOOST_TEST(S("1234567890").starts_with("123")); + BOOST_TEST(S("1234567890").starts_with("1234567890")); + BOOST_TEST(!S("1234567890").starts_with("234")); + BOOST_TEST(!S("1234567890").starts_with("12345678900")); + BOOST_TEST(S("1234567890").starts_with(string_view("1234567890"))); + + BOOST_TEST(S("1234567890").ends_with('0')); + BOOST_TEST(S("1234567890").ends_with("890")); + BOOST_TEST(S("1234567890").ends_with("1234567890")); + BOOST_TEST(!S("1234567890").ends_with("234")); + BOOST_TEST(!S("1234567890").ends_with("12345678900")); + BOOST_TEST(S("1234567890").ends_with(string_view("1234567890"))); +} + +int +runTests() +{ + testConstruct(); + + testAssignment(); + + testElements(); + + testIterators(); + + testCapacity(); + + testClear(); + testInsert(); + testErase(); + testPushBack(); + testPopBack(); + testAppend(); + testPlusEquals(); + + testCompare(); + testSwap(); + testGeneral(); + testToStaticString(); + + testFind(); + + testReplace(); + testSubstr(); + testStartsEnds(); + + return report_errors(); +} + +} // fixed_string +} // boost + +int +main() +{ + return boost::fixed_string::runTests(); +}