File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -283,6 +283,12 @@ class json_objectt:public jsont
283
283
{
284
284
}
285
285
286
+ explicit json_objectt (
287
+ std::initializer_list<typename objectt::value_type> initializer_list)
288
+ : json_objectt{objectt{initializer_list}}
289
+ {
290
+ }
291
+
286
292
jsont &operator [](const std::string &key)
287
293
{
288
294
return object[key];
Original file line number Diff line number Diff line change @@ -46,3 +46,30 @@ SCENARIO(
46
46
}
47
47
}
48
48
}
49
+
50
+ SCENARIO (
51
+ " Test that json_objectt can be constructed from an initializer list." ,
52
+ " [core][util][json]" )
53
+ {
54
+ GIVEN (" A json_objectt constructed from an initializer list." )
55
+ {
56
+ const json_objectt object{
57
+ {" number" , json_numbert{" 6" }},
58
+ {" string" , json_stringt{" eggs" }},
59
+ {" mice" ,
60
+ json_objectt{{" number" , json_numbert{" 3" }},
61
+ {" string" , json_stringt{" blind" }}}}};
62
+ THEN (" The fields of the json_objectt match the initialiser list." )
63
+ {
64
+ REQUIRE (object[" number" ].kind == jsont::kindt::J_NUMBER);
65
+ REQUIRE (object[" number" ].value == " 6" );
66
+ REQUIRE (object[" string" ].kind == jsont::kindt::J_STRING);
67
+ REQUIRE (object[" string" ].value == " eggs" );
68
+ const json_objectt mice = to_json_object (object[" mice" ]);
69
+ REQUIRE (mice[" number" ].kind == jsont::kindt::J_NUMBER);
70
+ REQUIRE (mice[" number" ].value == " 3" );
71
+ REQUIRE (mice[" string" ].kind == jsont::kindt::J_STRING);
72
+ REQUIRE (mice[" string" ].value == " blind" );
73
+ }
74
+ }
75
+ }
You can’t perform that action at this time.
0 commit comments