2018-07-26 21:25:22 +02:00
|
|
|
#include "tests.h"
|
|
|
|
#include "fort.hpp"
|
2018-11-24 21:14:26 +01:00
|
|
|
#include "test_utils.hpp"
|
2018-08-12 11:00:07 +02:00
|
|
|
|
2019-08-09 20:29:05 +02:00
|
|
|
void test_cpp_bug_fixes(void)
|
|
|
|
{
|
|
|
|
SCENARIO("Issue 11 - https://github.com/seleznevae/libfort/issues/11") {
|
|
|
|
fort::table table;
|
|
|
|
table << fort::header
|
|
|
|
<< "1" << "2" << fort::endr
|
|
|
|
<< "3" << "4" << fort::endr;
|
|
|
|
|
|
|
|
table.set_border_style(FT_PLAIN_STYLE);
|
|
|
|
table.set_cell_bottom_padding(0);
|
|
|
|
table.set_cell_top_padding(0);
|
|
|
|
table.set_cell_left_padding(1);
|
|
|
|
table.set_cell_right_padding(1);
|
|
|
|
table.set_cell_empty_str_height(0);
|
|
|
|
|
|
|
|
std::string table_str = table.to_string();
|
|
|
|
std::string table_str_etalon =
|
|
|
|
" ------- \n"
|
|
|
|
" 1 2 \n"
|
|
|
|
" ------- \n"
|
|
|
|
" 3 4 \n"
|
|
|
|
" \n";
|
|
|
|
assert_string_equal(table_str, table_str_etalon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-26 21:25:22 +02:00
|
|
|
void test_cpp_table_basic(void)
|
|
|
|
{
|
2018-11-02 18:06:04 +01:00
|
|
|
WHEN("All columns are equal and not empty.") {
|
2018-11-21 18:50:56 +01:00
|
|
|
fort::table table;
|
|
|
|
assert_true(set_cpp_test_props_for_table(&table));
|
2018-08-12 11:00:07 +02:00
|
|
|
|
|
|
|
table << fort::header
|
|
|
|
<< "3" << "c" << "234" << "3.140000" << fort::endr
|
|
|
|
<< "3" << "c" << "234" << "3.140000" << fort::endr
|
|
|
|
<< "3" << "c" << "234" << "3.140000" << fort::endr;
|
|
|
|
|
|
|
|
std::string table_str = table.to_string();
|
|
|
|
std::string 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_string_equal(table_str, table_str_etalon);
|
|
|
|
}
|
|
|
|
|
2018-11-02 18:06:04 +01:00
|
|
|
WHEN("Checking basic constructors and assignmets.") {
|
2018-11-21 18:50:56 +01:00
|
|
|
fort::table table;
|
|
|
|
assert_true(set_cpp_test_props_for_table(&table));
|
2018-11-02 18:06:04 +01:00
|
|
|
|
|
|
|
table << fort::header
|
|
|
|
<< "3" << "c" << "234" << "3.140000" << fort::endr
|
|
|
|
<< "3" << "c" << "234" << "3.140000" << fort::endr
|
|
|
|
<< "3" << "c" << "234" << "3.140000" << fort::endr;
|
|
|
|
|
2018-11-21 18:50:56 +01:00
|
|
|
fort::table table2(std::move(table));
|
|
|
|
fort::table table3;
|
2018-11-02 18:06:04 +01:00
|
|
|
table3 = std::move(table2);
|
|
|
|
|
2018-11-21 18:50:56 +01:00
|
|
|
fort::table table4(table3);
|
|
|
|
fort::table table5;
|
2018-11-03 10:41:58 +01:00
|
|
|
table5 = table4;
|
|
|
|
|
|
|
|
std::string table_str = table5.to_string();
|
2018-11-02 18:06:04 +01:00
|
|
|
std::string 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_string_equal(table_str, table_str_etalon);
|
|
|
|
}
|
|
|
|
|
2018-08-12 11:00:07 +02:00
|
|
|
WHEN("All columns are not equal and not empty") {
|
2018-11-21 18:50:56 +01:00
|
|
|
fort::table table;
|
|
|
|
assert_true(set_cpp_test_props_for_table(&table));
|
2018-08-12 11:00:07 +02:00
|
|
|
|
|
|
|
table << fort::header
|
|
|
|
<< "3" << "c" << "234" << "3.140000" << fort::endr
|
|
|
|
<< "c" << "234" << "3.140000" << "3" << fort::endr
|
|
|
|
<< "234" << "3.140000" << "3" << "c" << fort::endr;
|
|
|
|
|
|
|
|
std::string table_str = table.to_string();
|
|
|
|
std::string table_str_etalon =
|
|
|
|
"+-----+----------+----------+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3 | c | 234 | 3.140000 |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+-----+----------+----------+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| c | 234 | 3.140000 | 3 |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+-----+----------+----------+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 234 | 3.140000 | 3 | c |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+-----+----------+----------+----------+\n";
|
|
|
|
assert_string_equal(table_str, table_str_etalon);
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("All columns are not equal and some cells are empty") {
|
2018-11-21 18:50:56 +01:00
|
|
|
fort::table table;
|
|
|
|
assert_true(set_cpp_test_props_for_table(&table));
|
2018-08-12 11:00:07 +02:00
|
|
|
|
|
|
|
table << fort::header
|
|
|
|
<< "" << "" << "234" << "3.140000" << fort::endr
|
|
|
|
<< "c" << "234" << "3.140000" << "" << fort::endr
|
|
|
|
<< "234" << "3.140000" << "" << "" << fort::endr;
|
|
|
|
|
|
|
|
std::string table_str = table.to_string();
|
|
|
|
std::string table_str_etalon =
|
|
|
|
"+-----+----------+----------+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | 234 | 3.140000 |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+-----+----------+----------+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| c | 234 | 3.140000 | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+-----+----------+----------+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 234 | 3.140000 | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+-----+----------+----------+----------+\n";
|
|
|
|
assert_string_equal(table_str, table_str_etalon);
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("All cells are empty") {
|
2018-11-21 18:50:56 +01:00
|
|
|
fort::table table;
|
|
|
|
assert_true(set_cpp_test_props_for_table(&table));
|
2018-07-26 21:25:22 +02:00
|
|
|
|
2018-08-12 11:00:07 +02:00
|
|
|
table << fort::header
|
|
|
|
<< "" << "" << "" << "" << fort::endr
|
|
|
|
<< "" << "" << "" << "" << fort::endr
|
|
|
|
<< "" << "" << "" << "" << fort::endr;
|
|
|
|
|
|
|
|
std::string table_str = table.to_string();
|
|
|
|
std::string table_str_etalon =
|
|
|
|
"+--+--+--+--+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+--+--+--+--+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+--+--+--+--+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+--+--+--+--+\n";
|
|
|
|
assert_string_equal(table_str, table_str_etalon);
|
|
|
|
}
|
2018-07-26 21:25:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-12 11:00:07 +02:00
|
|
|
void test_cpp_table_write(void)
|
|
|
|
{
|
|
|
|
SCENARIO("Test write functions") {
|
2018-11-21 18:50:56 +01:00
|
|
|
fort::table table;
|
|
|
|
assert_true(set_cpp_test_props_for_table(&table));
|
2018-08-12 11:00:07 +02:00
|
|
|
table << fort::header;
|
|
|
|
assert_true(table.write("3"));
|
|
|
|
assert_true(table.write("c"));
|
|
|
|
assert_true(table.write("234"));
|
|
|
|
assert_true(table.write_ln("3.140000"));
|
|
|
|
|
|
|
|
assert_true(table.write("c"));
|
|
|
|
assert_true(table.write("235"));
|
|
|
|
assert_true(table.write("3.150000"));
|
|
|
|
assert_true(table.write_ln("5"));
|
|
|
|
|
|
|
|
assert_true(table.write("234"));
|
|
|
|
assert_true(table.write("3.140000"));
|
|
|
|
assert_true(table.write("3"));
|
|
|
|
assert_true(table.write_ln("c"));
|
|
|
|
|
|
|
|
/* Replace old values */
|
|
|
|
table[1][1] = "234";
|
2018-12-01 08:39:25 +01:00
|
|
|
table[1][2] = std::string("3.140000");
|
2018-08-12 11:00:07 +02:00
|
|
|
assert_true(table.write_ln("3"));
|
|
|
|
|
|
|
|
std::string table_str = table.to_string();
|
|
|
|
std::string table_str_etalon =
|
|
|
|
"+-----+----------+----------+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3 | c | 234 | 3.140000 |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+-----+----------+----------+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| c | 234 | 3.140000 | 3 |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+-----+----------+----------+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 234 | 3.140000 | 3 | c |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+-----+----------+----------+----------+\n";
|
|
|
|
assert_string_equal(table_str, table_str_etalon);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCENARIO("Test n write functions") {
|
2018-11-21 18:50:56 +01:00
|
|
|
fort::table table;
|
|
|
|
assert_true(set_cpp_test_props_for_table(&table));
|
2018-08-12 11:00:07 +02:00
|
|
|
table << fort::header;
|
|
|
|
assert_true(table.write("3", "c", "234", "3.140000"));
|
|
|
|
table << fort::endr;
|
|
|
|
|
|
|
|
assert_true(table.write_ln("c", "235", "3.150000", "5"));
|
|
|
|
assert_true(table.write_ln("234", "3.140000", "3", "c"));
|
|
|
|
|
|
|
|
/* Replace old values */
|
|
|
|
table[1][1] = "234";
|
|
|
|
assert_true(table.write_ln("3.140000", "3"));
|
|
|
|
|
|
|
|
std::string table_str = table.to_string();
|
|
|
|
std::string table_str_etalon =
|
|
|
|
"+-----+----------+----------+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3 | c | 234 | 3.140000 |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+-----+----------+----------+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| c | 234 | 3.140000 | 3 |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+-----+----------+----------+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 234 | 3.140000 | 3 | c |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+-----+----------+----------+----------+\n";
|
|
|
|
assert_string_equal(table_str, table_str_etalon);
|
|
|
|
}
|
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
SCENARIO("Test range_write functions") {
|
2018-11-21 18:50:56 +01:00
|
|
|
fort::table table;
|
|
|
|
assert_true(set_cpp_test_props_for_table(&table));
|
2018-08-12 11:00:07 +02:00
|
|
|
|
|
|
|
table << fort::header;
|
|
|
|
const char *row_0[4] = {"3", "c", "234", "3.140000"};
|
|
|
|
const char *row_1[4] = {"c", "235", "3.150000", "5"};
|
|
|
|
const char *row_2[4] = {"234", "3.140000", "3", "c"};
|
2018-12-01 08:39:25 +01:00
|
|
|
assert_true(table.range_write_ln(std::begin(row_0), std::end(row_0)));
|
|
|
|
assert_true(table.range_write(std::begin(row_1), std::end(row_1)));
|
2018-08-12 11:00:07 +02:00
|
|
|
table << fort::endr;
|
2018-12-01 08:39:25 +01:00
|
|
|
assert_true(table.range_write_ln(std::begin(row_2), std::end(row_2)));
|
2018-08-12 11:00:07 +02:00
|
|
|
|
|
|
|
/* Replace old values */
|
|
|
|
table[1][1] = "234";
|
2019-04-27 15:21:24 +02:00
|
|
|
const char *row_11[2] = {"3.140000", "3"};
|
2018-12-01 08:39:25 +01:00
|
|
|
assert_true(table.range_write_ln(std::begin(row_11), std::end(row_11)));
|
2018-08-12 11:00:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
std::string table_str = table.to_string();
|
|
|
|
std::string table_str_etalon =
|
|
|
|
"+-----+----------+----------+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3 | c | 234 | 3.140000 |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+-----+----------+----------+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| c | 234 | 3.140000 | 3 |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+-----+----------+----------+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 234 | 3.140000 | 3 | c |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+-----+----------+----------+----------+\n";
|
|
|
|
assert_string_equal(table_str, table_str_etalon);
|
|
|
|
}
|
|
|
|
}
|