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
ec9647ae
Commit
ec9647ae
authored
Nov 04, 2019
by
Anthony VH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved test for #1647 regression to regressions file.
parent
ddda67a0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
25 deletions
+38
-25
test/src/unit-conversions.cpp
test/src/unit-conversions.cpp
+0
-25
test/src/unit-regression.cpp
test/src/unit-regression.cpp
+38
-0
No files found.
test/src/unit-conversions.cpp
View file @
ec9647ae
...
...
@@ -1537,31 +1537,6 @@ NLOHMANN_JSON_SERIALIZE_ENUM(TaskState,
{
TS_COMPLETED
,
"completed"
},
})
namespace
{
// Helper struct to test whether compile error does not trigger upon
// conversion of an enum in the presence of non-member operator== for
// user-defined type with "non default" from_json function (#1647).
struct
NonDefaultFromJsonStruct
{
};
inline
bool
operator
==
(
NonDefaultFromJsonStruct
const
&
lhs
,
NonDefaultFromJsonStruct
const
&
rhs
)
{
return
true
;
}
}
namespace
nlohmann
{
template
<
>
struct
adl_serializer
<
NonDefaultFromJsonStruct
>
{
static
NonDefaultFromJsonStruct
from_json
(
json
const
&
j
)
{
return
{};
}
};
}
TEST_CASE
(
"JSON to enum mapping"
)
{
SECTION
(
"enum class"
)
...
...
test/src/unit-regression.cpp
View file @
ec9647ae
...
...
@@ -159,6 +159,38 @@ bool operator==(Data const& lhs, Data const& rhs)
using
float_json
=
nlohmann
::
basic_json
<
std
::
map
,
std
::
vector
,
std
::
string
,
bool
,
std
::
int64_t
,
std
::
uint64_t
,
float
>
;
/////////////////////////////////////////////////////////////////////
// for #1647
/////////////////////////////////////////////////////////////////////
namespace
{
struct
NonDefaultFromJsonStruct
{
};
inline
bool
operator
==
(
NonDefaultFromJsonStruct
const
&
lhs
,
NonDefaultFromJsonStruct
const
&
rhs
)
{
return
true
;
}
enum
class
for_1647
{
one
,
two
};
NLOHMANN_JSON_SERIALIZE_ENUM
(
for_1647
,
{
{
for_1647
::
one
,
"one"
},
{
for_1647
::
two
,
"two"
},
})
}
namespace
nlohmann
{
template
<
>
struct
adl_serializer
<
NonDefaultFromJsonStruct
>
{
static
NonDefaultFromJsonStruct
from_json
(
json
const
&
j
)
{
return
{};
}
};
}
TEST_CASE
(
"regression tests"
)
{
...
...
@@ -1820,6 +1852,12 @@ TEST_CASE("regression tests")
CHECK
(
j
.
contains
(
jptr1
));
CHECK
(
j
.
contains
(
jptr2
));
}
SECTION
(
"issue #1647 - compile error when deserializing enum if both non-default from_json and non-member operator== exists for other type"
)
{
auto
val
=
nlohmann
::
json
(
"one"
).
get
<
for_1647
>
();
CHECK
(
val
==
for_1647
::
one
);
}
}
#if not defined(JSON_NOEXCEPTION)
...
...
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