Commit f6d6c90a authored by Jesse Beder's avatar Jesse Beder
Browse files

Updated old api spectests with common spec examples

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