xo-object2: expand Printable.test.cpp to exercise DString
This commit is contained in:
parent
72b282d550
commit
71dcbe69f0
2 changed files with 29 additions and 11 deletions
|
|
@ -87,10 +87,10 @@ namespace xo {
|
|||
* @return pointer to newly created DString
|
||||
**/
|
||||
template <typename... Args>
|
||||
static DString * snprintf(obj<AAllocator> mm,
|
||||
size_type cap,
|
||||
const char * fmt,
|
||||
Args&&... args)
|
||||
static DString * printf(obj<AAllocator> mm,
|
||||
size_type cap,
|
||||
const char * fmt,
|
||||
Args&&... args)
|
||||
{
|
||||
DString * result = DString::empty(mm, cap);
|
||||
if (result) {
|
||||
|
|
@ -148,7 +148,12 @@ namespace xo {
|
|||
**/
|
||||
template <typename... Args>
|
||||
size_type sprintf(const char * fmt, Args&&... args) {
|
||||
int n = std::snprintf(chars_, capacity_, fmt, std::forward<Args>(args)...);
|
||||
int n;
|
||||
if constexpr (sizeof...(Args) == 0) {
|
||||
n = std::snprintf(chars_, capacity_, "%s", fmt);
|
||||
} else {
|
||||
n = std::snprintf(chars_, capacity_, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
if (n < 0) {
|
||||
size_ = 0;
|
||||
chars_[0] = '\0';
|
||||
|
|
|
|||
|
|
@ -12,6 +12,10 @@
|
|||
#include <xo/object2/IGCObject_DList.hpp>
|
||||
#include <xo/object2/IPrintable_DList.hpp>
|
||||
|
||||
#include <xo/object2/DString.hpp>
|
||||
#include <xo/object2/string/IGCObject_DString.hpp>
|
||||
#include <xo/object2/string/IPrintable_DString.hpp>
|
||||
|
||||
#include <xo/object2/DInteger.hpp>
|
||||
#include <xo/object2/IGCObject_DInteger.hpp>
|
||||
|
||||
|
|
@ -35,6 +39,7 @@ namespace ut {
|
|||
using xo::scm::ListOps;
|
||||
using xo::scm::DList;
|
||||
using xo::scm::DInteger;
|
||||
using xo::scm::DString;
|
||||
using xo::mm::AAllocator;
|
||||
using xo::mm::ACollector;
|
||||
using xo::mm::AGCObject;
|
||||
|
|
@ -70,10 +75,10 @@ namespace ut {
|
|||
std::vector<testcase_pp>
|
||||
s_testcase_v = {
|
||||
testcase_pp(16384, 8192, 0, "()"),
|
||||
testcase_pp(16384, 8192, 1, "(1000)"),
|
||||
testcase_pp(16384, 8192, 2, "(1000 1197)"),
|
||||
testcase_pp(16384, 8192, 5, "(1000 1197 1394 1591 1788)"),
|
||||
testcase_pp(16384, 8192, 10, "(1000 1197 1394 1591 1788 1985 2182 2379 2576 2773)"),
|
||||
testcase_pp(16384, 8192, 1, "(01000)"),
|
||||
testcase_pp(16384, 8192, 2, "(01000 1197)"),
|
||||
testcase_pp(16384, 8192, 5, "(01000 1197 01394 1591 01788)"),
|
||||
testcase_pp(16384, 8192, 10, "(01000 1197 01394 1591 01788 1985 02182 2379 02576 2773)"),
|
||||
testcase_pp(16384, 8192, 20, "(...)"),
|
||||
};
|
||||
}
|
||||
|
|
@ -117,9 +122,17 @@ namespace ut {
|
|||
c_o.add_gc_root(&l0_o);
|
||||
|
||||
for(int ip1 = tc.list_.size(); ip1 > 0; --ip1) {
|
||||
auto xi_o = DInteger::box<AGCObject>(gc_o, tc.list_[ip1 - 1]);
|
||||
obj<AGCObject> elt;
|
||||
|
||||
l0_o = ListOps::cons(gc_o, xi_o, l0_o);
|
||||
//elt = DInteger::box<AGCObject>(gc_o, tc.list_[ip1 - 1]);
|
||||
|
||||
if (ip1 % 2 == 0) {
|
||||
elt = DInteger::box<AGCObject>(gc_o, tc.list_[ip1 - 1]);
|
||||
} else {
|
||||
elt = obj<AGCObject,DString>(DString::printf(gc_o, 80, "%05d", tc.list_[ip1 - 1]));
|
||||
}
|
||||
|
||||
l0_o = ListOps::cons(gc_o, elt, l0_o);
|
||||
}
|
||||
|
||||
// TODO: log_streambuf using DArena
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue