[libc++] Prepare string.{access, capacity, cons} tests for constexpr

Reviewed By: ldionne, #libc

Spies: libcxx-commits, arphaman

Differential Revision: https://reviews.llvm.org/D119123
This commit is contained in:
Nikolas Klauser
2022-02-07 21:54:49 +01:00
parent ca9f0ec1a3
commit e85018b7dd
42 changed files with 734 additions and 361 deletions

View File

@@ -21,7 +21,7 @@
test_allocator_statistics alloc_stats;
template <class S>
void
TEST_CONSTEXPR_CXX20 void
test(S s)
{
alloc_stats.throw_after = 0;
@@ -42,9 +42,8 @@ test(S s)
alloc_stats.throw_after = INT_MAX;
}
int main(int, char**)
{
{
bool test() {
{
typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > S;
S s((test_allocator<char>(&alloc_stats)));
test(s);
@@ -54,13 +53,23 @@ int main(int, char**)
s.assign(100, 'a');
s.erase(50);
test(s);
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
S s;
assert(s.capacity() > 0);
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;

View File

@@ -17,16 +17,15 @@
#include "min_allocator.h"
template <class S>
void
TEST_CONSTEXPR_CXX20 void
test(S s)
{
s.clear();
assert(s.size() == 0);
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
S s;
test(s);
@@ -38,9 +37,9 @@ int main(int, char**)
s.assign(100, 'a');
s.erase(50);
test(s);
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
S s;
test(s);
@@ -52,7 +51,17 @@ int main(int, char**)
s.assign(100, 'a');
s.erase(50);
test(s);
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;

View File

@@ -17,28 +17,37 @@
#include "min_allocator.h"
template <class S>
void
TEST_CONSTEXPR_CXX20 void
test(const S& s)
{
ASSERT_NOEXCEPT(s.empty());
assert(s.empty() == (s.size() == 0));
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test(S());
test(S("123"));
test(S("12345678901234567890123456789012345678901234567890"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S());
test(S("123"));
test(S("12345678901234567890123456789012345678901234567890"));
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;

View File

@@ -18,10 +18,19 @@
#include "test_macros.h"
bool test() {
std::string c;
c.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
return true;
}
int main(int, char**)
{
std::string c;
c.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
return 0;
}

View File

@@ -23,21 +23,30 @@ test(const S& s)
assert(s.length() == s.size());
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test(S());
test(S("123"));
test(S("12345678901234567890123456789012345678901234567890"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S());
test(S("123"));
test(S("12345678901234567890123456789012345678901234567890"));
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;

View File

@@ -55,21 +55,30 @@ test(const S& s)
test2(s);
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test(S());
test(S("123"));
test(S("12345678901234567890123456789012345678901234567890"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S());
test(S("123"));
test(S("12345678901234567890123456789012345678901234567890"));
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;

View File

@@ -32,21 +32,30 @@ test(const S& s)
assert ( false );
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test(S());
test(S("123"));
test(S("12345678901234567890123456789012345678901234567890"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S());
test(S("123"));
test(S("12345678901234567890123456789012345678901234567890"));
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;

View File

@@ -20,7 +20,7 @@
#include "min_allocator.h"
template <class S>
void
TEST_CONSTEXPR_CXX20 void
test(typename S::size_type min_cap, typename S::size_type erased_index)
{
S s(min_cap, 'a');
@@ -37,8 +37,7 @@ test(typename S::size_type min_cap, typename S::size_type erased_index)
assert(s.capacity() >= s.size());
}
int main(int, char**)
{
bool test() {
{
typedef std::string S;
{
@@ -58,5 +57,15 @@ int main(int, char**)
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
}

View File

@@ -63,41 +63,50 @@ test(typename S::size_type min_cap, typename S::size_type erased_index, typename
#endif
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
{
test<S>(0, 0, 5);
test<S>(0, 0, 10);
test<S>(0, 0, 50);
test<S>(0, 0, 5);
test<S>(0, 0, 10);
test<S>(0, 0, 50);
}
{
test<S>(100, 50, 5);
test<S>(100, 50, 10);
test<S>(100, 50, 50);
test<S>(100, 50, 100);
test<S>(100, 50, 1000);
test<S>(100, 50, S::npos);
}
test<S>(100, 50, 5);
test<S>(100, 50, 10);
test<S>(100, 50, 50);
test<S>(100, 50, 100);
test<S>(100, 50, 1000);
test<S>(100, 50, S::npos);
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
{
test<S>(0, 0, 5);
test<S>(0, 0, 10);
test<S>(0, 0, 50);
test<S>(0, 0, 5);
test<S>(0, 0, 10);
test<S>(0, 0, 50);
}
{
test<S>(100, 50, 5);
test<S>(100, 50, 10);
test<S>(100, 50, 50);
test<S>(100, 50, 100);
test<S>(100, 50, 1000);
test<S>(100, 50, S::npos);
}
test<S>(100, 50, 5);
test<S>(100, 50, 10);
test<S>(100, 50, 50);
test<S>(100, 50, 100);
test<S>(100, 50, 1000);
test<S>(100, 50, S::npos);
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;

View File

@@ -18,7 +18,7 @@
#include "min_allocator.h"
template <class S>
void
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type n, S expected)
{
if (n <= s.max_size())
@@ -43,9 +43,8 @@ test(S s, typename S::size_type n, S expected)
#endif
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test(S(), 0, S());
test(S(), 1, S(1, '\0'));
@@ -63,9 +62,9 @@ int main(int, char**)
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"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S(), 0, S());
test(S(), 1, S(1, '\0'));
@@ -83,7 +82,17 @@ int main(int, char**)
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"));
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;

View File

@@ -43,9 +43,8 @@ test(S s, typename S::size_type n, typename S::value_type c, S expected)
#endif
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test(S(), 0, 'a', S());
test(S(), 1, 'a', S("a"));
@@ -63,9 +62,9 @@ int main(int, char**)
test(S("12345678901234567890123456789012345678901234567890"), 60, 'a',
S("12345678901234567890123456789012345678901234567890aaaaaaaaaa"));
test(S(), S::npos, 'a', S("not going to happen"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S(), 0, 'a', S());
test(S(), 1, 'a', S("a"));
@@ -83,7 +82,17 @@ int main(int, char**)
test(S("12345678901234567890123456789012345678901234567890"), 60, 'a',
S("12345678901234567890123456789012345678901234567890aaaaaaaaaa"));
test(S(), S::npos, 'a', S("not going to happen"));
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;

View File

@@ -29,8 +29,7 @@ test(S s)
assert(s.capacity() >= s.size());
}
int main(int, char**)
{
bool test() {
{
typedef std::string S;
S s;
@@ -60,5 +59,15 @@ int main(int, char**)
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
}

View File

@@ -17,27 +17,36 @@
#include "min_allocator.h"
template <class S>
void
TEST_CONSTEXPR_CXX20 void
test(const S& s, typename S::size_type c)
{
assert(s.size() == c);
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test(S(), 0);
test(S("123"), 3);
test(S("12345678901234567890123456789012345678901234567890"), 50);
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S(), 0);
test(S("123"), 3);
test(S("12345678901234567890123456789012345678901234567890"), 50);
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;