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
6b7cb45a
"vscode:/vscode.git/clone" did not exist on "70d2000eeea16b864617ea8cd00cb67477e9c412"
Commit
6b7cb45a
authored
Oct 22, 2010
by
Jesse Beder
Browse files
Added more tests for the newline, and disallowed newlines after implicit block keys
parent
1e421040
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
8 deletions
+58
-8
include/yaml-cpp/emitter.h
include/yaml-cpp/emitter.h
+2
-0
src/emitfromevents.cpp
src/emitfromevents.cpp
+1
-1
src/emitter.cpp
src/emitter.cpp
+13
-2
test/emittertests.cpp
test/emittertests.cpp
+38
-0
util/parse.cpp
util/parse.cpp
+4
-5
No files found.
include/yaml-cpp/emitter.h
View file @
6b7cb45a
...
...
@@ -82,6 +82,8 @@ namespace YAML
void
EmitKindTag
();
void
EmitTag
(
bool
verbatim
,
const
_Tag
&
tag
);
bool
CanEmitNewline
()
const
;
private:
ostream
m_stream
;
std
::
auto_ptr
<
EmitterState
>
m_pState
;
...
...
src/emitfromevents.cpp
View file @
6b7cb45a
...
...
@@ -98,7 +98,7 @@ namespace YAML
void
EmitFromEvents
::
EmitProps
(
const
std
::
string
&
tag
,
anchor_t
anchor
)
{
if
(
!
tag
.
empty
())
if
(
!
tag
.
empty
()
&&
tag
!=
"?"
)
m_emitter
<<
VerbatimTag
(
tag
);
if
(
anchor
)
m_emitter
<<
Anchor
(
ToString
(
anchor
));
...
...
src/emitter.cpp
View file @
6b7cb45a
...
...
@@ -513,8 +513,19 @@ namespace YAML
{
if
(
!
good
())
return
;
m_stream
<<
'\n'
;
if
(
CanEmitNewline
())
m_stream
<<
'\n'
;
}
bool
Emitter
::
CanEmitNewline
()
const
{
FLOW_TYPE
flowType
=
m_pState
->
GetCurGroupFlowType
();
if
(
flowType
==
FT_BLOCK
&&
m_pState
->
CurrentlyInLongKey
())
return
true
;
EMITTER_STATE
curState
=
m_pState
->
GetCurState
();
return
curState
!=
ES_DONE_WITH_BLOCK_MAP_KEY
&&
curState
!=
ES_WAITING_FOR_BLOCK_MAP_VALUE
&&
curState
!=
ES_WRITING_BLOCK_MAP_VALUE
;
}
// *******************************************************************************************
...
...
test/emittertests.cpp
View file @
6b7cb45a
...
...
@@ -673,7 +673,42 @@ namespace Test
out
<<
YAML
::
EndSeq
;
desiredOutput
=
"--- [a
\n
, b, c
\n
, d]"
;
}
void
NewlineInBlockMap
(
YAML
::
Emitter
&
out
,
std
::
string
&
desiredOutput
)
{
out
<<
YAML
::
BeginMap
;
out
<<
YAML
::
Key
<<
"a"
<<
YAML
::
Value
<<
"foo"
<<
YAML
::
Newline
;
out
<<
YAML
::
Key
<<
"b"
<<
YAML
::
Newline
<<
YAML
::
Value
<<
"bar"
;
out
<<
YAML
::
LongKey
<<
YAML
::
Key
<<
"c"
<<
YAML
::
Newline
<<
YAML
::
Value
<<
"car"
;
out
<<
YAML
::
EndMap
;
desiredOutput
=
"---
\n
a: foo
\n\n
b: bar
\n
? c
\n\n
: car"
;
}
void
NewlineInFlowMap
(
YAML
::
Emitter
&
out
,
std
::
string
&
desiredOutput
)
{
out
<<
YAML
::
Flow
<<
YAML
::
BeginMap
;
out
<<
YAML
::
Key
<<
"a"
<<
YAML
::
Value
<<
"foo"
<<
YAML
::
Newline
;
out
<<
YAML
::
Key
<<
"b"
<<
YAML
::
Newline
<<
YAML
::
Value
<<
"bar"
;
out
<<
YAML
::
EndMap
;
desiredOutput
=
"--- {a: foo
\n
, b
\n
: bar}"
;
}
void
LotsOfNewlines
(
YAML
::
Emitter
&
out
,
std
::
string
&
desiredOutput
)
{
out
<<
YAML
::
BeginSeq
;
out
<<
"a"
<<
YAML
::
Newline
;
out
<<
YAML
::
BeginSeq
;
out
<<
"b"
<<
"c"
<<
YAML
::
Newline
;
out
<<
YAML
::
EndSeq
;
out
<<
YAML
::
Newline
;
out
<<
YAML
::
BeginMap
;
out
<<
YAML
::
Newline
<<
YAML
::
Key
<<
"d"
<<
YAML
::
Value
<<
YAML
::
Newline
<<
"e"
;
out
<<
YAML
::
LongKey
<<
YAML
::
Key
<<
"f"
<<
YAML
::
Newline
<<
YAML
::
Value
<<
"foo"
;
out
<<
YAML
::
EndMap
;
out
<<
YAML
::
EndSeq
;
desiredOutput
=
"---
\n
- a
\n\n
-
\n
- b
\n
- c
\n\n\n
-
\n\n
d: e
\n
? f
\n\n
: foo"
;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
// incorrect emitting
...
...
@@ -857,6 +892,9 @@ namespace Test
RunEmitterTest
(
&
Emitter
::
NewlineAtEnd
,
"newline at end"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
NewlineInBlockSequence
,
"newline in block sequence"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
NewlineInFlowSequence
,
"newline in flow sequence"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
NewlineInBlockMap
,
"newline in block map"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
NewlineInFlowMap
,
"newline in flow map"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
LotsOfNewlines
,
"lots of newlines"
,
passed
,
total
);
RunEmitterErrorTest
(
&
Emitter
::
ExtraEndSeq
,
"extra EndSeq"
,
passed
,
total
);
RunEmitterErrorTest
(
&
Emitter
::
ExtraEndMap
,
"extra EndMap"
,
passed
,
total
);
...
...
util/parse.cpp
View file @
6b7cb45a
...
...
@@ -47,11 +47,10 @@ int main(int argc, char **argv)
YAML
::
Parser
parser
(
input
);
YAML
::
Node
doc
;
NullEventHandler
handler
;
// while(parser.GetNextDocument(doc)) {
while
(
parser
.
HandleNextDocument
(
handler
))
{
// YAML::Emitter emitter;
// emitter << doc;
// std::cout << emitter.c_str() << "\n";
while
(
parser
.
GetNextDocument
(
doc
))
{
YAML
::
Emitter
emitter
;
emitter
<<
doc
;
std
::
cout
<<
emitter
.
c_str
()
<<
"
\n
"
;
}
}
catch
(
const
YAML
::
Exception
&
e
)
{
std
::
cerr
<<
e
.
what
()
<<
"
\n
"
;
...
...
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