forked from ngcpp/proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy_fmt_format_tests.cpp
More file actions
50 lines (39 loc) · 1.57 KB
/
proxy_fmt_format_tests.cpp
File metadata and controls
50 lines (39 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.
#include <gtest/gtest.h>
#include <fmt/format.h>
#include <fmt/xchar.h>
#include <proxy/proxy.h>
#include <proxy/proxy_fmt.h>
namespace proxy_fmt_format_tests_details {
struct NonFormattable : pro::facade_builder::build {};
static_assert(
!std::is_default_constructible_v<
fmt::formatter<pro::proxy_indirect_accessor<NonFormattable>, char>>);
static_assert(
!std::is_default_constructible_v<
fmt::formatter<pro::proxy_indirect_accessor<NonFormattable>, wchar_t>>);
struct Formattable : pro::facade_builder //
::add_skill<pro::skills::fmt_format> //
::add_skill<pro::skills::fmt_wformat> //
::build {};
static_assert(std::is_default_constructible_v<
fmt::formatter<pro::proxy_indirect_accessor<Formattable>, char>>);
static_assert(
std::is_default_constructible_v<
fmt::formatter<pro::proxy_indirect_accessor<Formattable>, wchar_t>>);
} // namespace proxy_fmt_format_tests_details
namespace details = proxy_fmt_format_tests_details;
TEST(ProxyFmtFormatTests, TestFormat) {
int v = 123;
pro::proxy<details::Formattable> p = &v;
ASSERT_EQ(fmt::format("{}", *p), "123");
ASSERT_EQ(fmt::format("{:*<6}", *p), "123***");
}
TEST(ProxyFmtFormatTests, TestWformat) {
int v = 123;
pro::proxy<details::Formattable> p = &v;
ASSERT_EQ(fmt::format(L"{}", *p), L"123");
ASSERT_EQ(fmt::format(L"{:*<6}", *p), L"123***");
}