print: Add c++23 print compatible implementation
Change-Id: I2bb81f79550f3e9bdb0ea15cb21225a015d17800
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/print.cpp b/test/print.cpp
new file mode 100644
index 0000000..4e511ed
--- /dev/null
+++ b/test/print.cpp
@@ -0,0 +1,31 @@
+#include <stdplus/print.hpp>
+
+#include <cstdio>
+
+#include <gtest/gtest.h>
+
+namespace stdplus
+{
+
+TEST(Print, Basic)
+{
+ auto file = std::tmpfile();
+ print(file, "hello");
+ print(file, "hi {}\n", 4);
+ println(file, "ho\n");
+ println(file, "ho {}", 16);
+ EXPECT_EQ(0, std::fseek(file, 0, SEEK_SET));
+ constexpr std::string_view expect = "hellohi 4\nho\n\nho 16\n";
+ std::string buf(expect.size(), '\0');
+ EXPECT_EQ(buf.size(),
+ std::fread(buf.data(), sizeof(char), buf.size() + 1, file));
+ EXPECT_EQ(buf, expect);
+ EXPECT_EQ(0, std::fclose(file));
+
+ print("hello");
+ print("hi {}\n", 4);
+ println("ho\n");
+ println("ho {}", 16);
+}
+
+} // namespace stdplus