diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_format.cpp | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/test/test_format.cpp b/test/test_format.cpp index f0ea93f..9c95330 100644 --- a/test/test_format.cpp +++ b/test/test_format.cpp @@ -19,6 +19,7 @@ #include "fud_string_view.hpp" #include "gtest/gtest.h" +#include <format> namespace fud { @@ -410,31 +411,30 @@ TEST(FormatTest, FormatTest) EXPECT_EQ(formatSpecResult.takeError(), FudStatus::FormatInvalid); } -TEST(FormatTest, ValidateSpecHelperTest) -{ - constexpr size_t invalid = 0xFFFF; - EXPECT_EQ(impl::validateSpecHelper("").getOkayOr(invalid), 0); - EXPECT_EQ(impl::validateSpecHelper("{}").getOkayOr(invalid), 1); - EXPECT_EQ(impl::validateSpecHelper("{{{}").getOkayOr(invalid), 1); - EXPECT_EQ(impl::validateSpecHelper("{}}}").getOkayOr(invalid), 1); - EXPECT_EQ(impl::validateSpecHelper("{{{}}}").getOkayOr(invalid), 1); - EXPECT_EQ(impl::validateSpecHelper("}").getErrorOr(FudStatus::Failure), FudStatus::FormatInvalid); - EXPECT_EQ(impl::validateSpecHelper("{}}").getErrorOr(FudStatus::Failure), FudStatus::FormatInvalid); - EXPECT_EQ(impl::validateSpecHelper("{").getErrorOr(FudStatus::Failure), FudStatus::FormatInvalid); - EXPECT_EQ(impl::validateSpecHelper("{{}").getErrorOr(FudStatus::Failure), FudStatus::FormatInvalid); - EXPECT_EQ(impl::validateSpecHelper("{{}").getOkayOr(invalid), invalid); - EXPECT_EQ(impl::validateSpecHelper("{{{}}} {} {{ }} {{{}}}").getOkayOr(invalid), 3); - EXPECT_EQ(impl::validateSpecHelper("{{{}}} {} {{ }} {{ }}}").getOkayOr(invalid), invalid); - EXPECT_EQ( - impl::validateSpecHelper("{{{}}} {} {{ }} {{{ }}").getErrorOr(FudStatus::Failure), - FudStatus::FormatInvalid); -} - TEST(FormatTest, OneArgFormatTest) { String sink{}; - auto formatResult = format(sink, FormatCharMode::Unchecked, "Test {:X}", 42U); + auto formatResult = format(sink, FormatCharMode::Unchecked, "Test {:}", 42U); + EXPECT_TRUE(formatResult.isOkay()); + + ASSERT_EQ(sink.clear(), FudStatus::Success); + ASSERT_EQ(sink.drain(StringView{4, "TEST"}).bytesWritten, 4); + ASSERT_TRUE(sink.valid()); + ASSERT_EQ(sink.clear(), FudStatus::Success); + + auto expected = std::format("{:6}", 42U); + formatResult = format(sink, FormatCharMode::Unchecked, "{:6}", 42U); EXPECT_TRUE(formatResult.isOkay()); + EXPECT_STREQ(sink.c_str(), expected.c_str()); + + /* + EXPECT_EQ(std::format("{:6}", 'x') , "x "); + EXPECT_EQ(std::format("{:*<6}", 'x') , "x*****"); + EXPECT_EQ(std::format("{:*>6}", 'x') , "*****x"); + EXPECT_EQ(std::format("{:*^6}", 'x') , "**x***"); + EXPECT_EQ(std::format("{:6d}", c) , " 120"); + EXPECT_EQ(std::format("{:6}", true) , "true "); + */ } } // namespace fud |