From e8d1ba2293d724ea4d5e6878cf97c2eb0ad9b084 Mon Sep 17 00:00:00 2001 From: seleznevae Date: Tue, 27 Aug 2019 13:48:36 +0300 Subject: [PATCH] [A] Added tests for new table navigation functions --- docs/index.md | 2 ++ lib/fort.hpp | 18 +++++++++++ src/fort.hpp | 18 +++++++++++ tests/bb_tests_cpp/test_table_basic.cpp | 40 +++++++++++++++++++++++++ tests/main_test_cpp.cpp | 2 ++ 5 files changed, 80 insertions(+) diff --git a/docs/index.md b/docs/index.md index 84f362a..d249f0e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -50,6 +50,8 @@ These pages contain the API documentation of **libfort** - simple library to cre - @link fort::table @endlink -- basic table class - Table navigation - @link fort::table::set_cur_cell set_cur_cell @endlink -- set border style + - @link fort::table::cur_row cur_row @endlink -- get row number of the current cell + - @link fort::table::cur_col cur_col @endlink -- get column number of the current cell - Fill table with content - @link fort::table::operator<< operator<< @endlink -- write provided object to the table diff --git a/lib/fort.hpp b/lib/fort.hpp index 5276ea2..c3f8ddd 100644 --- a/lib/fort.hpp +++ b/lib/fort.hpp @@ -945,18 +945,36 @@ public: return (*this)[row_idx][col_idx]; } + /** + * Get column number of the current cell. + * + * @return + * Column number of the current cell. + */ size_t cur_col() { return ft_cur_col(table_); } + /** + * Get row number of the current cell. + * + * @return + * Row number of the current cell. + */ size_t cur_row() { return ft_cur_row(table_); } + /** + * Get current cell. + * + * @return + * Current cell. + */ class table_cell cur_cell() { diff --git a/src/fort.hpp b/src/fort.hpp index 5276ea2..c3f8ddd 100644 --- a/src/fort.hpp +++ b/src/fort.hpp @@ -945,18 +945,36 @@ public: return (*this)[row_idx][col_idx]; } + /** + * Get column number of the current cell. + * + * @return + * Column number of the current cell. + */ size_t cur_col() { return ft_cur_col(table_); } + /** + * Get row number of the current cell. + * + * @return + * Row number of the current cell. + */ size_t cur_row() { return ft_cur_row(table_); } + /** + * Get current cell. + * + * @return + * Current cell. + */ class table_cell cur_cell() { diff --git a/tests/bb_tests_cpp/test_table_basic.cpp b/tests/bb_tests_cpp/test_table_basic.cpp index 1b740e1..6bc7fa9 100644 --- a/tests/bb_tests_cpp/test_table_basic.cpp +++ b/tests/bb_tests_cpp/test_table_basic.cpp @@ -287,3 +287,43 @@ void test_cpp_table_write(void) assert_string_equal(table_str, table_str_etalon); } } + +void test_cpp_table_changing_cell(void) +{ + WHEN("All columns are equal and not empty") { + fort::table table; + assert_true(set_cpp_test_props_for_table(&table)); + + table << fort::header + << "3" << "c" << "234" << "3.140000" << fort::endr + << "3" << "c" << "234" << "3.140000" << fort::endr + << "3" << "c" << "234" << "3.140000" << fort::endr; + + assert_true(table.cur_row() == 3); + assert_true(table.cur_col() == 0); + + table.set_cur_cell(1, 1); + assert_true(table.cur_row() == 1); + assert_true(table.cur_col() == 1); + table << "A"; + assert_true(table.cur_row() == 1); + assert_true(table.cur_col() == 2); + + std::string table_str = table.to_string(); + std::string table_str_etalon = + "+---+---+-----+----------+\n" + "| | | | |\n" + "| 3 | c | 234 | 3.140000 |\n" + "| | | | |\n" + "+---+---+-----+----------+\n" + "| | | | |\n" + "| 3 | A | 234 | 3.140000 |\n" + "| | | | |\n" + "+---+---+-----+----------+\n" + "| | | | |\n" + "| 3 | c | 234 | 3.140000 |\n" + "| | | | |\n" + "+---+---+-----+----------+\n"; + assert_string_equal(table_str, table_str_etalon); + } +} diff --git a/tests/main_test_cpp.cpp b/tests/main_test_cpp.cpp index 4c38365..3b76aa6 100644 --- a/tests/main_test_cpp.cpp +++ b/tests/main_test_cpp.cpp @@ -5,6 +5,7 @@ /* Test cases */ void test_cpp_table_basic(void); void test_cpp_table_write(void); +void test_cpp_table_changing_cell(void); void test_cpp_table_tbl_properties(void); void test_cpp_table_cell_properties(void); void test_cpp_table_text_styles(void); @@ -14,6 +15,7 @@ void test_cpp_bug_fixes(void); struct test_case bb_test_suite [] = { {"test_cpp_table_basic", test_cpp_table_basic}, {"test_cpp_table_write", test_cpp_table_write}, + {"test_cpp_table_changing_cell", test_cpp_table_changing_cell}, {"test_cpp_table_tbl_properties", test_cpp_table_tbl_properties}, {"test_cpp_table_cell_properties", test_cpp_table_cell_properties}, {"test_cpp_table_text_styles", test_cpp_table_text_styles},