Add test for upper case conversions and fix as necessary

This commit is contained in:
King_DuckZ 2020-08-14 00:30:22 +01:00
parent f1d6ac789e
commit 1c6de14cd4
2 changed files with 9 additions and 1 deletions

View file

@ -286,7 +286,7 @@ namespace dhandy {
}
};
template <typename C>
using ASCIITranslatorUpcase = ASCIITranslator<C, 'A'>;
using ASCIITranslatorUpcase = ASCIITranslator<C, '0', 'A'>;
template <typename I, unsigned int Base=10, typename Tr=ASCIITranslator<char>>
constexpr inline auto int_to_ary (I in) {

View file

@ -34,6 +34,12 @@ namespace {
using AryConversion = dhandy::implem::AryConversion<T, Base, dhandy::ASCIITranslator<char>>;
CHECK(AryConversion::from_ary(s.data(), s.data() + s.size()) == expected);
}
template <typename T, unsigned int Base>
void AryConversionTestHelperUp (const std::string_view& s, T expected) {
using AryConversion = dhandy::implem::AryConversion<T, Base, dhandy::ASCIITranslatorUpcase<char>>;
CHECK(AryConversion::from_ary(s.data(), s.data() + s.size()) == expected);
}
} //unnamed namespace
TEST_CASE ("Check int to char array conversions", "[s2i][int_conv]") {
@ -74,6 +80,7 @@ TEST_CASE ("Check int to char array conversions", "[s2i][int_conv]") {
CHECK(int_to_ary<int64_t>(-1) == "-1");
CHECK(int_to_ary<int64_t>(0x1000000000000000) == "1152921504606846976");
CHECK(int_to_ary<int64_t>(0xF000000000000000) == "-1152921504606846976");
CHECK(int_to_ary<int, 16, dhandy::ASCIITranslatorUpcase<char>>(255) == "FF");
CHECK(int_to_ary<uint16_t SPROUT_PP_COMMA() 16>(0xFFFF) == "ffff");
CHECK(int_to_ary<uint16_t SPROUT_PP_COMMA() 16>(0xCACA) == "caca");
@ -155,6 +162,7 @@ TEST_CASE ("Check char array to int conversions", "[i2s][int_conv]") {
AryConversionTestHelper<int32_t, 16>("7fffffff", 0x7fffffff);
AryConversionTestHelper<bool, 10>("1", true);
AryConversionTestHelper<bool, 10>("0", false);
AryConversionTestHelperUp<uint64_t, 16>("ABCDEF123456ABCD", 0xabcdef123456abcd);
AryConversionTestHelper<signed int, 10>("-1", -1);
AryConversionTestHelper<signed int, 10>("-50000", -50000);