This commit is contained in:
mutouyun 2022-12-03 18:13:10 +08:00
parent d258e00710
commit c39b0fc18c
2 changed files with 17 additions and 2 deletions

View File

@ -4,7 +4,7 @@
#include <iomanip> // std::put_time #include <iomanip> // std::put_time
#include <sstream> // std::ostringstream #include <sstream> // std::ostringstream
#include <array> #include <array>
#include <cstring> // std::memcpy, std::strncat #include <cstring> // std::memcpy
#include <algorithm> // std::min #include <algorithm> // std::min
#include <initializer_list> #include <initializer_list>

View File

@ -5,7 +5,7 @@
#include "libimp/fmt.h" #include "libimp/fmt.h"
TEST(fmt, operator) { TEST(fmt, spec) {
EXPECT_STREQ(imp::spec("hello")(123).fstr.data(), "hello"); EXPECT_STREQ(imp::spec("hello")(123).fstr.data(), "hello");
EXPECT_EQ(imp::spec("hello")(123).param , 123); EXPECT_EQ(imp::spec("hello")(123).param , 123);
EXPECT_STREQ(imp::spec("hello")("world").fstr.data(), "hello"); EXPECT_STREQ(imp::spec("hello")("world").fstr.data(), "hello");
@ -82,3 +82,18 @@ TEST(fmt, fmt) {
EXPECT_EQ(s, "hello world."); EXPECT_EQ(s, "hello world.");
std::cout << imp::fmt('[', std::chrono::system_clock::now(), "] ", s) << "\n"; std::cout << imp::fmt('[', std::chrono::system_clock::now(), "] ", s) << "\n";
} }
namespace {
class foo {};
std::string tag_invoke(decltype(imp::fmt_to_string), foo arg) noexcept(false) {
throw arg;
return {};
}
} // namespace
TEST(fmt, throw) {
EXPECT_THROW(imp::fmt(foo{}), foo);
}