[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:
Brendan Emery authored and Louis Dionne committed 2023-09-01 13:35:18 -04:00
1 parent 823151f0cf
commit a40bada91a
417 files changed
+56733 -58199

No files matched your search

@@ -18,18 +18,16 @@
#include "min_allocator.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S& s, typename S::const_iterator p, typename S::value_type c, S expected)
{
bool sufficient_cap = s.size() < s.capacity();
typename S::difference_type pos = p - s.begin();
typename S::iterator i = s.insert(p, c);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
assert(i - s.begin() == pos);
assert(*i == c);
if (sufficient_cap)
assert(i == p);
TEST_CONSTEXPR_CXX20 void test(S& s, typename S::const_iterator p, typename S::value_type c, S expected) {
bool sufficient_cap = s.size() < s.capacity();
typename S::difference_type pos = p - s.begin();
typename S::iterator i = s.insert(p, c);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
assert(i - s.begin() == pos);
assert(*i == c);
if (sufficient_cap)
assert(i == p);
}
template <class S>
@@ -38,17 +36,17 @@ TEST_CONSTEXPR_CXX20 void test_string() {
test(s, s.begin(), '1', S("1"));
test(s, s.begin(), 'a', S("a1"));
test(s, s.end(), 'b', S("a1b"));
test(s, s.end()-1, 'c', S("a1cb"));
test(s, s.end()-2, 'd', S("a1dcb"));
test(s, s.end()-3, '2', S("a12dcb"));
test(s, s.end()-4, '3', S("a132dcb"));
test(s, s.end()-5, '4', S("a1432dcb"));
test(s, s.begin()+1, '5', S("a51432dcb"));
test(s, s.begin()+2, '6', S("a561432dcb"));
test(s, s.begin()+3, '7', S("a5671432dcb"));
test(s, s.begin()+4, 'A', S("a567A1432dcb"));
test(s, s.begin()+5, 'B', S("a567AB1432dcb"));
test(s, s.begin()+6, 'C', S("a567ABC1432dcb"));
test(s, s.end() - 1, 'c', S("a1cb"));
test(s, s.end() - 2, 'd', S("a1dcb"));
test(s, s.end() - 3, '2', S("a12dcb"));
test(s, s.end() - 4, '3', S("a132dcb"));
test(s, s.end() - 5, '4', S("a1432dcb"));
test(s, s.begin() + 1, '5', S("a51432dcb"));
test(s, s.begin() + 2, '6', S("a561432dcb"));
test(s, s.begin() + 3, '7', S("a5671432dcb"));
test(s, s.begin() + 4, 'A', S("a567A1432dcb"));
test(s, s.begin() + 5, 'B', S("a567AB1432dcb"));
test(s, s.begin() + 6, 'C', S("a567ABC1432dcb"));
}
TEST_CONSTEXPR_CXX20 bool test() {
@@ -60,8 +58,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());
@@ -12,7 +12,6 @@
// iterator insert(const_iterator p, initializer_list<charT> il); // constexpr since C++20
#include <string>
#include <cassert>
@@ -37,8 +36,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,90 +18,82 @@
#include "test_macros.h"
struct char_ascii {
char char_;
char char_;
char_ascii() = default;
char_ascii(char ch) : char_(ch) {
assert(ch <= 0x7f);
}
char_ascii() = default;
char_ascii(char ch) : char_(ch) { assert(ch <= 0x7f); }
};
template <>
struct std::char_traits<char_ascii> {
using char_type = char_ascii;
using int_type = typename std::char_traits<char>::int_type;
using off_type = typename std::char_traits<char>::off_type;
using pos_type = typename std::char_traits<char>::pos_type;
using state_type = typename std::char_traits<char>::state_type;
using char_type = char_ascii;
using int_type = typename std::char_traits<char>::int_type;
using off_type = typename std::char_traits<char>::off_type;
using pos_type = typename std::char_traits<char>::pos_type;
using state_type = typename std::char_traits<char>::state_type;
static void assign(char_type& r, char_type const& a) TEST_NOEXCEPT {
r = a;
static void assign(char_type& r, char_type const& a) TEST_NOEXCEPT { r = a; }
static char_type* assign(char_type* p, std::size_t count, char_type a) {
std::fill(p, p + count, a);
return p;
}
static bool eq(char_type a, char_type b) TEST_NOEXCEPT { return a.char_ == b.char_; }
static bool lt(char_type a, char_type b) TEST_NOEXCEPT { return a.char_ < b.char_; }
static std::size_t length(char_type const* s) {
std::size_t n = 0;
if (s) {
while (s->char_)
++n;
}
return n;
}
static char_type* assign(char_type* p, std::size_t count, char_type a) {
std::fill(p, p + count, a);
static const char_type* find(char_type const* p, std::size_t count, char_type const& ch) {
while (count > 0) {
if (p->char_ == ch.char_) {
return p;
} else {
++p;
--count;
}
}
return nullptr;
}
static bool eq(char_type a, char_type b) TEST_NOEXCEPT {
return a.char_ == b.char_;
static int compare(char_type const* s1, char_type const* s2, std::size_t count) {
for (std::size_t i = 0; i < count; ++i) {
if (s1->char_ < s2->char_)
return -1;
else if (s2->char_ < s1->char_)
return 1;
}
return 0;
}
static bool lt(char_type a, char_type b) TEST_NOEXCEPT {
return a.char_ < b.char_;
static char_type* move(char_type* dest, char_type const* src, std::size_t count) {
if (src <= dest && dest < src + count) {
std::copy_backward(src, src + count, dest + count);
} else {
std::copy(src, src + count, dest);
}
return dest;
}
static std::size_t length(char_type const* s) {
std::size_t n = 0;
if (s) {
while (s->char_)
++n;
}
return n;
}
static const char_type* find(char_type const* p, std::size_t count, char_type const& ch) {
while (count > 0) {
if (p->char_ == ch.char_) {
return p;
} else {
++p;
--count;
}
}
return nullptr;
}
static int compare(char_type const* s1, char_type const* s2, std::size_t count) {
for (std::size_t i = 0; i < count; ++i) {
if (s1->char_ < s2->char_)
return -1;
else if (s2->char_ < s1->char_)
return 1;
}
return 0;
}
static char_type* move(char_type* dest, char_type const* src, std::size_t count) {
if (src <= dest && dest < src + count) {
std::copy_backward(src, src + count, dest + count);
} else {
std::copy(src, src + count, dest);
}
return dest;
}
static char_type* copy(char_type* dest, char_type const* src, std::size_t count) {
return char_traits::move(dest, src, count);
}
static char_type* copy(char_type* dest, char_type const* src, std::size_t count) {
return char_traits::move(dest, src, count);
}
};
int main(int, char**) {
std::basic_string<char_ascii> str;
std::basic_string<char_ascii> str;
char_ascii ch('A');
str.insert(str.begin(), &ch, &ch + 1);
assert(str.size() == 1);
assert(str[0].char_ == 'A');
return 0;
char_ascii ch('A');
str.insert(str.begin(), &ch, &ch + 1);
assert(str.size() == 1);
assert(str[0].char_ == 'A');
return 0;
}
@@ -19,40 +19,39 @@
#include "min_allocator.h"
template <class S, class It>
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::difference_type pos, It first, It last, S expected)
{
typename S::const_iterator p = s.cbegin() + pos;
typename S::iterator i = s.insert(p, first, last);
LIBCPP_ASSERT(s.__invariants());
assert(i - s.begin() == pos);
assert(s == expected);
TEST_CONSTEXPR_CXX20 void test(S s, typename S::difference_type pos, It first, It last, S expected) {
typename S::const_iterator p = s.cbegin() + pos;
typename S::iterator i = s.insert(p, first, last);
LIBCPP_ASSERT(s.__invariants());
assert(i - s.begin() == pos);
assert(s == expected);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
struct Widget { operator char() const { throw 42; } };
struct Widget {
operator char() const { throw 42; }
};
template <class S, class It>
TEST_CONSTEXPR_CXX20 void
test_exceptions(S s, typename S::difference_type pos, It first, It last)
{
typename S::const_iterator p = s.cbegin() + pos;
TEST_CONSTEXPR_CXX20 void test_exceptions(S s, typename S::difference_type pos, It first, It last) {
typename S::const_iterator p = s.cbegin() + pos;
S original = s;
typename S::iterator begin = s.begin();
typename S::iterator end = s.end();
S original = s;
typename S::iterator begin = s.begin();
typename S::iterator end = s.end();
try {
s.insert(p, first, last);
assert(false);
} catch (...) {}
try {
s.insert(p, first, last);
assert(false);
} catch (...) {
}
// Part of "no effects" is that iterators and pointers
// into the string must not have been invalidated.
LIBCPP_ASSERT(s.__invariants());
assert(s == original);
assert(s.begin() == begin);
assert(s.end() == end);
// Part of "no effects" is that iterators and pointers
// into the string must not have been invalidated.
LIBCPP_ASSERT(s.__invariants());
assert(s == original);
assert(s.begin() == begin);
assert(s.end() == end);
}
#endif
@@ -60,46 +59,88 @@ template <class S>
TEST_CONSTEXPR_CXX20 void test_string() {
const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
test(S(), 0, s, s, S());
test(S(), 0, s, s+1, S("A"));
test(S(), 0, s, s+10, S("ABCDEFGHIJ"));
test(S(), 0, s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
test(S(), 0, s, s + 1, S("A"));
test(S(), 0, s, s + 10, S("ABCDEFGHIJ"));
test(S(), 0, s, s + 52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
test(S("12345"), 0, s, s, S("12345"));
test(S("12345"), 1, s, s+1, S("1A2345"));
test(S("12345"), 4, s, s+10, S("1234ABCDEFGHIJ5"));
test(S("12345"), 5, s, s+52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
test(S("12345"), 1, s, s + 1, S("1A2345"));
test(S("12345"), 4, s, s + 10, S("1234ABCDEFGHIJ5"));
test(S("12345"), 5, s, s + 52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
test(S("1234567890"), 0, s, s, S("1234567890"));
test(S("1234567890"), 1, s, s+1, S("1A234567890"));
test(S("1234567890"), 10, s, s+10, S("1234567890ABCDEFGHIJ"));
test(S("1234567890"), 8, s, s+52, S("12345678ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz90"));
test(S("1234567890"), 1, s, s + 1, S("1A234567890"));
test(S("1234567890"), 10, s, s + 10, S("1234567890ABCDEFGHIJ"));
test(S("1234567890"), 8, s, s + 52, S("12345678ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz90"));
test(S("12345678901234567890"), 3, s, s, S("12345678901234567890"));
test(S("12345678901234567890"), 3, s, s+1, S("123A45678901234567890"));
test(S("12345678901234567890"), 15, s, s+10, S("123456789012345ABCDEFGHIJ67890"));
test(S("12345678901234567890"), 20, s, s+52,
S("12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
test(S("12345678901234567890"), 3, s, s + 1, S("123A45678901234567890"));
test(S("12345678901234567890"), 15, s, s + 10, S("123456789012345ABCDEFGHIJ67890"));
test(S("12345678901234567890"),
20,
s,
s + 52,
S("12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S());
test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("A"));
test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("ABCDEFGHIJ"));
test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52), S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s + 1), S("A"));
test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s + 10), S("ABCDEFGHIJ"));
test(S(),
0,
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 52),
S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
test(S("12345"), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S("12345"));
test(S("12345"), 1, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("1A2345"));
test(S("12345"), 4, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("1234ABCDEFGHIJ5"));
test(S("12345"), 5, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52), S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
test(S("12345"), 1, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s + 1), S("1A2345"));
test(S("12345"),
4,
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 10),
S("1234ABCDEFGHIJ5"));
test(S("12345"),
5,
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 52),
S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
test(S("1234567890"), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S("1234567890"));
test(S("1234567890"), 1, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("1A234567890"));
test(S("1234567890"), 10, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("1234567890ABCDEFGHIJ"));
test(S("1234567890"), 8, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52), S("12345678ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz90"));
test(S("1234567890"),
1,
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 1),
S("1A234567890"));
test(S("1234567890"),
10,
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 10),
S("1234567890ABCDEFGHIJ"));
test(S("1234567890"),
8,
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 52),
S("12345678ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz90"));
test(S("12345678901234567890"), 3, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S("12345678901234567890"));
test(S("12345678901234567890"), 3, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("123A45678901234567890"));
test(S("12345678901234567890"), 15, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("123456789012345ABCDEFGHIJ67890"));
test(S("12345678901234567890"), 20, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
S("12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
test(S("12345678901234567890"),
3,
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s),
S("12345678901234567890"));
test(S("12345678901234567890"),
3,
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 1),
S("123A45678901234567890"));
test(S("12345678901234567890"),
15,
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 10),
S("123456789012345ABCDEFGHIJ67890"));
test(S("12345678901234567890"),
20,
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 52),
S("12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
}
TEST_CONSTEXPR_CXX20 bool test() {
@@ -114,16 +155,16 @@ TEST_CONSTEXPR_CXX20 bool test() {
typedef ThrowingIterator<char> TIter;
typedef cpp17_input_iterator<TIter> IIter;
const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
test_exceptions(S(), 0, IIter(TIter(s, s+10, 4, TIter::TAIncrement)), IIter(TIter()));
test_exceptions(S(), 0, IIter(TIter(s, s+10, 5, TIter::TADereference)), IIter(TIter()));
test_exceptions(S(), 0, IIter(TIter(s, s+10, 6, TIter::TAComparison)), IIter(TIter()));
test_exceptions(S(), 0, IIter(TIter(s, s + 10, 4, TIter::TAIncrement)), IIter(TIter()));
test_exceptions(S(), 0, IIter(TIter(s, s + 10, 5, TIter::TADereference)), IIter(TIter()));
test_exceptions(S(), 0, IIter(TIter(s, s + 10, 6, TIter::TAComparison)), IIter(TIter()));
test_exceptions(S(), 0, TIter(s, s+10, 4, TIter::TAIncrement), TIter());
test_exceptions(S(), 0, TIter(s, s+10, 5, TIter::TADereference), TIter());
test_exceptions(S(), 0, TIter(s, s+10, 6, TIter::TAComparison), TIter());
test_exceptions(S(), 0, TIter(s, s + 10, 4, TIter::TAIncrement), TIter());
test_exceptions(S(), 0, TIter(s, s + 10, 5, TIter::TADereference), TIter());
test_exceptions(S(), 0, TIter(s, s + 10, 6, TIter::TAComparison), TIter());
Widget w[100];
test_exceptions(S(), 0, w, w+100);
test_exceptions(S(), 0, w, w + 100);
}
#endif
@@ -153,14 +194,16 @@ TEST_CONSTEXPR_CXX20 bool test() {
}
if (!TEST_IS_CONSTANT_EVALUATED) { // regression-test inserting into self in sneaky ways
std::string s_short = "hello";
std::string s_long = "Lorem ipsum dolor sit amet, consectetur/";
std::string s_othertype = "hello";
const unsigned char *first = reinterpret_cast<const unsigned char*>(s_othertype.data());
std::string s_short = "hello";
std::string s_long = "Lorem ipsum dolor sit amet, consectetur/";
std::string s_othertype = "hello";
const unsigned char* first = reinterpret_cast<const unsigned char*>(s_othertype.data());
test(s_short, 0, s_short.data() + s_short.size(), s_short.data() + s_short.size() + 1,
std::string("\0hello", 6));
test(s_long, 0, s_long.data() + s_long.size(), s_long.data() + s_long.size() + 1,
test(s_short, 0, s_short.data() + s_short.size(), s_short.data() + s_short.size() + 1, std::string("\0hello", 6));
test(s_long,
0,
s_long.data() + s_long.size(),
s_long.data() + s_long.size() + 1,
std::string("\0Lorem ipsum dolor sit amet, consectetur/", 41));
test(s_othertype, 1, first + 2, first + 5, std::string("hlloello"));
}
@@ -192,8 +235,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,14 +18,12 @@
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::difference_type pos, typename S::size_type n,
typename S::value_type c, S expected)
{
typename S::const_iterator p = s.cbegin() + pos;
typename S::iterator i = s.insert(p, n, c);
LIBCPP_ASSERT(s.__invariants());
assert(i - s.begin() == pos);
assert(s == expected);
test(S s, typename S::difference_type pos, typename S::size_type n, typename S::value_type c, S expected) {
typename S::const_iterator p = s.cbegin() + pos;
typename S::iterator i = s.insert(p, n, c);
LIBCPP_ASSERT(s.__invariants());
assert(i - s.begin() == pos);
assert(s == expected);
}
template <class S>
@@ -105,8 +103,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());
@@ -19,31 +19,24 @@
#include "min_allocator.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos, const typename S::value_type* str, S expected)
{
const typename S::size_type old_size = s.size();
S s0 = s;
if (pos <= old_size)
{
s.insert(pos, str);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type pos, const typename S::value_type* str, S expected) {
const typename S::size_type old_size = s.size();
S s0 = s;
if (pos <= old_size) {
s.insert(pos, str);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED)
{
try
{
s.insert(pos, str);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > old_size);
assert(s == s0);
}
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
s.insert(pos, str);
assert(false);
} catch (std::out_of_range&) {
assert(pos > old_size);
assert(s == s0);
}
}
#endif
}
@@ -156,8 +149,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());
@@ -20,31 +20,24 @@
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos, const typename S::value_type* str,
typename S::size_type n, S expected)
{
const typename S::size_type old_size = s.size();
S s0 = s;
if (pos <= old_size)
{
s.insert(pos, str, n);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
test(S s, typename S::size_type pos, const typename S::value_type* str, typename S::size_type n, S expected) {
const typename S::size_type old_size = s.size();
S s0 = s;
if (pos <= old_size) {
s.insert(pos, str, n);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED)
{
try
{
s.insert(pos, str, n);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > old_size);
assert(s == s0);
}
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
s.insert(pos, str, n);
assert(false);
} catch (std::out_of_range&) {
assert(pos > old_size);
assert(s == s0);
}
}
#endif
}
@@ -391,8 +384,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}
int main(int, char**)
{
int main(int, char**) {
test<std::string>();
#if TEST_STD_VER >= 11
test<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
@@ -20,31 +20,24 @@
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos, typename S::size_type n,
typename S::value_type str, S expected)
{
const typename S::size_type old_size = s.size();
S s0 = s;
if (pos <= old_size)
{
s.insert(pos, n, str);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
test(S s, typename S::size_type pos, typename S::size_type n, typename S::value_type str, S expected) {
const typename S::size_type old_size = s.size();
S s0 = s;
if (pos <= old_size) {
s.insert(pos, n, str);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED)
{
try
{
s.insert(pos, n, str);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > old_size);
assert(s == s0);
}
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
s.insert(pos, n, str);
assert(false);
} catch (std::out_of_range&) {
assert(pos > old_size);
assert(s == s0);
}
}
#endif
}
@@ -141,8 +134,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());
@@ -19,31 +19,24 @@
#include "min_allocator.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos, S str, S expected)
{
const typename S::size_type old_size = s.size();
S s0 = s;
if (pos <= old_size)
{
s.insert(pos, str);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type pos, S str, S expected) {
const typename S::size_type old_size = s.size();
S s0 = s;
if (pos <= old_size) {
s.insert(pos, str);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED)
{
try
{
s.insert(pos, str);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > old_size);
assert(s == s0);
}
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
s.insert(pos, str);
assert(false);
} catch (std::out_of_range&) {
assert(pos > old_size);
assert(s == s0);
}
}
#endif
}
@@ -138,7 +131,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
#endif
#if TEST_STD_VER >= 11
{ // LWG 2946
{ // LWG 2946
std::string s;
s.insert(0, {"abc", 1});
assert(s.size() == 1);
@@ -149,8 +142,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());
@@ -19,31 +19,24 @@
#include "min_allocator.h"
template <class S, class SV>
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos, SV sv, S expected)
{
const typename S::size_type old_size = s.size();
S s0 = s;
if (pos <= old_size)
{
s.insert(pos, sv);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type pos, SV sv, S expected) {
const typename S::size_type old_size = s.size();
S s0 = s;
if (pos <= old_size) {
s.insert(pos, sv);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED)
{
try
{
s.insert(pos, sv);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > old_size);
assert(s == s0);
}
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
s.insert(pos, sv);
assert(false);
} catch (std::out_of_range&) {
assert(pos > old_size);
assert(s == s0);
}
}
#endif
}
@@ -157,8 +150,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());