-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathUtility.cpp
More file actions
55 lines (46 loc) · 1.54 KB
/
Copy pathUtility.cpp
File metadata and controls
55 lines (46 loc) · 1.54 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
//
// Copyright (c) 2016-2017 Kris Jusiak (kris at jusiak dot net)
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <gtest/gtest.h>
#include "GUnit/Detail/Utility.h"
namespace testing {
inline namespace v1 {
namespace detail {
TEST(Utility, ShouldReturnTrueIfIsValid) {
auto has_f = is_valid([](auto&& x) -> decltype(x.f()) {});
struct a {
void f() {}
};
struct b {};
EXPECT_TRUE(has_f(a{}));
EXPECT_FALSE(has_f(b{}));
}
TEST(Utility, ShouldCall) {
struct a {
double foo() { return 77.0; };
};
EXPECT_EQ(77.0,
(constexpr_if(is_valid([](auto&& x) -> decltype(void(x.foo())) {}),
[](auto&& x) { return x.foo(); },
[](auto&&) { return 42; })(a{})));
struct b {};
EXPECT_EQ(42,
(constexpr_if(is_valid([](auto&& x) -> decltype(void(x.foo())) {}),
[](auto&& x) { return x.foo(); },
[](auto&&) { return 42; })(b{})));
}
TEST(Utility, ShouldReturnTrueIfTupleContaintsType) {
EXPECT_FALSE((contains<int, std::tuple<>>::value));
EXPECT_FALSE((contains<int, std::tuple<double, float, char>>::value));
EXPECT_TRUE((contains<int, std::tuple<int>>::value));
EXPECT_TRUE((contains<int, std::tuple<int, double>>::value));
EXPECT_TRUE((contains<int, std::tuple<int, double, int>>::value));
EXPECT_TRUE((contains<int, std::tuple<double, float, int>>::value));
}
} // detail
} // v1
} // testing