fix fmt can't format enum
This commit is contained in:
parent
dbdc34279e
commit
56d57d5783
@ -124,6 +124,7 @@ if(SLED_BUILD_TESTS)
|
|||||||
src/any_test.cc
|
src/any_test.cc
|
||||||
src/filesystem/path_test.cc
|
src/filesystem/path_test.cc
|
||||||
src/futures/future_test.cc
|
src/futures/future_test.cc
|
||||||
|
src/log/fmt_test.cc
|
||||||
# src/profiling/profiling_test.cc
|
# src/profiling/profiling_test.cc
|
||||||
src/strings/base64_test.cc
|
src/strings/base64_test.cc
|
||||||
src/synchronization/sequence_checker_test.cc
|
src/synchronization/sequence_checker_test.cc
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#ifndef SLED_LOG_LOG_H
|
#ifndef SLED_LOG_LOG_H
|
||||||
#define SLED_LOG_LOG_H
|
#define SLED_LOG_LOG_H
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "sled/system/location.h"
|
#include "sled/system/location.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <fmt/chrono.h>
|
#include <fmt/chrono.h>
|
||||||
@ -19,6 +20,13 @@
|
|||||||
#include <fmt/std.h>
|
#include <fmt/std.h>
|
||||||
#include <fmt/xchar.h>
|
#include <fmt/xchar.h>
|
||||||
|
|
||||||
|
template<typename T, typename std::enable_if<std::is_enum<T>::value, int>::type = 0>
|
||||||
|
auto
|
||||||
|
format_as(const T &value) -> int
|
||||||
|
{
|
||||||
|
return static_cast<int>(value);
|
||||||
|
}
|
||||||
|
|
||||||
namespace sled {
|
namespace sled {
|
||||||
enum class LogLevel {
|
enum class LogLevel {
|
||||||
kTrace = 0,
|
kTrace = 0,
|
||||||
|
24
src/log/fmt_test.cc
Normal file
24
src/log/fmt_test.cc
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <sled/log/log.h>
|
||||||
|
|
||||||
|
TEST(format, enum)
|
||||||
|
{
|
||||||
|
enum EnumType {
|
||||||
|
kOne = 1,
|
||||||
|
kTwo = 2,
|
||||||
|
kThree = 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
EXPECT_EQ(fmt::format("{}{}{}", kOne, kTwo, kThree), "123");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(format, neg_enum)
|
||||||
|
{
|
||||||
|
enum EnumType {
|
||||||
|
kOne = -1,
|
||||||
|
kTwo = -2,
|
||||||
|
kThree = -3,
|
||||||
|
};
|
||||||
|
|
||||||
|
EXPECT_EQ(fmt::format("{}{}{}", kOne, kTwo, kThree), "-1-2-3");
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user