diff --git a/CMakeLists.txt b/CMakeLists.txt index 70d750a..acd469b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,6 +124,7 @@ if(SLED_BUILD_TESTS) src/any_test.cc src/filesystem/path_test.cc src/futures/future_test.cc + src/log/fmt_test.cc # src/profiling/profiling_test.cc src/strings/base64_test.cc src/synchronization/sequence_checker_test.cc diff --git a/include/sled/log/log.h b/include/sled/log/log.h index 6d491a8..dd42204 100644 --- a/include/sled/log/log.h +++ b/include/sled/log/log.h @@ -7,6 +7,7 @@ #ifndef SLED_LOG_LOG_H #define SLED_LOG_LOG_H #pragma once + #include "sled/system/location.h" #include #include @@ -19,6 +20,13 @@ #include #include +template::value, int>::type = 0> +auto +format_as(const T &value) -> int +{ + return static_cast(value); +} + namespace sled { enum class LogLevel { kTrace = 0, diff --git a/src/log/fmt_test.cc b/src/log/fmt_test.cc new file mode 100644 index 0000000..39d162b --- /dev/null +++ b/src/log/fmt_test.cc @@ -0,0 +1,24 @@ +#include +#include + +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"); +}