]> git.proxmox.com Git - ceph.git/blob - ceph/src/fmt/test/enforce-checks-test.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / fmt / test / enforce-checks-test.cc
1 // Formatting library for C++ - formatting library tests
2 //
3 // Copyright (c) 2012 - present, Victor Zverovich
4 // All rights reserved.
5 //
6 // For the license information refer to format.h.
7
8 #include <iterator>
9 #include <vector>
10
11 #include "fmt/chrono.h"
12 #include "fmt/color.h"
13 #include "fmt/format.h"
14 #include "fmt/ostream.h"
15 #include "fmt/ranges.h"
16 #include "fmt/xchar.h"
17
18 // Exercise the API to verify that everything we expect to can compile.
19 void test_format_api() {
20 fmt::format(FMT_STRING("{}"), 42);
21 fmt::format(FMT_STRING(L"{}"), 42);
22 fmt::format(FMT_STRING("noop"));
23
24 fmt::to_string(42);
25 fmt::to_wstring(42);
26
27 std::vector<char> out;
28 fmt::format_to(std::back_inserter(out), FMT_STRING("{}"), 42);
29
30 char buffer[4];
31 fmt::format_to_n(buffer, 3, FMT_STRING("{}"), 12345);
32
33 wchar_t wbuffer[4];
34 fmt::format_to_n(wbuffer, 3, FMT_STRING(L"{}"), 12345);
35 }
36
37 void test_chrono() {
38 fmt::format(FMT_STRING("{}"), std::chrono::seconds(42));
39 fmt::format(FMT_STRING(L"{}"), std::chrono::seconds(42));
40 }
41
42 void test_text_style() {
43 fmt::print(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)");
44 fmt::format(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)");
45
46 fmt::text_style ts = fg(fmt::rgb(255, 20, 30));
47 std::string out;
48 fmt::format_to(std::back_inserter(out), ts,
49 FMT_STRING("rgb(255,20,30){}{}{}"), 1, 2, 3);
50 }
51
52 void test_range() {
53 std::vector<char> hello = {'h', 'e', 'l', 'l', 'o'};
54 fmt::format(FMT_STRING("{}"), hello);
55 }
56
57 int main() {
58 test_format_api();
59 test_chrono();
60 test_text_style();
61 test_range();
62 }