yaml-cpp/test/ostream_wrapper_test.cpp
Isabella Muerte 5e9cb0128d Refactor CMake to use more modern paradigms (#741)
Remove 2.6-isms
Remove 2.8-isms
Bump CMake minimum version to 3.4

Disable some options when used as a subdirectory

Use `CONFIGURE_DEPENDS` with `file(GLOB)` when possible

Backport CMake 3.15's MSVC_RUNTIME_LIBRARY setting.
Set all compile options as generator expressions.
Set all find-package files to be installed to the correct file.

Remove `export(PACKAGE)`, as this has been deprecated.
Remove fat binary support
Remove manual setting of iPhone settings. These should be set by parent
projects.
Remove use of ExternalProject for a local use
Conditionally remove format target unless clang-format is found
2019-09-27 09:59:53 -05:00

67 lines
1.7 KiB
C++

#include <sstream>
#include <cstddef>
#include "gtest/gtest.h"
#include "yaml-cpp/ostream_wrapper.h"
namespace {
TEST(OstreamWrapperTest, BufferNoWrite) {
YAML::ostream_wrapper wrapper;
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());
}
}