[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,49 +30,30 @@ TEST_CONSTEXPR_CXX20 void test(const S& s, const S& str, int x) {
|
||||
assert(sign(s.compare(str)) == sign(x));
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S(""), S(""), 0);
|
||||
test(S(""), S("abcde"), -5);
|
||||
test(S(""), S("abcdefghij"), -10);
|
||||
test(S(""), S("abcdefghijklmnopqrst"), -20);
|
||||
test(S("abcde"), S(""), 5);
|
||||
test(S("abcde"), S("abcde"), 0);
|
||||
test(S("abcde"), S("abcdefghij"), -5);
|
||||
test(S("abcde"), S("abcdefghijklmnopqrst"), -15);
|
||||
test(S("abcdefghij"), S(""), 10);
|
||||
test(S("abcdefghij"), S("abcde"), 5);
|
||||
test(S("abcdefghij"), S("abcdefghij"), 0);
|
||||
test(S("abcdefghij"), S("abcdefghijklmnopqrst"), -10);
|
||||
test(S("abcdefghijklmnopqrst"), S(""), 20);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcde"), 15);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghij"), 10);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), 0);
|
||||
}
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test(S(""), S(""), 0);
|
||||
test(S(""), S("abcde"), -5);
|
||||
test(S(""), S("abcdefghij"), -10);
|
||||
test(S(""), S("abcdefghijklmnopqrst"), -20);
|
||||
test(S("abcde"), S(""), 5);
|
||||
test(S("abcde"), S("abcde"), 0);
|
||||
test(S("abcde"), S("abcdefghij"), -5);
|
||||
test(S("abcde"), S("abcdefghijklmnopqrst"), -15);
|
||||
test(S("abcdefghij"), S(""), 10);
|
||||
test(S("abcdefghij"), S("abcde"), 5);
|
||||
test(S("abcdefghij"), S("abcdefghij"), 0);
|
||||
test(S("abcdefghij"), S("abcdefghijklmnopqrst"), -10);
|
||||
test(S("abcdefghijklmnopqrst"), S(""), 20);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcde"), 15);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghij"), 10);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), 0);
|
||||
}
|
||||
#endif
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void test_string() {
|
||||
test(S(""), S(""), 0);
|
||||
test(S(""), S("abcde"), -5);
|
||||
test(S(""), S("abcdefghij"), -10);
|
||||
test(S(""), S("abcdefghijklmnopqrst"), -20);
|
||||
test(S("abcde"), S(""), 5);
|
||||
test(S("abcde"), S("abcde"), 0);
|
||||
test(S("abcde"), S("abcdefghij"), -5);
|
||||
test(S("abcde"), S("abcdefghijklmnopqrst"), -15);
|
||||
test(S("abcdefghij"), S(""), 10);
|
||||
test(S("abcdefghij"), S("abcde"), 5);
|
||||
test(S("abcdefghij"), S("abcdefghij"), 0);
|
||||
test(S("abcdefghij"), S("abcdefghijklmnopqrst"), -10);
|
||||
test(S("abcdefghijklmnopqrst"), S(""), 20);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcde"), 15);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghij"), 10);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), 0);
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
test_string<std::string>();
|
||||
#if TEST_STD_VER >= 11
|
||||
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
|
||||
{ // LWG 2946
|
||||
std::string s = " !";
|
||||
assert(s.compare({"abc", 1}) < 0);
|
||||
|
||||
Reference in new issue
Block a user