initial matador ng commit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "matador/sql/column_definition.hpp"
|
||||
|
||||
using namespace matador::sql;
|
||||
using namespace matador::utils;
|
||||
|
||||
TEST_CASE("Test create empty column", "[column]") {
|
||||
column_definition c("name");
|
||||
|
||||
REQUIRE(c.name() == "name");
|
||||
REQUIRE(c.index() == -1);
|
||||
REQUIRE(c.type() == basic_type::type_null);
|
||||
REQUIRE(c.ref_table().empty());
|
||||
REQUIRE(c.ref_column().empty());
|
||||
|
||||
c.set(std::string{"george"}, 255);
|
||||
REQUIRE(c.type() == basic_type::type_varchar);
|
||||
REQUIRE(c.as<std::string>() == "george");
|
||||
|
||||
c.set(7);
|
||||
REQUIRE(c.type() == basic_type::type_int32);
|
||||
REQUIRE(c.as<std::string>() == "7");
|
||||
REQUIRE(c.as<long>() == 7);
|
||||
REQUIRE(c.str() == "7");
|
||||
}
|
||||
|
||||
TEST_CASE("Test copy and move column", "[column]") {
|
||||
column_definition c("name");
|
||||
c.set(std::string{"george"}, 255);
|
||||
REQUIRE(c.name() == "name");
|
||||
REQUIRE(c.index() == -1);
|
||||
REQUIRE(c.ref_table().empty());
|
||||
REQUIRE(c.ref_column().empty());
|
||||
REQUIRE(c.type() == basic_type::type_varchar);
|
||||
REQUIRE(c.as<std::string>() == "george");
|
||||
REQUIRE(c.attributes().size() == 255);
|
||||
|
||||
auto c2 = c;
|
||||
REQUIRE(c2.name() == "name");
|
||||
REQUIRE(c2.index() == -1);
|
||||
REQUIRE(c2.ref_table().empty());
|
||||
REQUIRE(c2.ref_column().empty());
|
||||
REQUIRE(c2.type() == basic_type::type_varchar);
|
||||
REQUIRE(c2.as<std::string>() == "george");
|
||||
REQUIRE(c2.attributes().size() == 255);
|
||||
|
||||
auto c3 = std::move(c2);
|
||||
REQUIRE(c3.name() == "name");
|
||||
REQUIRE(c3.index() == -1);
|
||||
REQUIRE(c3.ref_table().empty());
|
||||
REQUIRE(c3.ref_column().empty());
|
||||
REQUIRE(c3.type() == basic_type::type_varchar);
|
||||
REQUIRE(c3.as<std::string>() == "george");
|
||||
REQUIRE(c3.attributes().size() == 255);
|
||||
|
||||
REQUIRE(c2.name().empty());
|
||||
REQUIRE(c2.index() == -1);
|
||||
REQUIRE(c2.ref_table().empty());
|
||||
REQUIRE(c2.ref_column().empty());
|
||||
REQUIRE(c2.type() == basic_type::type_null);
|
||||
// REQUIRE(!c2.as<std::string>().has_value());
|
||||
REQUIRE(c2.attributes().size() == 255);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "matador/sql/field.hpp"
|
||||
|
||||
using namespace matador;
|
||||
|
||||
TEST_CASE("Test field", "[field]") {
|
||||
sql::field f("name");
|
||||
|
||||
REQUIRE(f.name() == "name");
|
||||
REQUIRE(f.index() == -1);
|
||||
REQUIRE(f.is_null());
|
||||
REQUIRE(!f.is_integer());
|
||||
REQUIRE(!f.is_floating_point());
|
||||
REQUIRE(!f.is_blob());
|
||||
REQUIRE(!f.is_bool());
|
||||
REQUIRE(!f.is_string());
|
||||
|
||||
f = 7UL;
|
||||
REQUIRE(!f.is_null());
|
||||
REQUIRE(f.is_integer());
|
||||
REQUIRE(!f.is_floating_point());
|
||||
REQUIRE(!f.is_blob());
|
||||
REQUIRE(!f.is_bool());
|
||||
REQUIRE(!f.is_string());
|
||||
|
||||
auto int_val = f.as<int>();
|
||||
REQUIRE(int_val.has_value());
|
||||
REQUIRE(int_val.value() == 7);
|
||||
auto float_val = f.as<float>();
|
||||
REQUIRE(float_val.has_value());
|
||||
REQUIRE(float_val.value() == 7.0);
|
||||
auto str_val = f.as<std::string>();
|
||||
REQUIRE(str_val.has_value());
|
||||
REQUIRE(str_val.value() == "7");
|
||||
auto bool_val = f.as<bool>();
|
||||
REQUIRE(bool_val.has_value());
|
||||
REQUIRE(bool_val.value());
|
||||
|
||||
f = sql::field("name", utils::blob{ 7,8,6,5,4,3 }, 0, 1);
|
||||
REQUIRE(f.index() == 1);
|
||||
REQUIRE(!f.is_null());
|
||||
REQUIRE(!f.is_integer());
|
||||
REQUIRE(!f.is_floating_point());
|
||||
REQUIRE(f.is_blob());
|
||||
REQUIRE(!f.is_bool());
|
||||
REQUIRE(!f.is_string());
|
||||
|
||||
auto blob_val = f.as<utils::blob>();
|
||||
REQUIRE(blob_val.has_value());
|
||||
REQUIRE(blob_val.value() == utils::blob{ 7,8,6,5,4,3 });
|
||||
|
||||
REQUIRE(!f.as<std::string>().has_value());
|
||||
}
|
||||
Reference in New Issue
Block a user