Add EmitterStyle, which will allow sequence or map style (i.e., flow or block) to be preserved between parsing and emitting

This commit is contained in:
Jesse Beder
2015-01-24 12:19:20 -06:00
parent a397ad2925
commit ad712c4f2d
22 changed files with 1451 additions and 1369 deletions

View File

@@ -1,3 +1,4 @@
#include "yaml-cpp/emitterstyle.h"
#include "yaml-cpp/eventhandler.h"
#include "yaml-cpp/yaml.h" // IWYU pragma: keep
#include "gtest/gtest.h"
@@ -14,10 +15,12 @@ class NullEventHandler : public EventHandler {
virtual void OnScalar(const Mark&, const std::string&, anchor_t,
const std::string&) {}
virtual void OnSequenceStart(const Mark&, const std::string&, anchor_t) {}
virtual void OnSequenceStart(const Mark&, const std::string&, anchor_t,
EmitterStyle::value style) {}
virtual void OnSequenceEnd() {}
virtual void OnMapStart(const Mark&, const std::string&, anchor_t) {}
virtual void OnMapStart(const Mark&, const std::string&, anchor_t,
EmitterStyle::value style) {}
virtual void OnMapEnd() {}
};
@@ -775,13 +778,13 @@ TEST_F(EmitterTest, Binary) {
TEST_F(EmitterTest, LongBinary) {
out << Binary(
reinterpret_cast<const unsigned char*>(
"Man is distinguished, not only by his reason, but by this "
"singular passion from other animals, which is a lust of the "
"mind, that by a perseverance of delight in the continued and "
"indefatigable generation of knowledge, exceeds the short "
"vehemence of any carnal pleasure.\n"),
270);
reinterpret_cast<const unsigned char*>(
"Man is distinguished, not only by his reason, but by this "
"singular passion from other animals, which is a lust of the "
"mind, that by a perseverance of delight in the continued and "
"indefatigable generation of knowledge, exceeds the short "
"vehemence of any carnal pleasure.\n"),
270);
ExpectEmit(
"!!binary "
"\"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieS"

View File

@@ -95,7 +95,7 @@ class EncodingTest : public HandlerTest {
void Run() {
InSequence sequence;
EXPECT_CALL(handler, OnDocumentStart(_));
EXPECT_CALL(handler, OnSequenceStart(_, "?", 0));
EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
for (std::size_t i = 0; i < m_entries.size(); i++) {
EXPECT_CALL(handler, OnScalar(_, "!", 0, m_entries[i]));
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -11,8 +11,7 @@ using ::testing::_;
ASSERT_THROW(statement, ParserException); \
try { \
statement; \
} \
catch (const ParserException& e) { \
} catch (const ParserException& e) { \
EXPECT_EQ(e.msg, message); \
}
@@ -26,7 +25,7 @@ TEST_F(HandlerTest, NoEndOfMapFlow) {
TEST_F(HandlerTest, PlainScalarStartingWithQuestionMark) {
EXPECT_CALL(handler, OnDocumentStart(_));
EXPECT_CALL(handler, OnMapStart(_, "?", 0));
EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
EXPECT_CALL(handler, OnScalar(_, "?", 0, "foo"));
EXPECT_CALL(handler, OnScalar(_, "?", 0, "?bar"));
EXPECT_CALL(handler, OnMapEnd());
@@ -36,7 +35,7 @@ TEST_F(HandlerTest, PlainScalarStartingWithQuestionMark) {
TEST_F(HandlerTest, NullStringScalar) {
EXPECT_CALL(handler, OnDocumentStart(_));
EXPECT_CALL(handler, OnMapStart(_, "?", 0));
EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
EXPECT_CALL(handler, OnScalar(_, "?", 0, "foo"));
EXPECT_CALL(handler, OnNull(_, 0));
EXPECT_CALL(handler, OnMapEnd());