[libc++] Refactor string unit tests to ease addition of new allocators
While doing this, I also found a few tests that were either clearly incorrect (e.g. testing the wrong function) or that lacked basic test coverage like testing std::string itself (e.g. the test was only checking std::basic_string with a custom allocator). In these cases, I did a few conservative drive-by changes. Differential Revision: https://reviews.llvm.org/D140550 Co-authored-by: Brendan Emery <brendan.emery@esrlabs.com>
This commit is contained in:
1 parent
47b7f33b13
commit
6e1dcc9335
149 files changed
+2959
-4153
No files matched your search
+9
-11
@@ -18,18 +18,16 @@
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void test_string() {
|
||||
S s("123def456");
|
||||
s.replace(s.cbegin() + 3, s.cbegin() + 6, {'a', 'b', 'c'});
|
||||
assert(s == "123abc456");
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
std::string s("123def456");
|
||||
s.replace(s.cbegin() + 3, s.cbegin() + 6, {'a', 'b', 'c'});
|
||||
assert(s == "123abc456");
|
||||
}
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
S s("123def456");
|
||||
s.replace(s.cbegin() + 3, s.cbegin() + 6, {'a', 'b', 'c'});
|
||||
assert(s == "123abc456");
|
||||
}
|
||||
test_string<std::string>();
|
||||
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+11
-23
@@ -283,35 +283,23 @@ TEST_CONSTEXPR_CXX20 bool test2() {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test0<S>();
|
||||
test1<S>();
|
||||
test2<S>();
|
||||
test0<S>();
|
||||
test1<S>();
|
||||
test2<S>();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test0<S>());
|
||||
static_assert(test1<S>());
|
||||
static_assert(test2<S>());
|
||||
#endif
|
||||
}
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test0<S>();
|
||||
test1<S>();
|
||||
test2<S>();
|
||||
# if TEST_STD_VER > 17
|
||||
static_assert(test0<S>());
|
||||
static_assert(test1<S>());
|
||||
static_assert(test2<S>());
|
||||
# endif
|
||||
}
|
||||
static_assert(test0<S>());
|
||||
static_assert(test1<S>());
|
||||
static_assert(test2<S>());
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test();
|
||||
test<std::string>();
|
||||
#if TEST_STD_VER >= 11
|
||||
test<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
+21
-24
@@ -38,7 +38,7 @@ test(S s,
|
||||
}
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void test0() {
|
||||
TEST_CONSTEXPR_CXX20 bool test0() {
|
||||
test(S(""), 0, 0, 0, '3', S(""));
|
||||
test(S(""), 0, 0, 5, '3', S("33333"));
|
||||
test(S(""), 0, 0, 10, '3', S("3333333333"));
|
||||
@@ -139,10 +139,11 @@ TEST_CONSTEXPR_CXX20 void test0() {
|
||||
test(S("abcdefghij"), 1, 1, 5, '3', S("a33333cdefghij"));
|
||||
test(S("abcdefghij"), 1, 1, 10, '3', S("a3333333333cdefghij"));
|
||||
test(S("abcdefghij"), 1, 1, 20, '3', S("a33333333333333333333cdefghij"));
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void test1() {
|
||||
TEST_CONSTEXPR_CXX20 bool test1() {
|
||||
test(S("abcdefghij"), 1, 4, 0, '3', S("afghij"));
|
||||
test(S("abcdefghij"), 1, 4, 5, '3', S("a33333fghij"));
|
||||
test(S("abcdefghij"), 1, 4, 10, '3', S("a3333333333fghij"));
|
||||
@@ -243,10 +244,11 @@ TEST_CONSTEXPR_CXX20 void test1() {
|
||||
test(S("abcdefghijklmnopqrst"), 10, 9, 5, '3', S("abcdefghij33333t"));
|
||||
test(S("abcdefghijklmnopqrst"), 10, 9, 10, '3', S("abcdefghij3333333333t"));
|
||||
test(S("abcdefghijklmnopqrst"), 10, 9, 20, '3', S("abcdefghij33333333333333333333t"));
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void test2() {
|
||||
TEST_CONSTEXPR_CXX20 bool test2() {
|
||||
test(S("abcdefghijklmnopqrst"), 10, 10, 0, '3', S("abcdefghij"));
|
||||
test(S("abcdefghijklmnopqrst"), 10, 10, 5, '3', S("abcdefghij33333"));
|
||||
test(S("abcdefghijklmnopqrst"), 10, 10, 10, '3', S("abcdefghij3333333333"));
|
||||
@@ -263,31 +265,26 @@ TEST_CONSTEXPR_CXX20 void test2() {
|
||||
test(S("abcdefghijklmnopqrst"), 20, 0, 5, '3', S("abcdefghijklmnopqrst33333"));
|
||||
test(S("abcdefghijklmnopqrst"), 20, 0, 10, '3', S("abcdefghijklmnopqrst3333333333"));
|
||||
test(S("abcdefghijklmnopqrst"), 20, 0, 20, '3', S("abcdefghijklmnopqrst33333333333333333333"));
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test0<S>();
|
||||
test1<S>();
|
||||
test2<S>();
|
||||
}
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test0<S>();
|
||||
test1<S>();
|
||||
test2<S>();
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test();
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void test() {
|
||||
test0<S>();
|
||||
test1<S>();
|
||||
test2<S>();
|
||||
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
static_assert(test0<S>());
|
||||
static_assert(test1<S>());
|
||||
static_assert(test2<S>());
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::string>();
|
||||
#if TEST_STD_VER >= 11
|
||||
test<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
+13
-25
@@ -265,37 +265,25 @@ TEST_CONSTEXPR_CXX20 bool test2() {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class CharT, template <class> class Alloc>
|
||||
TEST_CONSTEXPR_CXX20 void test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
typedef std::string_view SV;
|
||||
test0<S, SV>();
|
||||
test1<S, SV>();
|
||||
test2<S, SV>();
|
||||
using S = std::basic_string<CharT, std::char_traits<CharT>, Alloc<CharT> >;
|
||||
using SV = std::basic_string_view<CharT, std::char_traits<CharT> >;
|
||||
test0<S, SV>();
|
||||
test1<S, SV>();
|
||||
test2<S, SV>();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test0<S, SV>());
|
||||
static_assert(test1<S, SV>());
|
||||
static_assert(test2<S, SV>());
|
||||
#endif
|
||||
}
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
typedef std::string_view SV;
|
||||
test0<S, SV>();
|
||||
test1<S, SV>();
|
||||
test2<S, SV>();
|
||||
# if TEST_STD_VER > 17
|
||||
static_assert(test0<S, SV>());
|
||||
static_assert(test1<S, SV>());
|
||||
static_assert(test2<S, SV>());
|
||||
# endif
|
||||
}
|
||||
static_assert(test0<S, SV>());
|
||||
static_assert(test1<S, SV>());
|
||||
static_assert(test2<S, SV>());
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test();
|
||||
test<char, std::allocator>();
|
||||
#if TEST_STD_VER >= 11
|
||||
test<char, min_allocator>();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
+6
-7
@@ -6154,8 +6154,10 @@ TEST_CONSTEXPR_CXX20 bool test56() {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class S, class SV>
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
template <class CharT, template <class> class Alloc>
|
||||
void test() {
|
||||
using S = std::basic_string<CharT, std::char_traits<CharT>, Alloc<CharT> >;
|
||||
using SV = std::basic_string_view<CharT, std::char_traits<CharT> >;
|
||||
test0<S, SV>();
|
||||
test1<S, SV>();
|
||||
test2<S, SV>();
|
||||
@@ -6271,15 +6273,12 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
static_assert(test54<S, SV>());
|
||||
static_assert(test55<S, SV>());
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::string, std::string_view>();
|
||||
test<char, std::allocator>();
|
||||
#if TEST_STD_VER >= 11
|
||||
test<std::basic_string<char, std::char_traits<char>, min_allocator<char>>,
|
||||
std::basic_string_view<char, std::char_traits<char>>>();
|
||||
test<char, min_allocator>();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
+2
-2
@@ -5977,7 +5977,7 @@ TEST_CONSTEXPR_CXX20 bool test55() {
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void test() {
|
||||
TEST_CONSTEXPR_CXX20 void test() {
|
||||
test0<S>();
|
||||
test1<S>();
|
||||
test2<S>();
|
||||
@@ -6098,7 +6098,7 @@ void test() {
|
||||
int main(int, char**) {
|
||||
test<std::string>();
|
||||
#if TEST_STD_VER >= 11
|
||||
test<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
|
||||
test<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
+11
-12
@@ -358,25 +358,24 @@ TEST_CONSTEXPR_CXX20 bool test2() {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class S>
|
||||
template <class CharT, template <class> class Alloc>
|
||||
void test() {
|
||||
{
|
||||
typedef std::string_view SV;
|
||||
test0<S, SV>();
|
||||
test1<S, SV>();
|
||||
test2<S, SV>();
|
||||
using S = std::basic_string<CharT, std::char_traits<CharT>, Alloc<CharT> >;
|
||||
using SV = std::basic_string_view<CharT, std::char_traits<CharT> >;
|
||||
test0<S, SV>();
|
||||
test1<S, SV>();
|
||||
test2<S, SV>();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test0<S, SV>());
|
||||
static_assert(test1<S, SV>());
|
||||
static_assert(test2<S, SV>());
|
||||
static_assert(test0<S, SV>());
|
||||
static_assert(test1<S, SV>());
|
||||
static_assert(test2<S, SV>());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::string>();
|
||||
test<char, std::allocator>();
|
||||
#if TEST_STD_VER >= 11
|
||||
test<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
|
||||
test<char, min_allocator>();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in new issue
Block a user