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

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 23 06:21:56 PDT 2020


thopre updated this revision to Diff 272702.
thopre marked 2 inline comments as done.
thopre added a comment.

Use std::to_string to test API for big values


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82300/new/

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,32 @@
   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(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));
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82300.272702.patch
Type: text/x-patch
Size: 1543 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200623/ebeb6fd1/attachment.bin>


More information about the llvm-commits mailing list