mirror of
https://github.com/fmtlib/fmt.git
synced 2025-10-28 20:51:42 +01:00
Deprecate fmt::char8_t
This commit is contained in:
@@ -10,12 +10,11 @@
|
||||
#include "test-assert.h"
|
||||
|
||||
// Include format.cc instead of format.h to test implementation.
|
||||
#include "../src/format.cc"
|
||||
#include "fmt/printf.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
#include "../src/format.cc"
|
||||
#include "fmt/printf.h"
|
||||
#include "gmock.h"
|
||||
#include "gtest-extra.h"
|
||||
#include "util.h"
|
||||
@@ -430,8 +429,10 @@ TEST(FormatTest, CountCodePoints) {
|
||||
#ifndef __cpp_char8_t
|
||||
using fmt::char8_t;
|
||||
#endif
|
||||
EXPECT_EQ(4, fmt::internal::count_code_points(
|
||||
fmt::basic_string_view<char8_t>(reinterpret_cast<const char8_t*>("ёжик"))));
|
||||
EXPECT_EQ(
|
||||
4, fmt::internal::count_code_points(
|
||||
fmt::basic_string_view<fmt::internal::char8_type>(
|
||||
reinterpret_cast<const fmt::internal::char8_type*>("ёжик"))));
|
||||
}
|
||||
|
||||
// Tests fmt::internal::count_digits for integer type Int.
|
||||
|
||||
@@ -2504,25 +2504,6 @@ TEST(FormatTest, FmtStringInTemplate) {
|
||||
|
||||
#endif // FMT_USE_CONSTEXPR
|
||||
|
||||
// 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.
|
||||
#ifndef __cpp_char8_t
|
||||
// Locally provide type char8_t defined in format.h
|
||||
using fmt::char8_t;
|
||||
#endif
|
||||
|
||||
// Convert 'char8_t' character sequences to 'char' sequences
|
||||
// Otherwise GTest will insist on inserting 'char8_t' NTBS into a 'char' stream,
|
||||
// but basic_ostream<char>::operator<< overloads taking 'char8_t' arguments
|
||||
// are defined as deleted by P1423.
|
||||
// Handling individual 'char8_t's is done inline.
|
||||
std::string from_u8str(const std::basic_string<char8_t>& str) {
|
||||
return std::string(str.begin(), str.end());
|
||||
}
|
||||
std::string from_u8str(const fmt::basic_string_view<char8_t>& str) {
|
||||
return std::string(str.begin(), str.end());
|
||||
}
|
||||
|
||||
TEST(FormatTest, EmphasisNonHeaderOnly) {
|
||||
// Ensure this compiles even if FMT_HEADER_ONLY is not defined.
|
||||
EXPECT_EQ(fmt::format(fmt::emphasis::bold, "bold error"),
|
||||
@@ -2561,10 +2542,18 @@ TEST(FormatTest, FormatCustomChar) {
|
||||
EXPECT_EQ(result[0], mychar('x'));
|
||||
}
|
||||
|
||||
// Convert a char8_t string to std::string. Otherwise GTest will insist on
|
||||
// inserting `char8_t` NTBS into a `char` stream which is disabled by P1423.
|
||||
template <typename S> std::string from_u8str(const S& str) {
|
||||
return std::string(str.begin(), str.end());
|
||||
}
|
||||
|
||||
TEST(FormatTest, FormatUTF8Precision) {
|
||||
using str_type = std::basic_string<char8_t>;
|
||||
str_type format(reinterpret_cast<const char8_t*>(u8"{:.4}"));
|
||||
str_type str(reinterpret_cast<const char8_t*>(u8"caf\u00e9s")); // cafés
|
||||
using str_type = std::basic_string<fmt::internal::char8_type>;
|
||||
str_type format(
|
||||
reinterpret_cast<const fmt::internal::char8_type*>(u8"{:.4}"));
|
||||
str_type str(reinterpret_cast<const fmt::internal::char8_type*>(
|
||||
u8"caf\u00e9s")); // cafés
|
||||
auto result = fmt::format(format, str);
|
||||
EXPECT_EQ(fmt::internal::count_code_points(result), 4);
|
||||
EXPECT_EQ(result.size(), 5);
|
||||
|
||||
Reference in New Issue
Block a user