From 973ac4b3bd14247e56747672278578792b0d4ba3 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Sun, 6 Sep 2009 22:17:53 +0000 Subject: [PATCH] Added spec tests through example 2.13 --- yaml-reader/spectests.cpp | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/yaml-reader/spectests.cpp b/yaml-reader/spectests.cpp index 60ee539..e64f653 100644 --- a/yaml-reader/spectests.cpp +++ b/yaml-reader/spectests.cpp @@ -333,6 +333,53 @@ namespace Test { YAML_ASSERT(doc[Pair("New York Yankees", "Atlanta Braves")][2] == "2001-08-14"); return true; } + + TEST CompactNestedMapping() + { + std::string input = + "---\n" + "# Products purchased\n" + "- item : Super Hoop\n" + " quantity: 1\n" + "- item : Basketball\n" + " quantity: 4\n" + "- item : Big Shoes\n" + " quantity: 1"; + std::stringstream stream(input); + YAML::Parser parser(stream); + YAML::Node doc; + parser.GetNextDocument(doc); + + YAML_ASSERT(doc.size() == 3); + YAML_ASSERT(doc[0].size() == 2); + YAML_ASSERT(doc[0]["item"] == "Super Hoop"); + YAML_ASSERT(doc[0]["quantity"] == 1); + YAML_ASSERT(doc[1].size() == 2); + YAML_ASSERT(doc[1]["item"] == "Basketball"); + YAML_ASSERT(doc[1]["quantity"] == 4); + YAML_ASSERT(doc[2].size() == 2); + YAML_ASSERT(doc[2]["item"] == "Big Shoes"); + YAML_ASSERT(doc[2]["quantity"] == 1); + return true; + } + + TEST InLiteralsNewlinesArePreserved() + { + std::string input = + "# ASCII Art\n" + "--- |\n" + " \\//||\\/||\n" + " // || ||__"; + std::stringstream stream(input); + YAML::Parser parser(stream); + YAML::Node doc; + parser.GetNextDocument(doc); + + YAML_ASSERT(doc == + "\\//||\\/||\n" + "// || ||__"); + return true; + } } bool RunSpecTests() @@ -349,6 +396,8 @@ namespace Test { RunSpecTest(&Spec::SingleDocumentWithTwoComments, "2.9", "Single Document with Two Comments", passed); RunSpecTest(&Spec::SimpleAnchor, "2.10", "Node for \"Sammy Sosa\" appears twice in this document", passed); RunSpecTest(&Spec::MappingBetweenSequences, "2.11", "Mapping between Sequences", passed); + RunSpecTest(&Spec::CompactNestedMapping, "2.12", "Compact Nested Mapping", passed); + RunSpecTest(&Spec::InLiteralsNewlinesArePreserved, "2.13", "In literals, newlines are preserved", passed); return passed; }