Skip to content

Commit

Permalink
Further unit tests for CTE expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
trueqbit committed Nov 12, 2023
1 parent 57b5097 commit 348a803
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dev/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ namespace sqlite_orm {
}

#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<orm_refers_to_recordset auto mapped, class... Args>
template<orm_refers_to_table auto mapped, class... Args>
int count(Args&&... args) {
return this->count<decay_table_reference_t<mapped>>(std::forward<Args>(args)...);
}
Expand Down
2 changes: 1 addition & 1 deletion include/sqlite_orm/sqlite_orm.h
Original file line number Diff line number Diff line change
Expand Up @@ -20211,7 +20211,7 @@ namespace sqlite_orm {
}

#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<orm_refers_to_recordset auto mapped, class... Args>
template<orm_refers_to_table auto mapped, class... Args>
int count(Args&&... args) {
return this->count<decay_table_reference_t<mapped>>(std::forward<Args>(args)...);
}
Expand Down
34 changes: 33 additions & 1 deletion tests/static_tests/cte.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<class T, class E>
void do_assert() {
Expand Down Expand Up @@ -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<internal::cte_moniker<'1'>>(1_ctealias);
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
runTest<internal::cte_moniker<'z'>>("z"_cte);
STATIC_REQUIRE(internal::is_cte_moniker_v<cte_1>);
STATIC_REQUIRE(orm_cte_moniker<cte_1>);
STATIC_REQUIRE(internal::is_recordset_alias_v<cte_1>);
STATIC_REQUIRE(orm_recordset_alias<cte_1>);
STATIC_REQUIRE_FALSE(internal::is_table_alias_v<cte_1>);
STATIC_REQUIRE_FALSE(orm_table_alias<cte_1>);
#endif
}
SECTION("builder") {
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
constexpr auto cte1 = 1_ctealias;
auto builder1 = cte<1_ctealias>();
#else
auto builder1 = cte<decltype(1_ctealias)>();
using cte_1 = decltype(1_ctealias);
auto builder1 = cte<cte_1>();
#endif
auto builder2 = 1_ctealias();
STATIC_REQUIRE(std::is_same<decltype(builder2), decltype(builder1)>::value);
Expand All @@ -85,4 +98,23 @@ TEST_CASE("CTE storage") {
tuple<decltype(cteTable), decltype(idx1), decltype(idx2), decltype(table)>>::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<internal::from_t<cte_1>>(from<cte1>());
runTest<internal::asterisk_t<cte_1>>(asterisk<cte1>());
runTest<internal::count_asterisk_t<cte_1>>(count<cte1>());
runTest<internal::left_join_t<cte_1, using_t<cte_1, alias_holder<x_t>>>>(left_join<cte1>(using_(cte1->*x)));
runTest<internal::join_t<cte_1, using_t<cte_1, alias_holder<x_t>>>>(join<cte1>(using_(cte1->*x)));
runTest<internal::left_outer_join_t<cte_1, using_t<cte_1, alias_holder<x_t>>>>(
left_outer_join<cte1>(using_(cte1->*x)));
runTest<internal::inner_join_t<cte_1, using_t<cte_1, alias_holder<x_t>>>>(inner_join<cte1>(using_(cte1->*x)));
}
#endif
}
#endif

0 comments on commit 348a803

Please sign in to comment.