mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Added a few simple node tests, and the sequence one doesn't pass (let's work now)
This commit is contained in:
@@ -105,14 +105,26 @@ namespace YAML
|
|||||||
// sequence
|
// sequence
|
||||||
void node_data::append(node& node, shared_memory_holder /* pMemory */)
|
void node_data::append(node& node, shared_memory_holder /* pMemory */)
|
||||||
{
|
{
|
||||||
|
if(m_type == NodeType::Undefined || m_type == NodeType::Null) {
|
||||||
|
m_type = NodeType::Sequence;
|
||||||
|
m_sequence.clear();
|
||||||
|
}
|
||||||
|
|
||||||
if(m_type != NodeType::Sequence)
|
if(m_type != NodeType::Sequence)
|
||||||
throw std::runtime_error("Can't append to a non-sequence node");
|
throw std::runtime_error("Can't append to a non-sequence node");
|
||||||
|
|
||||||
m_sequence.push_back(&node);
|
m_sequence.push_back(&node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_data::insert(node& key, node& value, shared_memory_holder /* pMemory */)
|
void node_data::insert(node& key, node& value, shared_memory_holder pMemory)
|
||||||
{
|
{
|
||||||
|
if(m_type == NodeType::Undefined || m_type == NodeType::Null) {
|
||||||
|
m_type = NodeType::Map;
|
||||||
|
m_map.clear();
|
||||||
|
} else if(m_type == NodeType::Sequence) {
|
||||||
|
convert_sequence_to_map(pMemory);
|
||||||
|
}
|
||||||
|
|
||||||
if(m_type != NodeType::Map)
|
if(m_type != NodeType::Map)
|
||||||
throw std::runtime_error("Can't insert into a non-map node");
|
throw std::runtime_error("Can't insert into a non-map node");
|
||||||
|
|
||||||
|
@@ -25,6 +25,28 @@ namespace Test
|
|||||||
YAML_ASSERT(node.as<std::string>() == "Hello, World!");
|
YAML_ASSERT(node.as<std::string>() == "Hello, World!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST IntScalar()
|
||||||
|
{
|
||||||
|
YAML::Node node = YAML::Node(15);
|
||||||
|
YAML_ASSERT(node.Type() == YAML::NodeType::Scalar);
|
||||||
|
YAML_ASSERT(node.as<int>() == 15);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST SimpleSequence()
|
||||||
|
{
|
||||||
|
YAML::Node node;
|
||||||
|
node.append(10);
|
||||||
|
node.append("foo");
|
||||||
|
node.append("monkey");
|
||||||
|
YAML_ASSERT(node.Type() == YAML::NodeType::Sequence);
|
||||||
|
YAML_ASSERT(node.size() == 3);
|
||||||
|
YAML_ASSERT(node[0].as<int>() == 10);
|
||||||
|
YAML_ASSERT(node[1].as<std::string>() == "foo");
|
||||||
|
YAML_ASSERT(node[1].as<std::string>() == "monkey");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunNodeTest(TEST (*test)(), const std::string& name, int& passed, int& total) {
|
void RunNodeTest(TEST (*test)(), const std::string& name, int& passed, int& total) {
|
||||||
@@ -50,6 +72,8 @@ namespace Test
|
|||||||
int total = 0;
|
int total = 0;
|
||||||
|
|
||||||
RunNodeTest(&Node::SimpleScalar, "simple scalar", passed, total);
|
RunNodeTest(&Node::SimpleScalar, "simple scalar", passed, total);
|
||||||
|
RunNodeTest(&Node::IntScalar, "int scalar", passed, total);
|
||||||
|
RunNodeTest(&Node::SimpleSequence, "simple sequence", passed, total);
|
||||||
|
|
||||||
std::cout << "Node tests: " << passed << "/" << total << " passed\n";
|
std::cout << "Node tests: " << passed << "/" << total << " passed\n";
|
||||||
return passed == total;
|
return passed == total;
|
||||||
|
Reference in New Issue
Block a user