From 927f33f1b8f67b15122b42de669ce9f8c4152b04 Mon Sep 17 00:00:00 2001 From: seleznevae Date: Fri, 2 Nov 2018 20:06:04 +0300 Subject: [PATCH] [A] Added basic operators --- lib/fort.hpp | 44 +++++++++++++++++++++++++ tests/bb_tests_cpp/test_table_basic.cpp | 33 ++++++++++++++++++- 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/lib/fort.hpp b/lib/fort.hpp index 424a0da..3aba196 100644 --- a/lib/fort.hpp +++ b/lib/fort.hpp @@ -105,6 +105,50 @@ public: ft_destroy_table(table); } + /** + * Not implemented yet. + */ + Table(const Table& tbl) = delete; + + /** + * Move contstructor. + */ + Table(Table&& tbl) + :table(tbl.table) + { + if (tbl.stream.tellp() >= 0) { + stream << tbl.stream.str(); + tbl.stream.str(std::string()); + } + tbl.table = 0; + } + + /** + * Not implemented yet. + */ + Table& operator=(const Table& tbl) = delete; + + /** + * Move assignment operator. + */ + Table& operator=(Table&& tbl) + { + if (&tbl == this) + return *this; + + if (tbl.table) { + stream.str(std::string()); + if (tbl.stream.tellp() >= 0) { + stream << tbl.stream.str(); + tbl.stream.str(std::string()); + } + ft_destroy_table(table); + table = tbl.table; + tbl.table = NULL; + } + return *this; + } + /** * Convert table to string representation. * diff --git a/tests/bb_tests_cpp/test_table_basic.cpp b/tests/bb_tests_cpp/test_table_basic.cpp index c415ad0..878d94f 100644 --- a/tests/bb_tests_cpp/test_table_basic.cpp +++ b/tests/bb_tests_cpp/test_table_basic.cpp @@ -34,7 +34,7 @@ bool set_test_options_for_table(fort::Table *table) void test_cpp_table_basic(void) { - WHEN("All columns are equal and not empty") { + WHEN("All columns are equal and not empty.") { fort::Table table; assert_true(set_test_options_for_table(&table)); @@ -61,6 +61,37 @@ void test_cpp_table_basic(void) assert_string_equal(table_str, table_str_etalon); } + WHEN("Checking basic constructors and assignmets.") { + fort::Table table; + assert_true(set_test_options_for_table(&table)); + + table << fort::header + << "3" << "c" << "234" << "3.140000" << fort::endr + << "3" << "c" << "234" << "3.140000" << fort::endr + << "3" << "c" << "234" << "3.140000" << fort::endr; + + fort::Table table2(std::move(table)); + fort::Table table3; + table3 = std::move(table2); + + std::string table_str = table3.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); + } + WHEN("All columns are not equal and not empty") { fort::Table table; assert_true(set_test_options_for_table(&table));