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
f9464734
Commit
f9464734
authored
Mar 23, 2014
by
Jesse Beder
Browse files
Merge from core
parents
05834520
90d7562b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
106 deletions
+89
-106
test/core/parsertests.cpp
test/core/parsertests.cpp
+0
-83
test/integration/handler_test.cpp
test/integration/handler_test.cpp
+89
-0
test/new-api/parsertests.cpp
test/new-api/parsertests.cpp
+0
-5
test/parsertests.h
test/parsertests.h
+0
-14
test/tests.cpp
test/tests.cpp
+0
-4
No files found.
test/core/parsertests.cpp
deleted
100644 → 0
View file @
05834520
#include <iostream>
#include "handlermacros.h"
#include "parsertests.h" // IWYU pragma: keep
#include "teststruct.h"
#include "yaml-cpp/parser.h"
namespace
YAML
{
class
Exception
;
class
ParserException
;
}
// namespace YAML
namespace
Test
{
namespace
Parser
{
TEST
NoEndOfMapFlow
()
{
try
{
HANDLE
(
"---{header: {id: 1"
);
}
catch
(
const
YAML
::
ParserException
&
e
)
{
YAML_ASSERT
(
e
.
msg
==
std
::
string
(
YAML
::
ErrorMsg
::
END_OF_MAP_FLOW
));
return
true
;
}
return
" no exception caught"
;
}
TEST
PlainScalarStartingWithQuestionMark
()
{
HANDLE
(
"foo: ?bar"
);
EXPECT_DOC_START
();
EXPECT_MAP_START
(
"?"
,
0
);
EXPECT_SCALAR
(
"?"
,
0
,
"foo"
);
EXPECT_SCALAR
(
"?"
,
0
,
"?bar"
);
EXPECT_MAP_END
();
EXPECT_DOC_END
();
DONE
();
}
TEST
NullStringScalar
()
{
HANDLE
(
"foo: null"
);
EXPECT_DOC_START
();
EXPECT_MAP_START
(
"?"
,
0
);
EXPECT_SCALAR
(
"?"
,
0
,
"foo"
);
EXPECT_NULL
(
0
);
EXPECT_MAP_END
();
EXPECT_DOC_END
();
DONE
();
}
}
namespace
{
void
RunParserTest
(
TEST
(
*
test
)(),
const
std
::
string
&
name
,
int
&
passed
,
int
&
total
)
{
TEST
ret
;
try
{
ret
=
test
();
}
catch
(
const
YAML
::
Exception
&
e
)
{
ret
.
ok
=
false
;
ret
.
error
=
std
::
string
(
" Exception caught: "
)
+
e
.
what
();
}
if
(
!
ret
.
ok
)
{
std
::
cout
<<
"Parser test failed: "
<<
name
<<
"
\n
"
;
std
::
cout
<<
ret
.
error
<<
"
\n
"
;
}
if
(
ret
.
ok
)
passed
++
;
total
++
;
}
}
bool
RunParserTests
()
{
int
passed
=
0
;
int
total
=
0
;
RunParserTest
(
&
Parser
::
NoEndOfMapFlow
,
"No end of map flow"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
PlainScalarStartingWithQuestionMark
,
"Plain scalar starting with question mark"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
NullStringScalar
,
"Null string scalar"
,
passed
,
total
);
std
::
cout
<<
"Parser tests: "
<<
passed
<<
"/"
<<
total
<<
" passed
\n
"
;
return
passed
==
total
;
}
}
test/integration/handler_test.cpp
0 → 100644
View file @
f9464734
#include "specexamples.h" // IWYU pragma: keep
#include "yaml-cpp/eventhandler.h"
#include "yaml-cpp/yaml.h" // IWYU pragma: keep
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using
::
testing
::
_
;
using
::
testing
::
InSequence
;
using
::
testing
::
NiceMock
;
using
::
testing
::
StrictMock
;
#define EXPECT_THROW_PARSER_EXCEPTION(statement, message) \
ASSERT_THROW(statement, ParserException); \
try { \
statement; \
} \
catch (const ParserException& e) { \
EXPECT_EQ(e.msg, message); \
}
namespace
YAML
{
namespace
{
class
MockEventHandler
:
public
EventHandler
{
public:
MOCK_METHOD1
(
OnDocumentStart
,
void
(
const
Mark
&
));
MOCK_METHOD0
(
OnDocumentEnd
,
void
());
MOCK_METHOD2
(
OnNull
,
void
(
const
Mark
&
,
anchor_t
));
MOCK_METHOD2
(
OnAlias
,
void
(
const
Mark
&
,
anchor_t
));
MOCK_METHOD4
(
OnScalar
,
void
(
const
Mark
&
,
const
std
::
string
&
,
anchor_t
,
const
std
::
string
&
));
MOCK_METHOD3
(
OnSequenceStart
,
void
(
const
Mark
&
,
const
std
::
string
&
,
anchor_t
));
MOCK_METHOD0
(
OnSequenceEnd
,
void
());
MOCK_METHOD3
(
OnMapStart
,
void
(
const
Mark
&
,
const
std
::
string
&
,
anchor_t
));
MOCK_METHOD0
(
OnMapEnd
,
void
());
};
class
HandlerTest
:
public
::
testing
::
Test
{
protected:
void
Parse
(
const
std
::
string
&
example
)
{
std
::
stringstream
stream
(
example
);
Parser
parser
(
stream
);
while
(
parser
.
HandleNextDocument
(
handler
))
{
}
}
void
IgnoreParse
(
const
std
::
string
&
example
)
{
std
::
stringstream
stream
(
example
);
Parser
parser
(
stream
);
while
(
parser
.
HandleNextDocument
(
nice_handler
))
{
}
}
InSequence
sequence
;
StrictMock
<
MockEventHandler
>
handler
;
NiceMock
<
MockEventHandler
>
nice_handler
;
};
TEST_F
(
HandlerTest
,
NoEndOfMapFlow
)
{
EXPECT_THROW_PARSER_EXCEPTION
(
IgnoreParse
(
"---{header: {id: 1"
),
ErrorMsg
::
END_OF_MAP_FLOW
);
}
TEST_F
(
HandlerTest
,
PlainScalarStartingWithQuestionMark
)
{
EXPECT_CALL
(
handler
,
OnDocumentStart
(
_
));
EXPECT_CALL
(
handler
,
OnMapStart
(
_
,
"?"
,
0
));
EXPECT_CALL
(
handler
,
OnScalar
(
_
,
"?"
,
0
,
"foo"
));
EXPECT_CALL
(
handler
,
OnScalar
(
_
,
"?"
,
0
,
"?bar"
));
EXPECT_CALL
(
handler
,
OnMapEnd
());
EXPECT_CALL
(
handler
,
OnDocumentEnd
());
Parse
(
"foo: ?bar"
);
}
TEST_F
(
HandlerTest
,
NullStringScalar
)
{
EXPECT_CALL
(
handler
,
OnDocumentStart
(
_
));
EXPECT_CALL
(
handler
,
OnMapStart
(
_
,
"?"
,
0
));
EXPECT_CALL
(
handler
,
OnScalar
(
_
,
"?"
,
0
,
"foo"
));
EXPECT_CALL
(
handler
,
OnNull
(
_
,
0
));
EXPECT_CALL
(
handler
,
OnMapEnd
());
EXPECT_CALL
(
handler
,
OnDocumentEnd
());
Parse
(
"foo: null"
);
}
}
}
test/new-api/parsertests.cpp
deleted
100644 → 0
View file @
05834520
#include "parsertests.h"
namespace
Test
{
bool
RunParserTests
()
{
return
true
;
}
}
test/parsertests.h
deleted
100644 → 0
View file @
05834520
#ifndef PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
namespace
Test
{
bool
RunParserTests
();
}
#endif // PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
test/tests.cpp
View file @
f9464734
...
...
@@ -5,15 +5,11 @@
#include "emittertests.h"
#include "nodetests.h"
#include "parsertests.h"
#include "tests.h"
namespace
Test
{
void
RunAll
()
{
bool
passed
=
true
;
if
(
!
RunParserTests
())
passed
=
false
;
if
(
!
RunEmitterTests
())
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