-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathformat.cpp
More file actions
49 lines (40 loc) · 1.39 KB
/
format.cpp
File metadata and controls
49 lines (40 loc) · 1.39 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
#include "pch.h"
#ifdef __cpp_lib_format
import std;
import winrt.Windows.Foundation;
//
// These tests confirm that std::format and std::formatter specializations work
// correctly when consumed via modules. Mirrors test/test_cpp20/format.cpp.
//
using namespace winrt;
using namespace Windows::Foundation;
TEST_CASE("module_format_hstring")
{
hstring str = L"World";
REQUIRE(std::format(L"Hello {}", str) == L"Hello World");
}
TEST_CASE("module_format_IStringable")
{
// Uri implements IStringable — exercises the generated
// std::formatter<IStringable, wchar_t> specialization through modules.
Uri uri(L"https://example.com/path");
IStringable stringable = uri;
REQUIRE(std::format(L"Visit: {}", stringable) == L"Visit: https://example.com/path");
}
TEST_CASE("module_format_projected_class")
{
// Exercises the generated std::formatter<Uri, wchar_t> specialization
// (inherits from formatter<IStringable>) through modules.
Uri uri(L"https://example.com");
REQUIRE(std::format(L"URL: {}", uri) == L"URL: https://example.com/");
}
#if __cpp_lib_format >= 202207L
TEST_CASE("module_format_winrt_format")
{
// winrt::format helper (C++23 formattable concept)
std::wstring str = L"World";
REQUIRE(winrt::format(L"Hello {}", str) == L"Hello World");
REQUIRE(winrt::format(L"C++/WinRT #{:d}", 1) == L"C++/WinRT #1");
}
#endif
#endif // __cpp_lib_format