[F] Fix ft_erase_range
behaviour with separators
This commit is contained in:
parent
5547d3abe2
commit
d8a9eaa77a
@ -2845,6 +2845,8 @@ int ft_erase_range(ft_table_t *table,
|
||||
++i;
|
||||
}
|
||||
|
||||
f_separator_t *separator = NULL;
|
||||
|
||||
size_t n_iterations = MIN(rows_n - 1, bottom_right_row) - top_left_row + 1;
|
||||
size_t j = 0;
|
||||
i = top_left_row;
|
||||
@ -2857,6 +2859,11 @@ int ft_erase_range(ft_table_t *table,
|
||||
status = vector_erase(table->rows, i);
|
||||
if (FT_IS_ERROR(status))
|
||||
return status;
|
||||
if (i < vector_size(table->separators)) {
|
||||
separator = VECTOR_AT(table->separators, i, f_separator_t *);
|
||||
destroy_separator(separator);
|
||||
vector_erase(table->separators, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -265,6 +265,8 @@ int ft_erase_range(ft_table_t *table,
|
||||
++i;
|
||||
}
|
||||
|
||||
f_separator_t *separator = NULL;
|
||||
|
||||
size_t n_iterations = MIN(rows_n - 1, bottom_right_row) - top_left_row + 1;
|
||||
size_t j = 0;
|
||||
i = top_left_row;
|
||||
@ -277,6 +279,11 @@ int ft_erase_range(ft_table_t *table,
|
||||
status = vector_erase(table->rows, i);
|
||||
if (FT_IS_ERROR(status))
|
||||
return status;
|
||||
if (i < vector_size(table->separators)) {
|
||||
separator = VECTOR_AT(table->separators, i, f_separator_t *);
|
||||
destroy_separator(separator);
|
||||
vector_erase(table->separators, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1932,4 +1932,34 @@ void test_table_erase(void)
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
WHEN("Erasion lines with separators") {
|
||||
ft_table_t *table = ft_create_table();
|
||||
assert_true(table != NULL);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_BOTTOM_PADDING, 0);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_TOP_PADDING, 0);
|
||||
|
||||
ft_write_ln(table, "00", "01", "02");
|
||||
ft_write_ln(table, "10", "11", "12");
|
||||
ft_add_separator(table);
|
||||
ft_write_ln(table, "20", "21", "22");
|
||||
ft_write_ln(table, "30", "31", "32");
|
||||
ft_add_separator(table);
|
||||
ft_write_ln(table, "40", "41", "42");
|
||||
|
||||
assert_true(FT_IS_SUCCESS(ft_erase_range(table, 1, 0, 2, 9999)));
|
||||
|
||||
const char *table_str = ft_to_string(table);
|
||||
assert_true(table_str != NULL);
|
||||
const char *table_str_etalon =
|
||||
"+----+----+----+\n"
|
||||
"| 00 | 01 | 02 |\n"
|
||||
"| 30 | 31 | 32 |\n"
|
||||
"+----+----+----+\n"
|
||||
"| 40 | 41 | 42 |\n"
|
||||
"+----+----+----+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user