-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
59 lines (54 loc) · 1.36 KB
/
test.cpp
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
// clang++ -std=c++17 test.cpp -lgtest -lgtest_main -lpthread
#include <gtest/gtest.h>
#include "coffin-serialize.hpp"
TEST(ToTieTest,Convert){
struct S{
int x = 0;
std::string y;
double z;
};
S a;
auto t = cfn::to_tie(a);
static_assert(std::is_same_v<std::tuple<int&,std::string&,double&>,decltype(t)>);
ASSERT_EQ(std::tie(a.x,a.y,a.z), t);
ASSERT_EQ(&std::get<0>(t), &a.x);
ASSERT_EQ(&std::get<1>(t), &a.y);
}
TEST(dump,Convert){
struct S2{
int x = 42;
std::string y = "foo\"\\bar";
int z = 3;
};
struct S1{
S2 a;
int x = 0;
S2 b;
};
S1 a;
ASSERT_EQ(cfn::dump(a), R"({"":{"":42,"":"foo\"\\bar","":3},"":0,"":{"":42,"":"foo\"\\bar","":3}})");
}
TEST(datatype, Convert){
struct A_impl{
int x;
std::string y;
int z;
};
using A = cfn::datatype<A_impl>;
ASSERT_TRUE((A{1,"",1} == A{1,"",1}));
ASSERT_TRUE((A{1,"",1} < A{1,"a",1}));
ASSERT_TRUE((A{1,"a",1} > A{1,"",1}));
ASSERT_TRUE((A{1,"",1} <= A{1,"a",1}));
ASSERT_TRUE((A{1,"a",1} >= A{1,"",1}));
}
template<class SelfType>
struct A_impl2{
int x;
std::string y;
int z;
SelfType id()const{return *this;}
};
TEST(datatype_with_self, Convert){
using A = cfn::datatype_with_self<A_impl2>;
ASSERT_EQ(typeid(A), typeid(A{}.id()));
}