[R] Refactoring of c++ API

This commit is contained in:
seleznevae
2019-09-28 11:02:34 +03:00
parent ba679b68ce
commit 77a4a1fb4c
18 changed files with 388 additions and 182 deletions

View File

@@ -2,10 +2,11 @@
#include "fort.hpp"
#include "test_utils.hpp"
void test_cpp_bug_fixes(void)
{
SCENARIO("Issue 11 - https://github.com/seleznevae/libfort/issues/11") {
fort::table table;
fort::char_table table;
table << fort::header
<< "1" << "2" << fort::endr
<< "3" << "4" << fort::endr;
@@ -30,7 +31,7 @@ void test_cpp_bug_fixes(void)
void test_cpp_table_basic(void)
{
WHEN("All columns are equal and not empty.") {
fort::table table;
fort::char_table table;
assert_true(set_cpp_test_props_for_table(&table));
table << fort::header
@@ -57,7 +58,7 @@ void test_cpp_table_basic(void)
}
WHEN("Checking basic constructors and assignmets.") {
fort::table table;
fort::char_table table;
assert_true(set_cpp_test_props_for_table(&table));
table << fort::header
@@ -65,12 +66,12 @@ void test_cpp_table_basic(void)
<< "3" << "c" << "234" << "3.140000" << fort::endr
<< "3" << "c" << "234" << "3.140000" << fort::endr;
fort::table table2(std::move(table));
fort::table table3;
fort::char_table table2(std::move(table));
fort::char_table table3;
table3 = std::move(table2);
fort::table table4(table3);
fort::table table5;
fort::char_table table4(table3);
fort::char_table table5;
table5 = table4;
std::string table_str = table5.to_string();
@@ -92,7 +93,7 @@ void test_cpp_table_basic(void)
}
WHEN("All columns are not equal and not empty") {
fort::table table;
fort::char_table table;
assert_true(set_cpp_test_props_for_table(&table));
table << fort::header
@@ -119,7 +120,7 @@ void test_cpp_table_basic(void)
}
WHEN("All columns are not equal and some cells are empty") {
fort::table table;
fort::char_table table;
assert_true(set_cpp_test_props_for_table(&table));
table << fort::header
@@ -146,7 +147,7 @@ void test_cpp_table_basic(void)
}
WHEN("All cells are empty") {
fort::table table;
fort::char_table table;
assert_true(set_cpp_test_props_for_table(&table));
table << fort::header
@@ -177,7 +178,7 @@ void test_cpp_table_basic(void)
void test_cpp_table_write(void)
{
SCENARIO("Test write functions") {
fort::table table;
fort::char_table table;
assert_true(set_cpp_test_props_for_table(&table));
table << fort::header;
assert_true(table.write("3"));
@@ -219,7 +220,7 @@ void test_cpp_table_write(void)
}
SCENARIO("Test n write functions") {
fort::table table;
fort::char_table table;
assert_true(set_cpp_test_props_for_table(&table));
table << fort::header;
assert_true(table.write("3", "c", "234", "3.140000"));
@@ -251,7 +252,7 @@ void test_cpp_table_write(void)
}
SCENARIO("Test range_write functions") {
fort::table table;
fort::char_table table;
assert_true(set_cpp_test_props_for_table(&table));
table << fort::header;
@@ -291,7 +292,7 @@ void test_cpp_table_write(void)
void test_cpp_table_changing_cell(void)
{
WHEN("All columns are equal and not empty") {
fort::table table;
fort::char_table table;
assert_true(set_cpp_test_props_for_table(&table));
table << fort::header

View File

@@ -5,7 +5,7 @@
void test_cpp_table_tbl_properties(void)
{
fort::table table;
fort::char_table table;
WHEN("Test setting entire table properties") {
set_test_properties_as_default();
@@ -66,7 +66,7 @@ void test_cpp_table_cell_properties(void)
WHEN("Setting property for one cell") {
set_test_properties_as_default();
fort::table table = create_cpp_test_int_table(false);
fort::char_table table = create_cpp_test_int_table(false);
table[1][1].set_cell_top_padding(2);
std::string table_str = table.to_string();
@@ -91,7 +91,7 @@ void test_cpp_table_cell_properties(void)
WHEN("Setting property for one cell(2)") {
set_test_properties_as_default();
fort::table table = create_cpp_test_int_table(false);
fort::char_table table = create_cpp_test_int_table(false);
table.cell(1, 1).set_cell_top_padding(2);
std::string table_str = table.to_string();
@@ -116,7 +116,7 @@ void test_cpp_table_cell_properties(void)
WHEN("Setting property for the row") {
set_test_properties_as_default();
fort::table table = create_cpp_test_int_table(false);
fort::char_table table = create_cpp_test_int_table(false);
table[1].set_cell_top_padding(2);
std::string table_str = table.to_string();
@@ -141,7 +141,7 @@ void test_cpp_table_cell_properties(void)
WHEN("Setting property for the column") {
set_test_properties_as_default();
fort::table table = create_cpp_test_int_table(false);
fort::char_table table = create_cpp_test_int_table(false);
table.column(1).set_cell_top_padding(2);
std::string table_str = table.to_string();
@@ -168,7 +168,7 @@ void test_cpp_table_cell_properties(void)
WHEN("Setting property for all cells in the table") {
set_test_properties_as_default();
fort::table table = create_cpp_test_int_table(false);
fort::char_table table = create_cpp_test_int_table(false);
table.set_cell_top_padding(2);
std::string table_str = table.to_string();
@@ -195,12 +195,12 @@ void test_cpp_table_cell_properties(void)
WHEN("All paddings = 1") {
set_test_properties_as_default();
fort::table::default_props().set_cell_top_padding(2);
fort::table::default_props().set_cell_bottom_padding(3);
fort::table::default_props().set_cell_left_padding(1);
fort::table::default_props().set_cell_right_padding(0);
fort::char_table::default_props().set_cell_top_padding(2);
fort::char_table::default_props().set_cell_bottom_padding(3);
fort::char_table::default_props().set_cell_left_padding(1);
fort::char_table::default_props().set_cell_right_padding(0);
fort::table table = create_cpp_test_int_table(false);
fort::char_table table = create_cpp_test_int_table(false);
std::string table_str = table.to_string();
std::string table_str_etalon =
@@ -230,12 +230,12 @@ void test_cpp_table_cell_properties(void)
}
WHEN("Top and bottom padding = 0") {
fort::table::default_props().set_cell_top_padding(0);
fort::table::default_props().set_cell_bottom_padding(0);
fort::table::default_props().set_cell_left_padding(1);
fort::table::default_props().set_cell_right_padding(1);
fort::char_table::default_props().set_cell_top_padding(0);
fort::char_table::default_props().set_cell_bottom_padding(0);
fort::char_table::default_props().set_cell_left_padding(1);
fort::char_table::default_props().set_cell_right_padding(1);
fort::table table = create_cpp_test_int_table(false);
fort::char_table table = create_cpp_test_int_table(false);
std::string table_str = table.to_string();
std::string table_str_etalon =
@@ -250,12 +250,12 @@ void test_cpp_table_cell_properties(void)
}
WHEN("Left and right padding = 0") {
fort::table::default_props().set_cell_top_padding(1);
fort::table::default_props().set_cell_bottom_padding(1);
fort::table::default_props().set_cell_left_padding(0);
fort::table::default_props().set_cell_right_padding(0);
fort::char_table::default_props().set_cell_top_padding(1);
fort::char_table::default_props().set_cell_bottom_padding(1);
fort::char_table::default_props().set_cell_left_padding(0);
fort::char_table::default_props().set_cell_right_padding(0);
fort::table table = create_cpp_test_int_table(false);
fort::char_table table = create_cpp_test_int_table(false);
std::string table_str = table.to_string();
std::string table_str_etalon =
@@ -276,12 +276,12 @@ void test_cpp_table_cell_properties(void)
}
WHEN("All paddings = 0") {
fort::table::default_props().set_cell_top_padding(0);
fort::table::default_props().set_cell_bottom_padding(0);
fort::table::default_props().set_cell_left_padding(0);
fort::table::default_props().set_cell_right_padding(0);
fort::char_table::default_props().set_cell_top_padding(0);
fort::char_table::default_props().set_cell_bottom_padding(0);
fort::char_table::default_props().set_cell_left_padding(0);
fort::char_table::default_props().set_cell_right_padding(0);
fort::table table = create_cpp_test_int_table(false);
fort::char_table table = create_cpp_test_int_table(false);
std::string table_str = table.to_string();
std::string table_str_etalon =
@@ -296,13 +296,13 @@ void test_cpp_table_cell_properties(void)
}
WHEN("Empty string has 0 heigt") {
fort::table::default_props().set_cell_top_padding(1);
fort::table::default_props().set_cell_bottom_padding(1);
fort::table::default_props().set_cell_left_padding(1);
fort::table::default_props().set_cell_right_padding(1);
fort::table::default_props().set_cell_empty_str_height(0);
fort::char_table::default_props().set_cell_top_padding(1);
fort::char_table::default_props().set_cell_bottom_padding(1);
fort::char_table::default_props().set_cell_left_padding(1);
fort::char_table::default_props().set_cell_right_padding(1);
fort::char_table::default_props().set_cell_empty_str_height(0);
fort::table table = create_cpp_test_int_table(false);
fort::char_table table = create_cpp_test_int_table(false);
table << "";
std::string table_str = table.to_string();
@@ -328,7 +328,7 @@ void test_cpp_table_cell_properties(void)
WHEN("Setting properties for a particular table") {
set_test_properties_as_default();
fort::table table = create_cpp_test_int_table(false);
fort::char_table table = create_cpp_test_int_table(false);
table.set_cell_bottom_padding(0);
table.set_cell_top_padding(0);
table.set_cell_left_padding(0);
@@ -371,7 +371,7 @@ void test_cpp_table_cell_properties(void)
WHEN("Set table width and column alignment") {
set_test_properties_as_default();
fort::table table = create_cpp_test_int_table(false);
fort::char_table table = create_cpp_test_int_table(false);
table.column(1).set_cell_min_width(7);
table.column(1).set_cell_text_align(fort::text_align::left);
@@ -401,10 +401,10 @@ void test_cpp_table_cell_properties(void)
WHEN("Set table width and column alignment as default") {
set_test_properties_as_default();
fort::table::default_props().set_cell_min_width(5);
fort::table::default_props().set_cell_text_align(fort::text_align::center);
fort::char_table::default_props().set_cell_min_width(5);
fort::char_table::default_props().set_cell_text_align(fort::text_align::center);
fort::table table = create_cpp_test_int_table(false);
fort::char_table table = create_cpp_test_int_table(false);
std::string table_str = table.to_string();
std::string table_str_etalon =
"+-----+-----+-----+-----+\n"
@@ -426,7 +426,7 @@ void test_cpp_table_cell_properties(void)
WHEN("Multiline cell") {
set_test_properties_as_default();
fort::table table;
fort::char_table table;
table[0].set_cell_row_type(fort::row_type::header);
table << 4 << 'c' << "234" << 3.14 << fort::endr;
@@ -454,7 +454,7 @@ void test_cpp_table_cell_properties(void)
WHEN("Cells with spans") {
set_test_properties_as_default();
fort::table table;
fort::char_table table;
table[0][0].set_cell_span(5);
table[1][1].set_cell_span(3);
@@ -499,7 +499,7 @@ void test_cpp_table_cell_properties(void)
WHEN("Cells with spans in common and header cells") {
set_test_properties_as_default();
fort::table table;
fort::char_table table;
table.set_border_style(FT_DOUBLE2_STYLE);
@@ -550,7 +550,7 @@ void test_cpp_table_text_styles(void)
set_test_properties_as_default();
WHEN("Simple table with one cell and foreground content color") {
fort::table table;
fort::char_table table;
table[0][0].set_cell_content_fg_color(fort::color::yellow);
table << 42;
@@ -566,7 +566,7 @@ void test_cpp_table_text_styles(void)
}
WHEN("Simple table with one cell and background content color") {
fort::table table;
fort::char_table table;
table[0][0].set_cell_content_bg_color(fort::color::yellow);
table << 42;
@@ -582,7 +582,7 @@ void test_cpp_table_text_styles(void)
}
WHEN("Simple table with one cell and background cell color") {
fort::table table;
fort::char_table table;
table[0][0].set_cell_bg_color(fort::color::yellow);
table << 42;
@@ -598,7 +598,7 @@ void test_cpp_table_text_styles(void)
}
WHEN("Simple table with one cell and content style") {
fort::table table;
fort::char_table table;
table[0][0].set_cell_content_text_style(fort::text_style::underlined);
table << 42;
@@ -614,7 +614,7 @@ void test_cpp_table_text_styles(void)
}
WHEN("Simple table with one cell and multiple content style") {
fort::table table;
fort::char_table table;
table[0][0].set_cell_content_text_style(fort::text_style::underlined);
table[0][0].set_cell_content_text_style(fort::text_style::bold);
@@ -631,7 +631,7 @@ void test_cpp_table_text_styles(void)
}
WHEN("Simple table with one cell and cell style") {
fort::table table;
fort::char_table table;
table[0][0].set_cell_text_style(fort::text_style::underlined);
table << 42;
@@ -647,7 +647,7 @@ void test_cpp_table_text_styles(void)
}
WHEN("Simple table with one cell and multiple cell style") {
fort::table table;
fort::char_table table;
table[0][0].set_cell_text_style(fort::text_style::underlined);
table[0][0].set_cell_text_style(fort::text_style::bold);
@@ -664,7 +664,7 @@ void test_cpp_table_text_styles(void)
}
WHEN("Simple table with one cell background color, content foreground color and style.") {
fort::table table;
fort::char_table table;
table[0][0].set_cell_content_fg_color(fort::color::yellow);
table[0][0].set_cell_bg_color(fort::color::red);

View File

@@ -2,7 +2,7 @@
#include "tests.h"
bool set_cpp_test_props_for_table(fort::table *table)
bool set_cpp_test_props_for_table(fort::char_table *table)
{
assert_true(table->set_cell_bottom_padding(1));
assert_true(table->set_cell_top_padding(1));
@@ -33,9 +33,9 @@ bool set_cpp_test_props_for_table(fort::table *table)
fort::table create_cpp_test_int_table(int set_test_opts)
fort::char_table create_cpp_test_int_table(int set_test_opts)
{
fort::table table;
fort::char_table table;
if (set_test_opts) {
assert_true(set_cpp_test_props_for_table(&table) == true);
@@ -54,14 +54,14 @@ int set_test_properties_as_default(void)
{
bool status = true;
status = status && fort::table::default_props().set_cell_min_width(0);
status = status && fort::table::default_props().set_cell_text_align(fort::text_align::right);
status = status && fort::char_table::default_props().set_cell_min_width(0);
status = status && fort::char_table::default_props().set_cell_text_align(fort::text_align::right);
status = status && fort::table::default_props().set_cell_bottom_padding(1);
status = status && fort::table::default_props().set_cell_top_padding(1);
status = status && fort::table::default_props().set_cell_left_padding(1);
status = status && fort::table::default_props().set_cell_right_padding(1);
status = status && fort::table::default_props().set_cell_empty_str_height(1);
status = status && fort::char_table::default_props().set_cell_bottom_padding(1);
status = status && fort::char_table::default_props().set_cell_top_padding(1);
status = status && fort::char_table::default_props().set_cell_left_padding(1);
status = status && fort::char_table::default_props().set_cell_right_padding(1);
status = status && fort::char_table::default_props().set_cell_empty_str_height(1);
assert_true(status == true);

View File

@@ -1,15 +1,11 @@
#ifndef TEST_UTILS_HPP
#define TEST_UTILS_HPP
namespace fort
{
class table;
}
#include "fort.hpp"
int set_test_properties_as_default(void);
bool set_cpp_test_props_for_table(fort::table *table);
fort::table create_cpp_test_int_table(int set_test_opts);
bool set_cpp_test_props_for_table(fort::char_table *table);
fort::char_table create_cpp_test_int_table(int set_test_opts);