Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
yaml-cpp
Commits
b4963ab0
Commit
b4963ab0
authored
Sep 10, 2011
by
Jesse Beder
Browse files
Added a few simple node tests, and the sequence one doesn't pass (let's work now)
parent
43226891
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletion
+37
-1
src/node/detail/node_data.cpp
src/node/detail/node_data.cpp
+13
-1
test/new-api/nodetests.cpp
test/new-api/nodetests.cpp
+24
-0
No files found.
src/node/detail/node_data.cpp
View file @
b4963ab0
...
@@ -105,14 +105,26 @@ namespace YAML
...
@@ -105,14 +105,26 @@ namespace YAML
// sequence
// sequence
void
node_data
::
append
(
node
&
node
,
shared_memory_holder
/* pMemory */
)
void
node_data
::
append
(
node
&
node
,
shared_memory_holder
/* pMemory */
)
{
{
if
(
m_type
==
NodeType
::
Undefined
||
m_type
==
NodeType
::
Null
)
{
m_type
=
NodeType
::
Sequence
;
m_sequence
.
clear
();
}
if
(
m_type
!=
NodeType
::
Sequence
)
if
(
m_type
!=
NodeType
::
Sequence
)
throw
std
::
runtime_error
(
"Can't append to a non-sequence node"
);
throw
std
::
runtime_error
(
"Can't append to a non-sequence node"
);
m_sequence
.
push_back
(
&
node
);
m_sequence
.
push_back
(
&
node
);
}
}
void
node_data
::
insert
(
node
&
key
,
node
&
value
,
shared_memory_holder
/*
pMemory
*/
)
void
node_data
::
insert
(
node
&
key
,
node
&
value
,
shared_memory_holder
pMemory
)
{
{
if
(
m_type
==
NodeType
::
Undefined
||
m_type
==
NodeType
::
Null
)
{
m_type
=
NodeType
::
Map
;
m_map
.
clear
();
}
else
if
(
m_type
==
NodeType
::
Sequence
)
{
convert_sequence_to_map
(
pMemory
);
}
if
(
m_type
!=
NodeType
::
Map
)
if
(
m_type
!=
NodeType
::
Map
)
throw
std
::
runtime_error
(
"Can't insert into a non-map node"
);
throw
std
::
runtime_error
(
"Can't insert into a non-map node"
);
...
...
test/new-api/nodetests.cpp
View file @
b4963ab0
...
@@ -25,6 +25,28 @@ namespace Test
...
@@ -25,6 +25,28 @@ namespace Test
YAML_ASSERT
(
node
.
as
<
std
::
string
>
()
==
"Hello, World!"
);
YAML_ASSERT
(
node
.
as
<
std
::
string
>
()
==
"Hello, World!"
);
return
true
;
return
true
;
}
}
TEST
IntScalar
()
{
YAML
::
Node
node
=
YAML
::
Node
(
15
);
YAML_ASSERT
(
node
.
Type
()
==
YAML
::
NodeType
::
Scalar
);
YAML_ASSERT
(
node
.
as
<
int
>
()
==
15
);
return
true
;
}
TEST
SimpleSequence
()
{
YAML
::
Node
node
;
node
.
append
(
10
);
node
.
append
(
"foo"
);
node
.
append
(
"monkey"
);
YAML_ASSERT
(
node
.
Type
()
==
YAML
::
NodeType
::
Sequence
);
YAML_ASSERT
(
node
.
size
()
==
3
);
YAML_ASSERT
(
node
[
0
].
as
<
int
>
()
==
10
);
YAML_ASSERT
(
node
[
1
].
as
<
std
::
string
>
()
==
"foo"
);
YAML_ASSERT
(
node
[
1
].
as
<
std
::
string
>
()
==
"monkey"
);
return
true
;
}
}
}
void
RunNodeTest
(
TEST
(
*
test
)(),
const
std
::
string
&
name
,
int
&
passed
,
int
&
total
)
{
void
RunNodeTest
(
TEST
(
*
test
)(),
const
std
::
string
&
name
,
int
&
passed
,
int
&
total
)
{
...
@@ -50,6 +72,8 @@ namespace Test
...
@@ -50,6 +72,8 @@ namespace Test
int
total
=
0
;
int
total
=
0
;
RunNodeTest
(
&
Node
::
SimpleScalar
,
"simple scalar"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
SimpleScalar
,
"simple scalar"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
IntScalar
,
"int scalar"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
SimpleSequence
,
"simple sequence"
,
passed
,
total
);
std
::
cout
<<
"Node tests: "
<<
passed
<<
"/"
<<
total
<<
" passed
\n
"
;
std
::
cout
<<
"Node tests: "
<<
passed
<<
"/"
<<
total
<<
" passed
\n
"
;
return
passed
==
total
;
return
passed
==
total
;
...
...
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