summaryrefslogtreecommitdiffstats
path: root/util/string/printf_ut.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/string/printf_ut.cpp
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/string/printf_ut.cpp')
-rw-r--r--util/string/printf_ut.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/util/string/printf_ut.cpp b/util/string/printf_ut.cpp
new file mode 100644
index 00000000000..2b2f980b70e
--- /dev/null
+++ b/util/string/printf_ut.cpp
@@ -0,0 +1,30 @@
+#include "printf.h"
+
+#include <library/cpp/testing/unittest/registar.h>
+
+Y_UNIT_TEST_SUITE(TStringPrintf) {
+ Y_UNIT_TEST(TestSprintf) {
+ TString s;
+ int len = sprintf(s, "Hello %s", "world");
+ UNIT_ASSERT_EQUAL(s, TString("Hello world"));
+ UNIT_ASSERT_EQUAL(len, 11);
+ }
+
+ Y_UNIT_TEST(TestFcat) {
+ TString s;
+ int len = sprintf(s, "Hello %s", "world");
+ UNIT_ASSERT_EQUAL(s, TString("Hello world"));
+ UNIT_ASSERT_EQUAL(len, 11);
+ len = fcat(s, " qwqw%s", "as");
+ UNIT_ASSERT_EQUAL(s, TString("Hello world qwqwas"));
+ UNIT_ASSERT_EQUAL(len, 7);
+ }
+
+ Y_UNIT_TEST(TestSpecial) {
+ UNIT_ASSERT_EQUAL("4294967295", Sprintf("%" PRIu32, (ui32)(-1)));
+ }
+
+ Y_UNIT_TEST(TestExplicitPositions) {
+ UNIT_ASSERT_EQUAL("abc xyz abc", Sprintf("%1$s %2$s %1$s", "abc", "xyz"));
+ }
+}