summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_assert.cpp14
-rw-r--r--test/test_format.cpp108
2 files changed, 109 insertions, 13 deletions
diff --git a/test/test_assert.cpp b/test/test_assert.cpp
index 1f95388..5129b97 100644
--- a/test/test_assert.cpp
+++ b/test/test_assert.cpp
@@ -18,6 +18,7 @@
#include "fud_assert.hpp"
#include "gtest/gtest.h"
+#include "gmock/gmock.h"
namespace fud {
@@ -26,4 +27,17 @@ TEST(AssertTest, AssertFud)
EXPECT_EXIT(fudAssert(false), ::testing::KilledBySignal(SIGABRT), ".*");
}
+TEST(AssertTest, AssertFudMessage)
+{
+ testing::internal::CaptureStderr();
+ auto sourceLoc = std::source_location::current();
+ constexpr const char* assertMessage = "Artificial Message";
+ impl::assertFailMessage(assertMessage, sourceLoc);
+ auto message = testing::internal::GetCapturedStderr();
+ EXPECT_THAT(message, testing::HasSubstr(sourceLoc.file_name()));
+ EXPECT_THAT(message, testing::HasSubstr(sourceLoc.function_name()));
+ EXPECT_THAT(message, testing::HasSubstr(std::to_string(sourceLoc.line())));
+ EXPECT_THAT(message, testing::HasSubstr(assertMessage));
+}
+
} // namespace fud
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