diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/char_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/char_string.pass.cpp index 2ca5788e6d8a..68a250c59331 100644 --- a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/char_string.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/char_string.pass.cpp @@ -16,39 +16,32 @@ // basic_string&& // operator+(charT lhs, basic_string&& rhs); // constexpr since C++20 +#include #include #include -#include #include "test_macros.h" #include "min_allocator.h" #include "asan_testing.h" -template -TEST_CONSTEXPR_CXX20 void test0(typename S::value_type lhs, const S& rhs, const S& x) { - assert(lhs + rhs == x); - LIBCPP_ASSERT(is_string_asan_correct(lhs + rhs)); -} - -#if TEST_STD_VER >= 11 -template -TEST_CONSTEXPR_CXX20 void test1(typename S::value_type lhs, S&& rhs, const S& x) { - assert(lhs + std::move(rhs) == x); -} -#endif - template TEST_CONSTEXPR_CXX20 void test_string() { - test0('a', S(""), S("a")); - test0('a', S("12345"), S("a12345")); - test0('a', S("1234567890"), S("a1234567890")); - test0('a', S("12345678901234567890"), S("a12345678901234567890")); + const char* test_data[] = {"", "12345", "1234567890", "12345678901234567890"}; + const char* results[] = {"a", "a12345", "a1234567890", "a12345678901234567890"}; + + for (size_t i = 0; i != 4; ++i) { + { // operator+(value_type, const string&); + const S str(test_data[i]); + assert('a' + str == results[i]); + LIBCPP_ASSERT(is_string_asan_correct('a' + str)); + } #if TEST_STD_VER >= 11 - test1('a', S(""), S("a")); - test1('a', S("12345"), S("a12345")); - test1('a', S("1234567890"), S("a1234567890")); - test1('a', S("12345678901234567890"), S("a12345678901234567890")); + { // operator+(value_type, string&&); + S str(test_data[i]); + assert('a' + std::move(str) == results[i]); + } #endif + } } TEST_CONSTEXPR_CXX20 bool test() { @@ -63,7 +56,7 @@ TEST_CONSTEXPR_CXX20 bool test() { int main(int, char**) { test(); -#if TEST_STD_VER > 17 +#if TEST_STD_VER >= 20 static_assert(test()); #endif diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/pointer_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/pointer_string.pass.cpp index fa14f657d826..434f7292c149 100644 --- a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/pointer_string.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/pointer_string.pass.cpp @@ -16,68 +16,49 @@ // basic_string&& // operator+(const charT* lhs, basic_string&& rhs); // constexpr since C++20 +#include #include #include -#include #include "test_macros.h" #include "min_allocator.h" -template -TEST_CONSTEXPR_CXX20 void test0(const typename S::value_type* lhs, const S& rhs, const S& x) { - assert(lhs + rhs == x); -} - -#if TEST_STD_VER >= 11 -template -TEST_CONSTEXPR_CXX20 void test1(const typename S::value_type* lhs, S&& rhs, const S& x) { - assert(lhs + std::move(rhs) == x); -} -#endif - template TEST_CONSTEXPR_CXX20 void test_string() { - test0("", S(""), S("")); - test0("", S("12345"), S("12345")); - test0("", S("1234567890"), S("1234567890")); - test0("", S("12345678901234567890"), S("12345678901234567890")); - test0("abcde", S(""), S("abcde")); - test0("abcde", S("12345"), S("abcde12345")); - test0("abcde", S("1234567890"), S("abcde1234567890")); - test0("abcde", S("12345678901234567890"), S("abcde12345678901234567890")); - test0("abcdefghij", S(""), S("abcdefghij")); - test0("abcdefghij", S("12345"), S("abcdefghij12345")); - test0("abcdefghij", S("1234567890"), S("abcdefghij1234567890")); - test0("abcdefghij", S("12345678901234567890"), S("abcdefghij12345678901234567890")); - test0("abcdefghijklmnopqrst", S(""), S("abcdefghijklmnopqrst")); - test0("abcdefghijklmnopqrst", S("12345"), S("abcdefghijklmnopqrst12345")); - test0("abcdefghijklmnopqrst", S("1234567890"), S("abcdefghijklmnopqrst1234567890")); - test0("abcdefghijklmnopqrst", S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890")); + const char* test_data[2][4] = { + {"", "abcde", "abcdefghij", "abcdefghijklmnopqrst"}, {"", "12345", "1234567890", "12345678901234567890"}}; + const char* results[4][4] = { + {"", "12345", "1234567890", "12345678901234567890"}, + {"abcde", "abcde12345", "abcde1234567890", "abcde12345678901234567890"}, + {"abcdefghij", "abcdefghij12345", "abcdefghij1234567890", "abcdefghij12345678901234567890"}, + {"abcdefghijklmnopqrst", + "abcdefghijklmnopqrst12345", + "abcdefghijklmnopqrst1234567890", + "abcdefghijklmnopqrst12345678901234567890"}}; + + for (size_t i = 0; i != 4; ++i) { + for (size_t k = 0; k != 4; ++k) { + { // operator+(const value_type*, const string&); + const char* lhs = test_data[0][i]; + const S rhs(test_data[1][k]); + assert(lhs + rhs == results[i][k]); + } #if TEST_STD_VER >= 11 - test1("", S(""), S("")); - test1("", S("12345"), S("12345")); - test1("", S("1234567890"), S("1234567890")); - test1("", S("12345678901234567890"), S("12345678901234567890")); - test1("abcde", S(""), S("abcde")); - test1("abcde", S("12345"), S("abcde12345")); - test1("abcde", S("1234567890"), S("abcde1234567890")); - test1("abcde", S("12345678901234567890"), S("abcde12345678901234567890")); - test1("abcdefghij", S(""), S("abcdefghij")); - test1("abcdefghij", S("12345"), S("abcdefghij12345")); - test1("abcdefghij", S("1234567890"), S("abcdefghij1234567890")); - test1("abcdefghij", S("12345678901234567890"), S("abcdefghij12345678901234567890")); - test1("abcdefghijklmnopqrst", S(""), S("abcdefghijklmnopqrst")); - test1("abcdefghijklmnopqrst", S("12345"), S("abcdefghijklmnopqrst12345")); - test1("abcdefghijklmnopqrst", S("1234567890"), S("abcdefghijklmnopqrst1234567890")); - test1("abcdefghijklmnopqrst", S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890")); + { // operator+(const value_type*, string&&); + const char* lhs = test_data[0][i]; + S rhs(test_data[1][k]); + assert(lhs + std::move(rhs) == results[i][k]); + } #endif + } + } } TEST_CONSTEXPR_CXX20 bool test() { test_string(); #if TEST_STD_VER >= 11 - test_string, min_allocator > >(); + test_string, min_allocator>>(); #endif return true; @@ -85,7 +66,7 @@ TEST_CONSTEXPR_CXX20 bool test() { int main(int, char**) { test(); -#if TEST_STD_VER > 17 +#if TEST_STD_VER >= 20 static_assert(test()); #endif diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_char.pass.cpp index 9c0fb56e1f1c..5c3989ae304e 100644 --- a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_char.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_char.pass.cpp @@ -16,41 +16,32 @@ // basic_string&& // operator+(basic_string&& lhs, charT rhs); // constexpr since C++20 +#include #include #include -#include -#include "test_macros.h" -#include "min_allocator.h" #include "asan_testing.h" - -template -TEST_CONSTEXPR_CXX20 void test0(const S& lhs, typename S::value_type rhs, const S& x) { - assert(lhs + rhs == x); - LIBCPP_ASSERT(is_string_asan_correct(lhs + rhs)); -} - -#if TEST_STD_VER >= 11 -template -TEST_CONSTEXPR_CXX20 void test1(S&& lhs, typename S::value_type rhs, const S& x) { - assert(std::move(lhs) + rhs == x); -} -#endif +#include "min_allocator.h" +#include "test_macros.h" template TEST_CONSTEXPR_CXX20 void test_string() { - test0(S(""), '1', S("1")); - test0(S(""), '1', S("1")); - test0(S("abcde"), '1', S("abcde1")); - test0(S("abcdefghij"), '1', S("abcdefghij1")); - test0(S("abcdefghijklmnopqrst"), '1', S("abcdefghijklmnopqrst1")); + const char* test_data[] = {"", "12345", "1234567890", "12345678901234567890"}; + const char* results[] = {"a", "12345a", "1234567890a", "12345678901234567890a"}; + for (size_t i = 0; i != 4; ++i) { + { // operator+(const string&, value_type); + const S str(test_data[i]); + assert(str + 'a' == results[i]); + LIBCPP_ASSERT(is_string_asan_correct(str + 'a')); + } #if TEST_STD_VER >= 11 - test1(S(""), '1', S("1")); - test1(S("abcde"), '1', S("abcde1")); - test1(S("abcdefghij"), '1', S("abcdefghij1")); - test1(S("abcdefghijklmnopqrst"), '1', S("abcdefghijklmnopqrst1")); + { // operator+(string&&, value_type); + S str(test_data[i]); + assert(std::move(str) + 'a' == results[i]); + } #endif + } } TEST_CONSTEXPR_CXX20 bool test() { @@ -65,7 +56,7 @@ TEST_CONSTEXPR_CXX20 bool test() { int main(int, char**) { test(); -#if TEST_STD_VER > 17 +#if TEST_STD_VER >= 20 static_assert(test()); #endif diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_pointer.pass.cpp index 3e1aaebf112e..589c737348a1 100644 --- a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_pointer.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_pointer.pass.cpp @@ -16,13 +16,13 @@ // basic_string&& // operator+(basic_string&& lhs, const charT* rhs); // constexpr since C++20 +#include #include #include -#include -#include "test_macros.h" -#include "min_allocator.h" #include "asan_testing.h" +#include "min_allocator.h" +#include "test_macros.h" template TEST_CONSTEXPR_CXX20 void test0(const S& lhs, const typename S::value_type* rhs, const S& x) { @@ -39,40 +39,34 @@ TEST_CONSTEXPR_CXX20 void test1(S&& lhs, const typename S::value_type* rhs, cons template TEST_CONSTEXPR_CXX20 void test_string() { - test0(S(""), "", S("")); - test0(S(""), "12345", S("12345")); - test0(S(""), "1234567890", S("1234567890")); - test0(S(""), "12345678901234567890", S("12345678901234567890")); - test0(S("abcde"), "", S("abcde")); - test0(S("abcde"), "12345", S("abcde12345")); - test0(S("abcde"), "1234567890", S("abcde1234567890")); - test0(S("abcde"), "12345678901234567890", S("abcde12345678901234567890")); - test0(S("abcdefghij"), "", S("abcdefghij")); - test0(S("abcdefghij"), "12345", S("abcdefghij12345")); - test0(S("abcdefghij"), "1234567890", S("abcdefghij1234567890")); - test0(S("abcdefghij"), "12345678901234567890", S("abcdefghij12345678901234567890")); - test0(S("abcdefghijklmnopqrst"), "", S("abcdefghijklmnopqrst")); - test0(S("abcdefghijklmnopqrst"), "12345", S("abcdefghijklmnopqrst12345")); - test0(S("abcdefghijklmnopqrst"), "1234567890", S("abcdefghijklmnopqrst1234567890")); - test0(S("abcdefghijklmnopqrst"), "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890")); + const char* test_data[2][4] = { + {"", "abcde", "abcdefghij", "abcdefghijklmnopqrst"}, {"", "12345", "1234567890", "12345678901234567890"}}; + + const char* results[4][4] = { + {"", "12345", "1234567890", "12345678901234567890"}, + {"abcde", "abcde12345", "abcde1234567890", "abcde12345678901234567890"}, + {"abcdefghij", "abcdefghij12345", "abcdefghij1234567890", "abcdefghij12345678901234567890"}, + {"abcdefghijklmnopqrst", + "abcdefghijklmnopqrst12345", + "abcdefghijklmnopqrst1234567890", + "abcdefghijklmnopqrst12345678901234567890"}}; + + for (size_t i = 0; i != 4; ++i) { + for (size_t k = 0; k != 4; ++k) { + { // operator+(const value_type*, const string&); + const S lhs(test_data[0][i]); + const char* rhs = test_data[1][k]; + assert(lhs + rhs == results[i][k]); + } #if TEST_STD_VER >= 11 - test1(S(""), "", S("")); - test1(S(""), "12345", S("12345")); - test1(S(""), "1234567890", S("1234567890")); - test1(S(""), "12345678901234567890", S("12345678901234567890")); - test1(S("abcde"), "", S("abcde")); - test1(S("abcde"), "12345", S("abcde12345")); - test1(S("abcde"), "1234567890", S("abcde1234567890")); - test1(S("abcde"), "12345678901234567890", S("abcde12345678901234567890")); - test1(S("abcdefghij"), "", S("abcdefghij")); - test1(S("abcdefghij"), "12345", S("abcdefghij12345")); - test1(S("abcdefghij"), "1234567890", S("abcdefghij1234567890")); - test1(S("abcdefghij"), "12345678901234567890", S("abcdefghij12345678901234567890")); - test1(S("abcdefghijklmnopqrst"), "", S("abcdefghijklmnopqrst")); - test1(S("abcdefghijklmnopqrst"), "12345", S("abcdefghijklmnopqrst12345")); - test1(S("abcdefghijklmnopqrst"), "1234567890", S("abcdefghijklmnopqrst1234567890")); - test1(S("abcdefghijklmnopqrst"), "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890")); + { // operator+(const value_type*, string&&); + S lhs(test_data[0][i]); + const char* rhs = test_data[1][k]; + assert(std::move(lhs) + rhs == results[i][k]); + } #endif + } + } } TEST_CONSTEXPR_CXX20 bool test() { @@ -87,7 +81,7 @@ TEST_CONSTEXPR_CXX20 bool test() { int main(int, char**) { test(); -#if TEST_STD_VER > 17 +#if TEST_STD_VER >= 20 static_assert(test()); #endif diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_string.pass.cpp index fcc8ceab8707..2badb5175339 100644 --- a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_string.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_string.pass.cpp @@ -28,114 +28,62 @@ // operator+(const basic_string&& lhs, // const basic_string&& rhs); // constexpr since C++20 +#include #include #include -#include -#include "test_macros.h" -#include "min_allocator.h" #include "asan_testing.h" - -template -TEST_CONSTEXPR_CXX20 void test0(const S& lhs, const S& rhs, const S& x) { - assert(lhs + rhs == x); - LIBCPP_ASSERT(is_string_asan_correct(lhs + rhs)); -} - -#if TEST_STD_VER >= 11 -template -TEST_CONSTEXPR_CXX20 void test1(S&& lhs, const S& rhs, const S& x) { - assert(std::move(lhs) + rhs == x); -} - -template -TEST_CONSTEXPR_CXX20 void test2(const S& lhs, S&& rhs, const S& x) { - assert(lhs + std::move(rhs) == x); -} - -template -TEST_CONSTEXPR_CXX20 void test3(S&& lhs, S&& rhs, const S& x) { - assert(std::move(lhs) + std::move(rhs) == x); -} -#endif +#include "min_allocator.h" +#include "test_macros.h" template TEST_CONSTEXPR_CXX20 void test_string() { - test0(S(""), S(""), S("")); - test0(S(""), S("12345"), S("12345")); - test0(S(""), S("1234567890"), S("1234567890")); - test0(S(""), S("12345678901234567890"), S("12345678901234567890")); - test0(S("abcde"), S(""), S("abcde")); - test0(S("abcde"), S("12345"), S("abcde12345")); - test0(S("abcde"), S("1234567890"), S("abcde1234567890")); - test0(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890")); - test0(S("abcdefghij"), S(""), S("abcdefghij")); - test0(S("abcdefghij"), S("12345"), S("abcdefghij12345")); - test0(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890")); - test0(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890")); - test0(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst")); - test0(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345")); - test0(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890")); - test0(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890")); + const char* test_data[2][4] = { + {"", "abcde", "abcdefghij", "abcdefghijklmnopqrst"}, {"", "12345", "1234567890", "12345678901234567890"}}; + + const char* results[4][4] = { + {"", "12345", "1234567890", "12345678901234567890"}, + {"abcde", "abcde12345", "abcde1234567890", "abcde12345678901234567890"}, + {"abcdefghij", "abcdefghij12345", "abcdefghij1234567890", "abcdefghij12345678901234567890"}, + {"abcdefghijklmnopqrst", + "abcdefghijklmnopqrst12345", + "abcdefghijklmnopqrst1234567890", + "abcdefghijklmnopqrst12345678901234567890"}}; + + for (size_t i = 0; i != 4; ++i) { + for (size_t k = 0; k != 4; ++k) { + { // operator+(const string&, const string&); + const S lhs(test_data[0][i]); + const S rhs(test_data[1][k]); + assert(lhs + rhs == results[i][k]); + LIBCPP_ASSERT(is_string_asan_correct(lhs + rhs)); + } #if TEST_STD_VER >= 11 - test1(S(""), S(""), S("")); - test1(S(""), S("12345"), S("12345")); - test1(S(""), S("1234567890"), S("1234567890")); - test1(S(""), S("12345678901234567890"), S("12345678901234567890")); - test1(S("abcde"), S(""), S("abcde")); - test1(S("abcde"), S("12345"), S("abcde12345")); - test1(S("abcde"), S("1234567890"), S("abcde1234567890")); - test1(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890")); - test1(S("abcdefghij"), S(""), S("abcdefghij")); - test1(S("abcdefghij"), S("12345"), S("abcdefghij12345")); - test1(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890")); - test1(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890")); - test1(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst")); - test1(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345")); - test1(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890")); - test1(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890")); - - test2(S(""), S(""), S("")); - test2(S(""), S("12345"), S("12345")); - test2(S(""), S("1234567890"), S("1234567890")); - test2(S(""), S("12345678901234567890"), S("12345678901234567890")); - test2(S("abcde"), S(""), S("abcde")); - test2(S("abcde"), S("12345"), S("abcde12345")); - test2(S("abcde"), S("1234567890"), S("abcde1234567890")); - test2(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890")); - test2(S("abcdefghij"), S(""), S("abcdefghij")); - test2(S("abcdefghij"), S("12345"), S("abcdefghij12345")); - test2(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890")); - test2(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890")); - test2(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst")); - test2(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345")); - test2(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890")); - test2(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890")); - - test3(S(""), S(""), S("")); - test3(S(""), S("12345"), S("12345")); - test3(S(""), S("1234567890"), S("1234567890")); - test3(S(""), S("12345678901234567890"), S("12345678901234567890")); - test3(S("abcde"), S(""), S("abcde")); - test3(S("abcde"), S("12345"), S("abcde12345")); - test3(S("abcde"), S("1234567890"), S("abcde1234567890")); - test3(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890")); - test3(S("abcdefghij"), S(""), S("abcdefghij")); - test3(S("abcdefghij"), S("12345"), S("abcdefghij12345")); - test3(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890")); - test3(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890")); - test3(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst")); - test3(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345")); - test3(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890")); - test3(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890")); + { // operator+(string&&, const string&); + S lhs(test_data[0][i]); + const S rhs(test_data[1][k]); + assert(std::move(lhs) + rhs == results[i][k]); + } + { // operator+(const string&, string&&); + const S lhs(test_data[0][i]); + S rhs(test_data[1][k]); + assert(lhs + std::move(rhs) == results[i][k]); + } + { // operator+(string&&, string&&); + S lhs(test_data[0][i]); + S rhs(test_data[1][k]); + assert(std::move(lhs) + std::move(rhs) == results[i][k]); + } #endif + } + } } TEST_CONSTEXPR_CXX20 bool test() { test_string(); #if TEST_STD_VER >= 11 - test_string, min_allocator > >(); - test_string, safe_allocator > >(); + test_string, min_allocator>>(); + test_string, safe_allocator>>(); #endif return true; @@ -143,7 +91,7 @@ TEST_CONSTEXPR_CXX20 bool test() { int main(int, char**) { test(); -#if TEST_STD_VER > 17 +#if TEST_STD_VER >= 20 static_assert(test()); #endif