summaryrefslogtreecommitdiff
path: root/test/test_format.cpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-10-25 17:13:49 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-10-25 17:13:49 -0500
commit7b30a5425eaf7aae1d72d5ba564092e342901fe8 (patch)
tree8a74d0810ea4db23d4d0c6c4ba8d91518d569db2 /test/test_format.cpp
parent11968f674a7de34fb7de744598a8086330cd88a3 (diff)
A lot of work on formatting.
Diffstat (limited to 'test/test_format.cpp')
-rw-r--r--test/test_format.cpp108
1 files changed, 95 insertions, 13 deletions
diff --git a/test/test_format.cpp b/test/test_format.cpp
index 9c95330..4a93d98 100644
--- a/test/test_format.cpp
+++ b/test/test_format.cpp
@@ -411,30 +411,112 @@ TEST(FormatTest, FormatTest)
EXPECT_EQ(formatSpecResult.takeError(), FudStatus::FormatInvalid);
}
-TEST(FormatTest, OneArgFormatTest)
+TEST(FormatTest, NoArgFormatTest)
{
String sink{};
- auto formatResult = format(sink, FormatCharMode::Unchecked, "Test {:}", 42U);
+ auto expected = std::format("Test");
+ auto formatResult = format(sink, FormatCharMode::Unchecked, "Test");
EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
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);
+ expected = std::format("");
+ formatResult = format(sink, FormatCharMode::Unchecked, "");
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+}
+TEST(FormatTest, OneNumberFormatTest)
+{
+ String sink{};
+ auto formatResult = format(sink, FormatCharMode::Unchecked, "Test {:}", 42U);
+ EXPECT_TRUE(formatResult.isOkay());
+
+ 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 ");
- */
+ ASSERT_EQ(sink.clear(), FudStatus::Success);
+ expected = std::format("{:*<6}", std::numeric_limits<uint64_t>::max());
+ formatResult = format(sink, FormatCharMode::Unchecked, "{:*<6}", std::numeric_limits<uint64_t>::max());
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+
+ ASSERT_EQ(sink.clear(), FudStatus::Success);
+ expected = std::format("{:*<6}", std::numeric_limits<int64_t>::min());
+ formatResult = format(sink, FormatCharMode::Unchecked, "{:*<6}", std::numeric_limits<int64_t>::min());
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+
+ ASSERT_EQ(sink.clear(), FudStatus::Success);
+ expected = std::format("{:}", std::numeric_limits<int8_t>::min());
+ formatResult = format(sink, FormatCharMode::Unchecked, "{:}", std::numeric_limits<int8_t>::min());
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+
+ ASSERT_EQ(sink.clear(), FudStatus::Success);
+ expected = std::format("{:#X}", std::numeric_limits<int8_t>::min());
+ formatResult = format(sink, FormatCharMode::Unchecked, "{:#X}", std::numeric_limits<int8_t>::min());
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+
+ ASSERT_EQ(sink.clear(), FudStatus::Success);
+ expected = std::format("{:*<6}", 42U);
+ formatResult = format(sink, FormatCharMode::Unchecked, "{:*<6}", 42U);
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+
+ ASSERT_EQ(sink.clear(), FudStatus::Success);
+ expected = std::format("{:*>6}", 42U);
+ formatResult = format(sink, FormatCharMode::Unchecked, "{:*>6}", 42U);
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+
+ ASSERT_EQ(sink.clear(), FudStatus::Success);
+ expected = std::format("{:*^6}", 42U);
+ formatResult = format(sink, FormatCharMode::Unchecked, "{:*^6}", 42U);
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+
+ ASSERT_EQ(sink.clear(), FudStatus::Success);
+ expected = std::format("{:*<6}", 'x');
+ formatResult = format(sink, FormatCharMode::Unchecked, "{:*<6}", 'x');
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+
+ ASSERT_EQ(sink.clear(), FudStatus::Success);
+ expected = std::format("{:6d}", 'x');
+ formatResult = format(sink, FormatCharMode::Unchecked, "{:6d}", 'x');
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+}
+
+TEST(FormatTest, OneBoolFormatTest)
+{
+ String sink{};
+
+ ASSERT_EQ(sink.clear(), FudStatus::Success);
+ auto expected = std::format("{:6}", true);
+ auto formatResult = format(sink, FormatCharMode::Unchecked, "{:6}", true);
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+}
+
+TEST(FormatTest, TwoArgFormatTest)
+{
+ String sink{};
+ auto expected = std::format("Test {:} {:}", 1U, false);
+ auto formatResult = format(sink, FormatCharMode::Unchecked, "Test {:} {:}", 1U, false);
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+
+ ASSERT_EQ(sink.clear(), FudStatus::Success);
+ expected = std::format("Test {:} {:}", 1U, "Hello");
+ formatResult = format(sink, FormatCharMode::Unchecked, "Test {:} {:}", 1U, "Hello");
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
}
} // namespace fud