Skip to content

Commit f9efc16

Browse files
committed
Updated test
1 parent 14162bf commit f9efc16

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

libcxx/test/std/strings/basic.string/string.ops/string_substr/subview.pass.cpp

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,49 @@
1515
#include <cassert>
1616
#include <string>
1717

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+
1851
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>();
2461

2562
return true;
2663
}

0 commit comments

Comments
 (0)