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
a04e2da1
"...composable_kernel.git" did not exist on "0a8087248b09e88cb3799b88cce10fd4c5c9a7da"
Commit
a04e2da1
authored
Oct 19, 2010
by
Jesse Beder
Browse files
Merged the extra tests from other-tags into the trunk (forgot last commit)
parent
51c84f1c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
142 additions
and
1 deletion
+142
-1
test/emittertests.cpp
test/emittertests.cpp
+28
-0
test/parsertests.cpp
test/parsertests.cpp
+114
-1
No files found.
test/emittertests.cpp
View file @
a04e2da1
...
...
@@ -373,6 +373,31 @@ namespace Test
desiredOutput
=
"---
\n
- !<!foo>
\n
[]
\n
- !<!bar>
\n
{}"
;
}
void
ByKindTagWithScalar
(
YAML
::
Emitter
&
out
,
std
::
string
&
desiredOutput
)
{
out
<<
YAML
::
BeginSeq
;
out
<<
YAML
::
DoubleQuoted
<<
"12"
;
out
<<
"12"
;
out
<<
YAML
::
TagByKind
<<
"12"
;
out
<<
YAML
::
EndSeq
;
desiredOutput
=
"---
\n
-
\"
12
\"\n
- 12
\n
- ! 12"
;
}
void
LocalTagWithScalar
(
YAML
::
Emitter
&
out
,
std
::
string
&
desiredOutput
)
{
out
<<
YAML
::
LocalTag
(
"foo"
)
<<
"bar"
;
desiredOutput
=
"--- !foo bar"
;
}
void
BadLocalTag
(
YAML
::
Emitter
&
out
,
std
::
string
&
desiredError
)
{
out
<<
YAML
::
LocalTag
(
"e!far"
)
<<
"bar"
;
desiredError
=
"invalid tag"
;
}
void
ComplexDoc
(
YAML
::
Emitter
&
out
,
std
::
string
&
desiredOutput
)
{
out
<<
YAML
::
BeginMap
;
...
...
@@ -789,6 +814,8 @@ namespace Test
RunEmitterTest
(
&
Emitter
::
VerbatimTagWithEmptySeq
,
"verbatim tag with empty seq"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
VerbatimTagWithEmptyMap
,
"verbatim tag with empty map"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
VerbatimTagWithEmptySeqAndMap
,
"verbatim tag with empty seq and map"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
ByKindTagWithScalar
,
"by-kind tag with scalar"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
LocalTagWithScalar
,
"local tag with scalar"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
ComplexDoc
,
"complex doc"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
STLContainers
,
"STL containers"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
SimpleComment
,
"simple comment"
,
passed
,
total
);
...
...
@@ -815,6 +842,7 @@ namespace Test
RunEmitterErrorTest
(
&
Emitter
::
MissingValue
,
"missing value"
,
passed
,
total
);
RunEmitterErrorTest
(
&
Emitter
::
UnexpectedKey
,
"unexpected key"
,
passed
,
total
);
RunEmitterErrorTest
(
&
Emitter
::
UnexpectedValue
,
"unexpected value"
,
passed
,
total
);
RunEmitterErrorTest
(
&
Emitter
::
BadLocalTag
,
"bad local tag"
,
passed
,
total
);
std
::
cout
<<
"Emitter tests: "
<<
passed
<<
"/"
<<
total
<<
" passed
\n
"
;
return
passed
==
total
;
...
...
test/parsertests.cpp
View file @
a04e2da1
...
...
@@ -706,6 +706,106 @@ namespace Test
return
false
;
return
true
;
}
void
PrepareNodeForTagExam
(
YAML
::
Node
&
doc
,
const
std
::
string
&
input
)
{
std
::
stringstream
stream
(
input
);
YAML
::
Parser
parser
(
stream
);
parser
.
GetNextDocument
(
doc
);
}
struct
TagMismatch
:
public
std
::
exception
{
TagMismatch
(
const
std
::
string
&
actualTag
,
const
std
::
string
&
expectedTag
)
{
std
::
stringstream
output
;
output
<<
"Tag has value
\"
"
<<
actualTag
<<
"
\"
but
\"
"
<<
expectedTag
<<
"
\"
was expected"
;
what_
=
output
.
str
();
}
virtual
~
TagMismatch
()
throw
()
{}
virtual
const
char
*
what
()
const
throw
()
{
return
what_
.
c_str
();
}
private:
std
::
string
what_
;
};
bool
ExpectedTagValue
(
YAML
::
Node
&
node
,
const
char
*
tag
)
{
if
(
node
.
GetTag
()
==
tag
)
return
true
;
throw
TagMismatch
(
node
.
GetTag
(),
tag
);
}
bool
DefaultPlainScalarTag
()
{
YAML
::
Node
node
;
PrepareNodeForTagExam
(
node
,
"--- 12"
);
return
ExpectedTagValue
(
node
,
"?"
);
}
bool
DefaultSingleQuotedScalarTag
()
{
YAML
::
Node
node
;
PrepareNodeForTagExam
(
node
,
"--- '12'"
);
return
ExpectedTagValue
(
node
,
"!"
);
}
bool
ExplicitNonSpecificPlainScalarTag
()
{
YAML
::
Node
node
;
PrepareNodeForTagExam
(
node
,
"--- ! 12"
);
return
ExpectedTagValue
(
node
,
"!"
);
}
bool
BasicLocalTag
()
{
YAML
::
Node
node
;
PrepareNodeForTagExam
(
node
,
"--- !foo 12"
);
return
ExpectedTagValue
(
node
,
"!foo"
);
}
bool
VerbatimLocalTag
()
{
YAML
::
Node
node
;
PrepareNodeForTagExam
(
node
,
"--- !<!foo> 12"
);
return
ExpectedTagValue
(
node
,
"!foo"
);
}
bool
StandardShortcutTag
()
{
YAML
::
Node
node
;
PrepareNodeForTagExam
(
node
,
"--- !!int 12"
);
return
ExpectedTagValue
(
node
,
"tag:yaml.org,2002:int"
);
}
bool
VerbatimURITag
()
{
YAML
::
Node
node
;
PrepareNodeForTagExam
(
node
,
"--- !<tag:yaml.org,2002:int> 12"
);
return
ExpectedTagValue
(
node
,
"tag:yaml.org,2002:int"
);
}
bool
DefaultSequenceTag
()
{
YAML
::
Node
node
;
PrepareNodeForTagExam
(
node
,
"--- [12]"
);
return
ExpectedTagValue
(
node
,
"?"
);
}
bool
ExplicitNonSpecificSequenceTag
()
{
YAML
::
Node
node
;
PrepareNodeForTagExam
(
node
,
"--- ! [12]"
);
return
ExpectedTagValue
(
node
,
"!"
);
}
}
namespace
{
...
...
@@ -746,7 +846,10 @@ namespace Test
ok
=
test
();
}
catch
(
const
YAML
::
Exception
&
e
)
{
ok
=
false
;
error
=
e
.
msg
;
error
=
e
.
what
();
}
catch
(
const
Parser
::
TagMismatch
&
e
)
{
ok
=
false
;
error
=
e
.
what
();
}
if
(
ok
)
{
passed
++
;
...
...
@@ -969,6 +1072,16 @@ namespace Test
RunParserTest
(
&
Parser
::
Bases
,
"bases"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
KeyNotFound
,
"key not found"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
DuplicateKey
,
"duplicate key"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
DefaultPlainScalarTag
,
"default plain scalar tag"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
DefaultSingleQuotedScalarTag
,
"default single-quoted scalar tag"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
ExplicitNonSpecificPlainScalarTag
,
"explicit, non-specific plain scalar tag"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
BasicLocalTag
,
"basic local tag"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
VerbatimLocalTag
,
"verbatim local tag"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
StandardShortcutTag
,
"standard shortcut tag"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
VerbatimURITag
,
"verbatim URI tag"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
DefaultPlainScalarTag
,
"default plain scalar tag"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
DefaultSequenceTag
,
"default sequence tag"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
ExplicitNonSpecificSequenceTag
,
"explicit, non-specific sequence tag"
,
passed
,
total
);
RunEncodingTest
(
&
EncodeToUtf8
,
false
,
"UTF-8, no BOM"
,
passed
,
total
);
RunEncodingTest
(
&
EncodeToUtf8
,
true
,
"UTF-8 with BOM"
,
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