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
9// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10
11// <string_view>
12
13// constexpr bool contains(const CharT *x) const;
14
15#include <string_view>
16#include <cassert>
17
18#include "test_macros.h"
19
20constexpr bool test() {
21 using SV = std::string_view;
22
23 const char* s = "abcde";
24 SV sv0;
25 SV sv1{s + 4, 1};
26 SV sv3{s + 2, 3};
27 SV svNot{"xyz", 3};
28
29 assert(sv0.contains(""));
30 assert(!sv0.contains("e"));
31
32 assert(sv1.contains(""));
33 assert(!sv1.contains("d"));
34 assert(sv1.contains("e"));
35 assert(!sv1.contains("de"));
36 assert(!sv1.contains("cd"));
37 assert(!sv1.contains("cde"));
38 assert(!sv1.contains("bcde"));
39 assert(!sv1.contains("abcde"));
40 assert(!sv1.contains("xyz"));
41
42 assert(sv3.contains(""));
43 assert(sv3.contains("d"));
44 assert(sv3.contains("e"));
45 assert(sv3.contains("de"));
46 assert(sv3.contains("cd"));
47 assert(!sv3.contains("ce"));
48 assert(sv3.contains("cde"));
49 assert(!sv3.contains("edc"));
50 assert(!sv3.contains("bcde"));
51 assert(!sv3.contains("abcde"));
52 assert(!sv3.contains("xyz"));
53
54 assert(svNot.contains(""));
55 assert(!svNot.contains("d"));
56 assert(!svNot.contains("e"));
57 assert(!svNot.contains("de"));
58 assert(!svNot.contains("cd"));
59 assert(!svNot.contains("cde"));
60 assert(!svNot.contains("bcde"));
61 assert(!svNot.contains("abcde"));
62 assert(svNot.contains("xyz"));
63 assert(!svNot.contains("zyx"));
64
65 return true;
66}
67
68int main(int, char**) {
69 test();
70 static_assert(test());
71
72 return 0;
73}
74

source code of libcxx/test/std/strings/string.view/string.view.template/contains.ptr.pass.cpp