Files
YYCCommonplace/testbench/yycc/carton/tabulate.cpp

62 lines
1.8 KiB
C++
Raw Normal View History

2025-08-19 20:53:51 +08:00
#include <gtest/gtest.h>
#include <yycc.hpp>
#include <yycc/carton/tabulate.hpp>
2025-08-21 14:32:51 +08:00
#include <yycc/string/reinterpret.hpp>
#include <sstream>
2025-08-19 20:53:51 +08:00
#define TABULATE ::yycc::carton::tabulate
2025-08-21 14:32:51 +08:00
#define REINTERPRET ::yycc::string::reinterpret
2025-08-19 20:53:51 +08:00
namespace yycctest::carton::tabulate {
2025-08-21 14:32:51 +08:00
class CartonTabulate : public ::testing::Test {
protected:
CartonTabulate() : table(3u), ss() {
// setup basic data
table.set_prefix(u8"# ");
table.set_header({u8"中文1", u8"中文2", u8"中文3"});
table.set_bar(u8"===");
table.add_row({u8"a", u8"b", u8"c"});
}
~CartonTabulate() override = default;
void expected_print(const std::u8string_view& exp) {
ss.str("");
table.print(ss);
EXPECT_EQ(REINTERPRET::as_utf8_view(ss.view()), exp);
}
TABULATE::Tabulate table;
std::stringstream ss;
};
TEST_F(CartonTabulate, Full) {
table.show_header(true);
table.show_bar(true);
expected_print(u8"# 中文1 中文2 中文3 \n"
u8"# === === === \n"
u8"# a b c \n");
}
TEST_F(CartonTabulate, NoHeader) {
table.show_header(false);
table.show_bar(true);
expected_print(u8"# === === === \n"
u8"# a b c \n");
}
TEST_F(CartonTabulate, NoBar) {
table.show_header(true);
table.show_bar(false);
expected_print(u8"# 中文1 中文2 中文3 \n"
u8"# a b c \n");
}
TEST_F(CartonTabulate, OnlyData) {
table.show_header(false);
table.show_bar(false);
expected_print(u8"# a b c \n");
2025-08-19 20:53:51 +08:00
}
2025-08-21 14:32:51 +08:00
} // namespace yycctest::carton::tabulate