summaryrefslogtreecommitdiff
path: root/test/test_format.cpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2025-03-30 23:08:43 -0500
committerDominick Allen <djallen@librehumanitas.org>2025-03-30 23:08:43 -0500
commitcb9fa588ba8144fcdd52ba4b83d69d93fb18066f (patch)
tree214574ca68c1551ec76e7fbb9e0263793180231d /test/test_format.cpp
parent1d357adfa19725ee69fb267a363f1fd217b1272f (diff)
Add hash map.
Diffstat (limited to 'test/test_format.cpp')
-rw-r--r--test/test_format.cpp160
1 files changed, 95 insertions, 65 deletions
diff --git a/test/test_format.cpp b/test/test_format.cpp
index 738b551..0c5c520 100644
--- a/test/test_format.cpp
+++ b/test/test_format.cpp
@@ -17,10 +17,13 @@
#include "fud_format.hpp"
#include "fud_string_view.hpp"
+#include "fud_print.hpp"
#include "gtest/gtest.h"
#include <format>
+// NOLINTBEGIN(readability-magic-numbers)
+
namespace fud {
TEST(FormatTest, BasePositionalTest)
@@ -506,27 +509,27 @@ TEST(FormatTest, OneBoolFormatTest)
TEST(FormatTest, OneFloatFormatUnspecifiedTest)
{
-/*
- String sink{};
-
- ASSERT_EQ(sink.clear(), FudStatus::Success);
- auto expected = std::format("{:}", 42.0);
- auto formatResult = format(sink, FormatCharMode::Unchecked, u8"{:}", 42.0);
- EXPECT_TRUE(formatResult.isOkay());
- EXPECT_STREQ(sink.c_str(), expected.c_str());
-
- ASSERT_EQ(sink.clear(), FudStatus::Success);
- expected = std::format("{:1.0}", 42.0);
- formatResult = format(sink, FormatCharMode::Unchecked, u8"{:1.0}", 42.0);
- EXPECT_TRUE(formatResult.isOkay());
- EXPECT_STREQ(sink.c_str(), expected.c_str());
- expected = std::format("{:1.0}", 42.0);
- expected = std::format("u {:}", 10.0);
- expected = std::format("u {:}", 100.0);
- expected = std::format("u {:}", 1000.0);
- expected = std::format("u {:}", 10000.0);
- expected = std::format("u {:}", 100000.0);
-*/
+ /*
+ String sink{};
+
+ ASSERT_EQ(sink.clear(), FudStatus::Success);
+ auto expected = std::format("{:}", 42.0);
+ auto formatResult = format(sink, FormatCharMode::Unchecked, u8"{:}", 42.0);
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+
+ ASSERT_EQ(sink.clear(), FudStatus::Success);
+ expected = std::format("{:1.0}", 42.0);
+ formatResult = format(sink, FormatCharMode::Unchecked, u8"{:1.0}", 42.0);
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+ expected = std::format("{:1.0}", 42.0);
+ expected = std::format("u {:}", 10.0);
+ expected = std::format("u {:}", 100.0);
+ expected = std::format("u {:}", 1000.0);
+ expected = std::format("u {:}", 10000.0);
+ expected = std::format("u {:}", 100000.0);
+ */
}
TEST(FormatTest, OneFloatFormatScientificTest)
@@ -648,50 +651,50 @@ TEST(FormatTest, OneFloatFormatScientificTest)
// Which is: "E#+ +0003.0000000000000000000000000000000000E+00"
// Which is: "E#+ +0003.00000000000000000000000000000000000000000000000000E+00"
-/*
- expected = std::format("E#+ {:Z>+#060.30E}", val);
- ASSERT_EQ(sink.clear(), FudStatus::Success);
- formatResult = format(sink, FormatCharMode::Unchecked, u8"E#+ {:Z>+#060.30E}", val);
- EXPECT_TRUE(formatResult.isOkay());
- EXPECT_STREQ(sink.c_str(), expected.c_str());
-
- expected = std::format("E#+ {:Z<+#060.30E}", val);
- ASSERT_EQ(sink.clear(), FudStatus::Success);
- formatResult = format(sink, FormatCharMode::Unchecked, u8"E#+ {:Z<+#060.30E}", val);
- EXPECT_TRUE(formatResult.isOkay());
- EXPECT_STREQ(sink.c_str(), expected.c_str());
-
- expected = std::format("E#+ {:Z^+#060.30E}", val);
- ASSERT_EQ(sink.clear(), FudStatus::Success);
- formatResult = format(sink, FormatCharMode::Unchecked, u8"E#+ {:Z^+#060.30E}", val);
- EXPECT_TRUE(formatResult.isOkay());
- EXPECT_STREQ(sink.c_str(), expected.c_str());
-*/
-
-/*
- double val = 3.0;
- expected = std::format("u {:}", val);
- expected = std::format("f {:f}", val);
- expected = std::format("F {:F}", val);
- expected = std::format("a {:a}", val);
- expected = std::format("A {:A}", val);
- expected = std::format("g {:g}", val);
- expected = std::format("G {:G}", val);
- expected = std::format("u# {:#}", val);
- expected = std::format("f# {:#f}", val);
- expected = std::format("F# {:#F}", val);
- expected = std::format("a# {:#a}", val);
- expected = std::format("A# {:#A}", val);
- expected = std::format("g# {:#g}", val);
- expected = std::format("G# {:#G}", val);
- expected = std::format("u#+ {:+#}", val);
- expected = std::format("f#+ {:+#f}", val);
- expected = std::format("F#+ {:+#F}", val);
- expected = std::format("a#+ {:+#a}", val);
- expected = std::format("A#+ {:+#A}", val);
- expected = std::format("g#+ {:+#g}", val);
- expected = std::format("G#+ {:+#010.3G}", val);
-*/
+ /*
+ expected = std::format("E#+ {:Z>+#060.30E}", val);
+ ASSERT_EQ(sink.clear(), FudStatus::Success);
+ formatResult = format(sink, FormatCharMode::Unchecked, u8"E#+ {:Z>+#060.30E}", val);
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+
+ expected = std::format("E#+ {:Z<+#060.30E}", val);
+ ASSERT_EQ(sink.clear(), FudStatus::Success);
+ formatResult = format(sink, FormatCharMode::Unchecked, u8"E#+ {:Z<+#060.30E}", val);
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+
+ expected = std::format("E#+ {:Z^+#060.30E}", val);
+ ASSERT_EQ(sink.clear(), FudStatus::Success);
+ formatResult = format(sink, FormatCharMode::Unchecked, u8"E#+ {:Z^+#060.30E}", val);
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+ */
+
+ /*
+ double val = 3.0;
+ expected = std::format("u {:}", val);
+ expected = std::format("f {:f}", val);
+ expected = std::format("F {:F}", val);
+ expected = std::format("a {:a}", val);
+ expected = std::format("A {:A}", val);
+ expected = std::format("g {:g}", val);
+ expected = std::format("G {:G}", val);
+ expected = std::format("u# {:#}", val);
+ expected = std::format("f# {:#f}", val);
+ expected = std::format("F# {:#F}", val);
+ expected = std::format("a# {:#a}", val);
+ expected = std::format("A# {:#A}", val);
+ expected = std::format("g# {:#g}", val);
+ expected = std::format("G# {:#G}", val);
+ expected = std::format("u#+ {:+#}", val);
+ expected = std::format("f#+ {:+#f}", val);
+ expected = std::format("F#+ {:+#F}", val);
+ expected = std::format("a#+ {:+#a}", val);
+ expected = std::format("A#+ {:+#A}", val);
+ expected = std::format("g#+ {:+#g}", val);
+ expected = std::format("G#+ {:+#010.3G}", val);
+ */
}
TEST(FormatTest, TwoArgFormatTest)
@@ -716,6 +719,33 @@ TEST(FormatTest, StringView)
auto formatResult = format(sink, FormatCharMode::Unchecked, u8"Test {}", StringView{u8"Hello, World!"});
EXPECT_TRUE(formatResult.isOkay());
EXPECT_STREQ(sink.c_str(), expected.c_str());
+
+ ASSERT_EQ(sink.clear(), FudStatus::Success);
+ formatResult = fud::format(
+ sink,
+ fud::FormatCharMode::Unchecked,
+ u8"CREATE TABLE IF NOT EXISTS {} ({} {} {});",
+ StringView{u8"AtomicSymbol"}.as_string_view(),
+ StringView{u8"AtomicNumber INTEGER PRIMARY KEY"}.as_string_view(),
+ StringView{u8"Symbol TEXT NOT NULL"}.as_string_view(),
+ StringView{u8"Name TEXT NOT NULL"}.as_string_view());
+ expected = std::format(
+ "CREATE TABLE IF NOT EXISTS {} ({} {} {});",
+ StringView{u8"AtomicSymbol"}.as_string_view(),
+ StringView{u8"AtomicNumber INTEGER PRIMARY KEY"}.as_string_view(),
+ StringView{u8"Symbol TEXT NOT NULL"}.as_string_view(),
+ StringView{u8"Name TEXT NOT NULL"}.as_string_view());
+ EXPECT_TRUE(formatResult.isOkay());
+ EXPECT_STREQ(sink.c_str(), expected.c_str());
+}
+
+TEST(FormatTest, NumArgs)
+{
+ String sink{};
+ auto formatResult = format(sink, FormatCharMode::Unchecked, u8"Test {} {} {}", StringView{u8"Hello, World!"});
+ ASSERT_EQ(formatResult.status, FudStatus::FormatInvalid);
}
} // namespace fud
+
+// NOLINTEND(readability-magic-numbers)