Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yaml-cpp
Overview
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
lvzhengyang
yaml-cpp
Commits
3d2888cc
Commit
3d2888cc
authored
Nov 01, 2024
by
Reini Urban
Committed by
Jesse Beder
Nov 01, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
missing keys should throw InvalidNode, not BadConversion
Fixes GH #1274
parent
c2bec4c7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
2 deletions
+12
-2
include/yaml-cpp/node/impl.h
+4
-2
test/node/node_test.cpp
+8
-0
No files found.
include/yaml-cpp/node/impl.h
View file @
3d2888cc
...
@@ -124,8 +124,8 @@ struct as_if<T, void> {
...
@@ -124,8 +124,8 @@ struct as_if<T, void> {
const
Node
&
node
;
const
Node
&
node
;
T
operator
()()
const
{
T
operator
()()
const
{
if
(
!
node
.
m_pNode
)
if
(
!
node
.
m_pNode
)
// no fallback
throw
TypedBadConversion
<
T
>
(
node
.
Mark
()
);
throw
InvalidNode
(
node
.
m_invalidKey
);
T
t
;
T
t
;
if
(
convert
<
T
>::
decode
(
node
,
t
))
if
(
convert
<
T
>::
decode
(
node
,
t
))
...
@@ -140,6 +140,8 @@ struct as_if<std::string, void> {
...
@@ -140,6 +140,8 @@ struct as_if<std::string, void> {
const
Node
&
node
;
const
Node
&
node
;
std
::
string
operator
()()
const
{
std
::
string
operator
()()
const
{
if
(
node
.
Type
()
==
NodeType
::
Undefined
)
// no fallback
throw
InvalidNode
(
node
.
m_invalidKey
);
if
(
node
.
Type
()
==
NodeType
::
Null
)
if
(
node
.
Type
()
==
NodeType
::
Null
)
return
"null"
;
return
"null"
;
if
(
node
.
Type
()
!=
NodeType
::
Scalar
)
if
(
node
.
Type
()
!=
NodeType
::
Scalar
)
...
...
test/node/node_test.cpp
View file @
3d2888cc
...
@@ -191,6 +191,14 @@ TEST(NodeTest, MapElementRemoval) {
...
@@ -191,6 +191,14 @@ TEST(NodeTest, MapElementRemoval) {
EXPECT_TRUE
(
!
node
[
"foo"
]);
EXPECT_TRUE
(
!
node
[
"foo"
]);
}
}
TEST
(
NodeTest
,
MissingKey
)
{
Node
node
;
node
[
"foo"
]
=
"value"
;
EXPECT_TRUE
(
!
node
[
"bar"
]);
EXPECT_EQ
(
NodeType
::
Undefined
,
node
[
"bar"
].
Type
());
EXPECT_THROW
(
node
[
"bar"
].
as
<
std
::
string
>
(),
InvalidNode
);
}
TEST
(
NodeTest
,
MapIntegerElementRemoval
)
{
TEST
(
NodeTest
,
MapIntegerElementRemoval
)
{
Node
node
;
Node
node
;
node
[
1
]
=
"hello"
;
node
[
1
]
=
"hello"
;
...
...
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