From f6d6c90aa9c019a3cba255f6a5acfb8336331823 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Sat, 17 Sep 2011 23:57:40 -0500 Subject: [PATCH] Updated old api spectests with common spec examples --- test/old-api/spectests.cpp | 1052 ++++-------------------------------- 1 file changed, 109 insertions(+), 943 deletions(-) diff --git a/test/old-api/spectests.cpp b/test/old-api/spectests.cpp index 7fe1321..fb5505b 100644 --- a/test/old-api/spectests.cpp +++ b/test/old-api/spectests.cpp @@ -18,12 +18,7 @@ namespace Test { namespace Spec { // 2.1 TEST SeqScalars() { - std::string input = - "- Mark McGwire\n" - "- Sammy Sosa\n" - "- Ken Griffey"; - - PARSE(doc, input); + PARSE(doc, ex2_1); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc[0].to() == "Mark McGwire"); YAML_ASSERT(doc[1].to() == "Sammy Sosa"); @@ -33,12 +28,7 @@ namespace Test { // 2.2 TEST MappingScalarsToScalars() { - std::string input = - "hr: 65 # Home runs\n" - "avg: 0.278 # Batting average\n" - "rbi: 147 # Runs Batted In"; - - PARSE(doc, input); + PARSE(doc, ex2_2); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc["hr"].to() == "65"); YAML_ASSERT(doc["avg"].to() == "0.278"); @@ -48,17 +38,7 @@ namespace Test { // 2.3 TEST MappingScalarsToSequences() { - std::string input = - "american:\n" - "- Boston Red Sox\n" - "- Detroit Tigers\n" - "- New York Yankees\n" - "national:\n" - "- New York Mets\n" - "- Chicago Cubs\n" - "- Atlanta Braves"; - - PARSE(doc, input); + PARSE(doc, ex2_3); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc["american"].size() == 3); YAML_ASSERT(doc["american"][0].to() == "Boston Red Sox"); @@ -74,17 +54,7 @@ namespace Test { // 2.4 TEST SequenceOfMappings() { - std::string input = - "-\n" - " name: Mark McGwire\n" - " hr: 65\n" - " avg: 0.278\n" - "-\n" - " name: Sammy Sosa\n" - " hr: 63\n" - " avg: 0.288"; - - PARSE(doc, input); + PARSE(doc, ex2_4); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc[0].size() == 3); YAML_ASSERT(doc[0]["name"].to() == "Mark McGwire"); @@ -100,12 +70,7 @@ namespace Test { // 2.5 TEST SequenceOfSequences() { - std::string input = - "- [name , hr, avg ]\n" - "- [Mark McGwire, 65, 0.278]\n" - "- [Sammy Sosa , 63, 0.288]"; - - PARSE(doc, input); + PARSE(doc, ex2_5); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc[0].size() == 3); YAML_ASSERT(doc[0][0].to() == "name"); @@ -125,14 +90,7 @@ namespace Test { // 2.6 TEST MappingOfMappings() { - std::string input = - "Mark McGwire: {hr: 65, avg: 0.278}\n" - "Sammy Sosa: {\n" - " hr: 63,\n" - " avg: 0.288\n" - " }"; - - PARSE(doc, input); + PARSE(doc, ex2_6); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc["Mark McGwire"].size() == 2); YAML_ASSERT(doc["Mark McGwire"]["hr"].to() == "65"); @@ -146,19 +104,7 @@ namespace Test { // 2.7 TEST TwoDocumentsInAStream() { - std::string input = - "# Ranking of 1998 home runs\n" - "---\n" - "- Mark McGwire\n" - "- Sammy Sosa\n" - "- Ken Griffey\n" - "\n" - "# Team ranking\n" - "---\n" - "- Chicago Cubs\n" - "- St Louis Cardinals"; - - PARSE(doc, input); + PARSE(doc, ex2_7); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc[0].to() == "Mark McGwire"); YAML_ASSERT(doc[1].to() == "Sammy Sosa"); @@ -174,19 +120,7 @@ namespace Test { // 2.8 TEST PlayByPlayFeed() { - std::string input = - "---\n" - "time: 20:03:20\n" - "player: Sammy Sosa\n" - "action: strike (miss)\n" - "...\n" - "---\n" - "time: 20:03:47\n" - "player: Sammy Sosa\n" - "action: grand slam\n" - "..."; - - PARSE(doc, input); + PARSE(doc, ex2_8); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc["time"].to() == "20:03:20"); YAML_ASSERT(doc["player"].to() == "Sammy Sosa"); @@ -203,17 +137,7 @@ namespace Test { // 2.9 TEST SingleDocumentWithTwoComments() { - std::string input = - "---\n" - "hr: # 1998 hr ranking\n" - " - Mark McGwire\n" - " - Sammy Sosa\n" - "rbi:\n" - " # 1998 rbi ranking\n" - " - Sammy Sosa\n" - " - Ken Griffey"; - - PARSE(doc, input); + PARSE(doc, ex2_9); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc["hr"].size() == 2); YAML_ASSERT(doc["hr"][0].to() == "Mark McGwire"); @@ -227,17 +151,7 @@ namespace Test { // 2.10 TEST SimpleAnchor() { - std::string input = - "---\n" - "hr:\n" - " - Mark McGwire\n" - " # Following node labeled SS\n" - " - &SS Sammy Sosa\n" - "rbi:\n" - " - *SS # Subsequent occurrence\n" - " - Ken Griffey"; - - PARSE(doc, input); + PARSE(doc, ex2_10); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc["hr"].size() == 2); YAML_ASSERT(doc["hr"][0].to() == "Mark McGwire"); @@ -266,18 +180,7 @@ namespace Test { // 2.11 TEST MappingBetweenSequences() { - std::string input = - "? - Detroit Tigers\n" - " - Chicago cubs\n" - ":\n" - " - 2001-07-23\n" - "\n" - "? [ New York Yankees,\n" - " Atlanta Braves ]\n" - ": [ 2001-07-02, 2001-08-12,\n" - " 2001-08-14 ]"; - - PARSE(doc, input); + PARSE(doc, ex2_11); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc[Pair("Detroit Tigers", "Chicago cubs")].size() == 1); YAML_ASSERT(doc[Pair("Detroit Tigers", "Chicago cubs")][0].to() == "2001-07-23"); @@ -291,17 +194,7 @@ namespace Test { // 2.12 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"; - - PARSE(doc, input); + PARSE(doc, ex2_12); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc[0].size() == 2); YAML_ASSERT(doc[0]["item"].to() == "Super Hoop"); @@ -318,13 +211,7 @@ namespace Test { // 2.13 TEST InLiteralsNewlinesArePreserved() { - std::string input = - "# ASCII Art\n" - "--- |\n" - " \\//||\\/||\n" - " // || ||__"; - - PARSE(doc, input); + PARSE(doc, ex2_13); YAML_ASSERT(doc.to() == "\\//||\\/||\n" "// || ||__"); @@ -334,13 +221,7 @@ namespace Test { // 2.14 TEST InFoldedScalarsNewlinesBecomeSpaces() { - std::string input = - "--- >\n" - " Mark McGwire's\n" - " year was crippled\n" - " by a knee injury."; - - PARSE(doc, input); + PARSE(doc, ex2_14); YAML_ASSERT(doc.to() == "Mark McGwire's year was crippled by a knee injury."); return true; } @@ -348,17 +229,7 @@ namespace Test { // 2.15 TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines() { - std::string input = - ">\n" - " Sammy Sosa completed another\n" - " fine season with great stats.\n" - " \n" - " 63 Home Runs\n" - " 0.288 Batting Average\n" - " \n" - " What a year!"; - - PARSE(doc, input); + PARSE(doc, ex2_15); YAML_ASSERT(doc.to() == "Sammy Sosa completed another fine season with great stats.\n\n" " 63 Home Runs\n" @@ -370,16 +241,7 @@ namespace Test { // 2.16 TEST IndentationDeterminesScope() { - std::string input = - "name: Mark McGwire\n" - "accomplishment: >\n" - " Mark set a major league\n" - " home run record in 1998.\n" - "stats: |\n" - " 65 Home Runs\n" - " 0.278 Batting Average\n"; - - PARSE(doc, input); + PARSE(doc, ex2_16); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc["name"].to() == "Mark McGwire"); YAML_ASSERT(doc["accomplishment"].to() == "Mark set a major league home run record in 1998.\n"); @@ -390,16 +252,7 @@ namespace Test { // 2.17 TEST QuotedScalars() { - std::string input = - "unicode: \"Sosa did fine.\\u263A\"\n" - "control: \"\\b1998\\t1999\\t2000\\n\"\n" - "hex esc: \"\\x0d\\x0a is \\r\\n\"\n" - "\n" - "single: '\"Howdy!\" he cried.'\n" - "quoted: ' # Not a ''comment''.'\n" - "tie-fighter: '|\\-*-/|'"; - - PARSE(doc, input); + PARSE(doc, ex2_17); YAML_ASSERT(doc.size() == 6); YAML_ASSERT(doc["unicode"].to() == "Sosa did fine.\xe2\x98\xba"); YAML_ASSERT(doc["control"].to() == "\b1998\t1999\t2000\n"); @@ -413,15 +266,7 @@ namespace Test { // 2.18 TEST MultiLineFlowScalars() { - std::string input = - "plain:\n" - " This unquoted scalar\n" - " spans many lines.\n" - "\n" - "quoted: \"So does this\n" - " quoted scalar.\\n\""; - - PARSE(doc, input); + PARSE(doc, ex2_18); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc["plain"].to() == "This unquoted scalar spans many lines."); YAML_ASSERT(doc["quoted"].to() == "So does this quoted scalar.\n"); @@ -433,22 +278,7 @@ namespace Test { // 2.23 TEST VariousExplicitTags() { - std::string input = - "---\n" - "not-date: !!str 2002-04-28\n" - "\n" - "picture: !!binary |\n" - " R0lGODlhDAAMAIQAAP//9/X\n" - " 17unp5WZmZgAAAOfn515eXv\n" - " Pz7Y6OjuDg4J+fn5OTk6enp\n" - " 56enmleECcgggoBADs=\n" - "\n" - "application specific tag: !something |\n" - " The semantics of the tag\n" - " above may be different for\n" - " different documents."; - - PARSE(doc, input); + PARSE(doc, ex2_23); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc["not-date"].Tag() == "tag:yaml.org,2002:str"); YAML_ASSERT(doc["not-date"].to() == "2002-04-28"); @@ -471,23 +301,7 @@ namespace Test { // 2.24 TEST GlobalTags() { - std::string input = - "%TAG ! tag:clarkevans.com,2002:\n" - "--- !shape\n" - " # Use the ! handle for presenting\n" - " # tag:clarkevans.com,2002:circle\n" - "- !circle\n" - " center: &ORIGIN {x: 73, y: 129}\n" - " radius: 7\n" - "- !line\n" - " start: *ORIGIN\n" - " finish: { x: 89, y: 102 }\n" - "- !label\n" - " start: *ORIGIN\n" - " color: 0xFFEEBB\n" - " text: Pretty vector drawing."; - - PARSE(doc, input); + PARSE(doc, ex2_24); YAML_ASSERT(doc.Tag() == "tag:clarkevans.com,2002:shape"); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc[0].Tag() == "tag:clarkevans.com,2002:circle"); @@ -517,16 +331,7 @@ namespace Test { // 2.25 TEST UnorderedSets() { - std::string input = - "# Sets are represented as a\n" - "# Mapping where each key is\n" - "# associated with a null value\n" - "--- !!set\n" - "? Mark McGwire\n" - "? Sammy Sosa\n" - "? Ken Griffey"; - - PARSE(doc, input); + PARSE(doc, ex2_25); YAML_ASSERT(doc.Tag() == "tag:yaml.org,2002:set"); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(IsNull(doc["Mark McGwire"])); @@ -538,16 +343,7 @@ namespace Test { // 2.26 TEST OrderedMappings() { - std::string input = - "# Ordered maps are represented as\n" - "# A sequence of mappings, with\n" - "# each mapping having one key\n" - "--- !!omap\n" - "- Mark McGwire: 65\n" - "- Sammy Sosa: 63\n" - "- Ken Griffey: 58"; - - PARSE(doc, input); + PARSE(doc, ex2_26); YAML_ASSERT(doc.Tag() == "tag:yaml.org,2002:omap"); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc[0].size() == 1); @@ -562,38 +358,7 @@ namespace Test { // 2.27 TEST Invoice() { - std::string input = - "--- !\n" - "invoice: 34843\n" - "date : 2001-01-23\n" - "bill-to: &id001\n" - " given : Chris\n" - " family : Dumars\n" - " address:\n" - " lines: |\n" - " 458 Walkman Dr.\n" - " Suite #292\n" - " city : Royal Oak\n" - " state : MI\n" - " postal : 48046\n" - "ship-to: *id001\n" - "product:\n" - " - sku : BL394D\n" - " quantity : 4\n" - " description : Basketball\n" - " price : 450.00\n" - " - sku : BL4438H\n" - " quantity : 1\n" - " description : Super Hoop\n" - " price : 2392.00\n" - "tax : 251.42\n" - "total: 4443.52\n" - "comments:\n" - " Late afternoon is best.\n" - " Backup contact is Nancy\n" - " Billsmer @ 338-4338."; - - PARSE(doc, input); + PARSE(doc, ex2_27); YAML_ASSERT(doc.Tag() == "tag:clarkevans.com,2002:invoice"); YAML_ASSERT(doc.size() == 8); YAML_ASSERT(doc["invoice"].to() == 34843); @@ -634,35 +399,7 @@ namespace Test { // 2.28 TEST LogFile() { - std::string input = - "---\n" - "Time: 2001-11-23 15:01:42 -5\n" - "User: ed\n" - "Warning:\n" - " This is an error message\n" - " for the log file\n" - "---\n" - "Time: 2001-11-23 15:02:31 -5\n" - "User: ed\n" - "Warning:\n" - " A slightly different error\n" - " message.\n" - "---\n" - "Date: 2001-11-23 15:03:17 -5\n" - "User: ed\n" - "Fatal:\n" - " Unknown variable \"bar\"\n" - "Stack:\n" - " - file: TopClass.py\n" - " line: 23\n" - " code: |\n" - " x = MoreObject(\"345\\n\")\n" - " - file: MoreClass.py\n" - " line: 58\n" - " code: |-\n" - " foo = bar"; - - PARSE(doc, input); + PARSE(doc, ex2_28); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc["Time"].to() == "2001-11-23 15:01:42 -5"); YAML_ASSERT(doc["User"].to() == "ed"); @@ -696,16 +433,7 @@ namespace Test { // 5.3 TEST BlockStructureIndicators() { - std::string input = - "sequence:\n" - "- one\n" - "- two\n" - "mapping:\n" - " ? sky\n" - " : blue\n" - " sea : green"; - - PARSE(doc, input); + PARSE(doc, ex5_3); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc["sequence"].size() == 2); YAML_ASSERT(doc["sequence"][0].to() == "one"); @@ -719,11 +447,7 @@ namespace Test { // 5.4 TEST FlowStructureIndicators() { - std::string input = - "sequence: [ one, two, ]\n" - "mapping: { sky: blue, sea: green }"; - - PARSE(doc, input); + PARSE(doc, ex5_4); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc["sequence"].size() == 2); YAML_ASSERT(doc["sequence"][0].to() == "one"); @@ -737,10 +461,7 @@ namespace Test { // 5.5 TEST CommentIndicator() { - std::string input = - "# Comment only."; - - PARSE(doc, input); + PARSE(doc, ex5_5); YAML_ASSERT(doc.size() == 0); return true; } @@ -748,11 +469,7 @@ namespace Test { // 5.6 TEST NodePropertyIndicators() { - std::string input = - "anchored: !local &anchor value\n" - "alias: *anchor"; - - PARSE(doc, input); + PARSE(doc, ex5_6); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc["anchored"].to() == "value"); // TODO: assert tag YAML_ASSERT(doc["alias"].to() == "value"); @@ -762,15 +479,7 @@ namespace Test { // 5.7 TEST BlockScalarIndicators() { - std::string input = - "literal: |\n" - " some\n" - " text\n" - "folded: >\n" - " some\n" - " text\n"; - - PARSE(doc, input); + PARSE(doc, ex5_7); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc["literal"].to() == "some\ntext\n"); YAML_ASSERT(doc["folded"].to() == "some text\n"); @@ -780,11 +489,7 @@ namespace Test { // 5.8 TEST QuotedScalarIndicators() { - std::string input = - "single: 'text'\n" - "double: \"text\""; - - PARSE(doc, input); + PARSE(doc, ex5_8); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc["single"].to() == "text"); YAML_ASSERT(doc["double"].to() == "text"); @@ -797,12 +502,7 @@ namespace Test { // 5.11 TEST LineBreakCharacters() { - std::string input = - "|\n" - " Line break (no glyph)\n" - " Line break (glyphed)\n"; - - PARSE(doc, input); + PARSE(doc, ex5_11); YAML_ASSERT(doc.to() == "Line break (no glyph)\nLine break (glyphed)\n"); return true; } @@ -810,15 +510,7 @@ namespace Test { // 5.12 TEST TabsAndSpaces() { - std::string input = - "# Tabs and spaces\n" - "quoted: \"Quoted\t\"\n" - "block: |\n" - " void main() {\n" - " \tprintf(\"Hello, world!\\n\");\n" - " }"; - - PARSE(doc, input); + PARSE(doc, ex5_12); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc["quoted"].to() == "Quoted\t"); YAML_ASSERT(doc["block"].to() == @@ -831,14 +523,7 @@ namespace Test { // 5.13 TEST EscapedCharacters() { - std::string input = - "\"Fun with \\\\\n" - "\\\" \\a \\b \\e \\f \\\n" - "\\n \\r \\t \\v \\0 \\\n" - "\\ \\_ \\N \\L \\P \\\n" - "\\x41 \\u0041 \\U00000041\""; - - PARSE(doc, input); + PARSE(doc, ex5_13); YAML_ASSERT(doc.to() == "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; } @@ -846,12 +531,7 @@ namespace Test { // 5.14 TEST InvalidEscapedCharacters() { - std::string input = - "Bad escapes:\n" - " \"\\c\n" - " \\xq-\""; - - std::stringstream stream(input); + std::stringstream stream(ex5_14); try { YAML::Parser parser(stream); YAML::Node doc; @@ -867,21 +547,7 @@ namespace Test { // 6.1 TEST IndentationSpaces() { - std::string input = - " # Leading comment line spaces are\n" - " # neither content nor indentation.\n" - " \n" - "Not indented:\n" - " By one space: |\n" - " By four\n" - " spaces\n" - " Flow style: [ # Leading spaces\n" - " By two, # in flow style\n" - " Also by two, # are neither\n" - " \tStill by two # content nor\n" - " ] # indentation."; - - PARSE(doc, input); + PARSE(doc, ex6_1); YAML_ASSERT(doc.size() == 1); YAML_ASSERT(doc["Not indented"].size() == 2); YAML_ASSERT(doc["Not indented"]["By one space"].to() == "By four\n spaces\n"); @@ -895,13 +561,7 @@ namespace Test { // 6.2 TEST IndentationIndicators() { - std::string input = - "? a\n" - ": -\tb\n" - " - -\tc\n" - " - d"; - - PARSE(doc, input); + PARSE(doc, ex6_2); YAML_ASSERT(doc.size() == 1); YAML_ASSERT(doc["a"].size() == 2); YAML_ASSERT(doc["a"][0].to() == "b"); @@ -914,12 +574,7 @@ namespace Test { // 6.3 TEST SeparationSpaces() { - std::string input = - "- foo:\t bar\n" - "- - baz\n" - " -\tbaz"; - - PARSE(doc, input); + PARSE(doc, ex6_3); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc[0].size() == 1); YAML_ASSERT(doc[0]["foo"].to() == "bar"); @@ -932,16 +587,7 @@ namespace Test { // 6.4 TEST LinePrefixes() { - std::string input = - "plain: text\n" - " lines\n" - "quoted: \"text\n" - " \tlines\"\n" - "block: |\n" - " text\n" - " \tlines\n"; - - PARSE(doc, input); + PARSE(doc, ex6_4); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc["plain"].to() == "text lines"); YAML_ASSERT(doc["quoted"].to() == "text lines"); @@ -952,16 +598,7 @@ namespace Test { // 6.5 TEST EmptyLines() { - std::string input = - "Folding:\n" - " \"Empty line\n" - " \t\n" - " as a line feed\"\n" - "Chomping: |\n" - " Clipped empty lines\n" - " "; - - PARSE(doc, input); + PARSE(doc, ex6_5); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc["Folding"].to() == "Empty line\nas a line feed"); YAML_ASSERT(doc["Chomping"].to() == "Clipped empty lines\n"); @@ -971,16 +608,7 @@ namespace Test { // 6.6 TEST LineFolding() { - std::string input = - ">-\n" - " trimmed\n" - " \n" - " \n" - "\n" - " as\n" - " space"; - - PARSE(doc, input); + PARSE(doc, ex6_6); YAML_ASSERT(doc.to() == "trimmed\n\n\nas space"); return true; } @@ -988,15 +616,7 @@ namespace Test { // 6.7 TEST BlockFolding() { - std::string input = - ">\n" - " foo \n" - " \n" - " \t bar\n" - "\n" - " baz\n"; - - PARSE(doc, input); + PARSE(doc, ex6_7); YAML_ASSERT(doc.to() == "foo \n\n\t bar\n\nbaz\n"); return true; } @@ -1004,16 +624,7 @@ namespace Test { // 6.8 TEST FlowFolding() { - std::string input = - "\"\n" - " foo \n" - " \n" - " \t bar\n" - "\n" - " baz\n" - "\""; - - PARSE(doc, input); + PARSE(doc, ex6_8); YAML_ASSERT(doc.to() == " foo\nbar\nbaz "); return true; } @@ -1021,11 +632,7 @@ namespace Test { // 6.9 TEST SeparatedComment() { - std::string input = - "key: # Comment\n" - " value"; - - PARSE(doc, input); + PARSE(doc, ex6_9); YAML_ASSERT(doc.size() == 1); YAML_ASSERT(doc["key"].to() == "value"); return true; @@ -1034,12 +641,7 @@ namespace Test { // 6.10 TEST CommentLines() { - std::string input = - " # Comment\n" - " \n" - "\n"; - - PARSE(doc, input); + PARSE(doc, ex6_10); YAML_ASSERT(doc.size() == 0); return true; } @@ -1047,13 +649,7 @@ namespace Test { // 6.11 TEST MultiLineComments() { - std::string input = - "key: # Comment\n" - " # lines\n" - " value\n" - "\n"; - - PARSE(doc, input); + PARSE(doc, ex6_11); YAML_ASSERT(doc.size() == 1); YAML_ASSERT(doc["key"].to() == "value"); return true; @@ -1081,15 +677,7 @@ namespace Test { // 6.12 TEST SeparationSpacesII() { - std::string input = - "{ first: Sammy, last: Sosa }:\n" - "# Statistics:\n" - " hr: # Home runs\n" - " 65\n" - " avg: # Average\n" - " 0.278"; - - PARSE(doc, input); + PARSE(doc, ex6_12); std::map key; key["first"] = "Sammy"; key["last"] = "Sosa"; @@ -1103,38 +691,22 @@ namespace Test { // 6.13 TEST ReservedDirectives() { - std::string input = - "%FOO bar baz # Should be ignored\n" - " # with a warning.\n" - "--- \"foo\""; - - PARSE(doc, input); + PARSE(doc, ex6_13); return true; } // 6.14 TEST YAMLDirective() { - std::string input = - "%YAML 1.3 # Attempt parsing\n" - " # with a warning\n" - "---\n" - "\"foo\""; - - PARSE(doc, input); + PARSE(doc, ex6_14); return true; } // 6.15 TEST InvalidRepeatedYAMLDirective() { - std::string input = - "%YAML 1.2\n" - "%YAML 1.1\n" - "foo"; - try { - PARSE(doc, input); + PARSE(doc, ex6_15); } catch(const YAML::ParserException& e) { if(e.msg == YAML::ErrorMsg::REPEATED_YAML_DIRECTIVE) return true; @@ -1148,12 +720,7 @@ namespace Test { // 6.16 TEST TagDirective() { - std::string input = - "%TAG !yaml! tag:yaml.org,2002:\n" - "---\n" - "!yaml!str \"foo\""; - - PARSE(doc, input); + PARSE(doc, ex6_16); YAML_ASSERT(doc.Tag() == "tag:yaml.org,2002:str"); YAML_ASSERT(doc.to() == "foo"); return true; @@ -1162,13 +729,8 @@ namespace Test { // 6.17 TEST InvalidRepeatedTagDirective() { - std::string input = - "%TAG ! !foo\n" - "%TAG ! !foo\n" - "bar"; - try { - PARSE(doc, input); + PARSE(doc, ex6_17); } catch(const YAML::ParserException& e) { if(e.msg == YAML::ErrorMsg::REPEATED_TAG_DIRECTIVE) return true; @@ -1182,16 +744,7 @@ namespace Test { // 6.18 TEST PrimaryTagHandle() { - std::string input = - "# Private\n" - "!foo \"bar\"\n" - "...\n" - "# Global\n" - "%TAG ! tag:example.com,2000:app/\n" - "---\n" - "!foo \"bar\""; - - PARSE(doc, input); + PARSE(doc, ex6_18); YAML_ASSERT(doc.Tag() == "!foo"); YAML_ASSERT(doc.to() == "bar"); @@ -1204,12 +757,7 @@ namespace Test { // 6.19 TEST SecondaryTagHandle() { - std::string input = - "%TAG !! tag:example.com,2000:app/\n" - "---\n" - "!!int 1 - 3 # Interval, not integer"; - - PARSE(doc, input); + PARSE(doc, ex6_19); YAML_ASSERT(doc.Tag() == "tag:example.com,2000:app/int"); YAML_ASSERT(doc.to() == "1 - 3"); return true; @@ -1218,12 +766,7 @@ namespace Test { // 6.20 TEST TagHandles() { - std::string input = - "%TAG !e! tag:example.com,2000:app/\n" - "---\n" - "!e!foo \"bar\""; - - PARSE(doc, input); + PARSE(doc, ex6_20); YAML_ASSERT(doc.Tag() == "tag:example.com,2000:app/foo"); YAML_ASSERT(doc.to() == "bar"); return true; @@ -1232,16 +775,7 @@ namespace Test { // 6.21 TEST LocalTagPrefix() { - std::string input = - "%TAG !m! !my-\n" - "--- # Bulb here\n" - "!m!light fluorescent\n" - "...\n" - "%TAG !m! !my-\n" - "--- # Color here\n" - "!m!light green"; - - PARSE(doc, input); + PARSE(doc, ex6_21); YAML_ASSERT(doc.Tag() == "!my-light"); YAML_ASSERT(doc.to() == "fluorescent"); @@ -1254,12 +788,7 @@ namespace Test { // 6.22 TEST GlobalTagPrefix() { - std::string input = - "%TAG !e! tag:example.com,2000:app/\n" - "---\n" - "- !e!foo \"bar\""; - - PARSE(doc, input); + PARSE(doc, ex6_22); YAML_ASSERT(doc.size() == 1); YAML_ASSERT(doc[0].Tag() == "tag:example.com,2000:app/foo"); YAML_ASSERT(doc[0].to() == "bar"); @@ -1269,12 +798,7 @@ namespace Test { // 6.23 TEST NodeProperties() { - std::string input = - "!!str &a1 \"foo\":\n" - " !!str bar\n" - "&a2 baz : *a1"; - - PARSE(doc, input); + PARSE(doc, ex6_23); YAML_ASSERT(doc.size() == 2); for(YAML::Iterator it=doc.begin();it!=doc.end();++it) { if(it.first().to() == "foo") { @@ -1293,11 +817,7 @@ namespace Test { // 6.24 TEST VerbatimTags() { - std::string input = - "! foo :\n" - " ! baz"; - - PARSE(doc, input); + PARSE(doc, ex6_24); YAML_ASSERT(doc.size() == 1); for(YAML::Iterator it=doc.begin();it!=doc.end();++it) { YAML_ASSERT(it.first().Tag() == "tag:yaml.org,2002:str"); @@ -1311,25 +831,14 @@ namespace Test { // 6.25 TEST InvalidVerbatimTags() { - std::string input = - "- ! foo\n" - "- !<$:?> bar\n"; - - PARSE(doc, input); + PARSE(doc, ex6_25); return " not implemented yet"; // TODO: check tags (but we probably will say these are valid, I think) } // 6.26 TEST TagShorthands() { - std::string input = - "%TAG !e! tag:example.com,2000:app/\n" - "---\n" - "- !local foo\n" - "- !!str bar\n" - "- !e!tag%21 baz\n"; - - PARSE(doc, input); + PARSE(doc, ex6_26); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc[0].Tag() == "!local"); YAML_ASSERT(doc[0].to() == "foo"); @@ -1343,14 +852,9 @@ namespace Test { // 6.27 TEST InvalidTagShorthands() { - std::string input1 = - "%TAG !e! tag:example,2000:app/\n" - "---\n" - "- !e! foo"; - bool threw = false; try { - PARSE(doc, input1); + PARSE(doc, ex6_27a); } catch(const YAML::ParserException& e) { threw = true; if(e.msg != YAML::ErrorMsg::TAG_WITH_NO_SUFFIX) @@ -1360,25 +864,14 @@ namespace Test { if(!threw) return " No exception was thrown for a tag with no suffix"; - std::string input2 = - "%TAG !e! tag:example,2000:app/\n" - "---\n" - "- !h!bar baz"; - - PARSE(doc, input2); // TODO: should we reject this one (since !h! is not declared)? + PARSE(doc, ex6_27b); // TODO: should we reject this one (since !h! is not declared)? return " not implemented yet"; } // 6.28 TEST NonSpecificTags() { - std::string input = - "# Assuming conventional resolution:\n" - "- \"12\"\n" - "- 12\n" - "- ! 12"; - - PARSE(doc, input); + PARSE(doc, ex6_28); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc[0].to() == "12"); // TODO: check tags. How? YAML_ASSERT(doc[1].to() == 12); @@ -1389,11 +882,7 @@ namespace Test { // 6.29 TEST NodeAnchors() { - std::string input = - "First occurrence: &anchor Value\n" - "Second occurrence: *anchor"; - - PARSE(doc, input); + PARSE(doc, ex6_29); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc["First occurrence"].to() == "Value"); YAML_ASSERT(doc["Second occurrence"].to() == "Value"); @@ -1403,13 +892,7 @@ namespace Test { // 7.1 TEST AliasNodes() { - std::string input = - "First occurrence: &anchor Foo\n" - "Second occurrence: *anchor\n" - "Override anchor: &anchor Bar\n" - "Reuse anchor: *anchor"; - - PARSE(doc, input); + PARSE(doc, ex7_1); YAML_ASSERT(doc.size() == 4); YAML_ASSERT(doc["First occurrence"].to() == "Foo"); YAML_ASSERT(doc["Second occurrence"].to() == "Foo"); @@ -1421,13 +904,7 @@ namespace Test { // 7.2 TEST EmptyNodes() { - std::string input = - "{\n" - " foo : !!str,\n" - " !!str : bar,\n" - "}"; - - PARSE(doc, input); + PARSE(doc, ex7_2); YAML_ASSERT(doc.size() == 2); for(YAML::Iterator it=doc.begin();it!=doc.end();++it) { if(it.first().to() == "foo") { @@ -1445,13 +922,7 @@ namespace Test { // 7.3 TEST CompletelyEmptyNodes() { - std::string input = - "{\n" - " ? foo :,\n" - " : bar,\n" - "}\n"; - - PARSE(doc, input); + PARSE(doc, ex7_3); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(IsNull(doc["foo"])); YAML_ASSERT(doc[YAML::Null].to() == "bar"); @@ -1461,12 +932,7 @@ namespace Test { // 7.4 TEST DoubleQuotedImplicitKeys() { - std::string input = - "\"implicit block key\" : [\n" - " \"implicit flow key\" : value,\n" - " ]"; - - PARSE(doc, input); + PARSE(doc, ex7_4); YAML_ASSERT(doc.size() == 1); YAML_ASSERT(doc["implicit block key"].size() == 1); YAML_ASSERT(doc["implicit block key"][0].size() == 1); @@ -1477,14 +943,7 @@ namespace Test { // 7.5 TEST DoubleQuotedLineBreaks() { - std::string input = - "\"folded \n" - "to a space,\t\n" - " \n" - "to a line feed, or \t\\\n" - " \\ \tnon-content\""; - - PARSE(doc, input); + PARSE(doc, ex7_5); YAML_ASSERT(doc.to() == "folded to a space,\nto a line feed, or \t \tnon-content"); return true; } @@ -1492,13 +951,7 @@ namespace Test { // 7.6 TEST DoubleQuotedLines() { - std::string input = - "\" 1st non-empty\n" - "\n" - " 2nd non-empty \n" - "\t3rd non-empty \""; - - PARSE(doc, input); + PARSE(doc, ex7_6); YAML_ASSERT(doc.to() == " 1st non-empty\n2nd non-empty 3rd non-empty "); return true; } @@ -1506,9 +959,7 @@ namespace Test { // 7.7 TEST SingleQuotedCharacters() { - std::string input = " 'here''s to \"quotes\"'"; - - PARSE(doc, input); + PARSE(doc, ex7_7); YAML_ASSERT(doc.to() == "here's to \"quotes\""); return true; } @@ -1516,12 +967,7 @@ namespace Test { // 7.8 TEST SingleQuotedImplicitKeys() { - std::string input = - "'implicit block key' : [\n" - " 'implicit flow key' : value,\n" - " ]"; - - PARSE(doc, input); + PARSE(doc, ex7_8); YAML_ASSERT(doc.size() == 1); YAML_ASSERT(doc["implicit block key"].size() == 1); YAML_ASSERT(doc["implicit block key"][0].size() == 1); @@ -1532,13 +978,7 @@ namespace Test { // 7.9 TEST SingleQuotedLines() { - std::string input = - "' 1st non-empty\n" - "\n" - " 2nd non-empty \n" - "\t3rd non-empty '"; - - PARSE(doc, input); + PARSE(doc, ex7_9); YAML_ASSERT(doc.to() == " 1st non-empty\n2nd non-empty 3rd non-empty "); return true; } @@ -1546,21 +986,7 @@ namespace Test { // 7.10 TEST PlainCharacters() { - std::string input = - "# Outside flow collection:\n" - "- ::vector\n" - "- \": - ()\"\n" - "- Up, up, and away!\n" - "- -123\n" - "- http://example.com/foo#bar\n" - "# Inside flow collection:\n" - "- [ ::vector,\n" - " \": - ()\",\n" - " \"Up, up, and away!\",\n" - " -123,\n" - " http://example.com/foo#bar ]"; - - PARSE(doc, input); + PARSE(doc, ex7_10); YAML_ASSERT(doc.size() == 6); YAML_ASSERT(doc[0].to() == "::vector"); YAML_ASSERT(doc[1].to() == ": - ()"); @@ -1579,12 +1005,7 @@ namespace Test { // 7.11 TEST PlainImplicitKeys() { - std::string input = - "implicit block key : [\n" - " implicit flow key : value,\n" - " ]"; - - PARSE(doc, input); + PARSE(doc, ex7_11); YAML_ASSERT(doc.size() == 1); YAML_ASSERT(doc["implicit block key"].size() == 1); YAML_ASSERT(doc["implicit block key"][0].size() == 1); @@ -1595,13 +1016,7 @@ namespace Test { // 7.12 TEST PlainLines() { - std::string input = - "1st non-empty\n" - "\n" - " 2nd non-empty \n" - "\t3rd non-empty"; - - PARSE(doc, input); + PARSE(doc, ex7_12); YAML_ASSERT(doc.to() == "1st non-empty\n2nd non-empty 3rd non-empty"); return true; } @@ -1609,11 +1024,7 @@ namespace Test { // 7.13 TEST FlowSequence() { - std::string input = - "- [ one, two, ]\n" - "- [three ,four]"; - - PARSE(doc, input); + PARSE(doc, ex7_13); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc[0].size() == 2); YAML_ASSERT(doc[0][0].to() == "one"); @@ -1627,17 +1038,7 @@ namespace Test { // 7.14 TEST FlowSequenceEntries() { - std::string input = - "[\n" - "\"double\n" - " quoted\", 'single\n" - " quoted',\n" - "plain\n" - " text, [ nested ],\n" - "single: pair,\n" - "]"; - - PARSE(doc, input); + PARSE(doc, ex7_14); YAML_ASSERT(doc.size() == 5); YAML_ASSERT(doc[0].to() == "double quoted"); YAML_ASSERT(doc[1].to() == "single quoted"); @@ -1652,11 +1053,7 @@ namespace Test { // 7.15 TEST FlowMappings() { - std::string input = - "- { one : two , three: four , }\n" - "- {five: six,seven : eight}"; - - PARSE(doc, input); + PARSE(doc, ex7_15); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc[0].size() == 2); YAML_ASSERT(doc[0]["one"].to() == "two"); @@ -1670,14 +1067,7 @@ namespace Test { // 7.16 TEST FlowMappingEntries() { - std::string input = - "{\n" - "? explicit: entry,\n" - "implicit: entry,\n" - "?\n" - "}"; - - PARSE(doc, input); + PARSE(doc, ex7_16); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc["explicit"].to() == "entry"); YAML_ASSERT(doc["implicit"].to() == "entry"); @@ -1688,15 +1078,7 @@ namespace Test { // 7.17 TEST FlowMappingSeparateValues() { - std::string input = - "{\n" - "unquoted : \"separate\",\n" - "http://foo.com,\n" - "omitted value:,\n" - ": omitted key,\n" - "}"; - - PARSE(doc, input); + PARSE(doc, ex7_17); YAML_ASSERT(doc.size() == 4); YAML_ASSERT(doc["unquoted"].to() == "separate"); YAML_ASSERT(IsNull(doc["http://foo.com"])); @@ -1708,14 +1090,7 @@ namespace Test { // 7.18 TEST FlowMappingAdjacentValues() { - std::string input = - "{\n" - "\"adjacent\":value,\n" - "\"readable\":value,\n" - "\"empty\":\n" - "}"; - - PARSE(doc, input); + PARSE(doc, ex7_18); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc["adjacent"].to() == "value"); YAML_ASSERT(doc["readable"].to() == "value"); @@ -1726,12 +1101,7 @@ namespace Test { // 7.19 TEST SinglePairFlowMappings() { - std::string input = - "[\n" - "foo: bar\n" - "]"; - - PARSE(doc, input); + PARSE(doc, ex7_19); YAML_ASSERT(doc.size() == 1); YAML_ASSERT(doc[0].size() == 1); YAML_ASSERT(doc[0]["foo"].to() == "bar"); @@ -1741,13 +1111,7 @@ namespace Test { // 7.20 TEST SinglePairExplicitEntry() { - std::string input = - "[\n" - "? foo\n" - " bar : baz\n" - "]"; - - PARSE(doc, input); + PARSE(doc, ex7_20); YAML_ASSERT(doc.size() == 1); YAML_ASSERT(doc[0].size() == 1); YAML_ASSERT(doc[0]["foo bar"].to() == "baz"); @@ -1757,12 +1121,7 @@ namespace Test { // 7.21 TEST SinglePairImplicitEntries() { - std::string input = - "- [ YAML : separate ]\n" - "- [ : empty key entry ]\n" - "- [ {JSON: like}:adjacent ]"; - - PARSE(doc, input); + PARSE(doc, ex7_21); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc[0].size() == 1); YAML_ASSERT(doc[0][0].size() == 1); @@ -1781,12 +1140,8 @@ namespace Test { // 7.22 TEST InvalidImplicitKeys() { - std::string input = - "[ foo\n" - " bar: invalid,"; // Note: we don't check (on purpose) the >1K chars for an implicit key - try { - PARSE(doc, input); + PARSE(doc, ex7_22); } catch(const YAML::Exception& e) { if(e.msg == YAML::ErrorMsg::END_OF_SEQ_FLOW) return true; @@ -1799,14 +1154,7 @@ namespace Test { // 7.23 TEST FlowContent() { - std::string input = - "- [ a, b ]\n" - "- { a: b }\n" - "- \"a\"\n" - "- 'b'\n" - "- c"; - - PARSE(doc, input); + PARSE(doc, ex7_23); YAML_ASSERT(doc.size() == 5); YAML_ASSERT(doc[0].size() == 2); YAML_ASSERT(doc[0][0].to() == "a"); @@ -1822,14 +1170,7 @@ namespace Test { // 7.24 TEST FlowNodes() { - std::string input = - "- !!str \"a\"\n" - "- 'b'\n" - "- &anchor \"c\"\n" - "- *anchor\n" - "- !!str"; - - PARSE(doc, input); + PARSE(doc, ex7_24); YAML_ASSERT(doc.size() == 5); YAML_ASSERT(doc[0].Tag() == "tag:yaml.org,2002:str"); YAML_ASSERT(doc[0].to() == "a"); @@ -1844,18 +1185,7 @@ namespace Test { // 8.1 TEST BlockScalarHeader() { - std::string input = - "- | # Empty header\n" - " literal\n" - "- >1 # Indentation indicator\n" - " folded\n" - "- |+ # Chomping indicator\n" - " keep\n" - "\n" - "- >1- # Both indicators\n" - " strip\n"; - - PARSE(doc, input); + PARSE(doc, ex8_1); YAML_ASSERT(doc.size() == 4); YAML_ASSERT(doc[0].to() == "literal\n"); YAML_ASSERT(doc[1].to() == " folded\n"); @@ -1867,20 +1197,7 @@ namespace Test { // 8.2 TEST BlockIndentationHeader() { - std::string input = - "- |\n" - " detected\n" - "- >\n" - " \n" - " \n" - " # detected\n" - "- |1\n" - " explicit\n" - "- >\n" - " \t\n" - " detected\n"; - - PARSE(doc, input); + PARSE(doc, ex8_2); YAML_ASSERT(doc.size() == 4); YAML_ASSERT(doc[0].to() == "detected\n"); YAML_ASSERT(doc[1].to() == "\n\n# detected\n"); @@ -1893,14 +1210,9 @@ namespace Test { TEST InvalidBlockScalarIndentationIndicators() { { - std::string input = - "- |\n" - " \n" - " text"; - bool threw = false; try { - PARSE(doc, input); + PARSE(doc, ex8_3a); } catch(const YAML::Exception& e) { if(e.msg != YAML::ErrorMsg::END_OF_SEQ) throw; @@ -1913,14 +1225,9 @@ namespace Test { } { - std::string input = - "- >\n" - " text\n" - " text"; - bool threw = false; try { - PARSE(doc, input); + PARSE(doc, ex8_3b); } catch(const YAML::Exception& e) { if(e.msg != YAML::ErrorMsg::END_OF_SEQ) throw; @@ -1933,13 +1240,9 @@ namespace Test { } { - std::string input = - "- |2\n" - " text"; - bool threw = false; try { - PARSE(doc, input); + PARSE(doc, ex8_3c); } catch(const YAML::Exception& e) { if(e.msg != YAML::ErrorMsg::END_OF_SEQ) throw; @@ -1957,15 +1260,7 @@ namespace Test { // 8.4 TEST ChompingFinalLineBreak() { - std::string input = - "strip: |-\n" - " text\n" - "clip: |\n" - " text\n" - "keep: |+\n" - " text\n"; - - PARSE(doc, input); + PARSE(doc, ex8_4); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc["strip"].to() == "text"); YAML_ASSERT(doc["clip"].to() == "text\n"); @@ -1976,28 +1271,7 @@ namespace Test { // 8.5 TEST ChompingTrailingLines() { - std::string input = - " # Strip\n" - " # Comments:\n" - "strip: |-\n" - " # text\n" - " \n" - " # Clip\n" - " # comments:\n" - "\n" - "clip: |\n" - " # text\n" - " \n" - " # Keep\n" - " # comments:\n" - "\n" - "keep: |+\n" - " # text\n" - "\n" - " # Trail\n" - " # Comments\n"; - - PARSE(doc, input); + PARSE(doc, ex8_5); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc["strip"].to() == "# text"); YAML_ASSERT(doc["clip"].to() == "# text\n"); @@ -2008,15 +1282,7 @@ namespace Test { // 8.6 TEST EmptyScalarChomping() { - std::string input = - "strip: >-\n" - "\n" - "clip: >\n" - "\n" - "keep: |+\n" - "\n"; - - PARSE(doc, input); + PARSE(doc, ex8_6); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc["strip"].to() == ""); YAML_ASSERT(doc["clip"].to() == ""); @@ -2027,13 +1293,7 @@ namespace Test { // 8.7 TEST LiteralScalar() { - std::string input = - "|\n" - " literal\n" - " \ttext\n" - "\n"; - - PARSE(doc, input); + PARSE(doc, ex8_7); YAML_ASSERT(doc.to() == "literal\n\ttext\n"); return true; } @@ -2041,18 +1301,7 @@ namespace Test { // 8.8 TEST LiteralContent() { - std::string input = - "|\n" - " \n" - " \n" - " literal\n" - " \n" - " \n" - " text\n" - "\n" - " # Comment\n"; - - PARSE(doc, input); + PARSE(doc, ex8_8); YAML_ASSERT(doc.to() == "\n\nliteral\n \n\ntext\n"); return true; } @@ -2060,13 +1309,7 @@ namespace Test { // 8.9 TEST FoldedScalar() { - std::string input = - ">\n" - " folded\n" - " text\n" - "\n"; - - PARSE(doc, input); + PARSE(doc, ex8_9); YAML_ASSERT(doc.to() == "folded text\n"); return true; } @@ -2074,25 +1317,7 @@ namespace Test { // 8.10 TEST FoldedLines() { - std::string input = - ">\n" - "\n" - " folded\n" - " line\n" - "\n" - " next\n" - " line\n" - " * bullet\n" - "\n" - " * list\n" - " * lines\n" - "\n" - " last\n" - " line\n" - "\n" - "# Comment\n"; - - PARSE(doc, input); + PARSE(doc, ex8_10); YAML_ASSERT(doc.to() == "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n"); return true; } @@ -2118,12 +1343,7 @@ namespace Test { // 8.14 TEST BlockSequence() { - std::string input = - "block sequence:\n" - " - one\n" - " - two : three\n"; - - PARSE(doc, input); + PARSE(doc, ex8_14); YAML_ASSERT(doc.size() == 1); YAML_ASSERT(doc["block sequence"].size() == 2); YAML_ASSERT(doc["block sequence"][0].to() == "one"); @@ -2135,15 +1355,7 @@ namespace Test { // 8.15 TEST BlockSequenceEntryTypes() { - std::string input = - "- # Empty\n" - "- |\n" - " block node\n" - "- - one # Compact\n" - " - two # sequence\n" - "- one: two # Compact mapping\n"; - - PARSE(doc, input); + PARSE(doc, ex8_15); YAML_ASSERT(doc.size() == 4); YAML_ASSERT(YAML::IsNull(doc[0])); YAML_ASSERT(doc[1].to() == "block node\n"); @@ -2158,11 +1370,7 @@ namespace Test { // 8.16 TEST BlockMappings() { - std::string input = - "block mapping:\n" - " key: value\n"; - - PARSE(doc, input); + PARSE(doc, ex8_16); YAML_ASSERT(doc.size() == 1); YAML_ASSERT(doc["block mapping"].size() == 1); YAML_ASSERT(doc["block mapping"]["key"].to() == "value"); @@ -2172,14 +1380,7 @@ namespace Test { // 8.17 TEST ExplicitBlockMappingEntries() { - std::string input = - "? explicit key # Empty value\n" - "? |\n" - " block key\n" - ": - one # Explicit compact\n" - " - two # block value\n"; - - PARSE(doc, input); + PARSE(doc, ex8_17); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(IsNull(doc["explicit key"])); YAML_ASSERT(doc["block key\n"].size() == 2); @@ -2191,13 +1392,7 @@ namespace Test { // 8.18 TEST ImplicitBlockMappingEntries() { - std::string input = - "plain key: in-line value\n" - ": # Both empty\n" - "\"quoted key\":\n" - "- entry\n"; - - PARSE(doc, input); + PARSE(doc, ex8_18); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc["plain key"].to() == "in-line value"); YAML_ASSERT(IsNull(doc[YAML::Null])); @@ -2209,12 +1404,7 @@ namespace Test { // 8.19 TEST CompactBlockMappings() { - std::string input = - "- sun: yellow\n" - "- ? earth: blue\n" - " : moon: white\n"; - - PARSE(doc, input); + PARSE(doc, ex8_19); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc[0].size() == 1); YAML_ASSERT(doc[0]["sun"].to() == "yellow"); @@ -2229,15 +1419,7 @@ namespace Test { // 8.20 TEST BlockNodeTypes() { - std::string input = - "-\n" - " \"flow in block\"\n" - "- >\n" - " Block scalar\n" - "- !!map # Block collection\n" - " foo : bar\n"; - - PARSE(doc, input); + PARSE(doc, ex8_20); YAML_ASSERT(doc.size() == 3); YAML_ASSERT(doc[0].to() == "flow in block"); YAML_ASSERT(doc[1].to() == "Block scalar\n"); @@ -2249,15 +1431,7 @@ namespace Test { // 8.21 TEST BlockScalarNodes() { - std::string input = - "literal: |2\n" - " value\n" - "folded:\n" - " !foo\n" - " >1\n" - " value\n"; - - PARSE(doc, input); + PARSE(doc, ex8_21); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc["literal"].to() == "value"); // Note: I believe this is a bug in the YAML spec - it should be "value\n" YAML_ASSERT(doc["folded"].to() == "value"); @@ -2268,15 +1442,7 @@ namespace Test { // 8.22 TEST BlockCollectionNodes() { - std::string input = - "sequence: !!seq\n" - "- entry\n" - "- !!seq\n" - " - nested\n" - "mapping: !!map\n" - " foo: bar\n"; - - PARSE(doc, input); + PARSE(doc, ex8_22); YAML_ASSERT(doc.size() == 2); YAML_ASSERT(doc["sequence"].size() == 2); YAML_ASSERT(doc["sequence"][0].to() == "entry");