Commit 3355bbb3 authored by Jesse Beder's avatar Jesse Beder
Browse files

Merge clang-format from core

parents 5b889311 9b4db068
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -7,19 +7,31 @@ ...@@ -7,19 +7,31 @@
#include <cassert> #include <cassert>
namespace Test { namespace Test {
inline std::string Quote(const std::string& text) { inline std::string Quote(const std::string& text) {
YAML::Emitter out; YAML::Emitter out;
out << YAML::DoubleQuoted << text; out << YAML::DoubleQuoted << text;
return out.c_str(); return out.c_str();
} }
struct Event { struct Event {
enum Type { DocStart, DocEnd, Null, Alias, Scalar, SeqStart, SeqEnd, MapStart, MapEnd }; enum Type {
DocStart,
DocEnd,
Null,
Alias,
Scalar,
SeqStart,
SeqEnd,
MapStart,
MapEnd
};
typedef YAML::Mark Mark; typedef YAML::Mark Mark;
typedef YAML::anchor_t anchor_t; typedef YAML::anchor_t anchor_t;
Event(Type type_, const std::string& tag_, anchor_t anchor_, const std::string& scalar_): type(type_), tag(tag_), anchor(anchor_), scalar(scalar_) {} Event(Type type_, const std::string& tag_, anchor_t anchor_,
const std::string& scalar_)
: type(type_), tag(tag_), anchor(anchor_), scalar(scalar_) {}
Type type; Type type;
std::string tag; std::string tag;
...@@ -27,7 +39,7 @@ namespace Test { ...@@ -27,7 +39,7 @@ namespace Test {
std::string scalar; std::string scalar;
std::ostream& write(std::ostream& out) const { std::ostream& write(std::ostream& out) const {
switch(type) { switch (type) {
case DocStart: case DocStart:
return out << "DocStart"; return out << "DocStart";
case DocEnd: case DocEnd:
...@@ -37,7 +49,8 @@ namespace Test { ...@@ -37,7 +49,8 @@ namespace Test {
case Alias: case Alias:
return out << "Alias(" << anchor << ")"; return out << "Alias(" << anchor << ")";
case Scalar: case Scalar:
return out << "Scalar(" << Quote(tag) << ", " << anchor << ", " << Quote(scalar) << ")"; return out << "Scalar(" << Quote(tag) << ", " << anchor << ", "
<< Quote(scalar) << ")";
case SeqStart: case SeqStart:
return out << "SeqStart(" << Quote(tag) << ", " << anchor << ")"; return out << "SeqStart(" << Quote(tag) << ", " << anchor << ")";
case SeqEnd: case SeqEnd:
...@@ -50,22 +63,20 @@ namespace Test { ...@@ -50,22 +63,20 @@ namespace Test {
assert(false); assert(false);
return out; return out;
} }
}; };
inline std::ostream& operator << (std::ostream& out, const Event& event) { inline std::ostream& operator<<(std::ostream& out, const Event& event) {
return event.write(out); return event.write(out);
} }
inline bool operator == (const Event& a, const Event& b) { inline bool operator==(const Event& a, const Event& b) {
return a.type == b.type && a.tag == b.tag && a.anchor == b.anchor && a.scalar == b.scalar; return a.type == b.type && a.tag == b.tag && a.anchor == b.anchor &&
} a.scalar == b.scalar;
}
inline bool operator != (const Event& a, const Event& b) { inline bool operator!=(const Event& a, const Event& b) { return !(a == b); }
return !(a == b);
}
class MockEventHandler: public YAML::EventHandler class MockEventHandler : public YAML::EventHandler {
{
public: public:
typedef YAML::Mark Mark; typedef YAML::Mark Mark;
typedef YAML::anchor_t anchor_t; typedef YAML::anchor_t anchor_t;
...@@ -88,11 +99,13 @@ namespace Test { ...@@ -88,11 +99,13 @@ namespace Test {
m_actualEvents.push_back(Event(Event::Alias, "", anchor, "")); m_actualEvents.push_back(Event(Event::Alias, "", anchor, ""));
} }
virtual void OnScalar(const Mark&, const std::string& tag, anchor_t anchor, const std::string& value) { virtual void OnScalar(const Mark&, const std::string& tag, anchor_t anchor,
const std::string& value) {
m_actualEvents.push_back(Event(Event::Scalar, tag, anchor, value)); m_actualEvents.push_back(Event(Event::Scalar, tag, anchor, value));
} }
virtual void OnSequenceStart(const Mark&, const std::string& tag, anchor_t anchor) { virtual void OnSequenceStart(const Mark&, const std::string& tag,
anchor_t anchor) {
m_actualEvents.push_back(Event(Event::SeqStart, tag, anchor, "")); m_actualEvents.push_back(Event(Event::SeqStart, tag, anchor, ""));
} }
...@@ -100,7 +113,8 @@ namespace Test { ...@@ -100,7 +113,8 @@ namespace Test {
m_actualEvents.push_back(Event(Event::SeqEnd, "", 0, "")); m_actualEvents.push_back(Event(Event::SeqEnd, "", 0, ""));
} }
virtual void OnMapStart(const Mark&, const std::string& tag, anchor_t anchor) { virtual void OnMapStart(const Mark&, const std::string& tag,
anchor_t anchor) {
m_actualEvents.push_back(Event(Event::MapStart, tag, anchor, "")); m_actualEvents.push_back(Event(Event::MapStart, tag, anchor, ""));
} }
...@@ -112,10 +126,10 @@ namespace Test { ...@@ -112,10 +126,10 @@ namespace Test {
Test::TEST Check() const { Test::TEST Check() const {
std::size_t N = std::max(m_expectedEvents.size(), m_actualEvents.size()); std::size_t N = std::max(m_expectedEvents.size(), m_actualEvents.size());
for(std::size_t i=0;i<N;i++) { for (std::size_t i = 0; i < N; i++) {
if(i >= m_expectedEvents.size()) { if (i >= m_expectedEvents.size()) {
std::stringstream out; std::stringstream out;
for(std::size_t j=0;j<i;j++) { for (std::size_t j = 0; j < i; j++) {
out << " " << m_expectedEvents[j] << "\n"; out << " " << m_expectedEvents[j] << "\n";
} }
out << " EXPECTED: (no event expected)\n"; out << " EXPECTED: (no event expected)\n";
...@@ -123,9 +137,9 @@ namespace Test { ...@@ -123,9 +137,9 @@ namespace Test {
return out.str().c_str(); return out.str().c_str();
} }
if(i >= m_actualEvents.size()) { if (i >= m_actualEvents.size()) {
std::stringstream out; std::stringstream out;
for(std::size_t j=0;j<i;j++) { for (std::size_t j = 0; j < i; j++) {
out << " " << m_expectedEvents[j] << "\n"; out << " " << m_expectedEvents[j] << "\n";
} }
out << " EXPECTED: " << m_expectedEvents[i] << "\n"; out << " EXPECTED: " << m_expectedEvents[i] << "\n";
...@@ -133,9 +147,9 @@ namespace Test { ...@@ -133,9 +147,9 @@ namespace Test {
return out.str().c_str(); return out.str().c_str();
} }
if(m_expectedEvents[i] != m_actualEvents[i]) { if (m_expectedEvents[i] != m_actualEvents[i]) {
std::stringstream out; std::stringstream out;
for(std::size_t j=0;j<i;j++) { for (std::size_t j = 0; j < i; j++) {
out << " " << m_expectedEvents[j] << "\n"; out << " " << m_expectedEvents[j] << "\n";
} }
out << " EXPECTED: " << m_expectedEvents[i] << "\n"; out << " EXPECTED: " << m_expectedEvents[i] << "\n";
...@@ -149,42 +163,35 @@ namespace Test { ...@@ -149,42 +163,35 @@ namespace Test {
std::vector<Event> m_expectedEvents; std::vector<Event> m_expectedEvents;
std::vector<Event> m_actualEvents; std::vector<Event> m_actualEvents;
}; };
#define HANDLE(ex)\
MockEventHandler handler;\
std::stringstream stream(ex);\
YAML::Parser parser(stream);\
while(parser.HandleNextDocument(handler)) {}
#define EXPECT_DOC_START()\ #define HANDLE(ex) \
handler.Expect(Event(Event::DocStart, "", 0, "")) MockEventHandler handler; \
std::stringstream stream(ex); \
YAML::Parser parser(stream); \
while (parser.HandleNextDocument(handler)) { \
}
#define EXPECT_DOC_END()\ #define EXPECT_DOC_START() handler.Expect(Event(Event::DocStart, "", 0, ""))
handler.Expect(Event(Event::DocEnd, "", 0, ""))
#define EXPECT_NULL(anchor)\ #define EXPECT_DOC_END() handler.Expect(Event(Event::DocEnd, "", 0, ""))
handler.Expect(Event(Event::Null, "", anchor, ""))
#define EXPECT_ALIAS(anchor)\ #define EXPECT_NULL(anchor) handler.Expect(Event(Event::Null, "", anchor, ""))
handler.Expect(Event(Event::Alias, "", anchor, ""))
#define EXPECT_SCALAR(tag, anchor, value)\ #define EXPECT_ALIAS(anchor) handler.Expect(Event(Event::Alias, "", anchor, ""))
handler.Expect(Event(Event::Scalar, tag, anchor, value))
#define EXPECT_SEQ_START(tag, anchor)\ #define EXPECT_SCALAR(tag, anchor, value) \
handler.Expect(Event(Event::SeqStart, tag, anchor, "")) handler.Expect(Event(Event::Scalar, tag, anchor, value))
#define EXPECT_SEQ_END()\ #define EXPECT_SEQ_START(tag, anchor) \
handler.Expect(Event(Event::SeqEnd, "", 0, "")) handler.Expect(Event(Event::SeqStart, tag, anchor, ""))
#define EXPECT_MAP_START(tag, anchor)\ #define EXPECT_SEQ_END() handler.Expect(Event(Event::SeqEnd, "", 0, ""))
handler.Expect(Event(Event::MapStart, tag, anchor, ""))
#define EXPECT_MAP_END()\ #define EXPECT_MAP_START(tag, anchor) \
handler.Expect(Event(Event::MapEnd, "", 0, "")) handler.Expect(Event(Event::MapStart, tag, anchor, ""))
#define DONE()\ #define EXPECT_MAP_END() handler.Expect(Event(Event::MapEnd, "", 0, ""))
return handler.Check()
#define DONE() return handler.Check()
} }
#include "tests.h" #include "tests.h"
int main() int main() {
{
Test::RunAll(); Test::RunAll();
return 0; return 0;
} }
#ifndef PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
namespace Test { namespace Test {
bool RunParserTests(); bool RunParserTests();
} }
#endif // PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
namespace Test { namespace Test {
namespace Spec { namespace Spec {
const char *ex2_1 = const char *ex2_1 =
"- Mark McGwire\n" "- Mark McGwire\n"
"- Sammy Sosa\n" "- Sammy Sosa\n"
"- Ken Griffey"; "- Ken Griffey";
const char *ex2_2 = const char *ex2_2 =
"hr: 65 # Home runs\n" "hr: 65 # Home runs\n"
"avg: 0.278 # Batting average\n" "avg: 0.278 # Batting average\n"
"rbi: 147 # Runs Batted In"; "rbi: 147 # Runs Batted In";
const char *ex2_3 = const char *ex2_3 =
"american:\n" "american:\n"
"- Boston Red Sox\n" "- Boston Red Sox\n"
"- Detroit Tigers\n" "- Detroit Tigers\n"
...@@ -20,7 +20,7 @@ namespace Test { ...@@ -20,7 +20,7 @@ namespace Test {
"- Chicago Cubs\n" "- Chicago Cubs\n"
"- Atlanta Braves"; "- Atlanta Braves";
const char *ex2_4 = const char *ex2_4 =
"-\n" "-\n"
" name: Mark McGwire\n" " name: Mark McGwire\n"
" hr: 65\n" " hr: 65\n"
...@@ -30,19 +30,19 @@ namespace Test { ...@@ -30,19 +30,19 @@ namespace Test {
" hr: 63\n" " hr: 63\n"
" avg: 0.288"; " avg: 0.288";
const char *ex2_5 = const char *ex2_5 =
"- [name , hr, avg ]\n" "- [name , hr, avg ]\n"
"- [Mark McGwire, 65, 0.278]\n" "- [Mark McGwire, 65, 0.278]\n"
"- [Sammy Sosa , 63, 0.288]"; "- [Sammy Sosa , 63, 0.288]";
const char *ex2_6 = const char *ex2_6 =
"Mark McGwire: {hr: 65, avg: 0.278}\n" "Mark McGwire: {hr: 65, avg: 0.278}\n"
"Sammy Sosa: {\n" "Sammy Sosa: {\n"
" hr: 63,\n" " hr: 63,\n"
" avg: 0.288\n" " avg: 0.288\n"
" }"; " }";
const char *ex2_7 = const char *ex2_7 =
"# Ranking of 1998 home runs\n" "# Ranking of 1998 home runs\n"
"---\n" "---\n"
"- Mark McGwire\n" "- Mark McGwire\n"
...@@ -54,7 +54,7 @@ namespace Test { ...@@ -54,7 +54,7 @@ namespace Test {
"- Chicago Cubs\n" "- Chicago Cubs\n"
"- St Louis Cardinals"; "- St Louis Cardinals";
const char *ex2_8 = const char *ex2_8 =
"---\n" "---\n"
"time: 20:03:20\n" "time: 20:03:20\n"
"player: Sammy Sosa\n" "player: Sammy Sosa\n"
...@@ -66,7 +66,7 @@ namespace Test { ...@@ -66,7 +66,7 @@ namespace Test {
"action: grand slam\n" "action: grand slam\n"
"..."; "...";
const char *ex2_9 = const char *ex2_9 =
"---\n" "---\n"
"hr: # 1998 hr ranking\n" "hr: # 1998 hr ranking\n"
" - Mark McGwire\n" " - Mark McGwire\n"
...@@ -76,7 +76,7 @@ namespace Test { ...@@ -76,7 +76,7 @@ namespace Test {
" - Sammy Sosa\n" " - Sammy Sosa\n"
" - Ken Griffey"; " - Ken Griffey";
const char *ex2_10 = const char *ex2_10 =
"---\n" "---\n"
"hr:\n" "hr:\n"
" - Mark McGwire\n" " - Mark McGwire\n"
...@@ -86,7 +86,7 @@ namespace Test { ...@@ -86,7 +86,7 @@ namespace Test {
" - *SS # Subsequent occurrence\n" " - *SS # Subsequent occurrence\n"
" - Ken Griffey"; " - Ken Griffey";
const char *ex2_11 = const char *ex2_11 =
"? - Detroit Tigers\n" "? - Detroit Tigers\n"
" - Chicago cubs\n" " - Chicago cubs\n"
":\n" ":\n"
...@@ -97,7 +97,7 @@ namespace Test { ...@@ -97,7 +97,7 @@ namespace Test {
": [ 2001-07-02, 2001-08-12,\n" ": [ 2001-07-02, 2001-08-12,\n"
" 2001-08-14 ]"; " 2001-08-14 ]";
const char *ex2_12 = const char *ex2_12 =
"---\n" "---\n"
"# Products purchased\n" "# Products purchased\n"
"- item : Super Hoop\n" "- item : Super Hoop\n"
...@@ -107,19 +107,19 @@ namespace Test { ...@@ -107,19 +107,19 @@ namespace Test {
"- item : Big Shoes\n" "- item : Big Shoes\n"
" quantity: 1"; " quantity: 1";
const char *ex2_13 = const char *ex2_13 =
"# ASCII Art\n" "# ASCII Art\n"
"--- |\n" "--- |\n"
" \\//||\\/||\n" " \\//||\\/||\n"
" // || ||__"; " // || ||__";
const char *ex2_14 = const char *ex2_14 =
"--- >\n" "--- >\n"
" Mark McGwire's\n" " Mark McGwire's\n"
" year was crippled\n" " year was crippled\n"
" by a knee injury."; " by a knee injury.";
const char *ex2_15 = const char *ex2_15 =
">\n" ">\n"
" Sammy Sosa completed another\n" " Sammy Sosa completed another\n"
" fine season with great stats.\n" " fine season with great stats.\n"
...@@ -129,7 +129,7 @@ namespace Test { ...@@ -129,7 +129,7 @@ namespace Test {
" \n" " \n"
" What a year!"; " What a year!";
const char *ex2_16 = const char *ex2_16 =
"name: Mark McGwire\n" "name: Mark McGwire\n"
"accomplishment: >\n" "accomplishment: >\n"
" Mark set a major league\n" " Mark set a major league\n"
...@@ -138,7 +138,7 @@ namespace Test { ...@@ -138,7 +138,7 @@ namespace Test {
" 65 Home Runs\n" " 65 Home Runs\n"
" 0.278 Batting Average\n"; " 0.278 Batting Average\n";
const char *ex2_17 = const char *ex2_17 =
"unicode: \"Sosa did fine.\\u263A\"\n" "unicode: \"Sosa did fine.\\u263A\"\n"
"control: \"\\b1998\\t1999\\t2000\\n\"\n" "control: \"\\b1998\\t1999\\t2000\\n\"\n"
"hex esc: \"\\x0d\\x0a is \\r\\n\"\n" "hex esc: \"\\x0d\\x0a is \\r\\n\"\n"
...@@ -147,7 +147,7 @@ namespace Test { ...@@ -147,7 +147,7 @@ namespace Test {
"quoted: ' # Not a ''comment''.'\n" "quoted: ' # Not a ''comment''.'\n"
"tie-fighter: '|\\-*-/|'"; "tie-fighter: '|\\-*-/|'";
const char *ex2_18 = const char *ex2_18 =
"plain:\n" "plain:\n"
" This unquoted scalar\n" " This unquoted scalar\n"
" spans many lines.\n" " spans many lines.\n"
...@@ -155,9 +155,9 @@ namespace Test { ...@@ -155,9 +155,9 @@ namespace Test {
"quoted: \"So does this\n" "quoted: \"So does this\n"
" quoted scalar.\\n\""; " quoted scalar.\\n\"";
// TODO: 2.19 - 2.22 schema tags // TODO: 2.19 - 2.22 schema tags
const char *ex2_23 = const char *ex2_23 =
"---\n" "---\n"
"not-date: !!str 2002-04-28\n" "not-date: !!str 2002-04-28\n"
"\n" "\n"
...@@ -172,7 +172,7 @@ namespace Test { ...@@ -172,7 +172,7 @@ namespace Test {
" above may be different for\n" " above may be different for\n"
" different documents."; " different documents.";
const char *ex2_24 = const char *ex2_24 =
"%TAG ! tag:clarkevans.com,2002:\n" "%TAG ! tag:clarkevans.com,2002:\n"
"--- !shape\n" "--- !shape\n"
" # Use the ! handle for presenting\n" " # Use the ! handle for presenting\n"
...@@ -188,7 +188,7 @@ namespace Test { ...@@ -188,7 +188,7 @@ namespace Test {
" color: 0xFFEEBB\n" " color: 0xFFEEBB\n"
" text: Pretty vector drawing."; " text: Pretty vector drawing.";
const char *ex2_25 = const char *ex2_25 =
"# Sets are represented as a\n" "# Sets are represented as a\n"
"# Mapping where each key is\n" "# Mapping where each key is\n"
"# associated with a null value\n" "# associated with a null value\n"
...@@ -197,7 +197,7 @@ namespace Test { ...@@ -197,7 +197,7 @@ namespace Test {
"? Sammy Sosa\n" "? Sammy Sosa\n"
"? Ken Griffey"; "? Ken Griffey";
const char *ex2_26 = const char *ex2_26 =
"# Ordered maps are represented as\n" "# Ordered maps are represented as\n"
"# A sequence of mappings, with\n" "# A sequence of mappings, with\n"
"# each mapping having one key\n" "# each mapping having one key\n"
...@@ -206,7 +206,7 @@ namespace Test { ...@@ -206,7 +206,7 @@ namespace Test {
"- Sammy Sosa: 63\n" "- Sammy Sosa: 63\n"
"- Ken Griffey: 58"; "- Ken Griffey: 58";
const char *ex2_27 = const char *ex2_27 =
"--- !<tag:clarkevans.com,2002:invoice>\n" "--- !<tag:clarkevans.com,2002:invoice>\n"
"invoice: 34843\n" "invoice: 34843\n"
"date : 2001-01-23\n" "date : 2001-01-23\n"
...@@ -237,7 +237,7 @@ namespace Test { ...@@ -237,7 +237,7 @@ namespace Test {
" Backup contact is Nancy\n" " Backup contact is Nancy\n"
" Billsmer @ 338-4338."; " Billsmer @ 338-4338.";
const char *ex2_28 = const char *ex2_28 =
"---\n" "---\n"
"Time: 2001-11-23 15:01:42 -5\n" "Time: 2001-11-23 15:01:42 -5\n"
"User: ed\n" "User: ed\n"
...@@ -265,9 +265,9 @@ namespace Test { ...@@ -265,9 +265,9 @@ namespace Test {
" code: |-\n" " code: |-\n"
" foo = bar"; " foo = bar";
// TODO: 5.1 - 5.2 BOM // TODO: 5.1 - 5.2 BOM
const char *ex5_3 = const char *ex5_3 =
"sequence:\n" "sequence:\n"
"- one\n" "- one\n"
"- two\n" "- two\n"
...@@ -276,18 +276,17 @@ namespace Test { ...@@ -276,18 +276,17 @@ namespace Test {
" : blue\n" " : blue\n"
" sea : green"; " sea : green";
const char *ex5_4 = const char *ex5_4 =
"sequence: [ one, two, ]\n" "sequence: [ one, two, ]\n"
"mapping: { sky: blue, sea: green }"; "mapping: { sky: blue, sea: green }";
const char *ex5_5 = const char *ex5_5 = "# Comment only.";
"# Comment only.";
const char *ex5_6 = const char *ex5_6 =
"anchored: !local &anchor value\n" "anchored: !local &anchor value\n"
"alias: *anchor"; "alias: *anchor";
const char *ex5_7 = const char *ex5_7 =
"literal: |\n" "literal: |\n"
" some\n" " some\n"
" text\n" " text\n"
...@@ -295,19 +294,19 @@ namespace Test { ...@@ -295,19 +294,19 @@ namespace Test {
" some\n" " some\n"
" text\n"; " text\n";
const char *ex5_8 = const char *ex5_8 =
"single: 'text'\n" "single: 'text'\n"
"double: \"text\""; "double: \"text\"";
// TODO: 5.9 directive // TODO: 5.9 directive
// TODO: 5.10 reserved indicator // TODO: 5.10 reserved indicator
const char *ex5_11 = const char *ex5_11 =
"|\n" "|\n"
" Line break (no glyph)\n" " Line break (no glyph)\n"
" Line break (glyphed)\n"; " Line break (glyphed)\n";
const char *ex5_12 = const char *ex5_12 =
"# Tabs and spaces\n" "# Tabs and spaces\n"
"quoted: \"Quoted\t\"\n" "quoted: \"Quoted\t\"\n"
"block: |\n" "block: |\n"
...@@ -315,19 +314,19 @@ namespace Test { ...@@ -315,19 +314,19 @@ namespace Test {
" \tprintf(\"Hello, world!\\n\");\n" " \tprintf(\"Hello, world!\\n\");\n"
" }"; " }";
const char *ex5_13 = const char *ex5_13 =
"\"Fun with \\\\\n" "\"Fun with \\\\\n"
"\\\" \\a \\b \\e \\f \\\n" "\\\" \\a \\b \\e \\f \\\n"
"\\n \\r \\t \\v \\0 \\\n" "\\n \\r \\t \\v \\0 \\\n"
"\\ \\_ \\N \\L \\P \\\n" "\\ \\_ \\N \\L \\P \\\n"
"\\x41 \\u0041 \\U00000041\""; "\\x41 \\u0041 \\U00000041\"";
const char *ex5_14 = const char *ex5_14 =
"Bad escapes:\n" "Bad escapes:\n"
" \"\\c\n" " \"\\c\n"
" \\xq-\""; " \\xq-\"";
const char *ex6_1 = const char *ex6_1 =
" # Leading comment line spaces are\n" " # Leading comment line spaces are\n"
" # neither content nor indentation.\n" " # neither content nor indentation.\n"
" \n" " \n"
...@@ -341,18 +340,18 @@ namespace Test { ...@@ -341,18 +340,18 @@ namespace Test {
" \tStill by two # content nor\n" " \tStill by two # content nor\n"
" ] # indentation."; " ] # indentation.";
const char *ex6_2 = const char *ex6_2 =
"? a\n" "? a\n"
": -\tb\n" ": -\tb\n"
" - -\tc\n" " - -\tc\n"
" - d"; " - d";
const char *ex6_3 = const char *ex6_3 =
"- foo:\t bar\n" "- foo:\t bar\n"
"- - baz\n" "- - baz\n"
" -\tbaz"; " -\tbaz";
const char *ex6_4 = const char *ex6_4 =
"plain: text\n" "plain: text\n"
" lines\n" " lines\n"
"quoted: \"text\n" "quoted: \"text\n"
...@@ -361,7 +360,7 @@ namespace Test { ...@@ -361,7 +360,7 @@ namespace Test {
" text\n" " text\n"
" \tlines\n"; " \tlines\n";
const char *ex6_5 = const char *ex6_5 =
"Folding:\n" "Folding:\n"
" \"Empty line\n" " \"Empty line\n"
" \t\n" " \t\n"
...@@ -370,7 +369,7 @@ namespace Test { ...@@ -370,7 +369,7 @@ namespace Test {
" Clipped empty lines\n" " Clipped empty lines\n"
" "; " ";
const char *ex6_6 = const char *ex6_6 =
">-\n" ">-\n"
" trimmed\n" " trimmed\n"
" \n" " \n"
...@@ -379,7 +378,7 @@ namespace Test { ...@@ -379,7 +378,7 @@ namespace Test {
" as\n" " as\n"
" space"; " space";
const char *ex6_7 = const char *ex6_7 =
">\n" ">\n"
" foo \n" " foo \n"
" \n" " \n"
...@@ -387,7 +386,7 @@ namespace Test { ...@@ -387,7 +386,7 @@ namespace Test {
"\n" "\n"
" baz\n"; " baz\n";
const char *ex6_8 = const char *ex6_8 =
"\"\n" "\"\n"
" foo \n" " foo \n"
" \n" " \n"
...@@ -396,22 +395,22 @@ namespace Test { ...@@ -396,22 +395,22 @@ namespace Test {
" baz\n" " baz\n"
"\""; "\"";
const char *ex6_9 = const char *ex6_9 =
"key: # Comment\n" "key: # Comment\n"
" value"; " value";
const char *ex6_10 = const char *ex6_10 =
" # Comment\n" " # Comment\n"
" \n" " \n"
"\n"; "\n";
const char *ex6_11 = const char *ex6_11 =
"key: # Comment\n" "key: # Comment\n"
" # lines\n" " # lines\n"
" value\n" " value\n"
"\n"; "\n";
const char *ex6_12 = const char *ex6_12 =
"{ first: Sammy, last: Sosa }:\n" "{ first: Sammy, last: Sosa }:\n"
"# Statistics:\n" "# Statistics:\n"
" hr: # Home runs\n" " hr: # Home runs\n"
...@@ -419,33 +418,33 @@ namespace Test { ...@@ -419,33 +418,33 @@ namespace Test {
" avg: # Average\n" " avg: # Average\n"
" 0.278"; " 0.278";
const char *ex6_13 = const char *ex6_13 =
"%FOO bar baz # Should be ignored\n" "%FOO bar baz # Should be ignored\n"
" # with a warning.\n" " # with a warning.\n"
"--- \"foo\""; "--- \"foo\"";
const char *ex6_14 = const char *ex6_14 =
"%YAML 1.3 # Attempt parsing\n" "%YAML 1.3 # Attempt parsing\n"
" # with a warning\n" " # with a warning\n"
"---\n" "---\n"
"\"foo\""; "\"foo\"";
const char *ex6_15 = const char *ex6_15 =
"%YAML 1.2\n" "%YAML 1.2\n"
"%YAML 1.1\n" "%YAML 1.1\n"
"foo"; "foo";
const char *ex6_16 = const char *ex6_16 =
"%TAG !yaml! tag:yaml.org,2002:\n" "%TAG !yaml! tag:yaml.org,2002:\n"
"---\n" "---\n"
"!yaml!str \"foo\""; "!yaml!str \"foo\"";
const char *ex6_17 = const char *ex6_17 =
"%TAG ! !foo\n" "%TAG ! !foo\n"
"%TAG ! !foo\n" "%TAG ! !foo\n"
"bar"; "bar";
const char *ex6_18 = const char *ex6_18 =
"# Private\n" "# Private\n"
"!foo \"bar\"\n" "!foo \"bar\"\n"
"...\n" "...\n"
...@@ -454,17 +453,17 @@ namespace Test { ...@@ -454,17 +453,17 @@ namespace Test {
"---\n" "---\n"
"!foo \"bar\""; "!foo \"bar\"";
const char *ex6_19 = const char *ex6_19 =
"%TAG !! tag:example.com,2000:app/\n" "%TAG !! tag:example.com,2000:app/\n"
"---\n" "---\n"
"!!int 1 - 3 # Interval, not integer"; "!!int 1 - 3 # Interval, not integer";
const char *ex6_20 = const char *ex6_20 =
"%TAG !e! tag:example.com,2000:app/\n" "%TAG !e! tag:example.com,2000:app/\n"
"---\n" "---\n"
"!e!foo \"bar\""; "!e!foo \"bar\"";
const char *ex6_21 = const char *ex6_21 =
"%TAG !m! !my-\n" "%TAG !m! !my-\n"
"--- # Bulb here\n" "--- # Bulb here\n"
"!m!light fluorescent\n" "!m!light fluorescent\n"
...@@ -473,102 +472,101 @@ namespace Test { ...@@ -473,102 +472,101 @@ namespace Test {
"--- # Color here\n" "--- # Color here\n"
"!m!light green"; "!m!light green";
const char *ex6_22 = const char *ex6_22 =
"%TAG !e! tag:example.com,2000:app/\n" "%TAG !e! tag:example.com,2000:app/\n"
"---\n" "---\n"
"- !e!foo \"bar\""; "- !e!foo \"bar\"";
const char *ex6_23 = const char *ex6_23 =
"!!str &a1 \"foo\":\n" "!!str &a1 \"foo\":\n"
" !!str bar\n" " !!str bar\n"
"&a2 baz : *a1"; "&a2 baz : *a1";
const char *ex6_24 = const char *ex6_24 =
"!<tag:yaml.org,2002:str> foo :\n" "!<tag:yaml.org,2002:str> foo :\n"
" !<!bar> baz"; " !<!bar> baz";
const char *ex6_25 = const char *ex6_25 =
"- !<!> foo\n" "- !<!> foo\n"
"- !<$:?> bar\n"; "- !<$:?> bar\n";
const char *ex6_26 = const char *ex6_26 =
"%TAG !e! tag:example.com,2000:app/\n" "%TAG !e! tag:example.com,2000:app/\n"
"---\n" "---\n"
"- !local foo\n" "- !local foo\n"
"- !!str bar\n" "- !!str bar\n"
"- !e!tag%21 baz\n"; "- !e!tag%21 baz\n";
const char *ex6_27a = const char *ex6_27a =
"%TAG !e! tag:example,2000:app/\n" "%TAG !e! tag:example,2000:app/\n"
"---\n" "---\n"
"- !e! foo"; "- !e! foo";
const char *ex6_27b = const char *ex6_27b =
"%TAG !e! tag:example,2000:app/\n" "%TAG !e! tag:example,2000:app/\n"
"---\n" "---\n"
"- !h!bar baz"; "- !h!bar baz";
const char *ex6_28 = const char *ex6_28 =
"# Assuming conventional resolution:\n" "# Assuming conventional resolution:\n"
"- \"12\"\n" "- \"12\"\n"
"- 12\n" "- 12\n"
"- ! 12"; "- ! 12";
const char *ex6_29 = const char *ex6_29 =
"First occurrence: &anchor Value\n" "First occurrence: &anchor Value\n"
"Second occurrence: *anchor"; "Second occurrence: *anchor";
const char *ex7_1 = const char *ex7_1 =
"First occurrence: &anchor Foo\n" "First occurrence: &anchor Foo\n"
"Second occurrence: *anchor\n" "Second occurrence: *anchor\n"
"Override anchor: &anchor Bar\n" "Override anchor: &anchor Bar\n"
"Reuse anchor: *anchor"; "Reuse anchor: *anchor";
const char *ex7_2 = const char *ex7_2 =
"{\n" "{\n"
" foo : !!str,\n" " foo : !!str,\n"
" !!str : bar,\n" " !!str : bar,\n"
"}"; "}";
const char *ex7_3 = const char *ex7_3 =
"{\n" "{\n"
" ? foo :,\n" " ? foo :,\n"
" : bar,\n" " : bar,\n"
"}\n"; "}\n";
const char *ex7_4 = const char *ex7_4 =
"\"implicit block key\" : [\n" "\"implicit block key\" : [\n"
" \"implicit flow key\" : value,\n" " \"implicit flow key\" : value,\n"
" ]"; " ]";
const char *ex7_5 = const char *ex7_5 =
"\"folded \n" "\"folded \n"
"to a space,\t\n" "to a space,\t\n"
" \n" " \n"
"to a line feed, or \t\\\n" "to a line feed, or \t\\\n"
" \\ \tnon-content\""; " \\ \tnon-content\"";
const char *ex7_6 = const char *ex7_6 =
"\" 1st non-empty\n" "\" 1st non-empty\n"
"\n" "\n"
" 2nd non-empty \n" " 2nd non-empty \n"
"\t3rd non-empty \""; "\t3rd non-empty \"";
const char *ex7_7 = const char *ex7_7 = " 'here''s to \"quotes\"'";
" 'here''s to \"quotes\"'";
const char *ex7_8 = const char *ex7_8 =
"'implicit block key' : [\n" "'implicit block key' : [\n"
" 'implicit flow key' : value,\n" " 'implicit flow key' : value,\n"
" ]"; " ]";
const char *ex7_9 = const char *ex7_9 =
"' 1st non-empty\n" "' 1st non-empty\n"
"\n" "\n"
" 2nd non-empty \n" " 2nd non-empty \n"
"\t3rd non-empty '"; "\t3rd non-empty '";
const char *ex7_10 = const char *ex7_10 =
"# Outside flow collection:\n" "# Outside flow collection:\n"
"- ::vector\n" "- ::vector\n"
"- \": - ()\"\n" "- \": - ()\"\n"
...@@ -582,22 +580,22 @@ namespace Test { ...@@ -582,22 +580,22 @@ namespace Test {
" -123,\n" " -123,\n"
" http://example.com/foo#bar ]"; " http://example.com/foo#bar ]";
const char *ex7_11 = const char *ex7_11 =
"implicit block key : [\n" "implicit block key : [\n"
" implicit flow key : value,\n" " implicit flow key : value,\n"
" ]"; " ]";
const char *ex7_12 = const char *ex7_12 =
"1st non-empty\n" "1st non-empty\n"
"\n" "\n"
" 2nd non-empty \n" " 2nd non-empty \n"
"\t3rd non-empty"; "\t3rd non-empty";
const char *ex7_13 = const char *ex7_13 =
"- [ one, two, ]\n" "- [ one, two, ]\n"
"- [three ,four]"; "- [three ,four]";
const char *ex7_14 = const char *ex7_14 =
"[\n" "[\n"
"\"double\n" "\"double\n"
" quoted\", 'single\n" " quoted\", 'single\n"
...@@ -607,18 +605,18 @@ namespace Test { ...@@ -607,18 +605,18 @@ namespace Test {
"single: pair,\n" "single: pair,\n"
"]"; "]";
const char *ex7_15 = const char *ex7_15 =
"- { one : two , three: four , }\n" "- { one : two , three: four , }\n"
"- {five: six,seven : eight}"; "- {five: six,seven : eight}";
const char *ex7_16 = const char *ex7_16 =
"{\n" "{\n"
"? explicit: entry,\n" "? explicit: entry,\n"
"implicit: entry,\n" "implicit: entry,\n"
"?\n" "?\n"
"}"; "}";
const char *ex7_17 = const char *ex7_17 =
"{\n" "{\n"
"unquoted : \"separate\",\n" "unquoted : \"separate\",\n"
"http://foo.com,\n" "http://foo.com,\n"
...@@ -626,48 +624,49 @@ namespace Test { ...@@ -626,48 +624,49 @@ namespace Test {
": omitted key,\n" ": omitted key,\n"
"}"; "}";
const char *ex7_18 = const char *ex7_18 =
"{\n" "{\n"
"\"adjacent\":value,\n" "\"adjacent\":value,\n"
"\"readable\":value,\n" "\"readable\":value,\n"
"\"empty\":\n" "\"empty\":\n"
"}"; "}";
const char *ex7_19 = const char *ex7_19 =
"[\n" "[\n"
"foo: bar\n" "foo: bar\n"
"]"; "]";
const char *ex7_20 = const char *ex7_20 =
"[\n" "[\n"
"? foo\n" "? foo\n"
" bar : baz\n" " bar : baz\n"
"]"; "]";
const char *ex7_21 = const char *ex7_21 =
"- [ YAML : separate ]\n" "- [ YAML : separate ]\n"
"- [ : empty key entry ]\n" "- [ : empty key entry ]\n"
"- [ {JSON: like}:adjacent ]"; "- [ {JSON: like}:adjacent ]";
const char *ex7_22 = const char *ex7_22 =
"[ foo\n" "[ foo\n"
" bar: invalid,"; // Note: we don't check (on purpose) the >1K chars for an implicit key " bar: invalid,"; // Note: we don't check (on purpose) the >1K chars for an
// implicit key
const char *ex7_23 = const char *ex7_23 =
"- [ a, b ]\n" "- [ a, b ]\n"
"- { a: b }\n" "- { a: b }\n"
"- \"a\"\n" "- \"a\"\n"
"- 'b'\n" "- 'b'\n"
"- c"; "- c";
const char *ex7_24 = const char *ex7_24 =
"- !!str \"a\"\n" "- !!str \"a\"\n"
"- 'b'\n" "- 'b'\n"
"- &anchor \"c\"\n" "- &anchor \"c\"\n"
"- *anchor\n" "- *anchor\n"
"- !!str"; "- !!str";
const char *ex8_1 = const char *ex8_1 =
"- | # Empty header\n" "- | # Empty header\n"
" literal\n" " literal\n"
"- >1 # Indentation indicator\n" "- >1 # Indentation indicator\n"
...@@ -678,7 +677,7 @@ namespace Test { ...@@ -678,7 +677,7 @@ namespace Test {
"- >1- # Both indicators\n" "- >1- # Both indicators\n"
" strip\n"; " strip\n";
const char *ex8_2 = const char *ex8_2 =
"- |\n" "- |\n"
" detected\n" " detected\n"
"- >\n" "- >\n"
...@@ -691,21 +690,21 @@ namespace Test { ...@@ -691,21 +690,21 @@ namespace Test {
" \t\n" " \t\n"
" detected\n"; " detected\n";
const char *ex8_3a = const char *ex8_3a =
"- |\n" "- |\n"
" \n" " \n"
" text"; " text";
const char *ex8_3b = const char *ex8_3b =
"- >\n" "- >\n"
" text\n" " text\n"
" text"; " text";
const char *ex8_3c = const char *ex8_3c =
"- |2\n" "- |2\n"
" text"; " text";
const char *ex8_4 = const char *ex8_4 =
"strip: |-\n" "strip: |-\n"
" text\n" " text\n"
"clip: |\n" "clip: |\n"
...@@ -713,7 +712,7 @@ namespace Test { ...@@ -713,7 +712,7 @@ namespace Test {
"keep: |+\n" "keep: |+\n"
" text\n"; " text\n";
const char *ex8_5 = const char *ex8_5 =
" # Strip\n" " # Strip\n"
" # Comments:\n" " # Comments:\n"
"strip: |-\n" "strip: |-\n"
...@@ -734,7 +733,7 @@ namespace Test { ...@@ -734,7 +733,7 @@ namespace Test {
" # Trail\n" " # Trail\n"
" # Comments\n"; " # Comments\n";
const char *ex8_6 = const char *ex8_6 =
"strip: >-\n" "strip: >-\n"
"\n" "\n"
"clip: >\n" "clip: >\n"
...@@ -742,13 +741,13 @@ namespace Test { ...@@ -742,13 +741,13 @@ namespace Test {
"keep: |+\n" "keep: |+\n"
"\n"; "\n";
const char *ex8_7 = const char *ex8_7 =
"|\n" "|\n"
" literal\n" " literal\n"
" \ttext\n" " \ttext\n"
"\n"; "\n";
const char *ex8_8 = const char *ex8_8 =
"|\n" "|\n"
" \n" " \n"
" \n" " \n"
...@@ -759,13 +758,13 @@ namespace Test { ...@@ -759,13 +758,13 @@ namespace Test {
"\n" "\n"
" # Comment\n"; " # Comment\n";
const char *ex8_9 = const char *ex8_9 =
">\n" ">\n"
" folded\n" " folded\n"
" text\n" " text\n"
"\n"; "\n";
const char *ex8_10 = const char *ex8_10 =
">\n" ">\n"
"\n" "\n"
" folded\n" " folded\n"
...@@ -783,16 +782,16 @@ namespace Test { ...@@ -783,16 +782,16 @@ namespace Test {
"\n" "\n"
"# Comment\n"; "# Comment\n";
const char *ex8_11 = ex8_10; const char *ex8_11 = ex8_10;
const char *ex8_12 = ex8_10; const char *ex8_12 = ex8_10;
const char *ex8_13 = ex8_10; const char *ex8_13 = ex8_10;
const char *ex8_14 = const char *ex8_14 =
"block sequence:\n" "block sequence:\n"
" - one\n" " - one\n"
" - two : three\n"; " - two : three\n";
const char *ex8_15 = const char *ex8_15 =
"- # Empty\n" "- # Empty\n"
"- |\n" "- |\n"
" block node\n" " block node\n"
...@@ -800,29 +799,29 @@ namespace Test { ...@@ -800,29 +799,29 @@ namespace Test {
" - two # sequence\n" " - two # sequence\n"
"- one: two # Compact mapping\n"; "- one: two # Compact mapping\n";
const char *ex8_16 = const char *ex8_16 =
"block mapping:\n" "block mapping:\n"
" key: value\n"; " key: value\n";
const char *ex8_17 = const char *ex8_17 =
"? explicit key # Empty value\n" "? explicit key # Empty value\n"
"? |\n" "? |\n"
" block key\n" " block key\n"
": - one # Explicit compact\n" ": - one # Explicit compact\n"
" - two # block value\n"; " - two # block value\n";
const char *ex8_18 = const char *ex8_18 =
"plain key: in-line value\n" "plain key: in-line value\n"
": # Both empty\n" ": # Both empty\n"
"\"quoted key\":\n" "\"quoted key\":\n"
"- entry\n"; "- entry\n";
const char *ex8_19 = const char *ex8_19 =
"- sun: yellow\n" "- sun: yellow\n"
"- ? earth: blue\n" "- ? earth: blue\n"
" : moon: white\n"; " : moon: white\n";
const char *ex8_20 = const char *ex8_20 =
"-\n" "-\n"
" \"flow in block\"\n" " \"flow in block\"\n"
"- >\n" "- >\n"
...@@ -830,7 +829,7 @@ namespace Test { ...@@ -830,7 +829,7 @@ namespace Test {
"- !!map # Block collection\n" "- !!map # Block collection\n"
" foo : bar\n"; " foo : bar\n";
const char *ex8_21 = const char *ex8_21 =
"literal: |2\n" "literal: |2\n"
" value\n" " value\n"
"folded:\n" "folded:\n"
...@@ -838,13 +837,12 @@ namespace Test { ...@@ -838,13 +837,12 @@ namespace Test {
" >1\n" " >1\n"
" value\n"; " value\n";
const char *ex8_22 = const char *ex8_22 =
"sequence: !!seq\n" "sequence: !!seq\n"
"- entry\n" "- entry\n"
"- !!seq\n" "- !!seq\n"
" - nested\n" " - nested\n"
"mapping: !!map\n" "mapping: !!map\n"
" foo: bar\n"; " foo: bar\n";
}
} }
}
...@@ -2,148 +2,223 @@ ...@@ -2,148 +2,223 @@
#include "yaml-cpp/yaml.h" #include "yaml-cpp/yaml.h"
#include <iostream> #include <iostream>
namespace Test namespace Test {
{ namespace {
namespace { void RunSpecTest(TEST (*test)(), const std::string& index,
void RunSpecTest(TEST (*test)(), const std::string& index, const std::string& name, int& passed, int& total) { const std::string& name, int& passed, int& total) {
TEST ret; TEST ret;
try { try {
ret = test(); ret = test();
} catch(const YAML::Exception& e) { }
catch (const YAML::Exception& e) {
ret.ok = false; ret.ok = false;
ret.error = std::string(" Exception caught: ") + e.what(); ret.error = std::string(" Exception caught: ") + e.what();
} }
if(!ret.ok) { if (!ret.ok) {
std::cout << "Spec test " << index << " failed: " << name << "\n"; std::cout << "Spec test " << index << " failed: " << name << "\n";
std::cout << ret.error << "\n"; std::cout << ret.error << "\n";
} }
if(ret.ok) if (ret.ok)
passed++; passed++;
total++; total++;
} }
} }
bool RunSpecTests() bool RunSpecTests() {
{
int passed = 0; int passed = 0;
int total = 0; int total = 0;
RunSpecTest(&Spec::SeqScalars, "2.1", "Sequence of Scalars", passed, total); RunSpecTest(&Spec::SeqScalars, "2.1", "Sequence of Scalars", passed, total);
RunSpecTest(&Spec::MappingScalarsToScalars, "2.2", "Mapping Scalars to Scalars", passed, total); RunSpecTest(&Spec::MappingScalarsToScalars, "2.2",
RunSpecTest(&Spec::MappingScalarsToSequences, "2.3", "Mapping Scalars to Sequences", passed, total); "Mapping Scalars to Scalars", passed, total);
RunSpecTest(&Spec::SequenceOfMappings, "2.4", "Sequence of Mappings", passed, total); RunSpecTest(&Spec::MappingScalarsToSequences, "2.3",
RunSpecTest(&Spec::SequenceOfSequences, "2.5", "Sequence of Sequences", passed, total); "Mapping Scalars to Sequences", passed, total);
RunSpecTest(&Spec::MappingOfMappings, "2.6", "Mapping of Mappings", passed, total); RunSpecTest(&Spec::SequenceOfMappings, "2.4", "Sequence of Mappings", passed,
RunSpecTest(&Spec::TwoDocumentsInAStream, "2.7", "Two Documents in a Stream", passed, total); total);
RunSpecTest(&Spec::PlayByPlayFeed, "2.8", "Play by Play Feed from a Game", passed, total); RunSpecTest(&Spec::SequenceOfSequences, "2.5", "Sequence of Sequences",
RunSpecTest(&Spec::SingleDocumentWithTwoComments, "2.9", "Single Document with Two Comments", passed, total); passed, total);
RunSpecTest(&Spec::SimpleAnchor, "2.10", "Node for \"Sammy Sosa\" appears twice in this document", passed, total); RunSpecTest(&Spec::MappingOfMappings, "2.6", "Mapping of Mappings", passed,
RunSpecTest(&Spec::MappingBetweenSequences, "2.11", "Mapping between Sequences", passed, total); total);
RunSpecTest(&Spec::CompactNestedMapping, "2.12", "Compact Nested Mapping", passed, total); RunSpecTest(&Spec::TwoDocumentsInAStream, "2.7", "Two Documents in a Stream",
RunSpecTest(&Spec::InLiteralsNewlinesArePreserved, "2.13", "In literals, newlines are preserved", passed, total); passed, total);
RunSpecTest(&Spec::InFoldedScalarsNewlinesBecomeSpaces, "2.14", "In folded scalars, newlines become spaces", passed, total); RunSpecTest(&Spec::PlayByPlayFeed, "2.8", "Play by Play Feed from a Game",
RunSpecTest(&Spec::FoldedNewlinesArePreservedForMoreIndentedAndBlankLines, "2.15", "Folded newlines are preserved for \"more indented\" and blank lines", passed, total); passed, total);
RunSpecTest(&Spec::IndentationDeterminesScope, "2.16", "Indentation determines scope", 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::QuotedScalars, "2.17", "Quoted scalars", passed, total);
RunSpecTest(&Spec::MultiLineFlowScalars, "2.18", "Multi-line flow 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::VariousExplicitTags, "2.23", "Various Explicit Tags",
passed, total);
RunSpecTest(&Spec::GlobalTags, "2.24", "Global Tags", passed, total); RunSpecTest(&Spec::GlobalTags, "2.24", "Global Tags", passed, total);
RunSpecTest(&Spec::UnorderedSets, "2.25", "Unordered Sets", passed, total); RunSpecTest(&Spec::UnorderedSets, "2.25", "Unordered Sets", passed, total);
RunSpecTest(&Spec::OrderedMappings, "2.26", "Ordered Mappings", passed, total); RunSpecTest(&Spec::OrderedMappings, "2.26", "Ordered Mappings", passed,
total);
RunSpecTest(&Spec::Invoice, "2.27", "Invoice", passed, total); RunSpecTest(&Spec::Invoice, "2.27", "Invoice", passed, total);
RunSpecTest(&Spec::LogFile, "2.28", "Log File", passed, total); RunSpecTest(&Spec::LogFile, "2.28", "Log File", passed, total);
RunSpecTest(&Spec::BlockStructureIndicators, "5.3", "Block Structure Indicators", passed, total); RunSpecTest(&Spec::BlockStructureIndicators, "5.3",
RunSpecTest(&Spec::FlowStructureIndicators, "5.4", "Flow Structure Indicators", passed, total); "Block Structure Indicators", passed, total);
RunSpecTest(&Spec::NodePropertyIndicators, "5.6", "Node Property Indicators", passed, total); RunSpecTest(&Spec::FlowStructureIndicators, "5.4",
RunSpecTest(&Spec::BlockScalarIndicators, "5.7", "Block Scalar Indicators", passed, total); "Flow Structure Indicators", passed, total);
RunSpecTest(&Spec::QuotedScalarIndicators, "5.8", "Quoted Scalar Indicators", passed, total); RunSpecTest(&Spec::NodePropertyIndicators, "5.6", "Node Property Indicators",
RunSpecTest(&Spec::LineBreakCharacters, "5.11", "Line Break Characters", passed, total); 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::TabsAndSpaces, "5.12", "Tabs and Spaces", passed, total);
RunSpecTest(&Spec::EscapedCharacters, "5.13", "Escaped Characters", passed, total); RunSpecTest(&Spec::EscapedCharacters, "5.13", "Escaped Characters", passed,
RunSpecTest(&Spec::InvalidEscapedCharacters, "5.14", "Invalid Escaped Characters", passed, total); total);
RunSpecTest(&Spec::InvalidEscapedCharacters, "5.14",
"Invalid Escaped Characters", passed, total);
RunSpecTest(&Spec::IndentationSpaces, "6.1", "Indentation Spaces", passed, total); RunSpecTest(&Spec::IndentationSpaces, "6.1", "Indentation Spaces", passed,
RunSpecTest(&Spec::IndentationIndicators, "6.2", "Indentation Indicators", passed, total); total);
RunSpecTest(&Spec::SeparationSpaces, "6.3", "Separation 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::LinePrefixes, "6.4", "Line Prefixes", passed, total);
RunSpecTest(&Spec::EmptyLines, "6.5", "Empty Lines", passed, total); RunSpecTest(&Spec::EmptyLines, "6.5", "Empty Lines", passed, total);
RunSpecTest(&Spec::LineFolding, "6.6", "Line Folding", passed, total); RunSpecTest(&Spec::LineFolding, "6.6", "Line Folding", passed, total);
RunSpecTest(&Spec::BlockFolding, "6.7", "Block Folding", passed, total); RunSpecTest(&Spec::BlockFolding, "6.7", "Block Folding", passed, total);
RunSpecTest(&Spec::FlowFolding, "6.8", "Flow Folding", passed, total); RunSpecTest(&Spec::FlowFolding, "6.8", "Flow Folding", passed, total);
RunSpecTest(&Spec::SeparatedComment, "6.9", "Separated Comment", passed, total); RunSpecTest(&Spec::SeparatedComment, "6.9", "Separated Comment", passed,
total);
RunSpecTest(&Spec::CommentLines, "6.10", "Comment Lines", passed, total); RunSpecTest(&Spec::CommentLines, "6.10", "Comment Lines", passed, total);
RunSpecTest(&Spec::MultiLineComments, "6.11", "Multi-Line Comments", passed, total); RunSpecTest(&Spec::MultiLineComments, "6.11", "Multi-Line Comments", passed,
RunSpecTest(&Spec::SeparationSpacesII, "6.12", "Separation Spaces", passed, total); total);
RunSpecTest(&Spec::ReservedDirectives, "6.13", "Reserved Directives", 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::YAMLDirective, "6.14", "YAML Directive", passed, total);
RunSpecTest(&Spec::InvalidRepeatedYAMLDirective, "6.15", "Invalid Repeated 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::TagDirective, "6.16", "Tag Directive", passed, total);
RunSpecTest(&Spec::InvalidRepeatedTagDirective, "6.17", "Invalid Repeated Tag Directive", passed, total); RunSpecTest(&Spec::InvalidRepeatedTagDirective, "6.17",
RunSpecTest(&Spec::PrimaryTagHandle, "6.18", "Primary Tag Handle", passed, total); "Invalid Repeated Tag Directive", passed, total);
RunSpecTest(&Spec::SecondaryTagHandle, "6.19", "SecondaryTagHandle", 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::TagHandles, "6.20", "TagHandles", passed, total);
RunSpecTest(&Spec::LocalTagPrefix, "6.21", "LocalTagPrefix", passed, total); RunSpecTest(&Spec::LocalTagPrefix, "6.21", "LocalTagPrefix", passed, total);
RunSpecTest(&Spec::GlobalTagPrefix, "6.22", "GlobalTagPrefix", passed, total); RunSpecTest(&Spec::GlobalTagPrefix, "6.22", "GlobalTagPrefix", passed, total);
RunSpecTest(&Spec::NodeProperties, "6.23", "NodeProperties", passed, total); RunSpecTest(&Spec::NodeProperties, "6.23", "NodeProperties", passed, total);
RunSpecTest(&Spec::VerbatimTags, "6.24", "Verbatim Tags", passed, total); RunSpecTest(&Spec::VerbatimTags, "6.24", "Verbatim Tags", passed, total);
RunSpecTest(&Spec::InvalidVerbatimTags, "6.25", "Invalid 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::TagShorthands, "6.26", "Tag Shorthands", passed, total);
RunSpecTest(&Spec::InvalidTagShorthands, "6.27", "Invalid Tag Shorthands", passed, total); RunSpecTest(&Spec::InvalidTagShorthands, "6.27", "Invalid Tag Shorthands",
RunSpecTest(&Spec::NonSpecificTags, "6.28", "Non Specific Tags", passed, total); passed, total);
RunSpecTest(&Spec::NonSpecificTags, "6.28", "Non Specific Tags", passed,
total);
RunSpecTest(&Spec::NodeAnchors, "6.29", "Node Anchors", passed, total); RunSpecTest(&Spec::NodeAnchors, "6.29", "Node Anchors", passed, total);
RunSpecTest(&Spec::AliasNodes, "7.1", "Alias Nodes", passed, total); RunSpecTest(&Spec::AliasNodes, "7.1", "Alias Nodes", passed, total);
RunSpecTest(&Spec::EmptyNodes, "7.2", "Empty Nodes", passed, total); RunSpecTest(&Spec::EmptyNodes, "7.2", "Empty Nodes", passed, total);
RunSpecTest(&Spec::CompletelyEmptyNodes, "7.3", "Completely Empty Nodes", passed, total); RunSpecTest(&Spec::CompletelyEmptyNodes, "7.3", "Completely Empty Nodes",
RunSpecTest(&Spec::DoubleQuotedImplicitKeys, "7.4", "Double Quoted Implicit Keys", passed, total); passed, total);
RunSpecTest(&Spec::DoubleQuotedLineBreaks, "7.5", "Double Quoted Line Breaks", passed, total); RunSpecTest(&Spec::DoubleQuotedImplicitKeys, "7.4",
RunSpecTest(&Spec::DoubleQuotedLines, "7.6", "Double Quoted Lines", passed, total); "Double Quoted Implicit Keys", passed, total);
RunSpecTest(&Spec::SingleQuotedCharacters, "7.7", "Single Quoted Characters", passed, total); RunSpecTest(&Spec::DoubleQuotedLineBreaks, "7.5", "Double Quoted Line Breaks",
RunSpecTest(&Spec::SingleQuotedImplicitKeys, "7.8", "Single Quoted Implicit Keys", passed, total); passed, total);
RunSpecTest(&Spec::SingleQuotedLines, "7.9", "Single Quoted Lines", passed, total); RunSpecTest(&Spec::DoubleQuotedLines, "7.6", "Double Quoted Lines", passed,
RunSpecTest(&Spec::PlainCharacters, "7.10", "Plain Characters", passed, total); total);
RunSpecTest(&Spec::PlainImplicitKeys, "7.11", "Plain Implicit Keys", 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::PlainLines, "7.12", "Plain Lines", passed, total);
RunSpecTest(&Spec::FlowSequence, "7.13", "Flow Sequence", passed, total); RunSpecTest(&Spec::FlowSequence, "7.13", "Flow Sequence", passed, total);
RunSpecTest(&Spec::FlowSequenceEntries, "7.14", "Flow Sequence Entries", passed, total); RunSpecTest(&Spec::FlowSequenceEntries, "7.14", "Flow Sequence Entries",
passed, total);
RunSpecTest(&Spec::FlowMappings, "7.15", "Flow Mappings", passed, total); RunSpecTest(&Spec::FlowMappings, "7.15", "Flow Mappings", passed, total);
RunSpecTest(&Spec::FlowMappingEntries, "7.16", "Flow Mapping Entries", passed, total); RunSpecTest(&Spec::FlowMappingEntries, "7.16", "Flow Mapping Entries", passed,
RunSpecTest(&Spec::FlowMappingSeparateValues, "7.17", "Flow Mapping Separate Values", passed, total); total);
RunSpecTest(&Spec::FlowMappingAdjacentValues, "7.18", "Flow Mapping Adjacent Values", passed, total); RunSpecTest(&Spec::FlowMappingSeparateValues, "7.17",
RunSpecTest(&Spec::SinglePairFlowMappings, "7.19", "Single Pair Flow Mappings", passed, total); "Flow Mapping Separate Values", passed, total);
RunSpecTest(&Spec::SinglePairExplicitEntry, "7.20", "Single Pair Explicit Entry", passed, total); RunSpecTest(&Spec::FlowMappingAdjacentValues, "7.18",
RunSpecTest(&Spec::SinglePairImplicitEntries, "7.21", "Single Pair Implicit Entries", passed, total); "Flow Mapping Adjacent Values", passed, total);
RunSpecTest(&Spec::InvalidImplicitKeys, "7.22", "Invalid Implicit Keys", 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::FlowContent, "7.23", "Flow Content", passed, total);
RunSpecTest(&Spec::FlowNodes, "7.24", "FlowNodes", passed, total); RunSpecTest(&Spec::FlowNodes, "7.24", "FlowNodes", passed, total);
RunSpecTest(&Spec::BlockScalarHeader, "8.1", "Block Scalar Header", passed, total); RunSpecTest(&Spec::BlockScalarHeader, "8.1", "Block Scalar Header", passed,
RunSpecTest(&Spec::BlockIndentationHeader, "8.2", "Block Indentation Header", passed, total); total);
RunSpecTest(&Spec::InvalidBlockScalarIndentationIndicators, "8.3", "Invalid Block Scalar Indentation Indicators", passed, total); RunSpecTest(&Spec::BlockIndentationHeader, "8.2", "Block Indentation Header",
RunSpecTest(&Spec::ChompingFinalLineBreak, "8.4", "Chomping Final Line Break", passed, total); passed, total);
RunSpecTest(&Spec::ChompingTrailingLines, "8.5", "Chomping Trailing Lines", passed, total); RunSpecTest(&Spec::InvalidBlockScalarIndentationIndicators, "8.3",
RunSpecTest(&Spec::EmptyScalarChomping, "8.6", "Empty Scalar Chomping", passed, total); "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::LiteralScalar, "8.7", "Literal Scalar", passed, total);
RunSpecTest(&Spec::LiteralContent, "8.8", "Literal Content", passed, total); RunSpecTest(&Spec::LiteralContent, "8.8", "Literal Content", passed, total);
RunSpecTest(&Spec::FoldedScalar, "8.9", "Folded Scalar", passed, total); RunSpecTest(&Spec::FoldedScalar, "8.9", "Folded Scalar", passed, total);
RunSpecTest(&Spec::FoldedLines, "8.10", "Folded Lines", passed, total); RunSpecTest(&Spec::FoldedLines, "8.10", "Folded Lines", passed, total);
RunSpecTest(&Spec::MoreIndentedLines, "8.11", "More Indented Lines", passed, total); RunSpecTest(&Spec::MoreIndentedLines, "8.11", "More Indented Lines", passed,
RunSpecTest(&Spec::EmptySeparationLines, "8.12", "Empty Separation Lines", passed, total); total);
RunSpecTest(&Spec::FinalEmptyLines, "8.13", "Final Empty 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::BlockSequence, "8.14", "Block Sequence", passed, total);
RunSpecTest(&Spec::BlockSequenceEntryTypes, "8.15", "Block Sequence Entry Types", passed, total); RunSpecTest(&Spec::BlockSequenceEntryTypes, "8.15",
"Block Sequence Entry Types", passed, total);
RunSpecTest(&Spec::BlockMappings, "8.16", "Block Mappings", passed, total); RunSpecTest(&Spec::BlockMappings, "8.16", "Block Mappings", passed, total);
RunSpecTest(&Spec::ExplicitBlockMappingEntries, "8.17", "Explicit Block Mapping Entries", passed, total); RunSpecTest(&Spec::ExplicitBlockMappingEntries, "8.17",
RunSpecTest(&Spec::ImplicitBlockMappingEntries, "8.18", "Implicit Block Mapping Entries", passed, total); "Explicit Block Mapping Entries", passed, total);
RunSpecTest(&Spec::CompactBlockMappings, "8.19", "Compact Block Mappings", 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::BlockNodeTypes, "8.20", "Block Node Types", passed, total);
RunSpecTest(&Spec::BlockScalarNodes, "8.21", "Block Scalar Nodes", passed, total); RunSpecTest(&Spec::BlockScalarNodes, "8.21", "Block Scalar Nodes", passed,
RunSpecTest(&Spec::BlockCollectionNodes, "8.22", "Block Collection Nodes", passed, total); total);
RunSpecTest(&Spec::BlockCollectionNodes, "8.22", "Block Collection Nodes",
passed, total);
std::cout << "Spec tests: " << passed << "/" << total << " passed\n"; std::cout << "Spec tests: " << passed << "/" << total << " passed\n";
return passed == total; return passed == total;
} }
} }
#ifndef SPECTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef SPECTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SPECTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define SPECTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include "teststruct.h" #include "teststruct.h"
namespace Test { namespace Test {
namespace Spec { namespace Spec {
// 2.1 // 2.1
TEST SeqScalars(); TEST SeqScalars();
// 2.2 // 2.2
TEST MappingScalarsToScalars(); TEST MappingScalarsToScalars();
// 2.3 // 2.3
TEST MappingScalarsToSequences(); TEST MappingScalarsToSequences();
// 2.4 // 2.4
TEST SequenceOfMappings(); TEST SequenceOfMappings();
// 2.5 // 2.5
TEST SequenceOfSequences(); TEST SequenceOfSequences();
// 2.6 // 2.6
TEST MappingOfMappings(); TEST MappingOfMappings();
// 2.7 // 2.7
TEST TwoDocumentsInAStream(); TEST TwoDocumentsInAStream();
// 2.8 // 2.8
TEST PlayByPlayFeed(); TEST PlayByPlayFeed();
// 2.9 // 2.9
TEST SingleDocumentWithTwoComments(); TEST SingleDocumentWithTwoComments();
// 2.10 // 2.10
TEST SimpleAnchor(); TEST SimpleAnchor();
// 2.11 // 2.11
TEST MappingBetweenSequences(); TEST MappingBetweenSequences();
// 2.12 // 2.12
TEST CompactNestedMapping(); TEST CompactNestedMapping();
// 2.13 // 2.13
TEST InLiteralsNewlinesArePreserved(); TEST InLiteralsNewlinesArePreserved();
// 2.14 // 2.14
TEST InFoldedScalarsNewlinesBecomeSpaces(); TEST InFoldedScalarsNewlinesBecomeSpaces();
// 2.15 // 2.15
TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines(); TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines();
// 2.16 // 2.16
TEST IndentationDeterminesScope(); TEST IndentationDeterminesScope();
// 2.17 // 2.17
TEST QuotedScalars(); TEST QuotedScalars();
// 2.18 // 2.18
TEST MultiLineFlowScalars(); TEST MultiLineFlowScalars();
// TODO: 2.19 - 2.22 schema tags // TODO: 2.19 - 2.22 schema tags
// 2.23 // 2.23
TEST VariousExplicitTags(); TEST VariousExplicitTags();
// 2.24 // 2.24
TEST GlobalTags(); TEST GlobalTags();
// 2.25 // 2.25
TEST UnorderedSets(); TEST UnorderedSets();
// 2.26 // 2.26
TEST OrderedMappings(); TEST OrderedMappings();
// 2.27 // 2.27
TEST Invoice(); TEST Invoice();
// 2.28 // 2.28
TEST LogFile(); TEST LogFile();
// TODO: 5.1 - 5.2 BOM // TODO: 5.1 - 5.2 BOM
// 5.3 // 5.3
TEST BlockStructureIndicators(); TEST BlockStructureIndicators();
// 5.4 // 5.4
TEST FlowStructureIndicators(); TEST FlowStructureIndicators();
// 5.5 // 5.5
TEST CommentIndicator(); TEST CommentIndicator();
// 5.6 // 5.6
TEST NodePropertyIndicators(); TEST NodePropertyIndicators();
// 5.7 // 5.7
TEST BlockScalarIndicators(); TEST BlockScalarIndicators();
// 5.8 // 5.8
TEST QuotedScalarIndicators(); TEST QuotedScalarIndicators();
// TODO: 5.9 directive // TODO: 5.9 directive
// TODO: 5.10 reserved indicator // TODO: 5.10 reserved indicator
// 5.11 // 5.11
TEST LineBreakCharacters(); TEST LineBreakCharacters();
// 5.12 // 5.12
TEST TabsAndSpaces(); TEST TabsAndSpaces();
// 5.13 // 5.13
TEST EscapedCharacters(); TEST EscapedCharacters();
// 5.14 // 5.14
TEST InvalidEscapedCharacters(); TEST InvalidEscapedCharacters();
// 6.1 // 6.1
TEST IndentationSpaces(); TEST IndentationSpaces();
// 6.2 // 6.2
TEST IndentationIndicators(); TEST IndentationIndicators();
// 6.3 // 6.3
TEST SeparationSpaces(); TEST SeparationSpaces();
// 6.4 // 6.4
TEST LinePrefixes(); TEST LinePrefixes();
// 6.5 // 6.5
TEST EmptyLines(); TEST EmptyLines();
// 6.6 // 6.6
TEST LineFolding(); TEST LineFolding();
// 6.7 // 6.7
TEST BlockFolding(); TEST BlockFolding();
// 6.8 // 6.8
TEST FlowFolding(); TEST FlowFolding();
// 6.9 // 6.9
TEST SeparatedComment(); TEST SeparatedComment();
// 6.10 // 6.10
TEST CommentLines(); TEST CommentLines();
// 6.11 // 6.11
TEST MultiLineComments(); TEST MultiLineComments();
// 6.12 // 6.12
TEST SeparationSpacesII(); TEST SeparationSpacesII();
// 6.13 // 6.13
TEST ReservedDirectives(); TEST ReservedDirectives();
// 6.14 // 6.14
TEST YAMLDirective(); TEST YAMLDirective();
// 6.15 // 6.15
TEST InvalidRepeatedYAMLDirective(); TEST InvalidRepeatedYAMLDirective();
// 6.16 // 6.16
TEST TagDirective(); TEST TagDirective();
// 6.17 // 6.17
TEST InvalidRepeatedTagDirective(); TEST InvalidRepeatedTagDirective();
// 6.18 // 6.18
TEST PrimaryTagHandle(); TEST PrimaryTagHandle();
// 6.19 // 6.19
TEST SecondaryTagHandle(); TEST SecondaryTagHandle();
// 6.20 // 6.20
TEST TagHandles(); TEST TagHandles();
// 6.21 // 6.21
TEST LocalTagPrefix(); TEST LocalTagPrefix();
// 6.22 // 6.22
TEST GlobalTagPrefix(); TEST GlobalTagPrefix();
// 6.23 // 6.23
TEST NodeProperties(); TEST NodeProperties();
// 6.24 // 6.24
TEST VerbatimTags(); TEST VerbatimTags();
// 6.25 // 6.25
TEST InvalidVerbatimTags(); TEST InvalidVerbatimTags();
// 6.26 // 6.26
TEST TagShorthands(); TEST TagShorthands();
// 6.27 // 6.27
TEST InvalidTagShorthands(); TEST InvalidTagShorthands();
// 6.28 // 6.28
TEST NonSpecificTags(); TEST NonSpecificTags();
// 6.29 // 6.29
TEST NodeAnchors(); TEST NodeAnchors();
// 7.1 // 7.1
TEST AliasNodes(); TEST AliasNodes();
// 7.2 // 7.2
TEST EmptyNodes(); TEST EmptyNodes();
// 7.3 // 7.3
TEST CompletelyEmptyNodes(); TEST CompletelyEmptyNodes();
// 7.4 // 7.4
TEST DoubleQuotedImplicitKeys(); TEST DoubleQuotedImplicitKeys();
// 7.5 // 7.5
TEST DoubleQuotedLineBreaks(); TEST DoubleQuotedLineBreaks();
// 7.6 // 7.6
TEST DoubleQuotedLines(); TEST DoubleQuotedLines();
// 7.7 // 7.7
TEST SingleQuotedCharacters(); TEST SingleQuotedCharacters();
// 7.8 // 7.8
TEST SingleQuotedImplicitKeys(); TEST SingleQuotedImplicitKeys();
// 7.9 // 7.9
TEST SingleQuotedLines(); TEST SingleQuotedLines();
// 7.10 // 7.10
TEST PlainCharacters(); TEST PlainCharacters();
// 7.11 // 7.11
TEST PlainImplicitKeys(); TEST PlainImplicitKeys();
// 7.12 // 7.12
TEST PlainLines(); TEST PlainLines();
// 7.13 // 7.13
TEST FlowSequence(); TEST FlowSequence();
// 7.14 // 7.14
TEST FlowSequenceEntries(); TEST FlowSequenceEntries();
// 7.15 // 7.15
TEST FlowMappings(); TEST FlowMappings();
// 7.16 // 7.16
TEST FlowMappingEntries(); TEST FlowMappingEntries();
// 7.17 // 7.17
TEST FlowMappingSeparateValues(); TEST FlowMappingSeparateValues();
// 7.18 // 7.18
TEST FlowMappingAdjacentValues(); TEST FlowMappingAdjacentValues();
// 7.19 // 7.19
TEST SinglePairFlowMappings(); TEST SinglePairFlowMappings();
// 7.20 // 7.20
TEST SinglePairExplicitEntry(); TEST SinglePairExplicitEntry();
// 7.21 // 7.21
TEST SinglePairImplicitEntries(); TEST SinglePairImplicitEntries();
// 7.22 // 7.22
TEST InvalidImplicitKeys(); TEST InvalidImplicitKeys();
// 7.23 // 7.23
TEST FlowContent(); TEST FlowContent();
// 7.24 // 7.24
TEST FlowNodes(); TEST FlowNodes();
// 8.1 // 8.1
TEST BlockScalarHeader(); TEST BlockScalarHeader();
// 8.2 // 8.2
TEST BlockIndentationHeader(); TEST BlockIndentationHeader();
// 8.3 // 8.3
TEST InvalidBlockScalarIndentationIndicators(); TEST InvalidBlockScalarIndentationIndicators();
// 8.4 // 8.4
TEST ChompingFinalLineBreak(); TEST ChompingFinalLineBreak();
// 8.5 // 8.5
TEST ChompingTrailingLines(); TEST ChompingTrailingLines();
// 8.6 // 8.6
TEST EmptyScalarChomping(); TEST EmptyScalarChomping();
// 8.7 // 8.7
TEST LiteralScalar(); TEST LiteralScalar();
// 8.8 // 8.8
TEST LiteralContent(); TEST LiteralContent();
// 8.9 // 8.9
TEST FoldedScalar(); TEST FoldedScalar();
// 8.10 // 8.10
TEST FoldedLines(); TEST FoldedLines();
// 8.11 // 8.11
TEST MoreIndentedLines(); TEST MoreIndentedLines();
// 8.12 // 8.12
TEST EmptySeparationLines(); TEST EmptySeparationLines();
// 8.13 // 8.13
TEST FinalEmptyLines(); TEST FinalEmptyLines();
// 8.14 // 8.14
TEST BlockSequence(); TEST BlockSequence();
// 8.15 // 8.15
TEST BlockSequenceEntryTypes(); TEST BlockSequenceEntryTypes();
// 8.16 // 8.16
TEST BlockMappings(); TEST BlockMappings();
// 8.17 // 8.17
TEST ExplicitBlockMappingEntries(); TEST ExplicitBlockMappingEntries();
// 8.18 // 8.18
TEST ImplicitBlockMappingEntries(); TEST ImplicitBlockMappingEntries();
// 8.19 // 8.19
TEST CompactBlockMappings(); TEST CompactBlockMappings();
// 8.20 // 8.20
TEST BlockNodeTypes(); TEST BlockNodeTypes();
// 8.21 // 8.21
TEST BlockScalarNodes(); TEST BlockScalarNodes();
// 8.22 // 8.22
TEST BlockCollectionNodes(); TEST BlockCollectionNodes();
} }
bool RunSpecTests(); bool RunSpecTests();
} }
#endif // SPECTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // SPECTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef TESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef TESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define TESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define TESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include <string> #include <string>
namespace Test { namespace Test {
void RunAll(); void RunAll();
namespace Parser { namespace Parser {
// scalar tests // scalar tests
void SimpleScalar(std::string& inputScalar, std::string& desiredOutput); void SimpleScalar(std::string& inputScalar, std::string& desiredOutput);
void MultiLineScalar(std::string& inputScalar, std::string& desiredOutput); void MultiLineScalar(std::string& inputScalar, std::string& desiredOutput);
void LiteralScalar(std::string& inputScalar, std::string& desiredOutput); void LiteralScalar(std::string& inputScalar, std::string& desiredOutput);
void FoldedScalar(std::string& inputScalar, std::string& desiredOutput); void FoldedScalar(std::string& inputScalar, std::string& desiredOutput);
void ChompedFoldedScalar(std::string& inputScalar, std::string& desiredOutput); void ChompedFoldedScalar(std::string& inputScalar, std::string& desiredOutput);
void ChompedLiteralScalar(std::string& inputScalar, std::string& desiredOutput); void ChompedLiteralScalar(std::string& inputScalar, std::string& desiredOutput);
void FoldedScalarWithIndent(std::string& inputScalar, std::string& desiredOutput); void FoldedScalarWithIndent(std::string& inputScalar,
void ColonScalar(std::string& inputScalar, std::string& desiredOutput); std::string& desiredOutput);
void QuotedScalar(std::string& inputScalar, std::string& desiredOutput); void ColonScalar(std::string& inputScalar, std::string& desiredOutput);
void CommaScalar(std::string& inputScalar, std::string& desiredOutput); void QuotedScalar(std::string& inputScalar, std::string& desiredOutput);
void DashScalar(std::string& inputScalar, std::string& desiredOutput); void CommaScalar(std::string& inputScalar, std::string& desiredOutput);
void URLScalar(std::string& inputScalar, std::string& desiredOutput); void DashScalar(std::string& inputScalar, std::string& desiredOutput);
void URLScalar(std::string& inputScalar, std::string& desiredOutput);
// misc tests // misc tests
bool SimpleSeq(); bool SimpleSeq();
bool SimpleMap(); bool SimpleMap();
bool FlowSeq(); bool FlowSeq();
bool FlowMap(); bool FlowMap();
bool FlowMapWithOmittedKey(); bool FlowMapWithOmittedKey();
bool FlowMapWithOmittedValue(); bool FlowMapWithOmittedValue();
bool FlowMapWithSoloEntry(); bool FlowMapWithSoloEntry();
bool FlowMapEndingWithSoloEntry(); bool FlowMapEndingWithSoloEntry();
bool QuotedSimpleKeys(); bool QuotedSimpleKeys();
bool CompressedMapAndSeq(); bool CompressedMapAndSeq();
bool NullBlockSeqEntry(); bool NullBlockSeqEntry();
bool NullBlockMapKey(); bool NullBlockMapKey();
bool NullBlockMapValue(); bool NullBlockMapValue();
bool SimpleAlias(); bool SimpleAlias();
bool AliasWithNull(); bool AliasWithNull();
bool AnchorInSimpleKey(); bool AnchorInSimpleKey();
bool AliasAsSimpleKey(); bool AliasAsSimpleKey();
bool ExplicitDoc(); bool ExplicitDoc();
bool MultipleDocs(); bool MultipleDocs();
bool ExplicitEndDoc(); bool ExplicitEndDoc();
bool MultipleDocsWithSomeExplicitIndicators(); bool MultipleDocsWithSomeExplicitIndicators();
} }
} }
#endif // TESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // TESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -2,17 +2,19 @@ ...@@ -2,17 +2,19 @@
#include <string> #include <string>
#define YAML_ASSERT(cond) do { if(!(cond)) return " Assert failed: " #cond; } while(false) #define YAML_ASSERT(cond) \
do { \
if (!(cond)) \
return " Assert failed: " #cond; \
} while (false)
namespace Test namespace Test {
{ struct TEST {
struct TEST { TEST() : ok(false) {}
TEST(): ok(false) {} TEST(bool ok_) : ok(ok_) {}
TEST(bool ok_): ok(ok_) {} TEST(const char *error_) : ok(false), error(error_) {}
TEST(const char *error_): ok(false), error(error_) {}
bool ok; bool ok;
std::string error; std::string error;
}; };
} }
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
#include "yaml-cpp/yaml.h" #include "yaml-cpp/yaml.h"
#include <iostream> #include <iostream>
int main() int main() {
{
{ {
// test.yaml // test.yaml
// - foo // - foo
...@@ -46,7 +45,8 @@ int main() ...@@ -46,7 +45,8 @@ int main()
other.push_back(root); // &1 [5, ~, two, *1] other.push_back(root); // &1 [5, ~, two, *1]
other[3][0] = 0; // &1 [0, ~, two, *1] # since it's a true alias other[3][0] = 0; // &1 [0, ~, two, *1] # since it's a true alias
other.push_back(Copy(root)); // &1 [0, ~, two, *1, &2 [0, ~, two, *2]] other.push_back(Copy(root)); // &1 [0, ~, two, *1, &2 [0, ~, two, *2]]
other[4][0] = 5; // &1 [0, ~, two, *1, &2 [5, ~, two, *2]] # they're really different other[4][0] = 5; // &1 [0, ~, two, *1, &2 [5, ~, two, *2]] # they're
// really different
} }
{ {
...@@ -54,8 +54,10 @@ int main() ...@@ -54,8 +54,10 @@ int main()
node[0] = 1; // [1] # auto-construct a sequence node[0] = 1; // [1] # auto-construct a sequence
node["key"] = 5; // {0: 1, key: 5} # auto-turn it into a map node["key"] = 5; // {0: 1, key: 5} # auto-turn it into a map
node.push_back(10); // error, can't turn a map into a sequence node.push_back(10); // error, can't turn a map into a sequence
node.erase("key"); // {0: 1} # still a map, even if we remove the key that caused the problem node.erase("key"); // {0: 1} # still a map, even if we remove the key that
node = "Hello"; // Hello # assignment overwrites everything, so it's now just a plain scalar // caused the problem
node = "Hello"; // Hello # assignment overwrites everything, so it's now
// just a plain scalar
} }
{ {
...@@ -74,18 +76,22 @@ int main() ...@@ -74,18 +76,22 @@ int main()
{ {
YAML::Value node; YAML::Value node;
YAML::Value subnode = node["key"]; // 'subnode' is not instantiated ('node' is still null) YAML::Value subnode =
node["key"]; // 'subnode' is not instantiated ('node' is still null)
subnode = "value"; // {key: value} # now it is subnode = "value"; // {key: value} # now it is
YAML::Value subnode2 = node["key2"]; YAML::Value subnode2 = node["key2"];
node["key3"] = subnode2; // subnode2 is still not instantiated, but node["key3"] is "pseudo" aliased to it node["key3"] = subnode2; // subnode2 is still not instantiated, but
subnode2 = "monkey"; // {key: value, key2: &1 monkey, key3: *1} # bam! it instantiates both // node["key3"] is "pseudo" aliased to it
subnode2 = "monkey"; // {key: value, key2: &1 monkey, key3: *1} # bam! it
// instantiates both
} }
{ {
YAML::Value seq = YAML::Sequence(); YAML::Value seq = YAML::Sequence();
seq[0] = "zero"; // [zero] seq[0] = "zero"; // [zero]
seq[1] = seq[0]; // [&1 zero, *1] seq[1] = seq[0]; // [&1 zero, *1]
seq[0] = seq[1]; // [&1 zero, *1] # no-op (they both alias the same thing, so setting them equal is nothing) seq[0] = seq[1]; // [&1 zero, *1] # no-op (they both alias the same thing,
// so setting them equal is nothing)
Is(seq[0], seq[1]); // true Is(seq[0], seq[1]); // true
seq[1] = "one"; // [&1 one, *1] seq[1] = "one"; // [&1 one, *1]
UnAlias(seq[1]); // [one, one] UnAlias(seq[1]); // [one, one]
...@@ -98,9 +104,11 @@ int main() ...@@ -98,9 +104,11 @@ int main()
root.push_back("one"); root.push_back("one");
root.push_back("two"); root.push_back("two");
YAML::Value two = root[2]; YAML::Value two = root[2];
root = "scalar"; // 'two' is still "two", even though 'root' is "scalar" (the sequence effectively no longer exists) root = "scalar"; // 'two' is still "two", even though 'root' is "scalar"
// (the sequence effectively no longer exists)
// Note: in all likelihood, the memory for nodes "zero" and "one" is still allocated. How can it go away? Weak pointers? // Note: in all likelihood, the memory for nodes "zero" and "one" is still
// allocated. How can it go away? Weak pointers?
} }
{ {
......
...@@ -2,9 +2,8 @@ ...@@ -2,9 +2,8 @@
#include "yaml-cpp/eventhandler.h" #include "yaml-cpp/eventhandler.h"
#include <iostream> #include <iostream>
class NullEventHandler: public YAML::EventHandler class NullEventHandler : public YAML::EventHandler {
{ public:
public:
typedef YAML::Mark Mark; typedef YAML::Mark Mark;
typedef YAML::anchor_t anchor_t; typedef YAML::anchor_t anchor_t;
...@@ -14,15 +13,15 @@ public: ...@@ -14,15 +13,15 @@ public:
virtual void OnDocumentEnd() {} virtual void OnDocumentEnd() {}
virtual void OnNull(const Mark&, anchor_t) {} virtual void OnNull(const Mark&, anchor_t) {}
virtual void OnAlias(const Mark&, anchor_t) {} virtual void OnAlias(const Mark&, anchor_t) {}
virtual void OnScalar(const Mark&, const std::string&, anchor_t, const std::string&) {} virtual void OnScalar(const Mark&, const std::string&, anchor_t,
const std::string&) {}
virtual void OnSequenceStart(const Mark&, const std::string&, anchor_t) {} virtual void OnSequenceStart(const Mark&, const std::string&, anchor_t) {}
virtual void OnSequenceEnd() {} virtual void OnSequenceEnd() {}
virtual void OnMapStart(const Mark&, const std::string&, anchor_t) {} virtual void OnMapStart(const Mark&, const std::string&, anchor_t) {}
virtual void OnMapEnd() {} virtual void OnMapEnd() {}
}; };
int main() int main() {
{
YAML::Parser parser(std::cin); YAML::Parser parser(std::cin);
NullEventHandler handler; NullEventHandler handler;
parser.HandleNextDocument(handler); parser.HandleNextDocument(handler);
......
...@@ -2,9 +2,8 @@ ...@@ -2,9 +2,8 @@
#include "yaml-cpp/eventhandler.h" #include "yaml-cpp/eventhandler.h"
#include <iostream> #include <iostream>
class NullEventHandler: public YAML::EventHandler class NullEventHandler : public YAML::EventHandler {
{ public:
public:
typedef YAML::Mark Mark; typedef YAML::Mark Mark;
typedef YAML::anchor_t anchor_t; typedef YAML::anchor_t anchor_t;
...@@ -14,18 +13,18 @@ public: ...@@ -14,18 +13,18 @@ public:
virtual void OnDocumentEnd() {} virtual void OnDocumentEnd() {}
virtual void OnNull(const Mark&, anchor_t) {} virtual void OnNull(const Mark&, anchor_t) {}
virtual void OnAlias(const Mark&, anchor_t) {} virtual void OnAlias(const Mark&, anchor_t) {}
virtual void OnScalar(const Mark&, const std::string&, anchor_t, const std::string&) {} virtual void OnScalar(const Mark&, const std::string&, anchor_t,
const std::string&) {}
virtual void OnSequenceStart(const Mark&, const std::string&, anchor_t) {} virtual void OnSequenceStart(const Mark&, const std::string&, anchor_t) {}
virtual void OnSequenceEnd() {} virtual void OnSequenceEnd() {}
virtual void OnMapStart(const Mark&, const std::string&, anchor_t) {} virtual void OnMapStart(const Mark&, const std::string&, anchor_t) {}
virtual void OnMapEnd() {} virtual void OnMapEnd() {}
}; };
int main() int main() {
{
std::stringstream stream("---{header: {id: 1"); std::stringstream stream("---{header: {id: 1");
YAML::Parser parser(stream); YAML::Parser parser(stream);
// parser.PrintTokens(std::cout); // parser.PrintTokens(std::cout);
NullEventHandler handler; NullEventHandler handler;
parser.HandleNextDocument(handler); parser.HandleNextDocument(handler);
return 0; return 0;
......
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