1 /*
2 * Copyright (c) 2016, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
8 */
9
10 #include <fatal/type/has_type.h>
11
12 #include <fatal/test/driver.h>
13
14 namespace fatal {
15
16 struct foo { using xyz = int; };
17 struct bar { typedef int xyz; };
18 struct baz {};
19 struct gaz { struct xyz {}; };
20 struct qux { int xyz; };
21
22 FATAL_HAS_TYPE(has_xyz, xyz);
23
FATAL_TEST(has_type,fatal_has_type)24 FATAL_TEST(has_type, fatal_has_type) {
25 FATAL_EXPECT_SAME<std::true_type, has_xyz::apply<foo>>();
26 FATAL_EXPECT_SAME<std::true_type, has_xyz::apply<bar>>();
27 FATAL_EXPECT_SAME<std::false_type, has_xyz::apply<baz>>();
28 FATAL_EXPECT_SAME<std::true_type, has_xyz::apply<gaz>>();
29 FATAL_EXPECT_SAME<std::false_type, has_xyz::apply<qux>>();
30 }
31
32 FATAL_HAS_TYPE_NAME(xyz);
33
FATAL_TEST(has_type,fatal_has_type_name)34 FATAL_TEST(has_type, fatal_has_type_name) {
35 FATAL_EXPECT_SAME<std::true_type, xyz::apply<foo>>();
36 FATAL_EXPECT_SAME<std::true_type, xyz::apply<bar>>();
37 FATAL_EXPECT_SAME<std::false_type, xyz::apply<baz>>();
38 FATAL_EXPECT_SAME<std::true_type, xyz::apply<gaz>>();
39 FATAL_EXPECT_SAME<std::false_type, xyz::apply<qux>>();
40 }
41
42 struct ifoo { using id = int; };
43 struct ibar { typedef int id; };
44 struct ibaz {};
45 struct igaz { struct id {}; };
46 struct iqux { int id; };
47
FATAL_TEST(has_type,has_type)48 FATAL_TEST(has_type, has_type) {
49 FATAL_EXPECT_SAME<std::true_type, has_type::id::apply<ifoo>>();
50 FATAL_EXPECT_SAME<std::true_type, has_type::id::apply<ibar>>();
51 FATAL_EXPECT_SAME<std::false_type, has_type::id::apply<ibaz>>();
52 FATAL_EXPECT_SAME<std::true_type, has_type::id::apply<igaz>>();
53 FATAL_EXPECT_SAME<std::false_type, has_type::id::apply<iqux>>();
54 }
55
56 } // namespace fatal {
57