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

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 22 07:30:17 PDT 2020


thopre created this revision.
thopre added a reviewer: jhenderson.
thopre added a project: LLVM.
Herald added a subscriber: dexonsmith.
thopre marked an inline comment as done.
thopre added inline comments.


================
Comment at: llvm/unittests/ADT/StringExtrasTest.cpp:198
+
+  EXPECT_EQ("-0", utostr(0, /*isNeg=*/true));
+  EXPECT_EQ("-1", utostr(1, /*isNeg=*/true));
----------------
Since there's no comment, I'm not sure whether it is supported by the API or not. I'd be tempted to add an assert and a comment not to support it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82300

Files:
  llvm/unittests/ADT/StringExtrasTest.cpp


Index: llvm/unittests/ADT/StringExtrasTest.cpp
===================================================================
--- llvm/unittests/ADT/StringExtrasTest.cpp
+++ 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<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("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<uint64_t>(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));
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82300.272420.patch
Type: text/x-patch
Size: 1450 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200622/1206f303/attachment-0001.bin>


More information about the llvm-commits mailing list