[C] Removed blank lines from SIMPLE_STYLE and PLAIN_STYLE

This commit is contained in:
seleznevae 2019-08-10 11:40:12 +03:00
parent 4d0cd8501b
commit c289503e0c
5 changed files with 189 additions and 86 deletions

View File

@ -2989,23 +2989,23 @@ fort_status_t set_default_cell_property(uint32_t property, int value)
#define SIMPLE_STYLE { \ #define SIMPLE_STYLE { \
/* border_chars */ \ /* border_chars */ \
{ \ { \
" ", " ", " ", " ", \
" ", " ", " ", \
"\0", "\0", "\0", "\0", \ "\0", "\0", "\0", "\0", \
" ", " ", " ", " ", \ "\0", " ", "\0", \
" ", " ", " ", " ", \ "\0", "\0", "\0", "\0", \
"\0", "\0", "\0", "\0", \
"\0", "\0", "\0", "\0", \
}, \ }, \
/* header_border_chars */ \ /* header_border_chars */ \
{ \ { \
" ", " ", " ", " ", \ "\0", "\0", "\0", "\0", \
" ", " ", " ", \ "\0", " ", "\0", \
" ", "-", " ", " ", \ "\0", "-", " ", "\0", \
" ", " ", " ", " ", \ "\0", " ", " ", "\0", \
" ", "-", " ", "-", \ " ", "-", " ", "-", \
}, \ }, \
/* separator_chars */ \ /* separator_chars */ \
{ \ { \
" ", "-", " ", " ", \ "\0", "-", " ", "\0", \
" ", " ", \ " ", " ", \
}, \ }, \
} }
@ -3013,23 +3013,23 @@ fort_status_t set_default_cell_property(uint32_t property, int value)
#define PLAIN_STYLE { \ #define PLAIN_STYLE { \
/* border_chars */ \ /* border_chars */ \
{ \ { \
" ", " ", " ", " ", \
" ", " ", " ", \
"\0", "\0", "\0", "\0", \ "\0", "\0", "\0", "\0", \
" ", " ", " ", " ", \ "\0", " ", "\0", \
" ", " ", " ", " ", \ "\0", "\0", "\0", "\0", \
"\0", "\0", "\0", "\0", \
"\0", "\0", "\0", "\0", \
}, \ }, \
/* header_border_chars */ \ /* header_border_chars */ \
{ \ { \
" ", "-", "-", " ", \ "\0", "-", "-", "\0", \
" ", " ", " ", \ "\0", " ", "\0", \
" ", "-", "-", " ", \ "\0", "-", "-", "\0", \
" ", "-", "-", " ", \ "\0", "-", "-", "\0", \
" ", "-", " ", "-", \ " ", "-", " ", "-", \
}, \ }, \
/* separator_chars */ \ /* separator_chars */ \
{ \ { \
" ", "-", "-", " ", \ "\0", "-", "-", "\0", \
"-", "-", \ "-", "-", \
}, \ }, \
} }

View File

@ -536,23 +536,23 @@ fort_status_t set_default_cell_property(uint32_t property, int value)
#define SIMPLE_STYLE { \ #define SIMPLE_STYLE { \
/* border_chars */ \ /* border_chars */ \
{ \ { \
" ", " ", " ", " ", \
" ", " ", " ", \
"\0", "\0", "\0", "\0", \ "\0", "\0", "\0", "\0", \
" ", " ", " ", " ", \ "\0", " ", "\0", \
" ", " ", " ", " ", \ "\0", "\0", "\0", "\0", \
"\0", "\0", "\0", "\0", \
"\0", "\0", "\0", "\0", \
}, \ }, \
/* header_border_chars */ \ /* header_border_chars */ \
{ \ { \
" ", " ", " ", " ", \ "\0", "\0", "\0", "\0", \
" ", " ", " ", \ "\0", " ", "\0", \
" ", "-", " ", " ", \ "\0", "-", " ", "\0", \
" ", " ", " ", " ", \ "\0", " ", " ", "\0", \
" ", "-", " ", "-", \ " ", "-", " ", "-", \
}, \ }, \
/* separator_chars */ \ /* separator_chars */ \
{ \ { \
" ", "-", " ", " ", \ "\0", "-", " ", "\0", \
" ", " ", \ " ", " ", \
}, \ }, \
} }
@ -560,23 +560,23 @@ fort_status_t set_default_cell_property(uint32_t property, int value)
#define PLAIN_STYLE { \ #define PLAIN_STYLE { \
/* border_chars */ \ /* border_chars */ \
{ \ { \
" ", " ", " ", " ", \
" ", " ", " ", \
"\0", "\0", "\0", "\0", \ "\0", "\0", "\0", "\0", \
" ", " ", " ", " ", \ "\0", " ", "\0", \
" ", " ", " ", " ", \ "\0", "\0", "\0", "\0", \
"\0", "\0", "\0", "\0", \
"\0", "\0", "\0", "\0", \
}, \ }, \
/* header_border_chars */ \ /* header_border_chars */ \
{ \ { \
" ", "-", "-", " ", \ "\0", "-", "-", "\0", \
" ", " ", " ", \ "\0", " ", "\0", \
" ", "-", "-", " ", \ "\0", "-", "-", "\0", \
" ", "-", "-", " ", \ "\0", "-", "-", "\0", \
" ", "-", " ", "-", \ " ", "-", " ", "-", \
}, \ }, \
/* separator_chars */ \ /* separator_chars */ \
{ \ { \
" ", "-", "-", " ", \ "\0", "-", "-", "\0", \
"-", "-", \ "-", "-", \
}, \ }, \
} }

View File

@ -97,11 +97,10 @@ void test_bug_fixes(void)
const char *table_str = ft_to_string(table); const char *table_str = ft_to_string(table);
assert_true(table_str != NULL); assert_true(table_str != NULL);
const char *table_str_etalon = const char *table_str_etalon =
" ------- \n" "-------\n"
" 1 2 \n" " 1 2 \n"
" ------- \n" "-------\n"
" 3 4 \n" " 3 4 \n";
" \n";
assert_str_equal(table_str, table_str_etalon); assert_str_equal(table_str, table_str_etalon);
ft_destroy_table(table); ft_destroy_table(table);
} }
@ -118,11 +117,10 @@ void test_bug_fixes(void)
const wchar_t *table_str = ft_to_wstring(table); const wchar_t *table_str = ft_to_wstring(table);
assert_true(table_str != NULL); assert_true(table_str != NULL);
const wchar_t *table_str_etalon = const wchar_t *table_str_etalon =
L" ------- \n" L"-------\n"
L" 1 2 \n" L" 1 2 \n"
L" ------- \n" L"-------\n"
L" 3 4 \n" L" 3 4 \n";
L" \n";
assert_wcs_equal(table_str, table_str_etalon); assert_wcs_equal(table_str, table_str_etalon);
ft_destroy_table(table); ft_destroy_table(table);
} }

View File

@ -190,6 +190,15 @@ void test_table_border_style(void)
} }
} }
static ft_table_t *create_simple_table(void)
{
ft_table_t *table = ft_create_table();
ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);
ft_write_ln(table, "111", "22");
ft_write_ln(table, "3", "4444");
return table;
}
static ft_table_t *create_basic_table(void) static ft_table_t *create_basic_table(void)
{ {
@ -209,6 +218,31 @@ static ft_table_t *create_basic_table(void)
return table; return table;
} }
static ft_table_t *create_complex_table(void)
{
ft_table_t *table = ft_create_table();
ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
ft_set_cell_prop(table, 1, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
ft_set_cell_prop(table, 2, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
ft_write_ln(table, "Rank", "Title", "Year", "Rating");
ft_write_ln(table, "Rank", "Title", "Year", "Rating");
ft_write_ln(table, "Rank", "Title", "Year", "Rating");
ft_set_cell_span(table, 1, 1, 2);
ft_write_ln(table, "1", "The Shawshank Redemption", "1994", "9.5");
ft_set_cell_span(table, 3, 2, 2);
ft_write_ln(table, "2", "12 Angry Men", "1957", "8.8");
ft_write_ln(table, "3", "It's a Wonderful Life", "1946", "8.6");
ft_set_cell_span(table, 4, 1, 2);
ft_add_separator(table);
ft_write_ln(table, "4", "2001: A Space Odyssey", "1968", "8.5");
ft_write_ln(table, "5", "Blade Runner", "1982", "8.1");
return table;
}
#ifdef FT_HAVE_WCHAR #ifdef FT_HAVE_WCHAR
static ft_table_t *create_basic_wtable(void) static ft_table_t *create_basic_wtable(void)
{ {
@ -229,6 +263,20 @@ static ft_table_t *create_basic_wtable(void)
} }
#endif #endif
static void test_table_style(const char *case_description,
ft_table_t *(*constructor)(void),
const struct ft_border_style *style,
const char *str_expected)
{
ft_table_t *table = constructor();
assert_true(table);
assert(ft_set_border_style(table, style) == 0);
const char *table_str = ft_to_string(table);
assert_true(table_str != NULL);
d_assert_str_equal(case_description, table_str, str_expected);
ft_destroy_table(table);
}
void test_table_builtin_border_styles(void) void test_table_builtin_border_styles(void)
{ {
ft_table_t *table = NULL; ft_table_t *table = NULL;
@ -286,45 +334,71 @@ void test_table_builtin_border_styles(void)
/* *************************************************************** */ /* *************************************************************** */
ft_set_default_border_style(FT_SIMPLE_STYLE); test_table_style("FT_SIMPLE_STYLE (simple layout)",
table = create_basic_table(); create_simple_table, FT_SIMPLE_STYLE,
table_str = ft_to_string(table); " 111 22 \n"
assert_true(table_str != NULL); " 3 4444 \n");
table_str_etalon = test_table_style("FT_SIMPLE_STYLE (ordinary layout)",
" \n" create_basic_table, FT_SIMPLE_STYLE,
" Rank Title Year Rating \n" " Rank Title Year Rating \n"
" ------ -------------------------- ------ -------- \n" "------ -------------------------- ------ --------\n"
" 1 The Shawshank Redemption 1994 9.5 \n" " 1 The Shawshank Redemption 1994 9.5 \n"
" 2 12 Angry Men 1957 8.8 \n" " 2 12 Angry Men 1957 8.8 \n"
" 3 It's a Wonderful Life 1946 8.6 \n" " 3 It's a Wonderful Life 1946 8.6 \n"
" ------ -------------------------- ------ -------- \n" "------ -------------------------- ------ --------\n"
" 4 2001: A Space Odyssey 1968 8.5 \n" " 4 2001: A Space Odyssey 1968 8.5 \n"
" 5 Blade Runner 1982 8.1 \n" " 5 Blade Runner 1982 8.1 \n");
" \n";
assert_str_equal(table_str, table_str_etalon); test_table_style("FT_SIMPLE_STYLE (complex layout)",
ft_destroy_table(table); create_complex_table, FT_SIMPLE_STYLE,
" Rank Title Year Rating \n"
"------ --------------------------------- --------\n"
" Rank Title Rating \n"
"------ --------------------------------- --------\n"
" Rank Title Year Rating \n"
"------ -------------------------- ---------------\n"
" 1 The Shawshank Redemption 1994 \n"
" 2 12 Angry Men 8.8 \n"
" 3 It's a Wonderful Life 1946 8.6 \n"
"------ -------------------------- ------ --------\n"
" 4 2001: A Space Odyssey 1968 8.5 \n"
" 5 Blade Runner 1982 8.1 \n");
/* *************************************************************** */ /* *************************************************************** */
ft_set_default_border_style(FT_PLAIN_STYLE); test_table_style("FT_PLAIN_STYLE (simple layout)",
table = create_basic_table(); create_simple_table, FT_PLAIN_STYLE,
table_str = ft_to_string(table); " 111 22 \n"
assert_true(table_str != NULL); " 3 4444 \n");
table_str_etalon = test_table_style("FT_PLAIN_STYLE (ordinary layout)",
" ------------------------------------------------- \n" create_basic_table, FT_PLAIN_STYLE,
"-------------------------------------------------\n"
" Rank Title Year Rating \n" " Rank Title Year Rating \n"
" ------------------------------------------------- \n" "-------------------------------------------------\n"
" 1 The Shawshank Redemption 1994 9.5 \n" " 1 The Shawshank Redemption 1994 9.5 \n"
" 2 12 Angry Men 1957 8.8 \n" " 2 12 Angry Men 1957 8.8 \n"
" 3 It's a Wonderful Life 1946 8.6 \n" " 3 It's a Wonderful Life 1946 8.6 \n"
" ------------------------------------------------- \n" "-------------------------------------------------\n"
" 4 2001: A Space Odyssey 1968 8.5 \n" " 4 2001: A Space Odyssey 1968 8.5 \n"
" 5 Blade Runner 1982 8.1 \n" " 5 Blade Runner 1982 8.1 \n");
" \n";
assert_str_equal(table_str, table_str_etalon); test_table_style("FT_PLAIN_STYLE (complex layout)",
ft_destroy_table(table); create_complex_table, FT_PLAIN_STYLE,
"-------------------------------------------------\n"
" Rank Title Year Rating \n"
"-------------------------------------------------\n"
" Rank Title Rating \n"
"-------------------------------------------------\n"
" Rank Title Year Rating \n"
"-------------------------------------------------\n"
" 1 The Shawshank Redemption 1994 \n"
" 2 12 Angry Men 8.8 \n"
" 3 It's a Wonderful Life 1946 8.6 \n"
"-------------------------------------------------\n"
" 4 2001: A Space Odyssey 1968 8.5 \n"
" 5 Blade Runner 1982 8.1 \n");
/* *************************************************************** */ /* *************************************************************** */
@ -496,6 +570,34 @@ void test_table_builtin_border_styles(void)
ft_destroy_table(table); ft_destroy_table(table);
#endif #endif
WHEN("FT_DOUBLE2_STYLE - complex layout") {
ft_set_default_border_style(FT_DOUBLE2_STYLE);
table = create_complex_table();
table_str = ft_to_string(table);
assert_true(table_str != NULL);
table_str_etalon =
"╔══════╤══════════════════════════╤══════╤════════╗\n"
"║ Rank │ Title │ Year │ Rating ║\n"
"╠══════╪══════════════════════════╧══════╪════════╣\n"
"║ Rank │ Title │ Rating ║\n"
"╠══════╪══════════════════════════╤══════╪════════╣\n"
"║ Rank │ Title │ Year │ Rating ║\n"
"╠══════╪══════════════════════════╪══════╧════════╣\n"
"║ 1 │ The Shawshank Redemption │ 1994 ║\n"
"╟──────┼──────────────────────────┴──────┬────────╢\n"
"║ 2 │ 12 Angry Men │ 8.8 ║\n"
"╟──────┼──────────────────────────┬──────┼────────╢\n"
"║ 3 │ It's a Wonderful Life │ 1946 │ 8.6 ║\n"
"╠══════╪══════════════════════════╪══════╪════════╣\n"
"║ 4 │ 2001: A Space Odyssey │ 1968 │ 8.5 ║\n"
"╟──────┼──────────────────────────┼──────┼────────╢\n"
"║ 5 │ Blade Runner │ 1982 │ 8.1 ║\n"
"╚══════╧══════════════════════════╧══════╧════════╝\n";
assert_str_equal(table_str, table_str_etalon);
ft_destroy_table(table);
}
/* *************************************************************** */ /* *************************************************************** */
ft_set_default_border_style(FT_BOLD_STYLE); ft_set_default_border_style(FT_BOLD_STYLE);

View File

@ -29,15 +29,18 @@ struct test_case {
#define assert_true(args) assert(args) #define assert_true(args) assert(args)
#define assert_str_equal(str1, str2) \ #define d_assert_str_equal(description, str1, str2) \
if (strcmp(str1, str2) != 0) \ if (strcmp(str1, str2) != 0) \
{ \ { \
fprintf(stderr, "%s:%d(%s):Abort! Not equals strings:\n",__FILE__,__LINE__, __func__); \ fprintf(stderr, "%s:%d(%s):Abort! %s failed. Not equals strings:\n",__FILE__,__LINE__, __func__, description); \
fprintf(stderr, "Left string(len = %d):\n%s\n", (int)strlen(str1), str1); \ fprintf(stderr, "Left string(len = %d):\n%s\n", (int)strlen(str1), str1); \
fprintf(stderr, "Right string(len = %d):\n%s\n", (int)strlen(str2), str2); \ fprintf(stderr, "Right string(len = %d):\n%s\n", (int)strlen(str2), str2); \
exit(EXIT_FAILURE); \ exit(EXIT_FAILURE); \
} }
#define assert_str_equal(str1, str2) \
d_assert_str_equal("Test", str1, str2)
#define assert_wcs_equal(str1, str2) \ #define assert_wcs_equal(str1, str2) \
if (wcscmp(str1, str2) != 0) \ if (wcscmp(str1, str2) != 0) \
{ \ { \