Commit 9b4db068 authored by Jesse Beder's avatar Jesse Beder
Browse files

Run clang-format

parent e40ed4f9
#ifndef TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define TOKEN_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
#endif
#include "yaml-cpp/mark.h"
#include <iostream>
#include <string>
#include <vector>
namespace YAML
{
const std::string TokenNames[] = {
"DIRECTIVE",
"DOC_START",
"DOC_END",
"BLOCK_SEQ_START",
"BLOCK_MAP_START",
"BLOCK_SEQ_END",
"BLOCK_MAP_END",
"BLOCK_ENTRY",
"FLOW_SEQ_START",
"FLOW_MAP_START",
"FLOW_SEQ_END",
"FLOW_MAP_END",
"FLOW_MAP_COMPACT",
"FLOW_ENTRY",
"KEY",
"VALUE",
"ANCHOR",
"ALIAS",
"TAG",
"SCALAR"
};
namespace YAML {
const std::string TokenNames[] = {
"DIRECTIVE", "DOC_START", "DOC_END", "BLOCK_SEQ_START",
"BLOCK_MAP_START", "BLOCK_SEQ_END", "BLOCK_MAP_END", "BLOCK_ENTRY",
"FLOW_SEQ_START", "FLOW_MAP_START", "FLOW_SEQ_END", "FLOW_MAP_END",
"FLOW_MAP_COMPACT", "FLOW_ENTRY", "KEY", "VALUE",
"ANCHOR", "ALIAS", "TAG", "SCALAR"};
struct Token {
struct Token {
// enums
enum STATUS { VALID, INVALID, UNVERIFIED };
enum STATUS {
VALID,
INVALID,
UNVERIFIED
};
enum TYPE {
DIRECTIVE,
DOC_START,
......@@ -64,11 +52,12 @@ namespace YAML
};
// data
Token(TYPE type_, const Mark& mark_): status(VALID), type(type_), mark(mark_), data(0) {}
Token(TYPE type_, const Mark& mark_)
: status(VALID), type(type_), mark(mark_), data(0) {}
friend std::ostream& operator << (std::ostream& out, const Token& token) {
friend std::ostream& operator<<(std::ostream& out, const Token& token) {
out << TokenNames[token.type] << std::string(": ") << token.value;
for(std::size_t i=0;i<token.params.size();i++)
for (std::size_t i = 0; i < token.params.size(); i++)
out << std::string(" ") << token.params[i];
return out;
}
......@@ -77,9 +66,9 @@ namespace YAML
TYPE type;
Mark mark;
std::string value;
std::vector <std::string> params;
std::vector<std::string> params;
int data;
};
};
}
#endif // TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66
......@@ -3,22 +3,20 @@
#include "yaml-cpp/yaml.h"
#include <iostream>
namespace Test
{
namespace Parser {
TEST NoEndOfMapFlow()
{
namespace Test {
namespace Parser {
TEST NoEndOfMapFlow() {
try {
HANDLE("---{header: {id: 1");
} catch(const YAML::ParserException& e) {
}
catch (const YAML::ParserException& e) {
YAML_ASSERT(e.msg == std::string(YAML::ErrorMsg::END_OF_MAP_FLOW));
return true;
}
return " no exception caught";
}
}
TEST PlainScalarStartingWithQuestionMark()
{
TEST PlainScalarStartingWithQuestionMark() {
HANDLE("foo: ?bar");
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -27,10 +25,9 @@ namespace Test
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
TEST NullStringScalar()
{
TEST NullStringScalar() {
HANDLE("foo: null");
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -39,39 +36,41 @@ namespace Test
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
}
}
namespace {
void RunParserTest(TEST (*test)(), const std::string& name, int& passed, int& total) {
namespace {
void RunParserTest(TEST (*test)(), const std::string& name, int& passed,
int& total) {
TEST ret;
try {
ret = test();
} catch(const YAML::Exception& e) {
}
catch (const YAML::Exception& e) {
ret.ok = false;
ret.error = std::string(" Exception caught: ") + e.what();
}
if(!ret.ok) {
if (!ret.ok) {
std::cout << "Parser test failed: " << name << "\n";
std::cout << ret.error << "\n";
}
if(ret.ok)
if (ret.ok)
passed++;
total++;
}
}
}
}
bool RunParserTests()
{
bool RunParserTests() {
int passed = 0;
int total = 0;
RunParserTest(&Parser::NoEndOfMapFlow, "No end of map flow", passed, total);
RunParserTest(&Parser::PlainScalarStartingWithQuestionMark, "Plain scalar starting with question mark", passed, total);
RunParserTest(&Parser::PlainScalarStartingWithQuestionMark,
"Plain scalar starting with question mark", passed, total);
RunParserTest(&Parser::NullStringScalar, "Null string scalar", passed, total);
std::cout << "Parser tests: " << passed << "/" << total << " passed\n";
return passed == total;
}
}
}
......@@ -5,10 +5,9 @@
#include <cassert>
namespace Test {
namespace Spec {
// 2.1
TEST SeqScalars()
{
namespace Spec {
// 2.1
TEST SeqScalars() {
HANDLE(ex2_1);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -18,11 +17,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.2
TEST MappingScalarsToScalars()
{
// 2.2
TEST MappingScalarsToScalars() {
HANDLE(ex2_2);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -35,11 +33,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.3
TEST MappingScalarsToSequences()
{
// 2.3
TEST MappingScalarsToSequences() {
HANDLE(ex2_3);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -58,11 +55,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.4
TEST SequenceOfMappings()
{
// 2.4
TEST SequenceOfMappings() {
HANDLE(ex2_4);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -85,11 +81,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.5
TEST SequenceOfSequences()
{
// 2.5
TEST SequenceOfSequences() {
HANDLE(ex2_5);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -111,11 +106,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.6
TEST MappingOfMappings()
{
// 2.6
TEST MappingOfMappings() {
HANDLE(ex2_6);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -136,11 +130,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.7
TEST TwoDocumentsInAStream()
{
// 2.7
TEST TwoDocumentsInAStream() {
HANDLE(ex2_7);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -156,11 +149,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.8
TEST PlayByPlayFeed()
{
// 2.8
TEST PlayByPlayFeed() {
HANDLE(ex2_8);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -183,11 +175,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.9
TEST SingleDocumentWithTwoComments()
{
// 2.9
TEST SingleDocumentWithTwoComments() {
HANDLE(ex2_9);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -204,11 +195,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.10
TEST SimpleAnchor()
{
// 2.10
TEST SimpleAnchor() {
HANDLE(ex2_10);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -225,11 +215,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.11
TEST MappingBetweenSequences()
{
// 2.11
TEST MappingBetweenSequences() {
HANDLE(ex2_11);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -252,11 +241,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.12
TEST CompactNestedMapping()
{
// 2.12
TEST CompactNestedMapping() {
HANDLE(ex2_12);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -281,11 +269,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.13
TEST InLiteralsNewlinesArePreserved()
{
// 2.13
TEST InLiteralsNewlinesArePreserved() {
HANDLE(ex2_13);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0,
......@@ -293,21 +280,19 @@ namespace Test {
"// || ||__");
EXPECT_DOC_END();
DONE();
}
}
// 2.14
TEST InFoldedScalarsNewlinesBecomeSpaces()
{
// 2.14
TEST InFoldedScalarsNewlinesBecomeSpaces() {
HANDLE(ex2_14);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "Mark McGwire's year was crippled by a knee injury.");
EXPECT_DOC_END();
DONE();
}
}
// 2.15
TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines()
{
// 2.15
TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines() {
HANDLE(ex2_15);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0,
......@@ -319,11 +304,10 @@ namespace Test {
"What a year!");
EXPECT_DOC_END();
DONE();
}
}
// 2.16
TEST IndentationDeterminesScope()
{
// 2.16
TEST IndentationDeterminesScope() {
HANDLE(ex2_16);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -338,11 +322,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.17
TEST QuotedScalars()
{
// 2.17
TEST QuotedScalars() {
HANDLE(ex2_17);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -361,11 +344,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.18
TEST MultiLineFlowScalars()
{
// 2.18
TEST MultiLineFlowScalars() {
HANDLE(ex2_18);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -376,13 +358,12 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// TODO: 2.19 - 2.22 schema tags
// TODO: 2.19 - 2.22 schema tags
// 2.23
TEST VariousExplicitTags()
{
// 2.23
TEST VariousExplicitTags() {
HANDLE(ex2_23);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -402,11 +383,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.24
TEST GlobalTags()
{
// 2.24
TEST GlobalTags() {
HANDLE(ex2_24);
EXPECT_DOC_START();
EXPECT_SEQ_START("tag:clarkevans.com,2002:shape", 0);
......@@ -443,11 +423,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.25
TEST UnorderedSets()
{
// 2.25
TEST UnorderedSets() {
HANDLE(ex2_25);
EXPECT_DOC_START();
EXPECT_MAP_START("tag:yaml.org,2002:set", 0);
......@@ -460,11 +439,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.26
TEST OrderedMappings()
{
// 2.26
TEST OrderedMappings() {
HANDLE(ex2_26);
EXPECT_DOC_START();
EXPECT_SEQ_START("tag:yaml.org,2002:omap", 0);
......@@ -483,11 +461,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.27
TEST Invoice()
{
// 2.27
TEST Invoice() {
HANDLE(ex2_27);
EXPECT_DOC_START();
EXPECT_MAP_START("tag:clarkevans.com,2002:invoice", 0);
......@@ -545,15 +522,16 @@ namespace Test {
EXPECT_SCALAR("?", 0, "total");
EXPECT_SCALAR("?", 0, "4443.52");
EXPECT_SCALAR("?", 0, "comments");
EXPECT_SCALAR("?", 0, "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.");
EXPECT_SCALAR(
"?", 0,
"Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.");
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.28
TEST LogFile()
{
// 2.28
TEST LogFile() {
HANDLE(ex2_28);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -605,13 +583,12 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// TODO: 5.1 - 5.2 BOM
// TODO: 5.1 - 5.2 BOM
// 5.3
TEST BlockStructureIndicators()
{
// 5.3
TEST BlockStructureIndicators() {
HANDLE(ex5_3);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -630,11 +607,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 5.4
TEST FlowStructureIndicators()
{
// 5.4
TEST FlowStructureIndicators() {
HANDLE(ex5_4);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -653,18 +629,16 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 5.5
TEST CommentIndicator()
{
// 5.5
TEST CommentIndicator() {
HANDLE(ex5_5);
DONE();
}
}
// 5.6
TEST NodePropertyIndicators()
{
// 5.6
TEST NodePropertyIndicators() {
HANDLE(ex5_6);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -675,11 +649,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 5.7
TEST BlockScalarIndicators()
{
// 5.7
TEST BlockScalarIndicators() {
HANDLE(ex5_7);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -690,11 +663,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 5.8
TEST QuotedScalarIndicators()
{
// 5.8
TEST QuotedScalarIndicators() {
HANDLE(ex5_8);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -705,14 +677,13 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// TODO: 5.9 directive
// TODO: 5.10 reserved indicator
// TODO: 5.9 directive
// TODO: 5.10 reserved indicator
// 5.11
TEST LineBreakCharacters()
{
// 5.11
TEST LineBreakCharacters() {
HANDLE(ex5_11);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0,
......@@ -720,11 +691,10 @@ namespace Test {
"Line break (glyphed)\n");
EXPECT_DOC_END();
DONE();
}
}
// 5.12
TEST TabsAndSpaces()
{
// 5.12
TEST TabsAndSpaces() {
HANDLE(ex5_12);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -738,33 +708,34 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 5.13
TEST EscapedCharacters()
{
// 5.13
TEST EscapedCharacters() {
HANDLE(ex5_13);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "Fun with \x5C \x22 \x07 \x08 \x1B \x0C \x0A \x0D \x09 \x0B " + std::string("\x00", 1) + " \x20 \xA0 \x85 \xe2\x80\xa8 \xe2\x80\xa9 A A A");
EXPECT_SCALAR("!", 0,
"Fun with \x5C \x22 \x07 \x08 \x1B \x0C \x0A \x0D \x09 \x0B " +
std::string("\x00", 1) +
" \x20 \xA0 \x85 \xe2\x80\xa8 \xe2\x80\xa9 A A A");
EXPECT_DOC_END();
DONE();
}
}
// 5.14
TEST InvalidEscapedCharacters()
{
// 5.14
TEST InvalidEscapedCharacters() {
try {
HANDLE(ex5_14);
} catch(const YAML::ParserException& e) {
}
catch (const YAML::ParserException& e) {
YAML_ASSERT(e.msg == std::string(YAML::ErrorMsg::INVALID_ESCAPE) + "c");
return true;
}
return " no exception caught";
}
}
// 6.1
TEST IndentationSpaces()
{
// 6.1
TEST IndentationSpaces() {
HANDLE(ex6_1);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -782,11 +753,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.2
TEST IndentationIndicators()
{
// 6.2
TEST IndentationIndicators() {
HANDLE(ex6_2);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -801,11 +771,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.3
TEST SeparationSpaces()
{
// 6.3
TEST SeparationSpaces() {
HANDLE(ex6_3);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -820,11 +789,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.4
TEST LinePrefixes()
{
// 6.4
TEST LinePrefixes() {
HANDLE(ex6_4);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -837,11 +805,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.5
TEST EmptyLines()
{
// 6.5
TEST EmptyLines() {
HANDLE(ex6_5);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -852,41 +819,37 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.6
TEST LineFolding()
{
// 6.6
TEST LineFolding() {
HANDLE(ex6_6);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "trimmed\n\n\nas space");
EXPECT_DOC_END();
DONE();
}
}
// 6.7
TEST BlockFolding()
{
// 6.7
TEST BlockFolding() {
HANDLE(ex6_7);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "foo \n\n\t bar\n\nbaz\n");
EXPECT_DOC_END();
DONE();
}
}
// 6.8
TEST FlowFolding()
{
// 6.8
TEST FlowFolding() {
HANDLE(ex6_8);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, " foo\nbar\nbaz ");
EXPECT_DOC_END();
DONE();
}
}
// 6.9
TEST SeparatedComment()
{
// 6.9
TEST SeparatedComment() {
HANDLE(ex6_9);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -895,18 +858,16 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.10
TEST CommentLines()
{
// 6.10
TEST CommentLines() {
HANDLE(ex6_10);
DONE();
}
}
// 6.11
TEST MultiLineComments()
{
// 6.11
TEST MultiLineComments() {
HANDLE(ex6_11);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -915,11 +876,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.12
TEST SeparationSpacesII()
{
// 6.12
TEST SeparationSpacesII() {
HANDLE(ex6_12);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -938,71 +898,67 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.13
TEST ReservedDirectives()
{
// 6.13
TEST ReservedDirectives() {
HANDLE(ex6_13);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "foo");
EXPECT_DOC_END();
DONE();
}
}
// 6.14
TEST YAMLDirective()
{
// 6.14
TEST YAMLDirective() {
HANDLE(ex6_14);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "foo");
EXPECT_DOC_END();
DONE();
}
}
// 6.15
TEST InvalidRepeatedYAMLDirective()
{
// 6.15
TEST InvalidRepeatedYAMLDirective() {
try {
HANDLE(ex6_15);
} catch(const YAML::ParserException& e) {
if(e.msg == YAML::ErrorMsg::REPEATED_YAML_DIRECTIVE)
}
catch (const YAML::ParserException& e) {
if (e.msg == YAML::ErrorMsg::REPEATED_YAML_DIRECTIVE)
return true;
throw;
}
return " No exception was thrown";
}
}
// 6.16
TEST TagDirective()
{
// 6.16
TEST TagDirective() {
HANDLE(ex6_16);
EXPECT_DOC_START();
EXPECT_SCALAR("tag:yaml.org,2002:str", 0, "foo");
EXPECT_DOC_END();
DONE();
}
}
// 6.17
TEST InvalidRepeatedTagDirective()
{
// 6.17
TEST InvalidRepeatedTagDirective() {
try {
HANDLE(ex6_17);
} catch(const YAML::ParserException& e) {
if(e.msg == YAML::ErrorMsg::REPEATED_TAG_DIRECTIVE)
}
catch (const YAML::ParserException& e) {
if (e.msg == YAML::ErrorMsg::REPEATED_TAG_DIRECTIVE)
return true;
throw;
}
return " No exception was thrown";
}
}
// 6.18
TEST PrimaryTagHandle()
{
// 6.18
TEST PrimaryTagHandle() {
HANDLE(ex6_18);
EXPECT_DOC_START();
EXPECT_SCALAR("!foo", 0, "bar");
......@@ -1011,31 +967,28 @@ namespace Test {
EXPECT_SCALAR("tag:example.com,2000:app/foo", 0, "bar");
EXPECT_DOC_END();
DONE();
}
}
// 6.19
TEST SecondaryTagHandle()
{
// 6.19
TEST SecondaryTagHandle() {
HANDLE(ex6_19);
EXPECT_DOC_START();
EXPECT_SCALAR("tag:example.com,2000:app/int", 0, "1 - 3");
EXPECT_DOC_END();
DONE();
}
}
// 6.20
TEST TagHandles()
{
// 6.20
TEST TagHandles() {
HANDLE(ex6_20);
EXPECT_DOC_START();
EXPECT_SCALAR("tag:example.com,2000:app/foo", 0, "bar");
EXPECT_DOC_END();
DONE();
}
}
// 6.21
TEST LocalTagPrefix()
{
// 6.21
TEST LocalTagPrefix() {
HANDLE(ex6_21);
EXPECT_DOC_START();
EXPECT_SCALAR("!my-light", 0, "fluorescent");
......@@ -1044,11 +997,10 @@ namespace Test {
EXPECT_SCALAR("!my-light", 0, "green");
EXPECT_DOC_END();
DONE();
}
}
// 6.22
TEST GlobalTagPrefix()
{
// 6.22
TEST GlobalTagPrefix() {
HANDLE(ex6_22);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1056,11 +1008,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.23
TEST NodeProperties()
{
// 6.23
TEST NodeProperties() {
HANDLE(ex6_23);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1071,11 +1022,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.24
TEST VerbatimTags()
{
// 6.24
TEST VerbatimTags() {
HANDLE(ex6_24);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1084,18 +1034,16 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.25
TEST InvalidVerbatimTags()
{
// 6.25
TEST InvalidVerbatimTags() {
HANDLE(ex6_25);
return " not implemented yet";
}
}
// 6.26
TEST TagShorthands()
{
// 6.26
TEST TagShorthands() {
HANDLE(ex6_26);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1105,30 +1053,30 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.27
TEST InvalidTagShorthands()
{
// 6.27
TEST InvalidTagShorthands() {
bool threw = false;
try {
HANDLE(ex6_27a);
} catch(const YAML::ParserException& e) {
}
catch (const YAML::ParserException& e) {
threw = true;
if(e.msg != YAML::ErrorMsg::TAG_WITH_NO_SUFFIX)
if (e.msg != YAML::ErrorMsg::TAG_WITH_NO_SUFFIX)
throw;
}
if(!threw)
if (!threw)
return " No exception was thrown for a tag with no suffix";
HANDLE(ex6_27b); // TODO: should we reject this one (since !h! is not declared)?
HANDLE(
ex6_27b); // TODO: should we reject this one (since !h! is not declared)?
return " not implemented yet";
}
}
// 6.28
TEST NonSpecificTags()
{
// 6.28
TEST NonSpecificTags() {
HANDLE(ex6_28);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1138,11 +1086,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.29
TEST NodeAnchors()
{
// 6.29
TEST NodeAnchors() {
HANDLE(ex6_29);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1153,11 +1100,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.1
TEST AliasNodes()
{
// 7.1
TEST AliasNodes() {
HANDLE(ex7_1);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1172,11 +1118,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.2
TEST EmptyNodes()
{
// 7.2
TEST EmptyNodes() {
HANDLE(ex7_2);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1187,11 +1132,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.3
TEST CompletelyEmptyNodes()
{
// 7.3
TEST CompletelyEmptyNodes() {
HANDLE(ex7_3);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1202,11 +1146,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.4
TEST DoubleQuotedImplicitKeys()
{
// 7.4
TEST DoubleQuotedImplicitKeys() {
HANDLE(ex7_4);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1220,41 +1163,38 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.5
TEST DoubleQuotedLineBreaks()
{
// 7.5
TEST DoubleQuotedLineBreaks() {
HANDLE(ex7_5);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "folded to a space,\nto a line feed, or \t \tnon-content");
EXPECT_SCALAR("!", 0,
"folded to a space,\nto a line feed, or \t \tnon-content");
EXPECT_DOC_END();
DONE();
}
}
// 7.6
TEST DoubleQuotedLines()
{
// 7.6
TEST DoubleQuotedLines() {
HANDLE(ex7_6);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, " 1st non-empty\n2nd non-empty 3rd non-empty ");
EXPECT_DOC_END();
DONE();
}
}
// 7.7
TEST SingleQuotedCharacters()
{
// 7.7
TEST SingleQuotedCharacters() {
HANDLE(ex7_7);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "here's to \"quotes\"");
EXPECT_DOC_END();
DONE();
}
}
// 7.8
TEST SingleQuotedImplicitKeys()
{
// 7.8
TEST SingleQuotedImplicitKeys() {
HANDLE(ex7_8);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1268,21 +1208,19 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.9
TEST SingleQuotedLines()
{
// 7.9
TEST SingleQuotedLines() {
HANDLE(ex7_9);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, " 1st non-empty\n2nd non-empty 3rd non-empty ");
EXPECT_DOC_END();
DONE();
}
}
// 7.10
TEST PlainCharacters()
{
// 7.10
TEST PlainCharacters() {
HANDLE(ex7_10);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1301,11 +1239,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.11
TEST PlainImplicitKeys()
{
// 7.11
TEST PlainImplicitKeys() {
HANDLE(ex7_11);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1319,21 +1256,19 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.12
TEST PlainLines()
{
// 7.12
TEST PlainLines() {
HANDLE(ex7_12);
EXPECT_DOC_START();
EXPECT_SCALAR("?", 0, "1st non-empty\n2nd non-empty 3rd non-empty");
EXPECT_DOC_END();
DONE();
}
}
// 7.13
TEST FlowSequence()
{
// 7.13
TEST FlowSequence() {
HANDLE(ex7_13);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1348,11 +1283,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.14
TEST FlowSequenceEntries()
{
// 7.14
TEST FlowSequenceEntries() {
HANDLE(ex7_14);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1369,11 +1303,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.15
TEST FlowMappings()
{
// 7.15
TEST FlowMappings() {
HANDLE(ex7_15);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1392,11 +1325,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.16
TEST FlowMappingEntries()
{
// 7.16
TEST FlowMappingEntries() {
HANDLE(ex7_16);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1409,11 +1341,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.17
TEST FlowMappingSeparateValues()
{
// 7.17
TEST FlowMappingSeparateValues() {
HANDLE(ex7_17);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1428,11 +1359,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.18
TEST FlowMappingAdjacentValues()
{
// 7.18
TEST FlowMappingAdjacentValues() {
HANDLE(ex7_18);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1445,11 +1375,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.19
TEST SinglePairFlowMappings()
{
// 7.19
TEST SinglePairFlowMappings() {
HANDLE(ex7_19);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1460,11 +1389,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.20
TEST SinglePairExplicitEntry()
{
// 7.20
TEST SinglePairExplicitEntry() {
HANDLE(ex7_20);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1475,11 +1403,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.21
TEST SinglePairImplicitEntries()
{
// 7.21
TEST SinglePairImplicitEntries() {
HANDLE(ex7_21);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1507,25 +1434,24 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.22
TEST InvalidImplicitKeys()
{
// 7.22
TEST InvalidImplicitKeys() {
try {
HANDLE(ex7_22);
} catch(const YAML::Exception& e) {
if(e.msg == YAML::ErrorMsg::END_OF_SEQ_FLOW)
}
catch (const YAML::Exception& e) {
if (e.msg == YAML::ErrorMsg::END_OF_SEQ_FLOW)
return true;
throw;
}
return " no exception thrown";
}
}
// 7.23
TEST FlowContent()
{
// 7.23
TEST FlowContent() {
HANDLE(ex7_23);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1543,11 +1469,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.24
TEST FlowNodes()
{
// 7.24
TEST FlowNodes() {
HANDLE(ex7_24);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1559,11 +1484,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.1
TEST BlockScalarHeader()
{
// 8.1
TEST BlockScalarHeader() {
HANDLE(ex8_1);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1574,11 +1498,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.2
TEST BlockIndentationHeader()
{
// 8.2
TEST BlockIndentationHeader() {
HANDLE(ex8_2);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1589,62 +1512,66 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.3
TEST InvalidBlockScalarIndentationIndicators()
{
// 8.3
TEST InvalidBlockScalarIndentationIndicators() {
{
bool threw = false;
try {
HANDLE(ex8_3a);
} catch(const YAML::Exception& e) {
if(e.msg != YAML::ErrorMsg::END_OF_SEQ)
}
catch (const YAML::Exception& e) {
if (e.msg != YAML::ErrorMsg::END_OF_SEQ)
throw;
threw = true;
}
if(!threw)
return " no exception thrown for less indented auto-detecting indentation for a literal block scalar";
if (!threw)
return " no exception thrown for less indented auto-detecting "
"indentation for a literal block scalar";
}
{
bool threw = false;
try {
HANDLE(ex8_3b);
} catch(const YAML::Exception& e) {
if(e.msg != YAML::ErrorMsg::END_OF_SEQ)
}
catch (const YAML::Exception& e) {
if (e.msg != YAML::ErrorMsg::END_OF_SEQ)
throw;
threw = true;
}
if(!threw)
return " no exception thrown for less indented auto-detecting indentation for a folded block scalar";
if (!threw)
return " no exception thrown for less indented auto-detecting "
"indentation for a folded block scalar";
}
{
bool threw = false;
try {
HANDLE(ex8_3c);
} catch(const YAML::Exception& e) {
if(e.msg != YAML::ErrorMsg::END_OF_SEQ)
}
catch (const YAML::Exception& e) {
if (e.msg != YAML::ErrorMsg::END_OF_SEQ)
throw;
threw = true;
}
if(!threw)
return " no exception thrown for less indented explicit indentation for a literal block scalar";
if (!threw)
return " no exception thrown for less indented explicit indentation for "
"a literal block scalar";
}
return true;
}
}
// 8.4
TEST ChompingFinalLineBreak()
{
// 8.4
TEST ChompingFinalLineBreak() {
HANDLE(ex8_4);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1657,11 +1584,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.5
TEST ChompingTrailingLines()
{
// 8.5
TEST ChompingTrailingLines() {
HANDLE(ex8_5);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1670,15 +1596,15 @@ namespace Test {
EXPECT_SCALAR("?", 0, "clip");
EXPECT_SCALAR("!", 0, "# text\n");
EXPECT_SCALAR("?", 0, "keep");
EXPECT_SCALAR("!", 0, "# text\n"); // Note: I believe this is a bug in the YAML spec - it should be "# text\n\n"
EXPECT_SCALAR("!", 0, "# text\n"); // Note: I believe this is a bug in the
// YAML spec - it should be "# text\n\n"
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.6
TEST EmptyScalarChomping()
{
// 8.6
TEST EmptyScalarChomping() {
HANDLE(ex8_6);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1691,81 +1617,81 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.7
TEST LiteralScalar()
{
// 8.7
TEST LiteralScalar() {
HANDLE(ex8_7);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "literal\n\ttext\n");
EXPECT_DOC_END();
DONE();
}
}
// 8.8
TEST LiteralContent()
{
// 8.8
TEST LiteralContent() {
HANDLE(ex8_8);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "\n\nliteral\n \n\ntext\n");
EXPECT_DOC_END();
DONE();
}
}
// 8.9
TEST FoldedScalar()
{
// 8.9
TEST FoldedScalar() {
HANDLE(ex8_9);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "folded text\n");
EXPECT_DOC_END();
DONE();
}
}
// 8.10
TEST FoldedLines()
{
// 8.10
TEST FoldedLines() {
HANDLE(ex8_10);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n");
EXPECT_SCALAR("!", 0,
"\nfolded line\nnext line\n * bullet\n\n * list\n * "
"lines\n\nlast line\n");
EXPECT_DOC_END();
DONE();
}
}
// 8.11
TEST MoreIndentedLines()
{
// 8.11
TEST MoreIndentedLines() {
HANDLE(ex8_11);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n");
EXPECT_SCALAR("!", 0,
"\nfolded line\nnext line\n * bullet\n\n * list\n * "
"lines\n\nlast line\n");
EXPECT_DOC_END();
DONE();
}
}
// 8.12
TEST EmptySeparationLines()
{
// 8.12
TEST EmptySeparationLines() {
HANDLE(ex8_12);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n");
EXPECT_SCALAR("!", 0,
"\nfolded line\nnext line\n * bullet\n\n * list\n * "
"lines\n\nlast line\n");
EXPECT_DOC_END();
DONE();
}
}
// 8.13
TEST FinalEmptyLines()
{
// 8.13
TEST FinalEmptyLines() {
HANDLE(ex8_13);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n");
EXPECT_SCALAR("!", 0,
"\nfolded line\nnext line\n * bullet\n\n * list\n * "
"lines\n\nlast line\n");
EXPECT_DOC_END();
DONE();
}
}
// 8.14
TEST BlockSequence()
{
// 8.14
TEST BlockSequence() {
HANDLE(ex8_14);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1780,11 +1706,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.15
TEST BlockSequenceEntryTypes()
{
// 8.15
TEST BlockSequenceEntryTypes() {
HANDLE(ex8_15);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1801,11 +1726,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.16
TEST BlockMappings()
{
// 8.16
TEST BlockMappings() {
HANDLE(ex8_16);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1817,11 +1741,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.17
TEST ExplicitBlockMappingEntries()
{
// 8.17
TEST ExplicitBlockMappingEntries() {
HANDLE(ex8_17);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1835,11 +1758,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.18
TEST ImplicitBlockMappingEntries()
{
// 8.18
TEST ImplicitBlockMappingEntries() {
HANDLE(ex8_18);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1854,11 +1776,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.19
TEST CompactBlockMappings()
{
// 8.19
TEST CompactBlockMappings() {
HANDLE(ex8_19);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1879,11 +1800,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.20
TEST BlockNodeTypes()
{
// 8.20
TEST BlockNodeTypes() {
HANDLE(ex8_20);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1896,26 +1816,25 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.21
TEST BlockScalarNodes()
{
// 8.21
TEST BlockScalarNodes() {
HANDLE(ex8_21);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
EXPECT_SCALAR("?", 0, "literal");
EXPECT_SCALAR("!", 0, "value"); // Note: I believe this is a bug in the YAML spec - it should be "value\n"
EXPECT_SCALAR("!", 0, "value"); // Note: I believe this is a bug in the YAML
// spec - it should be "value\n"
EXPECT_SCALAR("?", 0, "folded");
EXPECT_SCALAR("!foo", 0, "value");
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.22
TEST BlockCollectionNodes()
{
// 8.22
TEST BlockCollectionNodes() {
HANDLE(ex8_22);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1934,6 +1853,6 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
}
}
}
......@@ -4,18 +4,17 @@
#include "yaml-cpp/eventhandler.h"
#include <iostream>
namespace Test
{
namespace Emitter {
////////////////////////////////////////////////////////////////////////////////////////////////////////
// correct emitting
namespace Test {
namespace Emitter {
////////////////////////////////////////////////////////////////////////////////////////////////////////
// correct emitting
void SimpleScalar(YAML::Emitter& out, std::string& desiredOutput) {
void SimpleScalar(YAML::Emitter& out, std::string& desiredOutput) {
out << "Hello, World!";
desiredOutput = "Hello, World!";
}
}
void SimpleSeq(YAML::Emitter& out, std::string& desiredOutput) {
void SimpleSeq(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << "eggs";
out << "bread";
......@@ -23,9 +22,9 @@ namespace Test
out << YAML::EndSeq;
desiredOutput = "- eggs\n- bread\n- milk";
}
}
void SimpleFlowSeq(YAML::Emitter& out, std::string& desiredOutput) {
void SimpleFlowSeq(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Flow;
out << YAML::BeginSeq;
out << "Larry";
......@@ -34,35 +33,37 @@ namespace Test
out << YAML::EndSeq;
desiredOutput = "[Larry, Curly, Moe]";
}
}
void EmptyFlowSeq(YAML::Emitter& out, std::string& desiredOutput) {
void EmptyFlowSeq(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Flow;
out << YAML::BeginSeq;
out << YAML::EndSeq;
desiredOutput = "[]";
}
}
void NestedBlockSeq(YAML::Emitter& out, std::string& desiredOutput) {
void NestedBlockSeq(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << "item 1";
out << YAML::BeginSeq << "subitem 1" << "subitem 2" << YAML::EndSeq;
out << YAML::BeginSeq << "subitem 1"
<< "subitem 2" << YAML::EndSeq;
out << YAML::EndSeq;
desiredOutput = "- item 1\n-\n - subitem 1\n - subitem 2";
}
}
void NestedFlowSeq(YAML::Emitter& out, std::string& desiredOutput) {
void NestedFlowSeq(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << "one";
out << YAML::Flow << YAML::BeginSeq << "two" << "three" << YAML::EndSeq;
out << YAML::Flow << YAML::BeginSeq << "two"
<< "three" << YAML::EndSeq;
out << YAML::EndSeq;
desiredOutput = "- one\n- [two, three]";
}
}
void SimpleMap(YAML::Emitter& out, std::string& desiredOutput) {
void SimpleMap(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginMap;
out << YAML::Key << "name";
out << YAML::Value << "Ryan Braun";
......@@ -71,9 +72,9 @@ namespace Test
out << YAML::EndMap;
desiredOutput = "name: Ryan Braun\nposition: 3B";
}
}
void SimpleFlowMap(YAML::Emitter& out, std::string& desiredOutput) {
void SimpleFlowMap(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Flow;
out << YAML::BeginMap;
out << YAML::Key << "shape";
......@@ -83,20 +84,21 @@ namespace Test
out << YAML::EndMap;
desiredOutput = "{shape: square, color: blue}";
}
}
void MapAndList(YAML::Emitter& out, std::string& desiredOutput) {
void MapAndList(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginMap;
out << YAML::Key << "name";
out << YAML::Value << "Barack Obama";
out << YAML::Key << "children";
out << YAML::Value << YAML::BeginSeq << "Sasha" << "Malia" << YAML::EndSeq;
out << YAML::Value << YAML::BeginSeq << "Sasha"
<< "Malia" << YAML::EndSeq;
out << YAML::EndMap;
desiredOutput = "name: Barack Obama\nchildren:\n - Sasha\n - Malia";
}
}
void ListAndMap(YAML::Emitter& out, std::string& desiredOutput) {
void ListAndMap(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << "item 1";
out << YAML::BeginMap;
......@@ -107,9 +109,9 @@ namespace Test
out << YAML::EndSeq;
desiredOutput = "- item 1\n- pens: 8\n pencils: 14\n- item 2";
}
}
void NestedBlockMap(YAML::Emitter& out, std::string& desiredOutput) {
void NestedBlockMap(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginMap;
out << YAML::Key << "name";
out << YAML::Value << "Fred";
......@@ -122,10 +124,11 @@ namespace Test
out << YAML::EndMap;
out << YAML::EndMap;
desiredOutput = "name: Fred\ngrades:\n algebra: A\n physics: C+\n literature: B";
}
desiredOutput =
"name: Fred\ngrades:\n algebra: A\n physics: C+\n literature: B";
}
void NestedFlowMap(YAML::Emitter& out, std::string& desiredOutput) {
void NestedFlowMap(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Flow;
out << YAML::BeginMap;
out << YAML::Key << "name";
......@@ -139,10 +142,11 @@ namespace Test
out << YAML::EndMap;
out << YAML::EndMap;
desiredOutput = "{name: Fred, grades: {algebra: A, physics: C+, literature: B}}";
}
desiredOutput =
"{name: Fred, grades: {algebra: A, physics: C+, literature: B}}";
}
void MapListMix(YAML::Emitter& out, std::string& desiredOutput) {
void MapListMix(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginMap;
out << YAML::Key << "name";
out << YAML::Value << "Bob";
......@@ -153,10 +157,9 @@ namespace Test
out << YAML::EndMap;
desiredOutput = "name: Bob\nposition: [2, 4]\ninvincible: off";
}
}
void SimpleLongKey(YAML::Emitter& out, std::string& desiredOutput)
{
void SimpleLongKey(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::LongKey;
out << YAML::BeginMap;
out << YAML::Key << "height";
......@@ -166,10 +169,9 @@ namespace Test
out << YAML::EndMap;
desiredOutput = "? height\n: 5'9\"\n? weight\n: 145";
}
}
void SingleLongKey(YAML::Emitter& out, std::string& desiredOutput)
{
void SingleLongKey(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginMap;
out << YAML::Key << "age";
out << YAML::Value << "24";
......@@ -180,10 +182,9 @@ namespace Test
out << YAML::EndMap;
desiredOutput = "age: 24\n? height\n: 5'9\"\nweight: 145";
}
}
void ComplexLongKey(YAML::Emitter& out, std::string& desiredOutput)
{
void ComplexLongKey(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::LongKey;
out << YAML::BeginMap;
out << YAML::Key << YAML::BeginSeq << 1 << 3 << YAML::EndSeq;
......@@ -193,10 +194,9 @@ namespace Test
out << YAML::EndMap;
desiredOutput = "? - 1\n - 3\n: monster\n? [2, 0]\n: demon";
}
}
void AutoLongKey(YAML::Emitter& out, std::string& desiredOutput)
{
void AutoLongKey(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginMap;
out << YAML::Key << YAML::BeginSeq << 1 << 3 << YAML::EndSeq;
out << YAML::Value << "monster";
......@@ -207,34 +207,37 @@ namespace Test
out << YAML::EndMap;
desiredOutput = "? - 1\n - 3\n: monster\n[2, 0]: demon\nthe origin: angel";
}
}
void ScalarFormat(YAML::Emitter& out, std::string& desiredOutput)
{
void ScalarFormat(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << "simple scalar";
out << YAML::SingleQuoted << "explicit single-quoted scalar";
out << YAML::DoubleQuoted << "explicit double-quoted scalar";
out << "auto-detected\ndouble-quoted scalar";
out << "a non-\"auto-detected\" double-quoted scalar";
out << YAML::Literal << "literal scalar\nthat may span\nmany, many\nlines and have \"whatever\" crazy\tsymbols that we like";
out << YAML::Literal << "literal scalar\nthat may span\nmany, many\nlines "
"and have \"whatever\" crazy\tsymbols that we like";
out << YAML::EndSeq;
desiredOutput = "- simple scalar\n- 'explicit single-quoted scalar'\n- \"explicit double-quoted scalar\"\n- \"auto-detected\\ndouble-quoted scalar\"\n- a non-\"auto-detected\" double-quoted scalar\n- |\n literal scalar\n that may span\n many, many\n lines and have \"whatever\" crazy\tsymbols that we like";
}
desiredOutput =
"- simple scalar\n- 'explicit single-quoted scalar'\n- \"explicit "
"double-quoted scalar\"\n- \"auto-detected\\ndouble-quoted scalar\"\n- a "
"non-\"auto-detected\" double-quoted scalar\n- |\n literal scalar\n "
"that may span\n many, many\n lines and have \"whatever\" "
"crazy\tsymbols that we like";
}
void AutoLongKeyScalar(YAML::Emitter& out, std::string& desiredOutput)
{
void AutoLongKeyScalar(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginMap;
out << YAML::Key << YAML::Literal << "multi-line\nscalar";
out << YAML::Value << "and its value";
out << YAML::EndMap;
desiredOutput = "? |\n multi-line\n scalar\n: and its value";
}
}
void LongKeyFlowMap(YAML::Emitter& out, std::string& desiredOutput)
{
void LongKeyFlowMap(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Flow;
out << YAML::BeginMap;
out << YAML::Key << "simple key";
......@@ -244,10 +247,9 @@ namespace Test
out << YAML::EndMap;
desiredOutput = "{simple key: and value, ? long key: and its value}";
}
}
void BlockMapAsKey(YAML::Emitter& out, std::string& desiredOutput)
{
void BlockMapAsKey(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginMap;
out << YAML::Key;
out << YAML::BeginMap;
......@@ -259,10 +261,9 @@ namespace Test
out << YAML::EndMap;
desiredOutput = "? key: value\n next key: next value\n: total value";
}
}
void AliasAndAnchor(YAML::Emitter& out, std::string& desiredOutput)
{
void AliasAndAnchor(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << YAML::Anchor("fred");
out << YAML::BeginMap;
......@@ -273,20 +274,18 @@ namespace Test
out << YAML::EndSeq;
desiredOutput = "- &fred\n name: Fred\n age: 42\n- *fred";
}
}
void AliasAndAnchorWithNull(YAML::Emitter& out, std::string& desiredOutput)
{
void AliasAndAnchorWithNull(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << YAML::Anchor("fred") << YAML::Null;
out << YAML::Alias("fred");
out << YAML::EndSeq;
desiredOutput = "- &fred ~\n- *fred";
}
}
void AliasAndAnchorInFlow(YAML::Emitter& out, std::string& desiredOutput)
{
void AliasAndAnchorInFlow(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Flow << YAML::BeginSeq;
out << YAML::Anchor("fred");
out << YAML::BeginMap;
......@@ -297,101 +296,93 @@ namespace Test
out << YAML::EndSeq;
desiredOutput = "[&fred {name: Fred, age: 42}, *fred]";
}
}
void SimpleVerbatimTag(YAML::Emitter& out, std::string& desiredOutput)
{
void SimpleVerbatimTag(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::VerbatimTag("!foo") << "bar";
desiredOutput = "!<!foo> bar";
}
}
void VerbatimTagInBlockSeq(YAML::Emitter& out, std::string& desiredOutput)
{
void VerbatimTagInBlockSeq(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << YAML::VerbatimTag("!foo") << "bar";
out << "baz";
out << YAML::EndSeq;
desiredOutput = "- !<!foo> bar\n- baz";
}
}
void VerbatimTagInFlowSeq(YAML::Emitter& out, std::string& desiredOutput)
{
void VerbatimTagInFlowSeq(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Flow << YAML::BeginSeq;
out << YAML::VerbatimTag("!foo") << "bar";
out << "baz";
out << YAML::EndSeq;
desiredOutput = "[!<!foo> bar, baz]";
}
}
void VerbatimTagInFlowSeqWithNull(YAML::Emitter& out, std::string& desiredOutput)
{
void VerbatimTagInFlowSeqWithNull(YAML::Emitter& out,
std::string& desiredOutput) {
out << YAML::Flow << YAML::BeginSeq;
out << YAML::VerbatimTag("!foo") << YAML::Null;
out << "baz";
out << YAML::EndSeq;
desiredOutput = "[!<!foo> ~, baz]";
}
}
void VerbatimTagInBlockMap(YAML::Emitter& out, std::string& desiredOutput)
{
void VerbatimTagInBlockMap(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginMap;
out << YAML::Key << YAML::VerbatimTag("!foo") << "bar";
out << YAML::Value << YAML::VerbatimTag("!waz") << "baz";
out << YAML::EndMap;
desiredOutput = "!<!foo> bar: !<!waz> baz";
}
}
void VerbatimTagInFlowMap(YAML::Emitter& out, std::string& desiredOutput)
{
void VerbatimTagInFlowMap(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Flow << YAML::BeginMap;
out << YAML::Key << YAML::VerbatimTag("!foo") << "bar";
out << YAML::Value << "baz";
out << YAML::EndMap;
desiredOutput = "{!<!foo> bar: baz}";
}
}
void VerbatimTagInFlowMapWithNull(YAML::Emitter& out, std::string& desiredOutput)
{
void VerbatimTagInFlowMapWithNull(YAML::Emitter& out,
std::string& desiredOutput) {
out << YAML::Flow << YAML::BeginMap;
out << YAML::Key << YAML::VerbatimTag("!foo") << YAML::Null;
out << YAML::Value << "baz";
out << YAML::EndMap;
desiredOutput = "{!<!foo> ~: baz}";
}
}
void VerbatimTagWithEmptySeq(YAML::Emitter& out, std::string& desiredOutput)
{
void VerbatimTagWithEmptySeq(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::VerbatimTag("!foo") << YAML::BeginSeq << YAML::EndSeq;
desiredOutput = "!<!foo>\n[]";
}
}
void VerbatimTagWithEmptyMap(YAML::Emitter& out, std::string& desiredOutput)
{
void VerbatimTagWithEmptyMap(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::VerbatimTag("!bar") << YAML::BeginMap << YAML::EndMap;
desiredOutput = "!<!bar>\n{}";
}
}
void VerbatimTagWithEmptySeqAndMap(YAML::Emitter& out, std::string& desiredOutput)
{
void VerbatimTagWithEmptySeqAndMap(YAML::Emitter& out,
std::string& desiredOutput) {
out << YAML::BeginSeq;
out << YAML::VerbatimTag("!foo") << YAML::BeginSeq << YAML::EndSeq;
out << YAML::VerbatimTag("!bar") << YAML::BeginMap << YAML::EndMap;
out << YAML::EndSeq;
desiredOutput = "- !<!foo>\n []\n- !<!bar>\n {}";
}
}
void ByKindTagWithScalar(YAML::Emitter& out, std::string& desiredOutput)
{
void ByKindTagWithScalar(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << YAML::DoubleQuoted << "12";
out << "12";
......@@ -399,24 +390,21 @@ namespace Test
out << YAML::EndSeq;
desiredOutput = "- \"12\"\n- 12\n- ! 12";
}
}
void LocalTagWithScalar(YAML::Emitter& out, std::string& desiredOutput)
{
void LocalTagWithScalar(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::LocalTag("foo") << "bar";
desiredOutput = "!foo bar";
}
}
void BadLocalTag(YAML::Emitter& out, std::string& desiredError)
{
void BadLocalTag(YAML::Emitter& out, std::string& desiredError) {
out << YAML::LocalTag("e!far") << "bar";
desiredError = "invalid tag";
}
}
void ComplexDoc(YAML::Emitter& out, std::string& desiredOutput)
{
void ComplexDoc(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginMap;
out << YAML::Key << "receipt";
out << YAML::Value << "Oz-Ware Purchase Invoice";
......@@ -468,13 +456,19 @@ namespace Test
out << YAML::Value << YAML::Alias("id001");
out << YAML::EndMap;
desiredOutput = "receipt: Oz-Ware Purchase Invoice\ndate: 2007-08-06\ncustomer:\n given: Dorothy\n family: Gale\nitems:\n - part_no: A4786\n descrip: Water Bucket (Filled)\n price: 1.47\n quantity: 4\n - part_no: E1628\n descrip: High Heeled \"Ruby\" Slippers\n price: 100.27\n quantity: 1\nbill-to: &id001\n street: |\n 123 Tornado Alley\n Suite 16\n city: East Westville\n state: KS\nship-to: *id001";
}
desiredOutput =
"receipt: Oz-Ware Purchase Invoice\ndate: 2007-08-06\ncustomer:\n "
"given: Dorothy\n family: Gale\nitems:\n - part_no: A4786\n "
"descrip: Water Bucket (Filled)\n price: 1.47\n quantity: 4\n - "
"part_no: E1628\n descrip: High Heeled \"Ruby\" Slippers\n price: "
"100.27\n quantity: 1\nbill-to: &id001\n street: |\n 123 Tornado "
"Alley\n Suite 16\n city: East Westville\n state: KS\nship-to: "
"*id001";
}
void STLContainers(YAML::Emitter& out, std::string& desiredOutput)
{
void STLContainers(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
std::vector <int> primes;
std::vector<int> primes;
primes.push_back(2);
primes.push_back(3);
primes.push_back(5);
......@@ -482,128 +476,141 @@ namespace Test
primes.push_back(11);
primes.push_back(13);
out << YAML::Flow << primes;
std::map <std::string, int> ages;
std::map<std::string, int> ages;
ages["Daniel"] = 26;
ages["Jesse"] = 24;
out << ages;
out << YAML::EndSeq;
desiredOutput = "- [2, 3, 5, 7, 11, 13]\n- Daniel: 26\n Jesse: 24";
}
}
void SimpleComment(YAML::Emitter& out, std::string& desiredOutput)
{
void SimpleComment(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginMap;
out << YAML::Key << "method";
out << YAML::Value << "least squares" << YAML::Comment("should we change this method?");
out << YAML::Value << "least squares"
<< YAML::Comment("should we change this method?");
out << YAML::EndMap;
desiredOutput = "method: least squares # should we change this method?";
}
}
void MultiLineComment(YAML::Emitter& out, std::string& desiredOutput)
{
void MultiLineComment(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << "item 1" << YAML::Comment("really really long\ncomment that couldn't possibly\nfit on one line");
out << "item 1" << YAML::Comment(
"really really long\ncomment that couldn't "
"possibly\nfit on one line");
out << "item 2";
out << YAML::EndSeq;
desiredOutput = "- item 1 # really really long\n # comment that couldn't possibly\n # fit on one line\n- item 2";
}
desiredOutput =
"- item 1 # really really long\n # comment that couldn't "
"possibly\n # fit on one line\n- item 2";
}
void ComplexComments(YAML::Emitter& out, std::string& desiredOutput)
{
void ComplexComments(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginMap;
out << YAML::LongKey << YAML::Key << "long key" << YAML::Comment("long key");
out << YAML::Value << "value";
out << YAML::EndMap;
desiredOutput = "? long key # long key\n: value";
}
}
void InitialComment(YAML::Emitter& out, std::string& desiredOutput)
{
void InitialComment(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Comment("A comment describing the purpose of the file.");
out << YAML::BeginMap << YAML::Key << "key" << YAML::Value << "value" << YAML::EndMap;
out << YAML::BeginMap << YAML::Key << "key" << YAML::Value << "value"
<< YAML::EndMap;
desiredOutput = "# A comment describing the purpose of the file.\nkey: value";
}
}
void InitialCommentWithDocIndicator(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::BeginDoc << YAML::Comment("A comment describing the purpose of the file.");
out << YAML::BeginMap << YAML::Key << "key" << YAML::Value << "value" << YAML::EndMap;
void InitialCommentWithDocIndicator(YAML::Emitter& out,
std::string& desiredOutput) {
out << YAML::BeginDoc
<< YAML::Comment("A comment describing the purpose of the file.");
out << YAML::BeginMap << YAML::Key << "key" << YAML::Value << "value"
<< YAML::EndMap;
desiredOutput = "---\n# A comment describing the purpose of the file.\nkey: value";
}
desiredOutput =
"---\n# A comment describing the purpose of the file.\nkey: value";
}
void CommentInFlowSeq(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::Flow << YAML::BeginSeq << "foo" << YAML::Comment("foo!") << "bar" << YAML::EndSeq;
void CommentInFlowSeq(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Flow << YAML::BeginSeq << "foo" << YAML::Comment("foo!") << "bar"
<< YAML::EndSeq;
desiredOutput = "[foo, # foo!\nbar]";
}
}
void CommentInFlowMap(YAML::Emitter& out, std::string& desiredOutput)
{
void CommentInFlowMap(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Flow << YAML::BeginMap;
out << YAML::Key << "foo" << YAML::Value << "foo value";
out << YAML::Key << "bar" << YAML::Value << "bar value" << YAML::Comment("bar!");
out << YAML::Key << "baz" << YAML::Value << "baz value" << YAML::Comment("baz!");
out << YAML::Key << "bar" << YAML::Value << "bar value"
<< YAML::Comment("bar!");
out << YAML::Key << "baz" << YAML::Value << "baz value"
<< YAML::Comment("baz!");
out << YAML::EndMap;
desiredOutput = "{foo: foo value, bar: bar value, # bar!\nbaz: baz value, # baz!\n}";
}
desiredOutput =
"{foo: foo value, bar: bar value, # bar!\nbaz: baz value, # baz!\n}";
}
void Indentation(YAML::Emitter& out, std::string& desiredOutput)
{
void Indentation(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Indent(4);
out << YAML::BeginSeq;
out << YAML::BeginMap;
out << YAML::Key << "key 1" << YAML::Value << "value 1";
out << YAML::Key << "key 2" << YAML::Value << YAML::BeginSeq << "a" << "b" << "c" << YAML::EndSeq;
out << YAML::Key << "key 2" << YAML::Value << YAML::BeginSeq << "a"
<< "b"
<< "c" << YAML::EndSeq;
out << YAML::EndMap;
out << YAML::EndSeq;
desiredOutput = "- key 1: value 1\n key 2:\n - a\n - b\n - c";
}
desiredOutput =
"- key 1: value 1\n key 2:\n - a\n - b\n - "
" c";
}
void SimpleGlobalSettings(YAML::Emitter& out, std::string& desiredOutput)
{
void SimpleGlobalSettings(YAML::Emitter& out, std::string& desiredOutput) {
out.SetIndent(4);
out.SetMapFormat(YAML::LongKey);
out << YAML::BeginSeq;
out << YAML::BeginMap;
out << YAML::Key << "key 1" << YAML::Value << "value 1";
out << YAML::Key << "key 2" << YAML::Value << YAML::Flow << YAML::BeginSeq << "a" << "b" << "c" << YAML::EndSeq;
out << YAML::Key << "key 2" << YAML::Value << YAML::Flow << YAML::BeginSeq
<< "a"
<< "b"
<< "c" << YAML::EndSeq;
out << YAML::EndMap;
out << YAML::EndSeq;
desiredOutput = "- ? key 1\n : value 1\n ? key 2\n : [a, b, c]";
}
}
void ComplexGlobalSettings(YAML::Emitter& out, std::string& desiredOutput)
{
void ComplexGlobalSettings(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << YAML::Block;
out << YAML::BeginMap;
out << YAML::Key << "key 1" << YAML::Value << "value 1";
out << YAML::Key << "key 2" << YAML::Value;
out.SetSeqFormat(YAML::Flow);
out << YAML::BeginSeq << "a" << "b" << "c" << YAML::EndSeq;
out << YAML::BeginSeq << "a"
<< "b"
<< "c" << YAML::EndSeq;
out << YAML::EndMap;
out << YAML::BeginMap;
out << YAML::Key << YAML::BeginSeq << 1 << 2 << YAML::EndSeq;
out << YAML::Value << YAML::BeginMap << YAML::Key << "a" << YAML::Value << "b" << YAML::EndMap;
out << YAML::Value << YAML::BeginMap << YAML::Key << "a" << YAML::Value << "b"
<< YAML::EndMap;
out << YAML::EndMap;
out << YAML::EndSeq;
desiredOutput = "- key 1: value 1\n key 2: [a, b, c]\n- [1, 2]:\n a: b";
}
}
void Null(YAML::Emitter& out, std::string& desiredOutput)
{
void Null(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << YAML::Null;
out << YAML::BeginMap;
......@@ -613,194 +620,197 @@ namespace Test
out << YAML::EndSeq;
desiredOutput = "- ~\n- null value: ~\n ~: null key";
}
}
void EscapedUnicode(YAML::Emitter& out, std::string& desiredOutput)
{
void EscapedUnicode(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::EscapeNonAscii << "\x24 \xC2\xA2 \xE2\x82\xAC \xF0\xA4\xAD\xA2";
desiredOutput = "\"$ \\xa2 \\u20ac \\U00024b62\"";
}
}
void Unicode(YAML::Emitter& out, std::string& desiredOutput)
{
void Unicode(YAML::Emitter& out, std::string& desiredOutput) {
out << "\x24 \xC2\xA2 \xE2\x82\xAC \xF0\xA4\xAD\xA2";
desiredOutput = "\x24 \xC2\xA2 \xE2\x82\xAC \xF0\xA4\xAD\xA2";
}
}
void DoubleQuotedUnicode(YAML::Emitter& out, std::string& desiredOutput)
{
void DoubleQuotedUnicode(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::DoubleQuoted << "\x24 \xC2\xA2 \xE2\x82\xAC \xF0\xA4\xAD\xA2";
desiredOutput = "\"\x24 \xC2\xA2 \xE2\x82\xAC \xF0\xA4\xAD\xA2\"";
}
}
struct Foo {
Foo(): x(0) {}
Foo(int x_, const std::string& bar_): x(x_), bar(bar_) {}
struct Foo {
Foo() : x(0) {}
Foo(int x_, const std::string& bar_) : x(x_), bar(bar_) {}
int x;
std::string bar;
};
};
YAML::Emitter& operator << (YAML::Emitter& out, const Foo& foo) {
YAML::Emitter& operator<<(YAML::Emitter& out, const Foo& foo) {
out << YAML::BeginMap;
out << YAML::Key << "x" << YAML::Value << foo.x;
out << YAML::Key << "bar" << YAML::Value << foo.bar;
out << YAML::EndMap;
return out;
}
}
void UserType(YAML::Emitter& out, std::string& desiredOutput)
{
void UserType(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << Foo(5, "hello");
out << Foo(3, "goodbye");
out << YAML::EndSeq;
desiredOutput = "- x: 5\n bar: hello\n- x: 3\n bar: goodbye";
}
}
void UserTypeInContainer(YAML::Emitter& out, std::string& desiredOutput)
{
void UserTypeInContainer(YAML::Emitter& out, std::string& desiredOutput) {
std::vector<Foo> fv;
fv.push_back(Foo(5, "hello"));
fv.push_back(Foo(3, "goodbye"));
out << fv;
desiredOutput = "- x: 5\n bar: hello\n- x: 3\n bar: goodbye";
}
}
template <typename T>
YAML::Emitter& operator << (YAML::Emitter& out, const T *v) {
if(v)
template <typename T>
YAML::Emitter& operator<<(YAML::Emitter& out, const T* v) {
if (v)
out << *v;
else
out << YAML::Null;
return out;
}
}
void PointerToInt(YAML::Emitter& out, std::string& desiredOutput)
{
void PointerToInt(YAML::Emitter& out, std::string& desiredOutput) {
int foo = 5;
int *bar = &foo;
int *baz = 0;
int* bar = &foo;
int* baz = 0;
out << YAML::BeginSeq;
out << bar << baz;
out << YAML::EndSeq;
desiredOutput = "- 5\n- ~";
}
}
void PointerToUserType(YAML::Emitter& out, std::string& desiredOutput)
{
void PointerToUserType(YAML::Emitter& out, std::string& desiredOutput) {
Foo foo(5, "hello");
Foo *bar = &foo;
Foo *baz = 0;
Foo* bar = &foo;
Foo* baz = 0;
out << YAML::BeginSeq;
out << bar << baz;
out << YAML::EndSeq;
desiredOutput = "- x: 5\n bar: hello\n- ~";
}
}
void NewlineAtEnd(YAML::Emitter& out, std::string& desiredOutput)
{
void NewlineAtEnd(YAML::Emitter& out, std::string& desiredOutput) {
out << "Hello" << YAML::Newline << YAML::Newline;
desiredOutput = "Hello\n\n";
}
}
void NewlineInBlockSequence(YAML::Emitter& out, std::string& desiredOutput)
{
void NewlineInBlockSequence(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << "a" << YAML::Newline << "b" << "c" << YAML::Newline << "d";
out << "a" << YAML::Newline << "b"
<< "c" << YAML::Newline << "d";
out << YAML::EndSeq;
desiredOutput = "- a\n\n- b\n- c\n\n- d";
}
}
void NewlineInFlowSequence(YAML::Emitter& out, std::string& desiredOutput)
{
void NewlineInFlowSequence(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Flow << YAML::BeginSeq;
out << "a" << YAML::Newline << "b" << "c" << YAML::Newline << "d";
out << "a" << YAML::Newline << "b"
<< "c" << YAML::Newline << "d";
out << YAML::EndSeq;
desiredOutput = "[a,\nb, c,\nd]";
}
}
void NewlineInBlockMap(YAML::Emitter& out, std::string& desiredOutput)
{
void NewlineInBlockMap(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginMap;
out << YAML::Key << "a" << YAML::Value << "foo" << YAML::Newline;
out << YAML::Key << "b" << YAML::Newline << YAML::Value << "bar";
out << YAML::LongKey << YAML::Key << "c" << YAML::Newline << YAML::Value << "car";
out << YAML::LongKey << YAML::Key << "c" << YAML::Newline << YAML::Value
<< "car";
out << YAML::EndMap;
desiredOutput = "a: foo\nb:\n bar\n? c\n\n: car";
}
}
void NewlineInFlowMap(YAML::Emitter& out, std::string& desiredOutput)
{
void NewlineInFlowMap(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Flow << YAML::BeginMap;
out << YAML::Key << "a" << YAML::Value << "foo" << YAML::Newline;
out << YAML::Key << "b" << YAML::Value << "bar";
out << YAML::EndMap;
desiredOutput = "{a: foo,\nb: bar}";
}
}
void LotsOfNewlines(YAML::Emitter& out, std::string& desiredOutput)
{
void LotsOfNewlines(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << "a" << YAML::Newline;
out << YAML::BeginSeq;
out << "b" << "c" << YAML::Newline;
out << "b"
<< "c" << YAML::Newline;
out << YAML::EndSeq;
out << YAML::Newline;
out << YAML::BeginMap;
out << YAML::Newline << YAML::Key << "d" << YAML::Value << YAML::Newline << "e";
out << YAML::LongKey << YAML::Key << "f" << YAML::Newline << YAML::Value << "foo";
out << YAML::Newline << YAML::Key << "d" << YAML::Value << YAML::Newline
<< "e";
out << YAML::LongKey << YAML::Key << "f" << YAML::Newline << YAML::Value
<< "foo";
out << YAML::EndMap;
out << YAML::EndSeq;
desiredOutput = "- a\n\n-\n - b\n - c\n\n\n-\n d:\n e\n ? f\n\n : foo";
}
desiredOutput =
"- a\n\n-\n - b\n - c\n\n\n-\n d:\n e\n ? f\n\n : foo";
}
void Binary(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::Binary(reinterpret_cast<const unsigned char*>("Hello, World!"), 13);
void Binary(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Binary(reinterpret_cast<const unsigned char*>("Hello, World!"),
13);
desiredOutput = "!!binary \"SGVsbG8sIFdvcmxkIQ==\"";
}
}
void LongBinary(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::Binary(reinterpret_cast<const unsigned char*>("Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.\n"), 270);
desiredOutput = "!!binary \"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4K\"";
}
void LongBinary(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Binary(
reinterpret_cast<const unsigned char*>(
"Man is distinguished, not only by his reason, but by this "
"singular passion from other animals, which is a lust of the "
"mind, that by a perseverance of delight in the continued and "
"indefatigable generation of knowledge, exceeds the short "
"vehemence of any carnal pleasure.\n"),
270);
desiredOutput =
"!!binary "
"\"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieS"
"B0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIG"
"x1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbi"
"B0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZG"
"dlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS"
"4K\"";
}
void EmptyBinary(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::Binary(reinterpret_cast<const unsigned char *>(""), 0);
void EmptyBinary(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Binary(reinterpret_cast<const unsigned char*>(""), 0);
desiredOutput = "!!binary \"\"";
}
}
void ColonAtEndOfScalar(YAML::Emitter& out, std::string& desiredOutput)
{
void ColonAtEndOfScalar(YAML::Emitter& out, std::string& desiredOutput) {
out << "a:";
desiredOutput = "\"a:\"";
}
}
void ColonAsScalar(YAML::Emitter& out, std::string& desiredOutput)
{
void ColonAsScalar(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginMap;
out << YAML::Key << "apple" << YAML::Value << ":";
out << YAML::Key << "banana" << YAML::Value << ":";
out << YAML::EndMap;
desiredOutput = "apple: \":\"\nbanana: \":\"";
}
}
void ColonAtEndOfScalarInFlow(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::Flow << YAML::BeginMap << YAML::Key << "C:" << YAML::Value << "C:" << YAML::EndMap;
void ColonAtEndOfScalarInFlow(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Flow << YAML::BeginMap << YAML::Key << "C:" << YAML::Value
<< "C:" << YAML::EndMap;
desiredOutput = "{\"C:\": \"C:\"}";
}
}
void BoolFormatting(YAML::Emitter& out, std::string& desiredOutput)
{
void BoolFormatting(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << YAML::TrueFalseBool << YAML::UpperCase << true;
out << YAML::TrueFalseBool << YAML::CamelCase << true;
......@@ -832,10 +842,9 @@ namespace Test
"- YES\n- Yes\n- yes\n- NO\n- No\n- no\n"
"- ON\n- On\n- on\n- OFF\n- Off\n- off\n"
"- Y\n- Y\n- y\n- N\n- N\n- n";
}
}
void DocStartAndEnd(YAML::Emitter& out, std::string& desiredOutput)
{
void DocStartAndEnd(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginDoc;
out << YAML::BeginSeq << 1 << 2 << 3 << YAML::EndSeq;
out << YAML::BeginDoc;
......@@ -845,27 +854,25 @@ namespace Test
out << YAML::EndDoc;
out << YAML::BeginDoc;
out << YAML::VerbatimTag("foo") << "bar";
desiredOutput = "---\n- 1\n- 2\n- 3\n---\nHi there!\n...\n...\n...\n---\n!<foo> bar";
}
desiredOutput =
"---\n- 1\n- 2\n- 3\n---\nHi there!\n...\n...\n...\n---\n!<foo> bar";
}
void ImplicitDocStart(YAML::Emitter& out, std::string& desiredOutput)
{
void ImplicitDocStart(YAML::Emitter& out, std::string& desiredOutput) {
out << "Hi";
out << "Bye";
out << "Oops";
desiredOutput = "Hi\n---\nBye\n---\nOops";
}
}
void EmptyString(YAML::Emitter& out, std::string& desiredOutput)
{
void EmptyString(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginMap;
out << YAML::Key << "key" << YAML::Value << "";
out << YAML::EndMap;
desiredOutput = "key: \"\"";
}
}
void SingleChar(YAML::Emitter& out, std::string& desiredOutput)
{
void SingleChar(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << 'a';
out << ':';
......@@ -875,46 +882,41 @@ namespace Test
out << '\t';
out << YAML::EndSeq;
desiredOutput = "- a\n- \":\"\n- \"\\x10\"\n- \"\\n\"\n- \" \"\n- \"\\t\"";
}
}
void DefaultPrecision(YAML::Emitter& out, std::string& desiredOutput)
{
void DefaultPrecision(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << 1.234f;
out << 3.14159265358979;
out << YAML::EndSeq;
desiredOutput = "- 1.234\n- 3.14159265358979";
}
}
void SetPrecision(YAML::Emitter& out, std::string& desiredOutput)
{
void SetPrecision(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginSeq;
out << YAML::FloatPrecision(3) << 1.234f;
out << YAML::DoublePrecision(6) << 3.14159265358979;
out << YAML::EndSeq;
desiredOutput = "- 1.23\n- 3.14159";
}
}
void DashInBlockContext(YAML::Emitter& out, std::string& desiredOutput)
{
void DashInBlockContext(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::BeginMap;
out << YAML::Key << "key" << YAML::Value << "-";
out << YAML::EndMap;
desiredOutput = "key: \"-\"";
}
}
void HexAndOct(YAML::Emitter& out, std::string& desiredOutput)
{
void HexAndOct(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Flow << YAML::BeginSeq;
out << 31;
out << YAML::Hex << 31;
out << YAML::Oct << 31;
out << YAML::EndSeq;
desiredOutput = "[31, 0x1f, 037]";
}
}
void CompactMapWithNewline(YAML::Emitter& out, std::string& desiredOutput)
{
void CompactMapWithNewline(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::Comment("Characteristics");
out << YAML::BeginSeq;
out << YAML::BeginMap;
......@@ -937,20 +939,18 @@ namespace Test
"# Skills\n"
"- attack: 23\n"
" intelligence: 56";
}
}
void ForceSingleQuotedToDouble(YAML::Emitter& out, std::string& desiredOutput)
{
void ForceSingleQuotedToDouble(YAML::Emitter& out, std::string& desiredOutput) {
out << YAML::SingleQuoted << "Hello\nWorld";
desiredOutput = "\"Hello\\nWorld\"";
}
}
////////////////////////////////////////////////////////////////////////////////
// incorrect emitting
////////////////////////////////////////////////////////////////////////////////
// incorrect emitting
void ExtraEndSeq(YAML::Emitter& out, std::string& desiredError)
{
void ExtraEndSeq(YAML::Emitter& out, std::string& desiredError) {
desiredError = YAML::ErrorMsg::UNEXPECTED_END_SEQ;
out << YAML::BeginSeq;
......@@ -958,68 +958,70 @@ namespace Test
out << "World";
out << YAML::EndSeq;
out << YAML::EndSeq;
}
}
void ExtraEndMap(YAML::Emitter& out, std::string& desiredError)
{
void ExtraEndMap(YAML::Emitter& out, std::string& desiredError) {
desiredError = YAML::ErrorMsg::UNEXPECTED_END_MAP;
out << YAML::BeginMap;
out << YAML::Key << "Hello" << YAML::Value << "World";
out << YAML::EndMap;
out << YAML::EndMap;
}
}
void InvalidAnchor(YAML::Emitter& out, std::string& desiredError)
{
void InvalidAnchor(YAML::Emitter& out, std::string& desiredError) {
desiredError = YAML::ErrorMsg::INVALID_ANCHOR;
out << YAML::BeginSeq;
out << YAML::Anchor("new\nline") << "Test";
out << YAML::EndSeq;
}
}
void InvalidAlias(YAML::Emitter& out, std::string& desiredError)
{
void InvalidAlias(YAML::Emitter& out, std::string& desiredError) {
desiredError = YAML::ErrorMsg::INVALID_ALIAS;
out << YAML::BeginSeq;
out << YAML::Alias("new\nline");
out << YAML::EndSeq;
}
}
}
}
namespace {
class NullEventHandler: public YAML::EventHandler {
namespace {
class NullEventHandler : public YAML::EventHandler {
virtual void OnDocumentStart(const YAML::Mark&) {}
virtual void OnDocumentEnd() {}
virtual void OnNull(const YAML::Mark&, YAML::anchor_t) {}
virtual void OnAlias(const YAML::Mark&, YAML::anchor_t) {}
virtual void OnScalar(const YAML::Mark&, const std::string&, YAML::anchor_t, const std::string&) {}
virtual void OnScalar(const YAML::Mark&, const std::string&, YAML::anchor_t,
const std::string&) {}
virtual void OnSequenceStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {}
virtual void OnSequenceStart(const YAML::Mark&, const std::string&,
YAML::anchor_t) {}
virtual void OnSequenceEnd() {}
virtual void OnMapStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {}
virtual void OnMapStart(const YAML::Mark&, const std::string&,
YAML::anchor_t) {}
virtual void OnMapEnd() {}
};
};
void RunEmitterTest(void (*test)(YAML::Emitter&, std::string&), const std::string& name, int& passed, int& total) {
void RunEmitterTest(void (*test)(YAML::Emitter&, std::string&),
const std::string& name, int& passed, int& total) {
YAML::Emitter out;
std::string desiredOutput;
test(out, desiredOutput);
std::string output = out.c_str();
std::string lastError = out.GetLastError();
if(output == desiredOutput) {
if (output == desiredOutput) {
try {
std::stringstream stream(output);
YAML::Parser parser;
NullEventHandler handler;
parser.HandleNextDocument(handler);
passed++;
} catch(const YAML::Exception& e) {
}
catch (const YAML::Exception& e) {
std::cout << "Emitter test failed: " << name << "\n";
std::cout << "Parsing output error: " << e.what() << "\n";
}
......@@ -1029,63 +1031,65 @@ namespace Test
std::cout << output << "<<<\n";
std::cout << "Desired output:\n";
std::cout << desiredOutput << "<<<\n";
if(!out.good())
if (!out.good())
std::cout << "Emitter error: " << lastError << "\n";
}
total++;
}
}
void RunEmitterErrorTest(void (*test)(YAML::Emitter&, std::string&), const std::string& name, int& passed, int& total) {
void RunEmitterErrorTest(void (*test)(YAML::Emitter&, std::string&),
const std::string& name, int& passed, int& total) {
YAML::Emitter out;
std::string desiredError;
test(out, desiredError);
std::string lastError = out.GetLastError();
if(!out.good() && lastError == desiredError) {
if (!out.good() && lastError == desiredError) {
passed++;
} else {
std::cout << "Emitter test failed: " << name << "\n";
if(out.good())
if (out.good())
std::cout << "No error detected\n";
else
std::cout << "Detected error: " << lastError << "\n";
std::cout << "Expected error: " << desiredError << "\n";
}
total++;
}
}
void RunGenEmitterTest(TEST (*test)(YAML::Emitter&), const std::string& name, int& passed, int& total) {
void RunGenEmitterTest(TEST (*test)(YAML::Emitter&), const std::string& name,
int& passed, int& total) {
YAML::Emitter out;
TEST ret;
try {
ret = test(out);
} catch(const YAML::Exception& e) {
}
catch (const YAML::Exception& e) {
ret.ok = false;
ret.error = std::string(" Exception caught: ") + e.what();
}
if(!out.good()) {
if (!out.good()) {
ret.ok = false;
ret.error = out.GetLastError();
}
if(!ret.ok) {
if (!ret.ok) {
std::cout << "Generated emitter test failed: " << name << "\n";
std::cout << "Output:\n";
std::cout << out.c_str() << "<<<\n";
std::cout << ret.error << "\n";
}
if(ret.ok)
if (ret.ok)
passed++;
total++;
}
}
}
}
#include "genemittertests.h"
bool RunEmitterTests()
{
bool RunEmitterTests() {
int passed = 0;
int total = 0;
RunEmitterTest(&Emitter::SimpleScalar, "simple scalar", passed, total);
......@@ -1106,67 +1110,102 @@ namespace Test
RunEmitterTest(&Emitter::ComplexLongKey, "complex long key", passed, total);
RunEmitterTest(&Emitter::AutoLongKey, "auto long key", passed, total);
RunEmitterTest(&Emitter::ScalarFormat, "scalar format", passed, total);
RunEmitterTest(&Emitter::AutoLongKeyScalar, "auto long key scalar", passed, total);
RunEmitterTest(&Emitter::AutoLongKeyScalar, "auto long key scalar", passed,
total);
RunEmitterTest(&Emitter::LongKeyFlowMap, "long key flow map", passed, total);
RunEmitterTest(&Emitter::BlockMapAsKey, "block map as key", passed, total);
RunEmitterTest(&Emitter::AliasAndAnchor, "alias and anchor", passed, total);
RunEmitterTest(&Emitter::AliasAndAnchorWithNull, "alias and anchor with null", passed, total);
RunEmitterTest(&Emitter::AliasAndAnchorInFlow, "alias and anchor in flow", passed, total);
RunEmitterTest(&Emitter::SimpleVerbatimTag, "simple verbatim tag", passed, total);
RunEmitterTest(&Emitter::VerbatimTagInBlockSeq, "verbatim tag in block seq", passed, total);
RunEmitterTest(&Emitter::VerbatimTagInFlowSeq, "verbatim tag in flow seq", passed, total);
RunEmitterTest(&Emitter::VerbatimTagInFlowSeqWithNull, "verbatim tag in flow seq with null", passed, total);
RunEmitterTest(&Emitter::VerbatimTagInBlockMap, "verbatim tag in block map", passed, total);
RunEmitterTest(&Emitter::VerbatimTagInFlowMap, "verbatim tag in flow map", passed, total);
RunEmitterTest(&Emitter::VerbatimTagInFlowMapWithNull, "verbatim tag in flow map with null", passed, total);
RunEmitterTest(&Emitter::VerbatimTagWithEmptySeq, "verbatim tag with empty seq", passed, total);
RunEmitterTest(&Emitter::VerbatimTagWithEmptyMap, "verbatim tag with empty map", passed, total);
RunEmitterTest(&Emitter::VerbatimTagWithEmptySeqAndMap, "verbatim tag with empty seq and map", passed, total);
RunEmitterTest(&Emitter::ByKindTagWithScalar, "by-kind tag with scalar", passed, total);
RunEmitterTest(&Emitter::LocalTagWithScalar, "local tag with scalar", passed, total);
RunEmitterTest(&Emitter::AliasAndAnchorWithNull, "alias and anchor with null",
passed, total);
RunEmitterTest(&Emitter::AliasAndAnchorInFlow, "alias and anchor in flow",
passed, total);
RunEmitterTest(&Emitter::SimpleVerbatimTag, "simple verbatim tag", passed,
total);
RunEmitterTest(&Emitter::VerbatimTagInBlockSeq, "verbatim tag in block seq",
passed, total);
RunEmitterTest(&Emitter::VerbatimTagInFlowSeq, "verbatim tag in flow seq",
passed, total);
RunEmitterTest(&Emitter::VerbatimTagInFlowSeqWithNull,
"verbatim tag in flow seq with null", passed, total);
RunEmitterTest(&Emitter::VerbatimTagInBlockMap, "verbatim tag in block map",
passed, total);
RunEmitterTest(&Emitter::VerbatimTagInFlowMap, "verbatim tag in flow map",
passed, total);
RunEmitterTest(&Emitter::VerbatimTagInFlowMapWithNull,
"verbatim tag in flow map with null", passed, total);
RunEmitterTest(&Emitter::VerbatimTagWithEmptySeq,
"verbatim tag with empty seq", passed, total);
RunEmitterTest(&Emitter::VerbatimTagWithEmptyMap,
"verbatim tag with empty map", passed, total);
RunEmitterTest(&Emitter::VerbatimTagWithEmptySeqAndMap,
"verbatim tag with empty seq and map", passed, total);
RunEmitterTest(&Emitter::ByKindTagWithScalar, "by-kind tag with scalar",
passed, total);
RunEmitterTest(&Emitter::LocalTagWithScalar, "local tag with scalar", passed,
total);
RunEmitterTest(&Emitter::ComplexDoc, "complex doc", passed, total);
RunEmitterTest(&Emitter::STLContainers, "STL containers", passed, total);
RunEmitterTest(&Emitter::SimpleComment, "simple comment", passed, total);
RunEmitterTest(&Emitter::MultiLineComment, "multi-line comment", passed, total);
RunEmitterTest(&Emitter::MultiLineComment, "multi-line comment", passed,
total);
RunEmitterTest(&Emitter::ComplexComments, "complex comments", passed, total);
RunEmitterTest(&Emitter::InitialComment, "initial comment", passed, total);
RunEmitterTest(&Emitter::InitialCommentWithDocIndicator, "initial comment with doc indicator", passed, total);
RunEmitterTest(&Emitter::CommentInFlowSeq, "comment in flow seq", passed, total);
RunEmitterTest(&Emitter::CommentInFlowMap, "comment in flow map", passed, total);
RunEmitterTest(&Emitter::InitialCommentWithDocIndicator,
"initial comment with doc indicator", passed, total);
RunEmitterTest(&Emitter::CommentInFlowSeq, "comment in flow seq", passed,
total);
RunEmitterTest(&Emitter::CommentInFlowMap, "comment in flow map", passed,
total);
RunEmitterTest(&Emitter::Indentation, "indentation", passed, total);
RunEmitterTest(&Emitter::SimpleGlobalSettings, "simple global settings", passed, total);
RunEmitterTest(&Emitter::ComplexGlobalSettings, "complex global settings", passed, total);
RunEmitterTest(&Emitter::SimpleGlobalSettings, "simple global settings",
passed, total);
RunEmitterTest(&Emitter::ComplexGlobalSettings, "complex global settings",
passed, total);
RunEmitterTest(&Emitter::Null, "null", passed, total);
RunEmitterTest(&Emitter::EscapedUnicode, "escaped unicode", passed, total);
RunEmitterTest(&Emitter::Unicode, "unicode", passed, total);
RunEmitterTest(&Emitter::DoubleQuotedUnicode, "double quoted unicode", passed, total);
RunEmitterTest(&Emitter::DoubleQuotedUnicode, "double quoted unicode", passed,
total);
RunEmitterTest(&Emitter::UserType, "user type", passed, total);
RunEmitterTest(&Emitter::UserTypeInContainer, "user type in container", passed, total);
RunEmitterTest(&Emitter::UserTypeInContainer, "user type in container",
passed, total);
RunEmitterTest(&Emitter::PointerToInt, "pointer to int", passed, total);
RunEmitterTest(&Emitter::PointerToUserType, "pointer to user type", passed, total);
RunEmitterTest(&Emitter::PointerToUserType, "pointer to user type", passed,
total);
RunEmitterTest(&Emitter::NewlineAtEnd, "newline at end", passed, total);
RunEmitterTest(&Emitter::NewlineInBlockSequence, "newline in block sequence", passed, total);
RunEmitterTest(&Emitter::NewlineInFlowSequence, "newline in flow sequence", passed, total);
RunEmitterTest(&Emitter::NewlineInBlockMap, "newline in block map", passed, total);
RunEmitterTest(&Emitter::NewlineInFlowMap, "newline in flow map", passed, total);
RunEmitterTest(&Emitter::NewlineInBlockSequence, "newline in block sequence",
passed, total);
RunEmitterTest(&Emitter::NewlineInFlowSequence, "newline in flow sequence",
passed, total);
RunEmitterTest(&Emitter::NewlineInBlockMap, "newline in block map", passed,
total);
RunEmitterTest(&Emitter::NewlineInFlowMap, "newline in flow map", passed,
total);
RunEmitterTest(&Emitter::LotsOfNewlines, "lots of newlines", passed, total);
RunEmitterTest(&Emitter::Binary, "binary", passed, total);
RunEmitterTest(&Emitter::LongBinary, "long binary", passed, total);
RunEmitterTest(&Emitter::EmptyBinary, "empty binary", passed, total);
RunEmitterTest(&Emitter::ColonAtEndOfScalar, "colon at end of scalar", passed, total);
RunEmitterTest(&Emitter::ColonAtEndOfScalar, "colon at end of scalar", passed,
total);
RunEmitterTest(&Emitter::ColonAsScalar, "colon as scalar", passed, total);
RunEmitterTest(&Emitter::ColonAtEndOfScalarInFlow, "colon at end of scalar in flow", passed, total);
RunEmitterTest(&Emitter::ColonAtEndOfScalarInFlow,
"colon at end of scalar in flow", passed, total);
RunEmitterTest(&Emitter::BoolFormatting, "bool formatting", passed, total);
RunEmitterTest(&Emitter::DocStartAndEnd, "doc start and end", passed, total);
RunEmitterTest(&Emitter::ImplicitDocStart, "implicit doc start", passed, total);
RunEmitterTest(&Emitter::ImplicitDocStart, "implicit doc start", passed,
total);
RunEmitterTest(&Emitter::EmptyString, "empty string", passed, total);
RunEmitterTest(&Emitter::SingleChar, "single char", passed, total);
RunEmitterTest(&Emitter::DefaultPrecision, "default precision", passed, total);
RunEmitterTest(&Emitter::DefaultPrecision, "default precision", passed,
total);
RunEmitterTest(&Emitter::SetPrecision, "set precision", passed, total);
RunEmitterTest(&Emitter::DashInBlockContext, "dash in block context", passed, total);
RunEmitterTest(&Emitter::DashInBlockContext, "dash in block context", passed,
total);
RunEmitterTest(&Emitter::HexAndOct, "hex and oct", passed, total);
RunEmitterTest(&Emitter::CompactMapWithNewline, "compact map with newline", passed, total);
RunEmitterTest(&Emitter::ForceSingleQuotedToDouble, "force single quoted to double", passed, total);
RunEmitterTest(&Emitter::CompactMapWithNewline, "compact map with newline",
passed, total);
RunEmitterTest(&Emitter::ForceSingleQuotedToDouble,
"force single quoted to double", passed, total);
RunEmitterErrorTest(&Emitter::ExtraEndSeq, "extra EndSeq", passed, total);
RunEmitterErrorTest(&Emitter::ExtraEndMap, "extra EndMap", passed, total);
......@@ -1178,6 +1217,5 @@ namespace Test
std::cout << "Emitter tests: " << passed << "/" << total << " passed\n";
return passed == total;
}
}
}
#ifndef EMITTERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTERTESTS_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
#endif
namespace Test {
bool RunEmitterTests();
bool RunEmitterTests();
}
#endif // EMITTERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -7,19 +7,31 @@
#include <cassert>
namespace Test {
inline std::string Quote(const std::string& text) {
inline std::string Quote(const std::string& text) {
YAML::Emitter out;
out << YAML::DoubleQuoted << text;
return out.c_str();
}
}
struct Event {
enum Type { DocStart, DocEnd, Null, Alias, Scalar, SeqStart, SeqEnd, MapStart, MapEnd };
struct Event {
enum Type {
DocStart,
DocEnd,
Null,
Alias,
Scalar,
SeqStart,
SeqEnd,
MapStart,
MapEnd
};
typedef YAML::Mark Mark;
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;
std::string tag;
......@@ -27,7 +39,7 @@ namespace Test {
std::string scalar;
std::ostream& write(std::ostream& out) const {
switch(type) {
switch (type) {
case DocStart:
return out << "DocStart";
case DocEnd:
......@@ -37,7 +49,8 @@ namespace Test {
case Alias:
return out << "Alias(" << anchor << ")";
case Scalar:
return out << "Scalar(" << Quote(tag) << ", " << anchor << ", " << Quote(scalar) << ")";
return out << "Scalar(" << Quote(tag) << ", " << anchor << ", "
<< Quote(scalar) << ")";
case SeqStart:
return out << "SeqStart(" << Quote(tag) << ", " << anchor << ")";
case SeqEnd:
......@@ -50,22 +63,20 @@ namespace Test {
assert(false);
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);
}
}
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;
}
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;
}
inline bool operator != (const Event& a, const Event& b) {
return !(a == b);
}
inline bool operator!=(const Event& a, const Event& b) { return !(a == b); }
class MockEventHandler: public YAML::EventHandler
{
class MockEventHandler : public YAML::EventHandler {
public:
typedef YAML::Mark Mark;
typedef YAML::anchor_t anchor_t;
......@@ -88,11 +99,13 @@ namespace Test {
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));
}
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, ""));
}
......@@ -100,7 +113,8 @@ namespace Test {
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, ""));
}
......@@ -112,10 +126,10 @@ namespace Test {
Test::TEST Check() const {
std::size_t N = std::max(m_expectedEvents.size(), m_actualEvents.size());
for(std::size_t i=0;i<N;i++) {
if(i >= m_expectedEvents.size()) {
for (std::size_t i = 0; i < N; i++) {
if (i >= m_expectedEvents.size()) {
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 << " EXPECTED: (no event expected)\n";
......@@ -123,9 +137,9 @@ namespace Test {
return out.str().c_str();
}
if(i >= m_actualEvents.size()) {
if (i >= m_actualEvents.size()) {
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 << " EXPECTED: " << m_expectedEvents[i] << "\n";
......@@ -133,9 +147,9 @@ namespace Test {
return out.str().c_str();
}
if(m_expectedEvents[i] != m_actualEvents[i]) {
if (m_expectedEvents[i] != m_actualEvents[i]) {
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 << " EXPECTED: " << m_expectedEvents[i] << "\n";
......@@ -149,42 +163,35 @@ namespace Test {
std::vector<Event> m_expectedEvents;
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()\
handler.Expect(Event(Event::DocStart, "", 0, ""))
#define HANDLE(ex) \
MockEventHandler handler; \
std::stringstream stream(ex); \
YAML::Parser parser(stream); \
while (parser.HandleNextDocument(handler)) { \
}
#define EXPECT_DOC_END()\
handler.Expect(Event(Event::DocEnd, "", 0, ""))
#define EXPECT_DOC_START() handler.Expect(Event(Event::DocStart, "", 0, ""))
#define EXPECT_NULL(anchor)\
handler.Expect(Event(Event::Null, "", anchor, ""))
#define EXPECT_DOC_END() handler.Expect(Event(Event::DocEnd, "", 0, ""))
#define EXPECT_ALIAS(anchor)\
handler.Expect(Event(Event::Alias, "", anchor, ""))
#define EXPECT_NULL(anchor) handler.Expect(Event(Event::Null, "", anchor, ""))
#define EXPECT_SCALAR(tag, anchor, value)\
handler.Expect(Event(Event::Scalar, tag, anchor, value))
#define EXPECT_ALIAS(anchor) handler.Expect(Event(Event::Alias, "", anchor, ""))
#define EXPECT_SEQ_START(tag, anchor)\
handler.Expect(Event(Event::SeqStart, tag, anchor, ""))
#define EXPECT_SCALAR(tag, anchor, value) \
handler.Expect(Event(Event::Scalar, tag, anchor, value))
#define EXPECT_SEQ_END()\
handler.Expect(Event(Event::SeqEnd, "", 0, ""))
#define EXPECT_SEQ_START(tag, anchor) \
handler.Expect(Event(Event::SeqStart, tag, anchor, ""))
#define EXPECT_MAP_START(tag, anchor)\
handler.Expect(Event(Event::MapStart, tag, anchor, ""))
#define EXPECT_SEQ_END() handler.Expect(Event(Event::SeqEnd, "", 0, ""))
#define EXPECT_MAP_END()\
handler.Expect(Event(Event::MapEnd, "", 0, ""))
#define EXPECT_MAP_START(tag, anchor) \
handler.Expect(Event(Event::MapStart, tag, anchor, ""))
#define DONE()\
return handler.Check()
#define EXPECT_MAP_END() handler.Expect(Event(Event::MapEnd, "", 0, ""))
#define DONE() return handler.Check()
}
#include "tests.h"
int main()
{
int main() {
Test::RunAll();
return 0;
}
#ifndef 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
#endif
namespace Test {
bool RunParserTests();
bool RunParserTests();
}
#endif // PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
namespace Test {
namespace Spec {
const char *ex2_1 =
namespace Spec {
const char *ex2_1 =
"- Mark McGwire\n"
"- Sammy Sosa\n"
"- Ken Griffey";
const char *ex2_2 =
const char *ex2_2 =
"hr: 65 # Home runs\n"
"avg: 0.278 # Batting average\n"
"rbi: 147 # Runs Batted In";
const char *ex2_3 =
const char *ex2_3 =
"american:\n"
"- Boston Red Sox\n"
"- Detroit Tigers\n"
......@@ -20,7 +20,7 @@ namespace Test {
"- Chicago Cubs\n"
"- Atlanta Braves";
const char *ex2_4 =
const char *ex2_4 =
"-\n"
" name: Mark McGwire\n"
" hr: 65\n"
......@@ -30,19 +30,19 @@ namespace Test {
" hr: 63\n"
" avg: 0.288";
const char *ex2_5 =
const char *ex2_5 =
"- [name , hr, avg ]\n"
"- [Mark McGwire, 65, 0.278]\n"
"- [Sammy Sosa , 63, 0.288]";
const char *ex2_6 =
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 =
const char *ex2_7 =
"# Ranking of 1998 home runs\n"
"---\n"
"- Mark McGwire\n"
......@@ -54,7 +54,7 @@ namespace Test {
"- Chicago Cubs\n"
"- St Louis Cardinals";
const char *ex2_8 =
const char *ex2_8 =
"---\n"
"time: 20:03:20\n"
"player: Sammy Sosa\n"
......@@ -66,7 +66,7 @@ namespace Test {
"action: grand slam\n"
"...";
const char *ex2_9 =
const char *ex2_9 =
"---\n"
"hr: # 1998 hr ranking\n"
" - Mark McGwire\n"
......@@ -76,7 +76,7 @@ namespace Test {
" - Sammy Sosa\n"
" - Ken Griffey";
const char *ex2_10 =
const char *ex2_10 =
"---\n"
"hr:\n"
" - Mark McGwire\n"
......@@ -86,7 +86,7 @@ namespace Test {
" - *SS # Subsequent occurrence\n"
" - Ken Griffey";
const char *ex2_11 =
const char *ex2_11 =
"? - Detroit Tigers\n"
" - Chicago cubs\n"
":\n"
......@@ -97,7 +97,7 @@ namespace Test {
": [ 2001-07-02, 2001-08-12,\n"
" 2001-08-14 ]";
const char *ex2_12 =
const char *ex2_12 =
"---\n"
"# Products purchased\n"
"- item : Super Hoop\n"
......@@ -107,19 +107,19 @@ namespace Test {
"- item : Big Shoes\n"
" quantity: 1";
const char *ex2_13 =
const char *ex2_13 =
"# ASCII Art\n"
"--- |\n"
" \\//||\\/||\n"
" // || ||__";
const char *ex2_14 =
const char *ex2_14 =
"--- >\n"
" Mark McGwire's\n"
" year was crippled\n"
" by a knee injury.";
const char *ex2_15 =
const char *ex2_15 =
">\n"
" Sammy Sosa completed another\n"
" fine season with great stats.\n"
......@@ -129,7 +129,7 @@ namespace Test {
" \n"
" What a year!";
const char *ex2_16 =
const char *ex2_16 =
"name: Mark McGwire\n"
"accomplishment: >\n"
" Mark set a major league\n"
......@@ -138,7 +138,7 @@ namespace Test {
" 65 Home Runs\n"
" 0.278 Batting Average\n";
const char *ex2_17 =
const char *ex2_17 =
"unicode: \"Sosa did fine.\\u263A\"\n"
"control: \"\\b1998\\t1999\\t2000\\n\"\n"
"hex esc: \"\\x0d\\x0a is \\r\\n\"\n"
......@@ -147,7 +147,7 @@ namespace Test {
"quoted: ' # Not a ''comment''.'\n"
"tie-fighter: '|\\-*-/|'";
const char *ex2_18 =
const char *ex2_18 =
"plain:\n"
" This unquoted scalar\n"
" spans many lines.\n"
......@@ -155,9 +155,9 @@ namespace Test {
"quoted: \"So does this\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"
"not-date: !!str 2002-04-28\n"
"\n"
......@@ -172,7 +172,7 @@ namespace Test {
" above may be different for\n"
" different documents.";
const char *ex2_24 =
const char *ex2_24 =
"%TAG ! tag:clarkevans.com,2002:\n"
"--- !shape\n"
" # Use the ! handle for presenting\n"
......@@ -188,7 +188,7 @@ namespace Test {
" color: 0xFFEEBB\n"
" text: Pretty vector drawing.";
const char *ex2_25 =
const char *ex2_25 =
"# Sets are represented as a\n"
"# Mapping where each key is\n"
"# associated with a null value\n"
......@@ -197,7 +197,7 @@ namespace Test {
"? Sammy Sosa\n"
"? Ken Griffey";
const char *ex2_26 =
const char *ex2_26 =
"# Ordered maps are represented as\n"
"# A sequence of mappings, with\n"
"# each mapping having one key\n"
......@@ -206,7 +206,7 @@ namespace Test {
"- Sammy Sosa: 63\n"
"- Ken Griffey: 58";
const char *ex2_27 =
const char *ex2_27 =
"--- !<tag:clarkevans.com,2002:invoice>\n"
"invoice: 34843\n"
"date : 2001-01-23\n"
......@@ -237,7 +237,7 @@ namespace Test {
" Backup contact is Nancy\n"
" Billsmer @ 338-4338.";
const char *ex2_28 =
const char *ex2_28 =
"---\n"
"Time: 2001-11-23 15:01:42 -5\n"
"User: ed\n"
......@@ -265,9 +265,9 @@ namespace Test {
" code: |-\n"
" foo = bar";
// TODO: 5.1 - 5.2 BOM
// TODO: 5.1 - 5.2 BOM
const char *ex5_3 =
const char *ex5_3 =
"sequence:\n"
"- one\n"
"- two\n"
......@@ -276,18 +276,17 @@ namespace Test {
" : blue\n"
" sea : green";
const char *ex5_4 =
const char *ex5_4 =
"sequence: [ one, two, ]\n"
"mapping: { sky: blue, sea: green }";
const char *ex5_5 =
"# Comment only.";
const char *ex5_5 = "# Comment only.";
const char *ex5_6 =
const char *ex5_6 =
"anchored: !local &anchor value\n"
"alias: *anchor";
const char *ex5_7 =
const char *ex5_7 =
"literal: |\n"
" some\n"
" text\n"
......@@ -295,19 +294,19 @@ namespace Test {
" some\n"
" text\n";
const char *ex5_8 =
const char *ex5_8 =
"single: 'text'\n"
"double: \"text\"";
// TODO: 5.9 directive
// TODO: 5.10 reserved indicator
// TODO: 5.9 directive
// TODO: 5.10 reserved indicator
const char *ex5_11 =
const char *ex5_11 =
"|\n"
" Line break (no glyph)\n"
" Line break (glyphed)\n";
const char *ex5_12 =
const char *ex5_12 =
"# Tabs and spaces\n"
"quoted: \"Quoted\t\"\n"
"block: |\n"
......@@ -315,19 +314,19 @@ namespace Test {
" \tprintf(\"Hello, world!\\n\");\n"
" }";
const char *ex5_13 =
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 =
const char *ex5_14 =
"Bad escapes:\n"
" \"\\c\n"
" \\xq-\"";
const char *ex6_1 =
const char *ex6_1 =
" # Leading comment line spaces are\n"
" # neither content nor indentation.\n"
" \n"
......@@ -341,18 +340,18 @@ namespace Test {
" \tStill by two # content nor\n"
" ] # indentation.";
const char *ex6_2 =
const char *ex6_2 =
"? a\n"
": -\tb\n"
" - -\tc\n"
" - d";
const char *ex6_3 =
const char *ex6_3 =
"- foo:\t bar\n"
"- - baz\n"
" -\tbaz";
const char *ex6_4 =
const char *ex6_4 =
"plain: text\n"
" lines\n"
"quoted: \"text\n"
......@@ -361,7 +360,7 @@ namespace Test {
" text\n"
" \tlines\n";
const char *ex6_5 =
const char *ex6_5 =
"Folding:\n"
" \"Empty line\n"
" \t\n"
......@@ -370,7 +369,7 @@ namespace Test {
" Clipped empty lines\n"
" ";
const char *ex6_6 =
const char *ex6_6 =
">-\n"
" trimmed\n"
" \n"
......@@ -379,7 +378,7 @@ namespace Test {
" as\n"
" space";
const char *ex6_7 =
const char *ex6_7 =
">\n"
" foo \n"
" \n"
......@@ -387,7 +386,7 @@ namespace Test {
"\n"
" baz\n";
const char *ex6_8 =
const char *ex6_8 =
"\"\n"
" foo \n"
" \n"
......@@ -396,22 +395,22 @@ namespace Test {
" baz\n"
"\"";
const char *ex6_9 =
const char *ex6_9 =
"key: # Comment\n"
" value";
const char *ex6_10 =
const char *ex6_10 =
" # Comment\n"
" \n"
"\n";
const char *ex6_11 =
const char *ex6_11 =
"key: # Comment\n"
" # lines\n"
" value\n"
"\n";
const char *ex6_12 =
const char *ex6_12 =
"{ first: Sammy, last: Sosa }:\n"
"# Statistics:\n"
" hr: # Home runs\n"
......@@ -419,33 +418,33 @@ namespace Test {
" avg: # Average\n"
" 0.278";
const char *ex6_13 =
const char *ex6_13 =
"%FOO bar baz # Should be ignored\n"
" # with a warning.\n"
"--- \"foo\"";
const char *ex6_14 =
const char *ex6_14 =
"%YAML 1.3 # Attempt parsing\n"
" # with a warning\n"
"---\n"
"\"foo\"";
const char *ex6_15 =
const char *ex6_15 =
"%YAML 1.2\n"
"%YAML 1.1\n"
"foo";
const char *ex6_16 =
const char *ex6_16 =
"%TAG !yaml! tag:yaml.org,2002:\n"
"---\n"
"!yaml!str \"foo\"";
const char *ex6_17 =
const char *ex6_17 =
"%TAG ! !foo\n"
"%TAG ! !foo\n"
"bar";
const char *ex6_18 =
const char *ex6_18 =
"# Private\n"
"!foo \"bar\"\n"
"...\n"
......@@ -454,17 +453,17 @@ namespace Test {
"---\n"
"!foo \"bar\"";
const char *ex6_19 =
const char *ex6_19 =
"%TAG !! tag:example.com,2000:app/\n"
"---\n"
"!!int 1 - 3 # Interval, not integer";
const char *ex6_20 =
const char *ex6_20 =
"%TAG !e! tag:example.com,2000:app/\n"
"---\n"
"!e!foo \"bar\"";
const char *ex6_21 =
const char *ex6_21 =
"%TAG !m! !my-\n"
"--- # Bulb here\n"
"!m!light fluorescent\n"
......@@ -473,102 +472,101 @@ namespace Test {
"--- # Color here\n"
"!m!light green";
const char *ex6_22 =
const char *ex6_22 =
"%TAG !e! tag:example.com,2000:app/\n"
"---\n"
"- !e!foo \"bar\"";
const char *ex6_23 =
const char *ex6_23 =
"!!str &a1 \"foo\":\n"
" !!str bar\n"
"&a2 baz : *a1";
const char *ex6_24 =
const char *ex6_24 =
"!<tag:yaml.org,2002:str> foo :\n"
" !<!bar> baz";
const char *ex6_25 =
const char *ex6_25 =
"- !<!> foo\n"
"- !<$:?> bar\n";
const char *ex6_26 =
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_27a =
const char *ex6_27a =
"%TAG !e! tag:example,2000:app/\n"
"---\n"
"- !e! foo";
const char *ex6_27b =
const char *ex6_27b =
"%TAG !e! tag:example,2000:app/\n"
"---\n"
"- !h!bar baz";
const char *ex6_28 =
const char *ex6_28 =
"# Assuming conventional resolution:\n"
"- \"12\"\n"
"- 12\n"
"- ! 12";
const char *ex6_29 =
const char *ex6_29 =
"First occurrence: &anchor Value\n"
"Second occurrence: *anchor";
const char *ex7_1 =
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 =
const char *ex7_2 =
"{\n"
" foo : !!str,\n"
" !!str : bar,\n"
"}";
const char *ex7_3 =
const char *ex7_3 =
"{\n"
" ? foo :,\n"
" : bar,\n"
"}\n";
const char *ex7_4 =
const char *ex7_4 =
"\"implicit block key\" : [\n"
" \"implicit flow key\" : value,\n"
" ]";
const char *ex7_5 =
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 =
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_7 = " 'here''s to \"quotes\"'";
const char *ex7_8 =
const char *ex7_8 =
"'implicit block key' : [\n"
" 'implicit flow key' : value,\n"
" ]";
const char *ex7_9 =
const char *ex7_9 =
"' 1st non-empty\n"
"\n"
" 2nd non-empty \n"
"\t3rd non-empty '";
const char *ex7_10 =
const char *ex7_10 =
"# Outside flow collection:\n"
"- ::vector\n"
"- \": - ()\"\n"
......@@ -582,22 +580,22 @@ namespace Test {
" -123,\n"
" http://example.com/foo#bar ]";
const char *ex7_11 =
const char *ex7_11 =
"implicit block key : [\n"
" implicit flow key : value,\n"
" ]";
const char *ex7_12 =
const char *ex7_12 =
"1st non-empty\n"
"\n"
" 2nd non-empty \n"
"\t3rd non-empty";
const char *ex7_13 =
const char *ex7_13 =
"- [ one, two, ]\n"
"- [three ,four]";
const char *ex7_14 =
const char *ex7_14 =
"[\n"
"\"double\n"
" quoted\", 'single\n"
......@@ -607,18 +605,18 @@ namespace Test {
"single: pair,\n"
"]";
const char *ex7_15 =
const char *ex7_15 =
"- { one : two , three: four , }\n"
"- {five: six,seven : eight}";
const char *ex7_16 =
const char *ex7_16 =
"{\n"
"? explicit: entry,\n"
"implicit: entry,\n"
"?\n"
"}";
const char *ex7_17 =
const char *ex7_17 =
"{\n"
"unquoted : \"separate\",\n"
"http://foo.com,\n"
......@@ -626,48 +624,49 @@ namespace Test {
": omitted key,\n"
"}";
const char *ex7_18 =
const char *ex7_18 =
"{\n"
"\"adjacent\":value,\n"
"\"readable\":value,\n"
"\"empty\":\n"
"}";
const char *ex7_19 =
const char *ex7_19 =
"[\n"
"foo: bar\n"
"]";
const char *ex7_20 =
const char *ex7_20 =
"[\n"
"? foo\n"
" bar : baz\n"
"]";
const char *ex7_21 =
const char *ex7_21 =
"- [ YAML : separate ]\n"
"- [ : empty key entry ]\n"
"- [ {JSON: like}:adjacent ]";
const char *ex7_22 =
const char *ex7_22 =
"[ 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\"\n"
"- 'b'\n"
"- c";
const char *ex7_24 =
const char *ex7_24 =
"- !!str \"a\"\n"
"- 'b'\n"
"- &anchor \"c\"\n"
"- *anchor\n"
"- !!str";
const char *ex8_1 =
const char *ex8_1 =
"- | # Empty header\n"
" literal\n"
"- >1 # Indentation indicator\n"
......@@ -678,7 +677,7 @@ namespace Test {
"- >1- # Both indicators\n"
" strip\n";
const char *ex8_2 =
const char *ex8_2 =
"- |\n"
" detected\n"
"- >\n"
......@@ -691,21 +690,21 @@ namespace Test {
" \t\n"
" detected\n";
const char *ex8_3a =
const char *ex8_3a =
"- |\n"
" \n"
" text";
const char *ex8_3b =
const char *ex8_3b =
"- >\n"
" text\n"
" text";
const char *ex8_3c =
const char *ex8_3c =
"- |2\n"
" text";
const char *ex8_4 =
const char *ex8_4 =
"strip: |-\n"
" text\n"
"clip: |\n"
......@@ -713,7 +712,7 @@ namespace Test {
"keep: |+\n"
" text\n";
const char *ex8_5 =
const char *ex8_5 =
" # Strip\n"
" # Comments:\n"
"strip: |-\n"
......@@ -734,7 +733,7 @@ namespace Test {
" # Trail\n"
" # Comments\n";
const char *ex8_6 =
const char *ex8_6 =
"strip: >-\n"
"\n"
"clip: >\n"
......@@ -742,13 +741,13 @@ namespace Test {
"keep: |+\n"
"\n";
const char *ex8_7 =
const char *ex8_7 =
"|\n"
" literal\n"
" \ttext\n"
"\n";
const char *ex8_8 =
const char *ex8_8 =
"|\n"
" \n"
" \n"
......@@ -759,13 +758,13 @@ namespace Test {
"\n"
" # Comment\n";
const char *ex8_9 =
const char *ex8_9 =
">\n"
" folded\n"
" text\n"
"\n";
const char *ex8_10 =
const char *ex8_10 =
">\n"
"\n"
" folded\n"
......@@ -783,16 +782,16 @@ namespace Test {
"\n"
"# Comment\n";
const char *ex8_11 = ex8_10;
const char *ex8_12 = ex8_10;
const char *ex8_13 = ex8_10;
const char *ex8_11 = ex8_10;
const char *ex8_12 = ex8_10;
const char *ex8_13 = ex8_10;
const char *ex8_14 =
const char *ex8_14 =
"block sequence:\n"
" - one\n"
" - two : three\n";
const char *ex8_15 =
const char *ex8_15 =
"- # Empty\n"
"- |\n"
" block node\n"
......@@ -800,29 +799,29 @@ namespace Test {
" - two # sequence\n"
"- one: two # Compact mapping\n";
const char *ex8_16 =
const char *ex8_16 =
"block mapping:\n"
" key: value\n";
const char *ex8_17 =
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 =
const char *ex8_18 =
"plain key: in-line value\n"
": # Both empty\n"
"\"quoted key\":\n"
"- entry\n";
const char *ex8_19 =
const char *ex8_19 =
"- sun: yellow\n"
"- ? earth: blue\n"
" : moon: white\n";
const char *ex8_20 =
const char *ex8_20 =
"-\n"
" \"flow in block\"\n"
"- >\n"
......@@ -830,7 +829,7 @@ namespace Test {
"- !!map # Block collection\n"
" foo : bar\n";
const char *ex8_21 =
const char *ex8_21 =
"literal: |2\n"
" value\n"
"folded:\n"
......@@ -838,13 +837,12 @@ namespace Test {
" >1\n"
" value\n";
const char *ex8_22 =
const char *ex8_22 =
"sequence: !!seq\n"
"- entry\n"
"- !!seq\n"
" - nested\n"
"mapping: !!map\n"
" foo: bar\n";
}
}
}
......@@ -2,148 +2,223 @@
#include "yaml-cpp/yaml.h"
#include <iostream>
namespace Test
{
namespace {
void RunSpecTest(TEST (*test)(), const std::string& index, const std::string& name, int& passed, int& total) {
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) {
}
catch (const YAML::Exception& e) {
ret.ok = false;
ret.error = std::string(" Exception caught: ") + e.what();
}
if(!ret.ok) {
if (!ret.ok) {
std::cout << "Spec test " << index << " failed: " << name << "\n";
std::cout << ret.error << "\n";
}
if(ret.ok)
if (ret.ok)
passed++;
total++;
}
}
}
}
bool RunSpecTests()
{
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::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::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::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::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::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::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::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::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::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::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::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::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::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::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::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::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::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::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::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::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);
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;
}
}
}
#ifndef 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
#endif
#include "teststruct.h"
namespace Test {
namespace Spec {
// 2.1
TEST SeqScalars();
namespace Spec {
// 2.1
TEST SeqScalars();
// 2.2
TEST MappingScalarsToScalars();
// 2.2
TEST MappingScalarsToScalars();
// 2.3
TEST MappingScalarsToSequences();
// 2.3
TEST MappingScalarsToSequences();
// 2.4
TEST SequenceOfMappings();
// 2.4
TEST SequenceOfMappings();
// 2.5
TEST SequenceOfSequences();
// 2.5
TEST SequenceOfSequences();
// 2.6
TEST MappingOfMappings();
// 2.6
TEST MappingOfMappings();
// 2.7
TEST TwoDocumentsInAStream();
// 2.7
TEST TwoDocumentsInAStream();
// 2.8
TEST PlayByPlayFeed();
// 2.8
TEST PlayByPlayFeed();
// 2.9
TEST SingleDocumentWithTwoComments();
// 2.9
TEST SingleDocumentWithTwoComments();
// 2.10
TEST SimpleAnchor();
// 2.10
TEST SimpleAnchor();
// 2.11
TEST MappingBetweenSequences();
// 2.11
TEST MappingBetweenSequences();
// 2.12
TEST CompactNestedMapping();
// 2.12
TEST CompactNestedMapping();
// 2.13
TEST InLiteralsNewlinesArePreserved();
// 2.13
TEST InLiteralsNewlinesArePreserved();
// 2.14
TEST InFoldedScalarsNewlinesBecomeSpaces();
// 2.14
TEST InFoldedScalarsNewlinesBecomeSpaces();
// 2.15
TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines();
// 2.15
TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines();
// 2.16
TEST IndentationDeterminesScope();
// 2.16
TEST IndentationDeterminesScope();
// 2.17
TEST QuotedScalars();
// 2.17
TEST QuotedScalars();
// 2.18
TEST MultiLineFlowScalars();
// 2.18
TEST MultiLineFlowScalars();
// TODO: 2.19 - 2.22 schema tags
// TODO: 2.19 - 2.22 schema tags
// 2.23
TEST VariousExplicitTags();
// 2.23
TEST VariousExplicitTags();
// 2.24
TEST GlobalTags();
// 2.24
TEST GlobalTags();
// 2.25
TEST UnorderedSets();
// 2.25
TEST UnorderedSets();
// 2.26
TEST OrderedMappings();
// 2.26
TEST OrderedMappings();
// 2.27
TEST Invoice();
// 2.27
TEST Invoice();
// 2.28
TEST LogFile();
// 2.28
TEST LogFile();
// TODO: 5.1 - 5.2 BOM
// TODO: 5.1 - 5.2 BOM
// 5.3
TEST BlockStructureIndicators();
// 5.3
TEST BlockStructureIndicators();
// 5.4
TEST FlowStructureIndicators();
// 5.4
TEST FlowStructureIndicators();
// 5.5
TEST CommentIndicator();
// 5.5
TEST CommentIndicator();
// 5.6
TEST NodePropertyIndicators();
// 5.6
TEST NodePropertyIndicators();
// 5.7
TEST BlockScalarIndicators();
// 5.7
TEST BlockScalarIndicators();
// 5.8
TEST QuotedScalarIndicators();
// 5.8
TEST QuotedScalarIndicators();
// TODO: 5.9 directive
// TODO: 5.10 reserved indicator
// TODO: 5.9 directive
// TODO: 5.10 reserved indicator
// 5.11
TEST LineBreakCharacters();
// 5.11
TEST LineBreakCharacters();
// 5.12
TEST TabsAndSpaces();
// 5.12
TEST TabsAndSpaces();
// 5.13
TEST EscapedCharacters();
// 5.13
TEST EscapedCharacters();
// 5.14
TEST InvalidEscapedCharacters();
// 5.14
TEST InvalidEscapedCharacters();
// 6.1
TEST IndentationSpaces();
// 6.1
TEST IndentationSpaces();
// 6.2
TEST IndentationIndicators();
// 6.2
TEST IndentationIndicators();
// 6.3
TEST SeparationSpaces();
// 6.3
TEST SeparationSpaces();
// 6.4
TEST LinePrefixes();
// 6.4
TEST LinePrefixes();
// 6.5
TEST EmptyLines();
// 6.5
TEST EmptyLines();
// 6.6
TEST LineFolding();
// 6.6
TEST LineFolding();
// 6.7
TEST BlockFolding();
// 6.7
TEST BlockFolding();
// 6.8
TEST FlowFolding();
// 6.8
TEST FlowFolding();
// 6.9
TEST SeparatedComment();
// 6.9
TEST SeparatedComment();
// 6.10
TEST CommentLines();
// 6.10
TEST CommentLines();
// 6.11
TEST MultiLineComments();
// 6.11
TEST MultiLineComments();
// 6.12
TEST SeparationSpacesII();
// 6.12
TEST SeparationSpacesII();
// 6.13
TEST ReservedDirectives();
// 6.13
TEST ReservedDirectives();
// 6.14
TEST YAMLDirective();
// 6.14
TEST YAMLDirective();
// 6.15
TEST InvalidRepeatedYAMLDirective();
// 6.15
TEST InvalidRepeatedYAMLDirective();
// 6.16
TEST TagDirective();
// 6.16
TEST TagDirective();
// 6.17
TEST InvalidRepeatedTagDirective();
// 6.17
TEST InvalidRepeatedTagDirective();
// 6.18
TEST PrimaryTagHandle();
// 6.18
TEST PrimaryTagHandle();
// 6.19
TEST SecondaryTagHandle();
// 6.19
TEST SecondaryTagHandle();
// 6.20
TEST TagHandles();
// 6.20
TEST TagHandles();
// 6.21
TEST LocalTagPrefix();
// 6.21
TEST LocalTagPrefix();
// 6.22
TEST GlobalTagPrefix();
// 6.22
TEST GlobalTagPrefix();
// 6.23
TEST NodeProperties();
// 6.23
TEST NodeProperties();
// 6.24
TEST VerbatimTags();
// 6.24
TEST VerbatimTags();
// 6.25
TEST InvalidVerbatimTags();
// 6.25
TEST InvalidVerbatimTags();
// 6.26
TEST TagShorthands();
// 6.26
TEST TagShorthands();
// 6.27
TEST InvalidTagShorthands();
// 6.27
TEST InvalidTagShorthands();
// 6.28
TEST NonSpecificTags();
// 6.28
TEST NonSpecificTags();
// 6.29
TEST NodeAnchors();
// 6.29
TEST NodeAnchors();
// 7.1
TEST AliasNodes();
// 7.1
TEST AliasNodes();
// 7.2
TEST EmptyNodes();
// 7.2
TEST EmptyNodes();
// 7.3
TEST CompletelyEmptyNodes();
// 7.3
TEST CompletelyEmptyNodes();
// 7.4
TEST DoubleQuotedImplicitKeys();
// 7.4
TEST DoubleQuotedImplicitKeys();
// 7.5
TEST DoubleQuotedLineBreaks();
// 7.5
TEST DoubleQuotedLineBreaks();
// 7.6
TEST DoubleQuotedLines();
// 7.6
TEST DoubleQuotedLines();
// 7.7
TEST SingleQuotedCharacters();
// 7.7
TEST SingleQuotedCharacters();
// 7.8
TEST SingleQuotedImplicitKeys();
// 7.8
TEST SingleQuotedImplicitKeys();
// 7.9
TEST SingleQuotedLines();
// 7.9
TEST SingleQuotedLines();
// 7.10
TEST PlainCharacters();
// 7.10
TEST PlainCharacters();
// 7.11
TEST PlainImplicitKeys();
// 7.11
TEST PlainImplicitKeys();
// 7.12
TEST PlainLines();
// 7.12
TEST PlainLines();
// 7.13
TEST FlowSequence();
// 7.13
TEST FlowSequence();
// 7.14
TEST FlowSequenceEntries();
// 7.14
TEST FlowSequenceEntries();
// 7.15
TEST FlowMappings();
// 7.15
TEST FlowMappings();
// 7.16
TEST FlowMappingEntries();
// 7.16
TEST FlowMappingEntries();
// 7.17
TEST FlowMappingSeparateValues();
// 7.17
TEST FlowMappingSeparateValues();
// 7.18
TEST FlowMappingAdjacentValues();
// 7.18
TEST FlowMappingAdjacentValues();
// 7.19
TEST SinglePairFlowMappings();
// 7.19
TEST SinglePairFlowMappings();
// 7.20
TEST SinglePairExplicitEntry();
// 7.20
TEST SinglePairExplicitEntry();
// 7.21
TEST SinglePairImplicitEntries();
// 7.21
TEST SinglePairImplicitEntries();
// 7.22
TEST InvalidImplicitKeys();
// 7.22
TEST InvalidImplicitKeys();
// 7.23
TEST FlowContent();
// 7.23
TEST FlowContent();
// 7.24
TEST FlowNodes();
// 7.24
TEST FlowNodes();
// 8.1
TEST BlockScalarHeader();
// 8.1
TEST BlockScalarHeader();
// 8.2
TEST BlockIndentationHeader();
// 8.2
TEST BlockIndentationHeader();
// 8.3
TEST InvalidBlockScalarIndentationIndicators();
// 8.3
TEST InvalidBlockScalarIndentationIndicators();
// 8.4
TEST ChompingFinalLineBreak();
// 8.4
TEST ChompingFinalLineBreak();
// 8.5
TEST ChompingTrailingLines();
// 8.5
TEST ChompingTrailingLines();
// 8.6
TEST EmptyScalarChomping();
// 8.6
TEST EmptyScalarChomping();
// 8.7
TEST LiteralScalar();
// 8.7
TEST LiteralScalar();
// 8.8
TEST LiteralContent();
// 8.8
TEST LiteralContent();
// 8.9
TEST FoldedScalar();
// 8.9
TEST FoldedScalar();
// 8.10
TEST FoldedLines();
// 8.10
TEST FoldedLines();
// 8.11
TEST MoreIndentedLines();
// 8.11
TEST MoreIndentedLines();
// 8.12
TEST EmptySeparationLines();
// 8.12
TEST EmptySeparationLines();
// 8.13
TEST FinalEmptyLines();
// 8.13
TEST FinalEmptyLines();
// 8.14
TEST BlockSequence();
// 8.14
TEST BlockSequence();
// 8.15
TEST BlockSequenceEntryTypes();
// 8.15
TEST BlockSequenceEntryTypes();
// 8.16
TEST BlockMappings();
// 8.16
TEST BlockMappings();
// 8.17
TEST ExplicitBlockMappingEntries();
// 8.17
TEST ExplicitBlockMappingEntries();
// 8.18
TEST ImplicitBlockMappingEntries();
// 8.18
TEST ImplicitBlockMappingEntries();
// 8.19
TEST CompactBlockMappings();
// 8.19
TEST CompactBlockMappings();
// 8.20
TEST BlockNodeTypes();
// 8.20
TEST BlockNodeTypes();
// 8.21
TEST BlockScalarNodes();
// 8.21
TEST BlockScalarNodes();
// 8.22
TEST BlockCollectionNodes();
}
// 8.22
TEST BlockCollectionNodes();
}
bool RunSpecTests();
bool RunSpecTests();
}
#endif // SPECTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
......@@ -8,22 +8,19 @@
#include <vector>
#include <iostream>
namespace Test
{
void RunAll()
{
namespace Test {
void RunAll() {
bool passed = true;
if(!RunEmitterTests())
if (!RunEmitterTests())
passed = false;
if(!RunSpecTests())
if (!RunSpecTests())
passed = false;
if(!RunParserTests())
if (!RunParserTests())
passed = false;
if(passed)
if (passed)
std::cout << "All tests passed!\n";
}
}
}
#ifndef 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
#endif
#include <string>
namespace Test {
void RunAll();
void RunAll();
namespace Parser {
// scalar tests
void SimpleScalar(std::string& inputScalar, std::string& desiredOutput);
void MultiLineScalar(std::string& inputScalar, std::string& desiredOutput);
void LiteralScalar(std::string& inputScalar, std::string& desiredOutput);
void FoldedScalar(std::string& inputScalar, std::string& desiredOutput);
void ChompedFoldedScalar(std::string& inputScalar, std::string& desiredOutput);
void ChompedLiteralScalar(std::string& inputScalar, std::string& desiredOutput);
void FoldedScalarWithIndent(std::string& inputScalar, std::string& desiredOutput);
void ColonScalar(std::string& inputScalar, std::string& desiredOutput);
void QuotedScalar(std::string& inputScalar, std::string& desiredOutput);
void CommaScalar(std::string& inputScalar, std::string& desiredOutput);
void DashScalar(std::string& inputScalar, std::string& desiredOutput);
void URLScalar(std::string& inputScalar, std::string& desiredOutput);
namespace Parser {
// scalar tests
void SimpleScalar(std::string& inputScalar, std::string& desiredOutput);
void MultiLineScalar(std::string& inputScalar, std::string& desiredOutput);
void LiteralScalar(std::string& inputScalar, std::string& desiredOutput);
void FoldedScalar(std::string& inputScalar, std::string& desiredOutput);
void ChompedFoldedScalar(std::string& inputScalar, std::string& desiredOutput);
void ChompedLiteralScalar(std::string& inputScalar, std::string& desiredOutput);
void FoldedScalarWithIndent(std::string& inputScalar,
std::string& desiredOutput);
void ColonScalar(std::string& inputScalar, std::string& desiredOutput);
void QuotedScalar(std::string& inputScalar, std::string& desiredOutput);
void CommaScalar(std::string& inputScalar, std::string& desiredOutput);
void DashScalar(std::string& inputScalar, std::string& desiredOutput);
void URLScalar(std::string& inputScalar, std::string& desiredOutput);
// misc tests
bool SimpleSeq();
bool SimpleMap();
bool FlowSeq();
bool FlowMap();
bool FlowMapWithOmittedKey();
bool FlowMapWithOmittedValue();
bool FlowMapWithSoloEntry();
bool FlowMapEndingWithSoloEntry();
bool QuotedSimpleKeys();
bool CompressedMapAndSeq();
bool NullBlockSeqEntry();
bool NullBlockMapKey();
bool NullBlockMapValue();
bool SimpleAlias();
bool AliasWithNull();
bool AnchorInSimpleKey();
bool AliasAsSimpleKey();
bool ExplicitDoc();
bool MultipleDocs();
bool ExplicitEndDoc();
bool MultipleDocsWithSomeExplicitIndicators();
}
// misc tests
bool SimpleSeq();
bool SimpleMap();
bool FlowSeq();
bool FlowMap();
bool FlowMapWithOmittedKey();
bool FlowMapWithOmittedValue();
bool FlowMapWithSoloEntry();
bool FlowMapEndingWithSoloEntry();
bool QuotedSimpleKeys();
bool CompressedMapAndSeq();
bool NullBlockSeqEntry();
bool NullBlockMapKey();
bool NullBlockMapValue();
bool SimpleAlias();
bool AliasWithNull();
bool AnchorInSimpleKey();
bool AliasAsSimpleKey();
bool ExplicitDoc();
bool MultipleDocs();
bool ExplicitEndDoc();
bool MultipleDocsWithSomeExplicitIndicators();
}
}
#endif // TESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
......@@ -2,17 +2,19 @@
#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
{
struct TEST {
TEST(): ok(false) {}
TEST(bool ok_): ok(ok_) {}
TEST(const char *error_): ok(false), error(error_) {}
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;
};
};
}
......@@ -3,8 +3,7 @@
#include "yaml-cpp/yaml.h"
#include <iostream>
int main()
{
int main() {
{
// test.yaml
// - foo
......@@ -46,7 +45,8 @@ int main()
other.push_back(root); // &1 [5, ~, two, *1]
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[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()
node[0] = 1; // [1] # auto-construct a sequence
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.erase("key"); // {0: 1} # still a map, even if we remove the key that caused the problem
node = "Hello"; // Hello # assignment overwrites everything, so it's now just a plain scalar
node.erase("key"); // {0: 1} # still a map, even if we remove the key that
// caused the problem
node = "Hello"; // Hello # assignment overwrites everything, so it's now
// just a plain scalar
}
{
......@@ -74,18 +76,22 @@ int main()
{
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
YAML::Value subnode2 = node["key2"];
node["key3"] = subnode2; // subnode2 is still not instantiated, but node["key3"] is "pseudo" aliased to it
subnode2 = "monkey"; // {key: value, key2: &1 monkey, key3: *1} # bam! it instantiates both
node["key3"] = subnode2; // subnode2 is still not instantiated, but
// 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();
seq[0] = "zero"; // [zero]
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
seq[1] = "one"; // [&1 one, *1]
UnAlias(seq[1]); // [one, one]
......@@ -98,9 +104,11 @@ int main()
root.push_back("one");
root.push_back("two");
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 @@
#include "yaml-cpp/eventhandler.h"
#include <iostream>
class NullEventHandler: public YAML::EventHandler
{
public:
class NullEventHandler : public YAML::EventHandler {
public:
typedef YAML::Mark Mark;
typedef YAML::anchor_t anchor_t;
......@@ -14,15 +13,15 @@ public:
virtual void OnDocumentEnd() {}
virtual void OnNull(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 OnSequenceEnd() {}
virtual void OnMapStart(const Mark&, const std::string&, anchor_t) {}
virtual void OnMapEnd() {}
};
int main()
{
int main() {
YAML::Parser parser(std::cin);
NullEventHandler handler;
parser.HandleNextDocument(handler);
......
......@@ -2,9 +2,8 @@
#include "yaml-cpp/eventhandler.h"
#include <iostream>
class NullEventHandler: public YAML::EventHandler
{
public:
class NullEventHandler : public YAML::EventHandler {
public:
typedef YAML::Mark Mark;
typedef YAML::anchor_t anchor_t;
......@@ -14,18 +13,18 @@ public:
virtual void OnDocumentEnd() {}
virtual void OnNull(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 OnSequenceEnd() {}
virtual void OnMapStart(const Mark&, const std::string&, anchor_t) {}
virtual void OnMapEnd() {}
};
int main()
{
int main() {
std::stringstream stream("---{header: {id: 1");
YAML::Parser parser(stream);
// parser.PrintTokens(std::cout);
// parser.PrintTokens(std::cout);
NullEventHandler handler;
parser.HandleNextDocument(handler);
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