1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
12 // constexpr bool starts_with(string_view x) const noexcept;
14 #include <string_view>
17 #include "test_macros.h"
18 #include "constexpr_char_traits.h"
23 typedef std::string_view SV
;
24 const char *s
= "abcde";
33 LIBCPP_ASSERT_NOEXCEPT(sv0
.starts_with(""));
35 assert ( sv0
.starts_with(""));
36 assert (!sv0
.starts_with("a"));
38 assert ( sv1
.starts_with(""));
39 assert ( sv1
.starts_with("a"));
40 assert (!sv1
.starts_with("ab"));
41 assert (!sv1
.starts_with("abc"));
42 assert (!sv1
.starts_with("abcd"));
43 assert (!sv1
.starts_with("abcde"));
44 assert (!sv1
.starts_with("def"));
46 assert ( sv2
.starts_with(s
+ 5));
47 assert ( sv2
.starts_with("a"));
48 assert ( sv2
.starts_with("ab"));
49 assert (!sv2
.starts_with("abc"));
50 assert (!sv2
.starts_with("abcd"));
51 assert (!sv2
.starts_with("abcde"));
52 assert (!sv2
.starts_with("def"));
54 assert ( svNot
.starts_with(""));
55 assert (!svNot
.starts_with("a"));
56 assert (!svNot
.starts_with("ab"));
57 assert (!svNot
.starts_with("abc"));
58 assert (!svNot
.starts_with("abcd"));
59 assert (!svNot
.starts_with("abcde"));
60 assert ( svNot
.starts_with("def"));
65 typedef std::basic_string_view
<char, constexpr_char_traits
<char>> SV
;
66 constexpr const char *s
= "abcde";
68 constexpr SV sv1
{ s
, 1 };
69 constexpr SV sv2
{ s
, 2 };
70 // constexpr SV sv3 { s, 3 };
71 // constexpr SV sv4 { s, 4 };
72 // constexpr SV sv5 { s, 5 };
73 constexpr SV svNot
{"def", 3 };
75 static_assert ( sv0
.starts_with(""), "" );
76 static_assert (!sv0
.starts_with("a"), "" );
78 static_assert ( sv1
.starts_with(""), "" );
79 static_assert ( sv1
.starts_with("a"), "" );
80 static_assert (!sv1
.starts_with("ab"), "" );
81 static_assert (!sv1
.starts_with("abc"), "" );
82 static_assert (!sv1
.starts_with("abcd"), "" );
83 static_assert (!sv1
.starts_with("abcde"), "" );
84 static_assert (!sv1
.starts_with("def"), "" );
86 static_assert ( sv2
.starts_with(s
+ 5), "" );
87 static_assert ( sv2
.starts_with("a"), "" );
88 static_assert ( sv2
.starts_with("ab"), "" );
89 static_assert (!sv2
.starts_with("abc"), "" );
90 static_assert (!sv2
.starts_with("abcd"), "" );
91 static_assert (!sv2
.starts_with("abcde"), "" );
92 static_assert (!sv2
.starts_with("def"), "" );
94 static_assert ( svNot
.starts_with(""), "" );
95 static_assert (!svNot
.starts_with("a"), "" );
96 static_assert (!svNot
.starts_with("ab"), "" );
97 static_assert (!svNot
.starts_with("abc"), "" );
98 static_assert (!svNot
.starts_with("abcd"), "" );
99 static_assert (!svNot
.starts_with("abcde"), "" );
100 static_assert ( svNot
.starts_with("def"), "" );