Skip to content

Commit 469ec9d

Browse files
committed
Add a unit test
1 parent 59523f3 commit 469ec9d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

llvm/unittests/ADT/StringRefTest.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,29 @@ TEST(StringRefTest, Hashing) {
619619
hash_value(StringRef("hello world").slice(1, -1)));
620620
}
621621

622+
struct RadixPair {
623+
const char *Str;
624+
unsigned Expected;
625+
} RadixNumbers[] =
626+
{ {"123", 10}
627+
, {"1", 10}
628+
, {"0b1", 2}
629+
, {"01", 8}
630+
, {"0o1", 8}
631+
, {"0x1", 16}
632+
, {"0", 10}
633+
, {"00", 8}
634+
, {"", 10}
635+
};
636+
637+
TEST(StringRefTest, getAutoSenseRadix) {
638+
for (size_t i = 0; i < std::size(RadixNumbers); ++i) {
639+
StringRef number = RadixNumbers[i].Str;
640+
unsigned radix = getAutoSenseRadix(number);
641+
EXPECT_EQ(radix, RadixNumbers[i].Expected);
642+
}
643+
}
644+
622645
struct UnsignedPair {
623646
const char *Str;
624647
uint64_t Expected;

0 commit comments

Comments
 (0)