Alien-libpanda
view release on metacpan or search on metacpan
t/string_test.h view on Meta::CPAN
REQUIRE(s1 >= s2);
REQUIRE_FALSE(s1 >= s3);
REQUIRE(s1 >= s4);
REQUIRE_FALSE(s1 < s2);
REQUIRE(s1 < s3);
REQUIRE_FALSE(s1 < s4);
REQUIRE_FALSE(s1 <= s2);
REQUIRE(s1 <= s3);
REQUIRE(s1 <= s4);
CHECK_ALLOCS();
}
template <class FString>
static void test_find () {
auto npos = String::npos;
String s(cstr("jopa noviy god"));
SECTION("find") {
REQUIRE(s.find(FString(cstr("o"))) == 1);
REQUIRE(s.find(FString(cstr("jopa"))) == 0);
REQUIRE(s.find(FString(cstr("noviy"))) == 5);
REQUIRE(s.find(FString(cstr("god"))) == 11);
REQUIRE(s.find(FString(cstr("o")), 2) == 6);
REQUIRE(s.find(FString(EMPTY), 0) == 0);
REQUIRE(s.find(FString(EMPTY), 13) == 13);
REQUIRE(s.find(FString(EMPTY), 14) == 14);
REQUIRE(s.find(FString(EMPTY), 15) == npos);
REQUIRE(s.find(FString(cstr("o")), 14) == npos);
REQUIRE(s.find(FString(cstr("god")), 11) == 11);
REQUIRE(s.find(FString(cstr("god")), 12) == npos);
}
SECTION("rfind") {
REQUIRE(s.rfind(FString(cstr("o"))) == 12);
REQUIRE(s.rfind(FString(cstr("o")), 99999) == 12);
REQUIRE(s.rfind(FString(cstr("jopa"))) == 0);
REQUIRE(s.rfind(FString(cstr("jopa")), 0) == 0);
REQUIRE(s.rfind(FString(cstr("noviy"))) == 5);
REQUIRE(s.rfind(FString(cstr("o")), 11) == 6);
REQUIRE(s.rfind(FString(EMPTY), 0) == 0);
REQUIRE(s.rfind(FString(EMPTY), 13) == 13);
REQUIRE(s.rfind(FString(EMPTY), 14) == 14);
REQUIRE(s.rfind(FString(EMPTY), 15) == 14);
REQUIRE(s.rfind(FString(cstr("o")), 0) == npos);
REQUIRE(s.rfind(FString(cstr("god")), 11) == 11);
REQUIRE(s.rfind(FString(cstr("god")), 10) == npos);
}
SECTION("find_first_of") {
REQUIRE(s.find_first_of(FString(cstr("o"))) == 1);
REQUIRE(s.find_first_of(FString(cstr("o")), 2) == 6);
REQUIRE(s.find_first_of(FString(cstr("o")), 14) == npos);
REQUIRE(s.find_first_of(FString(EMPTY), 0) == npos);
REQUIRE(s.find_first_of(FString(EMPTY), 15) == npos);
REQUIRE(s.find_first_of(FString(cstr("pnv"))) == 2);
REQUIRE(s.find_first_of(FString(cstr("pnv")), 3) == 5);
REQUIRE(s.find_first_of(FString(cstr("pnv")), 6) == 7);
REQUIRE(s.find_first_of(FString(cstr("pnv")), 8) == npos);
}
SECTION("find_first_not_of") {
REQUIRE(s.find_first_not_of(FString(cstr("o"))) == 0);
REQUIRE(s.find_first_not_of(FString(cstr("j"))) == 1);
REQUIRE(s.find_first_not_of(FString(cstr("o")), 1) == 2);
REQUIRE(s.find_first_not_of(FString(cstr("d")), 13) == npos);
REQUIRE(s.find_first_not_of(FString(EMPTY), 0) == 0);
REQUIRE(s.find_first_not_of(FString(EMPTY), 15) == npos);
REQUIRE(s.find_first_not_of(FString(cstr("jopa nviy"))) == 11);
REQUIRE(s.find_first_not_of(FString(cstr("og ")), 10) == 13);
REQUIRE(s.find_first_not_of(FString(cstr("ogd ")), 10) == npos);
}
SECTION("find_last_of") {
REQUIRE(s.find_last_of(FString(cstr("o"))) == 12);
REQUIRE(s.find_last_of(FString(cstr("o")), 9999) == 12);
REQUIRE(s.find_last_of(FString(cstr("o")), 10) == 6);
REQUIRE(s.find_last_of(FString(cstr("o")), 1) == 1);
REQUIRE(s.find_last_of(FString(cstr("o")), 0) == npos);
REQUIRE(s.find_last_of(FString(EMPTY), 0) == npos);
REQUIRE(s.find_last_of(FString(EMPTY), 15) == npos);
REQUIRE(s.find_last_of(FString(cstr("pnv"))) == 7);
REQUIRE(s.find_last_of(FString(cstr("pnv")), 6) == 5);
REQUIRE(s.find_last_of(FString(cstr("pnv")), 4) == 2);
REQUIRE(s.find_last_of(FString(cstr("pnv")), 1) == npos);
}
SECTION("find_last_not_of") {
REQUIRE(s.find_last_not_of(FString(cstr("o"))) == 13);
REQUIRE(s.find_last_not_of(FString(cstr("d"))) == 12);
REQUIRE(s.find_last_not_of(FString(cstr("d")), 9999) == 12);
REQUIRE(s.find_last_not_of(FString(cstr("d")), 12) == 12);
REQUIRE(s.find_last_not_of(FString(cstr("o")), 12) == 11);
REQUIRE(s.find_last_not_of(FString(cstr("j")), 0) == npos);
REQUIRE(s.find_last_not_of(FString(EMPTY), 0) == 0);
REQUIRE(s.find_last_not_of(FString(EMPTY), 13) == 13);
REQUIRE(s.find_last_not_of(FString(EMPTY), 14) == 13);
REQUIRE(s.find_last_not_of(FString(EMPTY), 15) == 13);
REQUIRE(s.find_last_not_of(FString(cstr("nviy god"))) == 3);
REQUIRE(s.find_last_not_of(FString(cstr("jpa ")), 4) == 1);
REQUIRE(s.find_last_not_of(FString(cstr("jopa ")), 4) == npos);
}
}
static void test_reserve () {
get_allocs();
SECTION("literal") {
get_allocs();
String s(LITERAL);
SECTION(">len") {
s.reserve(100);
REQUIRE_STR(s, LITERAL, LITERAL_LEN, 100);
CHECK_ALLOCS(1, BUF_CHARS+100);
}
SECTION("<len") {
s.reserve(LITERAL_LEN-1);
REQUIRE_STR(s, LITERAL, LITERAL_LEN, LITERAL_LEN);
CHECK_ALLOCS(1, BUF_CHARS+LITERAL_LEN);
}
SECTION("=0") {
s.reserve(0);
REQUIRE_STR(s, LITERAL, LITERAL_LEN, LITERAL_LEN);
CHECK_ALLOCS(1, BUF_CHARS+LITERAL_LEN);
}
}
if (CHAR_SIZE == 1) {
SECTION("sso") {
get_allocs();
auto exp = mstr("hello");
SECTION("<= max sso") {
String s(exp.c_str());
s.reserve(0);
REQUIRE_STR(s, exp, MAX_SSO_CHARS);
CHECK_ALLOCS();
s.reserve(MAX_SSO_CHARS);
REQUIRE_STR(s, exp, MAX_SSO_CHARS);
CHECK_ALLOCS();
}
SECTION("> max sso") {
String s(exp.c_str());
s.reserve(MAX_SSO_CHARS+1);
REQUIRE_STR(s, exp, MAX_SSO_CHARS+1);
CHECK_ALLOCS(1, BUF_CHARS+MAX_SSO_CHARS+1);
}
SECTION("offset, <= capacity") {
String s((mstr("hi")+exp).c_str());
s.offset(2);
REQUIRE_STR(s, exp, MAX_SSO_CHARS-2);
s.reserve(MAX_SSO_CHARS-2);
REQUIRE_STR(s, exp, MAX_SSO_CHARS-2);
CHECK_ALLOCS();
}
SECTION("offset, > capacity, <= max sso") {
String s((mstr("hi")+exp).c_str());
s.offset(2);
REQUIRE_STR(s, exp, MAX_SSO_CHARS-2);
s.reserve(MAX_SSO_CHARS);
REQUIRE_STR(s, exp, MAX_SSO_CHARS);
CHECK_ALLOCS(); // string should has been moved to the beginning, no allocs
}
}
( run in 1.603 second using v1.01-cache-2.11-cpan-acebb50784d )