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
476b2e09
Unverified
Commit
476b2e09
authored
Mar 06, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
💚
added regression tests for #972 and #977
parent
62030615
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
643 additions
and
15 deletions
+643
-15
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+5
-6
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+5
-6
test/CMakeLists.txt
test/CMakeLists.txt
+1
-0
test/Makefile
test/Makefile
+1
-1
test/src/unit-inspection.cpp
test/src/unit-inspection.cpp
+2
-2
test/src/unit-regression.cpp
test/src/unit-regression.cpp
+78
-0
test/thirdparty/fifo_map/LICENSE.MIT
test/thirdparty/fifo_map/LICENSE.MIT
+21
-0
test/thirdparty/fifo_map/fifo_map.hpp
test/thirdparty/fifo_map/fifo_map.hpp
+530
-0
No files found.
include/nlohmann/json.hpp
View file @
476b2e09
...
...
@@ -1247,7 +1247,8 @@ class basic_json
@brief create a JSON value from an existing one
This is a constructor for existing @ref basic_json types.
It does not hijack copy/move constructors, since the parameter has different template arguments than the current ones.
It does not hijack copy/move constructors, since the parameter has different
template arguments than the current ones.
The constructor tries to convert the internal @ref m_value of the parameter.
...
...
@@ -2489,7 +2490,8 @@ class basic_json
/*!
@brief get special-case overload
This overloads converts the current @ref basic_json in a different @ref basic_json type
This overloads converts the current @ref basic_json in a different
@ref basic_json type
@tparam BasicJsonType == @ref basic_json
...
...
@@ -2502,15 +2504,12 @@ class basic_json
*/
template
<
typename
BasicJsonType
,
detail
::
enable_if_t
<
not
std
::
is_same
<
BasicJsonType
,
basic_json
>
::
value
and
detail
::
is_basic_json
<
BasicJsonType
>::
value
,
int
>
=
0
>
detail
::
is_basic_json
<
BasicJsonType
>::
value
,
int
>
=
0
>
BasicJsonType
get
()
const
{
return
*
this
;
}
/*!
@brief get a value (explicit)
...
...
single_include/nlohmann/json.hpp
View file @
476b2e09
...
...
@@ -10845,7 +10845,8 @@ class basic_json
@brief create a JSON value from an existing one
This is a constructor for existing @ref basic_json types.
It does not hijack copy/move constructors, since the parameter has different template arguments than the current ones.
It does not hijack copy/move constructors, since the parameter has different
template arguments than the current ones.
The constructor tries to convert the internal @ref m_value of the parameter.
...
...
@@ -12087,7 +12088,8 @@ class basic_json
/*!
@brief get special-case overload
This overloads converts the current @ref basic_json in a different @ref basic_json type
This overloads converts the current @ref basic_json in a different
@ref basic_json type
@tparam BasicJsonType == @ref basic_json
...
...
@@ -12100,15 +12102,12 @@ class basic_json
*/
template
<
typename
BasicJsonType
,
detail
::
enable_if_t
<
not
std
::
is_same
<
BasicJsonType
,
basic_json
>
::
value
and
detail
::
is_basic_json
<
BasicJsonType
>::
value
,
int
>
=
0
>
detail
::
is_basic_json
<
BasicJsonType
>::
value
,
int
>
=
0
>
BasicJsonType
get
()
const
{
return
*
this
;
}
/*!
@brief get a value (explicit)
...
...
test/CMakeLists.txt
View file @
476b2e09
...
...
@@ -104,6 +104,7 @@ foreach(file ${files})
target_compile_definitions
(
${
testcase
}
PRIVATE CATCH_CONFIG_FAST_COMPILE
)
target_include_directories
(
${
testcase
}
PRIVATE
"thirdparty/catch"
)
target_include_directories
(
${
testcase
}
PRIVATE
"thirdparty/fifo_map"
)
target_include_directories
(
${
testcase
}
PRIVATE
${
NLOHMANN_JSON_INCLUDE_BUILD_DIR
}
)
target_link_libraries
(
${
testcase
}
${
NLOHMANN_JSON_TARGET_NAME
}
)
...
...
test/Makefile
View file @
476b2e09
...
...
@@ -4,7 +4,7 @@
# additional flags
CXXFLAGS
+=
-std
=
c++11
-Wall
-Wextra
-pedantic
-Wcast-align
-Wcast-qual
-Wno-ctor-dtor-privacy
-Wdisabled-optimization
-Wformat
=
2
-Winit-self
-Wmissing-declarations
-Wmissing-include-dirs
-Wold-style-cast
-Woverloaded-virtual
-Wredundant-decls
-Wshadow
-Wsign-conversion
-Wsign-promo
-Wstrict-overflow
=
5
-Wswitch
-Wundef
-Wno-unused
-Wnon-virtual-dtor
-Wreorder
-Wdeprecated
-Wno-float-equal
CPPFLAGS
+=
-I
../single_include
-I
.
-I
thirdparty/catch
-DCATCH_CONFIG_FAST_COMPILE
CPPFLAGS
+=
-I
../single_include
-I
.
-I
thirdparty/catch
-
I
thirdparty/fifo_map
-
DCATCH_CONFIG_FAST_COMPILE
SOURCES
=
src/unit.cpp
\
src/unit-algorithms.cpp
\
...
...
test/src/unit-inspection.cpp
View file @
476b2e09
...
...
@@ -316,8 +316,8 @@ TEST_CASE("object inspection")
SECTION
(
"round trips"
)
{
for
(
const
auto
&
s
:
{
"3.141592653589793"
,
"1000000000000000010E5"
})
{
"3.141592653589793"
,
"1000000000000000010E5"
})
{
json
j1
=
json
::
parse
(
s
);
std
::
string
s1
=
j1
.
dump
();
...
...
test/src/unit-regression.cpp
View file @
476b2e09
...
...
@@ -32,10 +32,72 @@ SOFTWARE.
#include <nlohmann/json.hpp>
using
nlohmann
::
json
;
#include "fifo_map.hpp"
#include <fstream>
#include <list>
#include <cstdio>
/////////////////////////////////////////////////////////////////////
// for #972
/////////////////////////////////////////////////////////////////////
template
<
class
K
,
class
V
,
class
dummy_compare
,
class
A
>
using
my_workaround_fifo_map
=
nlohmann
::
fifo_map
<
K
,
V
,
nlohmann
::
fifo_map_compare
<
K
>
,
A
>
;
using
my_json
=
nlohmann
::
basic_json
<
my_workaround_fifo_map
>
;
/////////////////////////////////////////////////////////////////////
// for #977
/////////////////////////////////////////////////////////////////////
namespace
ns
{
struct
foo
{
int
x
;
};
template
<
typename
,
typename
SFINAE
=
void
>
struct
foo_serializer
;
template
<
typename
T
>
struct
foo_serializer
<
T
,
typename
std
::
enable_if
<
std
::
is_same
<
foo
,
T
>::
value
>::
type
>
{
template
<
typename
BasicJsonType
>
static
void
to_json
(
BasicJsonType
&
j
,
const
T
&
value
)
{
j
=
BasicJsonType
{{
"x"
,
value
.
x
}};
}
template
<
typename
BasicJsonType
>
static
void
from_json
(
const
BasicJsonType
&
j
,
T
&
value
)
// !!!
{
nlohmann
::
from_json
(
j
.
at
(
"x"
),
value
.
x
);
}
};
template
<
typename
T
>
struct
foo_serializer
<
T
,
typename
std
::
enable_if
<
!
std
::
is_same
<
foo
,
T
>::
value
>::
type
>
{
template
<
typename
BasicJsonType
>
static
void
to_json
(
BasicJsonType
&
j
,
const
T
&
value
)
noexcept
{
::
nlohmann
::
to_json
(
j
,
value
);
}
template
<
typename
BasicJsonType
>
static
void
from_json
(
const
BasicJsonType
&
j
,
T
&
value
)
//!!!
{
::
nlohmann
::
from_json
(
j
,
value
);
}
};
}
using
foo_json
=
nlohmann
::
basic_json
<
std
::
map
,
std
::
vector
,
std
::
string
,
bool
,
std
::
int64_t
,
std
::
uint64_t
,
double
,
std
::
allocator
,
ns
::
foo_serializer
>
;
/////////////////////////////////////////////////////////////////////
// for #805
/////////////////////////////////////////////////////////////////////
namespace
{
struct
nocopy
...
...
@@ -1436,4 +1498,20 @@ TEST_CASE("regression tests")
//CHECK_THROWS_WITH(json::from_ubjson(v_ubjson),
// "[json.exception.out_of_range.408] excessive object size: 8658170730974374167");
}
SECTION
(
"issue #972 - Segmentation fault on G++ when trying to assign json string literal to custom json type"
)
{
my_json
foo
=
R"([1, 2, 3])"
_json
;
}
SECTION
(
"issue #977 - Assigning between different json types"
)
{
foo_json
lj
=
ns
::
foo
{
3
};
ns
::
foo
ff
=
lj
;
CHECK
(
lj
.
is_object
());
CHECK
(
lj
.
size
()
==
1
);
CHECK
(
lj
[
"x"
]
==
3
);
CHECK
(
ff
.
x
==
3
);
nlohmann
::
json
nj
=
lj
;
// This line works as expected
}
}
test/thirdparty/fifo_map/LICENSE.MIT
0 → 100644
View file @
476b2e09
MIT License
Copyright (c) 2015-2017 Niels Lohmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
test/thirdparty/fifo_map/fifo_map.hpp
0 → 100644
View file @
476b2e09
This diff is collapsed.
Click to expand it.
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