File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,11 @@ class json_arrayt:public jsont
165
165
{
166
166
}
167
167
168
+ explicit json_arrayt (std::initializer_list<jsont> initializer_list)
169
+ : json_arrayt{arrayt{initializer_list}}
170
+ {
171
+ }
172
+
168
173
void resize (std::size_t size)
169
174
{
170
175
array.resize (size);
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ SRC += analyses/ai/ai.cpp \
51
51
util/graph.cpp \
52
52
util/irep.cpp \
53
53
util/irep_sharing.cpp \
54
+ util/json_array.cpp \
54
55
util/json_object.cpp \
55
56
util/memory_info.cpp \
56
57
util/message.cpp \
Original file line number Diff line number Diff line change
1
+ /* ******************************************************************\
2
+
3
+ Module: Catch tests for json_arrayt
4
+
5
+ Author: Diffblue Ltd.
6
+
7
+ \*******************************************************************/
8
+
9
+ #include < testing-utils/catch.hpp>
10
+ #include < util/json.h>
11
+
12
+ SCENARIO (
13
+ " Test that json_arrayt can be constructed from an initializer list." ,
14
+ " [core][util][json]" )
15
+ {
16
+ GIVEN (" A json_arrayt constructed from an initializer list." )
17
+ {
18
+ const json_arrayt array{
19
+ json_stringt{" one" }, json_numbert{" 2" }, json_stringt{" three" }};
20
+ THEN (" The elements of the `json_arrayt` match the initialiser list." )
21
+ {
22
+ auto it = array.begin ();
23
+ REQUIRE (it->kind == jsont::kindt::J_STRING);
24
+ REQUIRE (it->value == " one" );
25
+ ++it;
26
+ REQUIRE (it->kind == jsont::kindt::J_NUMBER);
27
+ REQUIRE (it->value == " 2" );
28
+ ++it;
29
+ REQUIRE (it->kind == jsont::kindt::J_STRING);
30
+ REQUIRE (it->value == " three" );
31
+ ++it;
32
+ REQUIRE (it == array.end ());
33
+ }
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments