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
e5999c6c
Commit
e5999c6c
authored
Nov 26, 2016
by
Théo DELRIEU
Committed by
Théo DELRIEU
Jan 21, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a few tests
parent
74bb11d9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
2 deletions
+41
-2
json.hpp
src/json.hpp
+4
-1
unit-udt.cpp
test/src/unit-udt.cpp
+37
-1
No files found.
src/json.hpp
View file @
e5999c6c
...
...
@@ -289,6 +289,8 @@ struct is_compatible_basic_json_type
T
>::
value
;
};
// This trait checks if JSONSerializer<T>::from_json exists
template
<
template
<
typename
,
typename
>
class
JSONSerializer
,
typename
Json
,
typename
T
>
struct
has_from_json
...
...
@@ -305,6 +307,7 @@ public:
detect
(
std
::
declval
<
JSONSerializer
<
T
,
void
>>
()))
>::
value
;
};
// This trait checks if JSONSerializer<T>::to_json exists
template
<
template
<
typename
,
typename
>
class
JSONSerializer
,
typename
Json
,
typename
T
>
struct
has_to_json
...
...
@@ -322,7 +325,7 @@ public:
};
// those declarations are needed to workaround a MSVC bug related to ADL
// (
idea taken from MSVC-Ranges implementation
// (
taken from MSVC-Ranges implementation)
void
to_json
();
void
from_json
();
...
...
test/src/unit-udt.cpp
View file @
e5999c6c
...
...
@@ -397,6 +397,29 @@ struct my_serializer
}
};
// partial specialization on optional_type
template
<
typename
T
>
struct
my_serializer
<
udt
::
optional_type
<
T
>>
{
template
<
typename
Json
>
static
void
from_json
(
Json
const
&
j
,
udt
::
optional_type
<
T
>&
opt
)
{
if
(
j
.
is_null
())
opt
=
nullptr
;
else
opt
=
j
.
get
<
T
>
();
}
template
<
typename
Json
>
static
void
to_json
(
Json
&
j
,
udt
::
optional_type
<
T
>
const
&
opt
)
{
if
(
opt
)
j
=
*
opt
;
else
j
=
nullptr
;
}
};
using
my_json
=
nlohmann
::
basic_json
<
std
::
map
,
std
::
vector
,
std
::
string
,
bool
,
std
::
int64_t
,
std
::
uint64_t
,
double
,
std
::
allocator
,
my_serializer
>
;
...
...
@@ -414,7 +437,7 @@ namespace udt
}
}
TEST_CASE
(
"custom serializer"
)
TEST_CASE
(
"custom serializer"
,
"[udt]"
)
{
SECTION
(
"default use works like default serializer"
)
{
...
...
@@ -429,4 +452,17 @@ TEST_CASE("custom serializer")
CHECK
(
pod2
==
pod3
);
CHECK
(
pod2
==
pod
);
}
SECTION
(
"serializer specialization"
)
{
udt
::
optional_type
<
int
>
opt
;
json
j
{
opt
};
CHECK
(
j
.
is_null
());
opt
=
42
;
j
=
json
{
opt
};
CHECK
(
j
.
get
<
udt
::
optional_type
<
int
>>
()
==
opt
);
CHECK
(
42
==
j
.
get
<
int
>
());
}
}
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