Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
moshelooks committed Sep 19, 2024
1 parent ee6c02d commit 8efd718
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ add_fmt_test(base-test)
add_fmt_test(assert-test)
add_fmt_test(chrono-test)
add_fmt_test(color-test)
add_fmt_test(compile-color-test)
add_fmt_test(gtest-extra-test)
add_fmt_test(format-test mock-allocator.h)
if (MSVC)
Expand Down
37 changes: 37 additions & 0 deletions test/compile-color-test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Formatting library for C++ - color tests with compiled format strings
//
// Copyright (c) 2012 - present, Victor Zverovich
// All rights reserved.
//
// For the license information refer to format.h.

#include "fmt/compile-color.h"

#include <iterator> // std::back_inserter

#include "gtest-extra.h" // EXPECT_WRITE

TEST(compile_color_test, format) {
EXPECT_EQ(fmt::format(fmt::text_style(), FMT_COMPILE("hi")), "hi");
EXPECT_EQ(fmt::format(fmt::text_style(), FMT_COMPILE("{} {}"), "hi", "there"),
"hi there");

EXPECT_EQ(fmt::format(fg(fmt::terminal_color::red), FMT_COMPILE("{}"), "foo"),
"\x1b[31mfoo\x1b[0m");
EXPECT_EQ(fmt::format(fg(fmt::terminal_color::red), FMT_COMPILE("{} {}"),
"foo", 42),
"\x1b[31mfoo 42\x1b[0m");
}

TEST(compile_color_test, format_to) {
auto out = std::string();
fmt::format_to(std::back_inserter(out), fg(fmt::rgb(255, 20, 30)),
FMT_COMPILE("rgb(255,20,30){}{}{}"), 1, 2, 3);
EXPECT_EQ(fmt::to_string(out),
"\x1b[38;2;255;020;030mrgb(255,20,30)123\x1b[0m");
}

TEST(color_test, print) {
EXPECT_WRITE(stdout, fmt::print(fg(fmt::rgb(255, 20, 30)), "rgb(255,20,30)"),
"\x1b[38;2;255;020;030mrgb(255,20,30)\x1b[0m");
}

0 comments on commit 8efd718

Please sign in to comment.