diff options
-rw-r--r-- | src/util/TextTable.cpp | 3 | ||||
-rw-r--r-- | unittest/test_util_TextTable.cpp | 6 |
2 files changed, 9 insertions, 0 deletions
diff --git a/src/util/TextTable.cpp b/src/util/TextTable.cpp index 618f7b7b..53014aa4 100644 --- a/src/util/TextTable.cpp +++ b/src/util/TextTable.cpp @@ -32,6 +32,7 @@ TextTable::add_heading(const std::string& text) Cell cell(text); cell.m_heading = true; m_rows.push_back({cell}); + m_columns = std::max(m_columns, size_t(1)); } void @@ -86,6 +87,8 @@ TextTable::render() const std::string result; for (const auto& row : m_rows) { + ASSERT(column_widths.size() >= row.size()); + std::string r; bool first = true; for (size_t i = 0; i < row.size(); ++i) { diff --git a/unittest/test_util_TextTable.cpp b/unittest/test_util_TextTable.cpp index 36240731..1a996c04 100644 --- a/unittest/test_util_TextTable.cpp +++ b/unittest/test_util_TextTable.cpp @@ -33,6 +33,12 @@ TEST_CASE("TextTable") CHECK(table.render() == ""); } + SUBCASE("only a heading") + { + table.add_heading("heading"); + CHECK(table.render() == "heading\n"); + } + SUBCASE("1x1") { table.add_row({"a"}); |