19 #include <sys/types.h> 36 #include "gmock/gmock.h" 37 #include "gtest/gtest.h" 57 using testing::MatchesRegex;
64 const int kFloatNumCases = 5000000;
69 std::string PerfectDtoa(
double d) {
70 if (d == 0)
return "0";
71 if (d < 0)
return "-" + PerfectDtoa(-d);
76 while (d >= 1ULL << 63) ++exp, d *= 0.5;
77 while ((mantissa = d) != d) --exp, d *= 2.0;
82 constexpr
int maxlen = 1100;
84 for (int64_t num = mantissa, pos = maxlen; --pos >= 0;) {
85 buf[pos] =
'0' + (num % 10);
88 char*
begin = &buf[0];
89 char*
end = buf + maxlen;
90 for (
int i = 0;
i != exp;
i += (exp > 0) ? 1 : -1) {
92 for (
char* p = end; --p !=
begin;) {
94 dig = dig * (exp > 0 ? 2 : 5) + carry;
102 memmove(end + 1 + exp, end + exp, 1 - exp);
106 while (*begin ==
'0' && begin[1] !=
'.') ++
begin;
110 TEST(ToString, PerfectDtoa) {
111 EXPECT_THAT(PerfectDtoa(1), Eq(
"1"));
112 EXPECT_THAT(PerfectDtoa(0.1),
113 Eq(
"0.1000000000000000055511151231257827021181583404541015625"));
114 EXPECT_THAT(PerfectDtoa(1e24), Eq(
"999999999999999983222784"));
115 EXPECT_THAT(PerfectDtoa(5e-324), MatchesRegex(
"0.0000.*625"));
116 for (
int i = 0;
i < 100; ++
i) {
117 for (
double multiplier :
118 {1e-300, 1e-200, 1e-100, 0.1, 1.0, 10.0, 1e100, 1e300}) {
119 double d = multiplier *
i;
120 std::string s = PerfectDtoa(d);
121 EXPECT_DOUBLE_EQ(d, strtod(s.c_str(),
nullptr));
126 template <
typename integer>
129 explicit constexpr MyInteger(integer i) : i(i) {}
130 constexpr
operator integer()
const {
return i; }
132 constexpr MyInteger
operator+(MyInteger other)
const {
return i + other.i; }
133 constexpr MyInteger
operator-(MyInteger other)
const {
return i - other.i; }
134 constexpr MyInteger
operator*(MyInteger other)
const {
return i * other.i; }
135 constexpr MyInteger
operator/(MyInteger other)
const {
return i / other.i; }
137 constexpr
bool operator<(MyInteger other)
const {
return i < other.i; }
138 constexpr
bool operator<=(MyInteger other)
const {
return i <= other.i; }
139 constexpr
bool operator==(MyInteger other)
const {
return i == other.i; }
140 constexpr
bool operator>=(MyInteger other)
const {
return i >= other.i; }
141 constexpr
bool operator>(MyInteger other)
const {
return i > other.i; }
142 constexpr
bool operator!=(MyInteger other)
const {
return i != other.i; }
144 integer as_integer()
const {
return i; }
147 typedef MyInteger<int64_t> MyInt64;
148 typedef MyInteger<uint64_t> MyUInt64;
150 void CheckInt32(int32_t x) {
153 std::string expected = std::to_string(x);
154 EXPECT_EQ(expected, std::string(buffer, actual)) <<
" Input " << x;
157 EXPECT_EQ(expected, std::string(buffer, generic_actual)) <<
" Input " << x;
160 void CheckInt64(int64_t x) {
166 std::string expected = std::to_string(x);
167 EXPECT_EQ(expected, std::string(&buffer[1], actual)) <<
" Input " << x;
168 EXPECT_EQ(buffer[0],
'*');
169 EXPECT_EQ(buffer[23],
'*');
170 EXPECT_EQ(buffer[24],
'*');
174 EXPECT_EQ(expected, std::string(&buffer[1], my_actual)) <<
" Input " << x;
177 void CheckUInt32(uint32_t x) {
180 std::string expected = std::to_string(x);
181 EXPECT_EQ(expected, std::string(buffer, actual)) <<
" Input " << x;
184 EXPECT_EQ(expected, std::string(buffer, generic_actual)) <<
" Input " << x;
187 void CheckUInt64(uint64_t x) {
190 std::string expected = std::to_string(x);
191 EXPECT_EQ(expected, std::string(&buffer[1], actual)) <<
" Input " << x;
194 EXPECT_EQ(expected, std::string(&buffer[1], generic_actual))
199 EXPECT_EQ(expected, std::string(&buffer[1], my_actual)) <<
" Input " << x;
202 void CheckHex64(uint64_t
v) {
203 char expected[16 + 1];
205 snprintf(expected,
sizeof(expected),
"%016" PRIx64, static_cast<uint64_t>(v));
206 EXPECT_EQ(expected, actual) <<
" Input " <<
v;
209 TEST(Numbers, TestFastPrints) {
210 for (
int i = -100;
i <= 100;
i++) {
214 for (
int i = 0;
i <= 100;
i++) {
221 CheckInt64(LONG_MIN);
222 CheckInt64(uint64_t{1000000000});
223 CheckInt64(uint64_t{9999999999});
224 CheckInt64(uint64_t{100000000000000});
225 CheckInt64(uint64_t{999999999999999});
226 CheckInt64(uint64_t{1000000000000000000});
227 CheckInt64(uint64_t{1199999999999999999});
228 CheckInt64(int64_t{-700000000000000000});
229 CheckInt64(LONG_MAX);
230 CheckUInt32(std::numeric_limits<uint32_t>::max());
231 CheckUInt64(uint64_t{1000000000});
232 CheckUInt64(uint64_t{9999999999});
233 CheckUInt64(uint64_t{100000000000000});
234 CheckUInt64(uint64_t{999999999999999});
235 CheckUInt64(uint64_t{1000000000000000000});
236 CheckUInt64(uint64_t{1199999999999999999});
237 CheckUInt64(std::numeric_limits<uint64_t>::max());
239 for (
int i = 0;
i < 10000;
i++) {
242 CheckHex64(uint64_t{0x123456789abcdef0});
245 template <
typename int_type,
typename in_val_type>
246 void VerifySimpleAtoiGood(in_val_type in_value, int_type exp_value) {
248 int_type x =
static_cast<int_type
>(~exp_value);
250 <<
"in_value=" << in_value <<
" s=" << s <<
" x=" << x;
251 EXPECT_EQ(exp_value, x);
252 x =
static_cast<int_type
>(~exp_value);
254 EXPECT_EQ(exp_value, x);
257 template <
typename int_type,
typename in_val_type>
258 void VerifySimpleAtoiBad(in_val_type in_value) {
265 TEST(NumbersTest, Atoi) {
267 VerifySimpleAtoiGood<int32_t>(0, 0);
268 VerifySimpleAtoiGood<int32_t>(42, 42);
269 VerifySimpleAtoiGood<int32_t>(-42, -42);
271 VerifySimpleAtoiGood<int32_t>(std::numeric_limits<int32_t>::min(),
272 std::numeric_limits<int32_t>::min());
273 VerifySimpleAtoiGood<int32_t>(std::numeric_limits<int32_t>::max(),
274 std::numeric_limits<int32_t>::max());
277 VerifySimpleAtoiGood<uint32_t>(0, 0);
278 VerifySimpleAtoiGood<uint32_t>(42, 42);
279 VerifySimpleAtoiBad<uint32_t>(-42);
281 VerifySimpleAtoiBad<uint32_t>(std::numeric_limits<int32_t>::min());
282 VerifySimpleAtoiGood<uint32_t>(std::numeric_limits<int32_t>::max(),
283 std::numeric_limits<int32_t>::max());
284 VerifySimpleAtoiGood<uint32_t>(std::numeric_limits<uint32_t>::max(),
285 std::numeric_limits<uint32_t>::max());
286 VerifySimpleAtoiBad<uint32_t>(std::numeric_limits<int64_t>::min());
287 VerifySimpleAtoiBad<uint32_t>(std::numeric_limits<int64_t>::max());
288 VerifySimpleAtoiBad<uint32_t>(std::numeric_limits<uint64_t>::max());
291 VerifySimpleAtoiGood<int64_t>(0, 0);
292 VerifySimpleAtoiGood<int64_t>(42, 42);
293 VerifySimpleAtoiGood<int64_t>(-42, -42);
295 VerifySimpleAtoiGood<int64_t>(std::numeric_limits<int32_t>::min(),
296 std::numeric_limits<int32_t>::min());
297 VerifySimpleAtoiGood<int64_t>(std::numeric_limits<int32_t>::max(),
298 std::numeric_limits<int32_t>::max());
299 VerifySimpleAtoiGood<int64_t>(std::numeric_limits<uint32_t>::max(),
300 std::numeric_limits<uint32_t>::max());
301 VerifySimpleAtoiGood<int64_t>(std::numeric_limits<int64_t>::min(),
302 std::numeric_limits<int64_t>::min());
303 VerifySimpleAtoiGood<int64_t>(std::numeric_limits<int64_t>::max(),
304 std::numeric_limits<int64_t>::max());
305 VerifySimpleAtoiBad<int64_t>(std::numeric_limits<uint64_t>::max());
308 VerifySimpleAtoiGood<uint64_t>(0, 0);
309 VerifySimpleAtoiGood<uint64_t>(42, 42);
310 VerifySimpleAtoiBad<uint64_t>(-42);
312 VerifySimpleAtoiBad<uint64_t>(std::numeric_limits<int32_t>::min());
313 VerifySimpleAtoiGood<uint64_t>(std::numeric_limits<int32_t>::max(),
314 std::numeric_limits<int32_t>::max());
315 VerifySimpleAtoiGood<uint64_t>(std::numeric_limits<uint32_t>::max(),
316 std::numeric_limits<uint32_t>::max());
317 VerifySimpleAtoiBad<uint64_t>(std::numeric_limits<int64_t>::min());
318 VerifySimpleAtoiGood<uint64_t>(std::numeric_limits<int64_t>::max(),
319 std::numeric_limits<int64_t>::max());
320 VerifySimpleAtoiGood<uint64_t>(std::numeric_limits<uint64_t>::max(),
321 std::numeric_limits<uint64_t>::max());
324 VerifySimpleAtoiGood<int>(-42, -42);
325 VerifySimpleAtoiGood<int32_t>(-42, -42);
326 VerifySimpleAtoiGood<uint32_t>(42, 42);
327 VerifySimpleAtoiGood<unsigned int>(42, 42);
328 VerifySimpleAtoiGood<int64_t>(-42, -42);
329 VerifySimpleAtoiGood<long>(-42, -42);
330 VerifySimpleAtoiGood<uint64_t>(42, 42);
331 VerifySimpleAtoiGood<size_t>(42, 42);
332 VerifySimpleAtoiGood<std::string::size_type>(42, 42);
335 TEST(NumbersTest, Atoenum) {
341 VerifySimpleAtoiGood<E01>(E01_zero, E01_zero);
342 VerifySimpleAtoiGood<E01>(E01_one, E01_one);
350 VerifySimpleAtoiGood<E_101>(E_101_minusone, E_101_minusone);
351 VerifySimpleAtoiGood<E_101>(E_101_zero, E_101_zero);
352 VerifySimpleAtoiGood<E_101>(E_101_one, E_101_one);
357 E_bigint_max31 =
static_cast<int32_t
>(0x7FFFFFFF),
360 VerifySimpleAtoiGood<E_bigint>(E_bigint_zero, E_bigint_zero);
361 VerifySimpleAtoiGood<E_bigint>(E_bigint_one, E_bigint_one);
362 VerifySimpleAtoiGood<E_bigint>(E_bigint_max31, E_bigint_max31);
367 E_fullint_max31 =
static_cast<int32_t
>(0x7FFFFFFF),
368 E_fullint_min32 = INT32_MIN,
371 VerifySimpleAtoiGood<E_fullint>(E_fullint_zero, E_fullint_zero);
372 VerifySimpleAtoiGood<E_fullint>(E_fullint_one, E_fullint_one);
373 VerifySimpleAtoiGood<E_fullint>(E_fullint_max31, E_fullint_max31);
374 VerifySimpleAtoiGood<E_fullint>(E_fullint_min32, E_fullint_min32);
379 E_biguint_max31 =
static_cast<uint32_t
>(0x7FFFFFFF),
380 E_biguint_max32 = static_cast<uint32_t>(0xFFFFFFFF),
383 VerifySimpleAtoiGood<E_biguint>(E_biguint_zero, E_biguint_zero);
384 VerifySimpleAtoiGood<E_biguint>(E_biguint_one, E_biguint_one);
385 VerifySimpleAtoiGood<E_biguint>(E_biguint_max31, E_biguint_max31);
386 VerifySimpleAtoiGood<E_biguint>(E_biguint_max32, E_biguint_max32);
392 EXPECT_EQ(0x34234324, value);
395 EXPECT_EQ(0x34234324, value);
398 EXPECT_EQ(0x34234324, value);
404 EXPECT_EQ(-0x34234324, value);
407 EXPECT_EQ(-0x34234324, value);
410 EXPECT_EQ(07654321, value);
413 EXPECT_EQ(-01234, value);
422 EXPECT_EQ(077, value);
432 EXPECT_EQ(34234324, value);
438 EXPECT_EQ(-34234324, value);
441 EXPECT_EQ(34234324, value);
456 EXPECT_EQ(0x1234, value);
460 EXPECT_EQ(1234, value);
463 TEST(stringtest, safe_strto32_range) {
467 EXPECT_EQ(std::numeric_limits<int32_t>::max(), value);
470 EXPECT_EQ(std::numeric_limits<int32_t>::min(), value);
473 EXPECT_EQ(std::numeric_limits<int32_t>::min(), value);
476 TEST(stringtest, safe_strto64_range) {
480 EXPECT_EQ(std::numeric_limits<int64_t>::max(), value);
483 EXPECT_EQ(std::numeric_limits<int64_t>::min(), value);
486 EXPECT_EQ(std::numeric_limits<int64_t>::min(), value);
489 TEST(stringtest, safe_strto32_leading_substring) {
496 EXPECT_EQ(4069, value);
499 EXPECT_EQ(0406, value);
502 EXPECT_EQ(4069, value);
505 EXPECT_EQ(0x4069ba, value);
511 TEST(stringtest, safe_strto64_leading_substring) {
518 EXPECT_EQ(4069, value);
521 EXPECT_EQ(0406, value);
524 EXPECT_EQ(4069, value);
527 EXPECT_EQ(0x4069ba, value);
536 EXPECT_EQ(int64_t{0x3423432448783446},
value);
539 EXPECT_EQ(int64_t{0x3423432448783446},
value);
545 EXPECT_EQ(int64_t{-0x3423432448783446},
value);
548 EXPECT_EQ(int64_t{-0x3423432448783446},
value);
551 EXPECT_EQ(int64_t{0123456701234567012},
value);
554 EXPECT_EQ(int64_t{-017777777777777},
value);
563 EXPECT_EQ(077, value);
573 EXPECT_EQ(int64_t{34234324487834466},
value);
579 EXPECT_EQ(int64_t{-34234324487834466},
value);
582 EXPECT_EQ(int64_t{34234324487834466},
value);
597 EXPECT_EQ(0x1234, value);
601 EXPECT_EQ(1234, value);
604 const size_t kNumRandomTests = 10000;
606 template <
typename IntType>
611 std::random_device rd;
613 std::uniform_int_distribution<IntType> random_int(
614 std::numeric_limits<IntType>::min());
615 std::uniform_int_distribution<int> random_base(2, 35);
616 for (
size_t i = 0;
i < kNumRandomTests;
i++) {
617 IntType value = random_int(rng);
618 int base = random_base(rng);
619 std::string str_value;
620 EXPECT_TRUE(Itoa<IntType>(value, base, &str_value));
621 IntType parsed_value;
624 EXPECT_TRUE(parse_func(str_value, &parsed_value, base));
625 EXPECT_EQ(parsed_value, value);
629 parse_func(
absl::StrCat(std::numeric_limits<IntType>::max(), value),
630 &parsed_value, base));
633 if (std::numeric_limits<IntType>::min() < 0) {
635 parse_func(
absl::StrCat(std::numeric_limits<IntType>::min(), value),
636 &parsed_value, base));
638 EXPECT_FALSE(parse_func(
absl::StrCat(
"-", value), &parsed_value, base));
643 TEST(stringtest, safe_strto32_random) {
646 TEST(stringtest, safe_strto64_random) {
649 TEST(stringtest, safe_strtou32_random) {
652 TEST(stringtest, safe_strtou64_random) {
661 <<
"str=\"" << e.str <<
"\" base=" << e.base;
663 EXPECT_EQ(e.expected, value) <<
"i=" <<
i <<
" str=\"" << e.str
664 <<
"\" base=" << e.base;
669 TEST(stringtest, safe_strtou32_base_length_delimited) {
672 std::string tmp(e.str);
676 EXPECT_EQ(e.expect_ok,
679 <<
"str=\"" << e.str <<
"\" base=" << e.base;
681 EXPECT_EQ(e.expected, value) <<
"i=" <<
i <<
" str=" << e.str
682 <<
" base=" << e.base;
692 <<
"str=\"" << e.str <<
"\" base=" << e.base;
694 EXPECT_EQ(e.expected, value) <<
"str=" << e.str <<
" base=" << e.base;
699 TEST(stringtest, safe_strtou64_base_length_delimited) {
702 std::string tmp(e.str);
706 EXPECT_EQ(e.expect_ok,
709 <<
"str=\"" << e.str <<
"\" base=" << e.base;
711 EXPECT_EQ(e.expected, value) <<
"str=\"" << e.str <<
"\" base=" << e.base;
718 #if defined(_MSC_VER) || defined(__APPLE__) || defined(__EMSCRIPTEN__) 719 #define ABSL_MISSING_FEENABLEEXCEPT 1 720 #define ABSL_MISSING_FEDISABLEEXCEPT 1 723 class SimpleDtoaTest :
public testing::Test {
725 void SetUp()
override {
727 feholdexcept(&fp_env_);
728 #ifndef ABSL_MISSING_FEENABLEEXCEPT 730 feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
734 void TearDown()
override {
738 #ifndef ABSL_MISSING_FEDISABLEEXCEPT 739 fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
744 std::string ToNineDigits(
double value) {
746 snprintf(buffer,
sizeof(buffer),
"%.9g", value);
759 template <
typename R>
760 void ExhaustiveFloat(uint32_t cases, R&& runnable) {
764 for (
float f = 0; f < std::numeric_limits<float>::max(); ) {
765 f = nextafterf(f, std::numeric_limits<float>::max());
771 std::set<float> floats = {3.4028234e38f};
772 for (
float f : {1.0, 3.14159265, 2.718281828, 1 / 2.718281828}) {
773 for (
float testf = f; testf != 0; testf *= 0.1f) floats.insert(testf);
774 for (
float testf = f; testf != 0; testf *= 0.5f) floats.insert(testf);
775 for (
float testf = f; testf < 3e38f / 2; testf *= 2.0f)
776 floats.insert(testf);
777 for (
float testf = f; testf < 3e38f / 10; testf *= 10) floats.insert(testf);
780 float last = *floats.begin();
784 int iters_per_float = cases / floats.size();
785 if (iters_per_float == 0) iters_per_float = 1;
786 for (
float f : floats) {
787 if (f == last)
continue;
788 float testf = std::nextafter(last, std::numeric_limits<float>::max());
792 if (f == last)
continue;
793 double step = (
double{f} - last) / iters_per_float;
794 for (
double d = last + step; d < f; d +=
step) {
802 testf = std::nextafter(f, 0.0f);
816 TEST_F(SimpleDtoaTest, ExhaustiveDoubleToSixDigits) {
817 uint64_t test_count = 0;
818 std::vector<double> mismatches;
819 auto checker = [&](
double d) {
826 if (strcmp(sixdigitsbuf, snprintfbuf) != 0) {
827 mismatches.push_back(d);
828 if (mismatches.size() < 10) {
830 absl::StrCat(
"Six-digit failure with double. ",
"d=", d,
831 "=", d,
" sixdigits=", sixdigitsbuf,
832 " printf(%g)=", snprintfbuf)
842 checker(1.7976931348623157e308);
847 checker(0.001953125);
849 checker(0.005859375);
851 checker(1.089095e-15);
852 checker(3.274195e-55);
853 checker(6.534355e-146);
854 checker(2.920845e+234);
856 if (mismatches.empty()) {
858 ExhaustiveFloat(kFloatNumCases, checker);
861 std::vector<int> digit_testcases{
862 100000, 100001, 100002, 100005, 100010, 100020, 100050, 100100,
864 200000, 500000, 800000,
866 900000, 990000, 999000, 999900, 999990, 999996, 999997, 999998, 999999};
867 if (kFloatNumCases >= 1e9) {
870 constexpr
int min_mantissa = 100000, max_mantissa = 999999;
871 digit_testcases.resize(max_mantissa - min_mantissa + 1);
872 std::iota(digit_testcases.begin(), digit_testcases.end(), min_mantissa);
877 if (powten == 0) powten = 5e-324;
878 if (kFloatNumCases >= 1e9) {
888 for (
int digits : digit_testcases) {
889 if (
exponent == 308 && digits >= 179769)
break;
890 double digiform = (digits + 0.5) * 0.00001;
891 double testval = digiform * powten;
892 double pretestval = nextafter(testval, 0);
893 double posttestval = nextafter(testval, 1.7976931348623157e308);
896 checker(posttestval);
900 EXPECT_EQ(mismatches.size(), 0);
901 for (
size_t i = 0;
i < mismatches.size(); ++
i) {
902 if (
i > 100)
i = mismatches.size() - 1;
903 double d = mismatches[
i];
908 double before = nextafter(d, 0.0);
909 double after = nextafter(d, 1.7976931348623157e308);
914 "Mismatch #",
i,
" d=", d,
" (", ToNineDigits(d),
")",
915 " sixdigits='", sixdigitsbuf,
"'",
" snprintf='", snprintfbuf,
916 "'",
" Before.=", PerfectDtoa(before),
" ",
918 " vs snprintf=", (snprintf(b1,
sizeof(b1),
"%g", before), b1),
920 " vs snprintf=", (snprintf(b1,
sizeof(b1),
"%g", d), b1),
921 " After.=.", PerfectDtoa(after),
" ",
923 " vs snprintf=", (snprintf(b1,
sizeof(b1),
"%g", after), b1))
929 TEST(StrToInt32, Partial) {
930 struct Int32TestLine {
935 const int32_t int32_min = std::numeric_limits<int32_t>::min();
936 const int32_t int32_max = std::numeric_limits<int32_t>::max();
937 Int32TestLine int32_test_line[] = {
941 {
"123@@@",
false, 123},
946 for (
const Int32TestLine& test_line : int32_test_line) {
949 EXPECT_EQ(test_line.status, status) << test_line.input;
950 EXPECT_EQ(test_line.value, value) << test_line.input;
953 EXPECT_EQ(test_line.status, status) << test_line.input;
954 EXPECT_EQ(test_line.value, value) << test_line.input;
957 EXPECT_EQ(test_line.status, status) << test_line.input;
958 EXPECT_EQ(test_line.value, value) << test_line.input;
962 TEST(StrToUint32, Partial) {
963 struct Uint32TestLine {
968 const uint32_t uint32_max = std::numeric_limits<uint32_t>::max();
969 Uint32TestLine uint32_test_line[] = {
973 {
"123@@@",
false, 123},
974 {
absl::StrCat(uint32_max, uint32_max),
false, uint32_max},
977 for (
const Uint32TestLine& test_line : uint32_test_line) {
980 EXPECT_EQ(test_line.status, status) << test_line.input;
981 EXPECT_EQ(test_line.value, value) << test_line.input;
984 EXPECT_EQ(test_line.status, status) << test_line.input;
985 EXPECT_EQ(test_line.value, value) << test_line.input;
988 EXPECT_EQ(test_line.status, status) << test_line.input;
989 EXPECT_EQ(test_line.value, value) << test_line.input;
993 TEST(StrToInt64, Partial) {
994 struct Int64TestLine {
999 const int64_t int64_min = std::numeric_limits<int64_t>::min();
1000 const int64_t int64_max = std::numeric_limits<int64_t>::max();
1001 Int64TestLine int64_test_line[] = {
1005 {
"123@@@",
false, 123},
1006 {
absl::StrCat(int64_min, int64_max),
false, int64_min},
1007 {
absl::StrCat(int64_max, int64_max),
false, int64_max},
1010 for (
const Int64TestLine& test_line : int64_test_line) {
1013 EXPECT_EQ(test_line.status, status) << test_line.input;
1014 EXPECT_EQ(test_line.value, value) << test_line.input;
1017 EXPECT_EQ(test_line.status, status) << test_line.input;
1018 EXPECT_EQ(test_line.value, value) << test_line.input;
1021 EXPECT_EQ(test_line.status, status) << test_line.input;
1022 EXPECT_EQ(test_line.value, value) << test_line.input;
1026 TEST(StrToUint64, Partial) {
1027 struct Uint64TestLine {
1032 const uint64_t uint64_max = std::numeric_limits<uint64_t>::max();
1033 Uint64TestLine uint64_test_line[] = {
1037 {
"123@@@",
false, 123},
1038 {
absl::StrCat(uint64_max, uint64_max),
false, uint64_max},
1041 for (
const Uint64TestLine& test_line : uint64_test_line) {
1044 EXPECT_EQ(test_line.status, status) << test_line.input;
1045 EXPECT_EQ(test_line.value, value) << test_line.input;
1048 EXPECT_EQ(test_line.status, status) << test_line.input;
1049 EXPECT_EQ(test_line.value, value) << test_line.input;
1052 EXPECT_EQ(test_line.status, status) << test_line.input;
1053 EXPECT_EQ(test_line.value, value) << test_line.input;
1057 TEST(StrToInt32Base, PrefixOnly) {
1058 struct Int32TestLine {
1063 Int32TestLine int32_test_line[] = {
1069 {
"-0x",
false, 0 },
1071 const int base_array[] = { 0, 2, 8, 10, 16 };
1073 for (
const Int32TestLine& line : int32_test_line) {
1074 for (
const int base : base_array) {
1077 EXPECT_EQ(line.status, status) << line.input <<
" " << base;
1078 EXPECT_EQ(line.value, value) << line.input <<
" " << base;
1081 EXPECT_EQ(line.status, status) << line.input <<
" " << base;
1082 EXPECT_EQ(line.value, value) << line.input <<
" " << base;
1085 EXPECT_EQ(line.status, status) << line.input <<
" " << base;
1086 EXPECT_EQ(line.value, value) << line.input <<
" " << base;
1091 TEST(StrToUint32Base, PrefixOnly) {
1092 struct Uint32TestLine {
1097 Uint32TestLine uint32_test_line[] = {
1102 const int base_array[] = { 0, 2, 8, 10, 16 };
1104 for (
const Uint32TestLine& line : uint32_test_line) {
1105 for (
const int base : base_array) {
1108 EXPECT_EQ(line.status, status) << line.input <<
" " << base;
1109 EXPECT_EQ(line.value, value) << line.input <<
" " << base;
1112 EXPECT_EQ(line.status, status) << line.input <<
" " << base;
1113 EXPECT_EQ(line.value, value) << line.input <<
" " << base;
1116 EXPECT_EQ(line.status, status) << line.input <<
" " << base;
1117 EXPECT_EQ(line.value, value) << line.input <<
" " << base;
1122 TEST(StrToInt64Base, PrefixOnly) {
1123 struct Int64TestLine {
1128 Int64TestLine int64_test_line[] = {
1134 {
"-0x",
false, 0 },
1136 const int base_array[] = { 0, 2, 8, 10, 16 };
1138 for (
const Int64TestLine& line : int64_test_line) {
1139 for (
const int base : base_array) {
1142 EXPECT_EQ(line.status, status) << line.input <<
" " << base;
1143 EXPECT_EQ(line.value, value) << line.input <<
" " << base;
1146 EXPECT_EQ(line.status, status) << line.input <<
" " << base;
1147 EXPECT_EQ(line.value, value) << line.input <<
" " << base;
1150 EXPECT_EQ(line.status, status) << line.input <<
" " << base;
1151 EXPECT_EQ(line.value, value) << line.input <<
" " << base;
1156 TEST(StrToUint64Base, PrefixOnly) {
1157 struct Uint64TestLine {
1162 Uint64TestLine uint64_test_line[] = {
1167 const int base_array[] = { 0, 2, 8, 10, 16 };
1169 for (
const Uint64TestLine& line : uint64_test_line) {
1170 for (
const int base : base_array) {
1173 EXPECT_EQ(line.status, status) << line.input <<
" " << base;
1174 EXPECT_EQ(line.value, value) << line.input <<
" " << base;
1177 EXPECT_EQ(line.status, status) << line.input <<
" " << base;
1178 EXPECT_EQ(line.value, value) << line.input <<
" " << base;
1181 EXPECT_EQ(line.status, status) << line.input <<
" " << base;
1182 EXPECT_EQ(line.value, value) << line.input <<
" " << base;
bool safe_strtou64_base(absl::string_view text, uint64_t *value, int base)
char * FastIntToBuffer(int32_t, char *)
#define ABSL_RAW_LOG(severity,...)
bool operator<(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
size_t SixDigitsToBuffer(double d, char *buffer)
uint128 operator-(uint128 lhs, uint128 rhs)
std::mt19937_64 RandomEngine
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
CONSTEXPR_F fields step(second_tag, fields f, diff_t n) noexcept
bool Itoa(IntType value, int base, std::string *destination)
uint128 operator*(uint128 lhs, uint128 rhs)
bool safe_strtou32_base(absl::string_view text, uint32_t *value, int base)
bool operator>(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
const std::array< uint64_test_case, 34 > & strtouint64_test_cases()
bool safe_strto32_base(absl::string_view text, int32_t *value, int base)
bool operator==(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
bool operator>=(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
ABSL_MUST_USE_RESULT bool SimpleAtoi(absl::string_view s, int_type *out)
uint128 operator+(uint128 lhs, uint128 rhs)
bool operator!=(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
TEST_F(GraphCyclesTest, NoCycle)
static const int kSixDigitsToBufferSize
bool safe_strto64_base(absl::string_view text, int64_t *value, int base)
const std::array< uint32_test_case, 27 > & strtouint32_test_cases()
TEST(Symbolize, Unimplemented)
static const int kFastToBufferSize
uint128 operator/(uint128 lhs, uint128 rhs)
bool operator<=(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)