mirror of
https://github.com/fmtlib/fmt.git
synced 2026-05-04 19:44:09 +02:00
Cleanup tests
This commit is contained in:
+2
-2
@@ -75,8 +75,8 @@ add_fmt_test(scan-test)
|
||||
|
||||
if (NOT MSVC)
|
||||
# FMT_ENFORCE_COMPILE_STRING is not supported under MSVC due to compiler bugs.
|
||||
add_fmt_test(enforce-compile-string-test)
|
||||
target_compile_definitions(enforce-compile-string-test PRIVATE
|
||||
add_fmt_test(enforce-checks-test)
|
||||
target_compile_definitions(enforce-checks-test PRIVATE
|
||||
-DFMT_ENFORCE_COMPILE_STRING)
|
||||
endif ()
|
||||
|
||||
|
||||
@@ -12,6 +12,14 @@
|
||||
#include "fmt/chrono.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
TEST(iterator_test, counting_iterator) {
|
||||
auto it = fmt::detail::counting_iterator();
|
||||
auto prev = it++;
|
||||
EXPECT_EQ(prev.count(), 0);
|
||||
EXPECT_EQ(it.count(), 1);
|
||||
EXPECT_EQ((it + 41).count(), 42);
|
||||
}
|
||||
|
||||
TEST(iterator_test, truncating_iterator) {
|
||||
char* p = nullptr;
|
||||
auto it = fmt::detail::truncating_iterator<char*>(p, 3);
|
||||
|
||||
@@ -37,6 +37,14 @@ TEST(string_view_test, value_type) {
|
||||
static_assert(std::is_same<string_view::value_type, char>::value, "");
|
||||
}
|
||||
|
||||
TEST(string_view_test, ctor) {
|
||||
EXPECT_STREQ("abc", fmt::string_view("abc").data());
|
||||
EXPECT_EQ(3u, fmt::string_view("abc").size());
|
||||
|
||||
EXPECT_STREQ("defg", fmt::string_view(std::string("defg")).data());
|
||||
EXPECT_EQ(4u, fmt::string_view(std::string("defg")).size());
|
||||
}
|
||||
|
||||
TEST(string_view_test, length) {
|
||||
// Test that string_view::size() returns string length, not buffer size.
|
||||
char str[100] = "some string";
|
||||
@@ -114,6 +122,35 @@ TYPED_TEST(is_string_test, is_string) {
|
||||
EXPECT_FALSE(fmt::detail::is_string<test_ns::non_string>::value);
|
||||
}
|
||||
|
||||
TEST(core_test, is_output_iterator) {
|
||||
EXPECT_TRUE((fmt::detail::is_output_iterator<char*, char>::value));
|
||||
EXPECT_FALSE((fmt::detail::is_output_iterator<const char*, char>::value));
|
||||
EXPECT_FALSE((fmt::detail::is_output_iterator<std::string, char>::value));
|
||||
EXPECT_TRUE(
|
||||
(fmt::detail::is_output_iterator<std::back_insert_iterator<std::string>,
|
||||
char>::value));
|
||||
EXPECT_TRUE(
|
||||
(fmt::detail::is_output_iterator<std::string::iterator, char>::value));
|
||||
EXPECT_FALSE((fmt::detail::is_output_iterator<std::string::const_iterator,
|
||||
char>::value));
|
||||
}
|
||||
|
||||
TEST(core_test, buffer_appender) {
|
||||
// back_insert_iterator is not default-constructible before C++20, so
|
||||
// buffer_appender can only be default-constructible when back_insert_iterator
|
||||
// is.
|
||||
static_assert(
|
||||
std::is_default_constructible<
|
||||
std::back_insert_iterator<fmt::detail::buffer<char>>>::value ==
|
||||
std::is_default_constructible<
|
||||
fmt::detail::buffer_appender<char>>::value,
|
||||
"");
|
||||
|
||||
#ifdef __cpp_lib_ranges
|
||||
static_assert(std::output_iterator<fmt::detail::buffer_appender<char>, char>);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 470
|
||||
TEST(buffer_test, noncopyable) {
|
||||
EXPECT_FALSE(std::is_copy_constructible<buffer<char>>::value);
|
||||
@@ -592,6 +629,14 @@ TEST(core_test, format_explicitly_convertible_to_std_string_view) {
|
||||
# endif
|
||||
#endif
|
||||
|
||||
struct convertible_to_long_long {
|
||||
operator long long() const { return 1LL << 32; }
|
||||
};
|
||||
|
||||
TEST(format_test, format_convertible_to_long_long) {
|
||||
EXPECT_EQ("100000000", fmt::format("{:x}", convertible_to_long_long()));
|
||||
}
|
||||
|
||||
struct disabled_rvalue_conversion {
|
||||
operator const char*() const& { return "foo"; }
|
||||
operator const char*() & { return "foo"; }
|
||||
|
||||
+378
-482
File diff suppressed because it is too large
Load Diff
@@ -8,14 +8,18 @@
|
||||
#ifndef FMT_MOCK_ALLOCATOR_H_
|
||||
#define FMT_MOCK_ALLOCATOR_H_
|
||||
|
||||
#include "fmt/format.h"
|
||||
#include <assert.h> // assert
|
||||
#include <stddef.h> // size_t
|
||||
|
||||
#include <memory> // std::allocator_traits
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
template <typename T> class mock_allocator {
|
||||
public:
|
||||
mock_allocator() {}
|
||||
mock_allocator(const mock_allocator&) {}
|
||||
typedef T value_type;
|
||||
using value_type = T;
|
||||
MOCK_METHOD1_T(allocate, T*(size_t n));
|
||||
MOCK_METHOD2_T(deallocate, void(T* p, size_t n));
|
||||
};
|
||||
@@ -30,7 +34,7 @@ template <typename Allocator> class allocator_ref {
|
||||
}
|
||||
|
||||
public:
|
||||
typedef typename Allocator::value_type value_type;
|
||||
using value_type = typename Allocator::value_type;
|
||||
|
||||
explicit allocator_ref(Allocator* alloc = nullptr) : alloc_(alloc) {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user