forked from fnc12/sqlite_orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatic_if_tests.cpp
More file actions
67 lines (65 loc) · 1.65 KB
/
static_if_tests.cpp
File metadata and controls
67 lines (65 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <sqlite_orm/sqlite_orm.h>
#include <catch2/catch.hpp>
using namespace sqlite_orm;
TEST_CASE("static_if") {
{ // simple true
auto value = 0;
internal::static_if<std::true_type{}>(
[&value] {
value = 1;
},
[&value] {
value = -1;
})();
REQUIRE(value == 1);
}
{ // simple false
auto value = 0;
internal::static_if<std::false_type{}>(
[&value] {
value = 1;
},
[&value] {
value = -1;
})();
REQUIRE(value == -1);
}
{ // tuple is empty
auto value = 0;
internal::static_if<std::is_empty<std::tuple<>>{}>(
[&value] {
value = 1;
},
[&value] {
value = -1;
})();
REQUIRE(value == 1);
}
{ // tuple is not empty
auto value = 0;
internal::static_if<internal::static_not<std::is_empty<std::tuple<>>>{}>(
[&value] {
value = 1;
},
[&value] {
value = -1;
})();
REQUIRE(value == -1);
}
{
struct User {
std::string name;
};
auto ch = check(length(&User::name) > 5);
static_assert(!internal::is_column<decltype(ch)>::value, "");
int called = 0;
internal::static_if<internal::is_column<decltype(ch)>{}>(
[&called] {
called = 1;
},
[&called] {
called = -1;
})();
REQUIRE(called == -1);
}
}