mirror of
https://github.com/fmtlib/fmt.git
synced 2026-11-10 23:30:12 +08:00
Run format tests without locale support
Build format-test.cc with FMT_USE_LOCALE=0 in nolocale-test instead of a separate test file. This replaces two ad-hoc checks with the whole format test suite. The locale-dependent tests were guarded by the removed FMT_STATIC_THOUSANDS_SEPARATOR macro, so the guard never took effect.
This commit is contained in:
parent
225bf7f287
commit
5da4e9a3fb
@ -2245,10 +2245,8 @@ template <typename Context> class value {
|
|||||||
FMT_ENABLE_IF(use_formatter<T>::value || !FMT_BUILTIN_TYPES)>
|
FMT_ENABLE_IF(use_formatter<T>::value || !FMT_BUILTIN_TYPES)>
|
||||||
FMT_CONSTEXPR FMT_INLINE value(T& x) : value(x, custom_tag()) {}
|
FMT_CONSTEXPR FMT_INLINE value(T& x) : value(x, custom_tag()) {}
|
||||||
|
|
||||||
// Could accept const pointer instead, but this avoids a GCC 16+ false
|
// A non-const pointer avoids a bogus gcc 16 -Wmaybe-uninitialized at -O0 in
|
||||||
// positive from `-Wmaybe-uninitialized` in Debug builds, in `named_arg_store`
|
// named_arg_store: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127470.
|
||||||
// constructor. Related bug report:
|
|
||||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127470
|
|
||||||
FMT_ALWAYS_INLINE value(named_arg_info<char_type>* args, size_t size)
|
FMT_ALWAYS_INLINE value(named_arg_info<char_type>* args, size_t size)
|
||||||
: named_args{args, size} {}
|
: named_args{args, size} {}
|
||||||
|
|
||||||
|
|||||||
@ -2793,9 +2793,8 @@ template <typename Char, typename Grouping, typename OutputIt,
|
|||||||
FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f,
|
FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f,
|
||||||
const format_specs& specs, sign s,
|
const format_specs& specs, sign s,
|
||||||
int exp_upper, locale_ref loc) -> OutputIt {
|
int exp_upper, locale_ref loc) -> OutputIt {
|
||||||
Char point = FMT_USE_LOCALE && specs.localized()
|
bool localized = FMT_USE_LOCALE && specs.localized();
|
||||||
? detail::decimal_point<Char>(loc)
|
Char point = localized ? detail::decimal_point<Char>(loc) : Char('.');
|
||||||
: Char('.');
|
|
||||||
int significand_size = get_significand_size(f);
|
int significand_size = get_significand_size(f);
|
||||||
int exp = f.exponent + significand_size - 1;
|
int exp = f.exponent + significand_size - 1;
|
||||||
if (specs.type() == presentation_type::fixed ||
|
if (specs.type() == presentation_type::fixed ||
|
||||||
|
|||||||
@ -128,11 +128,13 @@ if (FMT_PEDANTIC)
|
|||||||
target_compile_options(noexception-test PRIVATE ${PEDANTIC_COMPILE_FLAGS})
|
target_compile_options(noexception-test PRIVATE ${PEDANTIC_COMPILE_FLAGS})
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# Test that the library compiles without locale.
|
# Test that the library works without locale support.
|
||||||
add_executable(nolocale-test ../src/format.cc nolocale-test.cc)
|
add_executable(nolocale-test format-test.cc mock-allocator.h ${TEST_MAIN_SRC}
|
||||||
|
../src/format.cc ../src/os.cc)
|
||||||
target_include_directories(nolocale-test
|
target_include_directories(nolocale-test
|
||||||
PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||||
target_compile_definitions(nolocale-test PRIVATE FMT_USE_LOCALE=0)
|
target_compile_definitions(nolocale-test PRIVATE FMT_USE_LOCALE=0)
|
||||||
|
target_link_libraries(nolocale-test gtest)
|
||||||
target_compile_options(nolocale-test
|
target_compile_options(nolocale-test
|
||||||
PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/utf-8>)
|
PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/utf-8>)
|
||||||
add_test(NAME nolocale-test COMMAND nolocale-test)
|
add_test(NAME nolocale-test COMMAND nolocale-test)
|
||||||
|
|||||||
@ -1560,6 +1560,7 @@ TEST(format_test, format_int_locale) {
|
|||||||
TEST(format_test, format_float) {
|
TEST(format_test, format_float) {
|
||||||
EXPECT_EQ(fmt::format("{}", 0.0f), "0");
|
EXPECT_EQ(fmt::format("{}", 0.0f), "0");
|
||||||
EXPECT_EQ(fmt::format("{0:f}", 392.5f), "392.500000");
|
EXPECT_EQ(fmt::format("{0:f}", 392.5f), "392.500000");
|
||||||
|
EXPECT_EQ(fmt::format("{:L}", 1234.5), "1234.5");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(format_test, format_double) {
|
TEST(format_test, format_double) {
|
||||||
@ -2250,7 +2251,9 @@ TEST(format_test, fill_via_appender) {
|
|||||||
|
|
||||||
TEST(format_test, formatted_size) {
|
TEST(format_test, formatted_size) {
|
||||||
EXPECT_EQ(2u, fmt::formatted_size("{}", 42));
|
EXPECT_EQ(2u, fmt::formatted_size("{}", 42));
|
||||||
|
#if FMT_USE_LOCALE
|
||||||
EXPECT_EQ(2u, fmt::formatted_size(std::locale(), "{}", 42));
|
EXPECT_EQ(2u, fmt::formatted_size(std::locale(), "{}", 42));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(format_test, format_to_no_args) {
|
TEST(format_test, format_to_no_args) {
|
||||||
@ -2483,7 +2486,9 @@ TEST(format_int_test, format_int) {
|
|||||||
std::to_string(max_value<int64_t>()));
|
std::to_string(max_value<int64_t>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
|
// This file is also compiled with FMT_USE_LOCALE=0 by nolocale-test, so tests
|
||||||
|
// that use std::locale must go in this block.
|
||||||
|
#if FMT_USE_LOCALE
|
||||||
|
|
||||||
# include <locale>
|
# include <locale>
|
||||||
|
|
||||||
@ -2548,7 +2553,7 @@ TEST(format_test, format_locale) {
|
|||||||
EXPECT_EQ(fmt::format(loc, "{:10Lo}", 12345), " 30,071");
|
EXPECT_EQ(fmt::format(loc, "{:10Lo}", 12345), " 30,071");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // FMT_STATIC_THOUSANDS_SEPARATOR
|
#endif // FMT_USE_LOCALE
|
||||||
|
|
||||||
struct convertible_to_nonconst_cstring {
|
struct convertible_to_nonconst_cstring {
|
||||||
operator char*() const {
|
operator char*() const {
|
||||||
|
|||||||
@ -1,13 +0,0 @@
|
|||||||
// Formatting library for C++ - no-locale tests
|
|
||||||
//
|
|
||||||
// Copyright (c) 2012 - present, Victor Zverovich and {fmt} contributors
|
|
||||||
// All rights reserved.
|
|
||||||
//
|
|
||||||
// For the license information refer to format.h.
|
|
||||||
|
|
||||||
#include "fmt/format.h"
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
if (fmt::format("{:L}", 1234567) != "1234567") return 1;
|
|
||||||
if (fmt::format("{:L}", 1234.5) != "1234.5") return 1;
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user