1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
9 
10 // <string>
11 
12 // constexpr bool starts_with(string_view x) const noexcept;
13 
14 #include <string>
15 #include <cassert>
16 
17 #include "test_macros.h"
18 
19 template <class CharT, template <class> class Alloc>
test_string()20 constexpr void test_string() {
21   using S       = std::basic_string<CharT, std::char_traits<CharT>, Alloc<CharT> >;
22   using SV      = std::basic_string_view<CharT, std::char_traits<CharT> >;
23   const char* s = "abcde";
24 
25   S s0;
26   S s1{s, 1};
27   S s2{s, 2};
28   //  S   s3  { s, 3 };
29   //  S   s4  { s, 4 };
30   //  S   s5  { s, 5 };
31   S sNot{"def", 3};
32 
33   SV sv0;
34   SV sv1{s, 1};
35   SV sv2{s, 2};
36   SV sv3{s, 3};
37   SV sv4{s, 4};
38   SV sv5{s, 5};
39   SV svNot{"def", 3};
40 
41   ASSERT_NOEXCEPT(s0.starts_with(sv0));
42 
43   assert(s0.starts_with(sv0));
44   assert(!s0.starts_with(sv1));
45 
46   assert(s1.starts_with(sv0));
47   assert(s1.starts_with(sv1));
48   assert(!s1.starts_with(sv2));
49   assert(!s1.starts_with(sv3));
50   assert(!s1.starts_with(sv4));
51   assert(!s1.starts_with(sv5));
52   assert(!s1.starts_with(svNot));
53 
54   assert(s2.starts_with(sv0));
55   assert(s2.starts_with(sv1));
56   assert(s2.starts_with(sv2));
57   assert(!s2.starts_with(sv3));
58   assert(!s2.starts_with(sv4));
59   assert(!s2.starts_with(sv5));
60   assert(!s2.starts_with(svNot));
61 
62   assert(sNot.starts_with(sv0));
63   assert(!sNot.starts_with(sv1));
64   assert(!sNot.starts_with(sv2));
65   assert(!sNot.starts_with(sv3));
66   assert(!sNot.starts_with(sv4));
67   assert(!sNot.starts_with(sv5));
68   assert(sNot.starts_with(svNot));
69 }
70 
test()71 constexpr bool test() {
72   test_string<char, std::allocator>();
73 
74   return true;
75 }
76 
main(int,char **)77 int main(int, char**) {
78   test();
79   static_assert(test());
80 
81   return 0;
82 }
83