blob: deaf06ccc721e6de8e46bca1997da59d975c8dcf [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";
Zhikui Rena0d1b3f2021-10-05 16:21:56 -0700181}
182
183TEST(TemplateCharReplace, twoReplacementsWithMath2)
184{
185 nlohmann::json j = {{"foo", "4 / 2 equals $ADDRESS / 2 $BAR"}};
186 auto it = j.begin();
187 boost::container::flat_map<std::string, BasicVariantType> data;
188 data["ADDRESS"] = 4;
189 data["BAR"] = std::string("bar");
190
191 templateCharReplace(it, data, 0);
192
193 nlohmann::json expected = "4 / 2 equals 2 bar";
James Feist8c20feb2019-08-14 15:10:11 -0700194 EXPECT_EQ(expected, j["foo"]);
James Feistb0097d42019-08-15 09:24:13 -0700195}
196
197TEST(TemplateCharReplace, hexAndWrongCase)
198{
199 nlohmann::json j = {{"Address", "0x54"},
200 {"Bus", 15},
201 {"Name", "$bus sensor 0"},
202 {"Type", "SomeType"}};
203
204 boost::container::flat_map<std::string, BasicVariantType> data;
205 data["BUS"] = 15;
206
207 for (auto it = j.begin(); it != j.end(); it++)
208 {
209 templateCharReplace(it, data, 0);
210 }
211 nlohmann::json expected = {{"Address", 84},
212 {"Bus", 15},
213 {"Name", "15 sensor 0"},
214 {"Type", "SomeType"}};
215 EXPECT_EQ(expected, j);
216}
217
218TEST(TemplateCharReplace, replaceSecondAsInt)
219{
220 nlohmann::json j = {{"foo", "twelve is $TEST"}};
221 auto it = j.begin();
222 boost::container::flat_map<std::string, BasicVariantType> data;
223 data["test"] = 12;
224
225 templateCharReplace(it, data, 0);
226
227 nlohmann::json expected = "twelve is 12";
228 EXPECT_EQ(expected, j["foo"]);
229}
James Feistc296c802019-08-28 09:26:47 -0700230
231TEST(TemplateCharReplace, singleHex)
232{
233 nlohmann::json j = {{"foo", "0x54"}};
234 auto it = j.begin();
235 boost::container::flat_map<std::string, BasicVariantType> data;
236
237 templateCharReplace(it, data, 0);
238
239 nlohmann::json expected = 84;
240 EXPECT_EQ(expected, j["foo"]);
241}
Brad Bishop9d2ef082020-08-26 15:17:55 -0400242
243TEST(MatchProbe, stringEqString)
244{
245 nlohmann::json j = R"("foo")"_json;
246 BasicVariantType v = "foo"s;
247 EXPECT_TRUE(matchProbe(j, v));
248}
249
250TEST(MatchProbe, stringRegexEqString)
251{
252 nlohmann::json j = R"("foo*")"_json;
253 BasicVariantType v = "foobar"s;
254 EXPECT_TRUE(matchProbe(j, v));
255}
256
257TEST(MatchProbe, stringNeqString)
258{
259 nlohmann::json j = R"("foobar")"_json;
260 BasicVariantType v = "foo"s;
261 EXPECT_FALSE(matchProbe(j, v));
262}
263
264TEST(MatchProbe, stringRegexError)
265{
266 nlohmann::json j = R"("foo[")"_json;
267 BasicVariantType v = "foobar"s;
Brad Bishop5d525412020-08-26 08:50:50 -0400268 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop9d2ef082020-08-26 15:17:55 -0400269}
270
Brad Bishop5d525412020-08-26 08:50:50 -0400271TEST(MatchProbe, stringZeroNeqFalse)
Brad Bishop9d2ef082020-08-26 15:17:55 -0400272{
273 nlohmann::json j = R"("0")"_json;
274 BasicVariantType v = false;
Brad Bishop5d525412020-08-26 08:50:50 -0400275 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop9d2ef082020-08-26 15:17:55 -0400276}
277
Brad Bishop5d525412020-08-26 08:50:50 -0400278TEST(MatchProbe, stringOneNeqTrue)
Brad Bishop9d2ef082020-08-26 15:17:55 -0400279{
280 nlohmann::json j = R"("1")"_json;
281 BasicVariantType v = true;
Brad Bishop5d525412020-08-26 08:50:50 -0400282 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop9d2ef082020-08-26 15:17:55 -0400283}
284
285TEST(MatchProbe, stringElevenNeqTrue)
286{
287 nlohmann::json j = R"("11")"_json;
288 BasicVariantType v = true;
289 EXPECT_FALSE(matchProbe(j, v));
290}
291
292TEST(MatchProbe, stringFalseNeqFalse)
293{
294 nlohmann::json j = R"("false")"_json;
295 BasicVariantType v = false;
296 EXPECT_FALSE(matchProbe(j, v));
297}
298
299TEST(MatchProbe, stringTrueNeqTrue)
300{
301 nlohmann::json j = R"("true")"_json;
302 BasicVariantType v = true;
303 EXPECT_FALSE(matchProbe(j, v));
304}
305
306TEST(MatchProbe, stringFalseNeqTrue)
307{
308 nlohmann::json j = R"("false")"_json;
309 BasicVariantType v = true;
310 EXPECT_FALSE(matchProbe(j, v));
311}
312
Brad Bishop5d525412020-08-26 08:50:50 -0400313TEST(MatchProbe, stringNeqUint8)
Brad Bishop9d2ef082020-08-26 15:17:55 -0400314{
315 nlohmann::json j = R"("255")"_json;
316 BasicVariantType v = uint8_t(255);
Brad Bishop5d525412020-08-26 08:50:50 -0400317 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop9d2ef082020-08-26 15:17:55 -0400318}
319
320TEST(MatchProbe, stringNeqUint8Overflow)
321{
322 nlohmann::json j = R"("65535")"_json;
323 BasicVariantType v = uint8_t(255);
324 EXPECT_FALSE(matchProbe(j, v));
325}
326
327TEST(MatchProbe, stringFalseNeqUint8Zero)
328{
329 nlohmann::json j = R"("false")"_json;
330 BasicVariantType v = uint8_t(0);
331 EXPECT_FALSE(matchProbe(j, v));
332}
333
334TEST(MatchProbe, stringTrueNeqUint8Zero)
335{
336 nlohmann::json j = R"("true")"_json;
337 BasicVariantType v = uint8_t(1);
338 EXPECT_FALSE(matchProbe(j, v));
339}
340
Brad Bishop5d525412020-08-26 08:50:50 -0400341TEST(MatchProbe, stringNeqUint32)
Brad Bishop9d2ef082020-08-26 15:17:55 -0400342{
343 nlohmann::json j = R"("11")"_json;
344 BasicVariantType v = uint32_t(11);
Brad Bishop9d2ef082020-08-26 15:17:55 -0400345 EXPECT_FALSE(matchProbe(j, v));
346}
347
Brad Bishop9d2ef082020-08-26 15:17:55 -0400348TEST(MatchProbe, stringNeqInt32)
349{
Brad Bishop5d525412020-08-26 08:50:50 -0400350 nlohmann::json j = R"("-11")"_json;
Brad Bishop9d2ef082020-08-26 15:17:55 -0400351 BasicVariantType v = int32_t(-11);
352 EXPECT_FALSE(matchProbe(j, v));
353}
354
Brad Bishop5d525412020-08-26 08:50:50 -0400355TEST(MatchProbe, stringRegexNeqInt32)
Brad Bishop9d2ef082020-08-26 15:17:55 -0400356{
357 nlohmann::json j = R"("1*4")"_json;
358 BasicVariantType v = int32_t(124);
Brad Bishop5d525412020-08-26 08:50:50 -0400359 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop9d2ef082020-08-26 15:17:55 -0400360}
361
362TEST(MatchProbe, stringNeqUint64)
363{
364 nlohmann::json j = R"("foo")"_json;
365 BasicVariantType v = uint64_t(65535);
366 EXPECT_FALSE(matchProbe(j, v));
367}
368
Brad Bishop9d2ef082020-08-26 15:17:55 -0400369TEST(MatchProbe, stringNeqDouble)
370{
Brad Bishop5d525412020-08-26 08:50:50 -0400371 nlohmann::json j = R"("123.4")"_json;
Brad Bishop9d2ef082020-08-26 15:17:55 -0400372 BasicVariantType v = double(123.4);
373 EXPECT_FALSE(matchProbe(j, v));
374}
375
376TEST(MatchProbe, stringNeqEmpty)
377{
378 nlohmann::json j = R"("-123.4")"_json;
379 BasicVariantType v;
380 EXPECT_FALSE(matchProbe(j, v));
381}
Brad Bishopc5eba592020-08-28 10:38:24 -0400382
Brad Bishopcd1868e2020-08-28 17:58:52 -0400383TEST(MatchProbe, stringNeqArray)
384{
385 nlohmann::json j = R"("-123.4")"_json;
386 BasicVariantType v = std::vector<uint8_t>{1, 2};
387 EXPECT_FALSE(matchProbe(j, v));
388}
389
Brad Bishop5d525412020-08-26 08:50:50 -0400390TEST(MatchProbe, boolNeqString)
Brad Bishopc5eba592020-08-28 10:38:24 -0400391{
392 nlohmann::json j = R"(false)"_json;
393 BasicVariantType v = "false"s;
Brad Bishop5d525412020-08-26 08:50:50 -0400394 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc5eba592020-08-28 10:38:24 -0400395}
396
397TEST(MatchProbe, trueEqTrue)
398{
399 nlohmann::json j = R"(true)"_json;
400 BasicVariantType v = true;
401 EXPECT_TRUE(matchProbe(j, v));
402}
403
404TEST(MatchProbe, falseEqFalse)
405{
406 nlohmann::json j = R"(false)"_json;
407 BasicVariantType v = false;
408 EXPECT_TRUE(matchProbe(j, v));
409}
410
411TEST(MatchProbe, trueNeqFalse)
412{
413 nlohmann::json j = R"(true)"_json;
414 BasicVariantType v = false;
415 EXPECT_FALSE(matchProbe(j, v));
416}
417
418TEST(MatchProbe, trueNeqInt32Zero)
419{
420 nlohmann::json j = R"(true)"_json;
421 BasicVariantType v = int32_t(0);
422 EXPECT_FALSE(matchProbe(j, v));
423}
424
425TEST(MatchProbe, trueNeqInt32NegativeOne)
426{
427 nlohmann::json j = R"(true)"_json;
428 BasicVariantType v = int32_t(-1);
429 EXPECT_FALSE(matchProbe(j, v));
430}
431
432TEST(MatchProbe, falseNeqUint32One)
433{
434 nlohmann::json j = R"(false)"_json;
435 BasicVariantType v = uint32_t(1);
436 EXPECT_FALSE(matchProbe(j, v));
437}
438
Brad Bishop5d525412020-08-26 08:50:50 -0400439TEST(MatchProbe, falseNeqUint32Zero)
Brad Bishopc5eba592020-08-28 10:38:24 -0400440{
441 nlohmann::json j = R"(false)"_json;
442 BasicVariantType v = uint32_t(0);
Brad Bishop5d525412020-08-26 08:50:50 -0400443 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc5eba592020-08-28 10:38:24 -0400444}
445
446TEST(MatchProbe, trueNeqDoubleNegativeOne)
447{
448 nlohmann::json j = R"(true)"_json;
449 BasicVariantType v = double(-1.1);
450 EXPECT_FALSE(matchProbe(j, v));
451}
452
Brad Bishop5d525412020-08-26 08:50:50 -0400453TEST(MatchProbe, trueNeqDoubleOne)
Brad Bishopc5eba592020-08-28 10:38:24 -0400454{
455 nlohmann::json j = R"(true)"_json;
456 BasicVariantType v = double(1.0);
Brad Bishop5d525412020-08-26 08:50:50 -0400457 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc5eba592020-08-28 10:38:24 -0400458}
459
460TEST(MatchProbe, falseNeqDoubleOne)
461{
462 nlohmann::json j = R"(false)"_json;
463 BasicVariantType v = double(1.0);
464 EXPECT_FALSE(matchProbe(j, v));
465}
466
Brad Bishop5d525412020-08-26 08:50:50 -0400467TEST(MatchProbe, falseNeqDoubleZero)
Brad Bishopc5eba592020-08-28 10:38:24 -0400468{
469 nlohmann::json j = R"(false)"_json;
470 BasicVariantType v = double(0.0);
Brad Bishop5d525412020-08-26 08:50:50 -0400471 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc5eba592020-08-28 10:38:24 -0400472}
473
Brad Bishop5d525412020-08-26 08:50:50 -0400474TEST(MatchProbe, falseNeqEmpty)
Brad Bishopc5eba592020-08-28 10:38:24 -0400475{
476 nlohmann::json j = R"(false)"_json;
477 BasicVariantType v;
Brad Bishop5d525412020-08-26 08:50:50 -0400478 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc5eba592020-08-28 10:38:24 -0400479}
480
Brad Bishop5d525412020-08-26 08:50:50 -0400481TEST(MatchProbe, trueNeqEmpty)
Brad Bishopc5eba592020-08-28 10:38:24 -0400482{
483 nlohmann::json j = R"(true)"_json;
484 BasicVariantType v;
Brad Bishop5d525412020-08-26 08:50:50 -0400485 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc5eba592020-08-28 10:38:24 -0400486}
Brad Bishopc2af5312020-08-28 10:39:49 -0400487
Brad Bishopcd1868e2020-08-28 17:58:52 -0400488TEST(MatchProbe, trueNeqArray)
489{
490 nlohmann::json j = R"(true)"_json;
491 BasicVariantType v = std::vector<uint8_t>{1, 2};
492 EXPECT_FALSE(matchProbe(j, v));
493}
494
Brad Bishop5d525412020-08-26 08:50:50 -0400495TEST(MatchProbe, uintNeqString)
Brad Bishopc2af5312020-08-28 10:39:49 -0400496{
497 nlohmann::json j = R"(11)"_json;
498 BasicVariantType v = "11"s;
Brad Bishop5d525412020-08-26 08:50:50 -0400499 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc2af5312020-08-28 10:39:49 -0400500}
501
502TEST(MatchProbe, uintNeqTrue)
503{
Brad Bishop5d525412020-08-26 08:50:50 -0400504 nlohmann::json j = R"(1)"_json;
Brad Bishopc2af5312020-08-28 10:39:49 -0400505 BasicVariantType v = true;
506 EXPECT_FALSE(matchProbe(j, v));
507}
508
Brad Bishop5d525412020-08-26 08:50:50 -0400509TEST(MatchProbe, uintNeqFalse)
510{
511 nlohmann::json j = R"(0)"_json;
512 BasicVariantType v = false;
513 EXPECT_FALSE(matchProbe(j, v));
514}
515
Brad Bishopc2af5312020-08-28 10:39:49 -0400516TEST(MatchProbe, uintEqUint8)
517{
518 nlohmann::json j = R"(11)"_json;
519 BasicVariantType v = uint8_t(11);
520 EXPECT_TRUE(matchProbe(j, v));
521}
522
523TEST(MatchProbe, uintNeqUint8)
524{
525 nlohmann::json j = R"(11)"_json;
526 BasicVariantType v = uint8_t(12);
527 EXPECT_FALSE(matchProbe(j, v));
528}
529
530TEST(MatchProbe, uintNeqUint8Overflow)
531{
532 nlohmann::json j = R"(65535)"_json;
533 BasicVariantType v = uint8_t(255);
534 EXPECT_FALSE(matchProbe(j, v));
535}
536
537TEST(MatchProbe, uintEqInt8)
538{
539 nlohmann::json j = R"(11)"_json;
540 BasicVariantType v = int8_t(11);
541 EXPECT_TRUE(matchProbe(j, v));
542}
543
544TEST(MatchProbe, uintEqDouble)
545{
546 nlohmann::json j = R"(11)"_json;
547 BasicVariantType v = double(11.0);
548 EXPECT_TRUE(matchProbe(j, v));
549}
550
Brad Bishop5d525412020-08-26 08:50:50 -0400551TEST(MatchProbe, uintNeqDouble)
Brad Bishopc2af5312020-08-28 10:39:49 -0400552{
553 nlohmann::json j = R"(11)"_json;
554 BasicVariantType v = double(11.7);
Brad Bishop5d525412020-08-26 08:50:50 -0400555 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc2af5312020-08-28 10:39:49 -0400556}
557
Brad Bishop5d525412020-08-26 08:50:50 -0400558TEST(MatchProbe, uintNeqEmpty)
Brad Bishopc2af5312020-08-28 10:39:49 -0400559{
560 nlohmann::json j = R"(11)"_json;
561 BasicVariantType v;
Brad Bishop5d525412020-08-26 08:50:50 -0400562 EXPECT_FALSE(matchProbe(j, v));
Brad Bishopc2af5312020-08-28 10:39:49 -0400563}
Brad Bishop667e0502020-08-28 10:41:40 -0400564
Brad Bishopcd1868e2020-08-28 17:58:52 -0400565TEST(MatchProbe, uintNeqArray)
566{
567 nlohmann::json j = R"(11)"_json;
568 BasicVariantType v = std::vector<uint8_t>{11};
569 EXPECT_FALSE(matchProbe(j, v));
570}
571
Brad Bishop5d525412020-08-26 08:50:50 -0400572TEST(MatchProbe, intNeqString)
Brad Bishop667e0502020-08-28 10:41:40 -0400573{
574 nlohmann::json j = R"(-11)"_json;
575 BasicVariantType v = "-11"s;
Brad Bishop5d525412020-08-26 08:50:50 -0400576 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop667e0502020-08-28 10:41:40 -0400577}
578
579TEST(MatchProbe, intNeqTrue)
580{
581 nlohmann::json j = R"(-1)"_json;
582 BasicVariantType v = true;
583 EXPECT_FALSE(matchProbe(j, v));
584}
585
586TEST(MatchProbe, intNeqUint8)
587{
588 nlohmann::json j = R"(-11)"_json;
589 BasicVariantType v = uint8_t(11);
590 EXPECT_FALSE(matchProbe(j, v));
591}
592
593TEST(MatchProbe, intEqInt8)
594{
595 nlohmann::json j = R"(-11)"_json;
596 BasicVariantType v = int8_t(-11);
597 EXPECT_TRUE(matchProbe(j, v));
598}
599
600TEST(MatchProbe, intNeqDouble)
601{
602 nlohmann::json j = R"(-124)"_json;
603 BasicVariantType v = double(-123.0);
604 EXPECT_FALSE(matchProbe(j, v));
605}
606
607TEST(MatchProbe, intEqDouble)
608{
609 nlohmann::json j = R"(-11)"_json;
610 BasicVariantType v = double(-11.0);
611 EXPECT_TRUE(matchProbe(j, v));
612}
613
Brad Bishop5d525412020-08-26 08:50:50 -0400614TEST(MatchProbe, intNeqDoubleRound)
Brad Bishop667e0502020-08-28 10:41:40 -0400615{
616 nlohmann::json j = R"(-11)"_json;
617 BasicVariantType v = double(-11.7);
Brad Bishop5d525412020-08-26 08:50:50 -0400618 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop667e0502020-08-28 10:41:40 -0400619}
620
Brad Bishop5d525412020-08-26 08:50:50 -0400621TEST(MatchProbe, intNeqEmpty)
Brad Bishop667e0502020-08-28 10:41:40 -0400622{
623 nlohmann::json j = R"(-11)"_json;
624 BasicVariantType v;
Brad Bishop5d525412020-08-26 08:50:50 -0400625 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop667e0502020-08-28 10:41:40 -0400626}
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400627
Brad Bishopcd1868e2020-08-28 17:58:52 -0400628TEST(MatchProbe, intNeqArray)
629{
630 nlohmann::json j = R"(-11)"_json;
631 BasicVariantType v = std::vector<uint8_t>{11};
632 EXPECT_FALSE(matchProbe(j, v));
633}
634
Brad Bishop5d525412020-08-26 08:50:50 -0400635TEST(MatchProbe, doubleNeqString)
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400636{
637 nlohmann::json j = R"(0.0)"_json;
638 BasicVariantType v = "0.0"s;
Brad Bishop5d525412020-08-26 08:50:50 -0400639 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400640}
641
Brad Bishop5d525412020-08-26 08:50:50 -0400642TEST(MatchProbe, doubleNeqFalse)
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400643{
644 nlohmann::json j = R"(0.0)"_json;
645 BasicVariantType v = false;
Brad Bishop5d525412020-08-26 08:50:50 -0400646 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400647}
648
649TEST(MatchProbe, doubleNeqTrue)
650{
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400651 nlohmann::json j = R"(1.0)"_json;
652 BasicVariantType v = true;
Brad Bishop5d525412020-08-26 08:50:50 -0400653 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400654}
655
656TEST(MatchProbe, doubleEqInt32)
657{
658 nlohmann::json j = R"(-124.0)"_json;
659 BasicVariantType v = int32_t(-124);
660 EXPECT_TRUE(matchProbe(j, v));
661}
662
663TEST(MatchProbe, doubleNeqInt32)
664{
665 nlohmann::json j = R"(-124.0)"_json;
666 BasicVariantType v = int32_t(-123);
667 EXPECT_FALSE(matchProbe(j, v));
668}
669
670TEST(MatchProbe, doubleRoundNeqInt)
671{
672 nlohmann::json j = R"(124.7)"_json;
673 BasicVariantType v = int32_t(124);
674 EXPECT_FALSE(matchProbe(j, v));
675}
676TEST(MatchProbe, doubleEqDouble)
677{
678 nlohmann::json j = R"(-124.2)"_json;
679 BasicVariantType v = double(-124.2);
680 EXPECT_TRUE(matchProbe(j, v));
681}
682
683TEST(MatchProbe, doubleNeqDouble)
684{
685 nlohmann::json j = R"(-124.3)"_json;
686 BasicVariantType v = double(-124.2);
687 EXPECT_FALSE(matchProbe(j, v));
688}
689
Brad Bishop5d525412020-08-26 08:50:50 -0400690TEST(MatchProbe, doubleNeqEmpty)
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400691{
692 nlohmann::json j = R"(-11.0)"_json;
693 BasicVariantType v;
Brad Bishop5d525412020-08-26 08:50:50 -0400694 EXPECT_FALSE(matchProbe(j, v));
Brad Bishop3bd8e8d2020-08-28 10:42:27 -0400695}
Brad Bishopd14c2e22020-08-28 10:43:40 -0400696
Brad Bishopcd1868e2020-08-28 17:58:52 -0400697TEST(MatchProbe, doubleNeqArray)
698{
699 nlohmann::json j = R"(-11.2)"_json;
700 BasicVariantType v = std::vector<uint8_t>{11};
701 EXPECT_FALSE(matchProbe(j, v));
702}
703
Brad Bishopd14c2e22020-08-28 10:43:40 -0400704TEST(MatchProbe, arrayNeqString)
705{
706 nlohmann::json j = R"([1, 2])"_json;
707 BasicVariantType v = "hello"s;
708 EXPECT_FALSE(matchProbe(j, v));
709}
710
711TEST(MatchProbe, arrayNeqFalse)
712{
713 nlohmann::json j = R"([1, 2])"_json;
714 BasicVariantType v = false;
715 EXPECT_FALSE(matchProbe(j, v));
716}
717
718TEST(MatchProbe, arrayNeqTrue)
719{
720 nlohmann::json j = R"([1, 2])"_json;
721 BasicVariantType v = true;
722 EXPECT_FALSE(matchProbe(j, v));
723}
724
725TEST(MatchProbe, arrayNeqUint8)
726{
727 nlohmann::json j = R"([1, 2])"_json;
728 BasicVariantType v = uint8_t(1);
729 EXPECT_FALSE(matchProbe(j, v));
730}
731
732TEST(MatchProbe, arrayNeqInt32)
733{
734 nlohmann::json j = R"([1, 2])"_json;
735 BasicVariantType v = int32_t(-1);
736 EXPECT_FALSE(matchProbe(j, v));
737}
738
739TEST(MatchProbe, arrayNeqDouble)
740{
741 nlohmann::json j = R"([1, 2])"_json;
742 BasicVariantType v = double(1.1);
743 EXPECT_FALSE(matchProbe(j, v));
744}
Brad Bishop6660e2a2020-08-28 10:44:41 -0400745
Brad Bishopcd1868e2020-08-28 17:58:52 -0400746TEST(MatchProbe, arrayEqArray)
747{
748 nlohmann::json j = R"([1, 2])"_json;
749 BasicVariantType v = std::vector<uint8_t>{1, 2};
750 EXPECT_TRUE(matchProbe(j, v));
751}
752
753TEST(MatchProbe, arrayNeqArrayDiffSize1)
754{
755 nlohmann::json j = R"([1, 2, 3])"_json;
756 BasicVariantType v = std::vector<uint8_t>{1, 2};
757 EXPECT_FALSE(matchProbe(j, v));
758}
759
760TEST(MatchProbe, arrayNeqArrayDiffSize2)
761{
762 nlohmann::json j = R"([1, 2])"_json;
763 BasicVariantType v = std::vector<uint8_t>{1, 2, 3};
764 EXPECT_FALSE(matchProbe(j, v));
765}
766
767TEST(MatchProbe, emptyArrayEqEmptyArray)
768{
769 nlohmann::json j = R"([])"_json;
770 BasicVariantType v = std::vector<uint8_t>{};
771 EXPECT_TRUE(matchProbe(j, v));
772}
773
774TEST(MatchProbe, emptyArrayNeqArray)
775{
776 nlohmann::json j = R"([])"_json;
777 BasicVariantType v = std::vector<uint8_t>{1};
778 EXPECT_FALSE(matchProbe(j, v));
779}
780
781TEST(MatchProbe, arrayNeqEmptyArray)
782{
783 nlohmann::json j = R"([1])"_json;
784 BasicVariantType v = std::vector<uint8_t>{};
785 EXPECT_FALSE(matchProbe(j, v));
786}
787
Brad Bishop6660e2a2020-08-28 10:44:41 -0400788TEST(MatchProbe, objNeqString)
789{
790 nlohmann::json j = R"({"foo": "bar"})"_json;
791 BasicVariantType v = "hello"s;
792 EXPECT_FALSE(matchProbe(j, v));
793}
794
795TEST(MatchProbe, objNeqFalse)
796{
797 nlohmann::json j = R"({"foo": "bar"})"_json;
798 BasicVariantType v = false;
799 EXPECT_FALSE(matchProbe(j, v));
800}
801
802TEST(MatchProbe, objNeqTrue)
803{
804 nlohmann::json j = R"({"foo": "bar"})"_json;
805 BasicVariantType v = true;
806 EXPECT_FALSE(matchProbe(j, v));
807}
808
809TEST(MatchProbe, objNeqUint8)
810{
811 nlohmann::json j = R"({"foo": "bar"})"_json;
812 BasicVariantType v = uint8_t(1);
813 EXPECT_FALSE(matchProbe(j, v));
814}
815
816TEST(MatchProbe, objNeqInt32)
817{
818 nlohmann::json j = R"({"foo": "bar"})"_json;
819 BasicVariantType v = int32_t(-1);
820 EXPECT_FALSE(matchProbe(j, v));
821}
822
823TEST(MatchProbe, objNeqDouble)
824{
825 nlohmann::json j = R"({"foo": "bar"})"_json;
826 BasicVariantType v = double(1.1);
827 EXPECT_FALSE(matchProbe(j, v));
828}
Brad Bishopc776c412020-08-28 10:45:25 -0400829
Brad Bishopcd1868e2020-08-28 17:58:52 -0400830TEST(MatchProbe, objNeqArray)
831{
832 nlohmann::json j = R"({"foo": "bar"})"_json;
833 BasicVariantType v = std::vector<uint8_t>{1, 2};
834 EXPECT_FALSE(matchProbe(j, v));
835}
836
Brad Bishopc776c412020-08-28 10:45:25 -0400837TEST(MatchProbe, nullNeqString)
838{
839 nlohmann::json j = R"(null)"_json;
840 BasicVariantType v = "hello"s;
841 EXPECT_FALSE(matchProbe(j, v));
842}
843
844TEST(MatchProbe, nullNeqFalse)
845{
846 nlohmann::json j = R"(null)"_json;
847 BasicVariantType v = false;
848 EXPECT_FALSE(matchProbe(j, v));
849}
850
851TEST(MatchProbe, nullNeqTrue)
852{
853 nlohmann::json j = R"(null)"_json;
854 BasicVariantType v = true;
855 EXPECT_FALSE(matchProbe(j, v));
856}
857
858TEST(MatchProbe, nullNeqUint8)
859{
860 nlohmann::json j = R"(null)"_json;
861 BasicVariantType v = uint8_t(1);
862 EXPECT_FALSE(matchProbe(j, v));
863}
864
865TEST(MatchProbe, nullNeqInt32)
866{
867 nlohmann::json j = R"(null)"_json;
868 BasicVariantType v = int32_t(-1);
869 EXPECT_FALSE(matchProbe(j, v));
870}
871
872TEST(MatchProbe, nullNeqDouble)
873{
874 nlohmann::json j = R"(null)"_json;
875 BasicVariantType v = double(1.1);
876 EXPECT_FALSE(matchProbe(j, v));
877}
Brad Bishopcd1868e2020-08-28 17:58:52 -0400878
879TEST(MatchProbe, nullNeqArray)
880{
881 nlohmann::json j = R"(null)"_json;
882 BasicVariantType v = std::vector<uint8_t>{};
883 EXPECT_FALSE(matchProbe(j, v));
884}