@@ -86,6 +86,34 @@ void test_decimal()
86
86
}
87
87
}
88
88
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
+
89
117
int main ()
90
118
{
91
119
test_empty<boost::int128::uint128_t >();
@@ -100,6 +128,9 @@ int main()
100
128
test_decimal<boost::int128::uint128_t >();
101
129
test_decimal<boost::int128::int128_t >();
102
130
131
+ test_hex<boost::int128::uint128_t >();
132
+ test_hex<boost::int128::int128_t >();
133
+
103
134
return boost::report_errors ();
104
135
}
105
136
0 commit comments