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 // bool starts_with(const CharT *x) const;
13
14 #include <string>
15 #include <cassert>
16
17 #include "test_macros.h"
18
main(int,char **)19 int main(int, char**)
20 {
21 {
22 typedef std::string S;
23 const char *s = "abcde";
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 LIBCPP_ASSERT_NOEXCEPT(s0.starts_with(""));
33
34 assert ( s0.starts_with(""));
35 assert (!s0.starts_with("a"));
36
37 assert ( s1.starts_with(""));
38 assert ( s1.starts_with("a"));
39 assert (!s1.starts_with("ab"));
40 assert (!s1.starts_with("abc"));
41 assert (!s1.starts_with("abcd"));
42 assert (!s1.starts_with("abcde"));
43 assert (!s1.starts_with("def"));
44
45 assert ( s2.starts_with(""));
46 assert ( s2.starts_with("a"));
47 assert ( s2.starts_with("ab"));
48 assert (!s2.starts_with("abc"));
49 assert (!s2.starts_with("abcd"));
50 assert (!s2.starts_with("abcde"));
51 assert (!s2.starts_with("def"));
52
53 assert ( sNot.starts_with(""));
54 assert (!sNot.starts_with("a"));
55 assert (!sNot.starts_with("ab"));
56 assert (!sNot.starts_with("abc"));
57 assert (!sNot.starts_with("abcd"));
58 assert (!sNot.starts_with("abcde"));
59 assert ( sNot.starts_with("def"));
60 }
61
62 return 0;
63 }
64