Skip to content

Commit 064028b

Browse files
committedSep 7, 2017
Add even more string_view tests. These found some bugs in the default parameter value for rfind/find_last_of/find_last_not_of
llvm-svn: 312693
1 parent 5fba8ba commit 064028b

File tree

9 files changed

+1422
-6
lines changed

9 files changed

+1422
-6
lines changed
 

‎libcxx/include/string

+6-6
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public:
259259
size_type find(value_type c, size_type pos = 0) const noexcept;
260260
261261
size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
262-
size_type ffind(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
262+
size_type rfind(basic_string_view<charT, traits> sv, size_type pos = npos) const noexcept;
263263
size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
264264
size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
265265
size_type rfind(value_type c, size_type pos = npos) const noexcept;
@@ -271,7 +271,7 @@ public:
271271
size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
272272
273273
size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
274-
size_type find_last_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
274+
size_type find_last_of(basic_string_view<charT, traits> sv, size_type pos = npos) const noexcept;
275275
size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
276276
size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
277277
size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
@@ -283,7 +283,7 @@ public:
283283
size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
284284
285285
size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
286-
size_type find_last_not_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
286+
size_type find_last_not_of(basic_string_view<charT, traits> sv, size_type pos = npos) const noexcept;
287287
size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
288288
size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
289289
size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
@@ -1147,7 +1147,7 @@ public:
11471147
_LIBCPP_INLINE_VISIBILITY
11481148
size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
11491149
_LIBCPP_INLINE_VISIBILITY
1150-
size_type rfind(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
1150+
size_type rfind(__self_view __sv, size_type __pos = npos) const _NOEXCEPT;
11511151
size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
11521152
_LIBCPP_INLINE_VISIBILITY
11531153
size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
@@ -1166,7 +1166,7 @@ public:
11661166
_LIBCPP_INLINE_VISIBILITY
11671167
size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
11681168
_LIBCPP_INLINE_VISIBILITY
1169-
size_type find_last_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
1169+
size_type find_last_of(__self_view __sv, size_type __pos = npos) const _NOEXCEPT;
11701170
size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
11711171
_LIBCPP_INLINE_VISIBILITY
11721172
size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
@@ -1186,7 +1186,7 @@ public:
11861186
_LIBCPP_INLINE_VISIBILITY
11871187
size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
11881188
_LIBCPP_INLINE_VISIBILITY
1189-
size_type find_last_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
1189+
size_type find_last_not_of(__self_view __sv, size_type __pos = npos) const _NOEXCEPT;
11901190
size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
11911191
_LIBCPP_INLINE_VISIBILITY
11921192
size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;

‎libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string_view.pass.cpp

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

0 commit comments

Comments
 (0)