From b1100d7c5400cbe848f9a85219f6917c949c1560 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Tue, 13 Sep 2011 01:46:42 -0500 Subject: [PATCH] Copied over the 7.x tests that don't have tags --- test/new-api/spectests.cpp | 221 +++++++++++++++++++++++++++++++++---- 1 file changed, 199 insertions(+), 22 deletions(-) diff --git a/test/new-api/spectests.cpp b/test/new-api/spectests.cpp index 8912c4c..689f1ee 100644 --- a/test/new-api/spectests.cpp +++ b/test/new-api/spectests.cpp @@ -540,73 +540,250 @@ namespace Test } // 7.1 - TEST AliasNodes() { return " not written yet"; } + TEST AliasNodes() { + YAML::Node doc = YAML::Parse(ex7_1); + YAML_ASSERT(doc.size() == 4); + YAML_ASSERT(doc["First occurrence"].as() == "Foo"); + YAML_ASSERT(doc["Second occurrence"].as() == "Foo"); + YAML_ASSERT(doc["Override anchor"].as() == "Bar"); + YAML_ASSERT(doc["Reuse anchor"].as() == "Bar"); + return true; + } // 7.2 TEST EmptyNodes() { return " not written yet"; } // 7.3 - TEST CompletelyEmptyNodes() { return " not written yet"; } + TEST CompletelyEmptyNodes() { + YAML::Node doc = YAML::Parse(ex7_3); + YAML_ASSERT(doc.size() == 2); + YAML_ASSERT(doc["foo"].Type() == YAML::NodeType::Null); +// YAML_ASSERT(doc[YAML::Null].as() == "bar"); + return " null as a key not implemented"; + return true; + } // 7.4 - TEST DoubleQuotedImplicitKeys() { return " not written yet"; } + TEST DoubleQuotedImplicitKeys() { + YAML::Node doc = YAML::Parse(ex7_4); + YAML_ASSERT(doc.size() == 1); + YAML_ASSERT(doc["implicit block key"].size() == 1); + YAML_ASSERT(doc["implicit block key"][0].size() == 1); + YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"].as() == "value"); + return true; + } // 7.5 - TEST DoubleQuotedLineBreaks() { return " not written yet"; } + TEST DoubleQuotedLineBreaks() { + YAML::Node doc = YAML::Parse(ex7_5); + YAML_ASSERT(doc.as() == "folded to a space,\nto a line feed, or \t \tnon-content"); + return true; + } // 7.6 - TEST DoubleQuotedLines() { return " not written yet"; } + TEST DoubleQuotedLines() { + YAML::Node doc = YAML::Parse(ex7_6); + YAML_ASSERT(doc.as() == " 1st non-empty\n2nd non-empty 3rd non-empty "); + return true; + } // 7.7 - TEST SingleQuotedCharacters() { return " not written yet"; } + TEST SingleQuotedCharacters() { + YAML::Node doc = YAML::Parse(ex7_7); + YAML_ASSERT(doc.as() == "here's to \"quotes\""); + return true; + } // 7.8 - TEST SingleQuotedImplicitKeys() { return " not written yet"; } + TEST SingleQuotedImplicitKeys() { + YAML::Node doc = YAML::Parse(ex7_8); + YAML_ASSERT(doc.size() == 1); + YAML_ASSERT(doc["implicit block key"].size() == 1); + YAML_ASSERT(doc["implicit block key"][0].size() == 1); + YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"].as() == "value"); + return true; + } // 7.9 - TEST SingleQuotedLines() { return " not written yet"; } + TEST SingleQuotedLines() { + YAML::Node doc = YAML::Parse(ex7_9); + YAML_ASSERT(doc.as() == " 1st non-empty\n2nd non-empty 3rd non-empty "); + return true; + } // 7.10 - TEST PlainCharacters() { return " not written yet"; } + TEST PlainCharacters() { + YAML::Node doc = YAML::Parse(ex7_10); + YAML_ASSERT(doc.size() == 6); + YAML_ASSERT(doc[0].as() == "::vector"); + YAML_ASSERT(doc[1].as() == ": - ()"); + YAML_ASSERT(doc[2].as() == "Up, up, and away!"); + YAML_ASSERT(doc[3].as() == -123); + YAML_ASSERT(doc[4].as() == "http://example.com/foo#bar"); + YAML_ASSERT(doc[5].size() == 5); + YAML_ASSERT(doc[5][0].as() == "::vector"); + YAML_ASSERT(doc[5][1].as() == ": - ()"); + YAML_ASSERT(doc[5][2].as() == "Up, up, and away!"); + YAML_ASSERT(doc[5][3].as() == -123); + YAML_ASSERT(doc[5][4].as() == "http://example.com/foo#bar"); + return true; + } // 7.11 - TEST PlainImplicitKeys() { return " not written yet"; } + TEST PlainImplicitKeys() { + YAML::Node doc = YAML::Parse(ex7_11); + YAML_ASSERT(doc.size() == 1); + YAML_ASSERT(doc["implicit block key"].size() == 1); + YAML_ASSERT(doc["implicit block key"][0].size() == 1); + YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"].as() == "value"); + return true; + } // 7.12 - TEST PlainLines() { return " not written yet"; } + TEST PlainLines() { + YAML::Node doc = YAML::Parse(ex7_12); + YAML_ASSERT(doc.as() == "1st non-empty\n2nd non-empty 3rd non-empty"); + return true; + } // 7.13 - TEST FlowSequence() { return " not written yet"; } + TEST FlowSequence() { + YAML::Node doc = YAML::Parse(ex7_13); + YAML_ASSERT(doc.size() == 2); + YAML_ASSERT(doc[0].size() == 2); + YAML_ASSERT(doc[0][0].as() == "one"); + YAML_ASSERT(doc[0][1].as() == "two"); + YAML_ASSERT(doc[1].size() == 2); + YAML_ASSERT(doc[1][0].as() == "three"); + YAML_ASSERT(doc[1][1].as() == "four"); + return true; + } // 7.14 - TEST FlowSequenceEntries() { return " not written yet"; } + TEST FlowSequenceEntries() { + YAML::Node doc = YAML::Parse(ex7_14); + YAML_ASSERT(doc.size() == 5); + YAML_ASSERT(doc[0].as() == "double quoted"); + YAML_ASSERT(doc[1].as() == "single quoted"); + YAML_ASSERT(doc[2].as() == "plain text"); + YAML_ASSERT(doc[3].size() == 1); + YAML_ASSERT(doc[3][0].as() == "nested"); + YAML_ASSERT(doc[4].size() == 1); + YAML_ASSERT(doc[4]["single"].as() == "pair"); + return true; + } // 7.15 - TEST FlowMappings() { return " not written yet"; } + TEST FlowMappings() { + YAML::Node doc = YAML::Parse(ex7_15); + YAML_ASSERT(doc.size() == 2); + YAML_ASSERT(doc[0].size() == 2); + YAML_ASSERT(doc[0]["one"].as() == "two"); + YAML_ASSERT(doc[0]["three"].as() == "four"); + YAML_ASSERT(doc[1].size() == 2); + YAML_ASSERT(doc[1]["five"].as() == "six"); + YAML_ASSERT(doc[1]["seven"].as() == "eight"); + return true; + } // 7.16 - TEST FlowMappingEntries() { return " not written yet"; } + TEST FlowMappingEntries() { + YAML::Node doc = YAML::Parse(ex7_16); + YAML_ASSERT(doc.size() == 3); + YAML_ASSERT(doc["explicit"].as() == "entry"); + YAML_ASSERT(doc["implicit"].as() == "entry"); +// YAML_ASSERT(doc[YAML::Null].Type() == YAML::NodeType::Null); + return " null as a key not implemented"; + return true; + } // 7.17 - TEST FlowMappingSeparateValues() { return " not written yet"; } + TEST FlowMappingSeparateValues() { + YAML::Node doc = YAML::Parse(ex7_17); + YAML_ASSERT(doc.size() == 4); + YAML_ASSERT(doc["unquoted"].as() == "separate"); + YAML_ASSERT(doc["http://foo.com"].Type() == YAML::NodeType::Null); + YAML_ASSERT(doc["omitted value"].Type() == YAML::NodeType::Null); +// YAML_ASSERT(doc[YAML::Null].as() == "omitted key"); + return " null as a key not implemented"; + return true; + } // 7.18 - TEST FlowMappingAdjacentValues() { return " not written yet"; } + TEST FlowMappingAdjacentValues() { + YAML::Node doc = YAML::Parse(ex7_18); + YAML_ASSERT(doc.size() == 3); + YAML_ASSERT(doc["adjacent"].as() == "value"); + YAML_ASSERT(doc["readable"].as() == "value"); + YAML_ASSERT(doc["empty"].Type() == YAML::NodeType::Null); + return true; + } // 7.19 - TEST SinglePairFlowMappings() { return " not written yet"; } + TEST SinglePairFlowMappings() { + YAML::Node doc = YAML::Parse(ex7_19); + YAML_ASSERT(doc.size() == 1); + YAML_ASSERT(doc[0].size() == 1); + YAML_ASSERT(doc[0]["foo"].as() == "bar"); + return true; + } // 7.20 - TEST SinglePairExplicitEntry() { return " not written yet"; } + TEST SinglePairExplicitEntry() { + YAML::Node doc = YAML::Parse(ex7_20); + YAML_ASSERT(doc.size() == 1); + YAML_ASSERT(doc[0].size() == 1); + YAML_ASSERT(doc[0]["foo bar"].as() == "baz"); + return true; + } // 7.21 - TEST SinglePairImplicitEntries() { return " not written yet"; } + TEST SinglePairImplicitEntries() { + YAML::Node doc = YAML::Parse(ex7_21); + YAML_ASSERT(doc.size() == 3); + YAML_ASSERT(doc[0].size() == 1); + YAML_ASSERT(doc[0][0].size() == 1); + YAML_ASSERT(doc[0][0]["YAML"].as() == "separate"); + YAML_ASSERT(doc[1].size() == 1); + YAML_ASSERT(doc[1][0].size() == 1); +// YAML_ASSERT(doc[1][0][YAML::Null].as() == "empty key entry"); + return " null as a key not implemented"; + YAML_ASSERT(doc[2].size() == 1); + YAML_ASSERT(doc[2][0].size() == 1); + + std::map key; + key["JSON"] = "like"; + YAML_ASSERT(doc[2][0][key].as() == "adjacent"); + return true; + } // 7.22 - TEST InvalidImplicitKeys() { return " not written yet"; } + TEST InvalidImplicitKeys() { + try { + YAML::Parse(ex7_22); + } catch(const YAML::Exception& e) { + if(e.msg == YAML::ErrorMsg::END_OF_SEQ_FLOW) + return true; + + throw; + } + return " no exception thrown"; + } // 7.23 - TEST FlowContent() { return " not written yet"; } + TEST FlowContent() { + YAML::Node doc = YAML::Parse(ex7_23); + YAML_ASSERT(doc.size() == 5); + YAML_ASSERT(doc[0].size() == 2); + YAML_ASSERT(doc[0][0].as() == "a"); + YAML_ASSERT(doc[0][1].as() == "b"); + YAML_ASSERT(doc[1].size() == 1); + YAML_ASSERT(doc[1]["a"].as() == "b"); + YAML_ASSERT(doc[2].as() == "a"); + YAML_ASSERT(doc[3].as() == 'b'); + YAML_ASSERT(doc[4].as() == "c"); + return true; + } // 7.24 TEST FlowNodes() { return " not written yet"; }