Add parseUInt utility function

There is an increasing number of places where Catch2 wants to parse
strings into numbers, but being stuck in C++14 world, we do not
have good stdlib facilities to do this (`strtoul` and `stoul`
are both bad).
This commit is contained in:
Martin Hořeňovský
2022-10-20 15:06:26 +02:00
parent 38d926090a
commit d7341b5dc1
25 changed files with 550 additions and 14 deletions

View File

@@ -9055,6 +9055,75 @@ CmdLine.tests.cpp:<line number>: PASSED:
with expansion:
true
-------------------------------------------------------------------------------
Parse uints
proper inputs
-------------------------------------------------------------------------------
Parse.tests.cpp:<line number>
...............................................................................
Parse.tests.cpp:<line number>: PASSED:
REQUIRE( parseUInt( "0" ) == Optional<unsigned int>{ 0 } )
with expansion:
{?} == {?}
Parse.tests.cpp:<line number>: PASSED:
REQUIRE( parseUInt( "100" ) == Optional<unsigned int>{ 100 } )
with expansion:
{?} == {?}
Parse.tests.cpp:<line number>: PASSED:
REQUIRE( parseUInt( "4294967295" ) == Optional<unsigned int>{ 4294967295 } )
with expansion:
{?} == {?}
Parse.tests.cpp:<line number>: PASSED:
REQUIRE( parseUInt( "0x<hex digits>", 16 ) == Optional<unsigned int>{ 255 } )
with expansion:
{?} == {?}
-------------------------------------------------------------------------------
Parse uints
Bad inputs
-------------------------------------------------------------------------------
Parse.tests.cpp:<line number>
...............................................................................
Parse.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( parseUInt( "" ) )
with expansion:
!{?}
Parse.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( parseUInt( "!!KJHF*#" ) )
with expansion:
!{?}
Parse.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( parseUInt( "-1" ) )
with expansion:
!{?}
Parse.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( parseUInt( "4294967296" ) )
with expansion:
!{?}
Parse.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( parseUInt( "42949672964294967296429496729642949672964294967296" ) )
with expansion:
!{?}
Parse.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( parseUInt( "2 4" ) )
with expansion:
!{?}
Parse.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( parseUInt( "0x<hex digits>", 10 ) )
with expansion:
!{?}
-------------------------------------------------------------------------------
Parsed tags are matched case insensitive
-------------------------------------------------------------------------------
@@ -18450,6 +18519,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:
===============================================================================
test cases: 394 | 304 passed | 83 failed | 7 failed as expected
assertions: 2299 | 2129 passed | 143 failed | 27 failed as expected
test cases: 395 | 305 passed | 83 failed | 7 failed as expected
assertions: 2310 | 2140 passed | 143 failed | 27 failed as expected