1 // Formatting library for C++ - formatting library tests
3 // Copyright (c) 2012 - present, Victor Zverovich
4 // All rights reserved.
6 // For the license information refer to format.h.
11 #define I 42 // simulate https://en.cppreference.com/w/c/numeric/complex/I
12 #include "fmt/chrono.h"
13 #include "fmt/color.h"
14 #include "fmt/format.h"
15 #include "fmt/ostream.h"
16 #include "fmt/ranges.h"
17 #include "fmt/xchar.h"
20 // Exercise the API to verify that everything we expect to can compile.
21 void test_format_api() {
22 (void)fmt::format(FMT_STRING("{}"), 42);
23 (void)fmt::format(FMT_STRING(L
"{}"), 42);
24 (void)fmt::format(FMT_STRING("noop"));
26 (void)fmt::to_string(42);
27 (void)fmt::to_wstring(42);
29 std::vector
<char> out
;
30 fmt::format_to(std::back_inserter(out
), FMT_STRING("{}"), 42);
33 fmt::format_to_n(buffer
, 3, FMT_STRING("{}"), 12345);
36 fmt::format_to_n(wbuffer
, 3, FMT_STRING(L
"{}"), 12345);
40 (void)fmt::format(FMT_STRING("{}"), std::chrono::seconds(42));
41 (void)fmt::format(FMT_STRING(L
"{}"), std::chrono::seconds(42));
44 void test_text_style() {
45 fmt::print(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)");
46 (void)fmt::format(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"),
49 fmt::text_style ts
= fg(fmt::rgb(255, 20, 30));
51 fmt::format_to(std::back_inserter(out
), ts
,
52 FMT_STRING("rgb(255,20,30){}{}{}"), 1, 2, 3);
56 std::vector
<char> hello
= {'h', 'e', 'l', 'l', 'o'};
57 (void)fmt::format(FMT_STRING("{}"), hello
);