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(const CharT *x) const;
13 
14 #include <string>
15 #include <cassert>
16 
17 #include "test_macros.h"
18 
test()19 constexpr bool test() {
20   {
21     typedef std::string S;
22     const char *s = "abcde";
23     S  s0 {};
24     S  s1 { s, 1 };
25     S  s2 { s, 2 };
26 //     S  s3 { s, 3 };
27 //     S  s4 { s, 4 };
28 //     S  s5 { s, 5 };
29     S  sNot {"def", 3 };
30 
31     LIBCPP_ASSERT_NOEXCEPT(s0.starts_with(""));
32 
33     assert ( s0.starts_with(""));
34     assert (!s0.starts_with("a"));
35 
36     assert ( s1.starts_with(""));
37     assert ( s1.starts_with("a"));
38     assert (!s1.starts_with("ab"));
39     assert (!s1.starts_with("abc"));
40     assert (!s1.starts_with("abcd"));
41     assert (!s1.starts_with("abcde"));
42     assert (!s1.starts_with("def"));
43 
44     assert ( s2.starts_with(""));
45     assert ( s2.starts_with("a"));
46     assert ( s2.starts_with("ab"));
47     assert (!s2.starts_with("abc"));
48     assert (!s2.starts_with("abcd"));
49     assert (!s2.starts_with("abcde"));
50     assert (!s2.starts_with("def"));
51 
52     assert ( sNot.starts_with(""));
53     assert (!sNot.starts_with("a"));
54     assert (!sNot.starts_with("ab"));
55     assert (!sNot.starts_with("abc"));
56     assert (!sNot.starts_with("abcd"));
57     assert (!sNot.starts_with("abcde"));
58     assert ( sNot.starts_with("def"));
59   }
60 
61   return true;
62 }
63 
main(int,char **)64 int main(int, char**)
65 {
66   test();
67   static_assert(test());
68 
69   return 0;
70 }
71