• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 #ifndef FRUIT_TESTS_META_COMMON_H
3 #define FRUIT_TESTS_META_COMMON_H
4 
5 #define FRUIT_IN_META_TEST 1
6 
7 #include <fruit/impl/injection_debug_errors.h>
8 #include <fruit/impl/injection_errors.h>
9 #include <fruit/impl/meta/basics.h>
10 #include <fruit/impl/meta/errors.h>
11 #include <fruit/impl/meta/immutable_map.h>
12 #include <fruit/impl/meta/set.h>
13 #include <fruit/impl/meta/vector.h>
14 
15 using namespace std;
16 using namespace fruit;
17 using namespace fruit::impl;
18 using namespace fruit::impl::meta;
19 
20 template <typename T, typename U>
21 struct DifferentError {
22   static_assert(AlwaysFalse<T>::value, "T and U are different, but should have been equal/equivalent.");
23 };
24 
25 template <typename T, typename U>
26 struct SameError {
27   static_assert(AlwaysFalse<T>::value, "T and U are equal/equivalent but should have been different.");
28 };
29 
30 struct DifferentErrorTag {
31   template <typename T, typename U>
32   using apply = DifferentError<T, U>;
33 };
34 
35 struct SameErrorTag {
36   template <typename T, typename U>
37   using apply = SameError<T, U>;
38 };
39 
40 template <typename... Types>
41 using ToSet = Vector<Types...>;
42 
43 struct ConstructErrorWithoutUnwrapping {
44   template <typename ErrorTag, typename... Args>
45   struct apply {
46     using type = ConstructError(ErrorTag, Type<Args>...);
47   };
48 };
49 
50 using True = Bool<true>;
51 using False = Bool<false>;
52 
53 #undef Assert
54 
55 #define Assert(...) static_assert(Eval<__VA_ARGS__>::value, "")
56 #define AssertNot(...) Assert(Not(__VA_ARGS__))
57 #define AssertSame(...)                                                                                                \
58   static_assert(                                                                                                       \
59       true ||                                                                                                          \
60           sizeof(                                                                                                      \
61               typename CheckIfError<Eval<If(IsSame(__VA_ARGS__), True,                                                 \
62                                             ConstructErrorWithoutUnwrapping(DifferentErrorTag, __VA_ARGS__))>>::type), \
63       "")
64 #define AssertSameType(...)                                                                                            \
65   static_assert(                                                                                                       \
66       true || sizeof(typename CheckIfError<                                                                            \
67                      Eval<If(IsSame(__VA_ARGS__), True, ConstructError(DifferentErrorTag, __VA_ARGS__))>>::type),      \
68       "")
69 #define AssertSameSet(...)                                                                                             \
70   static_assert(                                                                                                       \
71       true || sizeof(typename CheckIfError<                                                                            \
72                      Eval<If(IsSameSet(__VA_ARGS__), True, ConstructError(DifferentErrorTag, __VA_ARGS__))>>::type),   \
73       "")
74 #define AssertSameProof(...)                                                                                           \
75   static_assert(true || sizeof(typename CheckIfError<Eval<If(IsProofTreeEqualTo(__VA_ARGS__), True,                    \
76                                                              ConstructError(DifferentErrorTag, __VA_ARGS__))>>::type), \
77                 "")
78 #define AssertSameForest(...)                                                                                          \
79   static_assert(true || sizeof(typename CheckIfError<Eval<CheckForestEqualTo(__VA_ARGS__)>>::type), "")
80 #define AssertNotSame(...)                                                                                             \
81   static_assert(                                                                                                       \
82       true ||                                                                                                          \
83           sizeof(typename CheckIfError<Eval<If(Not(IsSame(__VA_ARGS__)), True,                                         \
84                                                ConstructErrorWithoutUnwrapping(SameErrorTag, __VA_ARGS__))>>::type),   \
85       "")
86 #define AssertNotSameType(...)                                                                                         \
87   static_assert(                                                                                                       \
88       true || sizeof(typename CheckIfError<                                                                            \
89                      Eval<If(Not(IsSame(__VA_ARGS__)), True, ConstructError(SameErrorTag, __VA_ARGS__))>>::type),      \
90       "")
91 #define AssertNotSameProof(...)                                                                                        \
92   static_assert(true || sizeof(typename CheckIfError<Eval<If(Not(IsProofTreeEqualTo(__VA_ARGS__)), True,               \
93                                                              ConstructError(SameErrorTag, __VA_ARGS__))>>::type),      \
94                 "")
95 #define AssertNotSameForest(...)                                                                                       \
96   static_assert(                                                                                                       \
97       true ||                                                                                                          \
98           sizeof(typename CheckIfError<                                                                                \
99                  Eval<If(Not(IsForestEqualTo(__VA_ARGS__)), True, ConstructError(SameErrorTag, __VA_ARGS__))>>::type), \
100       "")
101 
102 #endif // FRUIT_TESTS_META_COMMON_H
103