[llvm] [ADT][NFC] Make `getAutoSenseRadix` in `StringRef` global (PR #152503)

Ilia Kuklin via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 7 08:19:30 PDT 2025


================
@@ -619,6 +619,29 @@ TEST(StringRefTest, Hashing) {
             hash_value(StringRef("hello world").slice(1, -1)));
 }
 
+struct RadixPair {
+  const char *Str;
+  unsigned Expected;
+} RadixNumbers[] =
+  { {"123", 10}
+  , {"1", 10}
+  , {"0b1", 2}
+  , {"01", 8}
+  , {"0o1", 8}
+  , {"0x1", 16}
+  , {"0", 10}
+  , {"00", 8}
+  , {"", 10}
+  };
+
+TEST(StringRefTest, getAutoSenseRadix) {
+  for (size_t i = 0; i < std::size(RadixNumbers); ++i) {
+    StringRef number = RadixNumbers[i].Str;
+    unsigned radix = getAutoSenseRadix(number);
+    EXPECT_EQ(radix, RadixNumbers[i].Expected);
+  }
----------------
kuilpd wrote:

I just copied the way it's done in other tests in that file, but I can redo it this way as well

https://github.com/llvm/llvm-project/pull/152503


More information about the llvm-commits mailing list