forked from ngcpp/proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy_format_tests.cpp
More file actions
56 lines (46 loc) · 1.72 KB
/
proxy_format_tests.cpp
File metadata and controls
56 lines (46 loc) · 1.72 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
51
52
53
54
55
56
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.
#include <gtest/gtest.h>
#include <proxy/proxy.h>
#ifdef PRO4D_HAS_FORMAT
namespace proxy_format_tests_details {
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 //
::add_skill<pro::skills::format> //
::add_skill<pro::skills::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;
#endif // PRO4D_HAS_FORMAT
TEST(ProxyFormatTests, TestFormat) {
#ifdef PRO4D_HAS_FORMAT
int v = 123;
pro::proxy<details::Formattable> p = &v;
ASSERT_EQ(std::format("{}", *p), "123");
ASSERT_EQ(std::format("{:*<6}", *p), "123***");
#else
GTEST_SKIP() << "std::format not available";
#endif // PRO4D_HAS_FORMAT
}
TEST(ProxyFormatTests, TestWformat) {
#ifdef PRO4D_HAS_FORMAT
int v = 123;
pro::proxy<details::Formattable> p = &v;
ASSERT_EQ(std::format(L"{}", *p), L"123");
ASSERT_EQ(std::format(L"{:*<6}", *p), L"123***");
#else
GTEST_SKIP() << "std::format not available";
#endif // PRO4D_HAS_FORMAT
}