Skip to content
This repository was archived by the owner on Jul 14, 2023. It is now read-only.

Commit affa752

Browse files
committed
Add tests
1 parent 550dfac commit affa752

File tree

2 files changed

+110
-25
lines changed

2 files changed

+110
-25
lines changed

.vscode/settings.json

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"files.associations": {
3+
"memory": "cpp",
4+
"__node_handle": "cpp",
5+
"optional": "cpp",
6+
"system_error": "cpp",
7+
"__bit_reference": "cpp",
8+
"__config": "cpp",
9+
"__debug": "cpp",
10+
"__errc": "cpp",
11+
"__functional_base": "cpp",
12+
"__hash_table": "cpp",
13+
"__locale": "cpp",
14+
"__mutex_base": "cpp",
15+
"__nullptr": "cpp",
16+
"__split_buffer": "cpp",
17+
"__string": "cpp",
18+
"__threading_support": "cpp",
19+
"__tree": "cpp",
20+
"__tuple": "cpp",
21+
"algorithm": "cpp",
22+
"array": "cpp",
23+
"atomic": "cpp",
24+
"bit": "cpp",
25+
"bitset": "cpp",
26+
"cctype": "cpp",
27+
"chrono": "cpp",
28+
"cinttypes": "cpp",
29+
"cmath": "cpp",
30+
"complex": "cpp",
31+
"cstdarg": "cpp",
32+
"cstddef": "cpp",
33+
"cstdint": "cpp",
34+
"cstdio": "cpp",
35+
"cstdlib": "cpp",
36+
"cstring": "cpp",
37+
"ctime": "cpp",
38+
"cwchar": "cpp",
39+
"cwctype": "cpp",
40+
"deque": "cpp",
41+
"exception": "cpp",
42+
"forward_list": "cpp",
43+
"fstream": "cpp",
44+
"functional": "cpp",
45+
"initializer_list": "cpp",
46+
"iomanip": "cpp",
47+
"ios": "cpp",
48+
"iosfwd": "cpp",
49+
"iostream": "cpp",
50+
"istream": "cpp",
51+
"iterator": "cpp",
52+
"limits": "cpp",
53+
"list": "cpp",
54+
"locale": "cpp",
55+
"map": "cpp",
56+
"mutex": "cpp",
57+
"new": "cpp",
58+
"ostream": "cpp",
59+
"queue": "cpp",
60+
"ratio": "cpp",
61+
"set": "cpp",
62+
"sstream": "cpp",
63+
"stack": "cpp",
64+
"stdexcept": "cpp",
65+
"streambuf": "cpp",
66+
"string": "cpp",
67+
"string_view": "cpp",
68+
"tuple": "cpp",
69+
"type_traits": "cpp",
70+
"typeinfo": "cpp",
71+
"unordered_map": "cpp",
72+
"unordered_set": "cpp",
73+
"utility": "cpp",
74+
"vector": "cpp"
75+
}
76+
}

Libraries/plist/Tests/Format/test_JSON.cpp

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,33 @@
1010
#include <plist/Format/JSON.h>
1111
#include <plist/Objects.h>
1212

13-
using plist::Format::JSON;
14-
using plist::Format::Encoding;
15-
using plist::String;
13+
using plist::Array;
1614
using plist::Boolean;
15+
using plist::Dictionary;
1716
using plist::Integer;
1817
using plist::Real;
19-
using plist::Dictionary;
20-
using plist::Array;
18+
using plist::String;
19+
using plist::Format::Encoding;
20+
using plist::Format::JSON;
2121

22-
static std::vector<uint8_t>
23-
Contents(std::string const &string)
24-
{
22+
static std::vector<uint8_t> Contents(std::string const &string) {
2523
return std::vector<uint8_t>(string.begin(), string.end());
2624
}
2725

28-
TEST(JSON, Serialize)
29-
{
26+
TEST(JSON, Serialize) {
3027
auto dictionary = Dictionary::New();
3128
dictionary->set("boolean", Boolean::New(true));
3229
dictionary->set("integer", Integer::New(42));
3330
dictionary->set("real", Real::New(3.14));
3431

3532
auto serialize = JSON::Serialize(dictionary.get(), JSON::Create());
3633
ASSERT_NE(serialize.first, nullptr);
37-
EXPECT_EQ(*serialize.first, Contents("{\n\t\"boolean\": true,\n\t\"integer\": 42,\n\t\"real\": 3.14\n}"));
34+
EXPECT_EQ(*serialize.first,
35+
Contents("{\n\t\"boolean\": true,\n\t\"integer\": "
36+
"42,\n\t\"real\": 3.14\n}"));
3837
}
3938

40-
TEST(JSON, SerializeCollections)
41-
{
39+
TEST(JSON, SerializeCollections) {
4240
auto dict = Dictionary::New();
4341
dict->set("one", String::New("1"));
4442
dict->set("two", Integer::New(1));
@@ -53,11 +51,13 @@ TEST(JSON, SerializeCollections)
5351

5452
auto serialize = JSON::Serialize(dictionary.get(), JSON::Create());
5553
ASSERT_NE(serialize.first, nullptr);
56-
EXPECT_EQ(*serialize.first, Contents("{\n\t\"dict\": {\n\t\t\"one\": \"1\",\n\t\t\"two\": 1\n\t},\n\t\"array\": [\n\t\t\"test\",\n\t\t99\n\t]\n}"));
54+
EXPECT_EQ(
55+
*serialize.first,
56+
Contents("{\n\t\"dict\": {\n\t\t\"one\": \"1\",\n\t\t\"two\": "
57+
"1\n\t},\n\t\"array\": [\n\t\t\"test\",\n\t\t99\n\t]\n}"));
5758
}
5859

59-
TEST(JSON, String)
60-
{
60+
TEST(JSON, String) {
6161
auto contents = Contents("\"str*ng\"");
6262

6363
auto deserialize = JSON::Deserialize(contents, JSON::Create());
@@ -69,11 +69,23 @@ TEST(JSON, String)
6969
auto serialize = JSON::Serialize(deserialize.first.get(), JSON::Create());
7070
ASSERT_NE(serialize.first, nullptr);
7171
EXPECT_EQ(*serialize.first, contents);
72+
73+
auto contents2 = Contents("\"©\"");
74+
75+
auto deserialize2 = JSON::Deserialize(contents2, JSON::Create());
76+
ASSERT_NE(deserialize2.first, nullptr);
77+
78+
auto string2 = String::New("©");
79+
EXPECT_TRUE(deserialize2.first->equals(string2.get()));
80+
81+
auto serialize2 = JSON::Serialize(deserialize2.first.get(), JSON::Create());
82+
ASSERT_NE(serialize2.first, nullptr);
83+
EXPECT_EQ(*serialize2.first, contents2);
7284
}
7385

74-
TEST(JSON, BooleanNumber)
75-
{
76-
auto contents = Contents("{\n\t\"boolean\": true,\n\t\"integer\": 42,\n\t\"real\": 3.14\n}");
86+
TEST(JSON, BooleanNumber) {
87+
auto contents = Contents(
88+
"{\n\t\"boolean\": true,\n\t\"integer\": 42,\n\t\"real\": 3.14\n}");
7789

7890
auto deserialize = JSON::Deserialize(contents, JSON::Create());
7991
ASSERT_NE(deserialize.first, nullptr);
@@ -89,24 +101,21 @@ TEST(JSON, BooleanNumber)
89101
EXPECT_EQ(*serialize.first, contents);
90102
}
91103

92-
TEST(JSON, Empty)
93-
{
104+
TEST(JSON, Empty) {
94105
auto contents = Contents("\n\n");
95106

96107
auto deserialize = JSON::Deserialize(contents, JSON::Create());
97108
ASSERT_EQ(deserialize.first, nullptr);
98109
}
99110

100-
TEST(JSON, SingleQuotes)
101-
{
111+
TEST(JSON, SingleQuotes) {
102112
/* Single quotes are not allowed in JSON. */
103113
auto contents = Contents("{ 'one': 1 }");
104114
auto deserialize = JSON::Deserialize(contents, JSON::Create());
105115
EXPECT_EQ(deserialize.first, nullptr);
106116
}
107117

108-
TEST(JSON, Number)
109-
{
118+
TEST(JSON, Number) {
110119
/* Numbers can be zero. */
111120
auto contents1 = Contents("{ \"key\" : 0 }");
112121
auto deserialize1 = JSON::Deserialize(contents1, JSON::Create());

0 commit comments

Comments
 (0)