Add a simple buffered stream with no sync
This commit is contained in:
@@ -141,7 +141,8 @@ class SuppressAssert {
|
||||
std::string read(fmt::file& f, size_t count);
|
||||
|
||||
# define EXPECT_READ(file, expected_content) \
|
||||
EXPECT_EQ(expected_content, read(file, std::strlen(expected_content)))
|
||||
EXPECT_EQ(expected_content, \
|
||||
read(file, fmt::string_view(expected_content).size()))
|
||||
|
||||
#else
|
||||
# define EXPECT_WRITE(file, statement, expected_output) SUCCEED()
|
||||
|
||||
@@ -287,6 +287,26 @@ TEST(BufferedFileTest, Fileno) {
|
||||
EXPECT_READ(copy, FILE_CONTENT);
|
||||
}
|
||||
|
||||
TEST(DirectBufferedFileTest, Print) {
|
||||
fmt::direct_buffered_file out(
|
||||
"test-file", fmt::file::WRONLY | fmt::file::CREATE);
|
||||
fmt::print(out, "The answer is {}.\n", 42);
|
||||
out.close();
|
||||
file in("test-file", file::RDONLY);
|
||||
EXPECT_READ(in, "The answer is 42.\n");
|
||||
}
|
||||
|
||||
TEST(DirectBufferedFileTest, BufferBoundary) {
|
||||
auto str = std::string(4096, 'x');
|
||||
fmt::direct_buffered_file out(
|
||||
"test-file", fmt::file::WRONLY | fmt::file::CREATE);
|
||||
fmt::print(out, "{}", str);
|
||||
fmt::print(out, "{}", str);
|
||||
out.close();
|
||||
file in("test-file", file::RDONLY);
|
||||
EXPECT_READ(in, str + str);
|
||||
}
|
||||
|
||||
TEST(FileTest, DefaultCtor) {
|
||||
file f;
|
||||
EXPECT_EQ(-1, f.descriptor());
|
||||
|
||||
Reference in New Issue
Block a user