32#include <jau/test/catch2_ext.hpp>
37template<
typename value_type>
38static void testTo(
int line, value_type v, std::string_view exp_s,
40 const uint32_t min_width = 0,
const char separator = 0,
const char padding =
'0')
42 std::string has_s =
jau::to_string(v, radix, capitalization,
prefix, min_width, separator, padding);
43 std::cerr <<
"line " << line <<
": v '" << v <<
", radix " << radix
44 <<
", exp_s '" << exp_s <<
"' (l " << exp_s.length()
45 <<
"), has_s '" << has_s <<
"' (l " << has_s.length() <<
", c " << has_s.capacity()
46 <<
"), match " << (exp_s == has_s) <<
"\n";
47 CHECK( exp_s.length() == has_s.length() );
48 REQUIRE( exp_s == has_s );
50template<
typename value_type>
51static void testToFrom(
int line, value_type exp_v, std::string_view exp_s, std::string_view in_s,
53 const uint32_t min_width = 0,
const char separator = 0,
const char padding =
'0')
55 testTo(line, exp_v, exp_s, radix, capitalization,
prefix, min_width, separator, padding);
58 std::cerr <<
"line " << line <<
": exp_v " << exp_v <<
", in_s '" << in_s <<
"', radix " << radix
59 <<
": ok " << ok <<
", consumed " << consumed <<
" (match " << (consumed == in_s.length()) <<
"), value " << v <<
" (match " << (exp_v == v) <<
")\n";
60 REQUIRE(
true == ok );
61 REQUIRE( exp_v == v );
65template<
typename value_type>
71TEST_CASE(
"Test 01 - from_chars()",
"[jau][string][toBitString]" ) {
90 {
"0", 0}, {
"1", 1}, {
"2", 2}, {
"3", 3}, {
"4", 4}, {
"5", 5}, {
"6", 6}, {
"7", 7}, {
"8", 8}, {
"9", 9},
91 {
"-1", -1}, {
"-2", -2}, {
"-3", -3}, {
"-4", -4}, {
"-5", -5}, {
"-6", -6}, {
"-7", -7}, {
"-8", -8}, {
"-9", -9},
92 {
"10", 10}, {
"-10", -10}, {
"123", 123}, {
"-123", -123}, {
"65432", 65432}, {
"-65432", -65432},
93 {
"-9223372036854775808", std::numeric_limits<int64_t>::min() },
94 {
"9223372036854775807", std::numeric_limits<int64_t>::max() }
105 {
"0", 0}, {
"1", 1}, {
"2", 2}, {
"3", 3}, {
"4", 4}, {
"5", 5}, {
"6", 6}, {
"7", 7}, {
"8", 8}, {
"9", 9},
106 {
"10", 10}, {
"123", 123}, {
"65432", 65432},
107 {
"9223372036854775807", std::numeric_limits<int64_t>::max() },
108 {
"18446744073709551615", std::numeric_limits<uint64_t>::max() }
std::string_view to_string(const endian_t v) noexcept
Return std::string representation of the given endian.
constexpr SizeBoolPair fromIntString(value_type &result, std::string_view str, uint32_t radix=10, const char separator=0) noexcept
Converts a given integer string representation to the given result reference, compatible with ::strto...
static void testTo(int line, value_type v, std::string_view exp_s, uint32_t radix=10, jau::LoUpCase capitalization=jau::LoUpCase::lower, jau::PrefixOpt prefix=jau::PrefixOpt::prefix, const uint32_t min_width=0, const char separator=0, const char padding='0')
TEST_CASE("Test 01 - from_chars()", "[jau][string][toBitString]")
static void testToFrom(int line, value_type exp_v, std::string_view exp_s, std::string_view in_s, uint32_t radix=10, jau::LoUpCase capitalization=jau::LoUpCase::lower, jau::PrefixOpt prefix=jau::PrefixOpt::prefix, const uint32_t min_width=0, const char separator=0, const char padding='0')