diff --git a/llvm/unittests/ADT/StringExtrasTest.cpp b/llvm/unittests/ADT/StringExtrasTest.cpp --- a/llvm/unittests/ADT/StringExtrasTest.cpp +++ b/llvm/unittests/ADT/StringExtrasTest.cpp @@ -182,3 +182,31 @@ testConvertToCamelCase(true, "Op_Name", "Op_Name"); testConvertToCamelCase(true, "opName", "OpName"); } + +constexpr uint64_t MaxUint64 = std::numeric_limits::max(); +constexpr int64_t MaxInt64 = std::numeric_limits::max(); +constexpr int64_t MinInt64 = std::numeric_limits::min(); + +TEST(StringExtras, UToStr) { + EXPECT_EQ("0", utostr(0)); + EXPECT_EQ("0", utostr(0, /*isNeg=*/false)); + EXPECT_EQ("1", utostr(1)); + EXPECT_EQ("1", utostr(1, /*isNeg=*/false)); + EXPECT_EQ("18446744073709551615", utostr(MaxUint64)); + EXPECT_EQ("18446744073709551615", utostr(MaxUint64, /*isNeg=*/false)); + + EXPECT_EQ("-0", utostr(0, /*isNeg=*/true)); + EXPECT_EQ("-1", utostr(1, /*isNeg=*/true)); + EXPECT_EQ("-9223372036854775807", utostr(MaxInt64, /*isNeg=*/true)); + EXPECT_EQ("-9223372036854775808", + utostr(-static_cast(MinInt64), /*isNeg=*/true)); + EXPECT_EQ("-18446744073709551615", utostr(MaxUint64, /*isNeg=*/true)); +} + +TEST(StringExtras, IToStr) { + EXPECT_EQ("0", itostr(0)); + EXPECT_EQ("1", itostr(1)); + EXPECT_EQ("-1", itostr(-1)); + EXPECT_EQ("-9223372036854775808", itostr(MinInt64)); + EXPECT_EQ("9223372036854775807", itostr(MaxInt64)); +}