Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / strings / string.view / string.view.find / find_pointer_size.pass.cpp
bloba144aaf46d964c20bf89ecae871354e4a16b93cd
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
11 // <string_view>
13 // constexpr size_type find(const charT* s, size_type pos = 0) const;
15 #include <string_view>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "constexpr_char_traits.h"
21 template <class S>
22 void test(const S& s, const typename S::value_type* str, typename S::size_type pos, typename S::size_type x) {
23 LIBCPP_ASSERT_NOEXCEPT(s.find(str, pos));
24 assert(s.find(str, pos) == x);
25 if (x != S::npos) {
26 typename S::size_type n = S::traits_type::length(str);
27 assert(pos <= x && x + n <= s.size());
31 template <class S>
32 void test(const S& s, const typename S::value_type* str, typename S::size_type x) {
33 LIBCPP_ASSERT_NOEXCEPT(s.find(str));
34 assert(s.find(str) == x);
35 if (x != S::npos) {
36 typename S::size_type n = S::traits_type::length(str);
37 assert(0 <= x && x + n <= s.size());
41 template <class S>
42 void test0() {
43 test(S(""), "", 0, 0);
44 test(S(""), "abcde", 0, S::npos);
45 test(S(""), "abcdeabcde", 0, S::npos);
46 test(S(""), "abcdeabcdeabcdeabcde", 0, S::npos);
47 test(S(""), "", 1, S::npos);
48 test(S(""), "abcde", 1, S::npos);
49 test(S(""), "abcdeabcde", 1, S::npos);
50 test(S(""), "abcdeabcdeabcdeabcde", 1, S::npos);
51 test(S("abcde"), "", 0, 0);
52 test(S("abcde"), "abcde", 0, 0);
53 test(S("abcde"), "abcdeabcde", 0, S::npos);
54 test(S("abcde"), "abcdeabcdeabcdeabcde", 0, S::npos);
55 test(S("abcde"), "", 1, 1);
56 test(S("abcde"), "abcde", 1, S::npos);
57 test(S("abcde"), "abcdeabcde", 1, S::npos);
58 test(S("abcde"), "abcdeabcdeabcdeabcde", 1, S::npos);
59 test(S("abcde"), "", 2, 2);
60 test(S("abcde"), "abcde", 2, S::npos);
61 test(S("abcde"), "abcdeabcde", 2, S::npos);
62 test(S("abcde"), "abcdeabcdeabcdeabcde", 2, S::npos);
63 test(S("abcde"), "", 4, 4);
64 test(S("abcde"), "abcde", 4, S::npos);
65 test(S("abcde"), "abcdeabcde", 4, S::npos);
66 test(S("abcde"), "abcdeabcdeabcdeabcde", 4, S::npos);
67 test(S("abcde"), "", 5, 5);
68 test(S("abcde"), "abcde", 5, S::npos);
69 test(S("abcde"), "abcdeabcde", 5, S::npos);
70 test(S("abcde"), "abcdeabcdeabcdeabcde", 5, S::npos);
71 test(S("abcde"), "", 6, S::npos);
72 test(S("abcde"), "abcde", 6, S::npos);
73 test(S("abcde"), "abcdeabcde", 6, S::npos);
74 test(S("abcde"), "abcdeabcdeabcdeabcde", 6, S::npos);
75 test(S("abcdeabcde"), "", 0, 0);
76 test(S("abcdeabcde"), "abcde", 0, 0);
77 test(S("abcdeabcde"), "abcdeabcde", 0, 0);
78 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 0, S::npos);
79 test(S("abcdeabcde"), "", 1, 1);
80 test(S("abcdeabcde"), "abcde", 1, 5);
81 test(S("abcdeabcde"), "abcdeabcde", 1, S::npos);
82 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 1, S::npos);
83 test(S("abcdeabcde"), "", 5, 5);
84 test(S("abcdeabcde"), "abcde", 5, 5);
85 test(S("abcdeabcde"), "abcdeabcde", 5, S::npos);
86 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 5, S::npos);
87 test(S("abcdeabcde"), "", 9, 9);
88 test(S("abcdeabcde"), "abcde", 9, S::npos);
89 test(S("abcdeabcde"), "abcdeabcde", 9, S::npos);
90 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 9, S::npos);
91 test(S("abcdeabcde"), "", 10, 10);
92 test(S("abcdeabcde"), "abcde", 10, S::npos);
93 test(S("abcdeabcde"), "abcdeabcde", 10, S::npos);
94 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 10, S::npos);
95 test(S("abcdeabcde"), "", 11, S::npos);
96 test(S("abcdeabcde"), "abcde", 11, S::npos);
97 test(S("abcdeabcde"), "abcdeabcde", 11, S::npos);
98 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 11, S::npos);
99 test(S("abcdeabcdeabcdeabcde"), "", 0, 0);
100 test(S("abcdeabcdeabcdeabcde"), "abcde", 0, 0);
101 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 0, 0);
102 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0, 0);
103 test(S("abcdeabcdeabcdeabcde"), "", 1, 1);
104 test(S("abcdeabcdeabcdeabcde"), "abcde", 1, 5);
105 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 1, 5);
106 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 1, S::npos);
107 test(S("abcdeabcdeabcdeabcde"), "", 10, 10);
108 test(S("abcdeabcdeabcdeabcde"), "abcde", 10, 10);
109 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 10, 10);
110 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 10, S::npos);
111 test(S("abcdeabcdeabcdeabcde"), "", 19, 19);
112 test(S("abcdeabcdeabcdeabcde"), "abcde", 19, S::npos);
113 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 19, S::npos);
114 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 19, S::npos);
115 test(S("abcdeabcdeabcdeabcde"), "", 20, 20);
116 test(S("abcdeabcdeabcdeabcde"), "abcde", 20, S::npos);
117 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, S::npos);
118 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, S::npos);
119 test(S("abcdeabcdeabcdeabcde"), "", 21, S::npos);
120 test(S("abcdeabcdeabcdeabcde"), "abcde", 21, S::npos);
121 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 21, S::npos);
122 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 21, S::npos);
125 template <class S>
126 void test1() {
127 test(S(""), "", 0);
128 test(S(""), "abcde", S::npos);
129 test(S(""), "abcdeabcde", S::npos);
130 test(S(""), "abcdeabcdeabcdeabcde", S::npos);
131 test(S("abcde"), "", 0);
132 test(S("abcde"), "abcde", 0);
133 test(S("abcde"), "abcdeabcde", S::npos);
134 test(S("abcde"), "abcdeabcdeabcdeabcde", S::npos);
135 test(S("abcdeabcde"), "", 0);
136 test(S("abcdeabcde"), "abcde", 0);
137 test(S("abcdeabcde"), "abcdeabcde", 0);
138 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", S::npos);
139 test(S("abcdeabcdeabcdeabcde"), "", 0);
140 test(S("abcdeabcdeabcdeabcde"), "abcde", 0);
141 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 0);
142 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0);
145 int main(int, char**) {
147 typedef std::string_view S;
148 test0<S>();
149 test1<S>();
152 #if TEST_STD_VER > 11
154 typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
155 constexpr SV sv1;
156 constexpr SV sv2{"abcde", 5};
158 static_assert(sv1.find("") == 0, "");
159 static_assert(sv1.find("abcde") == SV::npos, "");
160 static_assert(sv2.find("") == 0, "");
161 static_assert(sv2.find("abcde") == 0, "");
162 static_assert(sv2.find("abcde", 1) == SV::npos, "");
164 #endif
166 return 0;