]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | // Formatting library for C++ - color 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 "fmt/color.h" | |
f67539c2 | 9 | |
20effc67 | 10 | #include <iterator> // std::back_inserter |
9f95a23c | 11 | |
20effc67 | 12 | #include "gtest-extra.h" // EXPECT_WRITE |
9f95a23c | 13 | |
20effc67 | 14 | TEST(color_test, format) { |
9f95a23c TL |
15 | EXPECT_EQ(fmt::format(fg(fmt::rgb(255, 20, 30)), "rgb(255,20,30)"), |
16 | "\x1b[38;2;255;020;030mrgb(255,20,30)\x1b[0m"); | |
17 | EXPECT_EQ(fmt::format(fg(fmt::color::blue), "blue"), | |
18 | "\x1b[38;2;000;000;255mblue\x1b[0m"); | |
19 | EXPECT_EQ( | |
20 | fmt::format(fg(fmt::color::blue) | bg(fmt::color::red), "two color"), | |
21 | "\x1b[38;2;000;000;255m\x1b[48;2;255;000;000mtwo color\x1b[0m"); | |
22 | EXPECT_EQ(fmt::format(fmt::emphasis::bold, "bold"), "\x1b[1mbold\x1b[0m"); | |
23 | EXPECT_EQ(fmt::format(fmt::emphasis::italic, "italic"), | |
24 | "\x1b[3mitalic\x1b[0m"); | |
25 | EXPECT_EQ(fmt::format(fmt::emphasis::underline, "underline"), | |
26 | "\x1b[4munderline\x1b[0m"); | |
27 | EXPECT_EQ(fmt::format(fmt::emphasis::strikethrough, "strikethrough"), | |
28 | "\x1b[9mstrikethrough\x1b[0m"); | |
29 | EXPECT_EQ( | |
30 | fmt::format(fg(fmt::color::blue) | fmt::emphasis::bold, "blue/bold"), | |
31 | "\x1b[1m\x1b[38;2;000;000;255mblue/bold\x1b[0m"); | |
32 | EXPECT_EQ(fmt::format(fmt::emphasis::bold, "bold error"), | |
33 | "\x1b[1mbold error\x1b[0m"); | |
34 | EXPECT_EQ(fmt::format(fg(fmt::color::blue), "blue log"), | |
35 | "\x1b[38;2;000;000;255mblue log\x1b[0m"); | |
36 | EXPECT_EQ(fmt::format(fmt::text_style(), "hi"), "hi"); | |
37 | EXPECT_EQ(fmt::format(fg(fmt::terminal_color::red), "tred"), | |
38 | "\x1b[31mtred\x1b[0m"); | |
39 | EXPECT_EQ(fmt::format(bg(fmt::terminal_color::cyan), "tcyan"), | |
40 | "\x1b[46mtcyan\x1b[0m"); | |
41 | EXPECT_EQ(fmt::format(fg(fmt::terminal_color::bright_green), "tbgreen"), | |
42 | "\x1b[92mtbgreen\x1b[0m"); | |
43 | EXPECT_EQ(fmt::format(bg(fmt::terminal_color::bright_magenta), "tbmagenta"), | |
44 | "\x1b[105mtbmagenta\x1b[0m"); | |
f67539c2 TL |
45 | EXPECT_EQ(fmt::format(fg(fmt::terminal_color::red), "{}", "foo"), |
46 | "\x1b[31mfoo\x1b[0m"); | |
9f95a23c | 47 | } |
20effc67 TL |
48 | |
49 | TEST(color_test, format_to) { | |
50 | auto out = std::string(); | |
51 | fmt::format_to(std::back_inserter(out), fg(fmt::rgb(255, 20, 30)), | |
52 | "rgb(255,20,30){}{}{}", 1, 2, 3); | |
53 | EXPECT_EQ(fmt::to_string(out), | |
54 | "\x1b[38;2;255;020;030mrgb(255,20,30)123\x1b[0m"); | |
55 | } | |
56 | ||
57 | TEST(color_test, print) { | |
58 | EXPECT_WRITE(stdout, fmt::print(fg(fmt::rgb(255, 20, 30)), "rgb(255,20,30)"), | |
59 | "\x1b[38;2;255;020;030mrgb(255,20,30)\x1b[0m"); | |
60 | } |