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
1db573dd
Commit
1db573dd
authored
Sep 03, 2009
by
Jesse Beder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started implementing spec tests
parent
873ad336
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
1 deletions
+107
-1
yaml-reader/spectests.cpp
+91
-0
yaml-reader/spectests.h
+11
-0
yaml-reader/tests.cpp
+5
-1
No files found.
yaml-reader/spectests.cpp
0 → 100644
View file @
1db573dd
#include "spectests.h"
#include "yaml.h"
#include <fstream>
#include <sstream>
#include <vector>
#include <iostream>
namespace
Test
{
namespace
{
void
RunSpecTest
(
bool
(
*
test
)(),
const
std
::
string
&
index
,
const
std
::
string
&
name
,
bool
&
passed
)
{
std
::
string
error
;
bool
ok
=
true
;
try
{
ok
=
test
();
}
catch
(
const
YAML
::
Exception
&
e
)
{
ok
=
false
;
error
=
e
.
msg
;
}
if
(
ok
)
{
std
::
cout
<<
"Spec test "
<<
index
<<
" passed: "
<<
name
<<
"
\n
"
;
}
else
{
passed
=
false
;
std
::
cout
<<
"Spec test "
<<
index
<<
" failed: "
<<
name
<<
"
\n
"
;
if
(
error
!=
""
)
std
::
cout
<<
"Caught exception: "
<<
error
<<
"
\n
"
;
}
}
}
namespace
Spec
{
bool
SeqScalars
()
{
std
::
string
input
=
"- Mark McGwire
\n
"
"- Sammy Sosa
\n
"
"- Ken Griffey"
;
std
::
stringstream
stream
(
input
);
YAML
::
Parser
parser
(
stream
);
YAML
::
Node
doc
;
parser
.
GetNextDocument
(
doc
);
if
(
doc
.
size
()
!=
3
)
return
false
;
std
::
string
output
;
doc
[
0
]
>>
output
;
if
(
output
!=
"Mark McGwire"
)
return
false
;
doc
[
1
]
>>
output
;
if
(
output
!=
"Sammy Sosa"
)
return
false
;
doc
[
2
]
>>
output
;
if
(
output
!=
"Ken Griffey"
)
return
false
;
return
true
;
}
bool
MappingScalarsToScalars
()
{
std
::
string
input
=
"hr: 65 # Home runs
\n
"
"avg: 0.278 # Batting average
\n
"
"rbi: 147 # Runs Batted In"
;
std
::
stringstream
stream
(
input
);
YAML
::
Parser
parser
(
stream
);
YAML
::
Node
doc
;
parser
.
GetNextDocument
(
doc
);
std
::
string
output
;
doc
[
"hr"
]
>>
output
;
if
(
output
!=
"65"
)
return
false
;
doc
[
"avg"
]
>>
output
;
if
(
output
!=
"0.278"
)
return
false
;
doc
[
"rbi"
]
>>
output
;
if
(
output
!=
"147"
)
return
false
;
return
true
;
}
}
bool
RunSpecTests
()
{
bool
passed
=
true
;
RunSpecTest
(
&
Spec
::
SeqScalars
,
"2.1"
,
"Sequence of Scalars"
,
passed
);
RunSpecTest
(
&
Spec
::
MappingScalarsToScalars
,
"2.2"
,
"Mapping Scalars to Scalars"
,
passed
);
return
passed
;
}
}
yaml-reader/spectests.h
0 → 100644
View file @
1db573dd
#pragma once
#ifndef SPECTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SPECTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
namespace
Test
{
bool
RunSpecTests
();
}
#endif // SPECTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
yaml-reader/tests.cpp
View file @
1db573dd
#include "yaml.h"
#include "tests.h"
#include "tests.h"
#include "spectests.h"
#include "yaml.h"
#include <fstream>
#include <fstream>
#include <sstream>
#include <sstream>
#include <vector>
#include <vector>
...
@@ -13,6 +14,9 @@ namespace Test
...
@@ -13,6 +14,9 @@ namespace Test
if
(
!
RunParserTests
())
if
(
!
RunParserTests
())
passed
=
false
;
passed
=
false
;
if
(
!
RunSpecTests
())
passed
=
false
;
if
(
!
RunEmitterTests
())
if
(
!
RunEmitterTests
())
passed
=
false
;
passed
=
false
;
...
...
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