| 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_not_of(const charT* s, 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, const typename S::value_type* str, typename S::size_type pos, typename S::size_type x) { |
| 22 | LIBCPP_ASSERT_NOEXCEPT(s.find_first_not_of(str, pos)); |
| 23 | assert(s.find_first_not_of(str, 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, const typename S::value_type* str, typename S::size_type x) { |
| 30 | assert(s.find_first_not_of(str) == x); |
| 31 | if (x != S::npos) |
| 32 | assert(x < s.size()); |
| 33 | } |
| 34 | |
| 35 | template <class S> |
| 36 | TEST_CONSTEXPR_CXX20 void test0() { |
| 37 | test(S("" ), "" , 0, S::npos); |
| 38 | test(S("" ), "laenf" , 0, S::npos); |
| 39 | test(S("" ), "pqlnkmbdjo" , 0, S::npos); |
| 40 | test(S("" ), "qkamfogpnljdcshbreti" , 0, S::npos); |
| 41 | test(S("" ), "" , 1, S::npos); |
| 42 | test(S("" ), "bjaht" , 1, S::npos); |
| 43 | test(S("" ), "hjlcmgpket" , 1, S::npos); |
| 44 | test(S("" ), "htaobedqikfplcgjsmrn" , 1, S::npos); |
| 45 | test(S("fodgq" ), "" , 0, 0); |
| 46 | test(S("qanej" ), "dfkap" , 0, 0); |
| 47 | test(S("clbao" ), "ihqrfebgad" , 0, 0); |
| 48 | test(S("mekdn" ), "ngtjfcalbseiqrphmkdo" , 0, S::npos); |
| 49 | test(S("srdfq" ), "" , 1, 1); |
| 50 | test(S("oemth" ), "ikcrq" , 1, 1); |
| 51 | test(S("cdaih" ), "dmajblfhsg" , 1, 3); |
| 52 | test(S("qohtk" ), "oqftjhdmkgsblacenirp" , 1, S::npos); |
| 53 | test(S("cshmd" ), "" , 2, 2); |
| 54 | test(S("lhcdo" ), "oebqi" , 2, 2); |
| 55 | test(S("qnsoh" ), "kojhpmbsfe" , 2, S::npos); |
| 56 | test(S("pkrof" ), "acbsjqogpltdkhinfrem" , 2, S::npos); |
| 57 | test(S("fmtsp" ), "" , 4, 4); |
| 58 | test(S("khbpm" ), "aobjd" , 4, 4); |
| 59 | test(S("pbsji" ), "pcbahntsje" , 4, 4); |
| 60 | test(S("mprdj" ), "fhepcrntkoagbmldqijs" , 4, S::npos); |
| 61 | test(S("eqmpa" ), "" , 5, S::npos); |
| 62 | test(S("omigs" ), "kocgb" , 5, S::npos); |
| 63 | test(S("onmje" ), "fbslrjiqkm" , 5, S::npos); |
| 64 | test(S("oqmrj" ), "jeidpcmalhfnqbgtrsko" , 5, S::npos); |
| 65 | test(S("schfa" ), "" , 6, S::npos); |
| 66 | test(S("igdsc" ), "qngpd" , 6, S::npos); |
| 67 | test(S("brqgo" ), "rodhqklgmb" , 6, S::npos); |
| 68 | test(S("tnrph" ), "thdjgafrlbkoiqcspmne" , 6, S::npos); |
| 69 | test(S("hcjitbfapl" ), "" , 0, 0); |
| 70 | test(S("daiprenocl" ), "ashjd" , 0, 2); |
| 71 | test(S("litpcfdghe" ), "mgojkldsqh" , 0, 1); |
| 72 | test(S("aidjksrolc" ), "imqnaghkfrdtlopbjesc" , 0, S::npos); |
| 73 | test(S("qpghtfbaji" ), "" , 1, 1); |
| 74 | test(S("gfshlcmdjr" ), "nadkh" , 1, 1); |
| 75 | test(S("nkodajteqp" ), "ofdrqmkebl" , 1, 4); |
| 76 | test(S("gbmetiprqd" ), "bdfjqgatlksriohemnpc" , 1, S::npos); |
| 77 | test(S("crnklpmegd" ), "" , 5, 5); |
| 78 | test(S("jsbtafedoc" ), "prqgn" , 5, 5); |
| 79 | test(S("qnmodrtkeb" ), "pejafmnokr" , 5, 6); |
| 80 | test(S("cpebqsfmnj" ), "odnqkgijrhabfmcestlp" , 5, S::npos); |
| 81 | test(S("lmofqdhpki" ), "" , 9, 9); |
| 82 | test(S("hnefkqimca" ), "rtjpa" , 9, S::npos); |
| 83 | test(S("drtasbgmfp" ), "ktsrmnqagd" , 9, 9); |
| 84 | test(S("lsaijeqhtr" ), "rtdhgcisbnmoaqkfpjle" , 9, S::npos); |
| 85 | test(S("elgofjmbrq" ), "" , 10, S::npos); |
| 86 | test(S("mjqdgalkpc" ), "dplqa" , 10, S::npos); |
| 87 | test(S("kthqnfcerm" ), "dkacjoptns" , 10, S::npos); |
| 88 | test(S("dfsjhanorc" ), "hqfimtrgnbekpdcsjalo" , 10, S::npos); |
| 89 | test(S("eqsgalomhb" ), "" , 11, S::npos); |
| 90 | test(S("akiteljmoh" ), "lofbc" , 11, S::npos); |
| 91 | test(S("hlbdfreqjo" ), "astoegbfpn" , 11, S::npos); |
| 92 | test(S("taqobhlerg" ), "pdgreqomsncafklhtibj" , 11, S::npos); |
| 93 | test(S("snafbdlghrjkpqtoceim" ), "" , 0, 0); |
| 94 | test(S("aemtbrgcklhndjisfpoq" ), "lbtqd" , 0, 0); |
| 95 | test(S("pnracgfkjdiholtbqsem" ), "tboimldpjh" , 0, 1); |
| 96 | test(S("dicfltehbsgrmojnpkaq" ), "slcerthdaiqjfnobgkpm" , 0, S::npos); |
| 97 | test(S("jlnkraeodhcspfgbqitm" ), "" , 1, 1); |
| 98 | test(S("lhosrngtmfjikbqpcade" ), "aqibs" , 1, 1); |
| 99 | test(S("rbtaqjhgkneisldpmfoc" ), "gtfblmqinc" , 1, 3); |
| 100 | test(S("gpifsqlrdkbonjtmheca" ), "mkqpbtdalgniorhfescj" , 1, S::npos); |
| 101 | test(S("hdpkobnsalmcfijregtq" ), "" , 10, 10); |
| 102 | test(S("jtlshdgqaiprkbcoenfm" ), "pblas" , 10, 11); |
| 103 | test(S("fkdrbqltsgmcoiphneaj" ), "arosdhcfme" , 10, 13); |
| 104 | test(S("crsplifgtqedjohnabmk" ), "blkhjeogicatqfnpdmsr" , 10, S::npos); |
| 105 | test(S("niptglfbosehkamrdqcj" ), "" , 19, 19); |
| 106 | test(S("copqdhstbingamjfkler" ), "djkqc" , 19, 19); |
| 107 | test(S("mrtaefilpdsgocnhqbjk" ), "lgokshjtpb" , 19, S::npos); |
| 108 | test(S("kojatdhlcmigpbfrqnes" ), "bqjhtkfepimcnsgrlado" , 19, S::npos); |
| 109 | test(S("eaintpchlqsbdgrkjofm" ), "" , 20, S::npos); |
| 110 | test(S("gjnhidfsepkrtaqbmclo" ), "nocfa" , 20, S::npos); |
| 111 | test(S("spocfaktqdbiejlhngmr" ), "bgtajmiedc" , 20, S::npos); |
| 112 | test(S("rphmlekgfscndtaobiqj" ), "lsckfnqgdahejiopbtmr" , 20, S::npos); |
| 113 | test(S("liatsqdoegkmfcnbhrpj" ), "" , 21, S::npos); |
| 114 | test(S("binjagtfldkrspcomqeh" ), "gfsrt" , 21, S::npos); |
| 115 | test(S("latkmisecnorjbfhqpdg" ), "pfsocbhjtm" , 21, S::npos); |
| 116 | test(S("lecfratdjkhnsmqpoigb" ), "tpflmdnoicjgkberhqsa" , 21, S::npos); |
| 117 | } |
| 118 | |
| 119 | template <class S> |
| 120 | TEST_CONSTEXPR_CXX20 void test1() { |
| 121 | test(S("" ), "" , S::npos); |
| 122 | test(S("" ), "laenf" , S::npos); |
| 123 | test(S("" ), "pqlnkmbdjo" , S::npos); |
| 124 | test(S("" ), "qkamfogpnljdcshbreti" , S::npos); |
| 125 | test(S("nhmko" ), "" , 0); |
| 126 | test(S("lahfb" ), "irkhs" , 0); |
| 127 | test(S("gmfhd" ), "kantesmpgj" , 2); |
| 128 | test(S("odaft" ), "oknlrstdpiqmjbaghcfe" , S::npos); |
| 129 | test(S("eolhfgpjqk" ), "" , 0); |
| 130 | test(S("nbatdlmekr" ), "bnrpe" , 2); |
| 131 | test(S("jdmciepkaq" ), "jtdaefblso" , 2); |
| 132 | test(S("hkbgspoflt" ), "oselktgbcapndfjihrmq" , S::npos); |
| 133 | test(S("gprdcokbnjhlsfmtieqa" ), "" , 0); |
| 134 | test(S("qjghlnftcaismkropdeb" ), "bjaht" , 0); |
| 135 | test(S("pnalfrdtkqcmojiesbhg" ), "hjlcmgpket" , 1); |
| 136 | test(S("pniotcfrhqsmgdkjbael" ), "htaobedqikfplcgjsmrn" , S::npos); |
| 137 | } |
| 138 | |
| 139 | template <class S> |
| 140 | TEST_CONSTEXPR_CXX20 void test_string() { |
| 141 | test0<S>(); |
| 142 | test1<S>(); |
| 143 | } |
| 144 | |
| 145 | TEST_CONSTEXPR_CXX20 bool test() { |
| 146 | test_string<std::string>(); |
| 147 | #if TEST_STD_VER >= 11 |
| 148 | test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >(); |
| 149 | #endif |
| 150 | |
| 151 | return true; |
| 152 | } |
| 153 | |
| 154 | int main(int, char**) { |
| 155 | test(); |
| 156 | #if TEST_STD_VER > 17 |
| 157 | static_assert(test()); |
| 158 | #endif |
| 159 | |
| 160 | return 0; |
| 161 | } |
| 162 | |