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
33316d53
Unverified
Commit
33316d53
authored
May 31, 2020
by
Chen
Committed by
GitHub
May 31, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for some interfaces of emitter (#875)
parent
6701275f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
141 additions
and
0 deletions
+141
-0
test/integration/emitter_test.cpp
+141
-0
No files found.
test/integration/emitter_test.cpp
View file @
33316d53
...
@@ -52,6 +52,63 @@ TEST_F(EmitterTest, SimpleQuotedScalar) {
...
@@ -52,6 +52,63 @@ TEST_F(EmitterTest, SimpleQuotedScalar) {
ExpectEmit
(
"test"
);
ExpectEmit
(
"test"
);
}
}
TEST_F
(
EmitterTest
,
DumpAndSize
)
{
Node
n
(
Load
(
"test"
));
EXPECT_EQ
(
"test"
,
Dump
(
n
));
out
<<
n
;
EXPECT_EQ
(
4
,
out
.
size
());
}
TEST_F
(
EmitterTest
,
NullScalar
)
{
Node
n
(
Load
(
"null"
));
out
<<
n
;
ExpectEmit
(
"~"
);
}
TEST_F
(
EmitterTest
,
AliasScalar
)
{
Node
n
(
Load
(
"[&a str, *a]"
));
out
<<
n
;
ExpectEmit
(
"[&1 str, *1]"
);
}
TEST_F
(
EmitterTest
,
StringFormat
)
{
out
<<
BeginSeq
;
out
.
SetStringFormat
(
SingleQuoted
);
out
<<
"string"
;
out
.
SetStringFormat
(
DoubleQuoted
);
out
<<
"string"
;
out
.
SetStringFormat
(
Literal
);
out
<<
"string"
;
out
<<
EndSeq
;
ExpectEmit
(
"- 'string'
\n
-
\"
string
\"\n
- |
\n
string"
);
}
TEST_F
(
EmitterTest
,
IntBase
)
{
out
<<
BeginSeq
;
out
.
SetIntBase
(
Dec
);
out
<<
1024
;
out
.
SetIntBase
(
Hex
);
out
<<
1024
;
out
.
SetIntBase
(
Oct
);
out
<<
1024
;
out
<<
EndSeq
;
ExpectEmit
(
"- 1024
\n
- 0x400
\n
- 02000"
);
}
TEST_F
(
EmitterTest
,
NumberPrecision
)
{
out
.
SetFloatPrecision
(
3
);
out
.
SetDoublePrecision
(
2
);
out
<<
BeginSeq
;
out
<<
3.1425926
f
;
out
<<
53.5893
;
out
<<
2384626.4338
;
out
<<
EndSeq
;
ExpectEmit
(
"- 3.14
\n
- 54
\n
- 2.4e+06"
);
}
TEST_F
(
EmitterTest
,
SimpleSeq
)
{
TEST_F
(
EmitterTest
,
SimpleSeq
)
{
out
<<
BeginSeq
;
out
<<
BeginSeq
;
out
<<
"eggs"
;
out
<<
"eggs"
;
...
@@ -429,6 +486,12 @@ TEST_F(EmitterTest, ByKindTagWithScalar) {
...
@@ -429,6 +486,12 @@ TEST_F(EmitterTest, ByKindTagWithScalar) {
ExpectEmit
(
"-
\"
12
\"\n
- 12
\n
- ! 12"
);
ExpectEmit
(
"-
\"
12
\"\n
- 12
\n
- ! 12"
);
}
}
TEST_F
(
EmitterTest
,
LocalTagInNameHandle
)
{
out
<<
LocalTag
(
"a"
,
"foo"
)
<<
"bar"
;
ExpectEmit
(
"!a!foo bar"
);
}
TEST_F
(
EmitterTest
,
LocalTagWithScalar
)
{
TEST_F
(
EmitterTest
,
LocalTagWithScalar
)
{
out
<<
LocalTag
(
"foo"
)
<<
"bar"
;
out
<<
LocalTag
(
"foo"
)
<<
"bar"
;
...
@@ -516,6 +579,17 @@ TEST_F(EmitterTest, STLContainers) {
...
@@ -516,6 +579,17 @@ TEST_F(EmitterTest, STLContainers) {
ExpectEmit
(
"- [2, 3, 5, 7, 11, 13]
\n
- Daniel: 26
\n
Jesse: 24"
);
ExpectEmit
(
"- [2, 3, 5, 7, 11, 13]
\n
- Daniel: 26
\n
Jesse: 24"
);
}
}
TEST_F
(
EmitterTest
,
CommentStyle
)
{
out
.
SetPreCommentIndent
(
1
);
out
.
SetPostCommentIndent
(
2
);
out
<<
BeginMap
;
out
<<
Key
<<
"method"
;
out
<<
Value
<<
"least squares"
<<
Comment
(
"should we change this method?"
);
out
<<
EndMap
;
ExpectEmit
(
"method: least squares # should we change this method?"
);
}
TEST_F
(
EmitterTest
,
SimpleComment
)
{
TEST_F
(
EmitterTest
,
SimpleComment
)
{
out
<<
BeginMap
;
out
<<
BeginMap
;
out
<<
Key
<<
"method"
;
out
<<
Key
<<
"method"
;
...
@@ -644,6 +718,17 @@ TEST_F(EmitterTest, Null) {
...
@@ -644,6 +718,17 @@ TEST_F(EmitterTest, Null) {
ExpectEmit
(
"- ~
\n
- null value: ~
\n
~: null key"
);
ExpectEmit
(
"- ~
\n
- null value: ~
\n
~: null key"
);
}
}
TEST_F
(
EmitterTest
,
OutputCharset
)
{
out
<<
BeginSeq
;
out
.
SetOutputCharset
(
EmitNonAscii
);
out
<<
"
\x24
\xC2\xA2
\xE2\x82\xAC
"
;
out
.
SetOutputCharset
(
EscapeNonAscii
);
out
<<
"
\x24
\xC2\xA2
\xE2\x82\xAC
"
;
out
<<
EndSeq
;
ExpectEmit
(
"- $ ¢ €
\n
-
\"
$
\\
xa2
\\
u20ac
\"
"
);
}
TEST_F
(
EmitterTest
,
EscapedUnicode
)
{
TEST_F
(
EmitterTest
,
EscapedUnicode
)
{
out
<<
EscapeNonAscii
<<
"
\x24
\xC2\xA2
\xE2\x82\xAC
\xF0\xA4\xAD\xA2
"
;
out
<<
EscapeNonAscii
<<
"
\x24
\xC2\xA2
\xE2\x82\xAC
\xF0\xA4\xAD\xA2
"
;
...
@@ -660,6 +745,11 @@ TEST_F(EmitterTest, DoubleQuotedUnicode) {
...
@@ -660,6 +745,11 @@ TEST_F(EmitterTest, DoubleQuotedUnicode) {
ExpectEmit
(
"
\"\x24
\xC2\xA2
\xE2\x82\xAC
\xF0\xA4\xAD\xA2\"
"
);
ExpectEmit
(
"
\"\x24
\xC2\xA2
\xE2\x82\xAC
\xF0\xA4\xAD\xA2\"
"
);
}
}
TEST_F
(
EmitterTest
,
DoubleQuotedString
)
{
out
<<
DoubleQuoted
<<
"
\"
\\
\n
\t
\r
\b
\x15
\xEF\xBB\xBF
\x24
"
;
ExpectEmit
(
"
\"\\\"
\\\\
\\
n
\\
t
\\
r
\\
b
\\
x15
\\
ufeff $
\"
"
);
}
struct
Foo
{
struct
Foo
{
Foo
()
:
x
(
0
)
{}
Foo
()
:
x
(
0
)
{}
Foo
(
int
x_
,
const
std
::
string
&
bar_
)
:
x
(
x_
),
bar
(
bar_
)
{}
Foo
(
int
x_
,
const
std
::
string
&
bar_
)
:
x
(
x_
),
bar
(
bar_
)
{}
...
@@ -826,6 +916,57 @@ TEST_F(EmitterTest, ColonAtEndOfScalarInFlow) {
...
@@ -826,6 +916,57 @@ TEST_F(EmitterTest, ColonAtEndOfScalarInFlow) {
ExpectEmit
(
"{
\"
C:
\"
:
\"
C:
\"
}"
);
ExpectEmit
(
"{
\"
C:
\"
:
\"
C:
\"
}"
);
}
}
TEST_F
(
EmitterTest
,
GlobalBoolFormatting
)
{
out
<<
BeginSeq
;
out
.
SetBoolFormat
(
UpperCase
);
out
.
SetBoolFormat
(
YesNoBool
);
out
<<
true
;
out
<<
false
;
out
.
SetBoolFormat
(
TrueFalseBool
);
out
<<
true
;
out
<<
false
;
out
.
SetBoolFormat
(
OnOffBool
);
out
<<
true
;
out
<<
false
;
out
.
SetBoolFormat
(
LowerCase
);
out
.
SetBoolFormat
(
YesNoBool
);
out
<<
true
;
out
<<
false
;
out
.
SetBoolFormat
(
TrueFalseBool
);
out
<<
true
;
out
<<
false
;
out
.
SetBoolFormat
(
OnOffBool
);
out
<<
true
;
out
<<
false
;
out
.
SetBoolFormat
(
CamelCase
);
out
.
SetBoolFormat
(
YesNoBool
);
out
<<
true
;
out
<<
false
;
out
.
SetBoolFormat
(
TrueFalseBool
);
out
<<
true
;
out
<<
false
;
out
.
SetBoolFormat
(
OnOffBool
);
out
<<
true
;
out
<<
false
;
out
.
SetBoolFormat
(
ShortBool
);
out
.
SetBoolFormat
(
UpperCase
);
out
.
SetBoolFormat
(
YesNoBool
);
out
<<
true
;
out
<<
false
;
out
.
SetBoolFormat
(
TrueFalseBool
);
out
<<
true
;
out
<<
false
;
out
.
SetBoolFormat
(
OnOffBool
);
out
<<
true
;
out
<<
false
;
out
<<
EndSeq
;
ExpectEmit
(
"- YES
\n
- NO
\n
- TRUE
\n
- FALSE
\n
- ON
\n
- OFF
\n
"
"- yes
\n
- no
\n
- true
\n
- false
\n
- on
\n
- off
\n
"
"- Yes
\n
- No
\n
- True
\n
- False
\n
- On
\n
- Off
\n
"
"- Y
\n
- N
\n
- Y
\n
- N
\n
- Y
\n
- N"
);
}
TEST_F
(
EmitterTest
,
BoolFormatting
)
{
TEST_F
(
EmitterTest
,
BoolFormatting
)
{
out
<<
BeginSeq
;
out
<<
BeginSeq
;
out
<<
TrueFalseBool
<<
UpperCase
<<
true
;
out
<<
TrueFalseBool
<<
UpperCase
<<
true
;
...
...
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