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
53c9564c
Commit
53c9564c
authored
Feb 11, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fix and test cases
parent
4d23c496
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
269 additions
and
3 deletions
+269
-3
src/json.hpp
src/json.hpp
+2
-1
src/json.hpp.re2c
src/json.hpp.re2c
+2
-1
test/unit.cpp
test/unit.cpp
+265
-1
No files found.
src/json.hpp
View file @
53c9564c
...
...
@@ -256,6 +256,8 @@ class basic_json
std
::
enable_if
<
not
std
::
is_same
<
V
,
basic_json
::
iterator
>
::
value
and
not
std
::
is_same
<
V
,
basic_json
::
const_iterator
>::
value
and
not
std
::
is_same
<
V
,
typename
array_t
::
iterator
>::
value
and
not
std
::
is_same
<
V
,
typename
array_t
::
const_iterator
>::
value
and
std
::
is_constructible
<
basic_json
,
typename
V
::
value_type
>::
value
,
int
>::
type
=
0
>
inline
basic_json
(
const
V
&
value
)
...
...
@@ -1678,7 +1680,6 @@ class basic_json
/// copy assignment
inline
iterator
&
operator
=
(
const
iterator
&
other
)
noexcept
{
assert
(
false
);
// not sure if function will ever be called
m_object
=
other
.
m_object
;
m_it
=
other
.
m_it
;
return
*
this
;
...
...
src/json.hpp.re2c
View file @
53c9564c
...
...
@@ -256,6 +256,8 @@ class basic_json
std::enable_if<
not std::is_same<V, basic_json::iterator>::value and
not std::is_same<V, basic_json::const_iterator>::value and
not std::is_same<V, typename array_t::iterator>::value and
not std::is_same<V, typename array_t::const_iterator>::value and
std::is_constructible<basic_json, typename V::value_type>::value, int>::type
= 0>
inline basic_json(const V& value)
...
...
@@ -1678,7 +1680,6 @@ class basic_json
/// copy assignment
inline iterator& operator=(const iterator& other) noexcept
{
assert(false); // not sure if function will ever be called
m_object = other.m_object;
m_it = other.m_it;
return *this;
...
...
test/unit.cpp
View file @
53c9564c
...
...
@@ -3912,13 +3912,275 @@ TEST_CASE("deserialization")
ss
>>
j
;
CHECK
(
j
==
json
({
"foo"
,
1
,
2
,
3
,
false
,
{{
"one"
,
1
}}}));
}
SECTION
(
"user-defined string literal"
)
{
CHECK
(
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}]"
_json
==
json
({
"foo"
,
1
,
2
,
3
,
false
,
{{
"one"
,
1
}}}));
}
}
TEST_CASE
(
"iterator class"
)
{
SECTION
(
"initialization"
)
{
SECTION
(
"constructor with object"
)
{
SECTION
(
"null"
)
{
json
j
(
json
::
value_t
::
null
);
json
::
iterator
it
(
&
j
);
}
SECTION
(
"object"
)
{
json
j
(
json
::
value_t
::
object
);
json
::
iterator
it
(
&
j
);
}
SECTION
(
"array"
)
{
json
j
(
json
::
value_t
::
array
);
json
::
iterator
it
(
&
j
);
}
}
SECTION
(
"copy assignment"
)
{
json
j
(
json
::
value_t
::
null
);
json
::
iterator
it
(
&
j
);
json
::
iterator
it2
(
&
j
);
it2
=
it
;
}
SECTION
(
"set_begin"
)
{
SECTION
(
"null"
)
{
json
j
(
json
::
value_t
::
null
);
json
::
iterator
it
(
&
j
);
it
.
set_begin
();
CHECK
(
it
==
j
.
begin
());
}
SECTION
(
"object"
)
{
json
j
(
json
::
value_t
::
object
);
json
::
iterator
it
(
&
j
);
it
.
set_begin
();
CHECK
(
it
==
j
.
begin
());
}
SECTION
(
"array"
)
{
json
j
(
json
::
value_t
::
array
);
json
::
iterator
it
(
&
j
);
it
.
set_begin
();
CHECK
(
it
==
j
.
begin
());
}
}
SECTION
(
"set_end"
)
{
SECTION
(
"null"
)
{
json
j
(
json
::
value_t
::
null
);
json
::
iterator
it
(
&
j
);
it
.
set_end
();
CHECK
(
it
==
j
.
end
());
}
SECTION
(
"object"
)
{
json
j
(
json
::
value_t
::
object
);
json
::
iterator
it
(
&
j
);
it
.
set_end
();
CHECK
(
it
==
j
.
end
());
}
SECTION
(
"array"
)
{
json
j
(
json
::
value_t
::
array
);
json
::
iterator
it
(
&
j
);
it
.
set_end
();
CHECK
(
it
==
j
.
end
());
}
}
}
SECTION
(
"element access"
)
{
SECTION
(
"operator*"
)
{
SECTION
(
"null"
)
{
json
j
(
json
::
value_t
::
null
);
json
::
iterator
it
=
j
.
begin
();
CHECK_THROWS_AS
(
*
it
,
std
::
out_of_range
);
}
SECTION
(
"number"
)
{
json
j
(
17
);
json
::
iterator
it
=
j
.
begin
();
CHECK
(
*
it
==
json
(
17
));
it
=
j
.
end
();
CHECK_THROWS_AS
(
*
it
,
std
::
out_of_range
);
}
SECTION
(
"object"
)
{
json
j
({{
"foo"
,
"bar"
}});
json
::
iterator
it
=
j
.
begin
();
CHECK
(
*
it
==
json
(
"bar"
));
}
SECTION
(
"array"
)
{
json
j
({
1
,
2
,
3
,
4
});
json
::
iterator
it
=
j
.
begin
();
CHECK
(
*
it
==
json
(
1
));
}
}
SECTION
(
"operator->"
)
{
SECTION
(
"null"
)
{
json
j
(
json
::
value_t
::
null
);
json
::
iterator
it
=
j
.
begin
();
CHECK_THROWS_AS
(
it
->
type_name
(),
std
::
out_of_range
);
}
SECTION
(
"number"
)
{
json
j
(
17
);
json
::
iterator
it
=
j
.
begin
();
CHECK
(
it
->
type_name
()
==
"number"
);
it
=
j
.
end
();
CHECK_THROWS_AS
(
it
->
type_name
(),
std
::
out_of_range
);
}
SECTION
(
"object"
)
{
json
j
({{
"foo"
,
"bar"
}});
json
::
iterator
it
=
j
.
begin
();
CHECK
(
it
->
type_name
()
==
"string"
);
}
SECTION
(
"array"
)
{
json
j
({
1
,
2
,
3
,
4
});
json
::
iterator
it
=
j
.
begin
();
CHECK
(
it
->
type_name
()
==
"number"
);
}
}
}
SECTION
(
"increment/decrement"
)
{
SECTION
(
"post-increment"
)
{
SECTION
(
"null"
)
{
json
j
(
json
::
value_t
::
null
);
json
::
iterator
it
=
j
.
begin
();
CHECK
(
it
.
m_it
.
generic_iterator
==
json
::
generic_iterator_value
::
end
);
it
++
;
CHECK
(
it
.
m_it
.
generic_iterator
==
json
::
generic_iterator_value
::
invalid
);
}
SECTION
(
"number"
)
{
json
j
(
17
);
json
::
iterator
it
=
j
.
begin
();
CHECK
(
it
.
m_it
.
generic_iterator
==
json
::
generic_iterator_value
::
begin
);
it
++
;
CHECK
(
it
.
m_it
.
generic_iterator
==
json
::
generic_iterator_value
::
end
);
it
++
;
CHECK
(
it
.
m_it
.
generic_iterator
==
json
::
generic_iterator_value
::
invalid
);
}
SECTION
(
"object"
)
{
json
j
({{
"foo"
,
"bar"
}});
json
::
iterator
it
=
j
.
begin
();
CHECK
(
it
.
m_it
.
object_iterator
==
it
.
m_object
->
m_value
.
object
->
begin
());
it
++
;
CHECK
(
it
.
m_it
.
object_iterator
==
it
.
m_object
->
m_value
.
object
->
end
());
}
SECTION
(
"array"
)
{
json
j
({
1
,
2
,
3
,
4
});
json
::
iterator
it
=
j
.
begin
();
CHECK
(
it
.
m_it
.
array_iterator
==
it
.
m_object
->
m_value
.
array
->
begin
());
it
++
;
CHECK
(
it
.
m_it
.
array_iterator
!=
it
.
m_object
->
m_value
.
array
->
begin
());
CHECK
(
it
.
m_it
.
array_iterator
!=
it
.
m_object
->
m_value
.
array
->
end
());
it
++
;
CHECK
(
it
.
m_it
.
array_iterator
!=
it
.
m_object
->
m_value
.
array
->
begin
());
CHECK
(
it
.
m_it
.
array_iterator
!=
it
.
m_object
->
m_value
.
array
->
end
());
it
++
;
CHECK
(
it
.
m_it
.
array_iterator
!=
it
.
m_object
->
m_value
.
array
->
begin
());
CHECK
(
it
.
m_it
.
array_iterator
!=
it
.
m_object
->
m_value
.
array
->
end
());
it
++
;
CHECK
(
it
.
m_it
.
array_iterator
!=
it
.
m_object
->
m_value
.
array
->
begin
());
CHECK
(
it
.
m_it
.
array_iterator
==
it
.
m_object
->
m_value
.
array
->
end
());
}
}
SECTION
(
"pre-increment"
)
{
SECTION
(
"null"
)
{
json
j
(
json
::
value_t
::
null
);
json
::
iterator
it
=
j
.
begin
();
CHECK
(
it
.
m_it
.
generic_iterator
==
json
::
generic_iterator_value
::
end
);
++
it
;
CHECK
(
it
.
m_it
.
generic_iterator
==
json
::
generic_iterator_value
::
invalid
);
}
SECTION
(
"number"
)
{
json
j
(
17
);
json
::
iterator
it
=
j
.
begin
();
CHECK
(
it
.
m_it
.
generic_iterator
==
json
::
generic_iterator_value
::
begin
);
++
it
;
CHECK
(
it
.
m_it
.
generic_iterator
==
json
::
generic_iterator_value
::
end
);
++
it
;
CHECK
(
it
.
m_it
.
generic_iterator
==
json
::
generic_iterator_value
::
invalid
);
}
SECTION
(
"object"
)
{
json
j
({{
"foo"
,
"bar"
}});
json
::
iterator
it
=
j
.
begin
();
CHECK
(
it
.
m_it
.
object_iterator
==
it
.
m_object
->
m_value
.
object
->
begin
());
++
it
;
CHECK
(
it
.
m_it
.
object_iterator
==
it
.
m_object
->
m_value
.
object
->
end
());
}
SECTION
(
"array"
)
{
json
j
({
1
,
2
,
3
,
4
});
json
::
iterator
it
=
j
.
begin
();
CHECK
(
it
.
m_it
.
array_iterator
==
it
.
m_object
->
m_value
.
array
->
begin
());
++
it
;
CHECK
(
it
.
m_it
.
array_iterator
!=
it
.
m_object
->
m_value
.
array
->
begin
());
CHECK
(
it
.
m_it
.
array_iterator
!=
it
.
m_object
->
m_value
.
array
->
end
());
++
it
;
CHECK
(
it
.
m_it
.
array_iterator
!=
it
.
m_object
->
m_value
.
array
->
begin
());
CHECK
(
it
.
m_it
.
array_iterator
!=
it
.
m_object
->
m_value
.
array
->
end
());
++
it
;
CHECK
(
it
.
m_it
.
array_iterator
!=
it
.
m_object
->
m_value
.
array
->
begin
());
CHECK
(
it
.
m_it
.
array_iterator
!=
it
.
m_object
->
m_value
.
array
->
end
());
++
it
;
CHECK
(
it
.
m_it
.
array_iterator
!=
it
.
m_object
->
m_value
.
array
->
begin
());
CHECK
(
it
.
m_it
.
array_iterator
==
it
.
m_object
->
m_value
.
array
->
end
());
}
}
}
}
TEST_CASE
(
"convenience functions"
)
{
...
...
@@ -4202,6 +4464,8 @@ TEST_CASE("parser class")
CHECK_THROWS_AS
(
json
::
parser
(
"-"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"--"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"-0."
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"-."
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"0.:"
).
parse
(),
std
::
invalid_argument
);
// unexpected end of null
CHECK_THROWS_AS
(
json
::
parser
(
"n"
).
parse
(),
std
::
invalid_argument
);
...
...
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