Skip to content

Commit 428d64f

Browse files
authored
CXXCBC-638: fix transactions examples test (#710)
1 parent 4ece9a8 commit 428d64f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

test/test_transaction_examples.cxx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,11 @@ class byte_appender
377377
using iterator_category = std::output_iterator_tag;
378378
using value_type = void;
379379

380+
explicit byte_appender(std::vector<std::byte>& output)
381+
: buffer_{ output }
382+
{
383+
}
384+
380385
auto operator=(char ch) -> byte_appender&
381386
{
382387
buffer_.push_back(static_cast<std::byte>(ch));
@@ -398,13 +403,8 @@ class byte_appender
398403
return *this;
399404
}
400405

401-
[[nodiscard]] auto buffer() const -> const std::vector<std::byte>&
402-
{
403-
return buffer_;
404-
}
405-
406406
private:
407-
std::vector<std::byte> buffer_{};
407+
std::vector<std::byte>& buffer_;
408408
};
409409

410410
template<>
@@ -452,7 +452,14 @@ class ledger
452452

453453
[[nodiscard]] auto to_csv() const -> std::vector<std::byte>
454454
{
455-
byte_appender output;
455+
if (entries_.empty()) {
456+
return {
457+
std::byte{ '\n' },
458+
};
459+
}
460+
461+
std::vector<std::byte> buffer;
462+
byte_appender output{ buffer };
456463

457464
fmt::format_to(output, "Date,Description,Account,Debit,Credit\n");
458465
for (const auto& entry : entries_) {
@@ -464,7 +471,7 @@ class ledger
464471
entry.debit,
465472
entry.credit);
466473
}
467-
return output.buffer();
474+
return buffer;
468475
}
469476

470477
static auto from_csv(const std::vector<std::byte>& blob) -> ledger

0 commit comments

Comments
 (0)