aboutsummaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorwiggles dog <rbt@sent.as>2024-03-29 01:13:45 +0000
committerGerrit Code Review <gerrit@lix>2024-03-29 01:13:45 +0000
commit236bc046ba9713e5f7647b97d41608477daafa3b (patch)
tree6eef870ac08725e0d0d40403b7f08901f8bbcb54 /tests/unit
parent55350bd68decdc1287a34e0b52a1f9fce9ae854b (diff)
parent8e63eca912a01659cef81b9d6d1cc7cb11edfff5 (diff)
Merge "Remove `HintFmt::operator%`" into main
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/libutil/fmt.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/unit/libutil/fmt.cc b/tests/unit/libutil/fmt.cc
new file mode 100644
index 000000000..383a688d3
--- /dev/null
+++ b/tests/unit/libutil/fmt.cc
@@ -0,0 +1,23 @@
+#include "fmt.hh"
+#include "ansicolor.hh"
+
+#include <gtest/gtest.h>
+
+namespace nix {
+
+TEST(HintFmt, arg_count)
+{
+ // Single arg is treated as a literal string.
+ ASSERT_EQ(HintFmt("%s").str(), "%s");
+
+ // Other strings format as expected:
+ ASSERT_EQ(HintFmt("%s", 1).str(), ANSI_MAGENTA "1" ANSI_NORMAL);
+ ASSERT_EQ(HintFmt("%1%", "hello").str(), ANSI_MAGENTA "hello" ANSI_NORMAL);
+
+ // Argument counts are detected at construction.
+ ASSERT_THROW(HintFmt("%s %s", 1), boost::io::too_few_args);
+
+ ASSERT_THROW(HintFmt("%s", 1, 2), boost::io::too_many_args);
+}
+
+}