mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Add more ostream_wrapper tests
This commit is contained in:
@@ -41,7 +41,7 @@ class ostream_wrapper {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
mutable std::vector<char> m_buffer;
|
mutable std::vector<char> m_buffer;
|
||||||
std::ostream* m_pStream;
|
std::ostream* const m_pStream;
|
||||||
|
|
||||||
std::size_t m_pos;
|
std::size_t m_pos;
|
||||||
std::size_t m_row, m_col;
|
std::size_t m_row, m_col;
|
||||||
|
@@ -1,15 +1,66 @@
|
|||||||
#include "yaml-cpp/ostream_wrapper.h"
|
#include "yaml-cpp/ostream_wrapper.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class OstreamWrapperTest : public ::testing::Test {
|
TEST(OstreamWrapperTest, BufferNoWrite) {
|
||||||
protected:
|
|
||||||
};
|
|
||||||
|
|
||||||
// Tests that the Foo::Bar() method does Abc.
|
|
||||||
TEST_F(OstreamWrapperTest, ConstructNoWrite) {
|
|
||||||
YAML::ostream_wrapper wrapper;
|
YAML::ostream_wrapper wrapper;
|
||||||
EXPECT_STREQ("", wrapper.str());
|
EXPECT_STREQ("", wrapper.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(OstreamWrapperTest, BufferWriteStr) {
|
||||||
|
YAML::ostream_wrapper wrapper;
|
||||||
|
wrapper.write(std::string("Hello, world"));
|
||||||
|
EXPECT_STREQ("Hello, world", wrapper.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(OstreamWrapperTest, BufferWriteCStr) {
|
||||||
|
YAML::ostream_wrapper wrapper;
|
||||||
|
wrapper.write("Hello, world");
|
||||||
|
EXPECT_STREQ("Hello, world", wrapper.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(OstreamWrapperTest, StreamNoWrite) {
|
||||||
|
std::stringstream stream;
|
||||||
|
YAML::ostream_wrapper wrapper(stream);
|
||||||
|
EXPECT_STREQ(NULL, wrapper.str());
|
||||||
|
EXPECT_EQ("", stream.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(OstreamWrapperTest, StreamWriteStr) {
|
||||||
|
std::stringstream stream;
|
||||||
|
YAML::ostream_wrapper wrapper(stream);
|
||||||
|
wrapper.write(std::string("Hello, world"));
|
||||||
|
EXPECT_STREQ(NULL, wrapper.str());
|
||||||
|
EXPECT_EQ("Hello, world", stream.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(OstreamWrapperTest, StreamWriteCStr) {
|
||||||
|
std::stringstream stream;
|
||||||
|
YAML::ostream_wrapper wrapper(stream);
|
||||||
|
wrapper.write("Hello, world");
|
||||||
|
EXPECT_STREQ(NULL, wrapper.str());
|
||||||
|
EXPECT_EQ("Hello, world", stream.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(OstreamWrapperTest, Position) {
|
||||||
|
YAML::ostream_wrapper wrapper;
|
||||||
|
wrapper.write("Hello, world\n");
|
||||||
|
EXPECT_EQ(1, wrapper.row());
|
||||||
|
EXPECT_EQ(0, wrapper.col());
|
||||||
|
EXPECT_EQ(13, wrapper.pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(OstreamWrapperTest, Comment) {
|
||||||
|
YAML::ostream_wrapper wrapper;
|
||||||
|
wrapper.write("Hello, world ");
|
||||||
|
wrapper.set_comment();
|
||||||
|
EXPECT_TRUE(wrapper.comment());
|
||||||
|
wrapper.write("foo");
|
||||||
|
EXPECT_TRUE(wrapper.comment());
|
||||||
|
wrapper.write("\n");
|
||||||
|
EXPECT_FALSE(wrapper.comment());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user