Factored out spec examples, and sketched skeleton for spec tests for new API

This commit is contained in:
Jesse Beder
2011-09-12 22:55:37 -05:00
parent 1721750d9e
commit a04dfdeb07
4 changed files with 1677 additions and 3 deletions

View File

@@ -1,8 +1,341 @@
#include "spectests.h"
namespace Test {
bool RunSpecTests()
namespace Test
{
namespace Spec
{
return true;
// 2.1
TEST SeqScalars() { return " not written yet"; }
// 2.2
TEST MappingScalarsToScalars() { return " not written yet"; }
// 2.3
TEST MappingScalarsToSequences() { return " not written yet"; }
// 2.4
TEST SequenceOfMappings() { return " not written yet"; }
// 2.5
TEST SequenceOfSequences() { return " not written yet"; }
// 2.6
TEST MappingOfMappings() { return " not written yet"; }
// 2.7
TEST TwoDocumentsInAStream() { return " not written yet"; }
// 2.8
TEST PlayByPlayFeed() { return " not written yet"; }
// 2.9
TEST SingleDocumentWithTwoComments() { return " not written yet"; }
// 2.10
TEST SimpleAnchor() { return " not written yet"; }
// 2.11
TEST MappingBetweenSequences() { return " not written yet"; }
// 2.12
TEST CompactNestedMapping() { return " not written yet"; }
// 2.13
TEST InLiteralsNewlinesArePreserved() { return " not written yet"; }
// 2.14
TEST InFoldedScalarsNewlinesBecomeSpaces() { return " not written yet"; }
// 2.15
TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines() { return " not written yet"; }
// 2.16
TEST IndentationDeterminesScope() { return " not written yet"; }
// 2.17
TEST QuotedScalars() { return " not written yet"; }
// 2.18
TEST MultiLineFlowScalars() { return " not written yet"; }
// TODO: 2.19 - 2.22 schema tags
// 2.23
TEST VariousExplicitTags() { return " not written yet"; }
// 2.24
TEST GlobalTags() { return " not written yet"; }
// 2.25
TEST UnorderedSets() { return " not written yet"; }
// 2.26
TEST OrderedMappings() { return " not written yet"; }
// 2.27
TEST Invoice() { return " not written yet"; }
// 2.28
TEST LogFile() { return " not written yet"; }
// TODO: 5.1 - 5.2 BOM
// 5.3
TEST BlockStructureIndicators() { return " not written yet"; }
// 5.4
TEST FlowStructureIndicators() { return " not written yet"; }
// 5.5
TEST CommentIndicator() { return " not written yet"; }
// 5.6
TEST NodePropertyIndicators() { return " not written yet"; }
// 5.7
TEST BlockScalarIndicators() { return " not written yet"; }
// 5.8
TEST QuotedScalarIndicators() { return " not written yet"; }
// TODO: 5.9 directive
// TODO: 5.10 reserved indicator
// 5.11
TEST LineBreakCharacters() { return " not written yet"; }
// 5.12
TEST TabsAndSpaces() { return " not written yet"; }
// 5.13
TEST EscapedCharacters() { return " not written yet"; }
// 5.14
TEST InvalidEscapedCharacters() { return " not written yet"; }
// 6.1
TEST IndentationSpaces() { return " not written yet"; }
// 6.2
TEST IndentationIndicators() { return " not written yet"; }
// 6.3
TEST SeparationSpaces() { return " not written yet"; }
// 6.4
TEST LinePrefixes() { return " not written yet"; }
// 6.5
TEST EmptyLines() { return " not written yet"; }
// 6.6
TEST LineFolding() { return " not written yet"; }
// 6.7
TEST BlockFolding() { return " not written yet"; }
// 6.8
TEST FlowFolding() { return " not written yet"; }
// 6.9
TEST SeparatedComment() { return " not written yet"; }
// 6.10
TEST CommentLines() { return " not written yet"; }
// 6.11
TEST MultiLineComments() { return " not written yet"; }
// 6.12
TEST SeparationSpacesII() { return " not written yet"; }
// 6.13
TEST ReservedDirectives() { return " not written yet"; }
// 6.14
TEST YAMLDirective() { return " not written yet"; }
// 6.15
TEST InvalidRepeatedYAMLDirective() { return " not written yet"; }
// 6.16
TEST TagDirective() { return " not written yet"; }
// 6.17
TEST InvalidRepeatedTagDirective() { return " not written yet"; }
// 6.18
TEST PrimaryTagHandle() { return " not written yet"; }
// 6.19
TEST SecondaryTagHandle() { return " not written yet"; }
// 6.20
TEST TagHandles() { return " not written yet"; }
// 6.21
TEST LocalTagPrefix() { return " not written yet"; }
// 6.22
TEST GlobalTagPrefix() { return " not written yet"; }
// 6.23
TEST NodeProperties() { return " not written yet"; }
// 6.24
TEST VerbatimTags() { return " not written yet"; }
// 6.25
TEST InvalidVerbatimTags() { return " not written yet"; }
// 6.26
TEST TagShorthands() { return " not written yet"; }
// 6.27
TEST InvalidTagShorthands() { return " not written yet"; }
// 6.28
TEST NonSpecificTags() { return " not written yet"; }
// 6.29
TEST NodeAnchors() { return " not written yet"; }
// 7.1
TEST AliasNodes() { return " not written yet"; }
// 7.2
TEST EmptyNodes() { return " not written yet"; }
// 7.3
TEST CompletelyEmptyNodes() { return " not written yet"; }
// 7.4
TEST DoubleQuotedImplicitKeys() { return " not written yet"; }
// 7.5
TEST DoubleQuotedLineBreaks() { return " not written yet"; }
// 7.6
TEST DoubleQuotedLines() { return " not written yet"; }
// 7.7
TEST SingleQuotedCharacters() { return " not written yet"; }
// 7.8
TEST SingleQuotedImplicitKeys() { return " not written yet"; }
// 7.9
TEST SingleQuotedLines() { return " not written yet"; }
// 7.10
TEST PlainCharacters() { return " not written yet"; }
// 7.11
TEST PlainImplicitKeys() { return " not written yet"; }
// 7.12
TEST PlainLines() { return " not written yet"; }
// 7.13
TEST FlowSequence() { return " not written yet"; }
// 7.14
TEST FlowSequenceEntries() { return " not written yet"; }
// 7.15
TEST FlowMappings() { return " not written yet"; }
// 7.16
TEST FlowMappingEntries() { return " not written yet"; }
// 7.17
TEST FlowMappingSeparateValues() { return " not written yet"; }
// 7.18
TEST FlowMappingAdjacentValues() { return " not written yet"; }
// 7.19
TEST SinglePairFlowMappings() { return " not written yet"; }
// 7.20
TEST SinglePairExplicitEntry() { return " not written yet"; }
// 7.21
TEST SinglePairImplicitEntries() { return " not written yet"; }
// 7.22
TEST InvalidImplicitKeys() { return " not written yet"; }
// 7.23
TEST FlowContent() { return " not written yet"; }
// 7.24
TEST FlowNodes() { return " not written yet"; }
// 8.1
TEST BlockScalarHeader() { return " not written yet"; }
// 8.2
TEST BlockIndentationHeader() { return " not written yet"; }
// 8.3
TEST InvalidBlockScalarIndentationIndicators() { return " not written yet"; }
// 8.4
TEST ChompingFinalLineBreak() { return " not written yet"; }
// 8.5
TEST ChompingTrailingLines() { return " not written yet"; }
// 8.6
TEST EmptyScalarChomping() { return " not written yet"; }
// 8.7
TEST LiteralScalar() { return " not written yet"; }
// 8.8
TEST LiteralContent() { return " not written yet"; }
// 8.9
TEST FoldedScalar() { return " not written yet"; }
// 8.10
TEST FoldedLines() { return " not written yet"; }
// 8.11
TEST MoreIndentedLines() { return " not written yet"; }
// 8.12
TEST EmptySeparationLines() { return " not written yet"; }
// 8.13
TEST FinalEmptyLines() { return " not written yet"; }
// 8.14
TEST BlockSequence() { return " not written yet"; }
// 8.15
TEST BlockSequenceEntryTypes() { return " not written yet"; }
// 8.16
TEST BlockMappings() { return " not written yet"; }
// 8.17
TEST ExplicitBlockMappingEntries() { return " not written yet"; }
// 8.18
TEST ImplicitBlockMappingEntries() { return " not written yet"; }
// 8.19
TEST CompactBlockMappings() { return " not written yet"; }
// 8.20
TEST BlockNodeTypes() { return " not written yet"; }
// 8.21
TEST BlockScalarNodes() { return " not written yet"; }
// 8.22
TEST BlockCollectionNodes() { return " not written yet"; }
}
}

846
test/specexamples.h Normal file
View File

@@ -0,0 +1,846 @@
namespace Test {
namespace Spec {
const char *ex2_1 =
"- Mark McGwire\n"
"- Sammy Sosa\n"
"- Ken Griffey";
const char *ex2_2 =
"hr: 65 # Home runs\n"
"avg: 0.278 # Batting average\n"
"rbi: 147 # Runs Batted In";
const char *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";
const char *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";
const char *ex2_5 =
"- [name , hr, avg ]\n"
"- [Mark McGwire, 65, 0.278]\n"
"- [Sammy Sosa , 63, 0.288]";
const char *ex2_6 =
"Mark McGwire: {hr: 65, avg: 0.278}\n"
"Sammy Sosa: {\n"
" hr: 63,\n"
" avg: 0.288\n"
" }";
const char *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";
const char *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"
"...";
const char *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";
const char *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";
const char *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 ]";
const char *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";
const char *ex2_13 =
"# ASCII Art\n"
"--- |\n"
" \\//||\\/||\n"
" // || ||__";
const char *ex2_14 =
"--- >\n"
" Mark McGwire's\n"
" year was crippled\n"
" by a knee injury.";
const char *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!";
const char *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";
const char *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: '|\\-*-/|'";
const char *ex2_18 =
"plain:\n"
" This unquoted scalar\n"
" spans many lines.\n"
"\n"
"quoted: \"So does this\n"
" quoted scalar.\\n\"";
// TODO: 2.19 - 2.22 schema tags
const char *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.";
const char *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.";
const char *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";
const char *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";
const char *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.";
const char *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";
// TODO: 5.1 - 5.2 BOM
const char *ex5_3 =
"sequence:\n"
"- one\n"
"- two\n"
"mapping:\n"
" ? sky\n"
" : blue\n"
" sea : green";
const char *ex5_4 =
"sequence: [ one, two, ]\n"
"mapping: { sky: blue, sea: green }";
const char *ex5_5 =
"# Comment only.";
const char *ex5_6 =
"anchored: !local &anchor value\n"
"alias: *anchor";
const char *ex5_7 =
"literal: |\n"
" some\n"
" text\n"
"folded: >\n"
" some\n"
" text\n";
const char *ex5_8 =
"single: 'text'\n"
"double: \"text\"";
// TODO: 5.9 directive
// TODO: 5.10 reserved indicator
const char *ex5_11 =
"|\n"
" Line break (no glyph)\n"
" Line break (glyphed)\n";
const char *ex5_12 =
"# Tabs and spaces\n"
"quoted: \"Quoted\t\"\n"
"block: |\n"
" void main() {\n"
" \tprintf(\"Hello, world!\\n\");\n"
" }";
const char *ex5_13 =
"\"Fun with \\\\\n"
"\\\" \\a \\b \\e \\f \\\n"
"\\n \\r \\t \\v \\0 \\\n"
"\\ \\_ \\N \\L \\P \\\n"
"\\x41 \\u0041 \\U00000041\"";
const char *ex5_14 =
"Bad escapes:\n"
" \"\\c\n"
" \\xq-\"";
const char *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.";
const char *ex6_2 =
"? a\n"
": -\tb\n"
" - -\tc\n"
" - d";
const char *ex6_3 =
"- foo:\t bar\n"
"- - baz\n"
" -\tbaz";
const char *ex6_4 =
"plain: text\n"
" lines\n"
"quoted: \"text\n"
" \tlines\"\n"
"block: |\n"
" text\n"
" \tlines\n";
const char *ex6_5 =
"Folding:\n"
" \"Empty line\n"
" \t\n"
" as a line feed\"\n"
"Chomping: |\n"
" Clipped empty lines\n"
" ";
const char *ex6_6 =
">-\n"
" trimmed\n"
" \n"
" \n"
"\n"
" as\n"
" space";
const char *ex6_7 =
">\n"
" foo \n"
" \n"
" \t bar\n"
"\n"
" baz\n";
const char *ex6_8 =
"\"\n"
" foo \n"
" \n"
" \t bar\n"
"\n"
" baz\n"
"\"";
const char *ex6_9 =
"key: # Comment\n"
" value";
const char *ex6_10 =
" # Comment\n"
" \n"
"\n";
const char *ex6_11 =
"key: # Comment\n"
" # lines\n"
" value\n"
"\n";
const char *ex6_12 =
"{ first: Sammy, last: Sosa }:\n"
"# Statistics:\n"
" hr: # Home runs\n"
" 65\n"
" avg: # Average\n"
" 0.278";
const char *ex6_13 =
"%FOO bar baz # Should be ignored\n"
" # with a warning.\n"
"--- \"foo\"";
const char *ex6_14 =
"%YAML 1.3 # Attempt parsing\n"
" # with a warning\n"
"---\n"
"\"foo\"";
const char *ex6_15 =
"%YAML 1.2\n"
"%YAML 1.1\n"
"foo";
const char *ex6_16 =
"%TAG !yaml! tag:yaml.org,2002:\n"
"---\n"
"!yaml!str \"foo\"";
const char *ex6_17 =
std::string input =
"%TAG ! !foo\n"
"%TAG ! !foo\n"
"bar";
const char *ex6_18 =
"# Private\n"
"!foo \"bar\"\n"
"...\n"
"# Global\n"
"%TAG ! tag:example.com,2000:app/\n"
"---\n"
"!foo \"bar\"";
const char *ex6_19 =
"%TAG !! tag:example.com,2000:app/\n"
"---\n"
"!!int 1 - 3 # Interval, not integer";
const char *ex6_20 =
"%TAG !e! tag:example.com,2000:app/\n"
"---\n"
"!e!foo \"bar\"";
const char *ex6_21 =
"%TAG !m! !my-\n"
"--- # Bulb here\n"
"!m!light fluorescent\n"
"...\n"
"%TAG !m! !my-\n"
"--- # Color here\n"
"!m!light green";
const char *ex6_22 =
"%TAG !e! tag:example.com,2000:app/\n"
"---\n"
"- !e!foo \"bar\"";
const char *ex6_23 =
"!!str &a1 \"foo\":\n"
" !!str bar\n"
"&a2 baz : *a1";
const char *ex6_24 =
"!<tag:yaml.org,2002:str> foo :\n"
" !<!bar> baz";
const char *ex6_25 =
"- !<!> foo\n"
"- !<$:?> bar\n";
const char *ex6_26 =
"%TAG !e! tag:example.com,2000:app/\n"
"---\n"
"- !local foo\n"
"- !!str bar\n"
"- !e!tag%21 baz\n";
const char *ex6_27 =
"%TAG !e! tag:example,2000:app/\n"
"---\n"
"- !e! foo";
const char *ex6_28 =
"# Assuming conventional resolution:\n"
"- \"12\"\n"
"- 12\n"
"- ! 12";
const char *ex6_29 =
"First occurrence: &anchor Value\n"
"Second occurrence: *anchor";
const char *ex7_1 =
"First occurrence: &anchor Foo\n"
"Second occurrence: *anchor\n"
"Override anchor: &anchor Bar\n"
"Reuse anchor: *anchor";
const char *ex7_2 =
"{\n"
" foo : !!str,\n"
" !!str : bar,\n"
"}";
const char *ex7_3 =
"{\n"
" ? foo :,\n"
" : bar,\n"
"}\n";
const char *ex7_4 =
"\"implicit block key\" : [\n"
" \"implicit flow key\" : value,\n"
" ]";
const char *ex7_5 =
"\"folded \n"
"to a space,\t\n"
" \n"
"to a line feed, or \t\\\n"
" \\ \tnon-content\"";
const char *ex7_6 =
"\" 1st non-empty\n"
"\n"
" 2nd non-empty \n"
"\t3rd non-empty \"";
const char *ex7_7 =
" 'here''s to \"quotes\"'";
const char *ex7_8 =
"'implicit block key' : [\n"
" 'implicit flow key' : value,\n"
" ]";
const char *ex7_9 =
"' 1st non-empty\n"
"\n"
" 2nd non-empty \n"
"\t3rd non-empty '";
const char *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 ]";
const char *ex7_11 =
"implicit block key : [\n"
" implicit flow key : value,\n"
" ]";
const char *ex7_12 =
"1st non-empty\n"
"\n"
" 2nd non-empty \n"
"\t3rd non-empty";
const char *ex7_13 =
"- [ one, two, ]\n"
"- [three ,four]";
const char *ex7_14 =
"[\n"
"\"double\n"
" quoted\", 'single\n"
" quoted',\n"
"plain\n"
" text, [ nested ],\n"
"single: pair,\n"
"]";
const char *ex7_15 =
"- { one : two , three: four , }\n"
"- {five: six,seven : eight}";
const char *ex7_16 =
"{\n"
"? explicit: entry,\n"
"implicit: entry,\n"
"?\n"
"}";
const char *ex7_17 =
"{\n"
"unquoted : \"separate\",\n"
"http://foo.com,\n"
"omitted value:,\n"
": omitted key,\n"
"}";
const char *ex7_18 =
"{\n"
"\"adjacent\":value,\n"
"\"readable\":value,\n"
"\"empty\":\n"
"}";
const char *ex7_19 =
"[\n"
"foo: bar\n"
"]";
const char *ex7_20 =
"[\n"
"? foo\n"
" bar : baz\n"
"]";
const char *ex7_21 =
"- [ YAML : separate ]\n"
"- [ : empty key entry ]\n"
"- [ {JSON: like}:adjacent ]";
const char *ex7_22 =
"[ foo\n"
" bar: invalid,"; // Note: we don't check (on purpose) the >1K chars for an implicit key
const char *ex7_23 =
"- [ a, b ]\n"
"- { a: b }\n"
"- \"a\"\n"
"- 'b'\n"
"- c";
const char *ex7_24 =
"- !!str \"a\"\n"
"- 'b'\n"
"- &anchor \"c\"\n"
"- *anchor\n"
"- !!str";
const char *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";
const char *ex8_2 =
"- |\n"
" detected\n"
"- >\n"
" \n"
" \n"
" # detected\n"
"- |1\n"
" explicit\n"
"- >\n"
" \t\n"
" detected\n";
const char *ex8_3_a =
"- |\n"
" \n"
" text";
const char *ex8_3_b =
"- >\n"
" text\n"
" text";
const char *ex8_3_b =
"- |2\n"
" text";
const char *ex8_4 =
"strip: |-\n"
" text\n"
"clip: |\n"
" text\n"
"keep: |+\n"
" text\n";
const char *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";
const char *ex8_6 =
"strip: >-\n"
"\n"
"clip: >\n"
"\n"
"keep: |+\n"
"\n";
const char *ex8_7 =
"|\n"
" literal\n"
" \ttext\n"
"\n";
const char *ex8_8 =
"|\n"
" \n"
" \n"
" literal\n"
" \n"
" \n"
" text\n"
"\n"
" # Comment\n";
const char *ex8_9 =
">\n"
" folded\n"
" text\n"
"\n";
const char *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";
const char *ex8_11 = ex8_10;
const char *ex8_12 = ex8_10;
const char *ex8_13 = ex8_10;
const char *ex8_14 =
"block sequence:\n"
" - one\n"
" - two : three\n";
const char *ex8_15 =
"- # Empty\n"
"- |\n"
" block node\n"
"- - one # Compact\n"
" - two # sequence\n"
"- one: two # Compact mapping\n";
const char *ex8_16 =
"block mapping:\n"
" key: value\n";
const char *ex8_17 =
"? explicit key # Empty value\n"
"? |\n"
" block key\n"
": - one # Explicit compact\n"
" - two # block value\n";
const char *ex8_18 =
"plain key: in-line value\n"
": # Both empty\n"
"\"quoted key\":\n"
"- entry\n";
const char *ex8_19 =
"- sun: yellow\n"
"- ? earth: blue\n"
" : moon: white\n";
const char *ex8_20 =
"-\n"
" \"flow in block\"\n"
"- >\n"
" Block scalar\n"
"- !!map # Block collection\n"
" foo : bar\n";
const char *ex8_21 =
"literal: |2\n"
" value\n"
"folded:\n"
" !foo\n"
" >1\n"
" value\n";
const char *ex8_22 =
"sequence: !!seq\n"
"- entry\n"
"- !!seq\n"
" - nested\n"
"mapping: !!map\n"
" foo: bar\n";
}
}

148
test/spectests.cpp Normal file
View File

@@ -0,0 +1,148 @@
#include "spectests.h"
#include "yaml-cpp/yaml.h"
namespace Test
{
namespace {
void RunSpecTest(TEST (*test)(), const std::string& index, const std::string& name, int& passed, int& total) {
TEST ret;
try {
ret = test();
} catch(const YAML::Exception& e) {
ret.ok = false;
ret.error = std::string(" Exception caught: ") + e.what();
}
if(!ret.ok) {
std::cout << "Spec test " << index << " failed: " << name << "\n";
std::cout << ret.error << "\n";
}
if(ret.ok)
passed++;
total++;
}
}
bool RunSpecTests()
{
int passed = 0;
int total = 0;
RunSpecTest(&Spec::SeqScalars, "2.1", "Sequence of Scalars", passed, total);
RunSpecTest(&Spec::MappingScalarsToScalars, "2.2", "Mapping Scalars to Scalars", passed, total);
RunSpecTest(&Spec::MappingScalarsToSequences, "2.3", "Mapping Scalars to Sequences", passed, total);
RunSpecTest(&Spec::SequenceOfMappings, "2.4", "Sequence of Mappings", passed, total);
RunSpecTest(&Spec::SequenceOfSequences, "2.5", "Sequence of Sequences", passed, total);
RunSpecTest(&Spec::MappingOfMappings, "2.6", "Mapping of Mappings", passed, total);
RunSpecTest(&Spec::TwoDocumentsInAStream, "2.7", "Two Documents in a Stream", passed, total);
RunSpecTest(&Spec::PlayByPlayFeed, "2.8", "Play by Play Feed from a Game", passed, total);
RunSpecTest(&Spec::SingleDocumentWithTwoComments, "2.9", "Single Document with Two Comments", passed, total);
RunSpecTest(&Spec::SimpleAnchor, "2.10", "Node for \"Sammy Sosa\" appears twice in this document", passed, total);
RunSpecTest(&Spec::MappingBetweenSequences, "2.11", "Mapping between Sequences", passed, total);
RunSpecTest(&Spec::CompactNestedMapping, "2.12", "Compact Nested Mapping", passed, total);
RunSpecTest(&Spec::InLiteralsNewlinesArePreserved, "2.13", "In literals, newlines are preserved", passed, total);
RunSpecTest(&Spec::InFoldedScalarsNewlinesBecomeSpaces, "2.14", "In folded scalars, newlines become spaces", passed, total);
RunSpecTest(&Spec::FoldedNewlinesArePreservedForMoreIndentedAndBlankLines, "2.15", "Folded newlines are preserved for \"more indented\" and blank lines", passed, total);
RunSpecTest(&Spec::IndentationDeterminesScope, "2.16", "Indentation determines scope", passed, total);
RunSpecTest(&Spec::QuotedScalars, "2.17", "Quoted scalars", passed, total);
RunSpecTest(&Spec::MultiLineFlowScalars, "2.18", "Multi-line flow scalars", passed, total);
RunSpecTest(&Spec::VariousExplicitTags, "2.23", "Various Explicit Tags", passed, total);
RunSpecTest(&Spec::GlobalTags, "2.24", "Global Tags", passed, total);
RunSpecTest(&Spec::UnorderedSets, "2.25", "Unordered Sets", passed, total);
RunSpecTest(&Spec::OrderedMappings, "2.26", "Ordered Mappings", passed, total);
RunSpecTest(&Spec::Invoice, "2.27", "Invoice", passed, total);
RunSpecTest(&Spec::LogFile, "2.28", "Log File", passed, total);
RunSpecTest(&Spec::BlockStructureIndicators, "5.3", "Block Structure Indicators", passed, total);
RunSpecTest(&Spec::FlowStructureIndicators, "5.4", "Flow Structure Indicators", passed, total);
RunSpecTest(&Spec::NodePropertyIndicators, "5.6", "Node Property Indicators", passed, total);
RunSpecTest(&Spec::BlockScalarIndicators, "5.7", "Block Scalar Indicators", passed, total);
RunSpecTest(&Spec::QuotedScalarIndicators, "5.8", "Quoted Scalar Indicators", passed, total);
RunSpecTest(&Spec::LineBreakCharacters, "5.11", "Line Break Characters", passed, total);
RunSpecTest(&Spec::TabsAndSpaces, "5.12", "Tabs and Spaces", passed, total);
RunSpecTest(&Spec::EscapedCharacters, "5.13", "Escaped Characters", passed, total);
RunSpecTest(&Spec::InvalidEscapedCharacters, "5.14", "Invalid Escaped Characters", passed, total);
RunSpecTest(&Spec::IndentationSpaces, "6.1", "Indentation Spaces", passed, total);
RunSpecTest(&Spec::IndentationIndicators, "6.2", "Indentation Indicators", passed, total);
RunSpecTest(&Spec::SeparationSpaces, "6.3", "Separation Spaces", passed, total);
RunSpecTest(&Spec::LinePrefixes, "6.4", "Line Prefixes", passed, total);
RunSpecTest(&Spec::EmptyLines, "6.5", "Empty Lines", passed, total);
RunSpecTest(&Spec::LineFolding, "6.6", "Line Folding", passed, total);
RunSpecTest(&Spec::BlockFolding, "6.7", "Block Folding", passed, total);
RunSpecTest(&Spec::FlowFolding, "6.8", "Flow Folding", passed, total);
RunSpecTest(&Spec::SeparatedComment, "6.9", "Separated Comment", passed, total);
RunSpecTest(&Spec::CommentLines, "6.10", "Comment Lines", passed, total);
RunSpecTest(&Spec::MultiLineComments, "6.11", "Multi-Line Comments", passed, total);
RunSpecTest(&Spec::SeparationSpacesII, "6.12", "Separation Spaces", passed, total);
RunSpecTest(&Spec::ReservedDirectives, "6.13", "Reserved Directives", passed, total);
RunSpecTest(&Spec::YAMLDirective, "6.14", "YAML Directive", passed, total);
RunSpecTest(&Spec::InvalidRepeatedYAMLDirective, "6.15", "Invalid Repeated YAML Directive", passed, total);
RunSpecTest(&Spec::TagDirective, "6.16", "Tag Directive", passed, total);
RunSpecTest(&Spec::InvalidRepeatedTagDirective, "6.17", "Invalid Repeated Tag Directive", passed, total);
RunSpecTest(&Spec::PrimaryTagHandle, "6.18", "Primary Tag Handle", passed, total);
RunSpecTest(&Spec::SecondaryTagHandle, "6.19", "SecondaryTagHandle", passed, total);
RunSpecTest(&Spec::TagHandles, "6.20", "TagHandles", passed, total);
RunSpecTest(&Spec::LocalTagPrefix, "6.21", "LocalTagPrefix", passed, total);
RunSpecTest(&Spec::GlobalTagPrefix, "6.22", "GlobalTagPrefix", passed, total);
RunSpecTest(&Spec::NodeProperties, "6.23", "NodeProperties", passed, total);
RunSpecTest(&Spec::VerbatimTags, "6.24", "Verbatim Tags", passed, total);
RunSpecTest(&Spec::InvalidVerbatimTags, "6.25", "Invalid Verbatim Tags", passed, total);
RunSpecTest(&Spec::TagShorthands, "6.26", "Tag Shorthands", passed, total);
RunSpecTest(&Spec::InvalidTagShorthands, "6.27", "Invalid Tag Shorthands", passed, total);
RunSpecTest(&Spec::NonSpecificTags, "6.28", "Non Specific Tags", passed, total);
RunSpecTest(&Spec::NodeAnchors, "6.29", "Node Anchors", passed, total);
RunSpecTest(&Spec::AliasNodes, "7.1", "Alias Nodes", passed, total);
RunSpecTest(&Spec::EmptyNodes, "7.2", "Empty Nodes", passed, total);
RunSpecTest(&Spec::CompletelyEmptyNodes, "7.3", "Completely Empty Nodes", passed, total);
RunSpecTest(&Spec::DoubleQuotedImplicitKeys, "7.4", "Double Quoted Implicit Keys", passed, total);
RunSpecTest(&Spec::DoubleQuotedLineBreaks, "7.5", "Double Quoted Line Breaks", passed, total);
RunSpecTest(&Spec::DoubleQuotedLines, "7.6", "Double Quoted Lines", passed, total);
RunSpecTest(&Spec::SingleQuotedCharacters, "7.7", "Single Quoted Characters", passed, total);
RunSpecTest(&Spec::SingleQuotedImplicitKeys, "7.8", "Single Quoted Implicit Keys", passed, total);
RunSpecTest(&Spec::SingleQuotedLines, "7.9", "Single Quoted Lines", passed, total);
RunSpecTest(&Spec::PlainCharacters, "7.10", "Plain Characters", passed, total);
RunSpecTest(&Spec::PlainImplicitKeys, "7.11", "Plain Implicit Keys", passed, total);
RunSpecTest(&Spec::PlainLines, "7.12", "Plain Lines", passed, total);
RunSpecTest(&Spec::FlowSequence, "7.13", "Flow Sequence", passed, total);
RunSpecTest(&Spec::FlowSequenceEntries, "7.14", "Flow Sequence Entries", passed, total);
RunSpecTest(&Spec::FlowMappings, "7.15", "Flow Mappings", passed, total);
RunSpecTest(&Spec::FlowMappingEntries, "7.16", "Flow Mapping Entries", passed, total);
RunSpecTest(&Spec::FlowMappingSeparateValues, "7.17", "Flow Mapping Separate Values", passed, total);
RunSpecTest(&Spec::FlowMappingAdjacentValues, "7.18", "Flow Mapping Adjacent Values", passed, total);
RunSpecTest(&Spec::SinglePairFlowMappings, "7.19", "Single Pair Flow Mappings", passed, total);
RunSpecTest(&Spec::SinglePairExplicitEntry, "7.20", "Single Pair Explicit Entry", passed, total);
RunSpecTest(&Spec::SinglePairImplicitEntries, "7.21", "Single Pair Implicit Entries", passed, total);
RunSpecTest(&Spec::InvalidImplicitKeys, "7.22", "Invalid Implicit Keys", passed, total);
RunSpecTest(&Spec::FlowContent, "7.23", "Flow Content", passed, total);
RunSpecTest(&Spec::FlowNodes, "7.24", "FlowNodes", passed, total);
RunSpecTest(&Spec::BlockScalarHeader, "8.1", "Block Scalar Header", passed, total);
RunSpecTest(&Spec::BlockIndentationHeader, "8.2", "Block Indentation Header", passed, total);
RunSpecTest(&Spec::InvalidBlockScalarIndentationIndicators, "8.3", "Invalid Block Scalar Indentation Indicators", passed, total);
RunSpecTest(&Spec::ChompingFinalLineBreak, "8.4", "Chomping Final Line Break", passed, total);
RunSpecTest(&Spec::ChompingTrailingLines, "8.5", "Chomping Trailing Lines", passed, total);
RunSpecTest(&Spec::EmptyScalarChomping, "8.6", "Empty Scalar Chomping", passed, total);
RunSpecTest(&Spec::LiteralScalar, "8.7", "Literal Scalar", passed, total);
RunSpecTest(&Spec::LiteralContent, "8.8", "Literal Content", passed, total);
RunSpecTest(&Spec::FoldedScalar, "8.9", "Folded Scalar", passed, total);
RunSpecTest(&Spec::FoldedLines, "8.10", "Folded Lines", passed, total);
RunSpecTest(&Spec::MoreIndentedLines, "8.11", "More Indented Lines", passed, total);
RunSpecTest(&Spec::EmptySeparationLines, "8.12", "Empty Separation Lines", passed, total);
RunSpecTest(&Spec::FinalEmptyLines, "8.13", "Final Empty Lines", passed, total);
RunSpecTest(&Spec::BlockSequence, "8.14", "Block Sequence", passed, total);
RunSpecTest(&Spec::BlockSequenceEntryTypes, "8.15", "Block Sequence Entry Types", passed, total);
RunSpecTest(&Spec::BlockMappings, "8.16", "Block Mappings", passed, total);
RunSpecTest(&Spec::ExplicitBlockMappingEntries, "8.17", "Explicit Block Mapping Entries", passed, total);
RunSpecTest(&Spec::ImplicitBlockMappingEntries, "8.18", "Implicit Block Mapping Entries", passed, total);
RunSpecTest(&Spec::CompactBlockMappings, "8.19", "Compact Block Mappings", passed, total);
RunSpecTest(&Spec::BlockNodeTypes, "8.20", "Block Node Types", passed, total);
RunSpecTest(&Spec::BlockScalarNodes, "8.21", "Block Scalar Nodes", passed, total);
RunSpecTest(&Spec::BlockCollectionNodes, "8.22", "Block Collection Nodes", passed, total);
std::cout << "Spec tests: " << passed << "/" << total << " passed\n";
return passed == total;
}
}

View File

@@ -5,7 +5,354 @@
#pragma once
#endif
#include <string>
namespace Test {
struct TEST {
TEST(): ok(false) {}
TEST(bool ok_): ok(ok_) {}
TEST(const char *error_): ok(false), error(error_) {}
bool ok;
std::string error;
};
namespace Spec {
// 2.1
TEST SeqScalars();
// 2.2
TEST MappingScalarsToScalars();
// 2.3
TEST MappingScalarsToSequences();
// 2.4
TEST SequenceOfMappings();
// 2.5
TEST SequenceOfSequences();
// 2.6
TEST MappingOfMappings();
// 2.7
TEST TwoDocumentsInAStream();
// 2.8
TEST PlayByPlayFeed();
// 2.9
TEST SingleDocumentWithTwoComments();
// 2.10
TEST SimpleAnchor();
// 2.11
TEST MappingBetweenSequences();
// 2.12
TEST CompactNestedMapping();
// 2.13
TEST InLiteralsNewlinesArePreserved();
// 2.14
TEST InFoldedScalarsNewlinesBecomeSpaces();
// 2.15
TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines();
// 2.16
TEST IndentationDeterminesScope();
// 2.17
TEST QuotedScalars();
// 2.18
TEST MultiLineFlowScalars();
// TODO: 2.19 - 2.22 schema tags
// 2.23
TEST VariousExplicitTags();
// 2.24
TEST GlobalTags();
// 2.25
TEST UnorderedSets();
// 2.26
TEST OrderedMappings();
// 2.27
TEST Invoice();
// 2.28
TEST LogFile();
// TODO: 5.1 - 5.2 BOM
// 5.3
TEST BlockStructureIndicators();
// 5.4
TEST FlowStructureIndicators();
// 5.5
TEST CommentIndicator();
// 5.6
TEST NodePropertyIndicators();
// 5.7
TEST BlockScalarIndicators();
// 5.8
TEST QuotedScalarIndicators();
// TODO: 5.9 directive
// TODO: 5.10 reserved indicator
// 5.11
TEST LineBreakCharacters();
// 5.12
TEST TabsAndSpaces();
// 5.13
TEST EscapedCharacters();
// 5.14
TEST InvalidEscapedCharacters();
// 6.1
TEST IndentationSpaces();
// 6.2
TEST IndentationIndicators();
// 6.3
TEST SeparationSpaces();
// 6.4
TEST LinePrefixes();
// 6.5
TEST EmptyLines();
// 6.6
TEST LineFolding();
// 6.7
TEST BlockFolding();
// 6.8
TEST FlowFolding();
// 6.9
TEST SeparatedComment();
// 6.10
TEST CommentLines();
// 6.11
TEST MultiLineComments();
// 6.12
TEST SeparationSpacesII();
// 6.13
TEST ReservedDirectives();
// 6.14
TEST YAMLDirective();
// 6.15
TEST InvalidRepeatedYAMLDirective();
// 6.16
TEST TagDirective();
// 6.17
TEST InvalidRepeatedTagDirective();
// 6.18
TEST PrimaryTagHandle();
// 6.19
TEST SecondaryTagHandle();
// 6.20
TEST TagHandles();
// 6.21
TEST LocalTagPrefix();
// 6.22
TEST GlobalTagPrefix();
// 6.23
TEST NodeProperties();
// 6.24
TEST VerbatimTags();
// 6.25
TEST InvalidVerbatimTags();
// 6.26
TEST TagShorthands();
// 6.27
TEST InvalidTagShorthands();
// 6.28
TEST NonSpecificTags();
// 6.29
TEST NodeAnchors();
// 7.1
TEST AliasNodes();
// 7.2
TEST EmptyNodes();
// 7.3
TEST CompletelyEmptyNodes();
// 7.4
TEST DoubleQuotedImplicitKeys();
// 7.5
TEST DoubleQuotedLineBreaks();
// 7.6
TEST DoubleQuotedLines();
// 7.7
TEST SingleQuotedCharacters();
// 7.8
TEST SingleQuotedImplicitKeys();
// 7.9
TEST SingleQuotedLines();
// 7.10
TEST PlainCharacters();
// 7.11
TEST PlainImplicitKeys();
// 7.12
TEST PlainLines();
// 7.13
TEST FlowSequence();
// 7.14
TEST FlowSequenceEntries();
// 7.15
TEST FlowMappings();
// 7.16
TEST FlowMappingEntries();
// 7.17
TEST FlowMappingSeparateValues();
// 7.18
TEST FlowMappingAdjacentValues();
// 7.19
TEST SinglePairFlowMappings();
// 7.20
TEST SinglePairExplicitEntry();
// 7.21
TEST SinglePairImplicitEntries();
// 7.22
TEST InvalidImplicitKeys();
// 7.23
TEST FlowContent();
// 7.24
TEST FlowNodes();
// 8.1
TEST BlockScalarHeader();
// 8.2
TEST BlockIndentationHeader();
// 8.3
TEST InvalidBlockScalarIndentationIndicators();
// 8.4
TEST ChompingFinalLineBreak();
// 8.5
TEST ChompingTrailingLines();
// 8.6
TEST EmptyScalarChomping();
// 8.7
TEST LiteralScalar();
// 8.8
TEST LiteralContent();
// 8.9
TEST FoldedScalar();
// 8.10
TEST FoldedLines();
// 8.11
TEST MoreIndentedLines();
// 8.12
TEST EmptySeparationLines();
// 8.13
TEST FinalEmptyLines();
// 8.14
TEST BlockSequence();
// 8.15
TEST BlockSequenceEntryTypes();
// 8.16
TEST BlockMappings();
// 8.17
TEST ExplicitBlockMappingEntries();
// 8.18
TEST ImplicitBlockMappingEntries();
// 8.19
TEST CompactBlockMappings();
// 8.20
TEST BlockNodeTypes();
// 8.21
TEST BlockScalarNodes();
// 8.22
TEST BlockCollectionNodes();
}
bool RunSpecTests();
}