4using namespace std::literals;
7 CHECK(kblib::to_string<62>(0) ==
"0");
8 CHECK(kblib::to_string<62>(1) ==
"1");
9 CHECK(kblib::to_string<62>(-1) ==
"-1");
10 CHECK(kblib::to_string<62>(10) ==
"A");
11 CHECK(kblib::to_string<62>(26) ==
"Q");
12 CHECK(kblib::to_string<62>(35) ==
"Z");
13 CHECK(kblib::to_string<62>(36) ==
"a");
14 CHECK(kblib::to_string<62>(61) ==
"z");
15 CHECK(kblib::to_string<62>(62) ==
"10");
16 CHECK(kblib::to_string<62>(63) ==
"11");
17 CHECK(kblib::to_string<62>(630) ==
"AA");
19 CHECK(kblib::to_string<2>(65536) ==
"10000000000000000");
23 static_assert(
decltype(one)
::value == 1,
"");
24 static_assert(one == 1,
"");
31 Message(
"\"\" is not an integer"));
33 Message(
"\"\" is not an integer"));
34 CHECK(kblib::parse_integer<long>(
"0") == 0);
35 CHECK(kblib::parse_integer<long>(
"1") == 1);
36 CHECK(kblib::parse_integer<long>(
"+1") == 1);
37 CHECK(kblib::parse_integer<long>(
"-1") == -1);
38 CHECK(kblib::parse_integer<long>(
"10") == 10);
39 CHECK(kblib::parse_integer<long>(
"010") == 010);
40 CHECK(kblib::parse_integer<long>(
"0x10") == 0x10);
41 CHECK(kblib::parse_integer<long>(
"0b10") == 0b10);
42 CHECK(kblib::parse_integer<long>(
"0b1'0000'0000'0000'0000")
43 == 0b1'0000'0000'0000'0000);
44 CHECK(kblib::parse_integer<long>(
"-10") == -10);
45 CHECK(kblib::parse_integer<long>(
"+10") == 10);
47 CHECK(kblib::parse_integer<long>(
"-010") == -010);
48 CHECK(kblib::parse_integer<long>(
"+010") == 010);
49 CHECK(kblib::parse_integer<long>(
"-0x10") == -0x10);
50 CHECK(kblib::parse_integer<long>(
"+0x10") == 0x10);
51 CHECK(kblib::parse_integer<long>(
"-0b10") == -0b10);
52 CHECK(kblib::parse_integer<long>(
"+0b10") == 0b10);
53 CHECK(kblib::parse_integer<long>(
"-0b1'0000'0000'0000'0000")
54 == -0b1'0000'0000'0000'0000);
55 CHECK(kblib::parse_integer<long>(
"+0b1'0000'0000'0000'0000")
56 == 0b1'0000'0000'0000'0000);
58 CHECK_THROWS_AS(kblib::parse_integer<long>(
"", 1), std::invalid_argument);
60 kblib::parse_integer<long>(
"1", 1), std::invalid_argument,
61 Message(
"base must be either 0 or a positive number between 2 and 62"));
62 CHECK_THROWS_AS(kblib::parse_integer<long>(
"1", -1), std::invalid_argument);
63 CHECK_THROWS_AS(kblib::parse_integer<long>(
"1", 63), std::invalid_argument);
64 CHECK_THROWS_AS(kblib::parse_integer<long>(
"1", 100), std::invalid_argument);
65 CHECK(kblib::parse_integer<long>(
"0", 10) == 0);
66 CHECK(kblib::parse_integer<long>(
"1'0000'0000'0000'0000", 2) == 65536);
69 std::invalid_argument,
70 Message(
"invalid character in integer"));
72 std::invalid_argument,
73 Message(
"unexpected - in integer"));
75 Message(
"unexpected - in integer"));
77 std::invalid_argument,
78 Message(
"unexpected - in integer"));
80 std::invalid_argument,
81 Message(
"unexpected - in integer"));
82 CHECK_THROWS_AS(kblib::parse_integer<long>(
"0+"), std::invalid_argument);
83 CHECK_THROWS_AS(kblib::parse_integer<long>(
"0+1"), std::invalid_argument);
84 CHECK_THROWS_AS(kblib::parse_integer<long>(
"0x+1"), std::invalid_argument);
85 CHECK_THROWS_AS(kblib::parse_integer<long>(
"0b+1"), std::invalid_argument);
86 CHECK_THROWS_AS(kblib::parse_integer<long>(
"--1"), std::invalid_argument);
87 CHECK_THROWS_AS(kblib::parse_integer<long>(
"-+1"), std::invalid_argument);
88 CHECK_THROWS_AS(kblib::parse_integer<long>(
"+-1"), std::invalid_argument);
89 CHECK_THROWS_AS(kblib::parse_integer<long>(
"++1"), std::invalid_argument);
92 CHECK(kblib::parse_integer<std::int16_t>(
"-32768") == -32768);
93 CHECK(kblib::parse_integer<std::int32_t>(
"-0x80'00'00'00")
94 ==
static_cast<std::int32_t
>(-0x80'00'00'00));
98 using namespace std::literals;
99 const std::string str =
"100";
100 CHECK(kblib::fromStr<std::string>(str) == str);
101 CHECK(kblib::fromStr<int>(str) == 100);
102 CHECK(kblib::fromStr<bool>(
"1") ==
true);
103 CHECK(kblib::fromStr<bool>(
"true") ==
true);
104 CHECK(kblib::fromStr<bool>(
"0") ==
false);
105 CHECK(kblib::fromStr<bool>(
"false") ==
false);
107#if KBLIB_USE_STRING_VIEW
108 const std::string_view strv = str;
109 CHECK(kblib::fromStr<std::string>(strv) == strv);
110 CHECK(kblib::fromStr<int>(strv) == 100);
111 CHECK(kblib::fromStr<bool>(
"1"sv) ==
true);
112 CHECK(kblib::fromStr<bool>(
"true"sv) ==
true);
113 CHECK(kblib::fromStr<bool>(
"0"sv) ==
false);
114 CHECK(kblib::fromStr<bool>(
"false"sv) ==
false);
#define CHECK_THROWS_AS(expr, exceptionType)
#define CHECK_THROWS_MATCHES(expr, exceptionType, matcher)
Provides facilities to convert between various kinds of representations.
GeneratorWrapper< T > value(T &&value)
Exception::ExceptionMessageMatcher Message(std::string const &message)