-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.cpp
More file actions
67 lines (56 loc) · 1.35 KB
/
Test.cpp
File metadata and controls
67 lines (56 loc) · 1.35 KB
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
#include <gtest/gtest.h>
#include <cppjson/cppjson.hpp>
TEST(BasicTests, ArraySize)
{
cppjson::Array array{};
array[] = 1;
array[] = 2;
array[] = 3.0;
EXPECT_TRUE(array.Size() == 3);
}
TEST(BasicTests, InvalidAssignment)
{
cppjson::Object obj{};
obj["number"] = 123.0;
EXPECT_THROW({ obj["number"] = "NaN"; }, std::logic_error);
}
TEST(BasicTests, NestedObjects)
{
cppjson::Object object{};
object["sub"]["veryNested"] = 6.0;
EXPECT_EQ(6.0, (double)object["sub"]["veryNested"]);
}
TEST(BasicTests, ObjectTypes)
{
cppjson::Object obj{};
obj["string"] = "Hello";
obj["number"] = 42.0;
obj["boolean"] = true;
obj["null"] = nullptr;
EXPECT_TRUE(IsType<std::string>(obj["string"]));
EXPECT_TRUE(IsType<double>(obj["number"]));
EXPECT_TRUE(IsType<bool>(obj["boolean"]));
EXPECT_TRUE(IsType<std::nullptr_t>(obj["null"]));
}
TEST(BasicTests, Primitives)
{
cppjson::Object object{};
object["test1"] = "Hello World";
object["test2"] = 123.0;
EXPECT_EQ("Hello World", static_cast<const std::string&>(object["test1"]));
EXPECT_EQ(123.0, (double)object["test2"]);
}
TEST(BasicTests, ValueComparisons)
{
cppjson::Object obj{};
obj["a"] = 5.0;
obj["b"] = 5.0;
obj["c"] = 10.0;
EXPECT_TRUE(obj["a"] == obj["b"]);
EXPECT_FALSE(obj["a"] == obj["c"]);
}
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}