[F] Fixed logic errors with cell options

This commit is contained in:
seleznevae
2018-11-03 12:41:58 +03:00
parent 78db8dd788
commit 68fbe947b4
9 changed files with 133 additions and 41 deletions

View File

@@ -68,40 +68,6 @@ void test_table_basic(void)
}
#endif
WHEN("Test table copy") {
table = ft_create_table();
assert_true(table != NULL);
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
ft_table_t *table_copy = ft_copy_table(table);
assert_true(table != NULL);
const char *table_str = ft_to_string(table_copy);
assert_true(table_str != NULL);
const char *table_str_etalon =
"+---+---+-----+----------+\n"
"| | | | |\n"
"| 3 | c | 234 | 3.140000 |\n"
"| | | | |\n"
"+---+---+-----+----------+\n"
"| | | | |\n"
"| 3 | c | 234 | 3.140000 |\n"
"| | | | |\n"
"+---+---+-----+----------+\n"
"| | | | |\n"
"| 3 | c | 234 | 3.140000 |\n"
"| | | | |\n"
"+---+---+-----+----------+\n";
assert_str_equal(table_str, table_str_etalon);
ft_destroy_table(table);
ft_destroy_table(table_copy);
}
WHEN("All columns are not equal and not empty") {
table = ft_create_table();
assert_true(table != NULL);
@@ -815,3 +781,67 @@ void test_table_write(void)
#endif
}
void test_table_copy(void)
{
ft_table_t *table = NULL;
WHEN("Test table copy") {
table = ft_create_table();
assert_true(table != NULL);
assert_true(ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_BOTTOM_PADDING, 1) == FT_SUCCESS);
assert_true(ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_TOP_PADDING, 1) == FT_SUCCESS);
assert_true(ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_LEFT_PADDING, 2) == FT_SUCCESS);
assert_true(ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_RIGHT_PADDING, 2) == FT_SUCCESS);
ft_set_border_style(table, FT_DOUBLE2_STYLE);
/* Set "header" type for the first row */
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
ft_write_ln(table, "Movie title", "Director", "Year", "Rating");
ft_write_ln(table, "The Shawshank Redemption", "Frank Darabont", "1994", "9.5");
ft_write_ln(table, "The Godfather", "Francis Ford Coppola", "1972", "9.2");
ft_add_separator(table);
ft_write_ln(table, "2001: A Space Odyssey", "Stanley Kubrick", "1968", "8.5");
/* Set center alignment for the 1st and 3rd columns */
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
ft_set_cell_option(table, FT_ANY_ROW, 3, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
ft_table_t *table_copy = ft_copy_table(table);
assert_true(table != NULL);
const char *table_str = ft_to_string(table_copy);
assert_true(table_str != NULL);
const char *table_str_etalon =
"╔════════════════════════════╤════════════════════════╤════════╤══════════╗\n"
"║ │ │ │ ║\n"
"║ Movie title │ Director │ Year │ Rating ║\n"
"║ │ │ │ ║\n"
"╠════════════════════════════╪════════════════════════╪════════╪══════════╣\n"
"║ │ │ │ ║\n"
"║ The Shawshank Redemption │ Frank Darabont │ 1994 │ 9.5 ║\n"
"║ │ │ │ ║\n"
"╟────────────────────────────┼────────────────────────┼────────┼──────────╢\n"
"║ │ │ │ ║\n"
"║ The Godfather │ Francis Ford Coppola │ 1972 │ 9.2 ║\n"
"║ │ │ │ ║\n"
"╠════════════════════════════╪════════════════════════╪════════╪══════════╣\n"
"║ │ │ │ ║\n"
"║ 2001: A Space Odyssey │ Stanley Kubrick │ 1968 │ 8.5 ║\n"
"║ │ │ │ ║\n"
"╚════════════════════════════╧════════════════════════╧════════╧══════════╝\n";
assert_str_equal(table_str, table_str_etalon);
ft_destroy_table(table);
ft_destroy_table(table_copy);
}
}

View File

@@ -74,7 +74,11 @@ void test_cpp_table_basic(void)
fort::Table table3;
table3 = std::move(table2);
std::string table_str = table3.to_string();
fort::Table table4(table3);
fort::Table table5;
table5 = table4;
std::string table_str = table5.to_string();
std::string table_str_etalon =
"+---+---+-----+----------+\n"
"| | | | |\n"

View File

@@ -9,6 +9,7 @@ struct test_case wb_test_suit [] = {
{"test_string_buffer", test_string_buffer},
{"test_table_sizes", test_table_sizes},
{"test_table_geometry", test_table_geometry},
{"test_table_copy", test_table_copy},
};
#endif

View File

@@ -25,6 +25,7 @@ void test_string_buffer(void);
void test_table_sizes(void);
void test_table_geometry(void);
void test_table_basic(void);
void test_table_copy(void);
#ifdef FT_HAVE_WCHAR
void test_wcs_table_boundaries(void);
#endif