|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
9 | 9 | #include "src/__support/CPP/string_view.h"
|
| 10 | +#include "src/__support/UInt.h" |
| 11 | +#include "src/__support/UInt128.h" |
10 | 12 | #include "src/__support/integer_to_string.h"
|
11 | 13 |
|
12 | 14 | #include "test/UnitTest/Test.h"
|
@@ -247,3 +249,42 @@ TEST(LlvmLibcIntegerToStringTest, UINT64_Base_36) {
|
247 | 249 | EXPECT_EQ(*IntegerToString::convert<36>(uint64_t(0xffffffffffffffff), buf),
|
248 | 250 | string_view("3w5e11264sgsf"));
|
249 | 251 | }
|
| 252 | + |
| 253 | +TEST(LlvmLibcIntegerToStringTest, UINT128_Base_16) { |
| 254 | + char buf[IntegerToString::hex_bufsize<UInt128>()]; |
| 255 | + EXPECT_EQ(*IntegerToString::hex(static_cast<UInt128>(0), buf), |
| 256 | + string_view("00000000000000000000000000000000")); |
| 257 | + EXPECT_EQ(*IntegerToString::hex(static_cast<UInt128>(0x12345), buf), |
| 258 | + string_view("00000000000000000000000000012345")); |
| 259 | + EXPECT_EQ((*IntegerToString::hex(static_cast<UInt128>(0x1234) << 112, buf)), |
| 260 | + string_view("12340000000000000000000000000000")); |
| 261 | + EXPECT_EQ((*IntegerToString::hex(static_cast<UInt128>(0x1234) << 48, buf)), |
| 262 | + string_view("00000000000000001234000000000000")); |
| 263 | + EXPECT_EQ((*IntegerToString::hex(static_cast<UInt128>(0x1234) << 52, buf)), |
| 264 | + string_view("00000000000000012340000000000000")); |
| 265 | +} |
| 266 | + |
| 267 | +TEST(LlvmLibcIntegerToStringTest, UINT256_Base_16) { |
| 268 | + using UInt256 = __llvm_libc::cpp::UInt<256>; |
| 269 | + char buf[IntegerToString::hex_bufsize<UInt256>()]; |
| 270 | + EXPECT_EQ( |
| 271 | + *IntegerToString::hex(static_cast<UInt256>(0), buf), |
| 272 | + string_view( |
| 273 | + "0000000000000000000000000000000000000000000000000000000000000000")); |
| 274 | + EXPECT_EQ( |
| 275 | + *IntegerToString::hex(static_cast<UInt256>(0x12345), buf), |
| 276 | + string_view( |
| 277 | + "0000000000000000000000000000000000000000000000000000000000012345")); |
| 278 | + EXPECT_EQ( |
| 279 | + (*IntegerToString::hex(static_cast<UInt256>(0x1234) << 112, buf)), |
| 280 | + string_view( |
| 281 | + "0000000000000000000000000000000012340000000000000000000000000000")); |
| 282 | + EXPECT_EQ( |
| 283 | + (*IntegerToString::hex(static_cast<UInt256>(0x1234) << 116, buf)), |
| 284 | + string_view( |
| 285 | + "0000000000000000000000000000000123400000000000000000000000000000")); |
| 286 | + EXPECT_EQ( |
| 287 | + (*IntegerToString::hex(static_cast<UInt256>(0x1234) << 240, buf)), |
| 288 | + string_view( |
| 289 | + "1234000000000000000000000000000000000000000000000000000000000000")); |
| 290 | +} |
0 commit comments