Debian Codegraph @

src/external/catch2/tests/SelfTest/IntrospectiveTests/Parse.tests.cpp

raw
1
2 // Copyright Catch2 Authors
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE.txt or copy at
5 // https://www.boost.org/LICENSE_1_0.txt)
6
7 // SPDX-License-Identifier: BSL-1.0
8
9 #include <catch2/catch_test_macros.hpp>
10
11 #include <catch2/internal/catch_parse_numbers.hpp>
12
13 TEST_CASE("Parse uints", "[parse-numbers]") {
14 using Catch::parseUInt;
15 using Catch::Optional;
16
17 SECTION("proper inputs") {
18 REQUIRE( parseUInt( "0" ) == Optional<unsigned int>{ 0 } );
19 REQUIRE( parseUInt( "100" ) == Optional<unsigned int>{ 100 } );
20 REQUIRE( parseUInt( "4294967295" ) ==
21 Optional<unsigned int>{ 4294967295 } );
22 REQUIRE( parseUInt( "0xFF", 16 ) == Optional<unsigned int>{ 255 } );
23 }
24 SECTION( "Bad inputs" ) {
25 // empty
26 REQUIRE_FALSE( parseUInt( "" ) );
27 // random noise
28 REQUIRE_FALSE( parseUInt( "!!KJHF*#" ) );
29 // negative
30 REQUIRE_FALSE( parseUInt( "-1" ) );
31 // too large
32 REQUIRE_FALSE( parseUInt( "4294967296" ) );
33 REQUIRE_FALSE( parseUInt( "42949672964294967296429496729642949672964294967296" ) );
34 REQUIRE_FALSE( parseUInt( "2 4" ) );
35 // hex with base 10
36 REQUIRE_FALSE( parseUInt( "0xFF", 10 ) );
37 }
38 }