| 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_first_of(charT c, size_type pos = 0) 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_first_of(c, pos)); |
| 23 | assert(s.find_first_of(c, pos) == x); |
| 24 | if (x != S::npos) |
| 25 | assert(pos <= x && 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_first_of(c)); |
| 31 | assert(s.find_first_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("" ), 'e', 0, S::npos); |
| 39 | test(S("" ), 'e', 1, S::npos); |
| 40 | test(S("kitcj" ), 'e', 0, S::npos); |
| 41 | test(S("qkamf" ), 'e', 1, S::npos); |
| 42 | test(S("nhmko" ), 'e', 2, S::npos); |
| 43 | test(S("tpsaf" ), 'e', 4, S::npos); |
| 44 | test(S("lahfb" ), 'e', 5, S::npos); |
| 45 | test(S("irkhs" ), 'e', 6, S::npos); |
| 46 | test(S("gmfhdaipsr" ), 'e', 0, S::npos); |
| 47 | test(S("kantesmpgj" ), 'e', 1, 4); |
| 48 | test(S("odaftiegpm" ), 'e', 5, 6); |
| 49 | test(S("oknlrstdpi" ), 'e', 9, S::npos); |
| 50 | test(S("eolhfgpjqk" ), 'e', 10, S::npos); |
| 51 | test(S("pcdrofikas" ), 'e', 11, S::npos); |
| 52 | test(S("nbatdlmekrgcfqsophij" ), 'e', 0, 7); |
| 53 | test(S("bnrpehidofmqtcksjgla" ), 'e', 1, 4); |
| 54 | test(S("jdmciepkaqgotsrfnhlb" ), 'e', 10, S::npos); |
| 55 | test(S("jtdaefblsokrmhpgcnqi" ), 'e', 19, S::npos); |
| 56 | test(S("hkbgspofltajcnedqmri" ), 'e', 20, S::npos); |
| 57 | test(S("oselktgbcapndfjihrmq" ), 'e', 21, S::npos); |
| 58 | |
| 59 | test(S("" ), 'e', S::npos); |
| 60 | test(S("csope" ), 'e', 4); |
| 61 | test(S("gfsmthlkon" ), 'e', S::npos); |
| 62 | test(S("laenfsbridchgotmkqpj" ), 'e', 2); |
| 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 | } |
| 82 | |