fix xchar support. tests moved/added to xchar-test.cc

This commit is contained in:
Tom Huntington 2023-02-25 13:35:01 +13:00
parent a406d8c5be
commit 0045255da1
3 changed files with 11 additions and 3 deletions

View File

@ -98,7 +98,7 @@ FMT_END_NAMESPACE
FMT_BEGIN_NAMESPACE
template <typename T, typename Char>
struct formatter<std::optional<T>, Char,
std::enable_if_t<is_formattable<T>::value>> {
std::enable_if_t<is_formattable<T, Char>::value>> {
private:
formatter<T, Char> underlying_;
static constexpr basic_string_view<Char> optional =

View File

@ -12,7 +12,6 @@
#include "fmt/os.h" // fmt::system_category
#include "fmt/ranges.h"
#include "fmt/xchar.h"
#include "gtest-extra.h" // StartsWith
using testing::StartsWith;
@ -53,7 +52,7 @@ TEST(std_test, thread_id) {
TEST(std_test, optional) {
#ifdef __cpp_lib_optional
EXPECT_EQ(fmt::format(L"{}", std::optional<int>{}), L"none");
EXPECT_EQ(fmt::format("{}", std::optional<int>{}), "none");
EXPECT_EQ(fmt::format("{}", std::pair{1, "second"}), "(1, \"second\")");
EXPECT_EQ(fmt::format("{}", std::vector{std::optional{1}, std::optional{2},
std::optional{3}}),

View File

@ -16,6 +16,7 @@
#include "fmt/color.h"
#include "fmt/ostream.h"
#include "fmt/ranges.h"
#include "fmt/std.h"
#include "gtest-extra.h" // Contains
#include "util.h" // get_locale
@ -588,4 +589,12 @@ TEST(locale_test, sign) {
EXPECT_EQ(fmt::format(std::locale(), L"{:L}", -50), L"-50");
}
TEST(std_test_xchar, optional) {
# ifdef __cpp_lib_optional
EXPECT_EQ(fmt::format(L"{}", std::optional{L'C'}), L"optional(\'C\')");
EXPECT_EQ(fmt::format(L"{}", std::optional{std::wstring{L"wide string"}}),
L"optional(\"wide string\")");
# endif
}
#endif // FMT_STATIC_THOUSANDS_SEPARATOR