[lld/COFF] Demangle symbol name in discarded section relocation error message (#119726)
[llvm-project.git] / libcxx / test / std / strings / string.view / string.view.find / rfind_pointer_size.pass.cpp
blobf436ece805eb58efc4121a06ece1cfdab9c4a7d5
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>
12 // constexpr size_type rfind(const charT* s, size_type pos = npos) const;
14 #include <string_view>
15 #include <cassert>
17 #include "test_macros.h"
18 #include "constexpr_char_traits.h"
20 template <class S>
21 void test(const S& s, const typename S::value_type* str, typename S::size_type pos, typename S::size_type x) {
22 LIBCPP_ASSERT_NOEXCEPT(s.rfind(str, pos));
23 assert(s.rfind(str, pos) == x);
24 if (x != S::npos) {
25 typename S::size_type n = S::traits_type::length(str);
26 assert(x <= pos && x + n <= s.size());
30 template <class S>
31 void test(const S& s, const typename S::value_type* str, typename S::size_type x) {
32 LIBCPP_ASSERT_NOEXCEPT(s.rfind(str));
33 assert(s.rfind(str) == x);
34 if (x != S::npos) {
35 typename S::size_type pos = s.size();
36 typename S::size_type n = S::traits_type::length(str);
37 assert(x <= pos && 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, 0);
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, 0);
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, 0);
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, 0);
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, 0);
69 test(S("abcde"), "abcdeabcde", 5, S::npos);
70 test(S("abcde"), "abcdeabcdeabcdeabcde", 5, S::npos);
71 test(S("abcde"), "", 6, 5);
72 test(S("abcde"), "abcde", 6, 0);
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, 0);
81 test(S("abcdeabcde"), "abcdeabcde", 1, 0);
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, 0);
86 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 5, S::npos);
87 test(S("abcdeabcde"), "", 9, 9);
88 test(S("abcdeabcde"), "abcde", 9, 5);
89 test(S("abcdeabcde"), "abcdeabcde", 9, 0);
90 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 9, S::npos);
91 test(S("abcdeabcde"), "", 10, 10);
92 test(S("abcdeabcde"), "abcde", 10, 5);
93 test(S("abcdeabcde"), "abcdeabcde", 10, 0);
94 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 10, S::npos);
95 test(S("abcdeabcde"), "", 11, 10);
96 test(S("abcdeabcde"), "abcde", 11, 5);
97 test(S("abcdeabcde"), "abcdeabcde", 11, 0);
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, 0);
105 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 1, 0);
106 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 1, 0);
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, 0);
111 test(S("abcdeabcdeabcdeabcde"), "", 19, 19);
112 test(S("abcdeabcdeabcdeabcde"), "abcde", 19, 15);
113 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 19, 10);
114 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 19, 0);
115 test(S("abcdeabcdeabcdeabcde"), "", 20, 20);
116 test(S("abcdeabcdeabcdeabcde"), "abcde", 20, 15);
117 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 10);
118 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 0);
119 test(S("abcdeabcdeabcdeabcde"), "", 21, 20);
120 test(S("abcdeabcdeabcdeabcde"), "abcde", 21, 15);
121 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 21, 10);
122 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 21, 0);
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"), "", 5);
132 test(S("abcde"), "abcde", 0);
133 test(S("abcde"), "abcdeabcde", S::npos);
134 test(S("abcde"), "abcdeabcdeabcdeabcde", S::npos);
135 test(S("abcdeabcde"), "", 10);
136 test(S("abcdeabcde"), "abcde", 5);
137 test(S("abcdeabcde"), "abcdeabcde", 0);
138 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", S::npos);
139 test(S("abcdeabcdeabcdeabcde"), "", 20);
140 test(S("abcdeabcdeabcdeabcde"), "abcde", 15);
141 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 10);
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.rfind("") == 0, "");
159 static_assert(sv1.rfind("abcde") == SV::npos, "");
160 static_assert(sv2.rfind("") == 5, "");
161 static_assert(sv2.rfind("abcde") == 0, "");
162 static_assert(sv2.rfind("abcde", 1) == 0, "");
164 #endif
166 return 0;