1481c5d5cSJames Feist #include "Utils.hpp"
2481c5d5cSJames Feist 
3481c5d5cSJames Feist #include <boost/container/flat_map.hpp>
4481c5d5cSJames Feist #include <nlohmann/json.hpp>
58c505da0SJames Feist 
69d2ef081SBrad Bishop #include <regex>
79d2ef081SBrad Bishop #include <string>
8481c5d5cSJames Feist #include <variant>
9481c5d5cSJames Feist 
10481c5d5cSJames Feist #include "gtest/gtest.h"
11481c5d5cSJames Feist 
129d2ef081SBrad Bishop using namespace std::string_literals;
139d2ef081SBrad Bishop 
14481c5d5cSJames Feist TEST(TemplateCharReplace, replaceOneInt)
15481c5d5cSJames Feist {
16481c5d5cSJames Feist     nlohmann::json j = {{"foo", "$bus"}};
17481c5d5cSJames Feist     auto it = j.begin();
18481c5d5cSJames Feist     boost::container::flat_map<std::string, BasicVariantType> data;
19481c5d5cSJames Feist     data["BUS"] = 23;
20481c5d5cSJames Feist 
21481c5d5cSJames Feist     templateCharReplace(it, data, 0);
22481c5d5cSJames Feist 
23481c5d5cSJames Feist     nlohmann::json expected = 23;
24481c5d5cSJames Feist     EXPECT_EQ(expected, j["foo"]);
25481c5d5cSJames Feist }
26481c5d5cSJames Feist 
27481c5d5cSJames Feist TEST(TemplateCharReplace, replaceOneStr)
28481c5d5cSJames Feist {
29481c5d5cSJames Feist     nlohmann::json j = {{"foo", "$TEST"}};
30481c5d5cSJames Feist     auto it = j.begin();
31481c5d5cSJames Feist     boost::container::flat_map<std::string, BasicVariantType> data;
32481c5d5cSJames Feist     data["TEST"] = std::string("Test");
33481c5d5cSJames Feist 
34481c5d5cSJames Feist     templateCharReplace(it, data, 0);
35481c5d5cSJames Feist 
36481c5d5cSJames Feist     nlohmann::json expected = "Test";
37481c5d5cSJames Feist     EXPECT_EQ(expected, j["foo"]);
38481c5d5cSJames Feist }
39481c5d5cSJames Feist 
40481c5d5cSJames Feist TEST(TemplateCharReplace, replaceSecondStr)
41481c5d5cSJames Feist {
42481c5d5cSJames Feist     nlohmann::json j = {{"foo", "the $TEST"}};
43481c5d5cSJames Feist     auto it = j.begin();
44481c5d5cSJames Feist     boost::container::flat_map<std::string, BasicVariantType> data;
45481c5d5cSJames Feist     data["TEST"] = std::string("Test");
46481c5d5cSJames Feist 
47481c5d5cSJames Feist     templateCharReplace(it, data, 0);
48481c5d5cSJames Feist 
49481c5d5cSJames Feist     nlohmann::json expected = "the Test";
50481c5d5cSJames Feist     EXPECT_EQ(expected, j["foo"]);
51481c5d5cSJames Feist }
52481c5d5cSJames Feist 
53481c5d5cSJames Feist TEST(TemplateCharReplace, replaceMiddleStr)
54481c5d5cSJames Feist {
55481c5d5cSJames Feist     nlohmann::json j = {{"foo", "the $TEST worked"}};
56481c5d5cSJames Feist     auto it = j.begin();
57481c5d5cSJames Feist     boost::container::flat_map<std::string, BasicVariantType> data;
58481c5d5cSJames Feist     data["TEST"] = std::string("Test");
59481c5d5cSJames Feist 
60481c5d5cSJames Feist     templateCharReplace(it, data, 0);
61481c5d5cSJames Feist 
62481c5d5cSJames Feist     nlohmann::json expected = "the Test worked";
63481c5d5cSJames Feist     EXPECT_EQ(expected, j["foo"]);
64481c5d5cSJames Feist }
65481c5d5cSJames Feist 
66481c5d5cSJames Feist TEST(TemplateCharReplace, replaceLastStr)
67481c5d5cSJames Feist {
68481c5d5cSJames Feist     nlohmann::json j = {{"foo", "the Test $TEST"}};
69481c5d5cSJames Feist     auto it = j.begin();
70481c5d5cSJames Feist     boost::container::flat_map<std::string, BasicVariantType> data;
71481c5d5cSJames Feist     data["TEST"] = 23;
72481c5d5cSJames Feist 
73481c5d5cSJames Feist     templateCharReplace(it, data, 0);
74481c5d5cSJames Feist 
75481c5d5cSJames Feist     nlohmann::json expected = "the Test 23";
76481c5d5cSJames Feist     EXPECT_EQ(expected, j["foo"]);
77481c5d5cSJames Feist }
78481c5d5cSJames Feist 
79481c5d5cSJames Feist TEST(TemplateCharReplace, increment)
80481c5d5cSJames Feist {
81481c5d5cSJames Feist     nlohmann::json j = {{"foo", "3 plus 1 equals $TEST + 1"}};
82481c5d5cSJames Feist     auto it = j.begin();
83481c5d5cSJames Feist     boost::container::flat_map<std::string, BasicVariantType> data;
84481c5d5cSJames Feist     data["TEST"] = 3;
85481c5d5cSJames Feist 
86481c5d5cSJames Feist     templateCharReplace(it, data, 0);
87481c5d5cSJames Feist 
88481c5d5cSJames Feist     nlohmann::json expected = "3 plus 1 equals 4";
89481c5d5cSJames Feist     EXPECT_EQ(expected, j["foo"]);
90481c5d5cSJames Feist }
91481c5d5cSJames Feist 
92481c5d5cSJames Feist TEST(TemplateCharReplace, decrement)
93481c5d5cSJames Feist {
94481c5d5cSJames Feist     nlohmann::json j = {{"foo", "3 minus 1 equals $TEST - 1 !"}};
95481c5d5cSJames Feist     auto it = j.begin();
96481c5d5cSJames Feist     boost::container::flat_map<std::string, BasicVariantType> data;
97481c5d5cSJames Feist     data["TEST"] = 3;
98481c5d5cSJames Feist 
99481c5d5cSJames Feist     templateCharReplace(it, data, 0);
100481c5d5cSJames Feist 
101481c5d5cSJames Feist     nlohmann::json expected = "3 minus 1 equals 2 !";
102481c5d5cSJames Feist     EXPECT_EQ(expected, j["foo"]);
103481c5d5cSJames Feist }
104481c5d5cSJames Feist 
105481c5d5cSJames Feist TEST(TemplateCharReplace, modulus)
106481c5d5cSJames Feist {
107481c5d5cSJames Feist     nlohmann::json j = {{"foo", "3 mod 2 equals $TEST % 2"}};
108481c5d5cSJames Feist     auto it = j.begin();
109481c5d5cSJames Feist     boost::container::flat_map<std::string, BasicVariantType> data;
110481c5d5cSJames Feist     data["TEST"] = 3;
111481c5d5cSJames Feist 
112481c5d5cSJames Feist     templateCharReplace(it, data, 0);
113481c5d5cSJames Feist 
114481c5d5cSJames Feist     nlohmann::json expected = "3 mod 2 equals 1";
115481c5d5cSJames Feist     EXPECT_EQ(expected, j["foo"]);
116481c5d5cSJames Feist }
117481c5d5cSJames Feist 
118481c5d5cSJames Feist TEST(TemplateCharReplace, multiply)
119481c5d5cSJames Feist {
120481c5d5cSJames Feist     nlohmann::json j = {{"foo", "3 * 2 equals $TEST * 2"}};
121481c5d5cSJames Feist     auto it = j.begin();
122481c5d5cSJames Feist     boost::container::flat_map<std::string, BasicVariantType> data;
123481c5d5cSJames Feist     data["TEST"] = 3;
124481c5d5cSJames Feist 
125481c5d5cSJames Feist     templateCharReplace(it, data, 0);
126481c5d5cSJames Feist 
127481c5d5cSJames Feist     nlohmann::json expected = "3 * 2 equals 6";
128481c5d5cSJames Feist     EXPECT_EQ(expected, j["foo"]);
129481c5d5cSJames Feist }
130481c5d5cSJames Feist 
131481c5d5cSJames Feist TEST(TemplateCharReplace, divide)
132481c5d5cSJames Feist {
133481c5d5cSJames Feist     nlohmann::json j = {{"foo", "4 / 2 equals $TEST / 2"}};
134481c5d5cSJames Feist     auto it = j.begin();
135481c5d5cSJames Feist     boost::container::flat_map<std::string, BasicVariantType> data;
136481c5d5cSJames Feist     data["TEST"] = 4;
137481c5d5cSJames Feist 
138481c5d5cSJames Feist     templateCharReplace(it, data, 0);
139481c5d5cSJames Feist 
140481c5d5cSJames Feist     nlohmann::json expected = "4 / 2 equals 2";
141481c5d5cSJames Feist     EXPECT_EQ(expected, j["foo"]);
142481c5d5cSJames Feist }
1438c20febcSJames Feist 
1448c20febcSJames Feist TEST(TemplateCharReplace, multiMath)
1458c20febcSJames Feist {
1468c20febcSJames Feist     nlohmann::json j = {{"foo", "4 * 2 % 6 equals $TEST * 2 % 6"}};
1478c20febcSJames Feist     auto it = j.begin();
1488c20febcSJames Feist     boost::container::flat_map<std::string, BasicVariantType> data;
1498c20febcSJames Feist     data["TEST"] = 4;
1508c20febcSJames Feist 
1518c20febcSJames Feist     templateCharReplace(it, data, 0);
1528c20febcSJames Feist 
1538c20febcSJames Feist     nlohmann::json expected = "4 * 2 % 6 equals 2";
1548c20febcSJames Feist     EXPECT_EQ(expected, j["foo"]);
1558c20febcSJames Feist }
1568c20febcSJames Feist 
1578c20febcSJames Feist TEST(TemplateCharReplace, twoReplacements)
1588c20febcSJames Feist {
1598c20febcSJames Feist     nlohmann::json j = {{"foo", "$FOO $BAR"}};
1608c20febcSJames Feist     auto it = j.begin();
1618c20febcSJames Feist     boost::container::flat_map<std::string, BasicVariantType> data;
1628c20febcSJames Feist     data["FOO"] = std::string("foo");
1638c20febcSJames Feist     data["BAR"] = std::string("bar");
1648c20febcSJames Feist 
1658c20febcSJames Feist     templateCharReplace(it, data, 0);
1668c20febcSJames Feist 
1678c20febcSJames Feist     nlohmann::json expected = "foo bar";
1688c20febcSJames Feist     EXPECT_EQ(expected, j["foo"]);
1698c20febcSJames Feist }
1708c20febcSJames Feist 
1718c20febcSJames Feist TEST(TemplateCharReplace, twoReplacementsWithMath)
1728c20febcSJames Feist {
1738c20febcSJames Feist     nlohmann::json j = {{"foo", "4 / 2 equals $TEST / 2 $BAR"}};
1748c20febcSJames Feist     auto it = j.begin();
1758c20febcSJames Feist     boost::container::flat_map<std::string, BasicVariantType> data;
1768c20febcSJames Feist     data["TEST"] = 4;
1778c20febcSJames Feist     data["BAR"] = std::string("bar");
1788c20febcSJames Feist 
1798c20febcSJames Feist     templateCharReplace(it, data, 0);
1808c20febcSJames Feist 
1818c20febcSJames Feist     nlohmann::json expected = "4 / 2 equals 2 bar";
1828c20febcSJames Feist     EXPECT_EQ(expected, j["foo"]);
1838c20febcSJames Feist }
184b0097d41SJames Feist 
185b0097d41SJames Feist TEST(TemplateCharReplace, hexAndWrongCase)
186b0097d41SJames Feist {
187b0097d41SJames Feist     nlohmann::json j = {{"Address", "0x54"},
188b0097d41SJames Feist                         {"Bus", 15},
189b0097d41SJames Feist                         {"Name", "$bus sensor 0"},
190b0097d41SJames Feist                         {"Type", "SomeType"}};
191b0097d41SJames Feist 
192b0097d41SJames Feist     boost::container::flat_map<std::string, BasicVariantType> data;
193b0097d41SJames Feist     data["BUS"] = 15;
194b0097d41SJames Feist 
195b0097d41SJames Feist     for (auto it = j.begin(); it != j.end(); it++)
196b0097d41SJames Feist     {
197b0097d41SJames Feist         templateCharReplace(it, data, 0);
198b0097d41SJames Feist     }
199b0097d41SJames Feist     nlohmann::json expected = {{"Address", 84},
200b0097d41SJames Feist                                {"Bus", 15},
201b0097d41SJames Feist                                {"Name", "15 sensor 0"},
202b0097d41SJames Feist                                {"Type", "SomeType"}};
203b0097d41SJames Feist     EXPECT_EQ(expected, j);
204b0097d41SJames Feist }
205b0097d41SJames Feist 
206b0097d41SJames Feist TEST(TemplateCharReplace, replaceSecondAsInt)
207b0097d41SJames Feist {
208b0097d41SJames Feist     nlohmann::json j = {{"foo", "twelve is $TEST"}};
209b0097d41SJames Feist     auto it = j.begin();
210b0097d41SJames Feist     boost::container::flat_map<std::string, BasicVariantType> data;
211b0097d41SJames Feist     data["test"] = 12;
212b0097d41SJames Feist 
213b0097d41SJames Feist     templateCharReplace(it, data, 0);
214b0097d41SJames Feist 
215b0097d41SJames Feist     nlohmann::json expected = "twelve is 12";
216b0097d41SJames Feist     EXPECT_EQ(expected, j["foo"]);
217b0097d41SJames Feist }
218c296c80eSJames Feist 
219c296c80eSJames Feist TEST(TemplateCharReplace, singleHex)
220c296c80eSJames Feist {
221c296c80eSJames Feist     nlohmann::json j = {{"foo", "0x54"}};
222c296c80eSJames Feist     auto it = j.begin();
223c296c80eSJames Feist     boost::container::flat_map<std::string, BasicVariantType> data;
224c296c80eSJames Feist 
225c296c80eSJames Feist     templateCharReplace(it, data, 0);
226c296c80eSJames Feist 
227c296c80eSJames Feist     nlohmann::json expected = 84;
228c296c80eSJames Feist     EXPECT_EQ(expected, j["foo"]);
229c296c80eSJames Feist }
2309d2ef081SBrad Bishop 
2319d2ef081SBrad Bishop TEST(MatchProbe, stringEqString)
2329d2ef081SBrad Bishop {
2339d2ef081SBrad Bishop     nlohmann::json j = R"("foo")"_json;
2349d2ef081SBrad Bishop     BasicVariantType v = "foo"s;
2359d2ef081SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
2369d2ef081SBrad Bishop }
2379d2ef081SBrad Bishop 
2389d2ef081SBrad Bishop TEST(MatchProbe, stringRegexEqString)
2399d2ef081SBrad Bishop {
2409d2ef081SBrad Bishop     nlohmann::json j = R"("foo*")"_json;
2419d2ef081SBrad Bishop     BasicVariantType v = "foobar"s;
2429d2ef081SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
2439d2ef081SBrad Bishop }
2449d2ef081SBrad Bishop 
2459d2ef081SBrad Bishop TEST(MatchProbe, stringNeqString)
2469d2ef081SBrad Bishop {
2479d2ef081SBrad Bishop     nlohmann::json j = R"("foobar")"_json;
2489d2ef081SBrad Bishop     BasicVariantType v = "foo"s;
2499d2ef081SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
2509d2ef081SBrad Bishop }
2519d2ef081SBrad Bishop 
2529d2ef081SBrad Bishop TEST(MatchProbe, stringRegexError)
2539d2ef081SBrad Bishop {
2549d2ef081SBrad Bishop     nlohmann::json j = R"("foo[")"_json;
2559d2ef081SBrad Bishop     BasicVariantType v = "foobar"s;
2569d2ef081SBrad Bishop     EXPECT_THROW(matchProbe(j, v), std::regex_error);
2579d2ef081SBrad Bishop }
2589d2ef081SBrad Bishop 
2599d2ef081SBrad Bishop TEST(MatchProbe, stringZeroEqFalse)
2609d2ef081SBrad Bishop {
2619d2ef081SBrad Bishop     nlohmann::json j = R"("0")"_json;
2629d2ef081SBrad Bishop     BasicVariantType v = false;
2639d2ef081SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
2649d2ef081SBrad Bishop }
2659d2ef081SBrad Bishop 
2669d2ef081SBrad Bishop TEST(MatchProbe, stringOneEqTrue)
2679d2ef081SBrad Bishop {
2689d2ef081SBrad Bishop     nlohmann::json j = R"("1")"_json;
2699d2ef081SBrad Bishop     BasicVariantType v = true;
2709d2ef081SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
2719d2ef081SBrad Bishop }
2729d2ef081SBrad Bishop 
2739d2ef081SBrad Bishop TEST(MatchProbe, stringElevenNeqTrue)
2749d2ef081SBrad Bishop {
2759d2ef081SBrad Bishop     nlohmann::json j = R"("11")"_json;
2769d2ef081SBrad Bishop     BasicVariantType v = true;
2779d2ef081SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
2789d2ef081SBrad Bishop }
2799d2ef081SBrad Bishop 
2809d2ef081SBrad Bishop TEST(MatchProbe, stringFalseNeqFalse)
2819d2ef081SBrad Bishop {
2829d2ef081SBrad Bishop     nlohmann::json j = R"("false")"_json;
2839d2ef081SBrad Bishop     BasicVariantType v = false;
2849d2ef081SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
2859d2ef081SBrad Bishop }
2869d2ef081SBrad Bishop 
2879d2ef081SBrad Bishop TEST(MatchProbe, stringTrueNeqTrue)
2889d2ef081SBrad Bishop {
2899d2ef081SBrad Bishop     nlohmann::json j = R"("true")"_json;
2909d2ef081SBrad Bishop     BasicVariantType v = true;
2919d2ef081SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
2929d2ef081SBrad Bishop }
2939d2ef081SBrad Bishop 
2949d2ef081SBrad Bishop TEST(MatchProbe, stringFalseNeqTrue)
2959d2ef081SBrad Bishop {
2969d2ef081SBrad Bishop     nlohmann::json j = R"("false")"_json;
2979d2ef081SBrad Bishop     BasicVariantType v = true;
2989d2ef081SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
2999d2ef081SBrad Bishop }
3009d2ef081SBrad Bishop 
3019d2ef081SBrad Bishop TEST(MatchProbe, stringEqUint8)
3029d2ef081SBrad Bishop {
3039d2ef081SBrad Bishop     nlohmann::json j = R"("255")"_json;
3049d2ef081SBrad Bishop     BasicVariantType v = uint8_t(255);
3059d2ef081SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
3069d2ef081SBrad Bishop }
3079d2ef081SBrad Bishop 
3089d2ef081SBrad Bishop TEST(MatchProbe, stringNeqUint8Overflow)
3099d2ef081SBrad Bishop {
3109d2ef081SBrad Bishop     nlohmann::json j = R"("65535")"_json;
3119d2ef081SBrad Bishop     BasicVariantType v = uint8_t(255);
3129d2ef081SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
3139d2ef081SBrad Bishop }
3149d2ef081SBrad Bishop 
3159d2ef081SBrad Bishop TEST(MatchProbe, stringFalseNeqUint8Zero)
3169d2ef081SBrad Bishop {
3179d2ef081SBrad Bishop     nlohmann::json j = R"("false")"_json;
3189d2ef081SBrad Bishop     BasicVariantType v = uint8_t(0);
3199d2ef081SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
3209d2ef081SBrad Bishop }
3219d2ef081SBrad Bishop 
3229d2ef081SBrad Bishop TEST(MatchProbe, stringTrueNeqUint8Zero)
3239d2ef081SBrad Bishop {
3249d2ef081SBrad Bishop     nlohmann::json j = R"("true")"_json;
3259d2ef081SBrad Bishop     BasicVariantType v = uint8_t(1);
3269d2ef081SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
3279d2ef081SBrad Bishop }
3289d2ef081SBrad Bishop 
3299d2ef081SBrad Bishop TEST(MatchProbe, stringEqUint32)
3309d2ef081SBrad Bishop {
3319d2ef081SBrad Bishop     nlohmann::json j = R"("11")"_json;
3329d2ef081SBrad Bishop     BasicVariantType v = uint32_t(11);
3339d2ef081SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
3349d2ef081SBrad Bishop }
3359d2ef081SBrad Bishop 
3369d2ef081SBrad Bishop TEST(MatchProbe, stringNeqUint32)
3379d2ef081SBrad Bishop {
3389d2ef081SBrad Bishop     nlohmann::json j = R"("12")"_json;
3399d2ef081SBrad Bishop     BasicVariantType v = uint32_t(11);
3409d2ef081SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
3419d2ef081SBrad Bishop }
3429d2ef081SBrad Bishop 
3439d2ef081SBrad Bishop TEST(MatchProbe, stringEqInt32)
3449d2ef081SBrad Bishop {
3459d2ef081SBrad Bishop     nlohmann::json j = R"("-11")"_json;
3469d2ef081SBrad Bishop     BasicVariantType v = int32_t(-11);
3479d2ef081SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
3489d2ef081SBrad Bishop }
3499d2ef081SBrad Bishop 
3509d2ef081SBrad Bishop TEST(MatchProbe, stringNeqInt32)
3519d2ef081SBrad Bishop {
3529d2ef081SBrad Bishop     nlohmann::json j = R"("-12")"_json;
3539d2ef081SBrad Bishop     BasicVariantType v = int32_t(-11);
3549d2ef081SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
3559d2ef081SBrad Bishop }
3569d2ef081SBrad Bishop 
3579d2ef081SBrad Bishop TEST(MatchProbe, stringRegexEqInt32)
3589d2ef081SBrad Bishop {
3599d2ef081SBrad Bishop     nlohmann::json j = R"("1*4")"_json;
3609d2ef081SBrad Bishop     BasicVariantType v = int32_t(124);
3619d2ef081SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
3629d2ef081SBrad Bishop }
3639d2ef081SBrad Bishop 
3649d2ef081SBrad Bishop TEST(MatchProbe, stringNeqUint64)
3659d2ef081SBrad Bishop {
3669d2ef081SBrad Bishop     nlohmann::json j = R"("foo")"_json;
3679d2ef081SBrad Bishop     BasicVariantType v = uint64_t(65535);
3689d2ef081SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
3699d2ef081SBrad Bishop }
3709d2ef081SBrad Bishop 
3719d2ef081SBrad Bishop TEST(MatchProbe, stringEqDouble)
3729d2ef081SBrad Bishop {
3739d2ef081SBrad Bishop     nlohmann::json j = R"("123.4")"_json;
3749d2ef081SBrad Bishop     BasicVariantType v = double(123.4);
3759d2ef081SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
3769d2ef081SBrad Bishop }
3779d2ef081SBrad Bishop 
3789d2ef081SBrad Bishop TEST(MatchProbe, stringNeqDouble)
3799d2ef081SBrad Bishop {
3809d2ef081SBrad Bishop     nlohmann::json j = R"("-123.4")"_json;
3819d2ef081SBrad Bishop     BasicVariantType v = double(123.4);
3829d2ef081SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
3839d2ef081SBrad Bishop }
3849d2ef081SBrad Bishop 
3859d2ef081SBrad Bishop TEST(MatchProbe, stringNeqEmpty)
3869d2ef081SBrad Bishop {
3879d2ef081SBrad Bishop     nlohmann::json j = R"("-123.4")"_json;
3889d2ef081SBrad Bishop     BasicVariantType v;
3899d2ef081SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
3909d2ef081SBrad Bishop }
391c5eba596SBrad Bishop 
392c5eba596SBrad Bishop TEST(MatchProbe, boolStringError)
393c5eba596SBrad Bishop {
394c5eba596SBrad Bishop     nlohmann::json j = R"(false)"_json;
395c5eba596SBrad Bishop     BasicVariantType v = "false"s;
396c5eba596SBrad Bishop     EXPECT_THROW(matchProbe(j, v), std::invalid_argument);
397c5eba596SBrad Bishop }
398c5eba596SBrad Bishop 
399c5eba596SBrad Bishop TEST(MatchProbe, trueEqTrue)
400c5eba596SBrad Bishop {
401c5eba596SBrad Bishop     nlohmann::json j = R"(true)"_json;
402c5eba596SBrad Bishop     BasicVariantType v = true;
403c5eba596SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
404c5eba596SBrad Bishop }
405c5eba596SBrad Bishop 
406c5eba596SBrad Bishop TEST(MatchProbe, falseEqFalse)
407c5eba596SBrad Bishop {
408c5eba596SBrad Bishop     nlohmann::json j = R"(false)"_json;
409c5eba596SBrad Bishop     BasicVariantType v = false;
410c5eba596SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
411c5eba596SBrad Bishop }
412c5eba596SBrad Bishop 
413c5eba596SBrad Bishop TEST(MatchProbe, trueNeqFalse)
414c5eba596SBrad Bishop {
415c5eba596SBrad Bishop     nlohmann::json j = R"(true)"_json;
416c5eba596SBrad Bishop     BasicVariantType v = false;
417c5eba596SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
418c5eba596SBrad Bishop }
419c5eba596SBrad Bishop 
420c5eba596SBrad Bishop TEST(MatchProbe, trueNeqInt32Zero)
421c5eba596SBrad Bishop {
422c5eba596SBrad Bishop     nlohmann::json j = R"(true)"_json;
423c5eba596SBrad Bishop     BasicVariantType v = int32_t(0);
424c5eba596SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
425c5eba596SBrad Bishop }
426c5eba596SBrad Bishop 
427c5eba596SBrad Bishop TEST(MatchProbe, trueNeqInt32NegativeOne)
428c5eba596SBrad Bishop {
429c5eba596SBrad Bishop     nlohmann::json j = R"(true)"_json;
430c5eba596SBrad Bishop     BasicVariantType v = int32_t(-1);
431c5eba596SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
432c5eba596SBrad Bishop }
433c5eba596SBrad Bishop 
434c5eba596SBrad Bishop TEST(MatchProbe, falseNeqUint32One)
435c5eba596SBrad Bishop {
436c5eba596SBrad Bishop     nlohmann::json j = R"(false)"_json;
437c5eba596SBrad Bishop     BasicVariantType v = uint32_t(1);
438c5eba596SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
439c5eba596SBrad Bishop }
440c5eba596SBrad Bishop 
441c5eba596SBrad Bishop TEST(MatchProbe, falseEqUint32Zero)
442c5eba596SBrad Bishop {
443c5eba596SBrad Bishop     nlohmann::json j = R"(false)"_json;
444c5eba596SBrad Bishop     BasicVariantType v = uint32_t(0);
445c5eba596SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
446c5eba596SBrad Bishop }
447c5eba596SBrad Bishop 
448c5eba596SBrad Bishop TEST(MatchProbe, trueNeqDoubleNegativeOne)
449c5eba596SBrad Bishop {
450c5eba596SBrad Bishop     nlohmann::json j = R"(true)"_json;
451c5eba596SBrad Bishop     BasicVariantType v = double(-1.1);
452c5eba596SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
453c5eba596SBrad Bishop }
454c5eba596SBrad Bishop 
455c5eba596SBrad Bishop TEST(MatchProbe, trueEqDoubleOne)
456c5eba596SBrad Bishop {
457c5eba596SBrad Bishop     nlohmann::json j = R"(true)"_json;
458c5eba596SBrad Bishop     BasicVariantType v = double(1.0);
459c5eba596SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
460c5eba596SBrad Bishop }
461c5eba596SBrad Bishop 
462c5eba596SBrad Bishop TEST(MatchProbe, falseNeqDoubleOne)
463c5eba596SBrad Bishop {
464c5eba596SBrad Bishop     nlohmann::json j = R"(false)"_json;
465c5eba596SBrad Bishop     BasicVariantType v = double(1.0);
466c5eba596SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
467c5eba596SBrad Bishop }
468c5eba596SBrad Bishop 
469c5eba596SBrad Bishop TEST(MatchProbe, falseEqDoubleZero)
470c5eba596SBrad Bishop {
471c5eba596SBrad Bishop     nlohmann::json j = R"(false)"_json;
472c5eba596SBrad Bishop     BasicVariantType v = double(0.0);
473c5eba596SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
474c5eba596SBrad Bishop }
475c5eba596SBrad Bishop 
476c5eba596SBrad Bishop TEST(MatchProbe, falseEmptyError)
477c5eba596SBrad Bishop {
478c5eba596SBrad Bishop     nlohmann::json j = R"(false)"_json;
479c5eba596SBrad Bishop     BasicVariantType v;
480c5eba596SBrad Bishop     EXPECT_THROW(matchProbe(j, v), std::invalid_argument);
481c5eba596SBrad Bishop }
482c5eba596SBrad Bishop 
483c5eba596SBrad Bishop TEST(MatchProbe, trueEmptyError)
484c5eba596SBrad Bishop {
485c5eba596SBrad Bishop     nlohmann::json j = R"(true)"_json;
486c5eba596SBrad Bishop     BasicVariantType v;
487c5eba596SBrad Bishop     EXPECT_THROW(matchProbe(j, v), std::invalid_argument);
488c5eba596SBrad Bishop }
489c2af531dSBrad Bishop 
490c2af531dSBrad Bishop TEST(MatchProbe, uintStringError)
491c2af531dSBrad Bishop {
492c2af531dSBrad Bishop     nlohmann::json j = R"(11)"_json;
493c2af531dSBrad Bishop     BasicVariantType v = "11"s;
494c2af531dSBrad Bishop     EXPECT_THROW(matchProbe(j, v), std::invalid_argument);
495c2af531dSBrad Bishop }
496c2af531dSBrad Bishop 
497c2af531dSBrad Bishop TEST(MatchProbe, uintEqTrue)
498c2af531dSBrad Bishop {
499c2af531dSBrad Bishop     nlohmann::json j = R"(1)"_json;
500c2af531dSBrad Bishop     BasicVariantType v = true;
501c2af531dSBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
502c2af531dSBrad Bishop }
503c2af531dSBrad Bishop 
504c2af531dSBrad Bishop TEST(MatchProbe, uintEqFalse)
505c2af531dSBrad Bishop {
506c2af531dSBrad Bishop     nlohmann::json j = R"(0)"_json;
507c2af531dSBrad Bishop     BasicVariantType v = false;
508c2af531dSBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
509c2af531dSBrad Bishop }
510c2af531dSBrad Bishop 
511c2af531dSBrad Bishop TEST(MatchProbe, uintNeqTrue)
512c2af531dSBrad Bishop {
513c2af531dSBrad Bishop     nlohmann::json j = R"(11)"_json;
514c2af531dSBrad Bishop     BasicVariantType v = true;
515c2af531dSBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
516c2af531dSBrad Bishop }
517c2af531dSBrad Bishop 
518c2af531dSBrad Bishop TEST(MatchProbe, uintEqUint8)
519c2af531dSBrad Bishop {
520c2af531dSBrad Bishop     nlohmann::json j = R"(11)"_json;
521c2af531dSBrad Bishop     BasicVariantType v = uint8_t(11);
522c2af531dSBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
523c2af531dSBrad Bishop }
524c2af531dSBrad Bishop 
525c2af531dSBrad Bishop TEST(MatchProbe, uintNeqUint8)
526c2af531dSBrad Bishop {
527c2af531dSBrad Bishop     nlohmann::json j = R"(11)"_json;
528c2af531dSBrad Bishop     BasicVariantType v = uint8_t(12);
529c2af531dSBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
530c2af531dSBrad Bishop }
531c2af531dSBrad Bishop 
532c2af531dSBrad Bishop TEST(MatchProbe, uintNeqUint8Overflow)
533c2af531dSBrad Bishop {
534c2af531dSBrad Bishop     nlohmann::json j = R"(65535)"_json;
535c2af531dSBrad Bishop     BasicVariantType v = uint8_t(255);
536c2af531dSBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
537c2af531dSBrad Bishop }
538c2af531dSBrad Bishop 
539c2af531dSBrad Bishop TEST(MatchProbe, uintEqInt8)
540c2af531dSBrad Bishop {
541c2af531dSBrad Bishop     nlohmann::json j = R"(11)"_json;
542c2af531dSBrad Bishop     BasicVariantType v = int8_t(11);
543c2af531dSBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
544c2af531dSBrad Bishop }
545c2af531dSBrad Bishop 
546c2af531dSBrad Bishop TEST(MatchProbe, uintEqDouble)
547c2af531dSBrad Bishop {
548c2af531dSBrad Bishop     nlohmann::json j = R"(11)"_json;
549c2af531dSBrad Bishop     BasicVariantType v = double(11.0);
550c2af531dSBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
551c2af531dSBrad Bishop }
552c2af531dSBrad Bishop 
553c2af531dSBrad Bishop TEST(MatchProbe, uintEqDoubleRound)
554c2af531dSBrad Bishop {
555c2af531dSBrad Bishop     nlohmann::json j = R"(11)"_json;
556c2af531dSBrad Bishop     BasicVariantType v = double(11.7);
557c2af531dSBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
558c2af531dSBrad Bishop }
559c2af531dSBrad Bishop 
560c2af531dSBrad Bishop TEST(MatchProbe, uintEmptyError)
561c2af531dSBrad Bishop {
562c2af531dSBrad Bishop     nlohmann::json j = R"(11)"_json;
563c2af531dSBrad Bishop     BasicVariantType v;
564c2af531dSBrad Bishop     EXPECT_THROW(matchProbe(j, v), std::invalid_argument);
565c2af531dSBrad Bishop }
566667e050dSBrad Bishop 
567667e050dSBrad Bishop TEST(MatchProbe, intStringError)
568667e050dSBrad Bishop {
569667e050dSBrad Bishop     nlohmann::json j = R"(-11)"_json;
570667e050dSBrad Bishop     BasicVariantType v = "-11"s;
571667e050dSBrad Bishop     EXPECT_THROW(matchProbe(j, v), std::invalid_argument);
572667e050dSBrad Bishop }
573667e050dSBrad Bishop 
574667e050dSBrad Bishop TEST(MatchProbe, intNeqTrue)
575667e050dSBrad Bishop {
576667e050dSBrad Bishop     nlohmann::json j = R"(-1)"_json;
577667e050dSBrad Bishop     BasicVariantType v = true;
578667e050dSBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
579667e050dSBrad Bishop }
580667e050dSBrad Bishop 
581667e050dSBrad Bishop TEST(MatchProbe, intNeqUint8)
582667e050dSBrad Bishop {
583667e050dSBrad Bishop     nlohmann::json j = R"(-11)"_json;
584667e050dSBrad Bishop     BasicVariantType v = uint8_t(11);
585667e050dSBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
586667e050dSBrad Bishop }
587667e050dSBrad Bishop 
588667e050dSBrad Bishop TEST(MatchProbe, intEqInt8)
589667e050dSBrad Bishop {
590667e050dSBrad Bishop     nlohmann::json j = R"(-11)"_json;
591667e050dSBrad Bishop     BasicVariantType v = int8_t(-11);
592667e050dSBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
593667e050dSBrad Bishop }
594667e050dSBrad Bishop 
595667e050dSBrad Bishop TEST(MatchProbe, intNeqDouble)
596667e050dSBrad Bishop {
597667e050dSBrad Bishop     nlohmann::json j = R"(-124)"_json;
598667e050dSBrad Bishop     BasicVariantType v = double(-123.0);
599667e050dSBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
600667e050dSBrad Bishop }
601667e050dSBrad Bishop 
602667e050dSBrad Bishop TEST(MatchProbe, intEqDouble)
603667e050dSBrad Bishop {
604667e050dSBrad Bishop     nlohmann::json j = R"(-11)"_json;
605667e050dSBrad Bishop     BasicVariantType v = double(-11.0);
606667e050dSBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
607667e050dSBrad Bishop }
608667e050dSBrad Bishop 
609667e050dSBrad Bishop TEST(MatchProbe, intEqDoubleRound)
610667e050dSBrad Bishop {
611667e050dSBrad Bishop     nlohmann::json j = R"(-11)"_json;
612667e050dSBrad Bishop     BasicVariantType v = double(-11.7);
613667e050dSBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
614667e050dSBrad Bishop }
615667e050dSBrad Bishop 
616667e050dSBrad Bishop TEST(MatchProbe, intEmptyError)
617667e050dSBrad Bishop {
618667e050dSBrad Bishop     nlohmann::json j = R"(-11)"_json;
619667e050dSBrad Bishop     BasicVariantType v;
620667e050dSBrad Bishop     EXPECT_THROW(matchProbe(j, v), std::invalid_argument);
621667e050dSBrad Bishop }
622*3bd8e8d6SBrad Bishop 
623*3bd8e8d6SBrad Bishop TEST(MatchProbe, doubleStringError)
624*3bd8e8d6SBrad Bishop {
625*3bd8e8d6SBrad Bishop     nlohmann::json j = R"(0.0)"_json;
626*3bd8e8d6SBrad Bishop     BasicVariantType v = "0.0"s;
627*3bd8e8d6SBrad Bishop     EXPECT_THROW(matchProbe(j, v), std::invalid_argument);
628*3bd8e8d6SBrad Bishop }
629*3bd8e8d6SBrad Bishop 
630*3bd8e8d6SBrad Bishop TEST(MatchProbe, doubleEqFalse)
631*3bd8e8d6SBrad Bishop {
632*3bd8e8d6SBrad Bishop     nlohmann::json j = R"(0.0)"_json;
633*3bd8e8d6SBrad Bishop     BasicVariantType v = false;
634*3bd8e8d6SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
635*3bd8e8d6SBrad Bishop }
636*3bd8e8d6SBrad Bishop 
637*3bd8e8d6SBrad Bishop TEST(MatchProbe, doubleNeqTrue)
638*3bd8e8d6SBrad Bishop {
639*3bd8e8d6SBrad Bishop     nlohmann::json j = R"(1.1)"_json;
640*3bd8e8d6SBrad Bishop     BasicVariantType v = true;
641*3bd8e8d6SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
642*3bd8e8d6SBrad Bishop }
643*3bd8e8d6SBrad Bishop 
644*3bd8e8d6SBrad Bishop TEST(MatchProbe, doubleEqTrue)
645*3bd8e8d6SBrad Bishop {
646*3bd8e8d6SBrad Bishop     nlohmann::json j = R"(1.0)"_json;
647*3bd8e8d6SBrad Bishop     BasicVariantType v = true;
648*3bd8e8d6SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
649*3bd8e8d6SBrad Bishop }
650*3bd8e8d6SBrad Bishop 
651*3bd8e8d6SBrad Bishop TEST(MatchProbe, doubleEqInt32)
652*3bd8e8d6SBrad Bishop {
653*3bd8e8d6SBrad Bishop     nlohmann::json j = R"(-124.0)"_json;
654*3bd8e8d6SBrad Bishop     BasicVariantType v = int32_t(-124);
655*3bd8e8d6SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
656*3bd8e8d6SBrad Bishop }
657*3bd8e8d6SBrad Bishop 
658*3bd8e8d6SBrad Bishop TEST(MatchProbe, doubleNeqInt32)
659*3bd8e8d6SBrad Bishop {
660*3bd8e8d6SBrad Bishop     nlohmann::json j = R"(-124.0)"_json;
661*3bd8e8d6SBrad Bishop     BasicVariantType v = int32_t(-123);
662*3bd8e8d6SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
663*3bd8e8d6SBrad Bishop }
664*3bd8e8d6SBrad Bishop 
665*3bd8e8d6SBrad Bishop TEST(MatchProbe, doubleRoundNeqInt)
666*3bd8e8d6SBrad Bishop {
667*3bd8e8d6SBrad Bishop     nlohmann::json j = R"(124.7)"_json;
668*3bd8e8d6SBrad Bishop     BasicVariantType v = int32_t(124);
669*3bd8e8d6SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
670*3bd8e8d6SBrad Bishop }
671*3bd8e8d6SBrad Bishop TEST(MatchProbe, doubleEqDouble)
672*3bd8e8d6SBrad Bishop {
673*3bd8e8d6SBrad Bishop     nlohmann::json j = R"(-124.2)"_json;
674*3bd8e8d6SBrad Bishop     BasicVariantType v = double(-124.2);
675*3bd8e8d6SBrad Bishop     EXPECT_TRUE(matchProbe(j, v));
676*3bd8e8d6SBrad Bishop }
677*3bd8e8d6SBrad Bishop 
678*3bd8e8d6SBrad Bishop TEST(MatchProbe, doubleNeqDouble)
679*3bd8e8d6SBrad Bishop {
680*3bd8e8d6SBrad Bishop     nlohmann::json j = R"(-124.3)"_json;
681*3bd8e8d6SBrad Bishop     BasicVariantType v = double(-124.2);
682*3bd8e8d6SBrad Bishop     EXPECT_FALSE(matchProbe(j, v));
683*3bd8e8d6SBrad Bishop }
684*3bd8e8d6SBrad Bishop 
685*3bd8e8d6SBrad Bishop TEST(MatchProbe, doubleEmptyError)
686*3bd8e8d6SBrad Bishop {
687*3bd8e8d6SBrad Bishop     nlohmann::json j = R"(-11.0)"_json;
688*3bd8e8d6SBrad Bishop     BasicVariantType v;
689*3bd8e8d6SBrad Bishop     EXPECT_THROW(matchProbe(j, v), std::invalid_argument);
690*3bd8e8d6SBrad Bishop }
691