blob: 1464774bca6420647fbbfc8f4a0a8c9df14f97ee [file] [log] [blame]
James Feist481c5d52019-08-13 14:40:40 -07001#include "Utils.hpp"
2
3#include <boost/container/flat_map.hpp>
4#include <nlohmann/json.hpp>
James Feist8c505da2020-05-28 10:06:33 -07005
Brad Bishop9d2ef082020-08-26 15:17:55 -04006#include <string>
James Feist481c5d52019-08-13 14:40:40 -07007#include <variant>
8
9#include "gtest/gtest.h"
10
Brad Bishop9d2ef082020-08-26 15:17:55 -040011using namespace std::string_literals;
12
James Feist481c5d52019-08-13 14:40:40 -070013TEST(TemplateCharReplace, replaceOneInt)
14{
15 nlohmann::json j = {{"foo", "$bus"}};
16 auto it = j.begin();
17 boost::container::flat_map<std::string, BasicVariantType> data;
18 data["BUS"] = 23;
19
20 templateCharReplace(it, data, 0);
21
22 nlohmann::json expected = 23;
23 EXPECT_EQ(expected, j["foo"]);
24}
25
26TEST(TemplateCharReplace, replaceOneStr)
27{
28 nlohmann::json j = {{"foo", "$TEST"}};
29 auto it = j.begin();
30 boost::container::flat_map<std::string, BasicVariantType> data;
31 data["TEST"] = std::string("Test");
32
33 templateCharReplace(it, data, 0);
34
35 nlohmann::json expected = "Test";
36 EXPECT_EQ(expected, j["foo"]);
37}
38
39TEST(TemplateCharReplace, replaceSecondStr)
40{
41 nlohmann::json j = {{"foo", "the $TEST"}};
42 auto it = j.begin();
43 boost::container::flat_map<std::string, BasicVariantType> data;
44 data["TEST"] = std::string("Test");
45
46 templateCharReplace(it, data, 0);
47
48 nlohmann::json expected = "the Test";
49 EXPECT_EQ(expected, j["foo"]);
50}
51
James Feist481c5d52019-08-13 14:40:40 -070052TEST(TemplateCharReplace, replaceMiddleStr)
53{
54 nlohmann::json j = {{"foo", "the $TEST worked"}};
55 auto it = j.begin();
56 boost::container::flat_map<std::string, BasicVariantType> data;
57 data["TEST"] = std::string("Test");
58
59 templateCharReplace(it, data, 0);
60
61 nlohmann::json expected = "the Test worked";
62 EXPECT_EQ(expected, j["foo"]);
63}
James Feist481c5d52019-08-13 14:40:40 -070064
65TEST(TemplateCharReplace, replaceLastStr)
66{
67 nlohmann::json j = {{"foo", "the Test $TEST"}};
68 auto it = j.begin();
69 boost::container::flat_map<std::string, BasicVariantType> data;
70 data["TEST"] = 23;
71
72 templateCharReplace(it, data, 0);
73
74 nlohmann::json expected = "the Test 23";
75 EXPECT_EQ(expected, j["foo"]);
76}
77
78TEST(TemplateCharReplace, increment)
79{
80 nlohmann::json j = {{"foo", "3 plus 1 equals $TEST + 1"}};
81 auto it = j.begin();
82 boost::container::flat_map<std::string, BasicVariantType> data;
83 data["TEST"] = 3;
84
85 templateCharReplace(it, data, 0);
86
87 nlohmann::json expected = "3 plus 1 equals 4";
88 EXPECT_EQ(expected, j["foo"]);
89}
90
91TEST(TemplateCharReplace, decrement)
92{
93 nlohmann::json j = {{"foo", "3 minus 1 equals $TEST - 1 !"}};
94 auto it = j.begin();
95 boost::container::flat_map<std::string, BasicVariantType> data;
96 data["TEST"] = 3;
97
98 templateCharReplace(it, data, 0);
99
100 nlohmann::json expected = "3 minus 1 equals 2 !";
101 EXPECT_EQ(expected, j["foo"]);
102}
103
104TEST(TemplateCharReplace, modulus)
105{
106 nlohmann::json j = {{"foo", "3 mod 2 equals $TEST % 2"}};
107 auto it = j.begin();
108 boost::container::flat_map<std::string, BasicVariantType> data;
109 data["TEST"] = 3;
110
111 templateCharReplace(it, data, 0);
112
113 nlohmann::json expected = "3 mod 2 equals 1";
114 EXPECT_EQ(expected, j["foo"]);
115}
116
117TEST(TemplateCharReplace, multiply)
118{
119 nlohmann::json j = {{"foo", "3 * 2 equals $TEST * 2"}};
120 auto it = j.begin();
121 boost::container::flat_map<std::string, BasicVariantType> data;
122 data["TEST"] = 3;
123
124 templateCharReplace(it, data, 0);
125
126 nlohmann::json expected = "3 * 2 equals 6";
127 EXPECT_EQ(expected, j["foo"]);
128}
129
130TEST(TemplateCharReplace, divide)
131{
132 nlohmann::json j = {{"foo", "4 / 2 equals $TEST / 2"}};
133 auto it = j.begin();
134 boost::container::flat_map<std::string, BasicVariantType> data;
135 data["TEST"] = 4;
136
137 templateCharReplace(it, data, 0);
138
139 nlohmann::json expected = "4 / 2 equals 2";
140 EXPECT_EQ(expected, j["foo"]);
James Feist8c20feb2019-08-14 15:10:11 -0700141}
142
143TEST(TemplateCharReplace, multiMath)
144{
145 nlohmann::json j = {{"foo", "4 * 2 % 6 equals $TEST * 2 % 6"}};
146 auto it = j.begin();
147 boost::container::flat_map<std::string, BasicVariantType> data;
148 data["TEST"] = 4;
149
150 templateCharReplace(it, data, 0);
151
152 nlohmann::json expected = "4 * 2 % 6 equals 2";
153 EXPECT_EQ(expected, j["foo"]);
154}
155
156TEST(TemplateCharReplace, twoReplacements)
157{
158 nlohmann::json j = {{"foo", "$FOO $BAR"}};
159 auto it = j.begin();
160 boost::container::flat_map<std::string, BasicVariantType> data;
161 data["FOO"] = std::string("foo");
162 data["BAR"] = std::string("bar");
163
164 templateCharReplace(it, data, 0);
165
166 nlohmann::json expected = "foo bar";
167 EXPECT_EQ(expected, j["foo"]);
168}
169
170TEST(TemplateCharReplace, twoReplacementsWithMath)
171{
172 nlohmann::json j = {{"foo", "4 / 2 equals $TEST / 2 $BAR"}};
173 auto it = j.begin();
174 boost::container::flat_map<std::string, BasicVariantType> data;
175 data["TEST"] = 4;
176 data["BAR"] = std::string("bar");
177
178 templateCharReplace(it, data, 0);
179
180 nlohmann::json expected = "4 / 2 equals 2 bar";
181 EXPECT_EQ(expected, j["foo"]);
James Feistb0097d42019-08-15 09:24:13 -0700182}
183
184TEST(TemplateCharReplace, hexAndWrongCase)
185{
186 nlohmann::json j = {{"Address", "0x54"},
187 {"Bus", 15},
188 {"Name", "$bus sensor 0"},
189 {"Type", "SomeType"}};
190
191 boost::container::flat_map<std::string, BasicVariantType> data;
192 data["BUS"] = 15;
193
194 for (auto it = j.begin(); it != j.end(); it++)
195 {
196 templateCharReplace(it, data, 0);
197 }
198 nlohmann::json expected = {{"Address", 84},
199 {"Bus", 15},
200 {"Name", "15 sensor 0"},
201 {"Type", "SomeType"}};
202 EXPECT_EQ(expected, j);
203}
204
205TEST(TemplateCharReplace, replaceSecondAsInt)
206{
207 nlohmann::json j = {{"foo", "twelve is $TEST"}};
208 auto it = j.begin();
209 boost::container::flat_map<std::string, BasicVariantType> data;
210 data["test"] = 12;
211
212 templateCharReplace(it, data, 0);
213
214 nlohmann::json expected = "twelve is 12";
215 EXPECT_EQ(expected, j["foo"]);
216}
James Feistc296c802019-08-28 09:26:47 -0700217
218TEST(TemplateCharReplace, singleHex)
219{
220 nlohmann::json j = {{"foo", "0x54"}};
221 auto it = j.begin();
222 boost::container::flat_map<std::string, BasicVariantType> data;
223
224 templateCharReplace(it, data, 0);
225
226 nlohmann::json expected = 84;
227 EXPECT_EQ(expected, j["foo"]);
228}
Brad Bishop9d2ef082020-08-26 15:17:55 -0400229
230TEST(MatchProbe, stringEqString)
231{
232 nlohmann::json j = R"("foo")"_json;
233 BasicVariantType v = "foo"s;
234 EXPECT_TRUE(matchProbe(j, v));
235}
236
237TEST(MatchProbe, stringRegexEqString)
238{
239 nlohmann::json j = R"("foo*")"_json;
240 BasicVariantType v = "foobar"s;
241 EXPECT_TRUE(matchProbe(j, v));
242}
243
244TEST(MatchProbe, stringNeqString)
245{
246 nlohmann::json j = R"("foobar")"_json;
247 BasicVariantType v = "foo"s;
248 EXPECT_FALSE(matchProbe(j, v));
249}
250
251TEST(MatchProbe, stringRegexError)
252{
253 nlohmann::json j = R"("foo[")"_json;
254 BasicVariantType v = "foobar"s;
Brad Bishop5d525412020-08-26 08:50:50 -0400255 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop9d2ef082020-08-26 15:17:55 -0400256}
257
Brad Bishop5d525412020-08-26 08:50:50 -0400258TEST(MatchProbe, stringZeroNeqFalse)
Brad Bishop9d2ef082020-08-26 15:17:55 -0400259{
260 nlohmann::json j = R"("0")"_json;
261 BasicVariantType v = false;
Brad Bishop5d525412020-08-26 08:50:50 -0400262 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop9d2ef082020-08-26 15:17:55 -0400263}
264
Brad Bishop5d525412020-08-26 08:50:50 -0400265TEST(MatchProbe, stringOneNeqTrue)
Brad Bishop9d2ef082020-08-26 15:17:55 -0400266{
267 nlohmann::json j = R"("1")"_json;
268 BasicVariantType v = true;
Brad Bishop5d525412020-08-26 08:50:50 -0400269 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop9d2ef082020-08-26 15:17:55 -0400270}
271
272TEST(MatchProbe, stringElevenNeqTrue)
273{
274 nlohmann::json j = R"("11")"_json;
275 BasicVariantType v = true;
276 EXPECT_FALSE(matchProbe(j, v));
277}
278
279TEST(MatchProbe, stringFalseNeqFalse)
280{
281 nlohmann::json j = R"("false")"_json;
282 BasicVariantType v = false;
283 EXPECT_FALSE(matchProbe(j, v));
284}
285
286TEST(MatchProbe, stringTrueNeqTrue)
287{
288 nlohmann::json j = R"("true")"_json;
289 BasicVariantType v = true;
290 EXPECT_FALSE(matchProbe(j, v));
291}
292
293TEST(MatchProbe, stringFalseNeqTrue)
294{
295 nlohmann::json j = R"("false")"_json;
296 BasicVariantType v = true;
297 EXPECT_FALSE(matchProbe(j, v));
298}
299
Brad Bishop5d525412020-08-26 08:50:50 -0400300TEST(MatchProbe, stringNeqUint8)
Brad Bishop9d2ef082020-08-26 15:17:55 -0400301{
302 nlohmann::json j = R"("255")"_json;
303 BasicVariantType v = uint8_t(255);
Brad Bishop5d525412020-08-26 08:50:50 -0400304 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop9d2ef082020-08-26 15:17:55 -0400305}
306
307TEST(MatchProbe, stringNeqUint8Overflow)
308{
309 nlohmann::json j = R"("65535")"_json;
310 BasicVariantType v = uint8_t(255);
311 EXPECT_FALSE(matchProbe(j, v));
312}
313
314TEST(MatchProbe, stringFalseNeqUint8Zero)
315{
316 nlohmann::json j = R"("false")"_json;
317 BasicVariantType v = uint8_t(0);
318 EXPECT_FALSE(matchProbe(j, v));
319}
320
321TEST(MatchProbe, stringTrueNeqUint8Zero)
322{
323 nlohmann::json j = R"("true")"_json;
324 BasicVariantType v = uint8_t(1);
325 EXPECT_FALSE(matchProbe(j, v));
326}
327
Brad Bishop5d525412020-08-26 08:50:50 -0400328TEST(MatchProbe, stringNeqUint32)
Brad Bishop9d2ef082020-08-26 15:17:55 -0400329{
330 nlohmann::json j = R"("11")"_json;
331 BasicVariantType v = uint32_t(11);
Brad Bishop9d2ef082020-08-26 15:17:55 -0400332 EXPECT_FALSE(matchProbe(j, v));
333}
334
Brad Bishop9d2ef082020-08-26 15:17:55 -0400335TEST(MatchProbe, stringNeqInt32)
336{
Brad Bishop5d525412020-08-26 08:50:50 -0400337 nlohmann::json j = R"("-11")"_json;
Brad Bishop9d2ef082020-08-26 15:17:55 -0400338 BasicVariantType v = int32_t(-11);
339 EXPECT_FALSE(matchProbe(j, v));
340}
341
Brad Bishop5d525412020-08-26 08:50:50 -0400342TEST(MatchProbe, stringRegexNeqInt32)
Brad Bishop9d2ef082020-08-26 15:17:55 -0400343{
344 nlohmann::json j = R"("1*4")"_json;
345 BasicVariantType v = int32_t(124);
Brad Bishop5d525412020-08-26 08:50:50 -0400346 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop9d2ef082020-08-26 15:17:55 -0400347}
348
349TEST(MatchProbe, stringNeqUint64)
350{
351 nlohmann::json j = R"("foo")"_json;
352 BasicVariantType v = uint64_t(65535);
353 EXPECT_FALSE(matchProbe(j, v));
354}
355
Brad Bishop9d2ef082020-08-26 15:17:55 -0400356TEST(MatchProbe, stringNeqDouble)
357{
Brad Bishop5d525412020-08-26 08:50:50 -0400358 nlohmann::json j = R"("123.4")"_json;
Brad Bishop9d2ef082020-08-26 15:17:55 -0400359 BasicVariantType v = double(123.4);
360 EXPECT_FALSE(matchProbe(j, v));
361}
362
363TEST(MatchProbe, stringNeqEmpty)
364{
365 nlohmann::json j = R"("-123.4")"_json;
366 BasicVariantType v;
367 EXPECT_FALSE(matchProbe(j, v));
368}
Brad Bishopc5eba592020-08-28 10:38:24 -0400369
Brad Bishopcd1868e2020-08-28 17:58:52 -0400370TEST(MatchProbe, stringNeqArray)
371{
372 nlohmann::json j = R"("-123.4")"_json;
373 BasicVariantType v = std::vector<uint8_t>{1, 2};
374 EXPECT_FALSE(matchProbe(j, v));
375}
376
Brad Bishop5d525412020-08-26 08:50:50 -0400377TEST(MatchProbe, boolNeqString)
Brad Bishopc5eba592020-08-28 10:38:24 -0400378{
379 nlohmann::json j = R"(false)"_json;
380 BasicVariantType v = "false"s;
Brad Bishop5d525412020-08-26 08:50:50 -0400381 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc5eba592020-08-28 10:38:24 -0400382}
383
384TEST(MatchProbe, trueEqTrue)
385{
386 nlohmann::json j = R"(true)"_json;
387 BasicVariantType v = true;
388 EXPECT_TRUE(matchProbe(j, v));
389}
390
391TEST(MatchProbe, falseEqFalse)
392{
393 nlohmann::json j = R"(false)"_json;
394 BasicVariantType v = false;
395 EXPECT_TRUE(matchProbe(j, v));
396}
397
398TEST(MatchProbe, trueNeqFalse)
399{
400 nlohmann::json j = R"(true)"_json;
401 BasicVariantType v = false;
402 EXPECT_FALSE(matchProbe(j, v));
403}
404
405TEST(MatchProbe, trueNeqInt32Zero)
406{
407 nlohmann::json j = R"(true)"_json;
408 BasicVariantType v = int32_t(0);
409 EXPECT_FALSE(matchProbe(j, v));
410}
411
412TEST(MatchProbe, trueNeqInt32NegativeOne)
413{
414 nlohmann::json j = R"(true)"_json;
415 BasicVariantType v = int32_t(-1);
416 EXPECT_FALSE(matchProbe(j, v));
417}
418
419TEST(MatchProbe, falseNeqUint32One)
420{
421 nlohmann::json j = R"(false)"_json;
422 BasicVariantType v = uint32_t(1);
423 EXPECT_FALSE(matchProbe(j, v));
424}
425
Brad Bishop5d525412020-08-26 08:50:50 -0400426TEST(MatchProbe, falseNeqUint32Zero)
Brad Bishopc5eba592020-08-28 10:38:24 -0400427{
428 nlohmann::json j = R"(false)"_json;
429 BasicVariantType v = uint32_t(0);
Brad Bishop5d525412020-08-26 08:50:50 -0400430 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc5eba592020-08-28 10:38:24 -0400431}
432
433TEST(MatchProbe, trueNeqDoubleNegativeOne)
434{
435 nlohmann::json j = R"(true)"_json;
436 BasicVariantType v = double(-1.1);
437 EXPECT_FALSE(matchProbe(j, v));
438}
439
Brad Bishop5d525412020-08-26 08:50:50 -0400440TEST(MatchProbe, trueNeqDoubleOne)
Brad Bishopc5eba592020-08-28 10:38:24 -0400441{
442 nlohmann::json j = R"(true)"_json;
443 BasicVariantType v = double(1.0);
Brad Bishop5d525412020-08-26 08:50:50 -0400444 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc5eba592020-08-28 10:38:24 -0400445}
446
447TEST(MatchProbe, falseNeqDoubleOne)
448{
449 nlohmann::json j = R"(false)"_json;
450 BasicVariantType v = double(1.0);
451 EXPECT_FALSE(matchProbe(j, v));
452}
453
Brad Bishop5d525412020-08-26 08:50:50 -0400454TEST(MatchProbe, falseNeqDoubleZero)
Brad Bishopc5eba592020-08-28 10:38:24 -0400455{
456 nlohmann::json j = R"(false)"_json;
457 BasicVariantType v = double(0.0);
Brad Bishop5d525412020-08-26 08:50:50 -0400458 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc5eba592020-08-28 10:38:24 -0400459}
460
Brad Bishop5d525412020-08-26 08:50:50 -0400461TEST(MatchProbe, falseNeqEmpty)
Brad Bishopc5eba592020-08-28 10:38:24 -0400462{
463 nlohmann::json j = R"(false)"_json;
464 BasicVariantType v;
Brad Bishop5d525412020-08-26 08:50:50 -0400465 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc5eba592020-08-28 10:38:24 -0400466}
467
Brad Bishop5d525412020-08-26 08:50:50 -0400468TEST(MatchProbe, trueNeqEmpty)
Brad Bishopc5eba592020-08-28 10:38:24 -0400469{
470 nlohmann::json j = R"(true)"_json;
471 BasicVariantType v;
Brad Bishop5d525412020-08-26 08:50:50 -0400472 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc5eba592020-08-28 10:38:24 -0400473}
Brad Bishopc2af5312020-08-28 10:39:49 -0400474
Brad Bishopcd1868e2020-08-28 17:58:52 -0400475TEST(MatchProbe, trueNeqArray)
476{
477 nlohmann::json j = R"(true)"_json;
478 BasicVariantType v = std::vector<uint8_t>{1, 2};
479 EXPECT_FALSE(matchProbe(j, v));
480}
481
Brad Bishop5d525412020-08-26 08:50:50 -0400482TEST(MatchProbe, uintNeqString)
Brad Bishopc2af5312020-08-28 10:39:49 -0400483{
484 nlohmann::json j = R"(11)"_json;
485 BasicVariantType v = "11"s;
Brad Bishop5d525412020-08-26 08:50:50 -0400486 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc2af5312020-08-28 10:39:49 -0400487}
488
489TEST(MatchProbe, uintNeqTrue)
490{
Brad Bishop5d525412020-08-26 08:50:50 -0400491 nlohmann::json j = R"(1)"_json;
Brad Bishopc2af5312020-08-28 10:39:49 -0400492 BasicVariantType v = true;
493 EXPECT_FALSE(matchProbe(j, v));
494}
495
Brad Bishop5d525412020-08-26 08:50:50 -0400496TEST(MatchProbe, uintNeqFalse)
497{
498 nlohmann::json j = R"(0)"_json;
499 BasicVariantType v = false;
500 EXPECT_FALSE(matchProbe(j, v));
501}
502
Brad Bishopc2af5312020-08-28 10:39:49 -0400503TEST(MatchProbe, uintEqUint8)
504{
505 nlohmann::json j = R"(11)"_json;
506 BasicVariantType v = uint8_t(11);
507 EXPECT_TRUE(matchProbe(j, v));
508}
509
510TEST(MatchProbe, uintNeqUint8)
511{
512 nlohmann::json j = R"(11)"_json;
513 BasicVariantType v = uint8_t(12);
514 EXPECT_FALSE(matchProbe(j, v));
515}
516
517TEST(MatchProbe, uintNeqUint8Overflow)
518{
519 nlohmann::json j = R"(65535)"_json;
520 BasicVariantType v = uint8_t(255);
521 EXPECT_FALSE(matchProbe(j, v));
522}
523
524TEST(MatchProbe, uintEqInt8)
525{
526 nlohmann::json j = R"(11)"_json;
527 BasicVariantType v = int8_t(11);
528 EXPECT_TRUE(matchProbe(j, v));
529}
530
531TEST(MatchProbe, uintEqDouble)
532{
533 nlohmann::json j = R"(11)"_json;
534 BasicVariantType v = double(11.0);
535 EXPECT_TRUE(matchProbe(j, v));
536}
537
Brad Bishop5d525412020-08-26 08:50:50 -0400538TEST(MatchProbe, uintNeqDouble)
Brad Bishopc2af5312020-08-28 10:39:49 -0400539{
540 nlohmann::json j = R"(11)"_json;
541 BasicVariantType v = double(11.7);
Brad Bishop5d525412020-08-26 08:50:50 -0400542 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc2af5312020-08-28 10:39:49 -0400543}
544
Brad Bishop5d525412020-08-26 08:50:50 -0400545TEST(MatchProbe, uintNeqEmpty)
Brad Bishopc2af5312020-08-28 10:39:49 -0400546{
547 nlohmann::json j = R"(11)"_json;
548 BasicVariantType v;
Brad Bishop5d525412020-08-26 08:50:50 -0400549 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc2af5312020-08-28 10:39:49 -0400550}
Brad Bishop667e0502020-08-28 10:41:40 -0400551
Brad Bishopcd1868e2020-08-28 17:58:52 -0400552TEST(MatchProbe, uintNeqArray)
553{
554 nlohmann::json j = R"(11)"_json;
555 BasicVariantType v = std::vector<uint8_t>{11};
556 EXPECT_FALSE(matchProbe(j, v));
557}
558
Brad Bishop5d525412020-08-26 08:50:50 -0400559TEST(MatchProbe, intNeqString)
Brad Bishop667e0502020-08-28 10:41:40 -0400560{
561 nlohmann::json j = R"(-11)"_json;
562 BasicVariantType v = "-11"s;
Brad Bishop5d525412020-08-26 08:50:50 -0400563 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop667e0502020-08-28 10:41:40 -0400564}
565
566TEST(MatchProbe, intNeqTrue)
567{
568 nlohmann::json j = R"(-1)"_json;
569 BasicVariantType v = true;
570 EXPECT_FALSE(matchProbe(j, v));
571}
572
573TEST(MatchProbe, intNeqUint8)
574{
575 nlohmann::json j = R"(-11)"_json;
576 BasicVariantType v = uint8_t(11);
577 EXPECT_FALSE(matchProbe(j, v));
578}
579
580TEST(MatchProbe, intEqInt8)
581{
582 nlohmann::json j = R"(-11)"_json;
583 BasicVariantType v = int8_t(-11);
584 EXPECT_TRUE(matchProbe(j, v));
585}
586
587TEST(MatchProbe, intNeqDouble)
588{
589 nlohmann::json j = R"(-124)"_json;
590 BasicVariantType v = double(-123.0);
591 EXPECT_FALSE(matchProbe(j, v));
592}
593
594TEST(MatchProbe, intEqDouble)
595{
596 nlohmann::json j = R"(-11)"_json;
597 BasicVariantType v = double(-11.0);
598 EXPECT_TRUE(matchProbe(j, v));
599}
600
Brad Bishop5d525412020-08-26 08:50:50 -0400601TEST(MatchProbe, intNeqDoubleRound)
Brad Bishop667e0502020-08-28 10:41:40 -0400602{
603 nlohmann::json j = R"(-11)"_json;
604 BasicVariantType v = double(-11.7);
Brad Bishop5d525412020-08-26 08:50:50 -0400605 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop667e0502020-08-28 10:41:40 -0400606}
607
Brad Bishop5d525412020-08-26 08:50:50 -0400608TEST(MatchProbe, intNeqEmpty)
Brad Bishop667e0502020-08-28 10:41:40 -0400609{
610 nlohmann::json j = R"(-11)"_json;
611 BasicVariantType v;
Brad Bishop5d525412020-08-26 08:50:50 -0400612 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop667e0502020-08-28 10:41:40 -0400613}
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400614
Brad Bishopcd1868e2020-08-28 17:58:52 -0400615TEST(MatchProbe, intNeqArray)
616{
617 nlohmann::json j = R"(-11)"_json;
618 BasicVariantType v = std::vector<uint8_t>{11};
619 EXPECT_FALSE(matchProbe(j, v));
620}
621
Brad Bishop5d525412020-08-26 08:50:50 -0400622TEST(MatchProbe, doubleNeqString)
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400623{
624 nlohmann::json j = R"(0.0)"_json;
625 BasicVariantType v = "0.0"s;
Brad Bishop5d525412020-08-26 08:50:50 -0400626 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400627}
628
Brad Bishop5d525412020-08-26 08:50:50 -0400629TEST(MatchProbe, doubleNeqFalse)
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400630{
631 nlohmann::json j = R"(0.0)"_json;
632 BasicVariantType v = false;
Brad Bishop5d525412020-08-26 08:50:50 -0400633 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400634}
635
636TEST(MatchProbe, doubleNeqTrue)
637{
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400638 nlohmann::json j = R"(1.0)"_json;
639 BasicVariantType v = true;
Brad Bishop5d525412020-08-26 08:50:50 -0400640 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400641}
642
643TEST(MatchProbe, doubleEqInt32)
644{
645 nlohmann::json j = R"(-124.0)"_json;
646 BasicVariantType v = int32_t(-124);
647 EXPECT_TRUE(matchProbe(j, v));
648}
649
650TEST(MatchProbe, doubleNeqInt32)
651{
652 nlohmann::json j = R"(-124.0)"_json;
653 BasicVariantType v = int32_t(-123);
654 EXPECT_FALSE(matchProbe(j, v));
655}
656
657TEST(MatchProbe, doubleRoundNeqInt)
658{
659 nlohmann::json j = R"(124.7)"_json;
660 BasicVariantType v = int32_t(124);
661 EXPECT_FALSE(matchProbe(j, v));
662}
663TEST(MatchProbe, doubleEqDouble)
664{
665 nlohmann::json j = R"(-124.2)"_json;
666 BasicVariantType v = double(-124.2);
667 EXPECT_TRUE(matchProbe(j, v));
668}
669
670TEST(MatchProbe, doubleNeqDouble)
671{
672 nlohmann::json j = R"(-124.3)"_json;
673 BasicVariantType v = double(-124.2);
674 EXPECT_FALSE(matchProbe(j, v));
675}
676
Brad Bishop5d525412020-08-26 08:50:50 -0400677TEST(MatchProbe, doubleNeqEmpty)
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400678{
679 nlohmann::json j = R"(-11.0)"_json;
680 BasicVariantType v;
Brad Bishop5d525412020-08-26 08:50:50 -0400681 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400682}
Brad Bishopd14c2e22020-08-28 10:43:40 -0400683
Brad Bishopcd1868e2020-08-28 17:58:52 -0400684TEST(MatchProbe, doubleNeqArray)
685{
686 nlohmann::json j = R"(-11.2)"_json;
687 BasicVariantType v = std::vector<uint8_t>{11};
688 EXPECT_FALSE(matchProbe(j, v));
689}
690
Brad Bishopd14c2e22020-08-28 10:43:40 -0400691TEST(MatchProbe, arrayNeqString)
692{
693 nlohmann::json j = R"([1, 2])"_json;
694 BasicVariantType v = "hello"s;
695 EXPECT_FALSE(matchProbe(j, v));
696}
697
698TEST(MatchProbe, arrayNeqFalse)
699{
700 nlohmann::json j = R"([1, 2])"_json;
701 BasicVariantType v = false;
702 EXPECT_FALSE(matchProbe(j, v));
703}
704
705TEST(MatchProbe, arrayNeqTrue)
706{
707 nlohmann::json j = R"([1, 2])"_json;
708 BasicVariantType v = true;
709 EXPECT_FALSE(matchProbe(j, v));
710}
711
712TEST(MatchProbe, arrayNeqUint8)
713{
714 nlohmann::json j = R"([1, 2])"_json;
715 BasicVariantType v = uint8_t(1);
716 EXPECT_FALSE(matchProbe(j, v));
717}
718
719TEST(MatchProbe, arrayNeqInt32)
720{
721 nlohmann::json j = R"([1, 2])"_json;
722 BasicVariantType v = int32_t(-1);
723 EXPECT_FALSE(matchProbe(j, v));
724}
725
726TEST(MatchProbe, arrayNeqDouble)
727{
728 nlohmann::json j = R"([1, 2])"_json;
729 BasicVariantType v = double(1.1);
730 EXPECT_FALSE(matchProbe(j, v));
731}
Brad Bishop6660e2a2020-08-28 10:44:41 -0400732
Brad Bishopcd1868e2020-08-28 17:58:52 -0400733TEST(MatchProbe, arrayEqArray)
734{
735 nlohmann::json j = R"([1, 2])"_json;
736 BasicVariantType v = std::vector<uint8_t>{1, 2};
737 EXPECT_TRUE(matchProbe(j, v));
738}
739
740TEST(MatchProbe, arrayNeqArrayDiffSize1)
741{
742 nlohmann::json j = R"([1, 2, 3])"_json;
743 BasicVariantType v = std::vector<uint8_t>{1, 2};
744 EXPECT_FALSE(matchProbe(j, v));
745}
746
747TEST(MatchProbe, arrayNeqArrayDiffSize2)
748{
749 nlohmann::json j = R"([1, 2])"_json;
750 BasicVariantType v = std::vector<uint8_t>{1, 2, 3};
751 EXPECT_FALSE(matchProbe(j, v));
752}
753
754TEST(MatchProbe, emptyArrayEqEmptyArray)
755{
756 nlohmann::json j = R"([])"_json;
757 BasicVariantType v = std::vector<uint8_t>{};
758 EXPECT_TRUE(matchProbe(j, v));
759}
760
761TEST(MatchProbe, emptyArrayNeqArray)
762{
763 nlohmann::json j = R"([])"_json;
764 BasicVariantType v = std::vector<uint8_t>{1};
765 EXPECT_FALSE(matchProbe(j, v));
766}
767
768TEST(MatchProbe, arrayNeqEmptyArray)
769{
770 nlohmann::json j = R"([1])"_json;
771 BasicVariantType v = std::vector<uint8_t>{};
772 EXPECT_FALSE(matchProbe(j, v));
773}
774
Brad Bishop6660e2a2020-08-28 10:44:41 -0400775TEST(MatchProbe, objNeqString)
776{
777 nlohmann::json j = R"({"foo": "bar"})"_json;
778 BasicVariantType v = "hello"s;
779 EXPECT_FALSE(matchProbe(j, v));
780}
781
782TEST(MatchProbe, objNeqFalse)
783{
784 nlohmann::json j = R"({"foo": "bar"})"_json;
785 BasicVariantType v = false;
786 EXPECT_FALSE(matchProbe(j, v));
787}
788
789TEST(MatchProbe, objNeqTrue)
790{
791 nlohmann::json j = R"({"foo": "bar"})"_json;
792 BasicVariantType v = true;
793 EXPECT_FALSE(matchProbe(j, v));
794}
795
796TEST(MatchProbe, objNeqUint8)
797{
798 nlohmann::json j = R"({"foo": "bar"})"_json;
799 BasicVariantType v = uint8_t(1);
800 EXPECT_FALSE(matchProbe(j, v));
801}
802
803TEST(MatchProbe, objNeqInt32)
804{
805 nlohmann::json j = R"({"foo": "bar"})"_json;
806 BasicVariantType v = int32_t(-1);
807 EXPECT_FALSE(matchProbe(j, v));
808}
809
810TEST(MatchProbe, objNeqDouble)
811{
812 nlohmann::json j = R"({"foo": "bar"})"_json;
813 BasicVariantType v = double(1.1);
814 EXPECT_FALSE(matchProbe(j, v));
815}
Brad Bishopc776c412020-08-28 10:45:25 -0400816
Brad Bishopcd1868e2020-08-28 17:58:52 -0400817TEST(MatchProbe, objNeqArray)
818{
819 nlohmann::json j = R"({"foo": "bar"})"_json;
820 BasicVariantType v = std::vector<uint8_t>{1, 2};
821 EXPECT_FALSE(matchProbe(j, v));
822}
823
Brad Bishopc776c412020-08-28 10:45:25 -0400824TEST(MatchProbe, nullNeqString)
825{
826 nlohmann::json j = R"(null)"_json;
827 BasicVariantType v = "hello"s;
828 EXPECT_FALSE(matchProbe(j, v));
829}
830
831TEST(MatchProbe, nullNeqFalse)
832{
833 nlohmann::json j = R"(null)"_json;
834 BasicVariantType v = false;
835 EXPECT_FALSE(matchProbe(j, v));
836}
837
838TEST(MatchProbe, nullNeqTrue)
839{
840 nlohmann::json j = R"(null)"_json;
841 BasicVariantType v = true;
842 EXPECT_FALSE(matchProbe(j, v));
843}
844
845TEST(MatchProbe, nullNeqUint8)
846{
847 nlohmann::json j = R"(null)"_json;
848 BasicVariantType v = uint8_t(1);
849 EXPECT_FALSE(matchProbe(j, v));
850}
851
852TEST(MatchProbe, nullNeqInt32)
853{
854 nlohmann::json j = R"(null)"_json;
855 BasicVariantType v = int32_t(-1);
856 EXPECT_FALSE(matchProbe(j, v));
857}
858
859TEST(MatchProbe, nullNeqDouble)
860{
861 nlohmann::json j = R"(null)"_json;
862 BasicVariantType v = double(1.1);
863 EXPECT_FALSE(matchProbe(j, v));
864}
Brad Bishopcd1868e2020-08-28 17:58:52 -0400865
866TEST(MatchProbe, nullNeqArray)
867{
868 nlohmann::json j = R"(null)"_json;
869 BasicVariantType v = std::vector<uint8_t>{};
870 EXPECT_FALSE(matchProbe(j, v));
871}