[libc++] Apply clang formatting to all string unit tests
This applies clang-format to the std::string unit tests in preparation for landing https://reviews.llvm.org/D140550. Differential Revision: https://reviews.llvm.org/D140612
This commit is contained in:
committed by
Louis Dionne
parent
823151f0cf
commit
a40bada91a
@@ -19,25 +19,22 @@
|
||||
#include "test_macros.h"
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(S s, test_allocator_statistics& alloc_stats)
|
||||
{
|
||||
alloc_stats.throw_after = 0;
|
||||
TEST_CONSTEXPR_CXX20 void test(S s, test_allocator_statistics& alloc_stats) {
|
||||
alloc_stats.throw_after = 0;
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
try
|
||||
try
|
||||
#endif
|
||||
{
|
||||
while (s.size() < s.capacity())
|
||||
s.push_back(typename S::value_type());
|
||||
assert(s.size() == s.capacity());
|
||||
}
|
||||
{
|
||||
while (s.size() < s.capacity())
|
||||
s.push_back(typename S::value_type());
|
||||
assert(s.size() == s.capacity());
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
catch (...)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
catch (...) {
|
||||
assert(false);
|
||||
}
|
||||
#endif
|
||||
alloc_stats.throw_after = INT_MAX;
|
||||
alloc_stats.throw_after = INT_MAX;
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
@@ -64,8 +61,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
int main(int, char**) {
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
|
||||
@@ -17,11 +17,9 @@
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(S s)
|
||||
{
|
||||
s.clear();
|
||||
assert(s.size() == 0);
|
||||
TEST_CONSTEXPR_CXX20 void test(S s) {
|
||||
s.clear();
|
||||
assert(s.size() == 0);
|
||||
}
|
||||
|
||||
template <class S>
|
||||
@@ -47,8 +45,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
int main(int, char**) {
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
|
||||
@@ -17,11 +17,9 @@
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(const S& s)
|
||||
{
|
||||
ASSERT_NOEXCEPT(s.empty());
|
||||
assert(s.empty() == (s.size() == 0));
|
||||
TEST_CONSTEXPR_CXX20 void test(const S& s) {
|
||||
ASSERT_NOEXCEPT(s.empty());
|
||||
assert(s.empty() == (s.size() == 0));
|
||||
}
|
||||
|
||||
template <class S>
|
||||
@@ -40,8 +38,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
int main(int, char**) {
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
|
||||
@@ -17,10 +17,8 @@
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(const S& s)
|
||||
{
|
||||
assert(s.length() == s.size());
|
||||
TEST_CONSTEXPR_CXX20 void test(const S& s) {
|
||||
assert(s.length() == s.size());
|
||||
}
|
||||
|
||||
template <class S>
|
||||
@@ -39,8 +37,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
int main(int, char**) {
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
|
||||
@@ -26,34 +26,34 @@
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test1(const S& s)
|
||||
{
|
||||
S s2(s);
|
||||
const std::size_t sz = s2.max_size() - 1;
|
||||
try { s2.resize(sz, 'x'); }
|
||||
catch ( const std::bad_alloc & ) { return ; }
|
||||
assert ( s2.size() == sz );
|
||||
TEST_CONSTEXPR_CXX20 void test1(const S& s) {
|
||||
S s2(s);
|
||||
const std::size_t sz = s2.max_size() - 1;
|
||||
try {
|
||||
s2.resize(sz, 'x');
|
||||
} catch (const std::bad_alloc&) {
|
||||
return;
|
||||
}
|
||||
assert(s2.size() == sz);
|
||||
}
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test2(const S& s)
|
||||
{
|
||||
S s2(s);
|
||||
const std::size_t sz = s2.max_size();
|
||||
try { s2.resize(sz, 'x'); }
|
||||
catch ( const std::bad_alloc & ) { return ; }
|
||||
assert ( s.size() == sz );
|
||||
TEST_CONSTEXPR_CXX20 void test2(const S& s) {
|
||||
S s2(s);
|
||||
const std::size_t sz = s2.max_size();
|
||||
try {
|
||||
s2.resize(sz, 'x');
|
||||
} catch (const std::bad_alloc&) {
|
||||
return;
|
||||
}
|
||||
assert(s.size() == sz);
|
||||
}
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(const S& s)
|
||||
{
|
||||
assert(s.max_size() >= s.size());
|
||||
test1(s);
|
||||
test2(s);
|
||||
TEST_CONSTEXPR_CXX20 void test(const S& s) {
|
||||
assert(s.max_size() >= s.size());
|
||||
test1(s);
|
||||
test2(s);
|
||||
}
|
||||
|
||||
template <class S>
|
||||
@@ -83,8 +83,7 @@ constexpr bool test_constexpr() {
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
int main(int, char**) {
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
test_constexpr();
|
||||
|
||||
@@ -26,15 +26,16 @@
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const S& s)
|
||||
{
|
||||
assert(s.max_size() >= s.size());
|
||||
S s2(s);
|
||||
const std::size_t sz = s2.max_size() + 1;
|
||||
try { s2.resize(sz, 'x'); }
|
||||
catch ( const std::length_error & ) { return ; }
|
||||
assert ( false );
|
||||
void test(const S& s) {
|
||||
assert(s.max_size() >= s.size());
|
||||
S s2(s);
|
||||
const std::size_t sz = s2.max_size() + 1;
|
||||
try {
|
||||
s2.resize(sz, 'x');
|
||||
} catch (const std::length_error&) {
|
||||
return;
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
|
||||
template <class S>
|
||||
@@ -53,8 +54,7 @@ bool test() {
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
int main(int, char**) {
|
||||
test();
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -15,6 +15,6 @@
|
||||
#include <string>
|
||||
|
||||
void f() {
|
||||
std::string s;
|
||||
s.reserve(); // expected-warning {{'reserve' is deprecated}}
|
||||
std::string s;
|
||||
s.reserve(); // expected-warning {{'reserve' is deprecated}}
|
||||
}
|
||||
|
||||
@@ -20,21 +20,19 @@
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(typename S::size_type min_cap, typename S::size_type erased_index)
|
||||
{
|
||||
S s(min_cap, 'a');
|
||||
s.erase(erased_index);
|
||||
assert(s.size() == erased_index);
|
||||
assert(s.capacity() >= min_cap); // Check that we really have at least this capacity.
|
||||
void test(typename S::size_type min_cap, typename S::size_type erased_index) {
|
||||
S s(min_cap, 'a');
|
||||
s.erase(erased_index);
|
||||
assert(s.size() == erased_index);
|
||||
assert(s.capacity() >= min_cap); // Check that we really have at least this capacity.
|
||||
|
||||
typename S::size_type old_cap = s.capacity();
|
||||
S s0 = s;
|
||||
s.reserve();
|
||||
LIBCPP_ASSERT(s.__invariants());
|
||||
assert(s == s0);
|
||||
assert(s.capacity() <= old_cap);
|
||||
assert(s.capacity() >= s.size());
|
||||
typename S::size_type old_cap = s.capacity();
|
||||
S s0 = s;
|
||||
s.reserve();
|
||||
LIBCPP_ASSERT(s.__invariants());
|
||||
assert(s == s0);
|
||||
assert(s.capacity() <= old_cap);
|
||||
assert(s.capacity() >= s.size());
|
||||
}
|
||||
|
||||
template <class S>
|
||||
@@ -53,8 +51,7 @@ bool test() {
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
int main(int, char**) {
|
||||
test();
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -23,42 +23,36 @@
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(typename S::size_type min_cap, typename S::size_type erased_index, typename S::size_type res_arg)
|
||||
{
|
||||
S s(min_cap, 'a');
|
||||
s.erase(erased_index);
|
||||
assert(s.size() == erased_index);
|
||||
assert(s.capacity() >= min_cap); // Check that we really have at least this capacity.
|
||||
test(typename S::size_type min_cap, typename S::size_type erased_index, typename S::size_type res_arg) {
|
||||
S s(min_cap, 'a');
|
||||
s.erase(erased_index);
|
||||
assert(s.size() == erased_index);
|
||||
assert(s.capacity() >= min_cap); // Check that we really have at least this capacity.
|
||||
|
||||
#if TEST_STD_VER > 17
|
||||
typename S::size_type old_cap = s.capacity();
|
||||
typename S::size_type old_cap = s.capacity();
|
||||
#endif
|
||||
S s0 = s;
|
||||
if (res_arg <= s.max_size())
|
||||
{
|
||||
s.reserve(res_arg);
|
||||
LIBCPP_ASSERT(s.__invariants());
|
||||
assert(s == s0);
|
||||
assert(s.capacity() >= res_arg);
|
||||
assert(s.capacity() >= s.size());
|
||||
S s0 = s;
|
||||
if (res_arg <= s.max_size()) {
|
||||
s.reserve(res_arg);
|
||||
LIBCPP_ASSERT(s.__invariants());
|
||||
assert(s == s0);
|
||||
assert(s.capacity() >= res_arg);
|
||||
assert(s.capacity() >= s.size());
|
||||
#if TEST_STD_VER > 17
|
||||
assert(s.capacity() >= old_cap); // reserve never shrinks as of P0966 (C++20)
|
||||
assert(s.capacity() >= old_cap); // reserve never shrinks as of P0966 (C++20)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else if (!TEST_IS_CONSTANT_EVALUATED)
|
||||
{
|
||||
try
|
||||
{
|
||||
s.reserve(res_arg);
|
||||
LIBCPP_ASSERT(s.__invariants());
|
||||
assert(false);
|
||||
}
|
||||
catch (std::length_error&)
|
||||
{
|
||||
assert(res_arg > s.max_size());
|
||||
}
|
||||
else if (!TEST_IS_CONSTANT_EVALUATED) {
|
||||
try {
|
||||
s.reserve(res_arg);
|
||||
LIBCPP_ASSERT(s.__invariants());
|
||||
assert(false);
|
||||
} catch (std::length_error&) {
|
||||
assert(res_arg > s.max_size());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -88,8 +82,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
int main(int, char**) {
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
|
||||
@@ -49,7 +49,7 @@ constexpr void test_truncating(std::size_t o, size_t N) {
|
||||
LIBCPP_ASSERT(s.begin().base() == p);
|
||||
assert(std::all_of(p, p + n, [](auto ch) { return ch == 'a'; }));
|
||||
p[n - 1] = 'b';
|
||||
p[n] = 'c'; // will be overwritten
|
||||
p[n] = 'c'; // will be overwritten
|
||||
return n;
|
||||
});
|
||||
const S expected = S(N - 1, 'a') + S(1, 'b');
|
||||
|
||||
@@ -18,28 +18,21 @@
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(S s, typename S::size_type n, S expected)
|
||||
{
|
||||
if (n <= s.max_size())
|
||||
{
|
||||
s.resize(n);
|
||||
LIBCPP_ASSERT(s.__invariants());
|
||||
assert(s == expected);
|
||||
}
|
||||
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type n, S expected) {
|
||||
if (n <= s.max_size()) {
|
||||
s.resize(n);
|
||||
LIBCPP_ASSERT(s.__invariants());
|
||||
assert(s == expected);
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else if (!TEST_IS_CONSTANT_EVALUATED)
|
||||
{
|
||||
try
|
||||
{
|
||||
s.resize(n);
|
||||
assert(false);
|
||||
}
|
||||
catch (std::length_error&)
|
||||
{
|
||||
assert(n > s.max_size());
|
||||
}
|
||||
else if (!TEST_IS_CONSTANT_EVALUATED) {
|
||||
try {
|
||||
s.resize(n);
|
||||
assert(false);
|
||||
} catch (std::length_error&) {
|
||||
assert(n > s.max_size());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -54,12 +47,13 @@ TEST_CONSTEXPR_CXX20 void test_string() {
|
||||
test(S("12345"), 5, S("12345"));
|
||||
test(S("12345"), 15, S("12345\0\0\0\0\0\0\0\0\0\0", 15));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 0, S());
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 10,
|
||||
S("1234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 50,
|
||||
S("12345678901234567890123456789012345678901234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 60,
|
||||
S("12345678901234567890123456789012345678901234567890\0\0\0\0\0\0\0\0\0\0", 60));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 10, S("1234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"),
|
||||
50,
|
||||
S("12345678901234567890123456789012345678901234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"),
|
||||
60,
|
||||
S("12345678901234567890123456789012345678901234567890\0\0\0\0\0\0\0\0\0\0", 60));
|
||||
test(S(), S::npos, S("not going to happen"));
|
||||
}
|
||||
|
||||
@@ -72,8 +66,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
int main(int, char**) {
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
|
||||
@@ -18,28 +18,21 @@
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(S s, typename S::size_type n, typename S::value_type c, S expected)
|
||||
{
|
||||
if (n <= s.max_size())
|
||||
{
|
||||
s.resize(n, c);
|
||||
LIBCPP_ASSERT(s.__invariants());
|
||||
assert(s == expected);
|
||||
}
|
||||
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type n, typename S::value_type c, S expected) {
|
||||
if (n <= s.max_size()) {
|
||||
s.resize(n, c);
|
||||
LIBCPP_ASSERT(s.__invariants());
|
||||
assert(s == expected);
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else if (!TEST_IS_CONSTANT_EVALUATED)
|
||||
{
|
||||
try
|
||||
{
|
||||
s.resize(n, c);
|
||||
assert(false);
|
||||
}
|
||||
catch (std::length_error&)
|
||||
{
|
||||
assert(n > s.max_size());
|
||||
}
|
||||
else if (!TEST_IS_CONSTANT_EVALUATED) {
|
||||
try {
|
||||
s.resize(n, c);
|
||||
assert(false);
|
||||
} catch (std::length_error&) {
|
||||
assert(n > s.max_size());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -54,12 +47,15 @@ TEST_CONSTEXPR_CXX20 void test_string() {
|
||||
test(S("12345"), 5, 'a', S("12345"));
|
||||
test(S("12345"), 15, 'a', S("12345aaaaaaaaaa"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 0, 'a', S());
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 10, 'a',
|
||||
S("1234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 50, 'a',
|
||||
S("12345678901234567890123456789012345678901234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 60, 'a',
|
||||
S("12345678901234567890123456789012345678901234567890aaaaaaaaaa"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 10, 'a', S("1234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"),
|
||||
50,
|
||||
'a',
|
||||
S("12345678901234567890123456789012345678901234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"),
|
||||
60,
|
||||
'a',
|
||||
S("12345678901234567890123456789012345678901234567890aaaaaaaaaa"));
|
||||
test(S(), S::npos, 'a', S("not going to happen"));
|
||||
}
|
||||
|
||||
@@ -72,8 +68,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
int main(int, char**) {
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
|
||||
@@ -31,7 +31,7 @@ struct string16_char_traits {
|
||||
typedef std::mbstate_t state_type;
|
||||
typedef std::fpos<state_type> pos_type;
|
||||
|
||||
static void assign(char_type&, const char_type&) { }
|
||||
static void assign(char_type&, const char_type&) {}
|
||||
static bool eq(const char_type&, const char_type&) { return false; }
|
||||
static bool lt(const char_type&, const char_type&) { return false; }
|
||||
static int compare(const char_type*, const char_type*, std::size_t) { return 0; }
|
||||
@@ -53,7 +53,7 @@ template class std::basic_string<char16, string16_char_traits>;
|
||||
extern template class std::basic_string<char16, string16_char_traits>;
|
||||
|
||||
int main(int, char**) {
|
||||
std::basic_string<char16, string16_char_traits> s;
|
||||
s.shrink_to_fit();
|
||||
std::basic_string<char16, string16_char_traits> s;
|
||||
s.shrink_to_fit();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -17,16 +17,14 @@
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(S s)
|
||||
{
|
||||
typename S::size_type old_cap = s.capacity();
|
||||
S s0 = s;
|
||||
s.shrink_to_fit();
|
||||
LIBCPP_ASSERT(s.__invariants());
|
||||
assert(s == s0);
|
||||
assert(s.capacity() <= old_cap);
|
||||
assert(s.capacity() >= s.size());
|
||||
TEST_CONSTEXPR_CXX20 void test(S s) {
|
||||
typename S::size_type old_cap = s.capacity();
|
||||
S s0 = s;
|
||||
s.shrink_to_fit();
|
||||
LIBCPP_ASSERT(s.__invariants());
|
||||
assert(s == s0);
|
||||
assert(s.capacity() <= old_cap);
|
||||
assert(s.capacity() >= s.size());
|
||||
}
|
||||
|
||||
template <class S>
|
||||
@@ -52,8 +50,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
int main(int, char**) {
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
|
||||
@@ -17,10 +17,8 @@
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(const S& s, typename S::size_type c)
|
||||
{
|
||||
assert(s.size() == c);
|
||||
TEST_CONSTEXPR_CXX20 void test(const S& s, typename S::size_type c) {
|
||||
assert(s.size() == c);
|
||||
}
|
||||
|
||||
template <class S>
|
||||
@@ -39,8 +37,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
int main(int, char**) {
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
|
||||
Reference in New Issue
Block a user