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 
test()19 constexpr bool test() {
20     typedef std::string S;
21     typedef std::string_view SV;
22     const char *s = "abcde";
23 
24     S   s0;
25     S   s1  { s, 1 };
26     S   s2  { s, 2 };
27 //  S   s3  { s, 3 };
28 //  S   s4  { s, 4 };
29 //  S   s5  { s, 5 };
30     S  sNot { "def", 3 };
31 
32     SV  sv0;
33     SV  sv1 { s, 1 };
34     SV  sv2 { s, 2 };
35     SV  sv3 { s, 3 };
36     SV  sv4 { s, 4 };
37     SV  sv5 { s, 5 };
38     SV svNot {"def", 3 };
39 
40     ASSERT_NOEXCEPT(s0.starts_with(sv0));
41 
42     assert ( s0.starts_with(sv0));
43     assert (!s0.starts_with(sv1));
44 
45     assert ( s1.starts_with(sv0));
46     assert ( s1.starts_with(sv1));
47     assert (!s1.starts_with(sv2));
48     assert (!s1.starts_with(sv3));
49     assert (!s1.starts_with(sv4));
50     assert (!s1.starts_with(sv5));
51     assert (!s1.starts_with(svNot));
52 
53     assert ( s2.starts_with(sv0));
54     assert ( s2.starts_with(sv1));
55     assert ( s2.starts_with(sv2));
56     assert (!s2.starts_with(sv3));
57     assert (!s2.starts_with(sv4));
58     assert (!s2.starts_with(sv5));
59     assert (!s2.starts_with(svNot));
60 
61     assert ( sNot.starts_with(sv0));
62     assert (!sNot.starts_with(sv1));
63     assert (!sNot.starts_with(sv2));
64     assert (!sNot.starts_with(sv3));
65     assert (!sNot.starts_with(sv4));
66     assert (!sNot.starts_with(sv5));
67     assert ( sNot.starts_with(svNot));
68 
69     return true;
70 }
71 
main(int,char **)72 int main(int, char**)
73 {
74   test();
75   static_assert(test());
76 
77   return 0;
78 }
79