1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
10
11 // <string>
12
13 // bool starts_with(const CharT *x) const;
14
15 #include <string>
16 #include <cassert>
17
18 #include "test_macros.h"
19
main()20 int main()
21 {
22 {
23 typedef std::string S;
24 const char *s = "abcde";
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 LIBCPP_ASSERT_NOEXCEPT(s0.starts_with(""));
34
35 assert ( s0.starts_with(""));
36 assert (!s0.starts_with("a"));
37
38 assert ( s1.starts_with(""));
39 assert ( s1.starts_with("a"));
40 assert (!s1.starts_with("ab"));
41 assert (!s1.starts_with("abc"));
42 assert (!s1.starts_with("abcd"));
43 assert (!s1.starts_with("abcde"));
44 assert (!s1.starts_with("def"));
45
46 assert ( s2.starts_with(""));
47 assert ( s2.starts_with("a"));
48 assert ( s2.starts_with("ab"));
49 assert (!s2.starts_with("abc"));
50 assert (!s2.starts_with("abcd"));
51 assert (!s2.starts_with("abcde"));
52 assert (!s2.starts_with("def"));
53
54 assert ( sNot.starts_with(""));
55 assert (!sNot.starts_with("a"));
56 assert (!sNot.starts_with("ab"));
57 assert (!sNot.starts_with("abc"));
58 assert (!sNot.starts_with("abcd"));
59 assert (!sNot.starts_with("abcde"));
60 assert ( sNot.starts_with("def"));
61 }
62 }
63