Skip to content

Commit

Permalink
added column tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fnc12 committed Oct 4, 2023
1 parent 85c58f2 commit 20beff7
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
1 change: 0 additions & 1 deletion dev/node_tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "ast/match.h"

namespace sqlite_orm {

namespace internal {

template<class T, class SFINAE = void>
Expand Down
2 changes: 1 addition & 1 deletion dev/serializing_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ namespace sqlite_orm {
ss << serialize(constraint, context) << ' ';
});
if(isNotNull) {
ss << "NOT NULL ";
ss << "NOT NULL";
}

return ss;
Expand Down
3 changes: 1 addition & 2 deletions include/sqlite_orm/sqlite_orm.h
Original file line number Diff line number Diff line change
Expand Up @@ -13579,7 +13579,7 @@ namespace sqlite_orm {
ss << serialize(constraint, context) << ' ';
});
if(isNotNull) {
ss << "NOT NULL ";
ss << "NOT NULL";
}

return ss;
Expand Down Expand Up @@ -19009,7 +19009,6 @@ namespace sqlite_orm {
// #include "ast/match.h"

namespace sqlite_orm {

namespace internal {

template<class T, class SFINAE = void>
Expand Down
15 changes: 15 additions & 0 deletions tests/schema/column_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,18 @@ TEST_CASE("column tests is_generated") {
REQUIRE_FALSE(column.is_generated());
}
}

TEST_CASE("column is_not_null") {
struct User {
int id = 0;
std::unique_ptr<std::string> name;
};
SECTION("not null") {
auto column = make_column("id", &User::id);
REQUIRE(column.is_not_null());
}
SECTION("null") {
auto column = make_column("name", &User::name);
REQUIRE(!column.is_not_null());
}
}
21 changes: 12 additions & 9 deletions tests/statement_serializer_tests/collate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ using namespace sqlite_orm;
TEST_CASE("statement_serializer collate") {
internal::db_objects_tuple<> storage;
internal::serializer_context<internal::db_objects_tuple<>> context{storage};
{
std::string value;
std::string expected;
SECTION("COLLATE NOCASE") {
auto col = collate_nocase();
auto value = serialize(col, context);
REQUIRE(value == "COLLATE NOCASE");
value = serialize(col, context);
expected = "COLLATE NOCASE";
}
{
SECTION("COLLATE BINARY") {
auto col = collate_binary();
auto value = serialize(col, context);
REQUIRE(value == "COLLATE BINARY");
value = serialize(col, context);
expected = "COLLATE BINARY";
}
{
SECTION("COLLATE RTRIM") {
auto col = collate_rtrim();
auto value = serialize(col, context);
REQUIRE(value == "COLLATE RTRIM");
value = serialize(col, context);
expected = "COLLATE RTRIM";
}
REQUIRE(value == expected);
}
11 changes: 11 additions & 0 deletions tests/static_tests/column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
using namespace sqlite_orm;

TEST_CASE("Column") {
{
using column_type = decltype(make_column("name", &User::name));
STATIC_REQUIRE(std::tuple_size<column_type::constraints_type>::value == 0);
STATIC_REQUIRE(std::is_same<column_type::object_type, User>::value);
STATIC_REQUIRE(std::is_same<column_type::field_type, std::unique_ptr<std::string>>::value);
STATIC_REQUIRE(std::is_same<column_type::member_pointer_t, std::unique_ptr<std::string> User::*>::value);
STATIC_REQUIRE(std::is_same<column_type::setter_type, internal::empty_setter>::value);

using field_type = column_type::field_type;
STATIC_REQUIRE(type_is_nullable<field_type>::value);
}
{
using column_type = decltype(make_column("id", &User::id));
STATIC_REQUIRE(std::tuple_size<column_type::constraints_type>::value == 0);
Expand Down
4 changes: 4 additions & 0 deletions tests/static_tests/static_tests_common.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#pragma once

#include <memory> // std::unique_ptr
#include <string> // std::string

struct User {
int id;
std::unique_ptr<std::string> name;

const int& getIdByRefConst() const {
return this->id;
Expand Down

0 comments on commit 20beff7

Please sign in to comment.