aboutsummaryrefslogtreecommitdiff
path: root/tests/src/NodeLocation.cpp
blob: 97e9ac80bcd8aaafad41694151638d6427bb4b6b (plain) (blame)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#include <string_view>

#include <openvic-dataloader/NodeLocation.hpp>

#include <snitch/snitch.hpp>

using namespace ovdl;
using namespace std::string_view_literals;

TEST_CASE("NodeLocation", "[node-location]") {
   BasicNodeLocation<char> char_node_location;
   CHECK(char_node_location.begin() == nullptr);
   CHECK(char_node_location.end() == nullptr);
   CHECK(char_node_location.is_synthesized());

   BasicNodeLocation<unsigned char> uchar_node_location;
   CHECK(uchar_node_location.begin() == nullptr);
   CHECK(uchar_node_location.end() == nullptr);
   CHECK(uchar_node_location.is_synthesized());

   BasicNodeLocation<char16_t> char_16_node_location;
   CHECK(char_16_node_location.begin() == nullptr);
   CHECK(char_16_node_location.end() == nullptr);
   CHECK(char_16_node_location.is_synthesized());

   BasicNodeLocation<char32_t> char_32_node_location;
   CHECK(char_32_node_location.begin() == nullptr);
   CHECK(char_32_node_location.end() == nullptr);
   CHECK(char_32_node_location.is_synthesized());

#ifdef __cpp_char8_t
   BasicNodeLocation<char8_t> char_8_node_location;
   CHECK(char_8_node_location.begin() == nullptr);
   CHECK(char_8_node_location.end() == nullptr);
   CHECK(char_8_node_location.is_synthesized());
#endif

   static constexpr auto char_buffer = "buffer"sv;

   static constexpr unsigned char uarray[] = "buffer";
   static constexpr std::basic_string_view<unsigned char> uchar_buffer = uarray;

   static constexpr auto char_16_buffer = u"buffer"sv;
   static constexpr auto char_32_buffer = U"buffer"sv;

#ifdef __cpp_char8_t
   static constexpr auto char_8_buffer = u8"buffer"sv;
#endif

   char_node_location = { &char_buffer[0] };
   CHECK(char_node_location.begin() == &char_buffer[0]);
   CHECK(char_node_location.end() == &char_buffer[0]);
   CHECK_FALSE(char_node_location.is_synthesized());

   uchar_node_location = { &uchar_buffer[0] };
   CHECK(uchar_node_location.begin() == &uchar_buffer[0]);
   CHECK(uchar_node_location.end() == &uchar_buffer[0]);
   CHECK_FALSE(uchar_node_location.is_synthesized());

   char_16_node_location = { &char_16_buffer[0] };
   CHECK(char_16_node_location.begin() == &char_16_buffer[0]);
   CHECK(char_16_node_location.end() == &char_16_buffer[0]);
   CHECK_FALSE(char_16_node_location.is_synthesized());

   char_32_node_location = { &char_32_buffer[0] };
   CHECK(char_32_node_location.begin() == &char_32_buffer[0]);
   CHECK(char_32_node_location.end() == &char_32_buffer[0]);
   CHECK_FALSE(char_32_node_location.is_synthesized());

#ifdef __cpp_char8_t
   char_8_node_location = { &char_8_buffer[0] };
   CHECK(char_8_node_location.begin() == &char_8_buffer[0]);
   CHECK(char_8_node_location.end() == &char_8_buffer[0]);
   CHECK_FALSE(char_8_node_location.is_synthesized());
#endif

   char_node_location = { &char_buffer[0], &char_buffer.back() };
   CHECK(char_node_location.begin() == &char_buffer[0]);
   CHECK(char_node_location.end() == &char_buffer.back());
   CHECK_FALSE(char_node_location.is_synthesized());

   uchar_node_location = { &uchar_buffer[0], &uchar_buffer.back() };
   CHECK(uchar_node_location.begin() == &uchar_buffer[0]);
   CHECK(uchar_node_location.end() == &uchar_buffer.back());
   CHECK_FALSE(uchar_node_location.is_synthesized());

   char_16_node_location = { &char_16_buffer[0], &char_16_buffer.back() };
   CHECK(char_16_node_location.begin() == &char_16_buffer[0]);
   CHECK(char_16_node_location.end() == &char_16_buffer.back());
   CHECK_FALSE(char_16_node_location.is_synthesized());

   char_32_node_location = { &char_32_buffer[0], &char_32_buffer.back() };
   CHECK(char_32_node_location.begin() == &char_32_buffer[0]);
   CHECK(char_32_node_location.end() == &char_32_buffer.back());
   CHECK_FALSE(char_32_node_location.is_synthesized());

#ifdef __cpp_char8_t
   char_8_node_location = { &char_8_buffer[0], &char_8_buffer.back() };
   CHECK(char_8_node_location.begin() == &char_8_buffer[0]);
   CHECK(char_8_node_location.end() == &char_8_buffer.back());
   CHECK_FALSE(char_8_node_location.is_synthesized());
#endif

   BasicNodeLocation<char> char_node_location_copy = { char_node_location };
   char_node_location_copy._begin++;
   CHECK(char_node_location.begin() == &char_buffer[0]);
   CHECK(char_node_location_copy.begin() == &char_buffer[1]);
   CHECK(char_node_location_copy.end() == &char_buffer.back());
   CHECK_FALSE(char_node_location_copy.is_synthesized());

   BasicNodeLocation<unsigned char> uchar_node_location_copy = { uchar_node_location };
   uchar_node_location_copy._begin++;
   CHECK(uchar_node_location.begin() == &uchar_buffer[0]);
   CHECK(uchar_node_location_copy.begin() == &uchar_buffer[1]);
   CHECK(uchar_node_location_copy.end() == &uchar_buffer.back());
   CHECK_FALSE(uchar_node_location_copy.is_synthesized());

   BasicNodeLocation<char16_t> char_16_node_location_copy = { char_16_node_location };
   char_16_node_location_copy._begin++;
   CHECK(char_16_node_location.begin() == &char_16_buffer[0]);
   CHECK(char_16_node_location_copy.begin() == &char_16_buffer[1]);
   CHECK(char_16_node_location_copy.end() == &char_16_buffer.back());
   CHECK_FALSE(char_16_node_location_copy.is_synthesized());

   BasicNodeLocation<char32_t> char_32_node_location_copy = { char_32_node_location };
   char_32_node_location_copy._begin++;
   CHECK(char_32_node_location.begin() == &char_32_buffer[0]);
   CHECK(char_32_node_location_copy.begin() == &char_32_buffer[1]);
   CHECK(char_32_node_location_copy.end() == &char_32_buffer.back());
   CHECK_FALSE(char_32_node_location_copy.is_synthesized());

#ifdef __cpp_char8_t
   BasicNodeLocation<char8_t> char_8_node_location_copy = { char_8_node_location };
   char_8_node_location_copy._begin++;
   CHECK(char_8_node_location.begin() == &char_8_buffer[0]);
   CHECK(char_8_node_location_copy.begin() == &char_8_buffer[1]);
   CHECK(char_8_node_location_copy.end() == &char_8_buffer.back());
   CHECK_FALSE(char_8_node_location_copy.is_synthesized());
#endif

   BasicNodeLocation<char> char_node_location_move = { std::move(char_node_location) };
   CHECK(char_node_location_move.begin() == char_node_location.begin());
   CHECK_FALSE(char_node_location.is_synthesized());
   CHECK(char_node_location_move.begin() == &char_buffer[0]);
   CHECK(char_node_location_move.end() == &char_buffer.back());
   CHECK_FALSE(char_node_location_move.is_synthesized());

   BasicNodeLocation<unsigned char> uchar_node_location_move = { std::move(uchar_node_location) };
   CHECK(uchar_node_location_move.begin() == uchar_node_location.begin());
   CHECK_FALSE(uchar_node_location.is_synthesized());
   CHECK(uchar_node_location_move.begin() == &uchar_buffer[0]);
   CHECK(uchar_node_location_move.end() == &uchar_buffer.back());
   CHECK_FALSE(uchar_node_location_move.is_synthesized());

   BasicNodeLocation<char16_t> char_16_node_location_move = { std::move(char_16_node_location) };
   CHECK(char_16_node_location_move.begin() == char_16_node_location.begin());
   CHECK_FALSE(char_16_node_location.is_synthesized());
   CHECK(char_16_node_location_move.begin() == &char_16_buffer[0]);
   CHECK(char_16_node_location_move.end() == &char_16_buffer.back());
   CHECK_FALSE(char_16_node_location_move.is_synthesized());

   BasicNodeLocation<char32_t> char_32_node_location_move = { std::move(char_32_node_location) };
   CHECK(char_32_node_location_move.begin() == char_32_node_location.begin());
   CHECK_FALSE(char_32_node_location_move.is_synthesized());
   CHECK(char_32_node_location_move.begin() == &char_32_buffer[0]);
   CHECK(char_32_node_location_move.end() == &char_32_buffer.back());
   CHECK_FALSE(char_32_node_location_move.is_synthesized());

#ifdef __cpp_char8_t
   BasicNodeLocation<char8_t> char_8_node_location_move = { std::move(char_8_node_location) };
   CHECK(char_8_node_location_move.begin() == char_8_node_location.begin());
   CHECK_FALSE(char_8_node_location.is_synthesized());
   CHECK(char_8_node_location_move.begin() == &char_8_buffer[0]);
   CHECK(char_8_node_location_move.end() == &char_8_buffer.back());
   CHECK_FALSE(char_8_node_location_move.is_synthesized());
#endif

   BasicNodeLocation<char> char_node_from;
   char_node_from.set_from(char_node_location);
   CHECK(char_node_from.begin() == &char_buffer[0]);
   CHECK(char_node_from.end() == &char_buffer.back());
   CHECK_FALSE(char_node_from.is_synthesized());

   BasicNodeLocation<unsigned char> uchar_node_from;
   uchar_node_from.set_from(uchar_node_location);
   CHECK(uchar_node_from.begin() == &uchar_buffer[0]);
   CHECK(uchar_node_from.end() == &uchar_buffer.back());
   CHECK_FALSE(uchar_node_from.is_synthesized());

   BasicNodeLocation<char16_t> char_16_node_from;
   char_16_node_from.set_from(char_16_node_location);
   CHECK(char_16_node_from.begin() == &char_16_buffer[0]);
   CHECK(char_16_node_from.end() == &char_16_buffer.back());
   CHECK_FALSE(char_16_node_from.is_synthesized());

   BasicNodeLocation<char32_t> char_32_node_from;
   char_32_node_from.set_from(char_32_node_location);
   CHECK(char_32_node_from.begin() == &char_32_buffer[0]);
   CHECK(char_32_node_from.end() == &char_32_buffer.back());
   CHECK_FALSE(char_32_node_from.is_synthesized());

#ifdef __cpp_char8_t
   BasicNodeLocation<char8_t> char_8_node_from;
   char_8_node_from.set_from(char_8_node_location);
   CHECK(char_8_node_from.begin() == &char_8_buffer[0]);
   CHECK(char_8_node_from.end() == &char_8_buffer.back());
   CHECK_FALSE(char_8_node_from.is_synthesized());
#endif

   char_node_from.set_from(uchar_node_location);
   CHECK(char_node_from.begin() == reinterpret_cast<const char*>(&uchar_buffer[0]));
   CHECK(char_node_from.end() == reinterpret_cast<const char*>(&uchar_buffer.back()));
   CHECK_FALSE(char_node_from.is_synthesized());

   uchar_node_from.set_from(char_node_location);
   CHECK(uchar_node_from.begin() == reinterpret_cast<const unsigned char*>(&char_buffer[0]));
   CHECK(uchar_node_from.end() == reinterpret_cast<const unsigned char*>(&char_buffer.back()));
   CHECK_FALSE(uchar_node_from.is_synthesized());

   char_16_node_from.set_from(char_node_location);
   CHECK(char_16_node_from.begin() == reinterpret_cast<const char16_t*>(&char_buffer[0]));
   CHECK(char_16_node_from.end() == reinterpret_cast<const char16_t*>(&char_buffer.back() - 1));
   CHECK_FALSE(char_16_node_from.is_synthesized());

   char_32_node_from.set_from(char_node_location);
   CHECK(char_32_node_from.begin() == reinterpret_cast<const char32_t*>(&char_buffer[0]));
   CHECK(char_32_node_from.end() == reinterpret_cast<const char32_t*>(&char_buffer.back() - 3));
   CHECK_FALSE(char_32_node_from.is_synthesized());

#ifdef __cpp_char8_t
   char_8_node_from.set_from(char_node_location);
   CHECK(char_8_node_from.begin() == reinterpret_cast<const char8_t*>(&char_buffer[0]));
   CHECK(char_8_node_from.end() == reinterpret_cast<const char8_t*>(&char_buffer.back()));
   CHECK_FALSE(char_8_node_from.is_synthesized());
#endif

   char_node_from.set_from(char_16_node_location);
   CHECK(char_node_from.begin() == reinterpret_cast<const char*>(&char_16_buffer[0]));
   CHECK(char_node_from.end() == reinterpret_cast<const char*>(&char_16_buffer.back()) + 1);
   CHECK_FALSE(char_node_from.is_synthesized());

   char_node_from.set_from(char_32_node_location);
   CHECK(char_node_from.begin() == reinterpret_cast<const char*>(&char_32_buffer[0]));
   CHECK(char_node_from.end() == reinterpret_cast<const char*>(&char_32_buffer.back()) + 3);
   CHECK_FALSE(char_node_from.is_synthesized());

   auto char_node_make = BasicNodeLocation<char>::make_from(&char_buffer[0], &char_buffer.back());
   CHECK(char_node_make.begin() == &char_buffer[0]);
   CHECK(char_node_make.end() == &char_buffer.back() + 1);
   CHECK_FALSE(char_node_make.is_synthesized());

   auto uchar_node_make = BasicNodeLocation<unsigned char>::make_from(&uchar_buffer[0], &uchar_buffer.back());
   CHECK(uchar_node_make.begin() == &uchar_buffer[0]);
   CHECK(uchar_node_make.end() == &uchar_buffer.back() + 1);
   CHECK_FALSE(uchar_node_make.is_synthesized());

   auto char_16_node_make = BasicNodeLocation<char16_t>::make_from(&char_16_buffer[0], &char_16_buffer.back());
   CHECK(char_16_node_make.begin() == &char_16_buffer[0]);
   CHECK(char_16_node_make.end() == &char_16_buffer.back() + 1);
   CHECK_FALSE(char_16_node_make.is_synthesized());

   auto char_32_node_make = BasicNodeLocation<char32_t>::make_from(&char_32_buffer[0], &char_32_buffer.back());
   CHECK(char_32_node_make.begin() == &char_32_buffer[0]);
   CHECK(char_32_node_make.end() == &char_32_buffer.back() + 1);
   CHECK_FALSE(char_32_node_make.is_synthesized());

#ifdef __cpp_char8_t
   auto char_8_node_make = BasicNodeLocation<char8_t>::make_from(&char_8_buffer[0], &char_8_buffer.back());
   CHECK(char_8_node_make.begin() == &char_8_buffer[0]);
   CHECK(char_8_node_make.end() == &char_8_buffer.back() + 1);
   CHECK_FALSE(char_8_node_make.is_synthesized());
#endif

   char_node_make = BasicNodeLocation<char>::make_from(&char_buffer[0] + 1, &char_buffer[0]);
   CHECK(char_node_make.begin() == &char_buffer[0] + 1);
   CHECK(char_node_make.end() == &char_buffer[0] + 1);
   CHECK_FALSE(char_node_make.is_synthesized());

   uchar_node_make = BasicNodeLocation<unsigned char>::make_from(&uchar_buffer[0] + 1, &uchar_buffer[0]);
   CHECK(uchar_node_make.begin() == &uchar_buffer[0] + 1);
   CHECK(uchar_node_make.end() == &uchar_buffer[0] + 1);
   CHECK_FALSE(uchar_node_make.is_synthesized());

   char_16_node_make = BasicNodeLocation<char16_t>::make_from(&char_16_buffer[0] + 1, &char_16_buffer[0]);
   CHECK(char_16_node_make.begin() == &char_16_buffer[0] + 1);
   CHECK(char_16_node_make.end() == &char_16_buffer[0] + 1);
   CHECK_FALSE(char_16_node_make.is_synthesized());

   char_32_node_make = BasicNodeLocation<char32_t>::make_from(&char_32_buffer[0] + 1, &char_32_buffer[0]);
   CHECK(char_32_node_make.begin() == &char_32_buffer[0] + 1);
   CHECK(char_32_node_make.end() == &char_32_buffer[0] + 1);
   CHECK_FALSE(char_32_node_make.is_synthesized());

#ifdef __cpp_char8_t
   char_8_node_make = BasicNodeLocation<char8_t>::make_from(&char_8_buffer[0] + 1, &char_8_buffer[0]);
   CHECK(char_8_node_make.begin() == &char_8_buffer[0] + 1);
   CHECK(char_8_node_make.end() == &char_8_buffer[0] + 1);
   CHECK_FALSE(char_8_node_make.is_synthesized());
#endif
}