Alien-libpanda
view release on metacpan or search on metacpan
t/string_test.h view on Meta::CPAN
SECTION("sso<->external") {
auto exp1 = mstr("eb");
auto exp2 = mstr("ta", 50);
String s1(exp1.c_str());
FString s2 = create_external<FString>(exp2);
get_allocs();
s1.swap(s2);
REQUIRE_STR(s1, exp2);
REQUIRE_STR(s2, exp1, MAX_SSO_CHARS);
s2 = EMPTY;
CHECK_ALLOCS();
s1 = EMPTY;
CHECK_ALLOCS(0,0,1,EBUF_CHARS,0,0,1,exp2.size());
}
SECTION("internal<->internal") {
auto exp1 = mstr("eb", 100);
auto exp2 = mstr("ta", 50);
String s1(exp1.c_str());
FString s2(exp2.c_str());
CHECK_ALLOCS(2, BUF_CHARS*2 + exp1.size() + exp2.size());
s1.swap(s2);
CHECK_ALLOCS();
REQUIRE_STR(s1, exp2);
REQUIRE_STR(s2, exp1);
s1 = EMPTY;
CHECK_ALLOCS(0,0,1,BUF_CHARS+exp2.size());
s2 = EMPTY;
CHECK_ALLOCS(0,0,1,BUF_CHARS+exp1.size());
}
SECTION("internal<->external") {
auto exp1 = mstr("eb", 100);
auto exp2 = mstr("ta", 50);
String s1(exp1.c_str());
FString s2 = create_external<FString>(exp2);
CHECK_ALLOCS(2, EBUF_CHARS + BUF_CHARS + exp1.size());
s1.swap(s2);
REQUIRE_STR(s1, exp2);
REQUIRE_STR(s2, exp1);
s1 = EMPTY;
CHECK_ALLOCS(0,0,1,EBUF_CHARS,0,0,1,exp2.size());
s2 = EMPTY;
CHECK_ALLOCS(0,0,1,BUF_CHARS+exp1.size());
}
SECTION("external<->external") {
auto exp1 = mstr("eb", 100);
auto exp2 = mstr("ta", 50);
String s1 = create_external<>(exp1);
FString s2 = create_external<FString>(exp2);
CHECK_ALLOCS(2, EBUF_CHARS*2);
s1.swap(s2);
REQUIRE_STR(s1, exp2);
REQUIRE_STR(s2, exp1);
s1 = EMPTY;
CHECK_ALLOCS(0,0,1,EBUF_CHARS,0,0,1,exp2.size());
s2 = EMPTY;
CHECK_ALLOCS(0,0,1,EBUF_CHARS,0,0,1,exp1.size());
}
}
static void test_copy () {
String s(cstr("the password for my bank account is w74mnds320ft but i won't tell you the login)"));
T t[500];
size_t cnt;
cnt = s.copy(t, 0);
REQUIRE(cnt == 0);
cnt = s.copy(t, 10);
REQUIRE(cnt == 10);
REQUIRE_STRM(String(t, cnt), mstr("the passwo"));
cnt = s.copy(t, 20, 15);
REQUIRE(cnt == 20);
REQUIRE_STRM(String(t, cnt), mstr("r my bank account is"));
cnt = s.copy(t, 20, 70); //too much count
REQUIRE(cnt == 10);
REQUIRE_STRM(String(t, cnt), mstr("the login)"));
cnt = s.copy(t, String::npos, 60); //count=npos
REQUIRE(cnt == 20);
REQUIRE_STRM(String(t, cnt), mstr(" tell you the login)"));
REQUIRE_THROWS(s.copy(t, 10, 90)); //too much offset
}
static void test_bool_empty () {
String s;
REQUIRE(s.empty());
REQUIRE(!s);
s = 'a';
REQUIRE(!s.empty());
REQUIRE(s);
}
static void test_use_count () {
String s1(LITERAL);
String s2(s1);
REQUIRE(s1.use_count() == 1);
REQUIRE(s2.use_count() == 1);
s1 = cstr("ab");
s2 = s1;
REQUIRE(s1.use_count() == 1);
REQUIRE(s2.use_count() == 1);
s1 = cstr("a", 50);
REQUIRE(s1.use_count() == 1);
s2 = s1;
REQUIRE(s1.use_count() == 2);
REQUIRE(s2.use_count() == 2);
s1 = create_external<>(mstr("b", 50));
REQUIRE(s1.use_count() == 1);
s2 = s1;
REQUIRE(s1.use_count() == 2);
REQUIRE(s2.use_count() == 2);
}
static void test_detach () {
get_allocs();
( run in 0.714 second using v1.01-cache-2.11-cpan-fa01517f264 )