diff options
author | babenko <babenko@yandex-team.com> | 2022-09-19 16:59:49 +0300 |
---|---|---|
committer | babenko <babenko@yandex-team.com> | 2022-09-19 16:59:49 +0300 |
commit | ddbed3bdc9fbfec40475f0e3939187bb6ce716c3 (patch) | |
tree | e761fd77c2f6fb80c4edcd47d66d6356bdd71fcb /library/cpp/yt/string/unittests | |
parent | b5a861d056d17322efb73efb580e0d32238e452c (diff) | |
download | ydb-ddbed3bdc9fbfec40475f0e3939187bb6ce716c3.tar.gz |
Sane handling of %x and %X for pointers in Format
Diffstat (limited to 'library/cpp/yt/string/unittests')
-rw-r--r-- | library/cpp/yt/string/unittests/format_ut.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/library/cpp/yt/string/unittests/format_ut.cpp b/library/cpp/yt/string/unittests/format_ut.cpp index 20ec6392b5..47bb4602e3 100644 --- a/library/cpp/yt/string/unittests/format_ut.cpp +++ b/library/cpp/yt/string/unittests/format_ut.cpp @@ -160,9 +160,20 @@ TEST(TFormatTest, Nullable) TEST(TFormatTest, Pointers) { - // No idea if pointer format is standardized, check against Sprintf. - auto p = reinterpret_cast<void*>(123); - EXPECT_EQ(Sprintf("%p", reinterpret_cast<void*>(123)), Format("%p", p)); + { + auto ptr = reinterpret_cast<void*>(0x12345678); + EXPECT_EQ("0x12345678", Format("%p", ptr)); + EXPECT_EQ("0x12345678", Format("%v", ptr)); + EXPECT_EQ("12345678", Format("%x", ptr)); + EXPECT_EQ("12345678", Format("%X", ptr)); + } + { + auto ptr = reinterpret_cast<void*>(0x12345678abcdefab); + EXPECT_EQ("0x12345678abcdefab", Format("%p", ptr)); + EXPECT_EQ("0x12345678abcdefab", Format("%v", ptr)); + EXPECT_EQ("12345678abcdefab", Format("%x", ptr)); + EXPECT_EQ("12345678ABCDEFAB", Format("%X", ptr)); + } } //////////////////////////////////////////////////////////////////////////////// |