added field class
This commit is contained in:
+2
-1
@@ -38,7 +38,8 @@ add_executable(tests
|
||||
DummyConnection.cpp
|
||||
EntityQueryBuilderTest.cpp
|
||||
models/author.hpp
|
||||
models/book.hpp)
|
||||
models/book.hpp
|
||||
FieldTest.cpp)
|
||||
|
||||
target_link_libraries(tests PRIVATE
|
||||
Catch2::Catch2WithMain
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "matador/sql/field.hpp"
|
||||
|
||||
using namespace matador::sql;
|
||||
|
||||
TEST_CASE("Field test", "[field]") {
|
||||
field f("name");
|
||||
|
||||
REQUIRE(f.name() == "name");
|
||||
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());
|
||||
}
|
||||
Reference in New Issue
Block a user