[libc++][NFC] Remove some of the code duplication in the string tests
Reviewed By: ldionne, #libc, huixie90 Spies: huixie90, libcxx-commits, arphaman Differential Revision: https://reviews.llvm.org/D131856
This commit is contained in:
@@ -24,34 +24,24 @@ test(S s)
|
||||
assert(s.size() == 0);
|
||||
}
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void test_string() {
|
||||
S s;
|
||||
test(s);
|
||||
|
||||
s.assign(10, 'a');
|
||||
s.erase(5);
|
||||
test(s);
|
||||
|
||||
s.assign(100, 'a');
|
||||
s.erase(50);
|
||||
test(s);
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
S s;
|
||||
test(s);
|
||||
|
||||
s.assign(10, 'a');
|
||||
s.erase(5);
|
||||
test(s);
|
||||
|
||||
s.assign(100, 'a');
|
||||
s.erase(50);
|
||||
test(s);
|
||||
}
|
||||
test_string<std::string>();
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
S s;
|
||||
test(s);
|
||||
|
||||
s.assign(10, 'a');
|
||||
s.erase(5);
|
||||
test(s);
|
||||
|
||||
s.assign(100, 'a');
|
||||
s.erase(50);
|
||||
test(s);
|
||||
}
|
||||
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
||||
@@ -24,20 +24,17 @@ test(const S& s)
|
||||
assert(s.empty() == (s.size() == 0));
|
||||
}
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void test_string() {
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
||||
test_string<std::string>();
|
||||
#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"));
|
||||
}
|
||||
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
||||
@@ -23,20 +23,17 @@ test(const S& s)
|
||||
assert(s.length() == s.size());
|
||||
}
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void test_string() {
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
||||
test_string<std::string>();
|
||||
#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"));
|
||||
}
|
||||
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
||||
@@ -55,21 +55,20 @@ test(const S& s)
|
||||
test2(s);
|
||||
}
|
||||
|
||||
void test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void test_string() {
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
test_string<std::string>();
|
||||
#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"));
|
||||
}
|
||||
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if TEST_STD_VER > 17
|
||||
|
||||
@@ -37,20 +37,17 @@ test(const S& s)
|
||||
assert ( false );
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void test_string() {
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
||||
|
||||
bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
||||
test_string<std::string>();
|
||||
#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"));
|
||||
}
|
||||
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
||||
@@ -37,24 +37,17 @@ test(typename S::size_type min_cap, typename S::size_type erased_index)
|
||||
assert(s.capacity() >= s.size());
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void test_string() {
|
||||
test<S>(0, 0);
|
||||
test<S>(10, 5);
|
||||
test<S>(100, 50);
|
||||
}
|
||||
|
||||
bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
{
|
||||
test<S>(0, 0);
|
||||
test<S>(10, 5);
|
||||
test<S>(100, 50);
|
||||
}
|
||||
}
|
||||
test_string<std::string>();
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
{
|
||||
test<S>(0, 0);
|
||||
test<S>(10, 5);
|
||||
test<S>(100, 50);
|
||||
}
|
||||
}
|
||||
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
||||
@@ -62,40 +62,27 @@ test(typename S::size_type min_cap, typename S::size_type erased_index, typename
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void test_string() {
|
||||
{
|
||||
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_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
{
|
||||
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_string<std::string>();
|
||||
#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>(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_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
||||
@@ -43,46 +43,30 @@ test(S s, typename S::size_type n, S expected)
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void test_string() {
|
||||
test(S(), 0, S());
|
||||
test(S(), 1, S(1, '\0'));
|
||||
test(S(), 10, S(10, '\0'));
|
||||
test(S(), 100, S(100, '\0'));
|
||||
test(S("12345"), 0, S());
|
||||
test(S("12345"), 2, S("12"));
|
||||
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(), S::npos, S("not going to happen"));
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S(), 0, S());
|
||||
test(S(), 1, S(1, '\0'));
|
||||
test(S(), 10, S(10, '\0'));
|
||||
test(S(), 100, S(100, '\0'));
|
||||
test(S("12345"), 0, S());
|
||||
test(S("12345"), 2, S("12"));
|
||||
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(), S::npos, S("not going to happen"));
|
||||
}
|
||||
test_string<std::string>();
|
||||
#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'));
|
||||
test(S(), 10, S(10, '\0'));
|
||||
test(S(), 100, S(100, '\0'));
|
||||
test(S("12345"), 0, S());
|
||||
test(S("12345"), 2, S("12"));
|
||||
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(), S::npos, S("not going to happen"));
|
||||
}
|
||||
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
||||
@@ -43,46 +43,30 @@ test(S s, typename S::size_type n, typename S::value_type c, S expected)
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void test_string() {
|
||||
test(S(), 0, 'a', S());
|
||||
test(S(), 1, 'a', S("a"));
|
||||
test(S(), 10, 'a', S(10, 'a'));
|
||||
test(S(), 100, 'a', S(100, 'a'));
|
||||
test(S("12345"), 0, 'a', S());
|
||||
test(S("12345"), 2, 'a', S("12"));
|
||||
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(), S::npos, 'a', S("not going to happen"));
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S(), 0, 'a', S());
|
||||
test(S(), 1, 'a', S("a"));
|
||||
test(S(), 10, 'a', S(10, 'a'));
|
||||
test(S(), 100, 'a', S(100, 'a'));
|
||||
test(S("12345"), 0, 'a', S());
|
||||
test(S("12345"), 2, 'a', S("12"));
|
||||
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(), S::npos, 'a', S("not going to happen"));
|
||||
}
|
||||
test_string<std::string>();
|
||||
#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"));
|
||||
test(S(), 10, 'a', S(10, 'a'));
|
||||
test(S(), 100, 'a', S(100, 'a'));
|
||||
test(S("12345"), 0, 'a', S());
|
||||
test(S("12345"), 2, 'a', S("12"));
|
||||
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(), S::npos, 'a', S("not going to happen"));
|
||||
}
|
||||
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
||||
@@ -29,34 +29,24 @@ test(S s)
|
||||
assert(s.capacity() >= s.size());
|
||||
}
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void test_string() {
|
||||
S s;
|
||||
test(s);
|
||||
|
||||
s.assign(10, 'a');
|
||||
s.erase(5);
|
||||
test(s);
|
||||
|
||||
s.assign(100, 'a');
|
||||
s.erase(50);
|
||||
test(s);
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
S s;
|
||||
test(s);
|
||||
|
||||
s.assign(10, 'a');
|
||||
s.erase(5);
|
||||
test(s);
|
||||
|
||||
s.assign(100, 'a');
|
||||
s.erase(50);
|
||||
test(s);
|
||||
}
|
||||
test_string<std::string>();
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
S s;
|
||||
test(s);
|
||||
|
||||
s.assign(10, 'a');
|
||||
s.erase(5);
|
||||
test(s);
|
||||
|
||||
s.assign(100, 'a');
|
||||
s.erase(50);
|
||||
test(s);
|
||||
}
|
||||
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
||||
@@ -23,20 +23,17 @@ test(const S& s, typename S::size_type c)
|
||||
assert(s.size() == c);
|
||||
}
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void test_string() {
|
||||
test(S(), 0);
|
||||
test(S("123"), 3);
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 50);
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S(), 0);
|
||||
test(S("123"), 3);
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 50);
|
||||
}
|
||||
test_string<std::string>();
|
||||
#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);
|
||||
}
|
||||
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user