Skip to content

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fnc12 committed Oct 14, 2023
1 parent fe1ddd4 commit b1ff2e4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/constraints/default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,32 @@ TEST_CASE("default value for string") {
make_column("phone", &Contact::phone)));
storage.sync_schema();
}

TEST_CASE("default current time/date/timestamp") {
struct User {
int id = 0;
std::string current;
};
SECTION("time") {
auto storage = make_storage({},
make_table("users",
make_column("id", &User::id, primary_key()),
make_column("current", &User::current, default_value(current_time()))));
storage.sync_schema();
}
SECTION("date") {
auto storage = make_storage({},
make_table("users",
make_column("id", &User::id, primary_key()),
make_column("current", &User::current, default_value(current_date()))));
storage.sync_schema();
}
SECTION("timestamp") {
auto storage =
make_storage({},
make_table("users",
make_column("id", &User::id, primary_key()),
make_column("current", &User::current, default_value(current_timestamp()))));
storage.sync_schema();
}
}
20 changes: 20 additions & 0 deletions tests/statement_serializer_tests/schema/column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ TEST_CASE("statement_serializer column") {
value = serialize(column, context);
expected = "\"nullable_text\" TEXT NULL";
}
// default
SECTION("default") {
SECTION("current") {
SECTION("time") {
auto column = make_column("name", &User::name, default_value(current_time()));
value = serialize(column, context);
expected = "\"name\" TEXT DEFAULT (CURRENT_TIME) NOT NULL";
}
SECTION("date") {
auto column = make_column("name", &User::name, default_value(current_date()));
value = serialize(column, context);
expected = "\"name\" TEXT DEFAULT (CURRENT_DATE) NOT NULL";
}
SECTION("timestamp") {
auto column = make_column("name", &User::name, default_value(current_timestamp()));
value = serialize(column, context);
expected = "\"name\" TEXT DEFAULT (CURRENT_TIMESTAMP) NOT NULL";
}
}
}
}
SECTION("without types and constraints") {
context.skip_types_and_constraints = true;
Expand Down

0 comments on commit b1ff2e4

Please sign in to comment.