diff options
author | eldritch horrors <pennae@lix.systems> | 2024-06-27 21:23:50 +0200 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-07-05 22:28:16 +0000 |
commit | b51ea465de48e4c5516ba0182cc642b4e644be10 (patch) | |
tree | ed8aa9edc953af11c29a7e6b4d4f811555568d22 /tests | |
parent | b9f91ec3c5da5b59ff095011493dd6d2093bdd3d (diff) |
libutil: allow construction of sources from generators
Change-Id: I78ff8d0720f06bce731e26d5e1c53b1382bbd589
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/libutil/serialise.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/unit/libutil/serialise.cc b/tests/unit/libutil/serialise.cc index 78882ad2c..4fe010af8 100644 --- a/tests/unit/libutil/serialise.cc +++ b/tests/unit/libutil/serialise.cc @@ -214,4 +214,25 @@ TEST(WireFormatGenerator, exampleMessage) })); } +TEST(GeneratorSource, works) +{ + GeneratorSource src = []() -> Generator<Bytes> { + co_yield std::span{"", 0}; + co_yield std::span{"a", 1}; + co_yield std::span{"", 0}; + co_yield std::span{"bcd", 3}; + co_yield std::span{"", 0}; + }(); + + char buf[2]; + ASSERT_EQ(src.read(buf, sizeof(buf)), 1); + ASSERT_EQ(buf[0], 'a'); + ASSERT_EQ(src.read(buf, sizeof(buf)), 2); + ASSERT_EQ(buf[0], 'b'); + ASSERT_EQ(buf[1], 'c'); + ASSERT_EQ(src.read(buf, sizeof(buf)), 1); + ASSERT_EQ(buf[0], 'd'); + ASSERT_THROW(src.read(buf, sizeof(buf)), EndOfFile); +} + } |