mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-08 12:21:17 +00:00
Factored out HandlerTest as a base class
This commit is contained in:
32
test/handler_test.h
Normal file
32
test/handler_test.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "mock_event_handler.h"
|
||||
#include "yaml-cpp/yaml.h" // IWYU pragma: keep
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using ::testing::InSequence;
|
||||
using ::testing::NiceMock;
|
||||
using ::testing::StrictMock;
|
||||
|
||||
namespace YAML {
|
||||
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;
|
||||
};
|
||||
}
|
@@ -1,15 +1,11 @@
|
||||
#include "mock_event_handler.h"
|
||||
#include "specexamples.h" // IWYU pragma: keep
|
||||
#include "yaml-cpp/eventhandler.h"
|
||||
#include "handler_test.h"
|
||||
#include "specexamples.h" // IWYU pragma: keep
|
||||
#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); \
|
||||
@@ -23,26 +19,7 @@ using ::testing::StrictMock;
|
||||
namespace YAML {
|
||||
namespace {
|
||||
|
||||
class HandlerSpecTest : 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;
|
||||
};
|
||||
typedef HandlerTest HandlerSpecTest;
|
||||
|
||||
TEST_F(HandlerSpecTest, Ex2_1_SeqScalars) {
|
||||
EXPECT_CALL(handler, OnDocumentStart(_));
|
||||
|
@@ -1,15 +1,11 @@
|
||||
#include "mock_event_handler.h"
|
||||
#include "specexamples.h" // IWYU pragma: keep
|
||||
#include "yaml-cpp/eventhandler.h"
|
||||
#include "handler_test.h"
|
||||
#include "specexamples.h" // IWYU pragma: keep
|
||||
#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); \
|
||||
@@ -23,27 +19,6 @@ using ::testing::StrictMock;
|
||||
namespace YAML {
|
||||
namespace {
|
||||
|
||||
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);
|
||||
|
Reference in New Issue
Block a user