query/test/core/utils/IdentifierTest.cpp

118 lines
2.6 KiB
C++

#include <catch2/catch_test_macros.hpp>
#include "matador/utils/identifier.hpp"
#include "matador/utils/default_type_traits.hpp"
using namespace matador::utils;
TEST_CASE("Test create identifier", "[identifier][create]") {
const identifier id;
REQUIRE(id.is_null());
REQUIRE(!id.is_integer());
REQUIRE(!id.is_floating_point());
REQUIRE(!id.is_bool());
REQUIRE(!id.is_varchar());
REQUIRE(!id.is_date());
REQUIRE(!id.is_time());
REQUIRE(!id.is_blob());
REQUIRE(!id.is_valid());
REQUIRE(id.str() == "null");
}
TEST_CASE("Test assign value to identifier", "[identifier][assign]") {
identifier id;
REQUIRE(id.is_null());
REQUIRE(!id.is_valid());
REQUIRE(id.str() == "null");
id = 7;
REQUIRE(!id.is_null());
REQUIRE(id.is_valid());
REQUIRE(id.is_integer());
REQUIRE(id.str() == "7");
REQUIRE(id.type() == basic_type::type_int32);
REQUIRE(id.type_index() == std::type_index(typeid(int)));
id = std::string{"UniqueId"};
REQUIRE(!id.is_null());
REQUIRE(id.is_valid());
REQUIRE(id.is_varchar());
REQUIRE(id.str() == "UniqueId");
id = "UniqueId";
REQUIRE(!id.is_null());
REQUIRE(id.is_valid());
REQUIRE(id.is_varchar());
// REQUIRE(id == identifier{"UniqueId"});
}
TEST_CASE("Test compare identifier", "[identifier][compare]") {
identifier id1{6}, id2{7};
REQUIRE(id1 != id2);
REQUIRE(id1 < id2);
REQUIRE(id1 <= id2);
REQUIRE(id2 > id1);
REQUIRE(id2 >= id1);
REQUIRE(id1.hash() != id2.hash());
id2 = 6;
REQUIRE(id1 == id2);
REQUIRE(id1.hash() == id2.hash());
}
identifier create(const int id) {
return identifier{id};
}
TEST_CASE("Test copy identifier" "[identifier][copy]") {
identifier id1{"Unique"};
REQUIRE(id1.is_valid());
REQUIRE(id1.str() == "Unique");
const identifier id2(id1);
REQUIRE(id1 == id2);
REQUIRE(id1.hash() == id2.hash());
id1.clear();
REQUIRE(id1.is_null());
identifier id3 = id1;
REQUIRE(id1 == id3);
REQUIRE(id1 < id3);
REQUIRE(id3.is_null());
REQUIRE(id1.hash() == id3.hash());
id3 = create(9);
id3 = id1;
}
TEST_CASE("Test move identifier", "[identifier][move]") {
identifier id1{6};
REQUIRE(id1.is_integer());
REQUIRE(!id1.is_null());
const auto id2 = std::move(id1);
REQUIRE(id1.is_null());
REQUIRE(id2.is_integer());
}
TEST_CASE("Test share identifier", "[identifier][share]") {
const identifier id1{6};
REQUIRE(id1.use_count() == 1);
auto id2 = id1.share();
REQUIRE(id1 == id2);
REQUIRE(id1.use_count() == 2);
}