added column names and values generator and tests

This commit is contained in:
2023-11-12 22:27:19 +01:00
parent 30f2126225
commit 4ed01a617d
14 changed files with 374 additions and 23 deletions
+2 -1
View File
@@ -16,7 +16,8 @@ add_executable(tests builder.cpp
backend_provider.cpp
connection.cpp
product.hpp
column_generator.cpp)
column_generator.cpp
column_name_generator.cpp)
target_link_libraries(tests PRIVATE
Catch2::Catch2WithMain
matador
+30
View File
@@ -0,0 +1,30 @@
#include <catch2/catch_test_macros.hpp>
#include "matador/sql/column_name_generator.hpp"
#include "product.hpp"
using namespace matador::sql;
TEST_CASE("Generate column names from object", "[column name generator]") {
auto columns = column_name_generator::generate<matador::test::product>();
const std::vector<std::string> expected_columns = {
"product_name",
"supplier_id",
"category_id",
"quantity_per_unit",
"unit_price",
"units_in_stock",
"units_in_order",
"reorder_level",
"discontinued"
};
REQUIRE(!columns.empty());
REQUIRE(columns.size() == expected_columns.size());
for (size_t i = 0; i != expected_columns.size(); ++i) {
REQUIRE(expected_columns[i] == columns[i]);
}
}
+4 -1
View File
@@ -7,6 +7,7 @@
#include "product.hpp"
using namespace matador::sql;
using namespace matador::test;
TEST_CASE("Execute create table statement", "[connection]") {
connection_pool<connection> pool("sqlite://sqlite.db", 4);
@@ -21,7 +22,9 @@ TEST_CASE("Execute create table statement", "[connection]") {
REQUIRE(res.second == R"(CREATE TABLE "person" ("id" BIGINT NOT NULL PRIMARY KEY, "name" VARCHAR(255), "age" INTEGER))");
res = s.create().table<matador::test::product>("product").execute();
res = s.create().table<product>("product").execute();
REQUIRE(res.second == R"(CREATE TABLE "person" ("id" BIGINT NOT NULL PRIMARY KEY, "name" VARCHAR(255), "age" INTEGER))");
}
TEST_CASE("Execute drop table statement", "[connection]") {