[libc++] Prepare string.{contains, ends_with, iterators, require, starts_with} tests for constexpr

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D119304
This commit is contained in:
Nikolas Klauser 2022-02-09 02:03:27 +01:00
parent f97795121f
commit c515b652a0
18 changed files with 231 additions and 92 deletions

View File

@ -35,7 +35,10 @@ void test()
int main(int, char**)
{
test();
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -65,7 +65,10 @@ void test()
int main(int, char**)
{
test();
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -86,7 +86,10 @@ void test()
int main(int, char**)
{
test();
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -16,9 +16,8 @@
#include "test_macros.h"
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
S s1 {};
S s2 { "abcde", 5 };
@ -29,7 +28,17 @@ int main(int, char**)
assert (!s1.ends_with('x'));
assert ( s2.ends_with('e'));
assert (!s2.ends_with('x'));
}
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
}

View File

@ -16,9 +16,8 @@
#include "test_macros.h"
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
const char *s = "abcde";
@ -58,7 +57,16 @@ int main(int, char**)
assert (!sNot.ends_with("bcde"));
assert (!sNot.ends_with("abcde"));
assert ( sNot.ends_with("def"));
}
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
}

View File

@ -16,9 +16,8 @@
#include "test_macros.h"
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
typedef std::string_view SV;
const char *s = "abcde";
@ -67,7 +66,16 @@ int main(int, char**)
assert (!sNot.ends_with(sv4));
assert (!sNot.ends_with(sv5));
assert ( sNot.ends_with(svNot));
}
}
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)
{
const S& cs = s;
@ -31,19 +31,28 @@ test(S s)
assert(b == cb);
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test(S());
test(S("123"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S());
test(S("123"));
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;

View File

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

View File

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

View File

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

View File

@ -17,26 +17,35 @@
#include "min_allocator.h"
template <class S>
void
TEST_CONSTEXPR_CXX20 void
test(const S& s)
{
typename S::const_reverse_iterator ce = s.crend();
assert(ce == s.rend());
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test(S());
test(S("123"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S());
test(S("123"));
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;

View File

@ -19,7 +19,7 @@
#include "min_allocator.h"
template <class S>
void
TEST_CONSTEXPR_CXX20 void
test(S s)
{
const S& cs = s;
@ -34,19 +34,28 @@ test(S s)
assert(static_cast<std::size_t>(ce - cs.begin()) == cs.size());
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test(S());
test(S("123"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S());
test(S("123"));
}
}
#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)
{
const S& cs = s;
@ -31,19 +31,28 @@ test(S s)
assert(b == cb);
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test(S());
test(S("123"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S());
test(S("123"));
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;

View File

@ -34,19 +34,28 @@ test(S s)
assert(static_cast<std::size_t>(ce - cs.rbegin()) == cs.size());
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test(S());
test(S("123"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S());
test(S("123"));
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;

View File

@ -25,30 +25,39 @@ void test_contiguous ( const C &c )
assert ( *(c.begin() + static_cast<typename C::difference_type>(i)) == *(std::addressof(*c.begin()) + i));
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test_contiguous(S());
test_contiguous(S("1"));
test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890"));
}
}
{
{
typedef test_allocator<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
test_contiguous(S(A(3)));
test_contiguous(S("1", A(5)));
test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)));
}
}
#if TEST_STD_VER >= 11
{
{
typedef min_allocator<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
test_contiguous(S(A{}));
test_contiguous(S("1", A()));
test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()));
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;

View File

@ -16,9 +16,8 @@
#include "test_macros.h"
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
S s1 {};
S s2 { "abcde", 5 };
@ -29,7 +28,17 @@ int main(int, char**)
assert (!s1.starts_with('x'));
assert ( s2.starts_with('a'));
assert (!s2.starts_with('x'));
}
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
}

View File

@ -16,9 +16,8 @@
#include "test_macros.h"
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
const char *s = "abcde";
S s0 {};
@ -57,7 +56,17 @@ int main(int, char**)
assert (!sNot.starts_with("abcd"));
assert (!sNot.starts_with("abcde"));
assert ( sNot.starts_with("def"));
}
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
}

View File

@ -16,9 +16,7 @@
#include "test_macros.h"
int main(int, char**)
{
{
bool test() {
typedef std::string S;
typedef std::string_view SV;
const char *s = "abcde";
@ -67,7 +65,16 @@ int main(int, char**)
assert (!sNot.starts_with(sv4));
assert (!sNot.starts_with(sv5));
assert ( sNot.starts_with(svNot));
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
}