Use 'using' to provide char8_t type if neccessary as Victor's suggestion

This commit is contained in:
denchat 2019-05-09 12:22:32 +07:00 committed by GitHub
parent 63d6445592
commit c8cbf57e06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2494,16 +2494,14 @@ TEST(FormatTest, FmtStringInTemplate) {
// C++20 feature test, since r346892 Clang considers char8_t a fundamental // C++20 feature test, since r346892 Clang considers char8_t a fundamental
// type in this mode. If this is the case __cpp_char8_t will be defined. // type in this mode. If this is the case __cpp_char8_t will be defined.
#ifndef __cpp_char8_t #ifndef __cpp_char8_t
// A UTF-8 code unit type. // Locally provide type char8_t defined in format.h
#define CHAR8_T fmt::char8_t using fmt::char8_t
#else
#define CHAR8_T char8_t
#endif #endif
TEST(FormatTest, ConstructU8StringViewFromCString) { TEST(FormatTest, ConstructU8StringViewFromCString) {
fmt::u8string_view s("ab"); fmt::u8string_view s("ab");
EXPECT_EQ(s.size(), 2u); EXPECT_EQ(s.size(), 2u);
const CHAR8_T* data = s.data(); const char8_t* data = s.data();
EXPECT_EQ(data[0], 'a'); EXPECT_EQ(data[0], 'a');
EXPECT_EQ(data[1], 'b'); EXPECT_EQ(data[1], 'b');
} }
@ -2511,7 +2509,7 @@ TEST(FormatTest, ConstructU8StringViewFromCString) {
TEST(FormatTest, ConstructU8StringViewFromDataAndSize) { TEST(FormatTest, ConstructU8StringViewFromDataAndSize) {
fmt::u8string_view s("foobar", 3); fmt::u8string_view s("foobar", 3);
EXPECT_EQ(s.size(), 3u); EXPECT_EQ(s.size(), 3u);
const CHAR8_T* data = s.data(); const char8_t* data = s.data();
EXPECT_EQ(data[0], 'f'); EXPECT_EQ(data[0], 'f');
EXPECT_EQ(data[1], 'o'); EXPECT_EQ(data[1], 'o');
EXPECT_EQ(data[2], 'o'); EXPECT_EQ(data[2], 'o');
@ -2522,7 +2520,7 @@ TEST(FormatTest, U8StringViewLiteral) {
using namespace fmt::literals; using namespace fmt::literals;
fmt::u8string_view s = "ab"_u; fmt::u8string_view s = "ab"_u;
EXPECT_EQ(s.size(), 2u); EXPECT_EQ(s.size(), 2u);
const CHAR8_T* data = s.data(); const char8_t* data = s.data();
EXPECT_EQ(data[0], 'a'); EXPECT_EQ(data[0], 'a');
EXPECT_EQ(data[1], 'b'); EXPECT_EQ(data[1], 'b');
EXPECT_EQ(format("{:*^5}"_u, "🤡"_u), "**🤡**"_u); EXPECT_EQ(format("{:*^5}"_u, "🤡"_u), "**🤡**"_u);