- add termcolor and its testbench - add integer() in flag_enum and update its testbench according to the requirements in termcolor.
45 lines
1.6 KiB
C++
45 lines
1.6 KiB
C++
#include <gtest/gtest.h>
|
|
#include <yycc.hpp>
|
|
#include <yycc/carton/termcolor.hpp>
|
|
#include <yycc/flag_enum.hpp>
|
|
|
|
#define TERMCOLOR ::yycc::carton::termcolor
|
|
#define FLAG_ENUM ::yycc::flag_enum
|
|
|
|
using namespace std::literals::string_view_literals;
|
|
using Color = TERMCOLOR::Color;
|
|
using Attribute = TERMCOLOR::Attribute;
|
|
|
|
namespace yycctest::carton::termcolor {
|
|
|
|
TEST(CartonTermcolor, Lowlevel) {
|
|
EXPECT_EQ(TERMCOLOR::foreground(Color::Default), u8"");
|
|
EXPECT_EQ(TERMCOLOR::foreground(Color::Red), u8"\033[31m");
|
|
EXPECT_EQ(TERMCOLOR::foreground(Color::LightRed), u8"\033[91m");
|
|
|
|
EXPECT_EQ(TERMCOLOR::background(Color::Default), u8"");
|
|
EXPECT_EQ(TERMCOLOR::background(Color::Red), u8"\033[41m");
|
|
EXPECT_EQ(TERMCOLOR::background(Color::LightRed), u8"\033[101m");
|
|
|
|
EXPECT_EQ(TERMCOLOR::style(Attribute::Default), u8"");
|
|
EXPECT_EQ(TERMCOLOR::style(Attribute::Italic), u8"\033[3m");
|
|
EXPECT_EQ(TERMCOLOR::styles(FLAG_ENUM::merge(Attribute::Italic, Attribute::Bold)),
|
|
u8"\033[1m"
|
|
"\033[3m");
|
|
|
|
EXPECT_EQ(TERMCOLOR::reset(), u8"\033[0m"sv);
|
|
}
|
|
|
|
TEST(CartonTermcolor, Highlevel) {
|
|
EXPECT_EQ(TERMCOLOR::colored(u8"hello"sv), u8"hello\033[0m");
|
|
EXPECT_EQ(TERMCOLOR::colored(u8"hello"sv, Color::LightWhite, Color::Red, FLAG_ENUM::merge(Attribute::Italic, Attribute::Bold)),
|
|
u8"\033[97m"
|
|
"\033[41m"
|
|
"\033[1m"
|
|
"\033[3m"
|
|
"hello"
|
|
"\033[0m");
|
|
}
|
|
|
|
} // namespace yycctest::carton::termcolor
|