1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

[unittest, ADT] Add unit tests for itostr & utostr

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D82300
This commit is contained in:
Thomas Preud'homme 2020-06-22 15:00:00 +01:00
parent 313dfe1935
commit 362e7dd990

View File

@ -182,3 +182,32 @@ TEST(StringExtras, ConvertToCamelFromSnakeCase) {
testConvertToCamelCase(true, "Op_Name", "Op_Name"); testConvertToCamelCase(true, "Op_Name", "Op_Name");
testConvertToCamelCase(true, "opName", "OpName"); testConvertToCamelCase(true, "opName", "OpName");
} }
constexpr uint64_t MaxUint64 = std::numeric_limits<uint64_t>::max();
constexpr int64_t MaxInt64 = std::numeric_limits<int64_t>::max();
constexpr int64_t MinInt64 = std::numeric_limits<int64_t>::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(std::to_string(MaxUint64), utostr(MaxUint64));
EXPECT_EQ(std::to_string(MaxUint64), utostr(MaxUint64, /*isNeg=*/false));
EXPECT_EQ("-0", utostr(0, /*isNeg=*/true));
EXPECT_EQ("-1", utostr(1, /*isNeg=*/true));
EXPECT_EQ("-" + std::to_string(MaxInt64), utostr(MaxInt64, /*isNeg=*/true));
constexpr uint64_t MinusMinInt64 = -static_cast<uint64_t>(MinInt64);
EXPECT_EQ("-" + std::to_string(MinusMinInt64),
utostr(MinusMinInt64, /*isNeg=*/true));
EXPECT_EQ("-" + std::to_string(MaxUint64), utostr(MaxUint64, /*isNeg=*/true));
}
TEST(StringExtras, IToStr) {
EXPECT_EQ("0", itostr(0));
EXPECT_EQ("1", itostr(1));
EXPECT_EQ("-1", itostr(-1));
EXPECT_EQ(std::to_string(MinInt64), itostr(MinInt64));
EXPECT_EQ(std::to_string(MaxInt64), itostr(MaxInt64));
}