From f6b728d56c30b9bb35a4094381857483fe1e7359 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Tue, 13 Sep 2011 01:28:32 -0500 Subject: [PATCH] Copied over the 5.x tests --- test/new-api/spectests.cpp | 88 +++++++++++++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 10 deletions(-) diff --git a/test/new-api/spectests.cpp b/test/new-api/spectests.cpp index 9fe42ff..55a1ff8 100644 --- a/test/new-api/spectests.cpp +++ b/test/new-api/spectests.cpp @@ -250,37 +250,105 @@ namespace Test // TODO: 5.1 - 5.2 BOM // 5.3 - TEST BlockStructureIndicators() { return " not written yet"; } + TEST BlockStructureIndicators() { + YAML::Node doc = YAML::Parse(ex5_3); + YAML_ASSERT(doc.size() == 2); + YAML_ASSERT(doc["sequence"].size() == 2); + YAML_ASSERT(doc["sequence"][0].as() == "one"); + YAML_ASSERT(doc["sequence"][1].as() == "two"); + YAML_ASSERT(doc["mapping"].size() == 2); + YAML_ASSERT(doc["mapping"]["sky"].as() == "blue"); + YAML_ASSERT(doc["mapping"]["sea"].as() == "green"); + return true; + } // 5.4 - TEST FlowStructureIndicators() { return " not written yet"; } + TEST FlowStructureIndicators() { + YAML::Node doc = YAML::Parse(ex5_4); + YAML_ASSERT(doc.size() == 2); + YAML_ASSERT(doc["sequence"].size() == 2); + YAML_ASSERT(doc["sequence"][0].as() == "one"); + YAML_ASSERT(doc["sequence"][1].as() == "two"); + YAML_ASSERT(doc["mapping"].size() == 2); + YAML_ASSERT(doc["mapping"]["sky"].as() == "blue"); + YAML_ASSERT(doc["mapping"]["sea"].as() == "green"); + return true; + } // 5.5 - TEST CommentIndicator() { return " not written yet"; } + TEST CommentIndicator() { + YAML::Node doc = YAML::Parse(ex5_5); + YAML_ASSERT(doc.Type() == YAML::NodeType::Null); + return true; + } // 5.6 - TEST NodePropertyIndicators() { return " not written yet"; } + TEST NodePropertyIndicators() { + YAML::Node doc = YAML::Parse(ex5_6); + YAML_ASSERT(doc.size() == 2); + YAML_ASSERT(doc["anchored"].as() == "value"); // TODO: assert tag + YAML_ASSERT(doc["alias"].as() == "value"); + return true; + } // 5.7 - TEST BlockScalarIndicators() { return " not written yet"; } + TEST BlockScalarIndicators() { + YAML::Node doc = YAML::Parse(ex5_7); + YAML_ASSERT(doc.size() == 2); + YAML_ASSERT(doc["literal"].as() == "some\ntext\n"); + YAML_ASSERT(doc["folded"].as() == "some text\n"); + return true; + } // 5.8 - TEST QuotedScalarIndicators() { return " not written yet"; } + TEST QuotedScalarIndicators() { + YAML::Node doc = YAML::Parse(ex5_8); + YAML_ASSERT(doc.size() == 2); + YAML_ASSERT(doc["single"].as() == "text"); + YAML_ASSERT(doc["double"].as() == "text"); + return true; + } // TODO: 5.9 directive // TODO: 5.10 reserved indicator // 5.11 - TEST LineBreakCharacters() { return " not written yet"; } + TEST LineBreakCharacters() { + YAML::Node doc = YAML::Parse(ex5_11); + YAML_ASSERT(doc.as() == "Line break (no glyph)\nLine break (glyphed)\n"); + return true; + } // 5.12 - TEST TabsAndSpaces() { return " not written yet"; } + TEST TabsAndSpaces() { + YAML::Node doc = YAML::Parse(ex5_12); + YAML_ASSERT(doc.size() == 2); + YAML_ASSERT(doc["quoted"].as() == "Quoted\t"); + YAML_ASSERT(doc["block"].as() == + "void main() {\n" + "\tprintf(\"Hello, world!\\n\");\n" + "}"); + return true; + } // 5.13 - TEST EscapedCharacters() { return " not written yet"; } + TEST EscapedCharacters() { + YAML::Node doc = YAML::Parse(ex5_13); + YAML_ASSERT(doc.as() == "Fun with \x5C \x22 \x07 \x08 \x1B \x0C \x0A \x0D \x09 \x0B " + std::string("\x00", 1) + " \x20 \xA0 \x85 \xe2\x80\xa8 \xe2\x80\xa9 A A A"); + return true; + } // 5.14 - TEST InvalidEscapedCharacters() { return " not written yet"; } + TEST InvalidEscapedCharacters() { + try { + YAML::Parse(ex5_14); + } catch(const YAML::ParserException& e) { + YAML_ASSERT(e.msg == std::string(YAML::ErrorMsg::INVALID_ESCAPE) + "c"); + return true; + } + + return false; + } // 6.1 TEST IndentationSpaces() { return " not written yet"; }