[A] Added tests for new table navigation functions

This commit is contained in:
seleznevae 2019-08-27 13:48:36 +03:00
parent e6e7a08c0f
commit e8d1ba2293
5 changed files with 80 additions and 0 deletions

View File

@ -50,6 +50,8 @@ These pages contain the API documentation of **libfort** - simple library to cre
- @link fort::table @endlink -- basic table class - @link fort::table @endlink -- basic table class
- Table navigation - Table navigation
- @link fort::table::set_cur_cell set_cur_cell @endlink -- set border style - @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 - Fill table with content
- @link fort::table::operator<< operator<< @endlink -- write provided object to the table - @link fort::table::operator<< operator<< @endlink -- write provided object to the table

View File

@ -945,18 +945,36 @@ public:
return (*this)[row_idx][col_idx]; return (*this)[row_idx][col_idx];
} }
/**
* Get column number of the current cell.
*
* @return
* Column number of the current cell.
*/
size_t size_t
cur_col() cur_col()
{ {
return ft_cur_col(table_); return ft_cur_col(table_);
} }
/**
* Get row number of the current cell.
*
* @return
* Row number of the current cell.
*/
size_t size_t
cur_row() cur_row()
{ {
return ft_cur_row(table_); return ft_cur_row(table_);
} }
/**
* Get current cell.
*
* @return
* Current cell.
*/
class table_cell class table_cell
cur_cell() cur_cell()
{ {

View File

@ -945,18 +945,36 @@ public:
return (*this)[row_idx][col_idx]; return (*this)[row_idx][col_idx];
} }
/**
* Get column number of the current cell.
*
* @return
* Column number of the current cell.
*/
size_t size_t
cur_col() cur_col()
{ {
return ft_cur_col(table_); return ft_cur_col(table_);
} }
/**
* Get row number of the current cell.
*
* @return
* Row number of the current cell.
*/
size_t size_t
cur_row() cur_row()
{ {
return ft_cur_row(table_); return ft_cur_row(table_);
} }
/**
* Get current cell.
*
* @return
* Current cell.
*/
class table_cell class table_cell
cur_cell() cur_cell()
{ {

View File

@ -287,3 +287,43 @@ void test_cpp_table_write(void)
assert_string_equal(table_str, table_str_etalon); 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);
}
}

View File

@ -5,6 +5,7 @@
/* Test cases */ /* Test cases */
void test_cpp_table_basic(void); void test_cpp_table_basic(void);
void test_cpp_table_write(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_tbl_properties(void);
void test_cpp_table_cell_properties(void); void test_cpp_table_cell_properties(void);
void test_cpp_table_text_styles(void); void test_cpp_table_text_styles(void);
@ -14,6 +15,7 @@ void test_cpp_bug_fixes(void);
struct test_case bb_test_suite [] = { struct test_case bb_test_suite [] = {
{"test_cpp_table_basic", test_cpp_table_basic}, {"test_cpp_table_basic", test_cpp_table_basic},
{"test_cpp_table_write", test_cpp_table_write}, {"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_tbl_properties", test_cpp_table_tbl_properties},
{"test_cpp_table_cell_properties", test_cpp_table_cell_properties}, {"test_cpp_table_cell_properties", test_cpp_table_cell_properties},
{"test_cpp_table_text_styles", test_cpp_table_text_styles}, {"test_cpp_table_text_styles", test_cpp_table_text_styles},