summaryrefslogtreecommitdiff
path: root/absl/strings/numbers_test.cc
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2023-08-25 03:17:58 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2023-08-25 03:18:45 -0700
commit197bac8574c511b1937b60ce6405462f9af678ce (patch)
tree011b8d3302f6b83f131d6a6c974e49955b629657 /absl/strings/numbers_test.cc
parent8ebad34c3fa54a9ad2f46ca8cab98e75c4f750bf (diff)
Speed up `FastIntToBuffer`.
PiperOrigin-RevId: 560038034 Change-Id: I2c74d271b52faeefb6e8627d9830b2b53de64e73
Diffstat (limited to 'absl/strings/numbers_test.cc')
-rw-r--r--absl/strings/numbers_test.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/absl/strings/numbers_test.cc b/absl/strings/numbers_test.cc
index a450b99e..75c2dcf2 100644
--- a/absl/strings/numbers_test.cc
+++ b/absl/strings/numbers_test.cc
@@ -63,6 +63,7 @@ using absl::strings_internal::strtouint32_test_cases;
using absl::strings_internal::strtouint64_test_cases;
using testing::Eq;
using testing::MatchesRegex;
+using testing::Pointee;
// Number of floats to test with.
// 5,000,000 is a reasonable default for a test that only takes a few seconds.
@@ -1715,4 +1716,25 @@ TEST(FastHexToBufferZeroPad16, Smoke) {
}
}
+template <typename Int>
+void ExpectWritesNull() {
+ {
+ char buf[absl::numbers_internal::kFastToBufferSize];
+ Int x = std::numeric_limits<Int>::min();
+ EXPECT_THAT(absl::numbers_internal::FastIntToBuffer(x, buf), Pointee('\0'));
+ }
+ {
+ char buf[absl::numbers_internal::kFastToBufferSize];
+ Int x = std::numeric_limits<Int>::max();
+ EXPECT_THAT(absl::numbers_internal::FastIntToBuffer(x, buf), Pointee('\0'));
+ }
+}
+
+TEST(FastIntToBuffer, WritesNull) {
+ ExpectWritesNull<int32_t>();
+ ExpectWritesNull<uint32_t>();
+ ExpectWritesNull<int64_t>();
+ ExpectWritesNull<uint32_t>();
+}
+
} // namespace