Skip to content

Commit

Permalink
CXXCBC-638: fix transactions examples test
Browse files Browse the repository at this point in the history
  • Loading branch information
avsej committed Jan 14, 2025
1 parent 4ece9a8 commit 6b39a2c
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions test/test_transaction_examples.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,11 @@ class byte_appender
using iterator_category = std::output_iterator_tag;
using value_type = void;

explicit byte_appender(std::vector<std::byte>& output)
: buffer_{ output }
{
}

auto operator=(char ch) -> byte_appender&
{
buffer_.push_back(static_cast<std::byte>(ch));
Expand All @@ -398,13 +403,8 @@ class byte_appender
return *this;
}

[[nodiscard]] auto buffer() const -> const std::vector<std::byte>&
{
return buffer_;
}

private:
std::vector<std::byte> buffer_{};
std::vector<std::byte>& buffer_;
};

template<>
Expand Down Expand Up @@ -452,7 +452,14 @@ class ledger

[[nodiscard]] auto to_csv() const -> std::vector<std::byte>
{
byte_appender output;
if (entries_.empty()) {
return {
std::byte{ '\n' },
};
}

std::vector<std::byte> buffer;
byte_appender output{ buffer };

fmt::format_to(output, "Date,Description,Account,Debit,Credit\n");
for (const auto& entry : entries_) {
Expand All @@ -464,7 +471,7 @@ class ledger
entry.debit,
entry.credit);
}
return output.buffer();
return buffer;
}

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

0 comments on commit 6b39a2c

Please sign in to comment.