| 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 |
// <string> |
| 10 |
|
| 11 |
// size_type find_last_of(charT c, size_type pos = npos) const; // constexpr since C++20 |
| 12 |
|
| 13 |
#include <string> |
| 14 |
#include <cassert> |
| 15 |
|
| 16 |
#include "test_macros.h" |
| 17 |
#include "min_allocator.h" |
| 18 |
|
| 19 |
template <class S> |
| 20 |
TEST_CONSTEXPR_CXX20 void |
| 21 |
test(const S& s, typename S::value_type c, typename S::size_type pos, typename S::size_type x) { |
| 22 |
LIBCPP_ASSERT_NOEXCEPT(s.find_last_of(c, pos)); |
| 23 |
assert(s.find_last_of(c, pos) == x); |
| 24 |
if (x != S::npos) |
| 25 |
assert(x <= pos && x < s.size()); |
| 26 |
} |
| 27 |
|
| 28 |
template <class S> |
| 29 |
TEST_CONSTEXPR_CXX20 void test(const S& s, typename S::value_type c, typename S::size_type x) { |
| 30 |
LIBCPP_ASSERT_NOEXCEPT(s.find_last_of(c)); |
| 31 |
assert(s.find_last_of(c) == x); |
| 32 |
if (x != S::npos) |
| 33 |
assert(x < s.size()); |
| 34 |
} |
| 35 |
|
| 36 |
template <class S> |
| 37 |
TEST_CONSTEXPR_CXX20 void test_string() { |
| 38 |
test(S(""), 'm', 0, S::npos); |
| 39 |
test(S(""), 'm', 1, S::npos); |
| 40 |
test(S("kitcj"), 'm', 0, S::npos); |
| 41 |
test(S("qkamf"), 'm', 1, S::npos); |
| 42 |
test(S("nhmko"), 'm', 2, 2); |
| 43 |
test(S("tpsaf"), 'm', 4, S::npos); |
| 44 |
test(S("lahfb"), 'm', 5, S::npos); |
| 45 |
test(S("irkhs"), 'm', 6, S::npos); |
| 46 |
test(S("gmfhdaipsr"), 'm', 0, S::npos); |
| 47 |
test(S("kantesmpgj"), 'm', 1, S::npos); |
| 48 |
test(S("odaftiegpm"), 'm', 5, S::npos); |
| 49 |
test(S("oknlrstdpi"), 'm', 9, S::npos); |
| 50 |
test(S("eolhfgpjqk"), 'm', 10, S::npos); |
| 51 |
test(S("pcdrofikas"), 'm', 11, S::npos); |
| 52 |
test(S("nbatdlmekrgcfqsophij"), 'm', 0, S::npos); |
| 53 |
test(S("bnrpehidofmqtcksjgla"), 'm', 1, S::npos); |
| 54 |
test(S("jdmciepkaqgotsrfnhlb"), 'm', 10, 2); |
| 55 |
test(S("jtdaefblsokrmhpgcnqi"), 'm', 19, 12); |
| 56 |
test(S("hkbgspofltajcnedqmri"), 'm', 20, 17); |
| 57 |
test(S("oselktgbcapndfjihrmq"), 'm', 21, 18); |
| 58 |
|
| 59 |
test(S(""), 'm', S::npos); |
| 60 |
test(S("csope"), 'm', S::npos); |
| 61 |
test(S("gfsmthlkon"), 'm', 3); |
| 62 |
test(S("laenfsbridchgotmkqpj"), 'm', 15); |
| 63 |
} |
| 64 |
|
| 65 |
TEST_CONSTEXPR_CXX20 bool test() { |
| 66 |
test_string<std::string>(); |
| 67 |
#if TEST_STD_VER >= 11 |
| 68 |
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >(); |
| 69 |
#endif |
| 70 |
|
| 71 |
return true; |
| 72 |
} |
| 73 |
|
| 74 |
int main(int, char**) { |
| 75 |
test(); |
| 76 |
#if TEST_STD_VER > 17 |
| 77 |
static_assert(test()); |
| 78 |
#endif |
| 79 |
|
| 80 |
return 0; |
| 81 |
} |