Merge #20472: test: Add testing of ParseInt/ParseUInt edge cases with leading +/-/0:s

05c10953887bd78af2e21ef6d3c07f90dd885572 test: Add testing of ParseInt/ParseUInt edge cases with leading +/-/0:s (practicalswift)

Pull request description:

  Add testing of `ParseInt`/`ParseUInt` edge cases with leading `+`/`-`/`0`:s.

  Context: While working on #20457 and #20452 I noticed some edge cases which our unit tests are currently not covering.

ACKs for top commit:
  MarcoFalke:
    review ACK 05c10953887bd78af2e21ef6d3c07f90dd885572
  laanwj:
    Code review ACK 05c10953887bd78af2e21ef6d3c07f90dd885572
  jonatack:
    ACK 05c10953887bd78af2e21ef6d3c07f90dd885572
  promag:
    Code review ACK 05c10953887bd78af2e21ef6d3c07f90dd885572.

Tree-SHA512: bdfb94d8fa0293512dbba89907cb6dd0f8b1418d878267dd6d49c8c397a0e5b9714441345565d41a6a909a1cda052ef7cccece822f355ff604fcf85f2dc8136f
This commit is contained in:
MarcoFalke 2020-11-24 12:10:18 +01:00 committed by Pasta
parent fbf6c930b2
commit 2328ead832
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984

View File

@ -800,10 +800,18 @@ BOOST_AUTO_TEST_CASE(test_ParseInt32)
BOOST_CHECK(ParseInt32("2147483647", &n) && n == 2147483647);
BOOST_CHECK(ParseInt32("-2147483648", &n) && n == (-2147483647 - 1)); // (-2147483647 - 1) equals INT_MIN
BOOST_CHECK(ParseInt32("-1234", &n) && n == -1234);
BOOST_CHECK(ParseInt32("00000000000000001234", &n) && n == 1234);
BOOST_CHECK(ParseInt32("-00000000000000001234", &n) && n == -1234);
BOOST_CHECK(ParseInt32("00000000000000000000", &n) && n == 0);
BOOST_CHECK(ParseInt32("-00000000000000000000", &n) && n == 0);
// Invalid values
BOOST_CHECK(!ParseInt32("", &n));
BOOST_CHECK(!ParseInt32(" 1", &n)); // no padding inside
BOOST_CHECK(!ParseInt32("1 ", &n));
BOOST_CHECK(!ParseInt32("++1", &n));
BOOST_CHECK(!ParseInt32("+-1", &n));
BOOST_CHECK(!ParseInt32("-+1", &n));
BOOST_CHECK(!ParseInt32("--1", &n));
BOOST_CHECK(!ParseInt32("1a", &n));
BOOST_CHECK(!ParseInt32("aap", &n));
BOOST_CHECK(!ParseInt32("0x1", &n)); // no hex
@ -859,10 +867,19 @@ BOOST_AUTO_TEST_CASE(test_ParseUInt32)
BOOST_CHECK(ParseUInt32("2147483647", &n) && n == 2147483647);
BOOST_CHECK(ParseUInt32("2147483648", &n) && n == (uint32_t)2147483648);
BOOST_CHECK(ParseUInt32("4294967295", &n) && n == (uint32_t)4294967295);
BOOST_CHECK(ParseUInt32("+1234", &n) && n == 1234);
BOOST_CHECK(ParseUInt32("00000000000000001234", &n) && n == 1234);
BOOST_CHECK(ParseUInt32("00000000000000000000", &n) && n == 0);
// Invalid values
BOOST_CHECK(!ParseUInt32("-00000000000000000000", &n));
BOOST_CHECK(!ParseUInt32("", &n));
BOOST_CHECK(!ParseUInt32(" 1", &n)); // no padding inside
BOOST_CHECK(!ParseUInt32(" -1", &n));
BOOST_CHECK(!ParseUInt32("++1", &n));
BOOST_CHECK(!ParseUInt32("+-1", &n));
BOOST_CHECK(!ParseUInt32("-+1", &n));
BOOST_CHECK(!ParseUInt32("--1", &n));
BOOST_CHECK(!ParseUInt32("-1", &n));
BOOST_CHECK(!ParseUInt32("1 ", &n));
BOOST_CHECK(!ParseUInt32("1a", &n));
BOOST_CHECK(!ParseUInt32("aap", &n));