query/test/orm/sql/ColumnTest.cpp

62 lines
1.9 KiB
C++

#include <catch2/catch_test_macros.hpp>
#include "matador/object/attribute_definition.hpp"
using namespace matador::object;
using namespace matador::utils;
TEST_CASE("Test create empty column", "[column]") {
attribute_definition c("name");
REQUIRE(c.name() == "name");
REQUIRE(c.index() == -1);
REQUIRE(c.type() == basic_type::type_null);
REQUIRE(!c.reference_column());
c.change_type<std::string>(255);
REQUIRE(c.type() == basic_type::type_varchar);
c.change_type<int32_t>(7);
REQUIRE(c.type() == basic_type::type_int32);
}
TEST_CASE("Test copy and move column", "[column]") {
attribute_definition c(
"name",
basic_type::type_varchar,
2,
std::make_shared<attribute_definition>("author", "books", basic_type::type_uint32, constraints::FOREIGN_KEY),
{255, constraints::FOREIGN_KEY},
null_option_type::NOT_NULL
);
REQUIRE(c.name() == "name");
REQUIRE(c.index() == 2);
REQUIRE(c.reference_column());
REQUIRE(c.reference_column()->name() == "author");
REQUIRE(c.reference_column()->table_name() == "books");
REQUIRE(c.type() == basic_type::type_varchar);
REQUIRE(c.attributes().size() == 255);
auto c2 = c;
REQUIRE(c2.name() == "name");
REQUIRE(c2.index() == 2);
REQUIRE(c2.reference_column());
REQUIRE(c2.reference_column()->name() == "author");
REQUIRE(c2.reference_column()->table_name() == "books");
REQUIRE(c2.type() == basic_type::type_varchar);
REQUIRE(c2.attributes().size() == 255);
auto c3 = std::move(c2);
REQUIRE(c3.name() == "name");
REQUIRE(c3.index() == 2);
REQUIRE(c3.reference_column());
REQUIRE(c3.reference_column()->name() == "author");
REQUIRE(c3.reference_column()->table_name() == "books");
REQUIRE(c3.type() == basic_type::type_varchar);
REQUIRE(c3.attributes().size() == 255);
REQUIRE(c2.name().empty());
REQUIRE(c2.index() == 2);
REQUIRE(!c2.reference_column());
REQUIRE(c2.attributes().size() == 255);
}