Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
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
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
268 additions
and
2 deletions
+268
-2
json.hpp
src/json.hpp
+2
-1
json.hpp.re2c
src/json.hpp.re2c
+2
-1
unit.cpp
test/unit.cpp
+264
-0
No files found.
src/json.hpp
View file @
53c9564c
...
@@ -256,6 +256,8 @@ class basic_json
...
@@ -256,6 +256,8 @@ class basic_json
std
::
enable_if
<
std
::
enable_if
<
not
std
::
is_same
<
V
,
basic_json
::
iterator
>::
value
and
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
,
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
std
::
is_constructible
<
basic_json
,
typename
V
::
value_type
>::
value
,
int
>::
type
=
0
>
=
0
>
inline
basic_json
(
const
V
&
value
)
inline
basic_json
(
const
V
&
value
)
...
@@ -1678,7 +1680,6 @@ class basic_json
...
@@ -1678,7 +1680,6 @@ class basic_json
/// copy assignment
/// copy assignment
inline
iterator
&
operator
=
(
const
iterator
&
other
)
noexcept
inline
iterator
&
operator
=
(
const
iterator
&
other
)
noexcept
{
{
assert
(
false
);
// not sure if function will ever be called
m_object
=
other
.
m_object
;
m_object
=
other
.
m_object
;
m_it
=
other
.
m_it
;
m_it
=
other
.
m_it
;
return
*
this
;
return
*
this
;
...
...
src/json.hpp.re2c
View file @
53c9564c
...
@@ -256,6 +256,8 @@ class basic_json
...
@@ -256,6 +256,8 @@ class basic_json
std::enable_if<
std::enable_if<
not std::is_same<V, basic_json::iterator>::value and
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, 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
std::is_constructible<basic_json, typename V::value_type>::value, int>::type
= 0>
= 0>
inline basic_json(const V& value)
inline basic_json(const V& value)
...
@@ -1678,7 +1680,6 @@ class basic_json
...
@@ -1678,7 +1680,6 @@ class basic_json
/// copy assignment
/// copy assignment
inline iterator& operator=(const iterator& other) noexcept
inline iterator& operator=(const iterator& other) noexcept
{
{
assert(false); // not sure if function will ever be called
m_object = other.m_object;
m_object = other.m_object;
m_it = other.m_it;
m_it = other.m_it;
return *this;
return *this;
...
...
test/unit.cpp
View file @
53c9564c
...
@@ -3919,6 +3919,268 @@ TEST_CASE("deserialization")
...
@@ -3919,6 +3919,268 @@ TEST_CASE("deserialization")
}
}
}
}
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"
)
TEST_CASE
(
"convenience functions"
)
{
{
...
@@ -4202,6 +4464,8 @@ TEST_CASE("parser class")
...
@@ -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
(
"--"
).
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
(
"-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
// unexpected end of null
CHECK_THROWS_AS
(
json
::
parser
(
"n"
).
parse
(),
std
::
invalid_argument
);
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