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
5b3e30bf
Commit
5b3e30bf
authored
Nov 23, 2019
by
Igor [hyperxor]
Committed by
Jesse Beder
Nov 23, 2019
Browse files
Small readability improvements in Parser
Also add a test for a parser with no data
parent
72f699f5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
13 deletions
+24
-13
src/parser.cpp
src/parser.cpp
+5
-13
test/mock_event_handler.h
test/mock_event_handler.h
+3
-0
test/parser_test.cpp
test/parser_test.cpp
+16
-0
No files found.
src/parser.cpp
View file @
5b3e30bf
...
...
@@ -18,7 +18,7 @@ Parser::Parser(std::istream& in) : Parser() { Load(in); }
Parser
::~
Parser
()
=
default
;
Parser
::
operator
bool
()
const
{
return
m_pScanner
.
get
()
&&
!
m_pScanner
->
empty
();
return
m_pScanner
&&
!
m_pScanner
->
empty
();
}
void
Parser
::
Load
(
std
::
istream
&
in
)
{
...
...
@@ -27,7 +27,7 @@ void Parser::Load(std::istream& in) {
}
bool
Parser
::
HandleNextDocument
(
EventHandler
&
eventHandler
)
{
if
(
!
m_pScanner
.
get
()
)
if
(
!
m_pScanner
)
return
false
;
ParseDirectives
();
...
...
@@ -43,11 +43,7 @@ bool Parser::HandleNextDocument(EventHandler& eventHandler) {
void
Parser
::
ParseDirectives
()
{
bool
readDirective
=
false
;
while
(
1
)
{
if
(
m_pScanner
->
empty
())
{
break
;
}
while
(
!
m_pScanner
->
empty
())
{
Token
&
token
=
m_pScanner
->
peek
();
if
(
token
.
type
!=
Token
::
DIRECTIVE
)
{
break
;
...
...
@@ -113,15 +109,11 @@ void Parser::HandleTagDirective(const Token& token) {
}
void
Parser
::
PrintTokens
(
std
::
ostream
&
out
)
{
if
(
!
m_pScanner
.
get
()
)
{
if
(
!
m_pScanner
)
{
return
;
}
while
(
1
)
{
if
(
m_pScanner
->
empty
())
{
break
;
}
while
(
!
m_pScanner
->
empty
())
{
out
<<
m_pScanner
->
peek
()
<<
"
\n
"
;
m_pScanner
->
pop
();
}
...
...
test/mock_event_handler.h
View file @
5b3e30bf
#include "yaml-cpp/emitterstyle.h"
#include "yaml-cpp/eventhandler.h"
#include "yaml-cpp/mark.h"
#include "gmock/gmock.h"
#include <string>
namespace
YAML
{
class
MockEventHandler
:
public
EventHandler
{
...
...
test/parser_test.cpp
0 → 100644
View file @
5b3e30bf
#include "yaml-cpp/parser.h"
#include "mock_event_handler.h"
#include "gtest/gtest.h"
using
YAML
::
Parser
;
using
YAML
::
MockEventHandler
;
using
::
testing
::
StrictMock
;
TEST
(
ParserTest
,
Empty
)
{
Parser
parser
;
EXPECT_FALSE
(
parser
);
StrictMock
<
MockEventHandler
>
handler
;
EXPECT_FALSE
(
parser
.
HandleNextDocument
(
handler
));
}
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