From 291b0075bb8563859d7c0507d36b64b839417bf3 Mon Sep 17 00:00:00 2001 From: Junliang HU Date: Mon, 29 Mar 2021 21:00:31 +0800 Subject: [PATCH] Add a test case: move ostream while holding data --- test/os-test.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/os-test.cc b/test/os-test.cc index 44a2988f..d9d094ce 100644 --- a/test/os-test.cc +++ b/test/os-test.cc @@ -293,6 +293,19 @@ TEST(OStreamTest, Move) { moved.print("hello"); } +TEST(OStreamTest, MoveWhileHoldingData) { + { + fmt::ostream out = fmt::output_file("test-file"); + out.print("Hello, "); + fmt::ostream moved(std::move(out)); + moved.print("world!\n"); + } + { + file in("test-file", file::RDONLY); + EXPECT_READ(in, "Hello, world!\n"); + } +} + TEST(OStreamTest, Print) { fmt::ostream out = fmt::output_file("test-file"); out.print("The answer is {}.\n", fmt::join(std::initializer_list{42}, ", "));