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
4361c4d0
Commit
4361c4d0
authored
Feb 12, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more test cases
parent
583d20a3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
4 deletions
+63
-4
src/json.hpp
src/json.hpp
+9
-2
src/json.hpp.re2c
src/json.hpp.re2c
+9
-2
test/unit.cpp
test/unit.cpp
+45
-0
No files found.
src/json.hpp
View file @
4361c4d0
/*!
@file
@copyright The code is licensed under the MIT License
<http://opensource.org/licenses/MIT>,
Copyright (c) 2013-2015 Niels Lohmann.
@author Niels Lohmann <http://nlohmann.me>
@see https://github.com/nlohmann/json
*/
#ifndef _NLOHMANN_JSON
#define _NLOHMANN_JSON
...
...
@@ -1026,14 +1035,12 @@ class basic_json
m_value
.
object
->
insert
(
value
);
}
/*
/// add an object to an object
inline
reference
operator
+=
(
const
typename
object_t
::
value_type
&
value
)
{
push_back
(
value
);
return
operator
[](
value
.
first
);
}
*/
/// swaps the contents
inline
void
swap
(
reference
other
)
noexcept
...
...
src/json.hpp.re2c
View file @
4361c4d0
/*!
@file
@copyright The code is licensed under the MIT License
<http://opensource.org/licenses/MIT>,
Copyright (c) 2013-2015 Niels Lohmann.
@author Niels Lohmann <http://nlohmann.me>
@see https://github.com/nlohmann/json
*/
#ifndef _NLOHMANN_JSON
#define _NLOHMANN_JSON
...
...
@@ -1026,14 +1035,12 @@ class basic_json
m_value.object->insert(value);
}
/*
/// add an object to an object
inline reference operator+=(const typename object_t::value_type& value)
{
push_back(value);
return operator[](value.first);
}
*/
/// swaps the contents
inline void swap(reference other) noexcept
...
...
test/unit.cpp
View file @
4361c4d0
/*!
@file
@copyright The code is licensed under the MIT License
<http://opensource.org/licenses/MIT>,
Copyright (c) 2013-2015 Niels Lohmann.
@author Niels Lohmann <http://nlohmann.me>
@see https://github.com/nlohmann/json
*/
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
...
...
@@ -3553,6 +3562,16 @@ TEST_CASE("modifiers")
}
}
}
SECTION
(
"to object"
)
{
json
j
(
json
::
value_t
::
object
);
j
.
push_back
(
json
::
object_t
::
value_type
({
"one"
,
1
}));
j
.
push_back
(
json
::
object_t
::
value_type
({
"two"
,
2
}));
CHECK
(
j
.
size
()
==
2
);
CHECK
(
j
[
"one"
]
==
json
(
1
));
CHECK
(
j
[
"two"
]
==
json
(
2
));
}
}
SECTION
(
"operator+="
)
...
...
@@ -3614,6 +3633,16 @@ TEST_CASE("modifiers")
}
}
}
SECTION
(
"to object"
)
{
json
j
(
json
::
value_t
::
object
);
j
+=
json
::
object_t
::
value_type
({
"one"
,
1
});
j
+=
json
::
object_t
::
value_type
({
"two"
,
2
});
CHECK
(
j
.
size
()
==
2
);
CHECK
(
j
[
"one"
]
==
json
(
1
));
CHECK
(
j
[
"two"
]
==
json
(
2
));
}
}
SECTION
(
"swap()"
)
...
...
@@ -5073,11 +5102,23 @@ TEST_CASE("parser class")
CHECK
(
json
::
parser
(
"0.999"
).
parse
()
==
json
(
0.999
));
CHECK
(
json
::
parser
(
"128.5"
).
parse
()
==
json
(
128.5
));
}
SECTION
(
"with exponent"
)
{
CHECK
(
json
::
parser
(
"-128.5E3"
).
parse
()
==
json
(
-
128.5E3
));
CHECK
(
json
::
parser
(
"-128.5E-3"
).
parse
()
==
json
(
-
128.5E-3
));
}
}
SECTION
(
"invalid numbers"
)
{
CHECK_THROWS_AS
(
json
::
parser
(
"01"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"--1"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"1."
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"1E"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"1E-"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"1.E1"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"-1E"
).
parse
(),
std
::
invalid_argument
);
}
}
}
...
...
@@ -5119,8 +5160,11 @@ TEST_CASE("parser class")
CHECK_THROWS_AS
(
json
::
parser
(
"fals"
).
parse
(),
std
::
invalid_argument
);
// unexpected end of array
CHECK_THROWS_AS
(
json
::
parser
(
"["
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"[1"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"[1,"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"[1,]"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"]"
).
parse
(),
std
::
invalid_argument
);
// unexpected end of object
CHECK_THROWS_AS
(
json
::
parser
(
"{"
).
parse
(),
std
::
invalid_argument
);
...
...
@@ -5128,6 +5172,7 @@ TEST_CASE("parser class")
CHECK_THROWS_AS
(
json
::
parser
(
"{
\"
foo
\"
:"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"{
\"
foo
\"
:}"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"{
\"
foo
\"
:1,}"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"}"
).
parse
(),
std
::
invalid_argument
);
// unexpected end of string
CHECK_THROWS_AS
(
json
::
parser
(
"
\"
"
).
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