From bd9103f44a93eb1a2ec38ed276746a3dd0ec697f Mon Sep 17 00:00:00 2001 From: beder Date: Tue, 8 May 2012 12:23:37 -0500 Subject: [PATCH] Added node iterator tests --- test/new-api/nodetests.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/new-api/nodetests.cpp b/test/new-api/nodetests.cpp index 0826174..4a219a0 100644 --- a/test/new-api/nodetests.cpp +++ b/test/new-api/nodetests.cpp @@ -326,6 +326,27 @@ namespace Test return true; } + TEST IterateSequence() + { + YAML::Node node = YAML::Load("[1, 3, 5, 7]"); + int seq[] = {1, 3, 5, 7}; + int i=0; + for(YAML::const_iterator it=node.begin();it!=node.end();++it) { + int x = seq[i++]; + YAML_ASSERT(it->as() == x); + } + return true; + } + + TEST IterateMap() + { + YAML::Node node = YAML::Load("{a: A, b: B, c: C}"); + for(YAML::const_iterator it=node.begin();it!=node.end();++it) { + YAML_ASSERT(it->first.as() + 'A' - 'a' == it->second.as()); + } + return true; + } + TEST ForEach() { YAML::Node node = YAML::Load("[1, 3, 5, 7]"); @@ -386,6 +407,8 @@ namespace Test RunNodeTest(&Node::FallbackValues, "fallback values", passed, total); RunNodeTest(&Node::NumericConversion, "numeric conversion", passed, total); RunNodeTest(&Node::Binary, "binary", passed, total); + RunNodeTest(&Node::IterateSequence, "iterate sequence", passed, total); + RunNodeTest(&Node::IterateMap, "iterate map", passed, total); RunNodeTest(&Node::ForEach, "for each", passed, total); std::cout << "Node tests: " << passed << "/" << total << " passed\n";