Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / libc++ / trunk / test / experimental / string.view / string.view.find / find_last_of_pointer_size.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <string_view>
11
12 // constexpr size_type find_last_of(const charT* s, size_type pos = npos) const;
13
14 #include <experimental/string_view>
15 #include <cassert>
16
17 #include "constexpr_char_traits.hpp"
18
19 template <class S>
20 void
21 test(const S& s, const typename S::value_type* str, typename S::size_type pos,
22      typename S::size_type x)
23 {
24     assert(s.find_last_of(str, pos) == x);
25     if (x != S::npos)
26         assert(x <= pos && x < s.size());
27 }
28
29 template <class S>
30 void
31 test(const S& s, const typename S::value_type* str, typename S::size_type x)
32 {
33     assert(s.find_last_of(str) == x);
34     if (x != S::npos)
35         assert(x < s.size());
36 }
37
38 template <class S>
39 void test0()
40 {
41     test(S(""), "", 0, S::npos);
42     test(S(""), "laenf", 0, S::npos);
43     test(S(""), "pqlnkmbdjo", 0, S::npos);
44     test(S(""), "qkamfogpnljdcshbreti", 0, S::npos);
45     test(S(""), "", 1, S::npos);
46     test(S(""), "bjaht", 1, S::npos);
47     test(S(""), "hjlcmgpket", 1, S::npos);
48     test(S(""), "htaobedqikfplcgjsmrn", 1, S::npos);
49     test(S("fodgq"), "", 0, S::npos);
50     test(S("qanej"), "dfkap", 0, S::npos);
51     test(S("clbao"), "ihqrfebgad", 0, S::npos);
52     test(S("mekdn"), "ngtjfcalbseiqrphmkdo", 0, 0);
53     test(S("srdfq"), "", 1, S::npos);
54     test(S("oemth"), "ikcrq", 1, S::npos);
55     test(S("cdaih"), "dmajblfhsg", 1, 1);
56     test(S("qohtk"), "oqftjhdmkgsblacenirp", 1, 1);
57     test(S("cshmd"), "", 2, S::npos);
58     test(S("lhcdo"), "oebqi", 2, S::npos);
59     test(S("qnsoh"), "kojhpmbsfe", 2, 2);
60     test(S("pkrof"), "acbsjqogpltdkhinfrem", 2, 2);
61     test(S("fmtsp"), "", 4, S::npos);
62     test(S("khbpm"), "aobjd", 4, 2);
63     test(S("pbsji"), "pcbahntsje", 4, 3);
64     test(S("mprdj"), "fhepcrntkoagbmldqijs", 4, 4);
65     test(S("eqmpa"), "", 5, S::npos);
66     test(S("omigs"), "kocgb", 5, 3);
67     test(S("onmje"), "fbslrjiqkm", 5, 3);
68     test(S("oqmrj"), "jeidpcmalhfnqbgtrsko", 5, 4);
69     test(S("schfa"), "", 6, S::npos);
70     test(S("igdsc"), "qngpd", 6, 2);
71     test(S("brqgo"), "rodhqklgmb", 6, 4);
72     test(S("tnrph"), "thdjgafrlbkoiqcspmne", 6, 4);
73     test(S("hcjitbfapl"), "", 0, S::npos);
74     test(S("daiprenocl"), "ashjd", 0, 0);
75     test(S("litpcfdghe"), "mgojkldsqh", 0, 0);
76     test(S("aidjksrolc"), "imqnaghkfrdtlopbjesc", 0, 0);
77     test(S("qpghtfbaji"), "", 1, S::npos);
78     test(S("gfshlcmdjr"), "nadkh", 1, S::npos);
79     test(S("nkodajteqp"), "ofdrqmkebl", 1, 1);
80     test(S("gbmetiprqd"), "bdfjqgatlksriohemnpc", 1, 1);
81     test(S("crnklpmegd"), "", 5, S::npos);
82     test(S("jsbtafedoc"), "prqgn", 5, S::npos);
83     test(S("qnmodrtkeb"), "pejafmnokr", 5, 5);
84     test(S("cpebqsfmnj"), "odnqkgijrhabfmcestlp", 5, 5);
85     test(S("lmofqdhpki"), "", 9, S::npos);
86     test(S("hnefkqimca"), "rtjpa", 9, 9);
87     test(S("drtasbgmfp"), "ktsrmnqagd", 9, 7);
88     test(S("lsaijeqhtr"), "rtdhgcisbnmoaqkfpjle", 9, 9);
89     test(S("elgofjmbrq"), "", 10, S::npos);
90     test(S("mjqdgalkpc"), "dplqa", 10, 8);
91     test(S("kthqnfcerm"), "dkacjoptns", 10, 6);
92     test(S("dfsjhanorc"), "hqfimtrgnbekpdcsjalo", 10, 9);
93     test(S("eqsgalomhb"), "", 11, S::npos);
94     test(S("akiteljmoh"), "lofbc", 11, 8);
95     test(S("hlbdfreqjo"), "astoegbfpn", 11, 9);
96     test(S("taqobhlerg"), "pdgreqomsncafklhtibj", 11, 9);
97     test(S("snafbdlghrjkpqtoceim"), "", 0, S::npos);
98     test(S("aemtbrgcklhndjisfpoq"), "lbtqd", 0, S::npos);
99     test(S("pnracgfkjdiholtbqsem"), "tboimldpjh", 0, 0);
100     test(S("dicfltehbsgrmojnpkaq"), "slcerthdaiqjfnobgkpm", 0, 0);
101     test(S("jlnkraeodhcspfgbqitm"), "", 1, S::npos);
102     test(S("lhosrngtmfjikbqpcade"), "aqibs", 1, S::npos);
103     test(S("rbtaqjhgkneisldpmfoc"), "gtfblmqinc", 1, 1);
104     test(S("gpifsqlrdkbonjtmheca"), "mkqpbtdalgniorhfescj", 1, 1);
105     test(S("hdpkobnsalmcfijregtq"), "", 10, S::npos);
106     test(S("jtlshdgqaiprkbcoenfm"), "pblas", 10, 10);
107     test(S("fkdrbqltsgmcoiphneaj"), "arosdhcfme", 10, 10);
108     test(S("crsplifgtqedjohnabmk"), "blkhjeogicatqfnpdmsr", 10, 10);
109     test(S("niptglfbosehkamrdqcj"), "", 19, S::npos);
110     test(S("copqdhstbingamjfkler"), "djkqc", 19, 16);
111     test(S("mrtaefilpdsgocnhqbjk"), "lgokshjtpb", 19, 19);
112     test(S("kojatdhlcmigpbfrqnes"), "bqjhtkfepimcnsgrlado", 19, 19);
113     test(S("eaintpchlqsbdgrkjofm"), "", 20, S::npos);
114     test(S("gjnhidfsepkrtaqbmclo"), "nocfa", 20, 19);
115     test(S("spocfaktqdbiejlhngmr"), "bgtajmiedc", 20, 18);
116     test(S("rphmlekgfscndtaobiqj"), "lsckfnqgdahejiopbtmr", 20, 19);
117     test(S("liatsqdoegkmfcnbhrpj"), "", 21, S::npos);
118     test(S("binjagtfldkrspcomqeh"), "gfsrt", 21, 12);
119     test(S("latkmisecnorjbfhqpdg"), "pfsocbhjtm", 21, 17);
120     test(S("lecfratdjkhnsmqpoigb"), "tpflmdnoicjgkberhqsa", 21, 19);
121 }
122
123 template <class S>
124 void test1()
125 {
126     test(S(""), "", S::npos);
127     test(S(""), "laenf", S::npos);
128     test(S(""), "pqlnkmbdjo", S::npos);
129     test(S(""), "qkamfogpnljdcshbreti", S::npos);
130     test(S("nhmko"), "", S::npos);
131     test(S("lahfb"), "irkhs", 2);
132     test(S("gmfhd"), "kantesmpgj", 1);
133     test(S("odaft"), "oknlrstdpiqmjbaghcfe", 4);
134     test(S("eolhfgpjqk"), "", S::npos);
135     test(S("nbatdlmekr"), "bnrpe", 9);
136     test(S("jdmciepkaq"), "jtdaefblso", 8);
137     test(S("hkbgspoflt"), "oselktgbcapndfjihrmq", 9);
138     test(S("gprdcokbnjhlsfmtieqa"), "", S::npos);
139     test(S("qjghlnftcaismkropdeb"), "bjaht", 19);
140     test(S("pnalfrdtkqcmojiesbhg"), "hjlcmgpket", 19);
141     test(S("pniotcfrhqsmgdkjbael"), "htaobedqikfplcgjsmrn", 19);
142 }
143
144 int main()
145 {
146     {
147     typedef std::experimental::string_view S;
148     test0<S>();
149     test1<S>();
150     }
151
152 #if _LIBCPP_STD_VER > 11
153     {
154     typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
155     constexpr SV  sv1;
156     constexpr SV  sv2 { "abcde", 5 };
157
158     static_assert (sv1.find_last_of( "",      0) == SV::npos, "" );
159     static_assert (sv1.find_last_of( "irkhs", 5) == SV::npos, "" );
160     static_assert (sv2.find_last_of( "",      0) == SV::npos, "" );
161     static_assert (sv2.find_last_of( "gfsrt", 5) == SV::npos, "" );
162     static_assert (sv2.find_last_of( "lecar", 5) == 4, "" );
163     }
164 #endif
165 }