[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / strings / string.view / string.view.find / rfind_char_size.pass.cpp
blobe8229e1024e533970b96a5d66f998791e1504965
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 // <string_view>
10 // constexpr size_type rfind(charT c, size_type pos = npos) const;
12 #include <string_view>
13 #include <cassert>
15 #include "test_macros.h"
16 #include "constexpr_char_traits.h"
18 template <class S>
19 void
20 test(const S& s, typename S::value_type c, typename S::size_type pos,
21 typename S::size_type x)
23 assert(s.rfind(c, pos) == x);
24 if (x != S::npos)
25 assert(x <= pos && x + 1 <= s.size());
28 template <class S>
29 void
30 test(const S& s, typename S::value_type c, typename S::size_type x)
32 assert(s.rfind(c) == x);
33 if (x != S::npos)
34 assert(x + 1 <= s.size());
37 int main(int, char**)
40 typedef std::string_view S;
41 test(S(""), 'b', 0, S::npos);
42 test(S(""), 'b', 1, S::npos);
43 test(S("abcde"), 'b', 0, S::npos);
44 test(S("abcde"), 'b', 1, 1);
45 test(S("abcde"), 'b', 2, 1);
46 test(S("abcde"), 'b', 4, 1);
47 test(S("abcde"), 'b', 5, 1);
48 test(S("abcde"), 'b', 6, 1);
49 test(S("abcdeabcde"), 'b', 0, S::npos);
50 test(S("abcdeabcde"), 'b', 1, 1);
51 test(S("abcdeabcde"), 'b', 5, 1);
52 test(S("abcdeabcde"), 'b', 9, 6);
53 test(S("abcdeabcde"), 'b', 10, 6);
54 test(S("abcdeabcde"), 'b', 11, 6);
55 test(S("abcdeabcdeabcdeabcde"), 'b', 0, S::npos);
56 test(S("abcdeabcdeabcdeabcde"), 'b', 1, 1);
57 test(S("abcdeabcdeabcdeabcde"), 'b', 10, 6);
58 test(S("abcdeabcdeabcdeabcde"), 'b', 19, 16);
59 test(S("abcdeabcdeabcdeabcde"), 'b', 20, 16);
60 test(S("abcdeabcdeabcdeabcde"), 'b', 21, 16);
62 test(S(""), 'b', S::npos);
63 test(S("abcde"), 'b', 1);
64 test(S("abcdeabcde"), 'b', 6);
65 test(S("abcdeabcdeabcdeabcde"), 'b', 16);
68 #if TEST_STD_VER > 11
70 typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
71 constexpr SV sv1;
72 constexpr SV sv2 { "abcde", 5 };
74 static_assert (sv1.rfind( 'b', 0 ) == SV::npos, "" );
75 static_assert (sv1.rfind( 'b', 1 ) == SV::npos, "" );
76 static_assert (sv2.rfind( 'b', 0 ) == SV::npos, "" );
77 static_assert (sv2.rfind( 'b', 1 ) == 1, "" );
78 static_assert (sv2.rfind( 'b', 2 ) == 1, "" );
79 static_assert (sv2.rfind( 'b', 3 ) == 1, "" );
80 static_assert (sv2.rfind( 'b', 4 ) == 1, "" );
82 #endif
84 return 0;