forked from boostorg/static_string
Improve coverage
This commit is contained in:
@ -2412,8 +2412,7 @@ public:
|
||||
*/
|
||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||
void
|
||||
resize(
|
||||
size_type n);
|
||||
resize(size_type n);
|
||||
|
||||
/** Change the size of the string.
|
||||
|
||||
@ -5123,9 +5122,9 @@ void
|
||||
basic_static_string<N, CharT, Traits>::
|
||||
resize(size_type n)
|
||||
{
|
||||
const auto curr_size = size();
|
||||
BOOST_STATIC_STRING_THROW_IF(
|
||||
n > max_size(), std::length_error{"n > max_size()"});
|
||||
const auto curr_size = size();
|
||||
if(n > curr_size)
|
||||
traits_type::assign(&data()[curr_size], n - curr_size, value_type());
|
||||
this->set_size(n);
|
||||
@ -5138,9 +5137,9 @@ void
|
||||
basic_static_string<N, CharT, Traits>::
|
||||
resize(size_type n, value_type c)
|
||||
{
|
||||
const auto curr_size = size();
|
||||
BOOST_STATIC_STRING_THROW_IF(
|
||||
n > max_size(), std::length_error{"n > max_size()"});
|
||||
const auto curr_size = size();
|
||||
if(n > curr_size)
|
||||
traits_type::assign(&data()[curr_size], n - curr_size, c);
|
||||
this->set_size(n);
|
||||
|
@ -6903,7 +6903,8 @@ testStartsEnds()
|
||||
BOOST_TEST(S("1234567890").ends_with(string_view("1234567890")));
|
||||
}
|
||||
|
||||
void testHash()
|
||||
void
|
||||
testHash()
|
||||
{
|
||||
using U = static_string<30>;
|
||||
std::hash<U> hasher;
|
||||
@ -6911,15 +6912,28 @@ void testHash()
|
||||
BOOST_TEST(hasher(U("1234567890")) == hasher(U("1234567890")));
|
||||
}
|
||||
|
||||
void testEmpty()
|
||||
void
|
||||
testEmpty()
|
||||
{
|
||||
using E = static_string<0>;
|
||||
E a;
|
||||
static_string<0> a;
|
||||
BOOST_TEST(a.size() == 0);
|
||||
BOOST_TEST(a.data());
|
||||
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
|
||||
runTests()
|
||||
{
|
||||
@ -6947,6 +6961,7 @@ runTests()
|
||||
testSwap();
|
||||
testGeneral();
|
||||
testToStaticString();
|
||||
testResize();
|
||||
|
||||
testFind();
|
||||
|
||||
@ -6959,17 +6974,6 @@ runTests()
|
||||
|
||||
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
|
||||
} // boost
|
||||
|
||||
|
Reference in New Issue
Block a user