|
15 | 15 | #include <cassert> |
16 | 16 | #include <string> |
17 | 17 |
|
| 18 | +#include "asan_testing.h" |
| 19 | +#include "constexpr_char_traits.h" |
| 20 | +#include "make_string.h" |
| 21 | +#include "min_allocator.h" |
| 22 | +#include "test_allocator.h" |
| 23 | +#include "test_macros.h" |
| 24 | + |
| 25 | +#define CS(S) MAKE_CSTRING(CharT, S) |
| 26 | + |
| 27 | +template <typename CharT, typename TraitsT, typename AllocT> |
| 28 | +constexpr void test() { |
| 29 | + std::basic_string<CharT, TraitsT, AllocT> s{CS("Hello cruel world!"), AllocT{}}; |
| 30 | + |
| 31 | + std::same_as<std::basic_string_view<CharT, TraitsT>> decltype(auto) sv = s.subview(6); |
| 32 | + assert(sv == CS("cruel world!")); |
| 33 | + |
| 34 | + std::same_as<std::basic_string_view<CharT, TraitsT>> decltype(auto) subsv = sv.subview(0, 5); |
| 35 | + assert(subsv == CS("cruel")); |
| 36 | +} |
| 37 | + |
| 38 | +template <typename CharT> |
| 39 | +constexpr void test() { |
| 40 | + test<CharT, std::char_traits<CharT>, std::allocator<CharT>>(); |
| 41 | + test<CharT, std::char_traits<CharT>, min_allocator<CharT>>(); |
| 42 | + test<CharT, std::char_traits<CharT>, safe_allocator<CharT>>(); |
| 43 | + test<CharT, std::char_traits<CharT>, test_allocator<CharT>>(); |
| 44 | + |
| 45 | + test<CharT, constexpr_char_traits<CharT>, std::allocator<CharT>>(); |
| 46 | + test<CharT, constexpr_char_traits<CharT>, min_allocator<CharT>>(); |
| 47 | + test<CharT, constexpr_char_traits<CharT>, safe_allocator<CharT>>(); |
| 48 | + test<CharT, constexpr_char_traits<CharT>, test_allocator<CharT>>(); |
| 49 | +} |
| 50 | + |
18 | 51 | constexpr bool test() { |
19 | | - std::string s{"Hello cruel world!"}; |
20 | | - auto sub = s.subview(6); |
21 | | - assert(sub == "cruel world!"); |
22 | | - auto subsub = sub.subview(0, 5); |
23 | | - assert(subsub == "cruel"); |
| 52 | + test<char>(); |
| 53 | +#ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 54 | + test<wchar_t>(); |
| 55 | +#endif |
| 56 | +#ifndef TEST_HAS_NO_CHAR8_T |
| 57 | + test<char8_t>(); |
| 58 | +#endif |
| 59 | + test<char16_t>(); |
| 60 | + test<char32_t>(); |
24 | 61 |
|
25 | 62 | return true; |
26 | 63 | } |
|
0 commit comments