|
2 | 2 |
|
3 | 3 | #include <iris/colorize_format.hpp> |
4 | 4 |
|
| 5 | +// TODO: `checking_scanner` leads to GCC ICE only on constexpr context |
| 6 | +#if defined(__GNUC__) && !defined(__clang__) |
| 7 | +# define IRIS_CONSTEXPR_WORKAROUND |
| 8 | +#else |
| 9 | +# define IRIS_CONSTEXPR_WORKAROUND constexpr |
| 10 | +#endif |
| 11 | + |
5 | 12 | TEST_CASE("colorized_string") |
6 | 13 | { |
7 | | - { |
8 | | - constexpr auto test = [](iris::ansi_colorize::colorized_string_view) {}; |
9 | | - test("foo"); |
10 | | - test("[reset]"); |
11 | | - test("[fg:reset]"); |
12 | | - test("[bg:reset]"); |
13 | | - test("[black]"); |
14 | | - test("[red]"); |
15 | | - test("[green]"); |
16 | | - test("[yellow]"); |
17 | | - test("[blue]"); |
18 | | - test("[magenta]"); |
19 | | - test("[cyan]"); |
20 | | - test("[white]"); |
21 | | - test("[red|bold]"); |
22 | | - test("[bold|italic]"); |
23 | | - test("[fg:red|bg:blue]"); |
24 | | - } |
| 14 | + { [[maybe_unused]] IRIS_CONSTEXPR_WORKAROUND iris::ansi_colorize::colorized_string_view sv("foo"); } |
| 15 | + { [[maybe_unused]] IRIS_CONSTEXPR_WORKAROUND iris::ansi_colorize::colorized_string_view sv("[reset]"); } |
| 16 | + { [[maybe_unused]] IRIS_CONSTEXPR_WORKAROUND iris::ansi_colorize::colorized_string_view sv("[fg:reset]"); } |
| 17 | + { [[maybe_unused]] IRIS_CONSTEXPR_WORKAROUND iris::ansi_colorize::colorized_string_view sv("[bg:reset]"); } |
| 18 | + { [[maybe_unused]] IRIS_CONSTEXPR_WORKAROUND iris::ansi_colorize::colorized_string_view sv("[black]"); } |
| 19 | + { [[maybe_unused]] IRIS_CONSTEXPR_WORKAROUND iris::ansi_colorize::colorized_string_view sv("[red]"); } |
| 20 | + { [[maybe_unused]] IRIS_CONSTEXPR_WORKAROUND iris::ansi_colorize::colorized_string_view sv("[green]"); } |
| 21 | + { [[maybe_unused]] IRIS_CONSTEXPR_WORKAROUND iris::ansi_colorize::colorized_string_view sv("[yellow]"); } |
| 22 | + { [[maybe_unused]] IRIS_CONSTEXPR_WORKAROUND iris::ansi_colorize::colorized_string_view sv("[blue]"); } |
| 23 | + { [[maybe_unused]] IRIS_CONSTEXPR_WORKAROUND iris::ansi_colorize::colorized_string_view sv("[magenta]"); } |
| 24 | + { [[maybe_unused]] IRIS_CONSTEXPR_WORKAROUND iris::ansi_colorize::colorized_string_view sv("[cyan]"); } |
| 25 | + { [[maybe_unused]] IRIS_CONSTEXPR_WORKAROUND iris::ansi_colorize::colorized_string_view sv("[white]"); } |
| 26 | + { [[maybe_unused]] IRIS_CONSTEXPR_WORKAROUND iris::ansi_colorize::colorized_string_view sv("[red|bold]"); } |
| 27 | + { [[maybe_unused]] IRIS_CONSTEXPR_WORKAROUND iris::ansi_colorize::colorized_string_view sv("[bold|italic]"); } |
| 28 | + { [[maybe_unused]] IRIS_CONSTEXPR_WORKAROUND iris::ansi_colorize::colorized_string_view sv("[fg:red|bg:blue]"); } |
25 | 29 |
|
26 | 30 | CHECK_THROWS_AS((void)iris::colorize(iris::dynamic_colorize("[]")), iris::colorize_error); |
27 | 31 | CHECK_THROWS_AS((void)iris::colorize(iris::dynamic_colorize("[")), iris::colorize_error); |
28 | 32 | CHECK_THROWS_AS((void)iris::colorize(iris::dynamic_colorize("]")), iris::colorize_error); |
29 | 33 | CHECK_THROWS_AS((void)iris::colorize(iris::dynamic_colorize("[reset|red]")), iris::colorize_error); |
30 | 34 | CHECK_THROWS_AS((void)iris::colorize(iris::dynamic_colorize("[red|reset]")), iris::colorize_error); |
31 | 35 | CHECK_THROWS_AS((void)iris::colorize(iris::dynamic_colorize("[black|red]")), iris::colorize_error); |
32 | | -} |
33 | 36 |
|
34 | | -TEST_CASE("colorized_format_string") |
35 | | -{ |
36 | | - { |
37 | | - constexpr auto test = [](iris::ansi_colorize::colorized_format_string<>) {}; |
38 | | - test("foo"); |
39 | | - test("[reset]"); |
40 | | - test("[fg:reset]"); |
41 | | - test("[bg:reset]"); |
42 | | - test("[black]"); |
43 | | - test("[red]"); |
44 | | - test("[green]"); |
45 | | - test("[yellow]"); |
46 | | - test("[blue]"); |
47 | | - test("[magenta]"); |
48 | | - test("[cyan]"); |
49 | | - test("[white]"); |
50 | | - test("[red|bold]"); |
51 | | - test("[bold|italic]"); |
52 | | - test("[fg:red|bg:blue]"); |
53 | | - } |
| 37 | + // These can only be constexpr because `std::format_string` is consteval |
| 38 | +#if !(defined(__GNUC__) && !defined(__clang__)) |
| 39 | + { [[maybe_unused]] constexpr iris::ansi_colorize::colorized_format_string<> fmt("foo"); } |
| 40 | + { [[maybe_unused]] constexpr iris::ansi_colorize::colorized_format_string<> fmt("[reset]"); } |
| 41 | + { [[maybe_unused]] constexpr iris::ansi_colorize::colorized_format_string<> fmt("[fg:reset]"); } |
| 42 | + { [[maybe_unused]] constexpr iris::ansi_colorize::colorized_format_string<> fmt("[bg:reset]"); } |
| 43 | + { [[maybe_unused]] constexpr iris::ansi_colorize::colorized_format_string<> fmt("[black]"); } |
| 44 | + { [[maybe_unused]] constexpr iris::ansi_colorize::colorized_format_string<> fmt("[red]"); } |
| 45 | + { [[maybe_unused]] constexpr iris::ansi_colorize::colorized_format_string<> fmt("[green]"); } |
| 46 | + { [[maybe_unused]] constexpr iris::ansi_colorize::colorized_format_string<> fmt("[yellow]"); } |
| 47 | + { [[maybe_unused]] constexpr iris::ansi_colorize::colorized_format_string<> fmt("[blue]"); } |
| 48 | + { [[maybe_unused]] constexpr iris::ansi_colorize::colorized_format_string<> fmt("[magenta]"); } |
| 49 | + { [[maybe_unused]] constexpr iris::ansi_colorize::colorized_format_string<> fmt("[cyan]"); } |
| 50 | + { [[maybe_unused]] constexpr iris::ansi_colorize::colorized_format_string<> fmt("[white]"); } |
| 51 | + { [[maybe_unused]] constexpr iris::ansi_colorize::colorized_format_string<> fmt("[red|bold]"); } |
| 52 | + { [[maybe_unused]] constexpr iris::ansi_colorize::colorized_format_string<> fmt("[bold|italic]"); } |
| 53 | + { [[maybe_unused]] constexpr iris::ansi_colorize::colorized_format_string<> fmt("[fg:red|bg:blue]"); } |
| 54 | +#endif |
54 | 55 | } |
| 56 | +#undef IRIS_CONSTEXPR_WORKAROUND |
55 | 57 |
|
56 | 58 | TEST_CASE("colorize") |
57 | 59 | { |
@@ -140,11 +142,11 @@ TEST_CASE("colorize_format") |
140 | 142 | auto const s = iris::colorize_format("[red]{}", 42); |
141 | 143 | CHECK(s == "\033[38;2;255;0;0m42"); |
142 | 144 | } |
143 | | - { |
144 | | - std::string s; |
145 | | - iris::colorize_format_to(std::back_inserter(s), "[red]{}", 42); |
146 | | - CHECK(s == "\033[38;2;255;0;0m42"); |
147 | | - } |
| 145 | + //{ |
| 146 | + // std::string s; |
| 147 | + // iris::colorize_format_to(std::back_inserter(s), "[red]{}", 42); |
| 148 | + // CHECK(s == "\033[38;2;255;0;0m42"); |
| 149 | + //} |
148 | 150 | } |
149 | 151 |
|
150 | 152 | #if defined(__clang__) || _MSC_VER >= 1950 /* VS 2026 */ |
|
0 commit comments