15
15
#include < cassert>
16
16
#include < string>
17
17
18
- #include " asan_testing.h"
19
18
#include " constexpr_char_traits.h"
20
19
#include " make_string.h"
21
20
#include " min_allocator.h"
@@ -28,11 +27,30 @@ template <typename CharT, typename TraitsT, typename AllocT>
28
27
constexpr void test () {
29
28
std::basic_string<CharT, TraitsT, AllocT> s{CS (" Hello cruel world!" ), AllocT{}};
30
29
31
- std::same_as<std::basic_string_view<CharT, TraitsT>> decltype (auto ) sv = s.subview (6 );
32
- assert (sv == CS (" cruel world!" ));
30
+ { // With a default position and a character length.
31
+ std::same_as<std::basic_string_view<CharT, TraitsT>> decltype (auto ) sv = s.subview ();
32
+ assert (sv == CS (" Hello cruel world!" ));
33
+ }
33
34
34
- std::same_as<std::basic_string_view<CharT, TraitsT>> decltype (auto ) subsv = sv.subview (0 , 5 );
35
- assert (subsv == CS (" cruel" ));
35
+ { // With a explict position and a character length.
36
+ std::same_as<std::basic_string_view<CharT, TraitsT>> decltype (auto ) sv = s.subview (6 , 5 );
37
+ assert (sv == CS (" cruel" ));
38
+ }
39
+
40
+ { // From the beginning of the string with a explicit character length.
41
+ std::same_as<std::basic_string_view<CharT, TraitsT>> decltype (auto ) sv = s.subview (0 , 5 );
42
+ assert (sv == CS (" Hello" ));
43
+ }
44
+
45
+ { // To the end of string with the default character length.
46
+ std::same_as<std::basic_string_view<CharT, TraitsT>> decltype (auto ) sv = s.subview (12 );
47
+ assert (sv == CS (" world!" ));
48
+ }
49
+
50
+ { // From the beginning to the end of the string with explicit values.
51
+ std::same_as<std::basic_string_view<CharT, TraitsT>> decltype (auto ) sv = s.subview (0 , s.size ());
52
+ assert (sv == CS (" Hello cruel world!" ));
53
+ }
36
54
}
37
55
38
56
template <typename CharT>
0 commit comments