1515#include < cassert>
1616#include < string>
1717
18- #include " asan_testing.h"
1918#include " constexpr_char_traits.h"
2019#include " make_string.h"
2120#include " min_allocator.h"
@@ -28,11 +27,30 @@ template <typename CharT, typename TraitsT, typename AllocT>
2827constexpr void test () {
2928 std::basic_string<CharT, TraitsT, AllocT> s{CS (" Hello cruel world!" ), AllocT{}};
3029
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+ }
3334
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+ }
3654}
3755
3856template <typename CharT>
0 commit comments