mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add constexpr constructor for base_uint
This commit is contained in:
committed by
Nik Bougalis
parent
95426efb8a
commit
85307b29d0
@@ -195,6 +195,60 @@ struct base_uint_test : beast::unit_test::suite
|
||||
BEAST_EXPECT(tmp.parseHex(s1));
|
||||
BEAST_EXPECT(to_string(tmp) == s1);
|
||||
}
|
||||
|
||||
// Constexpr constructors
|
||||
{
|
||||
static_assert(test96{}.signum() == 0);
|
||||
static_assert(test96("0").signum() == 0);
|
||||
static_assert(test96("000000000000000000000000").signum() == 0);
|
||||
static_assert(test96("000000000000000000000001").signum() == 1);
|
||||
static_assert(test96("800000000000000000000000").signum() == 1);
|
||||
|
||||
// Everything within the #if should fail during compilation.
|
||||
#if 0
|
||||
// Too few characters
|
||||
static_assert(test96("00000000000000000000000").signum() == 0);
|
||||
|
||||
// Too many characters
|
||||
static_assert(test96("0000000000000000000000000").signum() == 0);
|
||||
|
||||
// Non-hex characters
|
||||
static_assert(test96("00000000000000000000000 ").signum() == 1);
|
||||
static_assert(test96("00000000000000000000000/").signum() == 1);
|
||||
static_assert(test96("00000000000000000000000:").signum() == 1);
|
||||
static_assert(test96("00000000000000000000000@").signum() == 1);
|
||||
static_assert(test96("00000000000000000000000G").signum() == 1);
|
||||
static_assert(test96("00000000000000000000000`").signum() == 1);
|
||||
static_assert(test96("00000000000000000000000g").signum() == 1);
|
||||
static_assert(test96("00000000000000000000000~").signum() == 1);
|
||||
#endif // 0
|
||||
|
||||
// Verify that constexpr base_uints interpret a string the same
|
||||
// way parseHex() does.
|
||||
struct StrBaseUint
|
||||
{
|
||||
char const* const str;
|
||||
test96 tst;
|
||||
|
||||
constexpr StrBaseUint(char const* s) : str(s), tst(s)
|
||||
{
|
||||
}
|
||||
};
|
||||
constexpr StrBaseUint testCases[] = {
|
||||
"000000000000000000000000",
|
||||
"000000000000000000000001",
|
||||
"fedcba9876543210ABCDEF91",
|
||||
"19FEDCBA0123456789abcdef",
|
||||
"800000000000000000000000",
|
||||
"fFfFfFfFfFfFfFfFfFfFfFfF"};
|
||||
|
||||
for (StrBaseUint const& t : testCases)
|
||||
{
|
||||
test96 t96;
|
||||
BEAST_EXPECT(t96.parseHex(t.str));
|
||||
BEAST_EXPECT(t96 == t.tst);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user