55//
66// For the license information refer to format.h.
77
8+ // Turn assertion failures into exceptions for testing.
89// clang-format off
910#include " test-assert.h"
1011// clang-format on
2223
2324#include " gmock/gmock.h"
2425
25- using fmt::detail::buffer;
26+ #ifdef FMT_FORMAT_H_
27+ # error base-test includes format.h
28+ #endif
2629
2730using testing::_;
2831using testing::Invoke;
2932using testing::Return;
3033
31- #ifdef FMT_FORMAT_H_
32- # error base-test includes format.h
33- #endif
34-
3534auto copy (fmt::string_view s, fmt::appender out) -> fmt::appender {
3635 for (char c : s) *out++ = c;
3736 return out;
@@ -96,35 +95,37 @@ TEST(string_view_test, compare) {
9695}
9796
9897#if FMT_USE_CONSTEVAL
99- template < size_t N> struct fixed_string {
100- char data[N] = {} ;
98+ TEST (string_view_test, from_constexpr_fixed_string) {
99+ constexpr int size = 4 ;
101100
102- constexpr fixed_string (const char (&m)[N]) {
103- for (size_t i = 0 ; i != N; ++i) data[i] = m[i];
104- }
105- };
101+ struct fixed_string {
102+ char data[size] = {};
106103
107- TEST (string_view_test, from_constexpr_fixed_string) {
108- static constexpr auto fs = fixed_string<4 >(" foo" );
104+ constexpr fixed_string (const char (&m)[size]) {
105+ for (size_t i = 0 ; i != size; ++i) data[i] = m[i];
106+ }
107+ };
108+
109+ static constexpr auto fs = fixed_string(" foo" );
109110 static constexpr auto sv = fmt::string_view(fs.data);
110111 EXPECT_EQ (sv, " foo" );
111112}
112113#endif // FMT_USE_CONSTEVAL
113114
114115#if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 470
115116TEST (buffer_test, noncopyable) {
116- EXPECT_FALSE (std::is_copy_constructible<buffer<char >>::value);
117+ EXPECT_FALSE (std::is_copy_constructible<fmt::detail:: buffer<char >>::value);
117118# if !FMT_MSC_VERSION
118119 // std::is_copy_assignable is broken in MSVC2013.
119- EXPECT_FALSE (std::is_copy_assignable<buffer<char >>::value);
120+ EXPECT_FALSE (std::is_copy_assignable<fmt::detail:: buffer<char >>::value);
120121# endif
121122}
122123
123124TEST (buffer_test, nonmoveable) {
124- EXPECT_FALSE (std::is_move_constructible<buffer<char >>::value);
125+ EXPECT_FALSE (std::is_move_constructible<fmt::detail:: buffer<char >>::value);
125126# if !FMT_MSC_VERSION
126127 // std::is_move_assignable is broken in MSVC2013.
127- EXPECT_FALSE (std::is_move_assignable<buffer<char >>::value);
128+ EXPECT_FALSE (std::is_move_assignable<fmt::detail:: buffer<char >>::value);
128129# endif
129130}
130131#endif
@@ -134,15 +135,16 @@ TEST(buffer_test, indestructible) {
134135 " buffer's destructor is protected" );
135136}
136137
137- template <typename T> struct mock_buffer final : buffer<T> {
138+ template <typename T> struct mock_buffer final : fmt::detail:: buffer<T> {
138139 MOCK_METHOD (size_t , do_grow, (size_t ));
139140
140- static void grow (buffer<T>& buf, size_t capacity) {
141+ static void grow (fmt::detail:: buffer<T>& buf, size_t capacity) {
141142 auto & self = static_cast <mock_buffer&>(buf);
142143 self.set (buf.data (), self.do_grow (capacity));
143144 }
144145
145- mock_buffer (T* data = nullptr , size_t buf_capacity = 0 ) : buffer<T>(grow) {
146+ mock_buffer (T* data = nullptr , size_t buf_capacity = 0 )
147+ : fmt::detail::buffer<T>(grow) {
146148 this ->set (data, buf_capacity);
147149 ON_CALL (*this , do_grow (_)).WillByDefault (Invoke ([](size_t capacity) {
148150 return capacity;
@@ -309,11 +311,6 @@ template <typename Char> struct formatter<test_struct, Char> {
309311};
310312FMT_END_NAMESPACE
311313
312- TEST (arg_test, format_args) {
313- auto args = fmt::format_args ();
314- EXPECT_FALSE (args.get (1 ));
315- }
316-
317314// Use a unique result type to make sure that there are no undesirable
318315// conversions.
319316struct test_result {};
@@ -379,33 +376,9 @@ VISIT_TYPE(unsigned long, unsigned long long);
379376 CHECK_ARG (expected, value) \
380377 }
381378
382- template <typename T> class numeric_arg_test : public testing ::Test {};
383-
384- #if FMT_BUILTIN_TYPES
385- using test_types =
386- testing::Types<bool , signed char , unsigned char , short , unsigned short , int ,
387- unsigned , long , unsigned long , long long , unsigned long long ,
388- float , double , long double >;
389- #else
390- using test_types = testing::Types<int >;
391- #endif
392- TYPED_TEST_SUITE (numeric_arg_test, test_types);
393-
394- template <typename T, fmt::enable_if_t <std::is_integral<T>::value, int > = 0 >
395- auto test_value () -> T {
396- return static_cast <T>(42 );
397- }
398-
399- template <typename T,
400- fmt::enable_if_t <std::is_floating_point<T>::value, int > = 0 >
401- auto test_value () -> T {
402- return static_cast <T>(4.2 );
403- }
404-
405- TYPED_TEST (numeric_arg_test, make_and_visit) {
406- CHECK_ARG_SIMPLE (test_value<TypeParam>());
407- CHECK_ARG_SIMPLE (std::numeric_limits<TypeParam>::min ());
408- CHECK_ARG_SIMPLE (std::numeric_limits<TypeParam>::max ());
379+ TEST (arg_test, format_args) {
380+ auto args = fmt::format_args ();
381+ EXPECT_FALSE (args.get (1 ));
409382}
410383
411384TEST (arg_test, char_arg) { CHECK_ARG (' a' , ' a' ); }
@@ -467,6 +440,35 @@ TEST(arg_test, visit_invalid_arg) {
467440 fmt::basic_format_arg<fmt::format_context>().visit (visitor);
468441}
469442
443+ template <typename T> class numeric_arg_test : public testing ::Test {};
444+
445+ #if FMT_BUILTIN_TYPES
446+ using test_types =
447+ testing::Types<bool , signed char , unsigned char , short , unsigned short , int ,
448+ unsigned , long , unsigned long , long long , unsigned long long ,
449+ float , double , long double >;
450+ #else
451+ using test_types = testing::Types<int >;
452+ #endif
453+ TYPED_TEST_SUITE (numeric_arg_test, test_types);
454+
455+ template <typename T, fmt::enable_if_t <std::is_integral<T>::value, int > = 0 >
456+ auto test_value () -> T {
457+ return static_cast <T>(42 );
458+ }
459+
460+ template <typename T,
461+ fmt::enable_if_t <std::is_floating_point<T>::value, int > = 0 >
462+ auto test_value () -> T {
463+ return static_cast <T>(4.2 );
464+ }
465+
466+ TYPED_TEST (numeric_arg_test, make_and_visit) {
467+ CHECK_ARG_SIMPLE (test_value<TypeParam>());
468+ CHECK_ARG_SIMPLE (std::numeric_limits<TypeParam>::min ());
469+ CHECK_ARG_SIMPLE (std::numeric_limits<TypeParam>::max ());
470+ }
471+
470472#if FMT_USE_CONSTEXPR
471473
472474enum class arg_id_result { none, index, name };
0 commit comments