summaryrefslogtreecommitdiff
path: root/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp
diff options
context:
space:
mode:
authorNikolas Klauser <nikolasklauser@berlin.de>2022-08-26 17:48:11 +0200
committerNikolas Klauser <nikolasklauser@berlin.de>2022-08-26 21:57:42 +0200
commit786366b18fadc3d7c4f150e89ef49c165767a668 (patch)
tree5472f5565b49545a15fb5e638838eae697711967 /libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp
parent9343ec861a2e47f05b3b4339f45f6e755b1c5f96 (diff)
[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
Diffstat (limited to 'libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp')
-rw-r--r--libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp49
1 files changed, 18 insertions, 31 deletions
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 <class S>
+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<std::string>();
#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"));
- 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<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
#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;
}