Skip to content

Commit 24b6e02

Browse files
committed
✅ improved test coverage
1 parent b27a142 commit 24b6e02

6 files changed

Lines changed: 204 additions & 72 deletions

File tree

test/src/unit-capacity.cpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ TEST_CASE("capacity")
3838
SECTION("boolean")
3939
{
4040
json j = true;
41-
json j_const(j);
41+
const json j_const(j);
4242

4343
SECTION("result of empty")
4444
{
@@ -56,7 +56,7 @@ TEST_CASE("capacity")
5656
SECTION("string")
5757
{
5858
json j = "hello world";
59-
json j_const(j);
59+
const json j_const(j);
6060

6161
SECTION("result of empty")
6262
{
@@ -76,7 +76,7 @@ TEST_CASE("capacity")
7676
SECTION("empty array")
7777
{
7878
json j = json::array();
79-
json j_const(j);
79+
const json j_const(j);
8080

8181
SECTION("result of empty")
8282
{
@@ -94,7 +94,7 @@ TEST_CASE("capacity")
9494
SECTION("filled array")
9595
{
9696
json j = {1, 2, 3};
97-
json j_const(j);
97+
const json j_const(j);
9898

9999
SECTION("result of empty")
100100
{
@@ -115,7 +115,7 @@ TEST_CASE("capacity")
115115
SECTION("empty object")
116116
{
117117
json j = json::object();
118-
json j_const(j);
118+
const json j_const(j);
119119

120120
SECTION("result of empty")
121121
{
@@ -133,7 +133,7 @@ TEST_CASE("capacity")
133133
SECTION("filled object")
134134
{
135135
json j = {{"one", 1}, {"two", 2}, {"three", 3}};
136-
json j_const(j);
136+
const json j_const(j);
137137

138138
SECTION("result of empty")
139139
{
@@ -151,8 +151,8 @@ TEST_CASE("capacity")
151151

152152
SECTION("number (integer)")
153153
{
154-
json j = 23;
155-
json j_const(j);
154+
json j = -23;
155+
const json j_const(j);
156156

157157
SECTION("result of empty")
158158
{
@@ -170,7 +170,7 @@ TEST_CASE("capacity")
170170
SECTION("number (unsigned)")
171171
{
172172
json j = 23u;
173-
json j_const(j);
173+
const json j_const(j);
174174

175175
SECTION("result of empty")
176176
{
@@ -188,7 +188,7 @@ TEST_CASE("capacity")
188188
SECTION("number (float)")
189189
{
190190
json j = 23.42;
191-
json j_const(j);
191+
const json j_const(j);
192192

193193
SECTION("result of empty")
194194
{
@@ -206,7 +206,7 @@ TEST_CASE("capacity")
206206
SECTION("null")
207207
{
208208
json j = nullptr;
209-
json j_const(j);
209+
const json j_const(j);
210210

211211
SECTION("result of empty")
212212
{
@@ -227,7 +227,7 @@ TEST_CASE("capacity")
227227
SECTION("boolean")
228228
{
229229
json j = true;
230-
json j_const(j);
230+
const json j_const(j);
231231

232232
SECTION("result of size")
233233
{
@@ -247,7 +247,7 @@ TEST_CASE("capacity")
247247
SECTION("string")
248248
{
249249
json j = "hello world";
250-
json j_const(j);
250+
const json j_const(j);
251251

252252
SECTION("result of size")
253253
{
@@ -269,7 +269,7 @@ TEST_CASE("capacity")
269269
SECTION("empty array")
270270
{
271271
json j = json::array();
272-
json j_const(j);
272+
const json j_const(j);
273273

274274
SECTION("result of size")
275275
{
@@ -289,7 +289,7 @@ TEST_CASE("capacity")
289289
SECTION("filled array")
290290
{
291291
json j = {1, 2, 3};
292-
json j_const(j);
292+
const json j_const(j);
293293

294294
SECTION("result of size")
295295
{
@@ -312,7 +312,7 @@ TEST_CASE("capacity")
312312
SECTION("empty object")
313313
{
314314
json j = json::object();
315-
json j_const(j);
315+
const json j_const(j);
316316

317317
SECTION("result of size")
318318
{
@@ -332,7 +332,7 @@ TEST_CASE("capacity")
332332
SECTION("filled object")
333333
{
334334
json j = {{"one", 1}, {"two", 2}, {"three", 3}};
335-
json j_const(j);
335+
const json j_const(j);
336336

337337
SECTION("result of size")
338338
{
@@ -352,8 +352,8 @@ TEST_CASE("capacity")
352352

353353
SECTION("number (integer)")
354354
{
355-
json j = 23;
356-
json j_const(j);
355+
json j = -23;
356+
const json j_const(j);
357357

358358
SECTION("result of size")
359359
{
@@ -373,7 +373,7 @@ TEST_CASE("capacity")
373373
SECTION("number (unsigned)")
374374
{
375375
json j = 23u;
376-
json j_const(j);
376+
const json j_const(j);
377377

378378
SECTION("result of size")
379379
{
@@ -393,7 +393,7 @@ TEST_CASE("capacity")
393393
SECTION("number (float)")
394394
{
395395
json j = 23.42;
396-
json j_const(j);
396+
const json j_const(j);
397397

398398
SECTION("result of size")
399399
{
@@ -413,7 +413,7 @@ TEST_CASE("capacity")
413413
SECTION("null")
414414
{
415415
json j = nullptr;
416-
json j_const(j);
416+
const json j_const(j);
417417

418418
SECTION("result of size")
419419
{
@@ -436,7 +436,7 @@ TEST_CASE("capacity")
436436
SECTION("boolean")
437437
{
438438
json j = true;
439-
json j_const(j);
439+
const json j_const(j);
440440

441441
SECTION("result of max_size")
442442
{
@@ -448,7 +448,7 @@ TEST_CASE("capacity")
448448
SECTION("string")
449449
{
450450
json j = "hello world";
451-
json j_const(j);
451+
const json j_const(j);
452452

453453
SECTION("result of max_size")
454454
{
@@ -462,7 +462,7 @@ TEST_CASE("capacity")
462462
SECTION("empty array")
463463
{
464464
json j = json::array();
465-
json j_const(j);
465+
const json j_const(j);
466466

467467
SECTION("result of max_size")
468468
{
@@ -474,7 +474,7 @@ TEST_CASE("capacity")
474474
SECTION("filled array")
475475
{
476476
json j = {1, 2, 3};
477-
json j_const(j);
477+
const json j_const(j);
478478

479479
SECTION("result of max_size")
480480
{
@@ -489,7 +489,7 @@ TEST_CASE("capacity")
489489
SECTION("empty object")
490490
{
491491
json j = json::object();
492-
json j_const(j);
492+
const json j_const(j);
493493

494494
SECTION("result of max_size")
495495
{
@@ -501,7 +501,7 @@ TEST_CASE("capacity")
501501
SECTION("filled object")
502502
{
503503
json j = {{"one", 1}, {"two", 2}, {"three", 3}};
504-
json j_const(j);
504+
const json j_const(j);
505505

506506
SECTION("result of max_size")
507507
{
@@ -513,8 +513,8 @@ TEST_CASE("capacity")
513513

514514
SECTION("number (integer)")
515515
{
516-
json j = 23;
517-
json j_const(j);
516+
json j = -23;
517+
const json j_const(j);
518518

519519
SECTION("result of max_size")
520520
{
@@ -526,7 +526,7 @@ TEST_CASE("capacity")
526526
SECTION("number (unsigned)")
527527
{
528528
json j = 23u;
529-
json j_const(j);
529+
const json j_const(j);
530530

531531
SECTION("result of max_size")
532532
{
@@ -538,7 +538,7 @@ TEST_CASE("capacity")
538538
SECTION("number (float)")
539539
{
540540
json j = 23.42;
541-
json j_const(j);
541+
const json j_const(j);
542542

543543
SECTION("result of max_size")
544544
{
@@ -550,7 +550,7 @@ TEST_CASE("capacity")
550550
SECTION("null")
551551
{
552552
json j = nullptr;
553-
json j_const(j);
553+
const json j_const(j);
554554

555555
SECTION("result of max_size")
556556
{

test/src/unit-comparison.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ TEST_CASE("lexicographical comparison operators")
8888
json j_values =
8989
{
9090
nullptr, nullptr,
91-
17, 42,
91+
-17, 42,
9292
8u, 13u,
9393
3.14159, 23.42,
9494
"foo", "bar",
@@ -125,6 +125,8 @@ TEST_CASE("lexicographical comparison operators")
125125
{
126126
CAPTURE(i);
127127
CAPTURE(j);
128+
CAPTURE(j_values[i]);
129+
CAPTURE(j_values[j]);
128130
// check precomputed values
129131
CHECK( (j_values[i] == j_values[j]) == expected[i][j] );
130132
}
@@ -172,11 +174,11 @@ TEST_CASE("lexicographical comparison operators")
172174
{
173175
{false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true},
174176
{false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true},
175-
{false, false, false, true, false, false, false, true, true, true, false, false, true, true, true, true},
177+
{false, false, false, true, true, true, true, true, true, true, false, false, true, true, true, true},
176178
{false, false, false, false, false, false, false, false, true, true, false, false, true, true, true, true},
177-
{false, false, true, true, false, true, false, true, true, true, false, false, true, true, true, true},
178-
{false, false, true, true, false, false, false, true, true, true, false, false, true, true, true, true},
179-
{false, false, true, true, true, true, false, true, true, true, false, false, true, true, true, true},
179+
{false, false, false, true, false, true, false, true, true, true, false, false, true, true, true, true},
180+
{false, false, false, true, false, false, false, true, true, true, false, false, true, true, true, true},
181+
{false, false, false, true, true, true, false, true, true, true, false, false, true, true, true, true},
180182
{false, false, false, true, false, false, false, false, true, true, false, false, true, true, true, true},
181183
{false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
182184
{false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false},
@@ -194,6 +196,8 @@ TEST_CASE("lexicographical comparison operators")
194196
{
195197
CAPTURE(i);
196198
CAPTURE(j);
199+
CAPTURE(j_values[i]);
200+
CAPTURE(j_values[j]);
197201
// check precomputed values
198202
CHECK( (j_values[i] < j_values[j]) == expected[i][j] );
199203
}

test/src/unit-constructor1.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,34 +77,39 @@ TEST_CASE("constructors")
7777
auto t = json::value_t::boolean;
7878
json j(t);
7979
CHECK(j.type() == t);
80+
CHECK(j == false);
8081
}
8182

8283
SECTION("string")
8384
{
8485
auto t = json::value_t::string;
8586
json j(t);
8687
CHECK(j.type() == t);
88+
CHECK(j == "");
8789
}
8890

8991
SECTION("number_integer")
9092
{
9193
auto t = json::value_t::number_integer;
9294
json j(t);
9395
CHECK(j.type() == t);
96+
CHECK(j == 0);
9497
}
9598

9699
SECTION("number_unsigned")
97100
{
98101
auto t = json::value_t::number_unsigned;
99102
json j(t);
100103
CHECK(j.type() == t);
104+
CHECK(j == 0);
101105
}
102106

103107
SECTION("number_float")
104108
{
105109
auto t = json::value_t::number_float;
106110
json j(t);
107111
CHECK(j.type() == t);
112+
CHECK(j == 0.0);
108113
}
109114
}
110115

test/src/unit-meta.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,10 @@ TEST_CASE("version information")
4747
{"minor", 1},
4848
{"patch", 1}
4949
}));
50+
51+
CHECK(j.find("platform") != j.end());
52+
CHECK(j.at("compiler").find("family") != j.at("compiler").end());
53+
CHECK(j.at("compiler").find("version") != j.at("compiler").end());
54+
CHECK(j.at("compiler").find("c++") != j.at("compiler").end());
5055
}
5156
}

test/src/unit-modifiers.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,13 @@ TEST_CASE("modifiers")
271271
j.push_back({"key2", "bar"});
272272
CHECK(j == json({{"key1", 1}, {"key2", "bar"}}));
273273

274-
json k = {{"key1", 1}};
275-
CHECK_THROWS_AS(k.push_back({1, 2, 3, 4}), json::type_error&);
276-
CHECK_THROWS_WITH(k.push_back({1, 2, 3, 4}), "[json.exception.type_error.308] cannot use push_back() with object");
274+
// invalid values (no string/val pair)
275+
CHECK_THROWS_AS(j.push_back({1}), json::type_error&);
276+
CHECK_THROWS_WITH(j.push_back({1}), "[json.exception.type_error.308] cannot use push_back() with object");
277+
CHECK_THROWS_AS(j.push_back({1,2}), json::type_error&);
278+
CHECK_THROWS_WITH(j.push_back({1, 2}), "[json.exception.type_error.308] cannot use push_back() with object");
279+
CHECK_THROWS_AS(j.push_back({1, 2, 3, 4}), json::type_error&);
280+
CHECK_THROWS_WITH(j.push_back({1, 2, 3, 4}), "[json.exception.type_error.308] cannot use push_back() with object");
277281
}
278282
}
279283
}

0 commit comments

Comments
 (0)