From 348a8039fb3c492b98d6459f4e383b8a9df6faef Mon Sep 17 00:00:00 2001 From: klaus triendl Date: Sun, 12 Nov 2023 14:22:16 +0200 Subject: [PATCH] Further unit tests for CTE expressions --- dev/storage.h | 2 +- include/sqlite_orm/sqlite_orm.h | 2 +- tests/static_tests/cte.cpp | 34 ++++++++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/dev/storage.h b/dev/storage.h index 037c93c84..cc68dc9d2 100644 --- a/dev/storage.h +++ b/dev/storage.h @@ -451,7 +451,7 @@ namespace sqlite_orm { } #ifdef SQLITE_ORM_WITH_CPP20_ALIASES - template + template int count(Args&&... args) { return this->count>(std::forward(args)...); } diff --git a/include/sqlite_orm/sqlite_orm.h b/include/sqlite_orm/sqlite_orm.h index 00bbbae9d..13d99bb74 100644 --- a/include/sqlite_orm/sqlite_orm.h +++ b/include/sqlite_orm/sqlite_orm.h @@ -20211,7 +20211,7 @@ namespace sqlite_orm { } #ifdef SQLITE_ORM_WITH_CPP20_ALIASES - template + template int count(Args&&... args) { return this->count>(std::forward(args)...); } diff --git a/tests/static_tests/cte.cpp b/tests/static_tests/cte.cpp index 385e2354a..8bde4462e 100644 --- a/tests/static_tests/cte.cpp +++ b/tests/static_tests/cte.cpp @@ -10,6 +10,9 @@ using internal::alias_holder, internal::column_alias; using internal::column_t; using std::is_same, std::is_constructible; using std::tuple; +#ifdef SQLITE_ORM_WITH_CPP20_ALIASES +using internal::using_t; +#endif template void do_assert() { @@ -50,16 +53,26 @@ TEST_CASE("CTE type traits") { TEST_CASE("CTE building") { SECTION("moniker") { + constexpr auto cte1 = 1_ctealias; + using cte_1 = decltype(1_ctealias); runTest>(1_ctealias); #ifdef SQLITE_ORM_WITH_CPP20_ALIASES runTest>("z"_cte); + STATIC_REQUIRE(internal::is_cte_moniker_v); + STATIC_REQUIRE(orm_cte_moniker); + STATIC_REQUIRE(internal::is_recordset_alias_v); + STATIC_REQUIRE(orm_recordset_alias); + STATIC_REQUIRE_FALSE(internal::is_table_alias_v); + STATIC_REQUIRE_FALSE(orm_table_alias); #endif } SECTION("builder") { #ifdef SQLITE_ORM_WITH_CPP20_ALIASES + constexpr auto cte1 = 1_ctealias; auto builder1 = cte<1_ctealias>(); #else - auto builder1 = cte(); + using cte_1 = decltype(1_ctealias); + auto builder1 = cte(); #endif auto builder2 = 1_ctealias(); STATIC_REQUIRE(std::is_same::value); @@ -85,4 +98,23 @@ TEST_CASE("CTE storage") { tuple>::value); } } + +TEST_CASE("CTE expressions") { +#ifdef SQLITE_ORM_WITH_CPP20_ALIASES + constexpr auto cte1 = 1_ctealias; + using cte_1 = decltype(1_ctealias); + constexpr auto x = 1_colalias; + using x_t = decltype(1_colalias); + SECTION("moniker expressions") { + runTest>(from()); + runTest>(asterisk()); + runTest>(count()); + runTest>>>(left_join(using_(cte1->*x))); + runTest>>>(join(using_(cte1->*x))); + runTest>>>( + left_outer_join(using_(cte1->*x))); + runTest>>>(inner_join(using_(cte1->*x))); + } +#endif +} #endif