Added tests for negative int formatting

This commit is contained in:
2021-11-22 12:46:33 +01:00
parent ba86cc40a5
commit 040dae6bf3
3 changed files with 26 additions and 6 deletions

View File

@@ -34,6 +34,7 @@ constexpr int get_output_len() {
// TODO: See if this is possible with <charconv>
// TODO: Steal some code from fmtlib
// TODO: In case of error, set chars to all 'f's
template <fmt_node_t fmt_node, std::integral arg_t>
constexpr std::array<char, fmt_node.length> format_arg(arg_t arg) {
check_fmt_params<fmt_node, arg_t>();
@@ -49,7 +50,7 @@ constexpr std::array<char, fmt_node.length> format_arg(arg_t arg) {
++offset;
}
for (int i = result.size() - 1; (i >= offset) && (arg > 0); --i) {
for (int i = result.size() - 1; (i >= static_cast<int>(offset)) && (arg > 0); --i) {
result[i] = arg % 10 + 48;
arg = arg / 10;
}
@@ -59,6 +60,7 @@ constexpr std::array<char, fmt_node.length> format_arg(arg_t arg) {
// TODO: See if this is possible with <charconv>
// TODO: Steal some code from fmtlib
// TODO: In case of error, set chars to all 'f's
template <fmt_node_t fmt_node, std::floating_point arg_t>
constexpr std::array<char, fmt_node.length> format_arg(arg_t arg) {
check_fmt_params<fmt_node, arg_t>();
@@ -88,6 +90,7 @@ constexpr std::array<char, fmt_node.length> format_arg(arg_t arg) {
}
// TODO: Steal some code from fmtlib
// TODO: In case of error, set chars to all 'f's
template <fmt_node_t fmt_node>
constexpr std::array<char, fmt_node.length> format_arg(const char* arg) {
check_fmt_params<fmt_node, const char*>();

View File

@@ -2,7 +2,7 @@
#define LOGGER_UTILITY_H
#include <cstdlib>
#include "parse_types.h"
namespace detail {