mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 04:41:16 +00:00
Started Node tests (for the new API Node)
This commit is contained in:
57
test/new-api/nodetests.cpp
Normal file
57
test/new-api/nodetests.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "nodetests.h"
|
||||
#include "yaml-cpp/yaml.h"
|
||||
|
||||
namespace {
|
||||
struct TEST {
|
||||
TEST(): ok(false) {}
|
||||
TEST(bool ok_): ok(ok_) {}
|
||||
TEST(const char *error_): ok(false), error(error_) {}
|
||||
|
||||
bool ok;
|
||||
std::string error;
|
||||
};
|
||||
}
|
||||
|
||||
#define YAML_ASSERT(cond) do { if(!(cond)) return " Assert failed: " #cond; } while(false)
|
||||
|
||||
namespace Test
|
||||
{
|
||||
namespace Node
|
||||
{
|
||||
TEST SimpleScalar()
|
||||
{
|
||||
YAML::Node node = YAML::Node("Hello, World!");
|
||||
YAML_ASSERT(node.Type() == YAML::NodeType::Scalar);
|
||||
YAML_ASSERT(node.as<std::string>() == "Hello, World!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void RunNodeTest(TEST (*test)(), const std::string& name, int& passed, int& total) {
|
||||
TEST ret;
|
||||
try {
|
||||
ret = test();
|
||||
} catch(...) {
|
||||
ret.ok = false;
|
||||
}
|
||||
if(ret.ok) {
|
||||
passed++;
|
||||
} else {
|
||||
std::cout << "Node test failed: " << name << "\n";
|
||||
if(ret.error != "")
|
||||
std::cout << ret.error << "\n";
|
||||
}
|
||||
total++;
|
||||
}
|
||||
|
||||
bool RunNodeTests()
|
||||
{
|
||||
int passed = 0;
|
||||
int total = 0;
|
||||
|
||||
RunNodeTest(&Node::SimpleScalar, "simple scalar", passed, total);
|
||||
|
||||
std::cout << "Node tests: " << passed << "/" << total << " passed\n";
|
||||
return passed == total;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user