Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
5ec43360
Commit
5ec43360
authored
Jan 31, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more test cases
parent
385865c4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
10 deletions
+47
-10
src/json.hpp
src/json.hpp
+2
-10
test/unit.cpp
test/unit.cpp
+45
-0
No files found.
src/json.hpp
View file @
5ec43360
...
...
@@ -350,7 +350,7 @@ class basic_json
// if object is wanted but impossible, throw an exception
if
(
manual_type
==
value_t
::
object
and
not
is_object
)
{
throw
std
::
logic_error
(
"cannot create JSON object"
);
throw
std
::
logic_error
(
"cannot create JSON object
from initializer list
"
);
}
}
...
...
@@ -378,17 +378,9 @@ class basic_json
}
inline
static
basic_json
object
(
list_init_t
l
=
list_init_t
())
{
// if more than one element is in the initializer list, wrap it
if
(
l
.
size
()
>
1
)
{
return
basic_json
({
l
},
false
,
value_t
::
object
);
}
else
{
return
basic_json
(
l
,
false
,
value_t
::
object
);
}
}
///////////////////////////////////////
// other constructors and destructor //
...
...
test/unit.cpp
View file @
5ec43360
...
...
@@ -3,6 +3,8 @@
#include "json.hpp"
#include <unordered_map>
#include <list>
#include <sstream>
using
nlohmann
::
json
;
...
...
@@ -62,6 +64,49 @@ TEST_CASE()
json
array_not_object
=
{
json
::
array
({
"currency"
,
"USD"
}),
json
::
array
({
"value"
,
42.99
})
};
std
::
cerr
<<
"array_not_object: "
<<
array_not_object
<<
std
::
endl
;
}
{
CHECK_THROWS_AS
(
json
::
object
({
1
,
2
,
3
}),
std
::
logic_error
);
}
{
CHECK
(
json
::
object
({{
"foo"
,
1
},
{
"bar"
,
2
},
{
"baz"
,
3
}}).
size
()
==
3
);
CHECK
(
json
::
object
({{
"foo"
,
1
}}).
size
()
==
1
);
CHECK
(
json
::
object
().
size
()
==
0
);
}
{
json
j
=
json
::
object
({{
"foo"
,
1
},
{
"bar"
,
2
},
{
"baz"
,
3
}});
{
CHECK
(
j
[
"foo"
]
==
json
(
1
));
CHECK
(
j
.
at
(
"foo"
)
==
json
(
1
));
}
{
std
::
map
<
std
::
string
,
json
>
m
=
j
;
auto
k
=
j
.
get
<
std
::
map
<
std
::
string
,
json
>>
();
CHECK
(
m
==
k
);
}
{
std
::
unordered_map
<
std
::
string
,
json
>
m
=
j
;
auto
k
=
j
.
get
<
std
::
unordered_map
<
std
::
string
,
json
>>
();
CHECK
(
m
==
k
);
}
}
{
json
j
=
{
1
,
2
,
3
,
4
,
5
};
{
CHECK
(
j
[
0
]
==
json
(
1
));
CHECK
(
j
.
at
(
0
)
==
json
(
1
));
}
{
std
::
vector
<
json
>
m
=
j
;
auto
k
=
j
.
get
<
std
::
list
<
json
>>
();
CHECK
(
m
==
k
);
}
{
std
::
set
<
json
>
m
=
j
;
auto
k
=
j
.
get
<
std
::
set
<
json
>>
();
CHECK
(
m
==
k
);
}
}
}
TEST_CASE
(
"null"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment