mirror of
https://github.com/boostorg/static_string.git
synced 2025-07-28 11:37:36 +02:00
Improve coverage
This commit is contained in:
@ -2412,8 +2412,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||||
void
|
void
|
||||||
resize(
|
resize(size_type n);
|
||||||
size_type n);
|
|
||||||
|
|
||||||
/** Change the size of the string.
|
/** Change the size of the string.
|
||||||
|
|
||||||
@ -5123,9 +5122,9 @@ void
|
|||||||
basic_static_string<N, CharT, Traits>::
|
basic_static_string<N, CharT, Traits>::
|
||||||
resize(size_type n)
|
resize(size_type n)
|
||||||
{
|
{
|
||||||
const auto curr_size = size();
|
|
||||||
BOOST_STATIC_STRING_THROW_IF(
|
BOOST_STATIC_STRING_THROW_IF(
|
||||||
n > max_size(), std::length_error{"n > max_size()"});
|
n > max_size(), std::length_error{"n > max_size()"});
|
||||||
|
const auto curr_size = size();
|
||||||
if(n > curr_size)
|
if(n > curr_size)
|
||||||
traits_type::assign(&data()[curr_size], n - curr_size, value_type());
|
traits_type::assign(&data()[curr_size], n - curr_size, value_type());
|
||||||
this->set_size(n);
|
this->set_size(n);
|
||||||
@ -5138,9 +5137,9 @@ void
|
|||||||
basic_static_string<N, CharT, Traits>::
|
basic_static_string<N, CharT, Traits>::
|
||||||
resize(size_type n, value_type c)
|
resize(size_type n, value_type c)
|
||||||
{
|
{
|
||||||
const auto curr_size = size();
|
|
||||||
BOOST_STATIC_STRING_THROW_IF(
|
BOOST_STATIC_STRING_THROW_IF(
|
||||||
n > max_size(), std::length_error{"n > max_size()"});
|
n > max_size(), std::length_error{"n > max_size()"});
|
||||||
|
const auto curr_size = size();
|
||||||
if(n > curr_size)
|
if(n > curr_size)
|
||||||
traits_type::assign(&data()[curr_size], n - curr_size, c);
|
traits_type::assign(&data()[curr_size], n - curr_size, c);
|
||||||
this->set_size(n);
|
this->set_size(n);
|
||||||
|
@ -6903,7 +6903,8 @@ testStartsEnds()
|
|||||||
BOOST_TEST(S("1234567890").ends_with(string_view("1234567890")));
|
BOOST_TEST(S("1234567890").ends_with(string_view("1234567890")));
|
||||||
}
|
}
|
||||||
|
|
||||||
void testHash()
|
void
|
||||||
|
testHash()
|
||||||
{
|
{
|
||||||
using U = static_string<30>;
|
using U = static_string<30>;
|
||||||
std::hash<U> hasher;
|
std::hash<U> hasher;
|
||||||
@ -6911,15 +6912,28 @@ void testHash()
|
|||||||
BOOST_TEST(hasher(U("1234567890")) == hasher(U("1234567890")));
|
BOOST_TEST(hasher(U("1234567890")) == hasher(U("1234567890")));
|
||||||
}
|
}
|
||||||
|
|
||||||
void testEmpty()
|
void
|
||||||
|
testEmpty()
|
||||||
{
|
{
|
||||||
using E = static_string<0>;
|
static_string<0> a;
|
||||||
E a;
|
|
||||||
BOOST_TEST(a.size() == 0);
|
BOOST_TEST(a.size() == 0);
|
||||||
BOOST_TEST(a.data());
|
BOOST_TEST(a.data());
|
||||||
BOOST_TEST(!a.capacity());
|
BOOST_TEST(!a.capacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
testResize()
|
||||||
|
{
|
||||||
|
static_string<10> a = "a";
|
||||||
|
a.resize(a.size() + 1);
|
||||||
|
BOOST_TEST(a.size() == 2);
|
||||||
|
|
||||||
|
static_string<10> b = "a";
|
||||||
|
b.resize(b.size() + 1, 'a');
|
||||||
|
BOOST_TEST(b == "aa");
|
||||||
|
BOOST_TEST(b.size() == 2);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
runTests()
|
runTests()
|
||||||
{
|
{
|
||||||
@ -6947,6 +6961,7 @@ runTests()
|
|||||||
testSwap();
|
testSwap();
|
||||||
testGeneral();
|
testGeneral();
|
||||||
testToStaticString();
|
testToStaticString();
|
||||||
|
testResize();
|
||||||
|
|
||||||
testFind();
|
testFind();
|
||||||
|
|
||||||
@ -6959,17 +6974,6 @@ runTests()
|
|||||||
|
|
||||||
return report_errors();
|
return report_errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
static_assert(std::is_base_of<
|
|
||||||
detail::static_string_base<0, char, std::char_traits<char>>,
|
|
||||||
static_string<0>>::value,
|
|
||||||
"the zero size optimization shall be used for N = 0");
|
|
||||||
|
|
||||||
static_assert(std::is_base_of<
|
|
||||||
detail::static_string_base<(std::numeric_limits<char>::max)() + 1, char, std::char_traits<char>>,
|
|
||||||
static_string<(std::numeric_limits<char>::max)() + 1>>::value,
|
|
||||||
"the minimum size type optimization shall be used for N > 0");
|
|
||||||
|
|
||||||
} // static_string
|
} // static_string
|
||||||
} // boost
|
} // boost
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user