summaryrefslogtreecommitdiff
path: root/test/test_format.cpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-10-25 01:09:10 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-10-25 01:09:10 -0500
commit11968f674a7de34fb7de744598a8086330cd88a3 (patch)
treebe5b885ef47c8ceab50f558c8aef6632fefc94d1 /test/test_format.cpp
parent512d026de016f2720060d264adec02e56123851d (diff)
Get working string formatting for unsigned numbers.
Diffstat (limited to 'test/test_format.cpp')
-rw-r--r--test/test_format.cpp42
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