[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
@@ -30,46 +30,30 @@ TEST_CONSTEXPR_CXX20 void test(const S& s, const typename S::value_type* str, in
|
||||
assert(sign(s.compare(str)) == sign(x));
|
||||
}
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void test_string() {
|
||||
test(S(""), "", 0);
|
||||
test(S(""), "abcde", -5);
|
||||
test(S(""), "abcdefghij", -10);
|
||||
test(S(""), "abcdefghijklmnopqrst", -20);
|
||||
test(S("abcde"), "", 5);
|
||||
test(S("abcde"), "abcde", 0);
|
||||
test(S("abcde"), "abcdefghij", -5);
|
||||
test(S("abcde"), "abcdefghijklmnopqrst", -15);
|
||||
test(S("abcdefghij"), "", 10);
|
||||
test(S("abcdefghij"), "abcde", 5);
|
||||
test(S("abcdefghij"), "abcdefghij", 0);
|
||||
test(S("abcdefghij"), "abcdefghijklmnopqrst", -10);
|
||||
test(S("abcdefghijklmnopqrst"), "", 20);
|
||||
test(S("abcdefghijklmnopqrst"), "abcde", 15);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghij", 10);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", 0);
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S(""), "", 0);
|
||||
test(S(""), "abcde", -5);
|
||||
test(S(""), "abcdefghij", -10);
|
||||
test(S(""), "abcdefghijklmnopqrst", -20);
|
||||
test(S("abcde"), "", 5);
|
||||
test(S("abcde"), "abcde", 0);
|
||||
test(S("abcde"), "abcdefghij", -5);
|
||||
test(S("abcde"), "abcdefghijklmnopqrst", -15);
|
||||
test(S("abcdefghij"), "", 10);
|
||||
test(S("abcdefghij"), "abcde", 5);
|
||||
test(S("abcdefghij"), "abcdefghij", 0);
|
||||
test(S("abcdefghij"), "abcdefghijklmnopqrst", -10);
|
||||
test(S("abcdefghijklmnopqrst"), "", 20);
|
||||
test(S("abcdefghijklmnopqrst"), "abcde", 15);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghij", 10);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", 0);
|
||||
}
|
||||
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(""), "abcde", -5);
|
||||
test(S(""), "abcdefghij", -10);
|
||||
test(S(""), "abcdefghijklmnopqrst", -20);
|
||||
test(S("abcde"), "", 5);
|
||||
test(S("abcde"), "abcde", 0);
|
||||
test(S("abcde"), "abcdefghij", -5);
|
||||
test(S("abcde"), "abcdefghijklmnopqrst", -15);
|
||||
test(S("abcdefghij"), "", 10);
|
||||
test(S("abcdefghij"), "abcde", 5);
|
||||
test(S("abcdefghij"), "abcdefghij", 0);
|
||||
test(S("abcdefghij"), "abcdefghijklmnopqrst", -10);
|
||||
test(S("abcdefghijklmnopqrst"), "", 20);
|
||||
test(S("abcdefghijklmnopqrst"), "abcde", 15);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghij", 10);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", 0);
|
||||
}
|
||||
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user