Add color format_to overloads

* Fix variable size basic_memory_buffer colorization
* Fix an unused arguments warning on GCC that blocks the CI otherwise
* Ref #1842
* Ref #1593
This commit is contained in:
Denis Blank
2020-08-30 21:48:49 +02:00
committed by Victor Zverovich
parent f19b8885f2
commit bff4d18efb
3 changed files with 56 additions and 4 deletions

View File

@@ -7,6 +7,10 @@
#include "fmt/color.h"
#include <iterator>
#include <string>
#include <utility>
#include "gtest-extra.h"
TEST(ColorsTest, ColorsPrint) {
@@ -84,3 +88,12 @@ TEST(ColorsTest, Format) {
EXPECT_EQ(fmt::format(fg(fmt::terminal_color::red), "{}", "foo"),
"\x1b[31mfoo\x1b[0m");
}
TEST(ColorsTest, FormatToOutAcceptsTextStyle) {
fmt::text_style const ts = fg(fmt::rgb(255, 20, 30));
std::string out;
fmt::format_to(std::back_inserter(out), ts, "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");
}

View File

@@ -145,7 +145,13 @@ std::string read(fmt::file& f, size_t count);
read(file, fmt::string_view(expected_content).size()))
#else
# define EXPECT_WRITE(file, statement, expected_output) SUCCEED()
# define EXPECT_WRITE(file, statement, expected_output) \
do { \
(void)(file); \
(void)(statement); \
(void)(expected_output); \
SUCCEED(); \
} while (false)
#endif // FMT_USE_FCNTL
template <typename Mock> struct ScopedMock : testing::StrictMock<Mock> {