[libc++] Prepare string.modifiers tests for constexpr

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D119329
This commit is contained in:
Nikolas Klauser committed 2022-02-10 21:43:18 +01:00
1 parent e43b1ce4d5
commit dcffa7d3e1
56 files changed
+2065 -1177

No files matched your search

@@ -18,7 +18,7 @@
#include "min_allocator.h"
template <class S>
void
TEST_CONSTEXPR_CXX20 void
test(S& s, typename S::const_iterator p, typename S::value_type c, S expected)
{
bool sufficient_cap = s.size() < s.capacity();
@@ -32,9 +32,8 @@ test(S& s, typename S::const_iterator p, typename S::value_type c, S expected)
assert(i == p);
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
S s;
test(s, s.begin(), '1', S("1"));
@@ -51,9 +50,9 @@ int main(int, char**)
test(s, s.begin()+4, 'A', S("a567A1432dcb"));
test(s, s.begin()+5, 'B', S("a567AB1432dcb"));
test(s, s.begin()+6, 'C', S("a567ABC1432dcb"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
S s;
test(s, s.begin(), '1', S("1"));
@@ -70,7 +69,17 @@ int main(int, char**)
test(s, s.begin()+4, 'A', S("a567A1432dcb"));
test(s, s.begin()+5, 'B', S("a567AB1432dcb"));
test(s, s.begin()+6, 'C', S("a567ABC1432dcb"));
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
@@ -19,21 +19,30 @@
#include "test_macros.h"
#include "min_allocator.h"
bool test() {
{
std::string s("123456");
std::string::iterator i = s.insert(s.begin() + 3, {'a', 'b', 'c'});
assert(i - s.begin() == 3);
assert(s == "123abc456");
}
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
S s("123456");
S::iterator i = s.insert(s.begin() + 3, {'a', 'b', 'c'});
assert(i - s.begin() == 3);
assert(s == "123abc456");
}
return true;
}
int main(int, char**)
{
{
std::string s("123456");
std::string::iterator i = s.insert(s.begin() + 3, {'a', 'b', 'c'});
assert(i - s.begin() == 3);
assert(s == "123abc456");
}
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
S s("123456");
S::iterator i = s.insert(s.begin() + 3, {'a', 'b', 'c'});
assert(i - s.begin() == 3);
assert(s == "123abc456");
}
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
}
@@ -19,7 +19,7 @@
#include "min_allocator.h"
template <class S, class It>
void
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::difference_type pos, It first, It last, S expected)
{
typename S::const_iterator p = s.cbegin() + pos;
@@ -33,7 +33,7 @@ test(S s, typename S::difference_type pos, It first, It last, S expected)
struct Widget { operator char() const { throw 42; } };
template <class S, class It>
void
TEST_CONSTEXPR_CXX20 void
test_exceptions(S s, typename S::difference_type pos, It first, It last)
{
typename S::const_iterator p = s.cbegin() + pos;
@@ -56,9 +56,8 @@ test_exceptions(S s, typename S::difference_type pos, It first, It last)
}
#endif
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
test(S(), 0, s, s, S());
@@ -102,9 +101,9 @@ int main(int, char**)
test(S("12345678901234567890"), 15, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("123456789012345ABCDEFGHIJ67890"));
test(S("12345678901234567890"), 20, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
S("12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
test(S(), 0, s, s, S());
@@ -148,10 +147,10 @@ int main(int, char**)
test(S("12345678901234567890"), 15, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("123456789012345ABCDEFGHIJ67890"));
test(S("12345678901234567890"), 20, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
S("12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
}
}
#endif
#ifndef TEST_HAS_NO_EXCEPTIONS
{ // test iterator operations that throw
{ // test iterator operations that throw
typedef std::string S;
typedef ThrowingIterator<char> TIter;
typedef cpp17_input_iterator<TIter> IIter;
@@ -166,10 +165,10 @@ int main(int, char**)
Widget w[100];
test_exceptions(S(), 0, w, w+100);
}
}
#endif
{ // test inserting into self
{ // test inserting into self
typedef std::string S;
S s_short = "123/";
S s_long = "Lorem ipsum dolor sit amet, consectetur/";
@@ -183,18 +182,18 @@ int main(int, char**)
s_long.insert(s_long.begin(), s_long.begin(), s_long.end());
assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
}
}
{ // test assigning a different type
{ // test assigning a different type
typedef std::string S;
const uint8_t p[] = "ABCD";
S s;
s.insert(s.begin(), p, p + 4);
assert(s == "ABCD");
}
}
{ // regression-test inserting into self in sneaky ways
{ // regression-test inserting into self in sneaky ways
std::string s_short = "hello";
std::string s_long = "Lorem ipsum dolor sit amet, consectetur/";
std::string s_othertype = "hello";
@@ -205,7 +204,7 @@ int main(int, char**)
test(s_long, 0, s_long.data() + s_long.size(), s_long.data() + s_long.size() + 1,
std::string("\0Lorem ipsum dolor sit amet, consectetur/", 41));
test(s_othertype, 1, first + 2, first + 5, std::string("hlloello"));
}
}
{ // test with a move iterator that returns char&&
typedef cpp17_input_iterator<const char*> It;
@@ -232,5 +231,15 @@ int main(int, char**)
assert(s == "ABCD");
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
}
@@ -17,7 +17,7 @@
#include "min_allocator.h"
template <class S>
void
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::difference_type pos, typename S::size_type n,
typename S::value_type c, S expected)
{
@@ -28,9 +28,8 @@ test(S s, typename S::difference_type pos, typename S::size_type n,
assert(s == expected);
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test(S(""), 0, 0, '1', S(""));
test(S(""), 0, 5, '1', S("11111"));
@@ -96,9 +95,9 @@ int main(int, char**)
test(S("abcdefghijklmnopqrst"), 20, 5, '1', S("abcdefghijklmnopqrst11111"));
test(S("abcdefghijklmnopqrst"), 20, 10, '1', S("abcdefghijklmnopqrst1111111111"));
test(S("abcdefghijklmnopqrst"), 20, 20, '1', S("abcdefghijklmnopqrst11111111111111111111"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S(""), 0, 0, '1', S(""));
test(S(""), 0, 5, '1', S("11111"));
@@ -164,7 +163,17 @@ int main(int, char**)
test(S("abcdefghijklmnopqrst"), 20, 5, '1', S("abcdefghijklmnopqrst11111"));
test(S("abcdefghijklmnopqrst"), 20, 10, '1', S("abcdefghijklmnopqrst1111111111"));
test(S("abcdefghijklmnopqrst"), 20, 20, '1', S("abcdefghijklmnopqrst11111111111111111111"));
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
@@ -21,7 +21,7 @@
#include "min_allocator.h"
template <class S, class SV>
void
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos1, SV sv, typename S::size_type pos2,
typename S::size_type n, S expected)
{
@@ -52,7 +52,7 @@ test(S s, typename S::size_type pos1, SV sv, typename S::size_type pos2,
}
template <class S, class SV>
void
TEST_CONSTEXPR_CXX20 void
test_npos(S s, typename S::size_type pos1, SV sv, typename S::size_type pos2, S expected)
{
static_assert((!std::is_same<S, SV>::value), "");
@@ -83,7 +83,7 @@ test_npos(S s, typename S::size_type pos1, SV sv, typename S::size_type pos2, S
template <class S, class SV>
void test0()
TEST_CONSTEXPR_CXX20 bool test0()
{
test(S(""), 0, SV(""), 0, 0, S(""));
test(S(""), 0, SV(""), 0, 1, S(""));
@@ -135,10 +135,12 @@ void test0()
test(S(""), 0, SV("1234567890"), 10, 0, S(""));
test(S(""), 0, SV("1234567890"), 10, 1, S(""));
test(S(""), 0, SV("1234567890"), 11, 0, S("can't happen"));
return true;
}
template <class S, class SV>
void test1()
TEST_CONSTEXPR_CXX20 bool test1()
{
test(S(""), 0, SV("12345678901234567890"), 0, 0, S(""));
test(S(""), 0, SV("12345678901234567890"), 0, 1, S("1"));
@@ -190,10 +192,12 @@ void test1()
test(S(""), 1, SV("12345"), 5, 0, S("can't happen"));
test(S(""), 1, SV("12345"), 5, 1, S("can't happen"));
test(S(""), 1, SV("12345"), 6, 0, S("can't happen"));
return true;
}
template <class S, class SV>
void test2()
TEST_CONSTEXPR_CXX20 bool test2()
{
test(S(""), 1, SV("1234567890"), 0, 0, S("can't happen"));
test(S(""), 1, SV("1234567890"), 0, 1, S("can't happen"));
@@ -245,10 +249,12 @@ void test2()
test(S(""), 1, SV("12345678901234567890"), 21, 0, S("can't happen"));
test(S("abcde"), 0, SV(""), 0, 0, S("abcde"));
test(S("abcde"), 0, SV(""), 0, 1, S("abcde"));
return true;
}
template <class S, class SV>
void test3()
TEST_CONSTEXPR_CXX20 bool test3()
{
test(S("abcde"), 0, SV(""), 1, 0, S("can't happen"));
test(S("abcde"), 0, SV("12345"), 0, 0, S("abcde"));
@@ -300,10 +306,12 @@ void test3()
test(S("abcde"), 0, SV("1234567890"), 11, 0, S("can't happen"));
test(S("abcde"), 0, SV("12345678901234567890"), 0, 0, S("abcde"));
test(S("abcde"), 0, SV("12345678901234567890"), 0, 1, S("1abcde"));
return true;
}
template <class S, class SV>
void test4()
TEST_CONSTEXPR_CXX20 bool test4()
{
test(S("abcde"), 0, SV("12345678901234567890"), 0, 10, S("1234567890abcde"));
test(S("abcde"), 0, SV("12345678901234567890"), 0, 19, S("1234567890123456789abcde"));
@@ -355,10 +363,12 @@ void test4()
test(S("abcde"), 1, SV("12345"), 6, 0, S("can't happen"));
test(S("abcde"), 1, SV("1234567890"), 0, 0, S("abcde"));
test(S("abcde"), 1, SV("1234567890"), 0, 1, S("a1bcde"));
return true;
}
template <class S, class SV>
void test5()
TEST_CONSTEXPR_CXX20 bool test5()
{
test(S("abcde"), 1, SV("1234567890"), 0, 5, S("a12345bcde"));
test(S("abcde"), 1, SV("1234567890"), 0, 9, S("a123456789bcde"));
@@ -410,10 +420,12 @@ void test5()
test(S("abcde"), 2, SV(""), 0, 1, S("abcde"));
test(S("abcde"), 2, SV(""), 1, 0, S("can't happen"));
test(S("abcde"), 2, SV("12345"), 0, 0, S("abcde"));
return true;
}
template <class S, class SV>
void test6()
TEST_CONSTEXPR_CXX20 bool test6()
{
test(S("abcde"), 2, SV("12345"), 0, 1, S("ab1cde"));
test(S("abcde"), 2, SV("12345"), 0, 2, S("ab12cde"));
@@ -465,10 +477,12 @@ void test6()
test(S("abcde"), 2, SV("12345678901234567890"), 0, 1, S("ab1cde"));
test(S("abcde"), 2, SV("12345678901234567890"), 0, 10, S("ab1234567890cde"));
test(S("abcde"), 2, SV("12345678901234567890"), 0, 19, S("ab1234567890123456789cde"));
return true;
}
template <class S, class SV>
void test7()
TEST_CONSTEXPR_CXX20 bool test7()
{
test(S("abcde"), 2, SV("12345678901234567890"), 0, 20, S("ab12345678901234567890cde"));
test(S("abcde"), 2, SV("12345678901234567890"), 0, 21, S("ab12345678901234567890cde"));
@@ -520,10 +534,12 @@ void test7()
test(S("abcde"), 4, SV("1234567890"), 0, 1, S("abcd1e"));
test(S("abcde"), 4, SV("1234567890"), 0, 5, S("abcd12345e"));
test(S("abcde"), 4, SV("1234567890"), 0, 9, S("abcd123456789e"));
return true;
}
template <class S, class SV>
void test8()
TEST_CONSTEXPR_CXX20 bool test8()
{
test(S("abcde"), 4, SV("1234567890"), 0, 10, S("abcd1234567890e"));
test(S("abcde"), 4, SV("1234567890"), 0, 11, S("abcd1234567890e"));
@@ -575,10 +591,12 @@ void test8()
test(S("abcde"), 5, SV("12345"), 0, 0, S("abcde"));
test(S("abcde"), 5, SV("12345"), 0, 1, S("abcde1"));
test(S("abcde"), 5, SV("12345"), 0, 2, S("abcde12"));
return true;
}
template <class S, class SV>
void test9()
TEST_CONSTEXPR_CXX20 bool test9()
{
test(S("abcde"), 5, SV("12345"), 0, 4, S("abcde1234"));
test(S("abcde"), 5, SV("12345"), 0, 5, S("abcde12345"));
@@ -630,10 +648,12 @@ void test9()
test(S("abcde"), 5, SV("12345678901234567890"), 0, 19, S("abcde1234567890123456789"));
test(S("abcde"), 5, SV("12345678901234567890"), 0, 20, S("abcde12345678901234567890"));
test(S("abcde"), 5, SV("12345678901234567890"), 0, 21, S("abcde12345678901234567890"));
return true;
}
template <class S, class SV>
void test10()
TEST_CONSTEXPR_CXX20 bool test10()
{
test(S("abcde"), 5, SV("12345678901234567890"), 1, 0, S("abcde"));
test(S("abcde"), 5, SV("12345678901234567890"), 1, 1, S("abcde2"));
@@ -685,10 +705,12 @@ void test10()
test(S("abcde"), 6, SV("1234567890"), 0, 9, S("can't happen"));
test(S("abcde"), 6, SV("1234567890"), 0, 10, S("can't happen"));
test(S("abcde"), 6, SV("1234567890"), 0, 11, S("can't happen"));
return true;
}
template <class S, class SV>
void test11()
TEST_CONSTEXPR_CXX20 bool test11()
{
test(S("abcde"), 6, SV("1234567890"), 1, 0, S("can't happen"));
test(S("abcde"), 6, SV("1234567890"), 1, 1, S("can't happen"));
@@ -740,10 +762,12 @@ void test11()
test(S("abcdefghij"), 0, SV("12345"), 0, 2, S("12abcdefghij"));
test(S("abcdefghij"), 0, SV("12345"), 0, 4, S("1234abcdefghij"));
test(S("abcdefghij"), 0, SV("12345"), 0, 5, S("12345abcdefghij"));
return true;
}
template <class S, class SV>
void test12()
TEST_CONSTEXPR_CXX20 bool test12()
{
test(S("abcdefghij"), 0, SV("12345"), 0, 6, S("12345abcdefghij"));
test(S("abcdefghij"), 0, SV("12345"), 1, 0, S("abcdefghij"));
@@ -795,10 +819,12 @@ void test12()
test(S("abcdefghij"), 0, SV("12345678901234567890"), 0, 21, S("12345678901234567890abcdefghij"));
test(S("abcdefghij"), 0, SV("12345678901234567890"), 1, 0, S("abcdefghij"));
test(S("abcdefghij"), 0, SV("12345678901234567890"), 1, 1, S("2abcdefghij"));
return true;
}
template <class S, class SV>
void test13()
TEST_CONSTEXPR_CXX20 bool test13()
{
test(S("abcdefghij"), 0, SV("12345678901234567890"), 1, 9, S("234567890abcdefghij"));
test(S("abcdefghij"), 0, SV("12345678901234567890"), 1, 18, S("234567890123456789abcdefghij"));
@@ -850,10 +876,12 @@ void test13()
test(S("abcdefghij"), 1, SV("1234567890"), 0, 11, S("a1234567890bcdefghij"));
test(S("abcdefghij"), 1, SV("1234567890"), 1, 0, S("abcdefghij"));
test(S("abcdefghij"), 1, SV("1234567890"), 1, 1, S("a2bcdefghij"));
return true;
}
template <class S, class SV>
void test14()
TEST_CONSTEXPR_CXX20 bool test14()
{
test(S("abcdefghij"), 1, SV("1234567890"), 1, 4, S("a2345bcdefghij"));
test(S("abcdefghij"), 1, SV("1234567890"), 1, 8, S("a23456789bcdefghij"));
@@ -905,10 +933,12 @@ void test14()
test(S("abcdefghij"), 5, SV("12345"), 0, 5, S("abcde12345fghij"));
test(S("abcdefghij"), 5, SV("12345"), 0, 6, S("abcde12345fghij"));
test(S("abcdefghij"), 5, SV("12345"), 1, 0, S("abcdefghij"));
return true;
}
template <class S, class SV>
void test15()
TEST_CONSTEXPR_CXX20 bool test15()
{
test(S("abcdefghij"), 5, SV("12345"), 1, 1, S("abcde2fghij"));
test(S("abcdefghij"), 5, SV("12345"), 1, 2, S("abcde23fghij"));
@@ -960,10 +990,12 @@ void test15()
test(S("abcdefghij"), 5, SV("12345678901234567890"), 1, 1, S("abcde2fghij"));
test(S("abcdefghij"), 5, SV("12345678901234567890"), 1, 9, S("abcde234567890fghij"));
test(S("abcdefghij"), 5, SV("12345678901234567890"), 1, 18, S("abcde234567890123456789fghij"));
return true;
}
template <class S, class SV>
void test16()
TEST_CONSTEXPR_CXX20 bool test16()
{
test(S("abcdefghij"), 5, SV("12345678901234567890"), 1, 19, S("abcde2345678901234567890fghij"));
test(S("abcdefghij"), 5, SV("12345678901234567890"), 1, 20, S("abcde2345678901234567890fghij"));
@@ -1015,10 +1047,12 @@ void test16()
test(S("abcdefghij"), 9, SV("1234567890"), 1, 1, S("abcdefghi2j"));
test(S("abcdefghij"), 9, SV("1234567890"), 1, 4, S("abcdefghi2345j"));
test(S("abcdefghij"), 9, SV("1234567890"), 1, 8, S("abcdefghi23456789j"));
return true;
}
template <class S, class SV>
void test17()
TEST_CONSTEXPR_CXX20 bool test17()
{
test(S("abcdefghij"), 9, SV("1234567890"), 1, 9, S("abcdefghi234567890j"));
test(S("abcdefghij"), 9, SV("1234567890"), 1, 10, S("abcdefghi234567890j"));
@@ -1070,10 +1104,12 @@ void test17()
test(S("abcdefghij"), 10, SV("12345"), 1, 0, S("abcdefghij"));
test(S("abcdefghij"), 10, SV("12345"), 1, 1, S("abcdefghij2"));
test(S("abcdefghij"), 10, SV("12345"), 1, 2, S("abcdefghij23"));
return true;
}
template <class S, class SV>
void test18()
TEST_CONSTEXPR_CXX20 bool test18()
{
test(S("abcdefghij"), 10, SV("12345"), 1, 3, S("abcdefghij234"));
test(S("abcdefghij"), 10, SV("12345"), 1, 4, S("abcdefghij2345"));
@@ -1125,10 +1161,12 @@ void test18()
test(S("abcdefghij"), 10, SV("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789"));
test(S("abcdefghij"), 10, SV("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890"));
test(S("abcdefghij"), 10, SV("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890"));
return true;
}
template <class S, class SV>
void test19()
TEST_CONSTEXPR_CXX20 bool test19()
{
test(S("abcdefghij"), 10, SV("12345678901234567890"), 10, 0, S("abcdefghij"));
test(S("abcdefghij"), 10, SV("12345678901234567890"), 10, 1, S("abcdefghij1"));
@@ -1180,10 +1218,12 @@ void test19()
test(S("abcdefghij"), 11, SV("1234567890"), 1, 8, S("can't happen"));
test(S("abcdefghij"), 11, SV("1234567890"), 1, 9, S("can't happen"));
test(S("abcdefghij"), 11, SV("1234567890"), 1, 10, S("can't happen"));
return true;
}
template <class S, class SV>
void test20()
TEST_CONSTEXPR_CXX20 bool test20()
{
test(S("abcdefghij"), 11, SV("1234567890"), 5, 0, S("can't happen"));
test(S("abcdefghij"), 11, SV("1234567890"), 5, 1, S("can't happen"));
@@ -1235,10 +1275,12 @@ void test20()
test(S("abcdefghijklmnopqrst"), 0, SV("12345"), 1, 2, S("23abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 0, SV("12345"), 1, 3, S("234abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 0, SV("12345"), 1, 4, S("2345abcdefghijklmnopqrst"));
return true;
}
template <class S, class SV>
void test21()
TEST_CONSTEXPR_CXX20 bool test21()
{
test(S("abcdefghijklmnopqrst"), 0, SV("12345"), 1, 5, S("2345abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 0, SV("12345"), 2, 0, S("abcdefghijklmnopqrst"));
@@ -1290,10 +1332,12 @@ void test21()
test(S("abcdefghijklmnopqrst"), 0, SV("12345678901234567890"), 1, 20, S("2345678901234567890abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 0, SV("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 0, SV("12345678901234567890"), 10, 1, S("1abcdefghijklmnopqrst"));
return true;
}
template <class S, class SV>
void test22()
TEST_CONSTEXPR_CXX20 bool test22()
{
test(S("abcdefghijklmnopqrst"), 0, SV("12345678901234567890"), 10, 5, S("12345abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 0, SV("12345678901234567890"), 10, 9, S("123456789abcdefghijklmnopqrst"));
@@ -1345,10 +1389,12 @@ void test22()
test(S("abcdefghijklmnopqrst"), 1, SV("1234567890"), 1, 10, S("a234567890bcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 1, SV("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 1, SV("1234567890"), 5, 1, S("a6bcdefghijklmnopqrst"));
return true;
}
template <class S, class SV>
void test23()
TEST_CONSTEXPR_CXX20 bool test23()
{
test(S("abcdefghijklmnopqrst"), 1, SV("1234567890"), 5, 2, S("a67bcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 1, SV("1234567890"), 5, 4, S("a6789bcdefghijklmnopqrst"));
@@ -1400,10 +1446,12 @@ void test23()
test(S("abcdefghijklmnopqrst"), 10, SV("12345"), 1, 4, S("abcdefghij2345klmnopqrst"));
test(S("abcdefghijklmnopqrst"), 10, SV("12345"), 1, 5, S("abcdefghij2345klmnopqrst"));
test(S("abcdefghijklmnopqrst"), 10, SV("12345"), 2, 0, S("abcdefghijklmnopqrst"));
return true;
}
template <class S, class SV>
void test24()
TEST_CONSTEXPR_CXX20 bool test24()
{
test(S("abcdefghijklmnopqrst"), 10, SV("12345"), 2, 1, S("abcdefghij3klmnopqrst"));
test(S("abcdefghijklmnopqrst"), 10, SV("12345"), 2, 2, S("abcdefghij34klmnopqrst"));
@@ -1455,10 +1503,12 @@ void test24()
test(S("abcdefghijklmnopqrst"), 10, SV("12345678901234567890"), 10, 1, S("abcdefghij1klmnopqrst"));
test(S("abcdefghijklmnopqrst"), 10, SV("12345678901234567890"), 10, 5, S("abcdefghij12345klmnopqrst"));
test(S("abcdefghijklmnopqrst"), 10, SV("12345678901234567890"), 10, 9, S("abcdefghij123456789klmnopqrst"));
return true;
}
template <class S, class SV>
void test25()
TEST_CONSTEXPR_CXX20 bool test25()
{
test(S("abcdefghijklmnopqrst"), 10, SV("12345678901234567890"), 10, 10, S("abcdefghij1234567890klmnopqrst"));
test(S("abcdefghijklmnopqrst"), 10, SV("12345678901234567890"), 10, 11, S("abcdefghij1234567890klmnopqrst"));
@@ -1510,10 +1560,12 @@ void test25()
test(S("abcdefghijklmnopqrst"), 19, SV("1234567890"), 5, 1, S("abcdefghijklmnopqrs6t"));
test(S("abcdefghijklmnopqrst"), 19, SV("1234567890"), 5, 2, S("abcdefghijklmnopqrs67t"));
test(S("abcdefghijklmnopqrst"), 19, SV("1234567890"), 5, 4, S("abcdefghijklmnopqrs6789t"));
return true;
}
template <class S, class SV>
void test26()
TEST_CONSTEXPR_CXX20 bool test26()
{
test(S("abcdefghijklmnopqrst"), 19, SV("1234567890"), 5, 5, S("abcdefghijklmnopqrs67890t"));
test(S("abcdefghijklmnopqrst"), 19, SV("1234567890"), 5, 6, S("abcdefghijklmnopqrs67890t"));
@@ -1565,10 +1617,12 @@ void test26()
test(S("abcdefghijklmnopqrst"), 20, SV("12345"), 2, 0, S("abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 20, SV("12345"), 2, 1, S("abcdefghijklmnopqrst3"));
test(S("abcdefghijklmnopqrst"), 20, SV("12345"), 2, 2, S("abcdefghijklmnopqrst34"));
return true;
}
template <class S, class SV>
void test27()
TEST_CONSTEXPR_CXX20 bool test27()
{
test(S("abcdefghijklmnopqrst"), 20, SV("12345"), 2, 3, S("abcdefghijklmnopqrst345"));
test(S("abcdefghijklmnopqrst"), 20, SV("12345"), 2, 4, S("abcdefghijklmnopqrst345"));
@@ -1620,10 +1674,12 @@ void test27()
test(S("abcdefghijklmnopqrst"), 20, SV("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrst123456789"));
test(S("abcdefghijklmnopqrst"), 20, SV("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrst1234567890"));
test(S("abcdefghijklmnopqrst"), 20, SV("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrst1234567890"));
return true;
}
template <class S, class SV>
void test28()
TEST_CONSTEXPR_CXX20 bool test28()
{
test(S("abcdefghijklmnopqrst"), 20, SV("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 20, SV("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrst0"));
@@ -1675,10 +1731,12 @@ void test28()
test(S("abcdefghijklmnopqrst"), 21, SV("1234567890"), 5, 4, S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, SV("1234567890"), 5, 5, S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, SV("1234567890"), 5, 6, S("can't happen"));
return true;
}
template <class S, class SV>
void test29()
TEST_CONSTEXPR_CXX20 bool test29()
{
test(S("abcdefghijklmnopqrst"), 21, SV("1234567890"), 9, 0, S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, SV("1234567890"), 9, 1, S("can't happen"));
@@ -1710,10 +1768,12 @@ void test29()
test(S("abcdefghijklmnopqrst"), 21, SV("12345678901234567890"), 20, 0, S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, SV("12345678901234567890"), 20, 1, S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, SV("12345678901234567890"), 21, 0, S("can't happen"));
return true;
}
template <class S, class SV>
void test30()
TEST_CONSTEXPR_CXX20 bool test30()
{
test_npos(S(""), 0, SV("12345678901234567890"), 0, S("12345678901234567890"));
test_npos(S(""), 0, SV("12345678901234567890"), 1, S( "2345678901234567890"));
@@ -1727,85 +1787,12 @@ void test30()
test_npos(S("abcdefghijklmnopqrst"), 10, SV("12345"), 3, S("abcdefghij45klmnopqrst"));
test_npos(S("abcdefghijklmnopqrst"), 10, SV("12345"), 5, S("abcdefghijklmnopqrst"));
test_npos(S("abcdefghijklmnopqrst"), 10, SV("12345"), 6, S("can't happen"));
return true;
}
int main(int, char**)
{
{
typedef std::string S;
typedef std::string_view SV;
test0<S, SV>();
test1<S, SV>();
test2<S, SV>();
test3<S, SV>();
test4<S, SV>();
test5<S, SV>();
test6<S, SV>();
test7<S, SV>();
test8<S, SV>();
test9<S, SV>();
test10<S, SV>();
test11<S, SV>();
test12<S, SV>();
test13<S, SV>();
test14<S, SV>();
test15<S, SV>();
test16<S, SV>();
test17<S, SV>();
test18<S, SV>();
test19<S, SV>();
test20<S, SV>();
test21<S, SV>();
test22<S, SV>();
test23<S, SV>();
test24<S, SV>();
test25<S, SV>();
test26<S, SV>();
test27<S, SV>();
test28<S, SV>();
test29<S, SV>();
test30<S, SV>();
}
#if TEST_STD_VER >= 11
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
typedef std::basic_string_view<char, std::char_traits<char>> SV;
test0<S, SV>();
test1<S, SV>();
test2<S, SV>();
test3<S, SV>();
test4<S, SV>();
test5<S, SV>();
test6<S, SV>();
test7<S, SV>();
test8<S, SV>();
test9<S, SV>();
test10<S, SV>();
test11<S, SV>();
test12<S, SV>();
test13<S, SV>();
test14<S, SV>();
test15<S, SV>();
test16<S, SV>();
test17<S, SV>();
test18<S, SV>();
test19<S, SV>();
test20<S, SV>();
test21<S, SV>();
test22<S, SV>();
test23<S, SV>();
test24<S, SV>();
test25<S, SV>();
test26<S, SV>();
test27<S, SV>();
test28<S, SV>();
test29<S, SV>();
test30<S, SV>();
}
#endif
{
typedef std::string S;
typedef std::string_view SV;
template <class S, class SV>
bool test31() {
S s;
SV sv = "EFGH";
char arr[] = "IJKL";
@@ -1837,7 +1824,88 @@ int main(int, char**)
s.insert(0, arr, 0); // calls insert(const char *, len)
assert(s == "");
s.clear();
}
return true;
}
template <class S, class SV>
void test() {
test0<S, SV>();
test1<S, SV>();
test2<S, SV>();
test3<S, SV>();
test4<S, SV>();
test5<S, SV>();
test6<S, SV>();
test7<S, SV>();
test8<S, SV>();
test9<S, SV>();
test10<S, SV>();
test11<S, SV>();
test12<S, SV>();
test13<S, SV>();
test14<S, SV>();
test15<S, SV>();
test16<S, SV>();
test17<S, SV>();
test18<S, SV>();
test19<S, SV>();
test20<S, SV>();
test21<S, SV>();
test22<S, SV>();
test23<S, SV>();
test24<S, SV>();
test25<S, SV>();
test26<S, SV>();
test27<S, SV>();
test28<S, SV>();
test29<S, SV>();
test30<S, SV>();
test31<S, SV>();
#if TEST_STD_VER > 17
// static_assert(test0<S, SV>());
// static_assert(test1<S, SV>());
// static_assert(test2<S, SV>());
// static_assert(test3<S, SV>());
// static_assert(test4<S, SV>());
// static_assert(test5<S, SV>());
// static_assert(test6<S, SV>());
// static_assert(test7<S, SV>());
// static_assert(test8<S, SV>());
// static_assert(test9<S, SV>());
// static_assert(test10<S, SV>());
// static_assert(test11<S, SV>());
// static_assert(test12<S, SV>());
// static_assert(test13<S, SV>());
// static_assert(test14<S, SV>());
// static_assert(test15<S, SV>());
// static_assert(test16<S, SV>());
// static_assert(test17<S, SV>());
// static_assert(test18<S, SV>());
// static_assert(test19<S, SV>());
// static_assert(test20<S, SV>());
// static_assert(test21<S, SV>());
// static_assert(test22<S, SV>());
// static_assert(test23<S, SV>());
// static_assert(test24<S, SV>());
// static_assert(test25<S, SV>());
// static_assert(test26<S, SV>());
// static_assert(test27<S, SV>());
// static_assert(test28<S, SV>());
// static_assert(test29<S, SV>());
// static_assert(test30<S, SV>());
// static_assert(test31<S, SV>());
#endif
}
int main(int, char**)
{
test<std::string, std::string_view>();
#if TEST_STD_VER >= 11
test<std::basic_string<char, std::char_traits<char>, min_allocator<char>>,
std::basic_string_view<char, std::char_traits<char>>>();
#endif
return 0;
}
@@ -19,7 +19,7 @@
#include "min_allocator.h"
template <class S>
void
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos, const typename S::value_type* str, S expected)
{
const typename S::size_type old_size = s.size();
@@ -47,9 +47,8 @@ test(S s, typename S::size_type pos, const typename S::value_type* str, S expect
#endif
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test(S(""), 0, "", S(""));
test(S(""), 0, "12345", S("12345"));
@@ -131,9 +130,9 @@ int main(int, char**)
test(S("abcdefghijklmnopqrst"), 21, "12345", S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, "1234567890", S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", S("can't happen"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S(""), 0, "", S(""));
test(S(""), 0, "12345", S("12345"));
@@ -215,10 +214,10 @@ int main(int, char**)
test(S("abcdefghijklmnopqrst"), 21, "12345", S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, "1234567890", S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", S("can't happen"));
}
}
#endif
{ // test inserting into self
{ // test inserting into self
typedef std::string S;
S s_short = "123/";
S s_long = "Lorem ipsum dolor sit amet, consectetur/";
@@ -232,7 +231,17 @@ int main(int, char**)
s_long.insert(0, s_long.c_str());
assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
}
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
}
@@ -19,7 +19,7 @@
#include "min_allocator.h"
template <class S>
void
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos, const typename S::value_type* str,
typename S::size_type n, S expected)
{
@@ -48,9 +48,8 @@ test(S s, typename S::size_type pos, const typename S::value_type* str,
#endif
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test(S(""), 0, "", 0, S(""));
test(S(""), 0, "12345", 0, S(""));
@@ -372,9 +371,9 @@ int main(int, char**)
test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 10, S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 19, S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 20, S("can't happen"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S(""), 0, "", 0, S(""));
test(S(""), 0, "12345", 0, S(""));
@@ -696,10 +695,10 @@ int main(int, char**)
test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 10, S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 19, S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 20, S("can't happen"));
}
}
#endif
{ // test inserting into self
{ // test inserting into self
typedef std::string S;
S s_short = "123/";
S s_long = "Lorem ipsum dolor sit amet, consectetur/";
@@ -713,7 +712,17 @@ int main(int, char**)
s_long.insert(0, s_long.data(), s_long.size());
assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
}
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
}
@@ -19,7 +19,7 @@
#include "min_allocator.h"
template <class S>
void
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos, typename S::size_type n,
typename S::value_type str, S expected)
{
@@ -48,9 +48,8 @@ test(S s, typename S::size_type pos, typename S::size_type n,
#endif
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test(S(""), 0, 0, '1', S(""));
test(S(""), 0, 5, '1', S("11111"));
@@ -132,9 +131,9 @@ int main(int, char**)
test(S("abcdefghijklmnopqrst"), 21, 5, '1', S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, 10, '1', S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, 20, '1', S("can't happen"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S(""), 0, 0, '1', S(""));
test(S(""), 0, 5, '1', S("11111"));
@@ -216,7 +215,17 @@ int main(int, char**)
test(S("abcdefghijklmnopqrst"), 21, 5, '1', S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, 10, '1', S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, 20, '1', S("can't happen"));
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
@@ -19,7 +19,7 @@
#include "min_allocator.h"
template <class S>
void
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos, S str, S expected)
{
const typename S::size_type old_size = s.size();
@@ -47,9 +47,8 @@ test(S s, typename S::size_type pos, S str, S expected)
#endif
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
test(S(""), 0, S(""), S(""));
test(S(""), 0, S("12345"), S("12345"));
@@ -131,9 +130,9 @@ int main(int, char**)
test(S("abcdefghijklmnopqrst"), 21, S("12345"), S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), S("can't happen"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S(""), 0, S(""), S(""));
test(S(""), 0, S("12345"), S("12345"));
@@ -215,16 +214,26 @@ int main(int, char**)
test(S("abcdefghijklmnopqrst"), 21, S("12345"), S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), S("can't happen"));
}
}
#endif
#if TEST_STD_VER > 3
{ // LWG 2946
{ // LWG 2946
std::string s;
s.insert(0, {"abc", 1});
assert(s.size() == 1);
assert(s == "a");
}
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
@@ -21,7 +21,7 @@
#include "min_allocator.h"
template <class S>
void
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos1, S str, typename S::size_type pos2,
typename S::size_type n, S expected)
{
@@ -51,7 +51,7 @@ test(S s, typename S::size_type pos1, S str, typename S::size_type pos2,
}
template <class S>
void
TEST_CONSTEXPR_CXX20 void
test_npos(S s, typename S::size_type pos1, S str, typename S::size_type pos2, S expected)
{
const typename S::size_type old_size = s.size();
@@ -81,7 +81,7 @@ test_npos(S s, typename S::size_type pos1, S str, typename S::size_type pos2, S
template <class S>
void test0()
TEST_CONSTEXPR_CXX20 bool test0()
{
test(S(""), 0, S(""), 0, 0, S(""));
test(S(""), 0, S(""), 0, 1, S(""));
@@ -133,10 +133,12 @@ void test0()
test(S(""), 0, S("1234567890"), 10, 0, S(""));
test(S(""), 0, S("1234567890"), 10, 1, S(""));
test(S(""), 0, S("1234567890"), 11, 0, S("can't happen"));
return true;
}
template <class S>
void test1()
TEST_CONSTEXPR_CXX20 bool test1()
{
test(S(""), 0, S("12345678901234567890"), 0, 0, S(""));
test(S(""), 0, S("12345678901234567890"), 0, 1, S("1"));
@@ -188,10 +190,12 @@ void test1()
test(S(""), 1, S("12345"), 5, 0, S("can't happen"));
test(S(""), 1, S("12345"), 5, 1, S("can't happen"));
test(S(""), 1, S("12345"), 6, 0, S("can't happen"));
return true;
}
template <class S>
void test2()
TEST_CONSTEXPR_CXX20 bool test2()
{
test(S(""), 1, S("1234567890"), 0, 0, S("can't happen"));
test(S(""), 1, S("1234567890"), 0, 1, S("can't happen"));
@@ -243,10 +247,12 @@ void test2()
test(S(""), 1, S("12345678901234567890"), 21, 0, S("can't happen"));
test(S("abcde"), 0, S(""), 0, 0, S("abcde"));
test(S("abcde"), 0, S(""), 0, 1, S("abcde"));
return true;
}
template <class S>
void test3()
TEST_CONSTEXPR_CXX20 bool test3()
{
test(S("abcde"), 0, S(""), 1, 0, S("can't happen"));
test(S("abcde"), 0, S("12345"), 0, 0, S("abcde"));
@@ -298,10 +304,12 @@ void test3()
test(S("abcde"), 0, S("1234567890"), 11, 0, S("can't happen"));
test(S("abcde"), 0, S("12345678901234567890"), 0, 0, S("abcde"));
test(S("abcde"), 0, S("12345678901234567890"), 0, 1, S("1abcde"));
return true;
}
template <class S>
void test4()
TEST_CONSTEXPR_CXX20 bool test4()
{
test(S("abcde"), 0, S("12345678901234567890"), 0, 10, S("1234567890abcde"));
test(S("abcde"), 0, S("12345678901234567890"), 0, 19, S("1234567890123456789abcde"));
@@ -353,10 +361,12 @@ void test4()
test(S("abcde"), 1, S("12345"), 6, 0, S("can't happen"));
test(S("abcde"), 1, S("1234567890"), 0, 0, S("abcde"));
test(S("abcde"), 1, S("1234567890"), 0, 1, S("a1bcde"));
return true;
}
template <class S>
void test5()
TEST_CONSTEXPR_CXX20 bool test5()
{
test(S("abcde"), 1, S("1234567890"), 0, 5, S("a12345bcde"));
test(S("abcde"), 1, S("1234567890"), 0, 9, S("a123456789bcde"));
@@ -408,10 +418,12 @@ void test5()
test(S("abcde"), 2, S(""), 0, 1, S("abcde"));
test(S("abcde"), 2, S(""), 1, 0, S("can't happen"));
test(S("abcde"), 2, S("12345"), 0, 0, S("abcde"));
return true;
}
template <class S>
void test6()
TEST_CONSTEXPR_CXX20 bool test6()
{
test(S("abcde"), 2, S("12345"), 0, 1, S("ab1cde"));
test(S("abcde"), 2, S("12345"), 0, 2, S("ab12cde"));
@@ -463,10 +475,12 @@ void test6()
test(S("abcde"), 2, S("12345678901234567890"), 0, 1, S("ab1cde"));
test(S("abcde"), 2, S("12345678901234567890"), 0, 10, S("ab1234567890cde"));
test(S("abcde"), 2, S("12345678901234567890"), 0, 19, S("ab1234567890123456789cde"));
return true;
}
template <class S>
void test7()
TEST_CONSTEXPR_CXX20 bool test7()
{
test(S("abcde"), 2, S("12345678901234567890"), 0, 20, S("ab12345678901234567890cde"));
test(S("abcde"), 2, S("12345678901234567890"), 0, 21, S("ab12345678901234567890cde"));
@@ -518,10 +532,12 @@ void test7()
test(S("abcde"), 4, S("1234567890"), 0, 1, S("abcd1e"));
test(S("abcde"), 4, S("1234567890"), 0, 5, S("abcd12345e"));
test(S("abcde"), 4, S("1234567890"), 0, 9, S("abcd123456789e"));
return true;
}
template <class S>
void test8()
TEST_CONSTEXPR_CXX20 bool test8()
{
test(S("abcde"), 4, S("1234567890"), 0, 10, S("abcd1234567890e"));
test(S("abcde"), 4, S("1234567890"), 0, 11, S("abcd1234567890e"));
@@ -573,10 +589,12 @@ void test8()
test(S("abcde"), 5, S("12345"), 0, 0, S("abcde"));
test(S("abcde"), 5, S("12345"), 0, 1, S("abcde1"));
test(S("abcde"), 5, S("12345"), 0, 2, S("abcde12"));
return true;
}
template <class S>
void test9()
TEST_CONSTEXPR_CXX20 bool test9()
{
test(S("abcde"), 5, S("12345"), 0, 4, S("abcde1234"));
test(S("abcde"), 5, S("12345"), 0, 5, S("abcde12345"));
@@ -628,10 +646,12 @@ void test9()
test(S("abcde"), 5, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789"));
test(S("abcde"), 5, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890"));
test(S("abcde"), 5, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890"));
return true;
}
template <class S>
void test10()
TEST_CONSTEXPR_CXX20 bool test10()
{
test(S("abcde"), 5, S("12345678901234567890"), 1, 0, S("abcde"));
test(S("abcde"), 5, S("12345678901234567890"), 1, 1, S("abcde2"));
@@ -683,10 +703,12 @@ void test10()
test(S("abcde"), 6, S("1234567890"), 0, 9, S("can't happen"));
test(S("abcde"), 6, S("1234567890"), 0, 10, S("can't happen"));
test(S("abcde"), 6, S("1234567890"), 0, 11, S("can't happen"));
return true;
}
template <class S>
void test11()
TEST_CONSTEXPR_CXX20 bool test11()
{
test(S("abcde"), 6, S("1234567890"), 1, 0, S("can't happen"));
test(S("abcde"), 6, S("1234567890"), 1, 1, S("can't happen"));
@@ -738,10 +760,12 @@ void test11()
test(S("abcdefghij"), 0, S("12345"), 0, 2, S("12abcdefghij"));
test(S("abcdefghij"), 0, S("12345"), 0, 4, S("1234abcdefghij"));
test(S("abcdefghij"), 0, S("12345"), 0, 5, S("12345abcdefghij"));
return true;
}
template <class S>
void test12()
TEST_CONSTEXPR_CXX20 bool test12()
{
test(S("abcdefghij"), 0, S("12345"), 0, 6, S("12345abcdefghij"));
test(S("abcdefghij"), 0, S("12345"), 1, 0, S("abcdefghij"));
@@ -793,10 +817,12 @@ void test12()
test(S("abcdefghij"), 0, S("12345678901234567890"), 0, 21, S("12345678901234567890abcdefghij"));
test(S("abcdefghij"), 0, S("12345678901234567890"), 1, 0, S("abcdefghij"));
test(S("abcdefghij"), 0, S("12345678901234567890"), 1, 1, S("2abcdefghij"));
return true;
}
template <class S>
void test13()
TEST_CONSTEXPR_CXX20 bool test13()
{
test(S("abcdefghij"), 0, S("12345678901234567890"), 1, 9, S("234567890abcdefghij"));
test(S("abcdefghij"), 0, S("12345678901234567890"), 1, 18, S("234567890123456789abcdefghij"));
@@ -848,10 +874,12 @@ void test13()
test(S("abcdefghij"), 1, S("1234567890"), 0, 11, S("a1234567890bcdefghij"));
test(S("abcdefghij"), 1, S("1234567890"), 1, 0, S("abcdefghij"));
test(S("abcdefghij"), 1, S("1234567890"), 1, 1, S("a2bcdefghij"));
return true;
}
template <class S>
void test14()
TEST_CONSTEXPR_CXX20 bool test14()
{
test(S("abcdefghij"), 1, S("1234567890"), 1, 4, S("a2345bcdefghij"));
test(S("abcdefghij"), 1, S("1234567890"), 1, 8, S("a23456789bcdefghij"));
@@ -903,10 +931,12 @@ void test14()
test(S("abcdefghij"), 5, S("12345"), 0, 5, S("abcde12345fghij"));
test(S("abcdefghij"), 5, S("12345"), 0, 6, S("abcde12345fghij"));
test(S("abcdefghij"), 5, S("12345"), 1, 0, S("abcdefghij"));
return true;
}
template <class S>
void test15()
TEST_CONSTEXPR_CXX20 bool test15()
{
test(S("abcdefghij"), 5, S("12345"), 1, 1, S("abcde2fghij"));
test(S("abcdefghij"), 5, S("12345"), 1, 2, S("abcde23fghij"));
@@ -958,10 +988,12 @@ void test15()
test(S("abcdefghij"), 5, S("12345678901234567890"), 1, 1, S("abcde2fghij"));
test(S("abcdefghij"), 5, S("12345678901234567890"), 1, 9, S("abcde234567890fghij"));
test(S("abcdefghij"), 5, S("12345678901234567890"), 1, 18, S("abcde234567890123456789fghij"));
return true;
}
template <class S>
void test16()
TEST_CONSTEXPR_CXX20 bool test16()
{
test(S("abcdefghij"), 5, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890fghij"));
test(S("abcdefghij"), 5, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890fghij"));
@@ -1013,10 +1045,12 @@ void test16()
test(S("abcdefghij"), 9, S("1234567890"), 1, 1, S("abcdefghi2j"));
test(S("abcdefghij"), 9, S("1234567890"), 1, 4, S("abcdefghi2345j"));
test(S("abcdefghij"), 9, S("1234567890"), 1, 8, S("abcdefghi23456789j"));
return true;
}
template <class S>
void test17()
TEST_CONSTEXPR_CXX20 bool test17()
{
test(S("abcdefghij"), 9, S("1234567890"), 1, 9, S("abcdefghi234567890j"));
test(S("abcdefghij"), 9, S("1234567890"), 1, 10, S("abcdefghi234567890j"));
@@ -1068,10 +1102,12 @@ void test17()
test(S("abcdefghij"), 10, S("12345"), 1, 0, S("abcdefghij"));
test(S("abcdefghij"), 10, S("12345"), 1, 1, S("abcdefghij2"));
test(S("abcdefghij"), 10, S("12345"), 1, 2, S("abcdefghij23"));
return true;
}
template <class S>
void test18()
TEST_CONSTEXPR_CXX20 bool test18()
{
test(S("abcdefghij"), 10, S("12345"), 1, 3, S("abcdefghij234"));
test(S("abcdefghij"), 10, S("12345"), 1, 4, S("abcdefghij2345"));
@@ -1123,10 +1159,12 @@ void test18()
test(S("abcdefghij"), 10, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789"));
test(S("abcdefghij"), 10, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890"));
test(S("abcdefghij"), 10, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890"));
return true;
}
template <class S>
void test19()
TEST_CONSTEXPR_CXX20 bool test19()
{
test(S("abcdefghij"), 10, S("12345678901234567890"), 10, 0, S("abcdefghij"));
test(S("abcdefghij"), 10, S("12345678901234567890"), 10, 1, S("abcdefghij1"));
@@ -1178,10 +1216,12 @@ void test19()
test(S("abcdefghij"), 11, S("1234567890"), 1, 8, S("can't happen"));
test(S("abcdefghij"), 11, S("1234567890"), 1, 9, S("can't happen"));
test(S("abcdefghij"), 11, S("1234567890"), 1, 10, S("can't happen"));
return true;
}
template <class S>
void test20()
TEST_CONSTEXPR_CXX20 bool test20()
{
test(S("abcdefghij"), 11, S("1234567890"), 5, 0, S("can't happen"));
test(S("abcdefghij"), 11, S("1234567890"), 5, 1, S("can't happen"));
@@ -1233,10 +1273,12 @@ void test20()
test(S("abcdefghijklmnopqrst"), 0, S("12345"), 1, 2, S("23abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 0, S("12345"), 1, 3, S("234abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 0, S("12345"), 1, 4, S("2345abcdefghijklmnopqrst"));
return true;
}
template <class S>
void test21()
TEST_CONSTEXPR_CXX20 bool test21()
{
test(S("abcdefghijklmnopqrst"), 0, S("12345"), 1, 5, S("2345abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 0, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
@@ -1288,10 +1330,12 @@ void test21()
test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 1, 20, S("2345678901234567890abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 10, 1, S("1abcdefghijklmnopqrst"));
return true;
}
template <class S>
void test22()
TEST_CONSTEXPR_CXX20 bool test22()
{
test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 10, 5, S("12345abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 10, 9, S("123456789abcdefghijklmnopqrst"));
@@ -1343,10 +1387,12 @@ void test22()
test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 1, 10, S("a234567890bcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 5, 1, S("a6bcdefghijklmnopqrst"));
return true;
}
template <class S>
void test23()
TEST_CONSTEXPR_CXX20 bool test23()
{
test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 5, 2, S("a67bcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 5, 4, S("a6789bcdefghijklmnopqrst"));
@@ -1398,10 +1444,12 @@ void test23()
test(S("abcdefghijklmnopqrst"), 10, S("12345"), 1, 4, S("abcdefghij2345klmnopqrst"));
test(S("abcdefghijklmnopqrst"), 10, S("12345"), 1, 5, S("abcdefghij2345klmnopqrst"));
test(S("abcdefghijklmnopqrst"), 10, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
return true;
}
template <class S>
void test24()
TEST_CONSTEXPR_CXX20 bool test24()
{
test(S("abcdefghijklmnopqrst"), 10, S("12345"), 2, 1, S("abcdefghij3klmnopqrst"));
test(S("abcdefghijklmnopqrst"), 10, S("12345"), 2, 2, S("abcdefghij34klmnopqrst"));
@@ -1453,10 +1501,12 @@ void test24()
test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 10, 1, S("abcdefghij1klmnopqrst"));
test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 10, 5, S("abcdefghij12345klmnopqrst"));
test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 10, 9, S("abcdefghij123456789klmnopqrst"));
return true;
}
template <class S>
void test25()
TEST_CONSTEXPR_CXX20 bool test25()
{
test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890klmnopqrst"));
test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890klmnopqrst"));
@@ -1508,10 +1558,12 @@ void test25()
test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 5, 1, S("abcdefghijklmnopqrs6t"));
test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 5, 2, S("abcdefghijklmnopqrs67t"));
test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 5, 4, S("abcdefghijklmnopqrs6789t"));
return true;
}
template <class S>
void test26()
TEST_CONSTEXPR_CXX20 bool test26()
{
test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 5, 5, S("abcdefghijklmnopqrs67890t"));
test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 5, 6, S("abcdefghijklmnopqrs67890t"));
@@ -1563,10 +1615,12 @@ void test26()
test(S("abcdefghijklmnopqrst"), 20, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 20, S("12345"), 2, 1, S("abcdefghijklmnopqrst3"));
test(S("abcdefghijklmnopqrst"), 20, S("12345"), 2, 2, S("abcdefghijklmnopqrst34"));
return true;
}
template <class S>
void test27()
TEST_CONSTEXPR_CXX20 bool test27()
{
test(S("abcdefghijklmnopqrst"), 20, S("12345"), 2, 3, S("abcdefghijklmnopqrst345"));
test(S("abcdefghijklmnopqrst"), 20, S("12345"), 2, 4, S("abcdefghijklmnopqrst345"));
@@ -1618,10 +1672,12 @@ void test27()
test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrst123456789"));
test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrst1234567890"));
test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrst1234567890"));
return true;
}
template <class S>
void test28()
TEST_CONSTEXPR_CXX20 bool test28()
{
test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrst0"));
@@ -1673,10 +1729,12 @@ void test28()
test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 5, 4, S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 5, 5, S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 5, 6, S("can't happen"));
return true;
}
template <class S>
void test29()
TEST_CONSTEXPR_CXX20 bool test29()
{
test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 9, 0, S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 9, 1, S("can't happen"));
@@ -1708,10 +1766,12 @@ void test29()
test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 20, 0, S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 20, 1, S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 21, 0, S("can't happen"));
return true;
}
template <class S>
void test30()
TEST_CONSTEXPR_CXX20 bool test30()
{
test_npos(S(""), 0, S("12345678901234567890"), 0, S("12345678901234567890"));
test_npos(S(""), 0, S("12345678901234567890"), 1, S( "2345678901234567890"));
@@ -1725,79 +1785,84 @@ void test30()
test_npos(S("abcdefghijklmnopqrst"), 10, S("12345"), 3, S("abcdefghij45klmnopqrst"));
test_npos(S("abcdefghijklmnopqrst"), 10, S("12345"), 5, S("abcdefghijklmnopqrst"));
test_npos(S("abcdefghijklmnopqrst"), 10, S("12345"), 6, S("can't happen"));
return true;
}
template <class S>
void test() {
test0<S>();
test1<S>();
test2<S>();
test3<S>();
test4<S>();
test5<S>();
test6<S>();
test7<S>();
test8<S>();
test9<S>();
test10<S>();
test11<S>();
test12<S>();
test13<S>();
test14<S>();
test15<S>();
test16<S>();
test17<S>();
test18<S>();
test19<S>();
test20<S>();
test21<S>();
test22<S>();
test23<S>();
test24<S>();
test25<S>();
test26<S>();
test27<S>();
test28<S>();
test29<S>();
test30<S>();
#if TEST_STD_VER > 17
// static_assert(test0<S>());
// static_assert(test1<S>());
// static_assert(test2<S>());
// static_assert(test3<S>());
// static_assert(test4<S>());
// static_assert(test5<S>());
// static_assert(test6<S>());
// static_assert(test7<S>());
// static_assert(test8<S>());
// static_assert(test9<S>());
// static_assert(test10<S>());
// static_assert(test11<S>());
// static_assert(test12<S>());
// static_assert(test13<S>());
// static_assert(test14<S>());
// static_assert(test15<S>());
// static_assert(test16<S>());
// static_assert(test17<S>());
// static_assert(test18<S>());
// static_assert(test19<S>());
// static_assert(test20<S>());
// static_assert(test21<S>());
// static_assert(test22<S>());
// static_assert(test23<S>());
// static_assert(test24<S>());
// static_assert(test25<S>());
// static_assert(test26<S>());
// static_assert(test27<S>());
// static_assert(test28<S>());
// static_assert(test29<S>());
// static_assert(test30<S>());
#endif
}
int main(int, char**)
{
{
typedef std::string S;
test0<S>();
test1<S>();
test2<S>();
test3<S>();
test4<S>();
test5<S>();
test6<S>();
test7<S>();
test8<S>();
test9<S>();
test10<S>();
test11<S>();
test12<S>();
test13<S>();
test14<S>();
test15<S>();
test16<S>();
test17<S>();
test18<S>();
test19<S>();
test20<S>();
test21<S>();
test22<S>();
test23<S>();
test24<S>();
test25<S>();
test26<S>();
test27<S>();
test28<S>();
test29<S>();
test30<S>();
}
test<std::string>();
#if TEST_STD_VER >= 11
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test0<S>();
test1<S>();
test2<S>();
test3<S>();
test4<S>();
test5<S>();
test6<S>();
test7<S>();
test8<S>();
test9<S>();
test10<S>();
test11<S>();
test12<S>();
test13<S>();
test14<S>();
test15<S>();
test16<S>();
test17<S>();
test18<S>();
test19<S>();
test20<S>();
test21<S>();
test22<S>();
test23<S>();
test24<S>();
test25<S>();
test26<S>();
test27<S>();
test28<S>();
test29<S>();
test30<S>();
}
test<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
#endif
return 0;
@@ -19,7 +19,7 @@
#include "min_allocator.h"
template <class S, class SV>
void
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type pos, SV sv, S expected)
{
const typename S::size_type old_size = s.size();
@@ -47,9 +47,8 @@ test(S s, typename S::size_type pos, SV sv, S expected)
#endif
}
int main(int, char**)
{
{
bool test() {
{
typedef std::string S;
typedef std::string_view SV;
test(S(""), 0, SV(""), S(""));
@@ -132,9 +131,9 @@ int main(int, char**)
test(S("abcdefghijklmnopqrst"), 21, SV("12345"), S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, SV("1234567890"), S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, SV("12345678901234567890"), S("can't happen"));
}
}
#if TEST_STD_VER >= 11
{
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
typedef std::string_view SV;
test(S(""), 0, SV(""), S(""));
@@ -217,10 +216,10 @@ int main(int, char**)
test(S("abcdefghijklmnopqrst"), 21, SV("12345"), S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, SV("1234567890"), S("can't happen"));
test(S("abcdefghijklmnopqrst"), 21, SV("12345678901234567890"), S("can't happen"));
}
}
#endif
{ // test inserting into self
{ // test inserting into self
typedef std::string S;
S s_short = "123/";
S s_long = "Lorem ipsum dolor sit amet, consectetur/";
@@ -234,7 +233,17 @@ int main(int, char**)
s_long.insert(0, s_long.c_str());
assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
}
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
// static_assert(test());
#endif
return 0;
}