Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.starts_with / starts_with.string_view.pass.cpp
blobc09afbae378498f8457c4f614d0e11005e69b987
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
10 // <string>
12 // constexpr bool starts_with(string_view x) const noexcept;
14 #include <string>
15 #include <cassert>
17 #include "test_macros.h"
19 template <class CharT, template <class> class Alloc>
20 constexpr void test_string() {
21 using S = std::basic_string<CharT, std::char_traits<CharT>, Alloc<CharT> >;
22 using SV = std::basic_string_view<CharT, std::char_traits<CharT> >;
23 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};
33 SV sv0;
34 SV sv1{s, 1};
35 SV sv2{s, 2};
36 SV sv3{s, 3};
37 SV sv4{s, 4};
38 SV sv5{s, 5};
39 SV svNot{"def", 3};
41 ASSERT_NOEXCEPT(s0.starts_with(sv0));
43 assert(s0.starts_with(sv0));
44 assert(!s0.starts_with(sv1));
46 assert(s1.starts_with(sv0));
47 assert(s1.starts_with(sv1));
48 assert(!s1.starts_with(sv2));
49 assert(!s1.starts_with(sv3));
50 assert(!s1.starts_with(sv4));
51 assert(!s1.starts_with(sv5));
52 assert(!s1.starts_with(svNot));
54 assert(s2.starts_with(sv0));
55 assert(s2.starts_with(sv1));
56 assert(s2.starts_with(sv2));
57 assert(!s2.starts_with(sv3));
58 assert(!s2.starts_with(sv4));
59 assert(!s2.starts_with(sv5));
60 assert(!s2.starts_with(svNot));
62 assert(sNot.starts_with(sv0));
63 assert(!sNot.starts_with(sv1));
64 assert(!sNot.starts_with(sv2));
65 assert(!sNot.starts_with(sv3));
66 assert(!sNot.starts_with(sv4));
67 assert(!sNot.starts_with(sv5));
68 assert(sNot.starts_with(svNot));
71 constexpr bool test() {
72 test_string<char, std::allocator>();
74 return true;
77 int main(int, char**) {
78 test();
79 static_assert(test());
81 return 0;