From 6f4267cb3a3615ebaf1706b34d73d608eaf597b5 Mon Sep 17 00:00:00 2001 From: seleznevae Date: Fri, 9 Aug 2019 19:59:48 +0300 Subject: [PATCH] [F] Fix incorrect border style for the last line in the table --- ChangeLog.md | 1 + lib/fort.c | 2 ++ src/fort_impl.c | 2 ++ tests/bb_tests/test_table_basic.c | 40 +++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index bb68f5e..8e69998 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,6 +3,7 @@ ### Bug fixes - Changed specific style reset tags to universal reset style tag. +- Fix incorrect border style for the last line in the table. ## v0.1.5 diff --git a/lib/fort.c b/lib/fort.c index 4cf906a..eb41085 100644 --- a/lib/fort.c +++ b/lib/fort.c @@ -1817,6 +1817,7 @@ const char *ft_to_string(const ft_table_t *table) } cur_row = NULL; cur_sep = (i < sep_size) ? (*(separator_t **)vector_at(table->separators, i)) : NULL; + context.row = i; CHCK_RSLT_ADD_TO_WRITTEN(print_row_separator_(buffer + written, sz - written, col_width_arr, cols, prev_row, cur_row, BottomSeparator, cur_sep, &context)); /* Print bottom margin */ @@ -1920,6 +1921,7 @@ const wchar_t *ft_to_wstring(const ft_table_t *table) } cur_row = NULL; cur_sep = (i < sep_size) ? (*(separator_t **)vector_at(table->separators, i)) : NULL; + context.row = i; CHCK_RSLT_ADD_TO_WRITTEN(print_row_separator_(buffer + written, sz - written, col_width_arr, cols, prev_row, cur_row, BottomSeparator, cur_sep, &context)); /* Print bottom margin */ diff --git a/src/fort_impl.c b/src/fort_impl.c index 5ae2a40..dbc5255 100644 --- a/src/fort_impl.c +++ b/src/fort_impl.c @@ -656,6 +656,7 @@ const char *ft_to_string(const ft_table_t *table) } cur_row = NULL; cur_sep = (i < sep_size) ? (*(separator_t **)vector_at(table->separators, i)) : NULL; + context.row = i; CHCK_RSLT_ADD_TO_WRITTEN(print_row_separator_(buffer + written, sz - written, col_width_arr, cols, prev_row, cur_row, BottomSeparator, cur_sep, &context)); /* Print bottom margin */ @@ -759,6 +760,7 @@ const wchar_t *ft_to_wstring(const ft_table_t *table) } cur_row = NULL; cur_sep = (i < sep_size) ? (*(separator_t **)vector_at(table->separators, i)) : NULL; + context.row = i; CHCK_RSLT_ADD_TO_WRITTEN(print_row_separator_(buffer + written, sz - written, col_width_arr, cols, prev_row, cur_row, BottomSeparator, cur_sep, &context)); /* Print bottom margin */ diff --git a/tests/bb_tests/test_table_basic.c b/tests/bb_tests/test_table_basic.c index 7dde6be..a3484d6 100644 --- a/tests/bb_tests/test_table_basic.c +++ b/tests/bb_tests/test_table_basic.c @@ -84,6 +84,46 @@ void test_bug_fixes(void) ft_destroy_table(table); } + + SCENARIO("Issue 11 - https://github.com/seleznevae/libfort/issues/11") { + ft_table_t *table = ft_create_table(); + ft_set_border_style(table, FT_PLAIN_STYLE); + + ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER); + ft_write_ln(table, "1", "2"); + ft_write_ln(table, "3", "4"); + + const char *table_str = ft_to_string(table); + assert_true(table_str != NULL); + const char *table_str_etalon = + " ------- \n" + " 1 2 \n" + " ------- \n" + " 3 4 \n" + " \n"; + assert_str_equal(table_str, table_str_etalon); + } + +#ifdef FT_HAVE_WCHAR + SCENARIO("Issue 11 - https://github.com/seleznevae/libfort/issues/11 (wchar case)") { + ft_table_t *table = ft_create_table(); + ft_set_border_style(table, FT_PLAIN_STYLE); + + ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER); + ft_wwrite_ln(table, L"1", L"2"); + ft_wwrite_ln(table, L"3", L"4"); + + const wchar_t *table_str = ft_to_wstring(table); + assert_true(table_str != NULL); + const wchar_t *table_str_etalon = + L" ------- \n" + L" 1 2 \n" + L" ------- \n" + L" 3 4 \n" + L" \n"; + assert_wcs_equal(table_str, table_str_etalon); + } +#endif } #endif