From 786366b18fadc3d7c4f150e89ef49c165767a668 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Fri, 26 Aug 2022 17:48:11 +0200 Subject: [libc++][NFC] Remove some of the code duplication in the string tests Reviewed By: ldionne, #libc, huixie90 Spies: huixie90, libcxx-commits, arphaman Differential Revision: https://reviews.llvm.org/D131856 --- .../string_append/pointer.pass.cpp | 49 ++++++++-------------- 1 file changed, 18 insertions(+), 31 deletions(-) (limited to 'libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp') 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 294645f76608..526fed83daca 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,38 +26,26 @@ test(S s, const typename S::value_type* str, S expected) assert(s == expected); } -TEST_CONSTEXPR_CXX20 bool test() { - { - typedef std::string S; - test(S(), "", S()); - test(S(), "12345", S("12345")); - test(S(), "12345678901234567890", S("12345678901234567890")); - - test(S("12345"), "", S("12345")); - test(S("12345"), "12345", S("1234512345")); - test(S("12345"), "1234567890", S("123451234567890")); +template +TEST_CONSTEXPR_CXX20 void test_string() { + test(S(), "", S()); + test(S(), "12345", S("12345")); + test(S(), "12345678901234567890", S("12345678901234567890")); + + test(S("12345"), "", S("12345")); + test(S("12345"), "12345", S("1234512345")); + test(S("12345"), "1234567890", S("123451234567890")); + + test(S("12345678901234567890"), "", S("12345678901234567890")); + test(S("12345678901234567890"), "12345", S("1234567890123456789012345")); + test(S("12345678901234567890"), "12345678901234567890", + S("1234567890123456789012345678901234567890")); +} - test(S("12345678901234567890"), "", S("12345678901234567890")); - test(S("12345678901234567890"), "12345", S("1234567890123456789012345")); - test(S("12345678901234567890"), "12345678901234567890", - S("1234567890123456789012345678901234567890")); - } +TEST_CONSTEXPR_CXX20 bool test() { + test_string(); #if TEST_STD_VER >= 11 - { - typedef std::basic_string, min_allocator> S; - test(S(), "", S()); - test(S(), "12345", S("12345")); - test(S(), "12345678901234567890", S("12345678901234567890")); - - test(S("12345"), "", S("12345")); - test(S("12345"), "12345", S("1234512345")); - test(S("12345"), "1234567890", S("123451234567890")); - - test(S("12345678901234567890"), "", S("12345678901234567890")); - test(S("12345678901234567890"), "12345", S("1234567890123456789012345")); - test(S("12345678901234567890"), "12345678901234567890", - S("1234567890123456789012345678901234567890")); - } + test_string, min_allocator>>(); #endif { // test appending to self @@ -75,7 +63,6 @@ TEST_CONSTEXPR_CXX20 bool test() { s_long.append(s_long.c_str()); assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/"); } - return true; } -- cgit v1.2.3