Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mingxwa committed Jan 6, 2025
1 parent 1b0c5d2 commit ee8fd54
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
7 changes: 7 additions & 0 deletions proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,10 @@ struct facade_conv_traits_impl<F, Cs...> : applicable_traits {
template <class P>
static constexpr bool conv_applicable_ptr =
(conv_traits<Cs>::template applicable_ptr<P> && ...);
template <bool IsDirect, class D, class O>
static constexpr bool is_invocable = std::is_base_of_v<dispatcher_meta<
typename overload_traits<O>::template meta_provider<IsDirect, D>>,
conv_meta>;
};
template <class F, class... Rs>
struct facade_refl_traits_impl : inapplicable_traits {};
Expand Down Expand Up @@ -2150,6 +2154,9 @@ ___PRO_DEBUG( \
namespace std {

template <class F, class CharT>
requires(pro::details::facade_traits<F>::template is_invocable<
false, pro::details::format_dispatch,
pro::details::format_overload_t<CharT>>)
struct formatter<pro::proxy_indirect_accessor<F>, CharT> {
constexpr auto parse(basic_format_parse_context<CharT>& pc) {
auto it = pc.begin();
Expand Down
18 changes: 13 additions & 5 deletions tests/proxy_format_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@

namespace proxy_format_tests_details {

struct TestFacade : pro::facade_builder
struct NonFormattable : pro::facade_builder::build {};

static_assert(!std::is_default_constructible_v<std::formatter<pro::proxy_indirect_accessor<NonFormattable>, char>>);
static_assert(!std::is_default_constructible_v<std::formatter<pro::proxy_indirect_accessor<NonFormattable>, wchar_t>>);

struct Formattable : pro::facade_builder
::support_format
::support_wformat
::build {};

static_assert(std::is_default_constructible_v<std::formatter<pro::proxy_indirect_accessor<Formattable>, char>>);
static_assert(std::is_default_constructible_v<std::formatter<pro::proxy_indirect_accessor<Formattable>, wchar_t>>);

} // namespace proxy_format_tests_details

namespace details = proxy_format_tests_details;

TEST(ProxyFormatTests, TestFormat_Null) {
pro::proxy<details::TestFacade> p;
pro::proxy<details::Formattable> p;
bool exception_thrown = false;
try {
std::ignore = std::format("{}", *p);
Expand All @@ -28,13 +36,13 @@ TEST(ProxyFormatTests, TestFormat_Null) {

TEST(ProxyFormatTests, TestFormat_Value) {
int v = 123;
pro::proxy<details::TestFacade> p = &v;
pro::proxy<details::Formattable> p = &v;
ASSERT_EQ(std::format("{}", *p), "123");
ASSERT_EQ(std::format("{:*<6}", *p), "123***");
}

TEST(ProxyFormatTests, TestWformat_Null) {
pro::proxy<details::TestFacade> p;
pro::proxy<details::Formattable> p;
bool exception_thrown = false;
try {
std::ignore = std::format(L"{}", *p);
Expand All @@ -46,7 +54,7 @@ TEST(ProxyFormatTests, TestWformat_Null) {

TEST(ProxyFormatTests, TestWformat_Value) {
int v = 123;
pro::proxy<details::TestFacade> p = &v;
pro::proxy<details::Formattable> p = &v;
ASSERT_EQ(std::format(L"{}", *p), L"123");
ASSERT_EQ(std::format(L"{:*<6}", *p), L"123***");
}

0 comments on commit ee8fd54

Please sign in to comment.