-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest_assert_assert.cpp
157 lines (132 loc) · 3.55 KB
/
test_assert_assert.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "../source/h2_unit.cpp"
#include "test_cplusplus.hpp"
SUITE(find_compare)
{
Case(simple)
{
OK("== b", h2::__find_compare("a == b", "=="));
OK("!= b", h2::__find_compare("a != b", "!="));
OK("< b", h2::__find_compare("a < b", "<"));
OK("<= b", h2::__find_compare("a <= b", "<="));
OK("> b", h2::__find_compare("a > b", ">"));
OK(">= b", h2::__find_compare("a >= b", ">="));
}
Case(no space)
{
OK("==b", h2::__find_compare("a ==b", "=="));
OK("!= b", h2::__find_compare("a!= b", "!="));
OK("<b", h2::__find_compare("a<b", "<"));
OK("<=b", h2::__find_compare("a <=b", "<="));
OK("> b", h2::__find_compare("a> b", ">"));
OK(">=b", h2::__find_compare("a>=b", ">="));
}
Case(in string)
{
OK("==b", h2::__find_compare("\"a==\" ==b", "=="));
OK("!= b", h2::__find_compare("\"a!=\"!= b", "!="));
OK("<b", h2::__find_compare("\"a<\"<b", "<"));
OK("<=b", h2::__find_compare("\"a<=\" <=b", "<="));
OK("> b", h2::__find_compare("\"a>\"> b", ">"));
OK(">=b", h2::__find_compare("\"a>=\">=b", ">="));
}
Case(has template)
{
OK("== b", h2::__find_compare("sizeof(std::vector<int>::size_type) == b", "=="));
OK("!= b", h2::__find_compare("sizeof(std::vector<int>::size_type)!= b", "!="));
OK("<b", h2::__find_compare("sizeof(std::vector<int>::size_type)<b", "<"));
OK("<=b", h2::__find_compare("sizeof(std::vector<int>::size_type) <=b", "<="));
OK("> b", h2::__find_compare("sizeof(std::vector<int>::size_type)> b", ">"));
OK(">=b", h2::__find_compare("sizeof(std::vector<int>::size_type)>=b", ">="));
}
}
CASE(split_compare)
{
h2::h2_string eexpr, aexpr;
h2::__split_compare("a1 == b1", "==", eexpr, aexpr);
OK("a1", eexpr);
OK("b1", aexpr);
h2::__split_compare("a2!= b2", "!=", eexpr, aexpr);
OK("a2", eexpr);
OK("b2", aexpr);
h2::__split_compare("a3 <b3", "<", eexpr, aexpr);
OK("a3", eexpr);
OK("b3", aexpr);
h2::__split_compare("a4<=b4", "<=", eexpr, aexpr);
OK("a4", eexpr);
OK("b4", aexpr);
h2::__split_compare("a5 \t> \n b5", ">", eexpr, aexpr);
OK("a5", eexpr);
OK("b5", aexpr);
h2::__split_compare("a6 >= b6", ">=", eexpr, aexpr);
OK("a6", eexpr);
OK("b6", aexpr);
}
static const char* ft(std::true_type)
{
return "True";
}
static const char* ft(std::false_type)
{
return "False";
}
SUITE(array detect)
{
Case(native array)
{
int a[3] = {1, 2, 3};
OK(std::is_array<decltype(a)>::value);
OK(3, std::extent<decltype(a)>::value);
int* b = a;
OK(!std::is_array<decltype(b)>::value);
}
Case(std vector)
{
OK(!std::is_array<std::vector<int>>::value);
}
Case(std deque)
{
OK(!std::is_array<std::deque<int>>::value);
}
Case(std array)
{
OK(!(std::is_array<std::array<int, 3>>::value));
}
Case(std list)
{
OK(!std::is_array<std::list<int>>::value);
}
Case(std forward_list)
{
OK(!std::is_array<std::forward_list<int>>::value);
}
Case(type)
{
int a1[] = {1, 2, 3};
OK("True", ft(std::is_array<decltype(a1)>{}));
int a2 = 123;
OK("False", ft(std::is_array<decltype(a2)>{}));
OK("False", ft(std::is_array<std::array<int, 3>>{}));
}
}
static int c1 = 0;
static int get1()
{
++c1;
return 1;
}
SUITE(nocall in decltype)
{
Case(decltype)
{
c1 = 0;
decltype(get1()) b = 0;
OK(0, c1);
OK(0, b);
}
Case(actual call one time)
{
c1 = 0;
OK(1, get1());
OK(1, c1);
}
}