Commit 3f4984fb authored by Victor Zverovich's avatar Victor Zverovich

Clean core-test and fix linkage errors on older gcc

parent d4366505
......@@ -755,6 +755,54 @@ class basic_format_arg {
bool is_arithmetic() const { return internal::is_arithmetic(type_); }
};
struct monostate {};
/**
\rst
Visits an argument dispatching to the appropriate visit method based on
the argument type. For example, if the argument type is ``double`` then
``vis(value)`` will be called with the value of type ``double``.
\endrst
*/
template <typename Visitor, typename Context>
FMT_CONSTEXPR typename internal::result_of<Visitor(int)>::type
visit(Visitor &&vis, const basic_format_arg<Context> &arg) {
typedef typename Context::char_type char_type;
switch (arg.type_) {
case internal::none_type:
break;
case internal::named_arg_type:
FMT_ASSERT(false, "invalid argument type");
break;
case internal::int_type:
return vis(arg.value_.int_value);
case internal::uint_type:
return vis(arg.value_.uint_value);
case internal::long_long_type:
return vis(arg.value_.long_long_value);
case internal::ulong_long_type:
return vis(arg.value_.ulong_long_value);
case internal::bool_type:
return vis(arg.value_.int_value != 0);
case internal::char_type:
return vis(static_cast<char_type>(arg.value_.int_value));
case internal::double_type:
return vis(arg.value_.double_value);
case internal::long_double_type:
return vis(arg.value_.long_double_value);
case internal::cstring_type:
return vis(arg.value_.string.value);
case internal::string_type:
return vis(basic_string_view<char_type>(
arg.value_.string.value, arg.value_.string.size));
case internal::pointer_type:
return vis(arg.value_.pointer);
case internal::custom_type:
return vis(typename basic_format_arg<Context>::handle(arg.value_.custom));
}
return vis(monostate());
}
// Parsing context consisting of a format string range being parsed and an
// argument counter for automatic indexing.
template <typename Char, typename ErrorHandler = internal::error_handler>
......
......@@ -1154,54 +1154,6 @@ template <typename T = void>
struct null {};
} // namespace internal
struct monostate {};
/**
\rst
Visits an argument dispatching to the appropriate visit method based on
the argument type. For example, if the argument type is ``double`` then
``vis(value)`` will be called with the value of type ``double``.
\endrst
*/
template <typename Visitor, typename Context>
FMT_CONSTEXPR typename internal::result_of<Visitor(int)>::type
visit(Visitor &&vis, const basic_format_arg<Context> &arg) {
typedef typename Context::char_type char_type;
switch (arg.type_) {
case internal::none_type:
break;
case internal::named_arg_type:
FMT_ASSERT(false, "invalid argument type");
break;
case internal::int_type:
return vis(arg.value_.int_value);
case internal::uint_type:
return vis(arg.value_.uint_value);
case internal::long_long_type:
return vis(arg.value_.long_long_value);
case internal::ulong_long_type:
return vis(arg.value_.ulong_long_value);
case internal::bool_type:
return vis(arg.value_.int_value != 0);
case internal::char_type:
return vis(static_cast<char_type>(arg.value_.int_value));
case internal::double_type:
return vis(arg.value_.double_value);
case internal::long_double_type:
return vis(arg.value_.long_double_value);
case internal::cstring_type:
return vis(arg.value_.string.value);
case internal::string_type:
return vis(basic_string_view<char_type>(
arg.value_.string.value, arg.value_.string.size));
case internal::pointer_type:
return vis(arg.value_.pointer);
case internal::custom_type:
return vis(typename basic_format_arg<Context>::handle(arg.value_.custom));
}
return vis(monostate());
}
enum alignment {
ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC
};
......
......@@ -14,33 +14,40 @@ template struct internal::basic_data<void>;
template FMT_API char internal::thousands_sep(locale_provider *lp);
template void internal::basic_buffer<char>::append(const char *, const char *);
template void basic_fixed_buffer<char>::grow(std::size_t);
template void internal::arg_map<format_context>::init(
const basic_format_args<format_context> &args);
template FMT_API int internal::char_traits<char>::format_float(
char *buffer, std::size_t size, const char *format, int precision,
double value);
char *, std::size_t, const char *, int, double);
template FMT_API int internal::char_traits<char>::format_float(
char *buffer, std::size_t size, const char *format, int precision,
long double value);
char *, std::size_t, const char *, int, long double);
template FMT_API std::string internal::vformat<char>(
string_view, basic_format_args<format_context>);
// Explicit instantiations for wchar_t.
template FMT_API wchar_t internal::thousands_sep(locale_provider *lp);
template FMT_API wchar_t internal::thousands_sep(locale_provider *);
template void internal::basic_buffer<wchar_t>::append(
const wchar_t *, const wchar_t *);
template void basic_fixed_buffer<wchar_t>::grow(std::size_t);
template void internal::arg_map<wformat_context>::init(
const basic_format_args<wformat_context> &args);
const basic_format_args<wformat_context> &);
template FMT_API int internal::char_traits<wchar_t>::format_float(
wchar_t *buffer, std::size_t size, const wchar_t *format,
int precision, double value);
wchar_t *, std::size_t, const wchar_t *, int, double);
template FMT_API int internal::char_traits<wchar_t>::format_float(
wchar_t *buffer, std::size_t size, const wchar_t *format,
int precision, long double value);
wchar_t *, std::size_t, const wchar_t *, int, long double);
template FMT_API std::wstring internal::vformat<wchar_t>(
wstring_view, basic_format_args<wformat_context>);
FMT_END_NAMESPACE
......@@ -85,9 +85,9 @@ function(add_fmt_test name)
endfunction()
add_fmt_test(assert-test)
add_fmt_test(core-test mock-allocator.h)
add_fmt_test(core-test)
add_fmt_test(gtest-extra-test)
add_fmt_test(format-test)
add_fmt_test(format-test mock-allocator.h)
add_fmt_test(format-impl-test)
add_fmt_test(ostream-test)
add_fmt_test(printf-test)
......
This diff is collapsed.
This diff is collapsed.
......@@ -9,23 +9,24 @@
#define FMT_MOCK_ALLOCATOR_H_
#include "gmock.h"
#include "fmt/format.h"
template <typename T>
class MockAllocator {
class mock_allocator {
public:
MockAllocator() {}
MockAllocator(const MockAllocator &) {}
mock_allocator() {}
mock_allocator(const mock_allocator &) {}
typedef T value_type;
MOCK_METHOD1_T(allocate, T* (std::size_t n));
MOCK_METHOD2_T(deallocate, void (T* p, std::size_t n));
};
template <typename Allocator>
class AllocatorRef {
class allocator_ref {
private:
Allocator *alloc_;
void move(AllocatorRef &other) {
void move(allocator_ref &other) {
alloc_ = other.alloc_;
other.alloc_ = nullptr;
}
......@@ -33,18 +34,18 @@ class AllocatorRef {
public:
typedef typename Allocator::value_type value_type;
explicit AllocatorRef(Allocator *alloc = nullptr) : alloc_(alloc) {}
explicit allocator_ref(Allocator *alloc = nullptr) : alloc_(alloc) {}
AllocatorRef(const AllocatorRef &other) : alloc_(other.alloc_) {}
AllocatorRef(AllocatorRef &&other) { move(other); }
allocator_ref(const allocator_ref &other) : alloc_(other.alloc_) {}
allocator_ref(allocator_ref &&other) { move(other); }
AllocatorRef& operator=(AllocatorRef &&other) {
allocator_ref& operator=(allocator_ref &&other) {
assert(this != &other);
move(other);
return *this;
}
AllocatorRef& operator=(const AllocatorRef &other) {
allocator_ref& operator=(const allocator_ref &other) {
alloc_ = other.alloc_;
return *this;
}
......
......@@ -5,23 +5,22 @@
//
// For the license information refer to format.h.
#ifndef FMT_TEST_ASSERT_H
#define FMT_TEST_ASSERT_H
#ifndef FMT_TEST_ASSERT_H_
#define FMT_TEST_ASSERT_H_
#include <stdexcept>
#include "gtest.h"
class AssertionFailure : public std::logic_error {
class assertion_failure : public std::logic_error {
public:
explicit AssertionFailure(const char *message) : std::logic_error(message) {}
explicit assertion_failure(const char *message) : std::logic_error(message) {}
};
#define FMT_ASSERT(condition, message) \
if (!(condition)) throw AssertionFailure(message);
#include "gtest-extra.h"
if (!(condition)) throw assertion_failure(message);
// Expects an assertion failure.
#define EXPECT_ASSERT(stmt, message) \
EXPECT_THROW_MSG(stmt, AssertionFailure, message)
FMT_TEST_THROW_(stmt, assertion_failure, message, GTEST_NONFATAL_FAILURE_)
#endif // FMT_TEST_ASSERT_H
#endif // FMT_TEST_ASSERT_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment