diff options
Diffstat (limited to 'libcxx/test/std/strings/basic.string/string.modifiers/string_append')
10 files changed, 192 insertions, 102 deletions
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp index 437524063621..028c1b881b8c 100644 --- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp @@ -20,7 +20,7 @@ #include "min_allocator.h" template <class S, class SV> -void +TEST_CONSTEXPR_CXX20 void test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected) { if (pos <= sv.size()) @@ -46,7 +46,7 @@ test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected) } template <class S, class SV> -void +TEST_CONSTEXPR_CXX20 void test_npos(S s, SV sv, typename S::size_type pos, S expected) { if (pos <= sv.size()) @@ -71,9 +71,8 @@ test_npos(S s, SV sv, typename S::size_type pos, S expected) #endif } -int main(int, char**) -{ - { +bool test() { + { typedef std::string S; typedef std::string_view SV; test(S(), SV(), 0, 0, S()); @@ -97,9 +96,9 @@ int main(int, char**) test(S("12345678901234567890"), SV("12345"), 1, 3, S("12345678901234567890234")); test(S("12345678901234567890"), SV("12345678901234567890"), 5, 10, S("123456789012345678906789012345")); - } + } #if TEST_STD_VER >= 11 - { + { typedef std::basic_string <char, std::char_traits<char>, min_allocator<char>> S; typedef std::basic_string_view<char, std::char_traits<char> > SV; test(S(), SV(), 0, 0, S()); @@ -123,9 +122,9 @@ int main(int, char**) test(S("12345678901234567890"), SV("12345"), 1, 3, S("12345678901234567890234")); test(S("12345678901234567890"), SV("12345678901234567890"), 5, 10, S("123456789012345678906789012345")); - } + } #endif - { + { typedef std::string S; typedef std::string_view SV; test_npos(S(), SV(), 0, S()); @@ -135,9 +134,9 @@ int main(int, char**) test_npos(S(), SV("12345"), 3, S("45")); test_npos(S(), SV("12345"), 5, S("")); test_npos(S(), SV("12345"), 6, S("not happening")); - } + } - { + { std::string s; std::string_view sv = "EFGH"; char arr[] = "IJKL"; @@ -169,9 +168,9 @@ int main(int, char**) s.append(arr, 0); // calls append(const char *, len) assert(s == ""); s.clear(); - } + } - { + { std::string s = "ABCD"; std::string_view sv = s; s.append(sv); @@ -184,9 +183,9 @@ int main(int, char**) sv = s; s.append(sv, sv.size()); assert(s == "ABCDABCDABCDABCD"); - } + } - { + { std::string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; std::string_view sv = s; s.append(sv); @@ -195,7 +194,17 @@ int main(int, char**) sv = s; s.append(sv, 0, std::string::npos); assert(s == "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"); - } + } + + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + // static_assert(test()); +#endif return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/initializer_list.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/initializer_list.pass.cpp index a252eaab9f8f..f72c3ce075f9 100644 --- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/initializer_list.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/initializer_list.pass.cpp @@ -18,19 +18,28 @@ #include "test_macros.h" #include "min_allocator.h" +bool test() { + { + std::string s("123"); + s.append({'a', 'b', 'c'}); + assert(s == "123abc"); + } + { + typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; + S s("123"); + s.append({'a', 'b', 'c'}); + assert(s == "123abc"); + } + + return true; +} + int main(int, char**) { - { - std::string s("123"); - s.append({'a', 'b', 'c'}); - assert(s == "123abc"); - } - { - typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; - S s("123"); - s.append({'a', 'b', 'c'}); - assert(s == "123abc"); - } + test(); +#if TEST_STD_VER > 17 + // static_assert(test()); +#endif return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp index 07c5586419b5..fd96af4c550e 100644 --- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp @@ -19,7 +19,7 @@ #include "min_allocator.h" template <class S, class It> -void +TEST_CONSTEXPR_CXX20 void test(S s, It first, It last, S expected) { s.append(first, last); @@ -31,7 +31,7 @@ test(S s, It first, It last, S expected) struct Widget { operator char() const { throw 42; } }; template <class S, class It> -void +TEST_CONSTEXPR_CXX20 void test_exceptions(S s, It first, It last) { S original = s; @@ -52,9 +52,8 @@ test_exceptions(S s, It first, It last) } #endif -int main(int, char**) -{ - { +bool test() { + { typedef std::string S; const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; test(S(), s, s, S()); @@ -111,9 +110,9 @@ int main(int, char**) S("12345678901234567890""ABCDEFGHIJ")); test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52), S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - } + } #if TEST_STD_VER >= 11 - { + { typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; test(S(), s, s, S()); @@ -170,10 +169,10 @@ int main(int, char**) S("12345678901234567890""ABCDEFGHIJ")); test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52), S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - } + } #endif #ifndef TEST_HAS_NO_EXCEPTIONS - { // test iterator operations that throw + { // test iterator operations that throw typedef std::string S; typedef ThrowingIterator<char> TIter; typedef cpp17_input_iterator<TIter> IIter; @@ -188,10 +187,10 @@ int main(int, char**) Widget w[100]; test_exceptions(S(), w, w+100); - } + } #endif - { // test appending to self + { // test appending to self typedef std::string S; S s_short = "123/"; S s_long = "Lorem ipsum dolor sit amet, consectetur/"; @@ -205,18 +204,18 @@ int main(int, char**) s_long.append(s_long.begin(), s_long.end()); assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/"); - } + } - { // test appending a different type + { // test appending a different type typedef std::string S; const uint8_t p[] = "ABCD"; S s; s.append(p, p + 4); assert(s == "ABCD"); - } + } - { // regression-test appending to self in sneaky ways + { // regression-test appending to self in sneaky ways std::string s_short = "hello"; std::string s_long = "Lorem ipsum dolor sit amet, consectetur/"; std::string s_othertype = "hello"; @@ -231,7 +230,7 @@ int main(int, char**) s_sneaky.reserve(12); test(s_sneaky, s_sneaky.data(), s_sneaky.data() + 6, std::string("hellohello\0", 11)); - } + } { // test with a move iterator that returns char&& typedef forward_iterator<const char*> It; @@ -250,5 +249,15 @@ int main(int, char**) assert(s == "ABCD"); } + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + // static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp index eba693d0e3d1..14b5c86e9edb 100644 --- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp @@ -26,9 +26,8 @@ test(S s, const typename S::value_type* str, S expected) assert(s == expected); } -int main(int, char**) -{ - { +bool test() { + { typedef std::string S; test(S(), "", S()); test(S(), "12345", S("12345")); @@ -42,9 +41,9 @@ int main(int, char**) test(S("12345678901234567890"), "12345", S("1234567890123456789012345")); test(S("12345678901234567890"), "12345678901234567890", S("1234567890123456789012345678901234567890")); - } + } #if TEST_STD_VER >= 11 - { + { typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; test(S(), "", S()); test(S(), "12345", S("12345")); @@ -58,10 +57,10 @@ int main(int, char**) test(S("12345678901234567890"), "12345", S("1234567890123456789012345")); test(S("12345678901234567890"), "12345678901234567890", S("1234567890123456789012345678901234567890")); - } + } #endif - { // test appending to self + { // test appending to self typedef std::string S; S s_short = "123/"; S s_long = "Lorem ipsum dolor sit amet, consectetur/"; @@ -75,7 +74,17 @@ int main(int, char**) s_long.append(s_long.c_str()); assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/"); - } + } + + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + // static_assert(test()); +#endif return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp index c214ab7c2ac3..69a5b93c4b15 100644 --- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp @@ -19,7 +19,7 @@ #include "min_allocator.h" template <class S> -void +TEST_CONSTEXPR_CXX20 void test(S s, const typename S::value_type* str, typename S::size_type n, S expected) { s.append(str, n); @@ -27,9 +27,8 @@ test(S s, const typename S::value_type* str, typename S::size_type n, S expected assert(s == expected); } -int main(int, char**) -{ - { +bool test() { + { typedef std::string S; test(S(), "", 0, S()); test(S(), "12345", 3, S("123")); @@ -47,9 +46,9 @@ int main(int, char**) test(S("12345678901234567890"), "12345", 5, S("1234567890123456789012345")); test(S("12345678901234567890"), "12345678901234567890", 20, S("1234567890123456789012345678901234567890")); - } + } #if TEST_STD_VER >= 11 - { + { typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; test(S(), "", 0, S()); test(S(), "12345", 3, S("123")); @@ -67,10 +66,10 @@ int main(int, char**) test(S("12345678901234567890"), "12345", 5, S("1234567890123456789012345")); test(S("12345678901234567890"), "12345678901234567890", 20, S("1234567890123456789012345678901234567890")); - } + } #endif - { // test appending to self + { // test appending to self typedef std::string S; S s_short = "123/"; S s_long = "Lorem ipsum dolor sit amet, consectetur/"; @@ -84,7 +83,17 @@ int main(int, char**) s_long.append(s_long.data(), s_long.size()); assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/"); - } + } + + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + // static_assert(test()); +#endif return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp index 6da03847e0d2..55506b37d25d 100644 --- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp @@ -23,7 +23,7 @@ struct veryLarge }; template <class S> -void +TEST_CONSTEXPR_CXX20 void test(S s, typename S::value_type c, S expected) { s.push_back(c); @@ -31,31 +31,40 @@ test(S s, typename S::value_type c, S expected) assert(s == expected); } -int main(int, char**) -{ - { +bool test() { + { typedef std::string S; test(S(), 'a', S(1, 'a')); test(S("12345"), 'a', S("12345a")); test(S("12345678901234567890"), 'a', S("12345678901234567890a")); - } + } #if TEST_STD_VER >= 11 - { + { typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; test(S(), 'a', S(1, 'a')); test(S("12345"), 'a', S("12345a")); test(S("12345678901234567890"), 'a', S("12345678901234567890a")); - } + } #endif - { + { // https://llvm.org/PR31454 std::basic_string<veryLarge> s; veryLarge vl = {}; s.push_back(vl); s.push_back(vl); s.push_back(vl); - } + } + + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + // static_assert(test()); +#endif return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp index c40624892917..5b66e686dd07 100644 --- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp @@ -18,7 +18,7 @@ #include "min_allocator.h" template <class S> -void +TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type n, typename S::value_type c, S expected) { s.append(n, c); @@ -26,9 +26,8 @@ test(S s, typename S::size_type n, typename S::value_type c, S expected) assert(s == expected); } -int main(int, char**) -{ - { +bool test() { + { typedef std::string S; test(S(), 0, 'a', S()); test(S(), 1, 'a', S(1, 'a')); @@ -42,9 +41,9 @@ int main(int, char**) test(S("12345678901234567890"), 0, 'a', S("12345678901234567890")); test(S("12345678901234567890"), 1, 'a', S("12345678901234567890a")); test(S("12345678901234567890"), 10, 'a', S("12345678901234567890aaaaaaaaaa")); - } + } #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(1, 'a')); @@ -58,7 +57,17 @@ int main(int, char**) test(S("12345678901234567890"), 0, 'a', S("12345678901234567890")); test(S("12345678901234567890"), 1, 'a', S("12345678901234567890a")); test(S("12345678901234567890"), 10, 'a', S("12345678901234567890aaaaaaaaaa")); - } + } +#endif + + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + // static_assert(test()); #endif return 0; diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp index 5e551d7a2b12..8c4bbf1d2b09 100644 --- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp @@ -18,7 +18,7 @@ #include "min_allocator.h" template <class S> -void +TEST_CONSTEXPR_CXX20 void test(S s, S str, S expected) { s.append(str); @@ -26,9 +26,8 @@ test(S s, S str, S expected) assert(s == expected); } -int main(int, char**) -{ - { +bool test() { + { typedef std::string S; test(S(), S(), S()); test(S(), S("12345"), S("12345")); @@ -50,9 +49,9 @@ int main(int, char**) test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890")); test(S("12345678901234567890"), S("12345678901234567890"), S("1234567890123456789012345678901234567890")); - } + } #if TEST_STD_VER >= 11 - { + { typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; test(S(), S(), S()); test(S(), S("12345"), S("12345")); @@ -74,16 +73,26 @@ int main(int, char**) test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890")); test(S("12345678901234567890"), S("12345678901234567890"), S("1234567890123456789012345678901234567890")); - } + } #endif #if TEST_STD_VER > 3 - { // LWG 2946 + { // LWG 2946 std::string s; s.append({"abc", 1}); assert(s.size() == 1); assert(s == "a"); - } + } +#endif + + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + // static_assert(test()); #endif return 0; diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp index 37985d00115c..a6ed128ee7ec 100644 --- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp @@ -20,7 +20,7 @@ #include "min_allocator.h" template <class S> -void +TEST_CONSTEXPR_CXX20 void test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected) { if (pos <= str.size()) @@ -46,7 +46,7 @@ test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected) } template <class S> -void +TEST_CONSTEXPR_CXX20 void test_npos(S s, S str, typename S::size_type pos, S expected) { if (pos <= str.size()) @@ -71,9 +71,8 @@ test_npos(S s, S str, typename S::size_type pos, S expected) #endif } -int main(int, char**) -{ - { +bool test() { + { typedef std::string S; test(S(), S(), 0, 0, S()); test(S(), S(), 1, 0, S()); @@ -96,9 +95,9 @@ int main(int, char**) test(S("12345678901234567890"), S("12345"), 1, 3, S("12345678901234567890234")); test(S("12345678901234567890"), S("12345678901234567890"), 5, 10, S("123456789012345678906789012345")); - } + } #if TEST_STD_VER >= 11 - { + { typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; test(S(), S(), 0, 0, S()); test(S(), S(), 1, 0, S()); @@ -121,9 +120,9 @@ int main(int, char**) test(S("12345678901234567890"), S("12345"), 1, 3, S("12345678901234567890234")); test(S("12345678901234567890"), S("12345678901234567890"), 5, 10, S("123456789012345678906789012345")); - } + } #endif - { + { typedef std::string S; test_npos(S(), S(), 0, S()); test_npos(S(), S(), 1, S()); @@ -132,7 +131,17 @@ int main(int, char**) test_npos(S(), S("12345"), 3, S("45")); test_npos(S(), S("12345"), 5, S("")); test_npos(S(), S("12345"), 6, S("not happening")); - } + } + + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + // static_assert(test()); +#endif return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_view.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_view.pass.cpp index d0fb1cc3315e..7c0f6c2f027b 100644 --- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_view.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_view.pass.cpp @@ -19,7 +19,7 @@ #include "min_allocator.h" template <class S, class SV> -void +TEST_CONSTEXPR_CXX20 void test(S s, SV sv, S expected) { s.append(sv); @@ -27,9 +27,8 @@ test(S s, SV sv, S expected) assert(s == expected); } -int main(int, char**) -{ - { +bool test() { + { typedef std::string S; typedef std::string_view SV; test(S(), SV(), S()); @@ -52,9 +51,9 @@ int main(int, char**) test(S("12345678901234567890"), SV("1234567890"), S("123456789012345678901234567890")); test(S("12345678901234567890"), SV("12345678901234567890"), S("1234567890123456789012345678901234567890")); - } + } #if TEST_STD_VER >= 11 - { + { typedef std::basic_string <char, std::char_traits<char>, min_allocator<char>> S; typedef std::basic_string_view<char, std::char_traits<char> > SV; test(S(), SV(), S()); @@ -77,7 +76,17 @@ int main(int, char**) test(S("12345678901234567890"), SV("1234567890"), S("123456789012345678901234567890")); test(S("12345678901234567890"), SV("12345678901234567890"), S("1234567890123456789012345678901234567890")); - } + } +#endif + + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + // static_assert(test()); #endif return 0; |
