Skip to content

Commit 950dc54

Browse files
committed
Add hex testing
1 parent c79eec9 commit 950dc54

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/test_format.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,34 @@ void test_decimal()
8686
}
8787
}
8888

89+
template <typename T>
90+
void test_hex()
91+
{
92+
BOOST_TEST_CSTR_EQ(std::format("{:x}", T{42}).c_str(), "2a");
93+
BOOST_TEST_CSTR_EQ(std::format("{:#x}", T{42}).c_str(), "0x2a");
94+
95+
BOOST_TEST_CSTR_EQ(std::format("{:X}", T{42}).c_str(), "2A");
96+
BOOST_TEST_CSTR_EQ(std::format("{:#X}", T{42}).c_str(), "0X2A");
97+
98+
BOOST_TEST_CSTR_EQ(std::format("{: X}", T{42}).c_str(), " 2A");
99+
BOOST_TEST_CSTR_EQ(std::format("{: #X}", T{42}).c_str(), " 0X2A");
100+
101+
BOOST_TEST_CSTR_EQ(std::format("{:+X}", T{42}).c_str(), "+2A");
102+
BOOST_TEST_CSTR_EQ(std::format("{:+#X}", T{42}).c_str(), "+0X2A");
103+
104+
if constexpr (std::is_same_v<T, boost::int128::int128_t>)
105+
{
106+
BOOST_TEST_CSTR_EQ(std::format("{:-X}", T{-42}).c_str(), "-2A");
107+
BOOST_TEST_CSTR_EQ(std::format("{:-#X}", T{-42}).c_str(), "-0X2A");
108+
}
109+
110+
BOOST_TEST_CSTR_EQ(std::format("{:5X}", T{42}).c_str(), "0002A");
111+
BOOST_TEST_CSTR_EQ(std::format("{:#5X}", T{42}).c_str(), "0X0002A");
112+
113+
BOOST_TEST_CSTR_EQ(std::format("{: 5X}", T{42}).c_str(), " 0002A");
114+
BOOST_TEST_CSTR_EQ(std::format("{: #5X}", T{42}).c_str(), " 0X0002A");
115+
}
116+
89117
int main()
90118
{
91119
test_empty<boost::int128::uint128_t>();
@@ -100,6 +128,9 @@ int main()
100128
test_decimal<boost::int128::uint128_t>();
101129
test_decimal<boost::int128::int128_t>();
102130

131+
test_hex<boost::int128::uint128_t>();
132+
test_hex<boost::int128::int128_t>();
133+
103134
return boost::report_errors();
104135
}
105136

0 commit comments

Comments
 (0)