[libc++] Prepare string.{access, capacity, cons} tests for constexpr

Reviewed By: ldionne, #libc

Spies: libcxx-commits, arphaman

Differential Revision: https://reviews.llvm.org/D119123
This commit is contained in:
Nikolas Klauser committed 2022-02-08 23:39:44 +01:00
1 parent ca9f0ec1a3
commit e85018b7dd
42 files changed
+734 -361

No files matched your search

@@ -36,9 +36,8 @@
#include "../cpp17_input_iterator.h"
#include "min_allocator.h"
int main(int, char**)
{
{
bool test() {
{
std::string_view sv = "12345678901234";
std::basic_string s1(sv);
using S = decltype(s1); // what type did we get?
@@ -47,9 +46,9 @@ int main(int, char**)
static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, "");
assert(s1.size() == sv.size());
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
}
{
{
std::string_view sv = "12345678901234";
std::basic_string s1{sv, std::allocator<char>{}};
using S = decltype(s1); // what type did we get?
@@ -58,9 +57,9 @@ int main(int, char**)
static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, "");
assert(s1.size() == sv.size());
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
}
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
{
{
std::wstring_view sv = L"12345678901234";
std::basic_string s1{sv, test_allocator<wchar_t>{}};
using S = decltype(s1); // what type did we get?
@@ -69,10 +68,10 @@ int main(int, char**)
static_assert(std::is_same_v<S::allocator_type, test_allocator<wchar_t>>, "");
assert(s1.size() == sv.size());
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
}
#endif
#if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
{
{
std::u8string_view sv = u8"12345678901234";
std::basic_string s1{sv, min_allocator<char8_t>{}};
using S = decltype(s1); // what type did we get?
@@ -81,9 +80,9 @@ int main(int, char**)
static_assert(std::is_same_v<S::allocator_type, min_allocator<char8_t>>, "");
assert(s1.size() == sv.size());
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
}
#endif
{
{
std::u16string_view sv = u"12345678901234";
std::basic_string s1{sv, min_allocator<char16_t>{}};
using S = decltype(s1); // what type did we get?
@@ -92,8 +91,8 @@ int main(int, char**)
static_assert(std::is_same_v<S::allocator_type, min_allocator<char16_t>>, "");
assert(s1.size() == sv.size());
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
{
}
{
std::u32string_view sv = U"12345678901234";
std::basic_string s1{sv, explicit_allocator<char32_t>{}};
using S = decltype(s1); // what type did we get?
@@ -102,7 +101,17 @@ int main(int, char**)
static_assert(std::is_same_v<S::allocator_type, explicit_allocator<char32_t>>, "");
assert(s1.size() == sv.size());
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
}