xo-object2: + StringOps::from_cstr + utest
This commit is contained in:
parent
3349cea289
commit
cb56e1ed26
2 changed files with 29 additions and 2 deletions
|
|
@ -22,6 +22,10 @@ namespace xo {
|
|||
template <typename AFacet = AGCObject>
|
||||
static obj<AFacet,DString> empty(obj<AAllocator> mm,
|
||||
size_type cap);
|
||||
|
||||
template <typename AFacet = AGCObject>
|
||||
static obj<AFacet,DString> from_cstr(obj<AAllocator> mm,
|
||||
const char * cstr);
|
||||
};
|
||||
|
||||
template <typename AFacet>
|
||||
|
|
@ -30,6 +34,13 @@ namespace xo {
|
|||
{
|
||||
return obj<AFacet,DString>(DString::empty(mm, cap));
|
||||
}
|
||||
|
||||
template <typename AFacet>
|
||||
obj<AFacet,DString>
|
||||
StringOps::from_cstr(obj<AAllocator> mm, const char * cstr)
|
||||
{
|
||||
return obj<AFacet,DString>(DString::from_cstr(mm, cstr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace xo {
|
|||
DArena arena = DArena::map(cfg);
|
||||
auto alloc = with_facet<AAllocator>::mkobj(&arena);
|
||||
|
||||
obj<AGCObject, DString> s = StringOps::empty(alloc, 16);
|
||||
auto s = StringOps::empty(alloc, 16);
|
||||
|
||||
REQUIRE(s.data() != nullptr);
|
||||
REQUIRE(s.data()->capacity() == 16);
|
||||
|
|
@ -41,13 +41,29 @@ namespace xo {
|
|||
DArena arena = DArena::map(cfg);
|
||||
auto alloc = with_facet<AAllocator>::mkobj(&arena);
|
||||
|
||||
obj<AGCObject, DString> s = StringOps::empty(alloc, 32);
|
||||
auto s = StringOps::empty(alloc, 32);
|
||||
|
||||
s.data()->sprintf("hello %s %d", "world", 42);
|
||||
|
||||
REQUIRE(s.data()->size() == 14);
|
||||
REQUIRE(std::strcmp(s.data()->chars(), "hello world 42") == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("StringOps-from_cstr", "[object2][StringOps]")
|
||||
{
|
||||
ArenaConfig cfg { .name_ = "testarena",
|
||||
.size_ = 4*1024 };
|
||||
DArena arena = DArena::map(cfg);
|
||||
auto alloc = with_facet<AAllocator>::mkobj(&arena);
|
||||
|
||||
const char * cstr = "hello world";
|
||||
auto s = StringOps::from_cstr(alloc, cstr);
|
||||
|
||||
REQUIRE(s.data() != nullptr);
|
||||
REQUIRE(s.data()->capacity() == 12);
|
||||
REQUIRE(s.data()->size() == 11);
|
||||
REQUIRE(std::strcmp(s.data()->chars(), cstr) == 0);
|
||||
}
|
||||
} /*namespace ut*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue