Add xchar support for write_escaped_string.

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
Vladislav Shchapov
2022-05-22 21:08:26 +05:00
committed by Victor Zverovich
parent 90b68783ff
commit 1f9eae7e31
3 changed files with 46 additions and 39 deletions

View File

@@ -70,13 +70,9 @@ struct box {
int value;
};
auto begin(const box& b) -> const int* {
return &b.value;
}
auto begin(const box& b) -> const int* { return &b.value; }
auto end(const box& b) -> const int* {
return &b.value + 1;
}
auto end(const box& b) -> const int* { return &b.value + 1; }
} // namespace adl
TEST(ranges_test, format_adl_begin_end) {
@@ -370,6 +366,7 @@ TEST(ranges_test, escape_string) {
EXPECT_EQ(fmt::format("{}", vec{"\xf0\xaa\x9b\x9e"}), "[\"\\U0002a6de\"]");
EXPECT_EQ(fmt::format("{}", vec{"\xf4\x8f\xbf\xc0"}),
"[\"\\xf4\\x8f\\xbf\\xc0\"]");
EXPECT_EQ(fmt::format("{}", vec{"понедельник"}), "[\"понедельник\"]");
}
}

View File

@@ -337,6 +337,17 @@ TEST(xchar_test, ostream) {
#endif
}
TEST(xchar_test, format_map) {
auto m = std::map<std::wstring, int>{{L"one", 1}, {L"t\"wo", 2}};
EXPECT_EQ(fmt::format(L"{}", m), L"{\"one\": 1, \"t\\\"wo\": 2}");
}
TEST(xchar_test, escape_string) {
using vec = std::vector<std::wstring>;
EXPECT_EQ(fmt::format(L"{}", vec{L"\n\r\t\"\\"}), L"[\"\\n\\r\\t\\\"\\\\\"]");
EXPECT_EQ(fmt::format(L"{}", vec{L"понедельник"}), L"[\"понедельник\"]");
}
TEST(xchar_test, to_wstring) { EXPECT_EQ(L"42", fmt::to_wstring(42)); }
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR