mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Compare commits
16 Commits
release-0.
...
release-0.
Author | SHA1 | Date | |
---|---|---|---|
![]() |
beb524489c | ||
![]() |
4ffb93c12b | ||
![]() |
ae06a40fe6 | ||
![]() |
315b00065b | ||
![]() |
6f02f7556e | ||
![]() |
fa0af88dfe | ||
![]() |
bce845bb1f | ||
![]() |
ed570b9f7c | ||
![]() |
59b0e986bf | ||
![]() |
cffb98d15b | ||
![]() |
3e1ba0f3b4 | ||
![]() |
d0b5bf4b7b | ||
![]() |
7db39e66b8 | ||
![]() |
94eb7f1dbd | ||
![]() |
5733b77b84 | ||
![]() |
98bebfb628 |
@@ -10,16 +10,18 @@ if(IPHONE)
|
|||||||
endif(IPHONE)
|
endif(IPHONE)
|
||||||
|
|
||||||
if(CMAKE_COMPILER_IS_GNUCC)
|
if(CMAKE_COMPILER_IS_GNUCC)
|
||||||
set(CMAKE_CXX_FLAGS "-O2 -Wall -pedantic -Wextra")
|
set(CMAKE_CXX_FLAGS "-O2 -Wall -pedantic -Wextra ${CMAKE_CXX_FLAGS}")
|
||||||
endif(CMAKE_COMPILER_IS_GNUCC)
|
endif(CMAKE_COMPILER_IS_GNUCC)
|
||||||
|
|
||||||
set(YAML_CPP_VERSION_MAJOR "0")
|
set(YAML_CPP_VERSION_MAJOR "0")
|
||||||
set(YAML_CPP_VERSION_MINOR "2")
|
set(YAML_CPP_VERSION_MINOR "2")
|
||||||
set(YAML_CPP_VERSION_PATCH "1")
|
set(YAML_CPP_VERSION_PATCH "2")
|
||||||
set(YAML_CPP_VERSION "${YAML_CPP_VERSION_MAJOR}.${YAML_CPP_VERSION_MINOR}.${YAML_CPP_VERSION_PATCH}")
|
set(YAML_CPP_VERSION "${YAML_CPP_VERSION_MAJOR}.${YAML_CPP_VERSION_MINOR}.${YAML_CPP_VERSION_PATCH}")
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
|
option(YAML_CPP_BUILD_TOOLS "Enables or disables yaml-reader and parse tools" true)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(_library_dir bin) # .dll are in PATH, like executables
|
set(_library_dir bin) # .dll are in PATH, like executables
|
||||||
else(WIN32)
|
else(WIN32)
|
||||||
@@ -64,5 +66,7 @@ if(UNIX)
|
|||||||
install(FILES ${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
|
install(FILES ${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
|
||||||
endif(UNIX)
|
endif(UNIX)
|
||||||
|
|
||||||
add_subdirectory (yaml-reader)
|
if(YAML_CPP_BUILD_TOOLS)
|
||||||
add_subdirectory (util)
|
add_subdirectory (yaml-reader)
|
||||||
|
add_subdirectory (util)
|
||||||
|
endif(YAML_CPP_BUILD_TOOLS)
|
||||||
|
@@ -29,6 +29,7 @@ namespace YAML
|
|||||||
const std::string GetLastError() const;
|
const std::string GetLastError() const;
|
||||||
|
|
||||||
// global setters
|
// global setters
|
||||||
|
bool SetOutputCharset(EMITTER_MANIP value);
|
||||||
bool SetStringFormat(EMITTER_MANIP value);
|
bool SetStringFormat(EMITTER_MANIP value);
|
||||||
bool SetBoolFormat(EMITTER_MANIP value);
|
bool SetBoolFormat(EMITTER_MANIP value);
|
||||||
bool SetIntBase(EMITTER_MANIP value);
|
bool SetIntBase(EMITTER_MANIP value);
|
||||||
|
@@ -12,6 +12,10 @@ namespace YAML
|
|||||||
// general manipulators
|
// general manipulators
|
||||||
Auto,
|
Auto,
|
||||||
|
|
||||||
|
// output character set
|
||||||
|
EmitNonAscii,
|
||||||
|
EscapeNonAscii,
|
||||||
|
|
||||||
// string manipulators
|
// string manipulators
|
||||||
// Auto, // duplicate
|
// Auto, // duplicate
|
||||||
SingleQuoted,
|
SingleQuoted,
|
||||||
|
@@ -79,22 +79,22 @@ namespace YAML
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline bool operator == (const T& value, const Node& node) {
|
inline bool operator == (const T& value, const Node& node) {
|
||||||
return value == node.Read<T>();
|
return value == node.operator T();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline bool operator == (const Node& node, const T& value) {
|
inline bool operator == (const Node& node, const T& value) {
|
||||||
return value == node.Read<T>();
|
return value == node.operator T();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline bool operator != (const T& value, const Node& node) {
|
inline bool operator != (const T& value, const Node& node) {
|
||||||
return value != node.Read<T>();
|
return value != node.operator T();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline bool operator != (const Node& node, const T& value) {
|
inline bool operator != (const Node& node, const T& value) {
|
||||||
return value != node.Read<T>();
|
return value != node.operator T();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator == (const char *value, const Node& node) {
|
inline bool operator == (const char *value, const Node& node) {
|
||||||
|
@@ -7,6 +7,17 @@ namespace YAML
|
|||||||
// thanks to litb from stackoverflow.com
|
// thanks to litb from stackoverflow.com
|
||||||
// http://stackoverflow.com/questions/1386183/how-to-call-a-templated-function-if-it-exists-and-something-else-otherwise/1386390#1386390
|
// http://stackoverflow.com/questions/1386183/how-to-call-a-templated-function-if-it-exists-and-something-else-otherwise/1386390#1386390
|
||||||
|
|
||||||
|
// Note: this doesn't work on gcc 3.2, but does on gcc 3.4 and above. I'm not sure about 3.3.
|
||||||
|
|
||||||
|
#if __GNUC__ && (__GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ <= 3))
|
||||||
|
// trick doesn't work? Just fall back to ConvertScalar.
|
||||||
|
// This means that we can't use any user-defined types as keys in a map
|
||||||
|
template <typename T>
|
||||||
|
inline bool Node::Read(T& value) const {
|
||||||
|
return ConvertScalar(*this, value);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// usual case: the trick!
|
||||||
template<bool>
|
template<bool>
|
||||||
struct read_impl;
|
struct read_impl;
|
||||||
|
|
||||||
@@ -52,6 +63,7 @@ namespace YAML
|
|||||||
|
|
||||||
return read_impl<sizeof (fallback::flag(), Convert(std::string(), value), fallback::flag()) != 1>::read(*this, value);
|
return read_impl<sizeof (fallback::flag(), Convert(std::string(), value), fallback::flag()) != 1>::read(*this, value);
|
||||||
}
|
}
|
||||||
|
#endif // done with trick
|
||||||
|
|
||||||
// the main conversion function
|
// the main conversion function
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@@ -4,28 +4,31 @@
|
|||||||
#define PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#define PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
|
|
||||||
|
#include "node.h"
|
||||||
|
#include "parserstate.h"
|
||||||
|
#include "noncopyable.h"
|
||||||
#include <ios>
|
#include <ios>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "node.h"
|
#include <memory>
|
||||||
#include "parserstate.h"
|
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
class Scanner;
|
class Scanner;
|
||||||
struct Token;
|
struct Token;
|
||||||
|
|
||||||
class Parser
|
class Parser: private noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Parser();
|
||||||
Parser(std::istream& in);
|
Parser(std::istream& in);
|
||||||
~Parser();
|
~Parser();
|
||||||
|
|
||||||
operator bool() const;
|
operator bool() const;
|
||||||
|
|
||||||
void Load(std::istream& in);
|
void Load(std::istream& in);
|
||||||
void GetNextDocument(Node& document);
|
bool GetNextDocument(Node& document);
|
||||||
void PrintTokens(std::ostream& out);
|
void PrintTokens(std::ostream& out);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -35,12 +38,7 @@ namespace YAML
|
|||||||
void HandleTagDirective(Token *pToken);
|
void HandleTagDirective(Token *pToken);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// can't copy this
|
std::auto_ptr<Scanner> m_pScanner;
|
||||||
Parser(const Parser&) {}
|
|
||||||
Parser& operator = (const Parser&) { return *this; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
Scanner *m_pScanner;
|
|
||||||
ParserState m_state;
|
ParserState m_state;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -37,6 +37,11 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
// global setters
|
// global setters
|
||||||
|
bool Emitter::SetOutputCharset(EMITTER_MANIP value)
|
||||||
|
{
|
||||||
|
return m_pState->SetOutputCharset(value, GLOBAL);
|
||||||
|
}
|
||||||
|
|
||||||
bool Emitter::SetStringFormat(EMITTER_MANIP value)
|
bool Emitter::SetStringFormat(EMITTER_MANIP value)
|
||||||
{
|
{
|
||||||
return m_pState->SetStringFormat(value, GLOBAL);
|
return m_pState->SetStringFormat(value, GLOBAL);
|
||||||
@@ -344,12 +349,18 @@ namespace YAML
|
|||||||
|
|
||||||
EMITTER_STATE curState = m_pState->GetCurState();
|
EMITTER_STATE curState = m_pState->GetCurState();
|
||||||
FLOW_TYPE flowType = m_pState->GetCurGroupFlowType();
|
FLOW_TYPE flowType = m_pState->GetCurGroupFlowType();
|
||||||
if(flowType == FT_BLOCK)
|
if(flowType == FT_BLOCK) {
|
||||||
assert(curState == ES_DONE_WITH_BLOCK_SEQ_ENTRY);
|
// Note: block sequences are *not* allowed to be empty, but we convert it
|
||||||
else if(flowType == FT_FLOW) {
|
// to a flow sequence if it is
|
||||||
m_stream << "]";
|
assert(curState == ES_DONE_WITH_BLOCK_SEQ_ENTRY || curState == ES_WAITING_FOR_BLOCK_SEQ_ENTRY);
|
||||||
|
if(curState == ES_WAITING_FOR_BLOCK_SEQ_ENTRY) {
|
||||||
|
unsigned curIndent = m_pState->GetCurIndent();
|
||||||
|
m_stream << IndentTo(curIndent) << "[]";
|
||||||
|
}
|
||||||
|
} else if(flowType == FT_FLOW) {
|
||||||
// Note: flow sequences are allowed to be empty
|
// Note: flow sequences are allowed to be empty
|
||||||
assert(curState == ES_DONE_WITH_FLOW_SEQ_ENTRY || curState == ES_WAITING_FOR_FLOW_SEQ_ENTRY);
|
assert(curState == ES_DONE_WITH_FLOW_SEQ_ENTRY || curState == ES_WAITING_FOR_FLOW_SEQ_ENTRY);
|
||||||
|
m_stream << "]";
|
||||||
} else
|
} else
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
||||||
@@ -399,12 +410,18 @@ namespace YAML
|
|||||||
|
|
||||||
EMITTER_STATE curState = m_pState->GetCurState();
|
EMITTER_STATE curState = m_pState->GetCurState();
|
||||||
FLOW_TYPE flowType = m_pState->GetCurGroupFlowType();
|
FLOW_TYPE flowType = m_pState->GetCurGroupFlowType();
|
||||||
if(flowType == FT_BLOCK)
|
if(flowType == FT_BLOCK) {
|
||||||
assert(curState == ES_DONE_WITH_BLOCK_MAP_VALUE);
|
// Note: block sequences are *not* allowed to be empty, but we convert it
|
||||||
else if(flowType == FT_FLOW) {
|
// to a flow sequence if it is
|
||||||
m_stream << "}";
|
assert(curState == ES_DONE_WITH_BLOCK_MAP_VALUE || curState == ES_WAITING_FOR_BLOCK_MAP_ENTRY);
|
||||||
|
if(curState == ES_WAITING_FOR_BLOCK_MAP_ENTRY) {
|
||||||
|
unsigned curIndent = m_pState->GetCurIndent();
|
||||||
|
m_stream << IndentTo(curIndent) << "{}";
|
||||||
|
}
|
||||||
|
} else if(flowType == FT_FLOW) {
|
||||||
// Note: flow maps are allowed to be empty
|
// Note: flow maps are allowed to be empty
|
||||||
assert(curState == ES_DONE_WITH_FLOW_MAP_VALUE || curState == ES_WAITING_FOR_FLOW_MAP_ENTRY);
|
assert(curState == ES_DONE_WITH_FLOW_MAP_VALUE || curState == ES_WAITING_FOR_FLOW_MAP_ENTRY);
|
||||||
|
m_stream << "}";
|
||||||
} else
|
} else
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
||||||
@@ -485,13 +502,14 @@ namespace YAML
|
|||||||
PreAtomicWrite();
|
PreAtomicWrite();
|
||||||
EmitSeparationIfNecessary();
|
EmitSeparationIfNecessary();
|
||||||
|
|
||||||
|
bool escapeNonAscii = m_pState->GetOutputCharset() == EscapeNonAscii;
|
||||||
EMITTER_MANIP strFmt = m_pState->GetStringFormat();
|
EMITTER_MANIP strFmt = m_pState->GetStringFormat();
|
||||||
FLOW_TYPE flowType = m_pState->GetCurGroupFlowType();
|
FLOW_TYPE flowType = m_pState->GetCurGroupFlowType();
|
||||||
unsigned curIndent = m_pState->GetCurIndent();
|
unsigned curIndent = m_pState->GetCurIndent();
|
||||||
|
|
||||||
switch(strFmt) {
|
switch(strFmt) {
|
||||||
case Auto:
|
case Auto:
|
||||||
Utils::WriteString(m_stream, str, flowType == FT_FLOW);
|
Utils::WriteString(m_stream, str, flowType == FT_FLOW, escapeNonAscii);
|
||||||
break;
|
break;
|
||||||
case SingleQuoted:
|
case SingleQuoted:
|
||||||
if(!Utils::WriteSingleQuotedString(m_stream, str)) {
|
if(!Utils::WriteSingleQuotedString(m_stream, str)) {
|
||||||
@@ -500,11 +518,11 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DoubleQuoted:
|
case DoubleQuoted:
|
||||||
Utils::WriteDoubleQuotedString(m_stream, str);
|
Utils::WriteDoubleQuotedString(m_stream, str, escapeNonAscii);
|
||||||
break;
|
break;
|
||||||
case Literal:
|
case Literal:
|
||||||
if(flowType == FT_FLOW)
|
if(flowType == FT_FLOW)
|
||||||
Utils::WriteString(m_stream, str, flowType == FT_FLOW);
|
Utils::WriteString(m_stream, str, flowType == FT_FLOW, escapeNonAscii);
|
||||||
else
|
else
|
||||||
Utils::WriteLiteralString(m_stream, str, curIndent + m_pState->GetIndent());
|
Utils::WriteLiteralString(m_stream, str, curIndent + m_pState->GetIndent());
|
||||||
break;
|
break;
|
||||||
@@ -679,3 +697,4 @@ namespace YAML
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,6 +9,7 @@ namespace YAML
|
|||||||
m_stateStack.push(ES_WAITING_FOR_DOC);
|
m_stateStack.push(ES_WAITING_FOR_DOC);
|
||||||
|
|
||||||
// set default global manipulators
|
// set default global manipulators
|
||||||
|
m_charset.set(EmitNonAscii);
|
||||||
m_strFmt.set(Auto);
|
m_strFmt.set(Auto);
|
||||||
m_boolFmt.set(TrueFalseBool);
|
m_boolFmt.set(TrueFalseBool);
|
||||||
m_boolLengthFmt.set(LongBool);
|
m_boolLengthFmt.set(LongBool);
|
||||||
@@ -43,6 +44,7 @@ namespace YAML
|
|||||||
// . Only the ones that make sense will be accepted
|
// . Only the ones that make sense will be accepted
|
||||||
void EmitterState::SetLocalValue(EMITTER_MANIP value)
|
void EmitterState::SetLocalValue(EMITTER_MANIP value)
|
||||||
{
|
{
|
||||||
|
SetOutputCharset(value, LOCAL);
|
||||||
SetStringFormat(value, LOCAL);
|
SetStringFormat(value, LOCAL);
|
||||||
SetBoolFormat(value, LOCAL);
|
SetBoolFormat(value, LOCAL);
|
||||||
SetBoolCaseFormat(value, LOCAL);
|
SetBoolCaseFormat(value, LOCAL);
|
||||||
@@ -133,6 +135,18 @@ namespace YAML
|
|||||||
m_modifiedSettings.clear();
|
m_modifiedSettings.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EmitterState::SetOutputCharset(EMITTER_MANIP value, FMT_SCOPE scope)
|
||||||
|
{
|
||||||
|
switch(value) {
|
||||||
|
case EmitNonAscii:
|
||||||
|
case EscapeNonAscii:
|
||||||
|
_Set(m_charset, value, scope);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool EmitterState::SetStringFormat(EMITTER_MANIP value, FMT_SCOPE scope)
|
bool EmitterState::SetStringFormat(EMITTER_MANIP value, FMT_SCOPE scope)
|
||||||
{
|
{
|
||||||
switch(value) {
|
switch(value) {
|
||||||
|
@@ -108,6 +108,9 @@ namespace YAML
|
|||||||
void ClearModifiedSettings();
|
void ClearModifiedSettings();
|
||||||
|
|
||||||
// formatters
|
// formatters
|
||||||
|
bool SetOutputCharset(EMITTER_MANIP value, FMT_SCOPE scope);
|
||||||
|
EMITTER_MANIP GetOutputCharset() const { return m_charset.get(); }
|
||||||
|
|
||||||
bool SetStringFormat(EMITTER_MANIP value, FMT_SCOPE scope);
|
bool SetStringFormat(EMITTER_MANIP value, FMT_SCOPE scope);
|
||||||
EMITTER_MANIP GetStringFormat() const { return m_strFmt.get(); }
|
EMITTER_MANIP GetStringFormat() const { return m_strFmt.get(); }
|
||||||
|
|
||||||
@@ -149,6 +152,7 @@ namespace YAML
|
|||||||
// other state
|
// other state
|
||||||
std::stack <EMITTER_STATE> m_stateStack;
|
std::stack <EMITTER_STATE> m_stateStack;
|
||||||
|
|
||||||
|
Setting <EMITTER_MANIP> m_charset;
|
||||||
Setting <EMITTER_MANIP> m_strFmt;
|
Setting <EMITTER_MANIP> m_strFmt;
|
||||||
Setting <EMITTER_MANIP> m_boolFmt;
|
Setting <EMITTER_MANIP> m_boolFmt;
|
||||||
Setting <EMITTER_MANIP> m_boolLengthFmt;
|
Setting <EMITTER_MANIP> m_boolLengthFmt;
|
||||||
|
@@ -11,11 +11,123 @@ namespace YAML
|
|||||||
namespace Utils
|
namespace Utils
|
||||||
{
|
{
|
||||||
namespace {
|
namespace {
|
||||||
bool IsPrintable(char ch) {
|
enum {REPLACEMENT_CHARACTER = 0xFFFD};
|
||||||
return (0x20 <= ch && ch <= 0x7E);
|
|
||||||
|
bool IsAnchorChar(int ch) { // test for ns-anchor-char
|
||||||
|
switch (ch) {
|
||||||
|
case ',': case '[': case ']': case '{': case '}': // c-flow-indicator
|
||||||
|
case ' ': case '\t': // s-white
|
||||||
|
case 0xFEFF: // c-byte-order-mark
|
||||||
|
case 0xA: case 0xD: // b-char
|
||||||
|
return false;
|
||||||
|
case 0x85:
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsValidPlainScalar(const std::string& str, bool inFlow) {
|
if (ch < 0x20)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (ch < 0x7E)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (ch < 0xA0)
|
||||||
|
return false;
|
||||||
|
if (ch >= 0xD800 && ch <= 0xDFFF)
|
||||||
|
return false;
|
||||||
|
if ((ch & 0xFFFE) == 0xFFFE)
|
||||||
|
return false;
|
||||||
|
if ((ch >= 0xFDD0) && (ch <= 0xFDEF))
|
||||||
|
return false;
|
||||||
|
if (ch > 0x10FFFF)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Utf8BytesIndicated(char ch) {
|
||||||
|
int byteVal = static_cast<unsigned char>(ch);
|
||||||
|
switch (byteVal >> 4) {
|
||||||
|
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
|
||||||
|
return 1;
|
||||||
|
case 12: case 13:
|
||||||
|
return 2;
|
||||||
|
case 14:
|
||||||
|
return 3;
|
||||||
|
case 15:
|
||||||
|
return 4;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsTrailingByte(char ch) {
|
||||||
|
return (ch & 0xC0) == 0x80;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GetNextCodePointAndAdvance(int& codePoint, std::string::const_iterator& first, std::string::const_iterator last) {
|
||||||
|
if (first == last)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int nBytes = Utf8BytesIndicated(*first);
|
||||||
|
if (nBytes < 1) {
|
||||||
|
// Bad lead byte
|
||||||
|
++first;
|
||||||
|
codePoint = REPLACEMENT_CHARACTER;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nBytes == 1) {
|
||||||
|
codePoint = *first++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gather bits from trailing bytes
|
||||||
|
codePoint = static_cast<unsigned char>(*first) & ~(0xFF << (7 - nBytes));
|
||||||
|
++first;
|
||||||
|
--nBytes;
|
||||||
|
for (; nBytes > 0; ++first, --nBytes) {
|
||||||
|
if ((first == last) || !IsTrailingByte(*first)) {
|
||||||
|
codePoint = REPLACEMENT_CHARACTER;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
codePoint <<= 6;
|
||||||
|
codePoint |= *first & 0x3F;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for illegal code points
|
||||||
|
if (codePoint > 0x10FFFF)
|
||||||
|
codePoint = REPLACEMENT_CHARACTER;
|
||||||
|
else if (codePoint >= 0xD800 && codePoint <= 0xDFFF)
|
||||||
|
codePoint = REPLACEMENT_CHARACTER;
|
||||||
|
else if ((codePoint & 0xFFFE) == 0xFFFE)
|
||||||
|
codePoint = REPLACEMENT_CHARACTER;
|
||||||
|
else if (codePoint >= 0xFDD0 && codePoint <= 0xFDEF)
|
||||||
|
codePoint = REPLACEMENT_CHARACTER;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WriteCodePoint(ostream& out, int codePoint) {
|
||||||
|
if (codePoint < 0 || codePoint > 0x10FFFF) {
|
||||||
|
codePoint = REPLACEMENT_CHARACTER;
|
||||||
|
}
|
||||||
|
if (codePoint < 0x7F) {
|
||||||
|
out << static_cast<char>(codePoint);
|
||||||
|
} else if (codePoint < 0x7FF) {
|
||||||
|
out << static_cast<char>(0xC0 | (codePoint >> 6))
|
||||||
|
<< static_cast<char>(0x80 | (codePoint & 0x3F));
|
||||||
|
} else if (codePoint < 0xFFFF) {
|
||||||
|
out << static_cast<char>(0xE0 | (codePoint >> 12))
|
||||||
|
<< static_cast<char>(0x80 | ((codePoint >> 6) & 0x3F))
|
||||||
|
<< static_cast<char>(0x80 | (codePoint & 0x3F));
|
||||||
|
} else {
|
||||||
|
out << static_cast<char>(0xF0 | (codePoint >> 18))
|
||||||
|
<< static_cast<char>(0x80 | ((codePoint >> 12) & 0x3F))
|
||||||
|
<< static_cast<char>(0x80 | ((codePoint >> 6) & 0x3F))
|
||||||
|
<< static_cast<char>(0x80 | (codePoint & 0x3F));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsValidPlainScalar(const std::string& str, bool inFlow, bool allowOnlyAscii) {
|
||||||
// first check the start
|
// first check the start
|
||||||
const RegEx& start = (inFlow ? Exp::PlainScalarInFlow : Exp::PlainScalar);
|
const RegEx& start = (inFlow ? Exp::PlainScalarInFlow : Exp::PlainScalar);
|
||||||
if(!start.Matches(str))
|
if(!start.Matches(str))
|
||||||
@@ -28,64 +140,109 @@ namespace YAML
|
|||||||
// then check until something is disallowed
|
// then check until something is disallowed
|
||||||
const RegEx& disallowed = (inFlow ? Exp::EndScalarInFlow : Exp::EndScalar)
|
const RegEx& disallowed = (inFlow ? Exp::EndScalarInFlow : Exp::EndScalar)
|
||||||
|| (Exp::BlankOrBreak + Exp::Comment)
|
|| (Exp::BlankOrBreak + Exp::Comment)
|
||||||
|| (!Exp::Printable)
|
|| Exp::NotPrintable
|
||||||
|
|| Exp::Utf8_ByteOrderMark
|
||||||
|| Exp::Break
|
|| Exp::Break
|
||||||
|| Exp::Tab;
|
|| Exp::Tab;
|
||||||
StringCharSource buffer(str.c_str(), str.size());
|
StringCharSource buffer(str.c_str(), str.size());
|
||||||
while(buffer) {
|
while(buffer) {
|
||||||
if(disallowed.Matches(buffer))
|
if(disallowed.Matches(buffer))
|
||||||
return false;
|
return false;
|
||||||
|
if(allowOnlyAscii && (0x7F < static_cast<unsigned char>(buffer[0])))
|
||||||
|
return false;
|
||||||
++buffer;
|
++buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WriteDoubleQuoteEscapeSequence(ostream& out, int codePoint) {
|
||||||
|
static const char hexDigits[] = "0123456789abcdef";
|
||||||
|
|
||||||
|
char escSeq[] = "\\U00000000";
|
||||||
|
int digits = 8;
|
||||||
|
if (codePoint < 0xFF) {
|
||||||
|
escSeq[1] = 'x';
|
||||||
|
digits = 2;
|
||||||
|
} else if (codePoint < 0xFFFF) {
|
||||||
|
escSeq[1] = 'u';
|
||||||
|
digits = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WriteString(ostream& out, const std::string& str, bool inFlow)
|
// Write digits into the escape sequence
|
||||||
|
int i = 2;
|
||||||
|
for (; digits > 0; --digits, ++i) {
|
||||||
|
escSeq[i] = hexDigits[(codePoint >> (4 * (digits - 1))) & 0xF];
|
||||||
|
}
|
||||||
|
|
||||||
|
escSeq[i] = 0; // terminate with NUL character
|
||||||
|
out << escSeq;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WriteAliasName(ostream& out, const std::string& str) {
|
||||||
|
int codePoint;
|
||||||
|
for(std::string::const_iterator i = str.begin();
|
||||||
|
GetNextCodePointAndAdvance(codePoint, i, str.end());
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if(IsValidPlainScalar(str, inFlow)) {
|
if (!IsAnchorChar(codePoint))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
WriteCodePoint(out, codePoint);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WriteString(ostream& out, const std::string& str, bool inFlow, bool escapeNonAscii)
|
||||||
|
{
|
||||||
|
if(IsValidPlainScalar(str, inFlow, escapeNonAscii)) {
|
||||||
out << str;
|
out << str;
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else
|
||||||
return WriteDoubleQuotedString(out, str);
|
return WriteDoubleQuotedString(out, str, escapeNonAscii);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WriteSingleQuotedString(ostream& out, const std::string& str)
|
bool WriteSingleQuotedString(ostream& out, const std::string& str)
|
||||||
{
|
{
|
||||||
out << "'";
|
out << "'";
|
||||||
for(std::size_t i=0;i<str.size();i++) {
|
int codePoint;
|
||||||
char ch = str[i];
|
for(std::string::const_iterator i = str.begin();
|
||||||
if(!IsPrintable(ch))
|
GetNextCodePointAndAdvance(codePoint, i, str.end());
|
||||||
return false;
|
)
|
||||||
|
{
|
||||||
|
if (codePoint == '\n')
|
||||||
|
return false; // We can't handle a new line and the attendant indentation yet
|
||||||
|
|
||||||
if(ch == '\'')
|
if (codePoint == '\'')
|
||||||
out << "''";
|
out << "''";
|
||||||
else
|
else
|
||||||
out << ch;
|
WriteCodePoint(out, codePoint);
|
||||||
}
|
}
|
||||||
out << "'";
|
out << "'";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WriteDoubleQuotedString(ostream& out, const std::string& str)
|
bool WriteDoubleQuotedString(ostream& out, const std::string& str, bool escapeNonAscii)
|
||||||
{
|
{
|
||||||
out << "\"";
|
out << "\"";
|
||||||
for(std::size_t i=0;i<str.size();i++) {
|
int codePoint;
|
||||||
char ch = str[i];
|
for(std::string::const_iterator i = str.begin();
|
||||||
if(IsPrintable(ch)) {
|
GetNextCodePointAndAdvance(codePoint, i, str.end());
|
||||||
if(ch == '\"')
|
)
|
||||||
|
{
|
||||||
|
if (codePoint == '\"')
|
||||||
out << "\\\"";
|
out << "\\\"";
|
||||||
else if(ch == '\\')
|
else if (codePoint == '\\')
|
||||||
out << "\\\\";
|
out << "\\\\";
|
||||||
|
else if (codePoint < 0x20 || (codePoint >= 0x80 && codePoint <= 0xA0)) // Control characters and non-breaking space
|
||||||
|
WriteDoubleQuoteEscapeSequence(out, codePoint);
|
||||||
|
else if (codePoint == 0xFEFF) // Byte order marks (ZWNS) should be escaped (YAML 1.2, sec. 5.2)
|
||||||
|
WriteDoubleQuoteEscapeSequence(out, codePoint);
|
||||||
|
else if (escapeNonAscii && codePoint > 0x7E)
|
||||||
|
WriteDoubleQuoteEscapeSequence(out, codePoint);
|
||||||
else
|
else
|
||||||
out << ch;
|
WriteCodePoint(out, codePoint);
|
||||||
} else {
|
|
||||||
// TODO: for the common escaped characters, give their usual symbol
|
|
||||||
std::stringstream str;
|
|
||||||
str << "\\x" << std::hex << std::setfill('0') << std::setw(2) << static_cast<unsigned int>(static_cast<unsigned char>(ch));
|
|
||||||
out << str.str();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
out << "\"";
|
out << "\"";
|
||||||
return true;
|
return true;
|
||||||
@@ -95,11 +252,15 @@ namespace YAML
|
|||||||
{
|
{
|
||||||
out << "|\n";
|
out << "|\n";
|
||||||
out << IndentTo(indent);
|
out << IndentTo(indent);
|
||||||
for(std::size_t i=0;i<str.size();i++) {
|
int codePoint;
|
||||||
if(str[i] == '\n')
|
for(std::string::const_iterator i = str.begin();
|
||||||
|
GetNextCodePointAndAdvance(codePoint, i, str.end());
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (codePoint == '\n')
|
||||||
out << "\n" << IndentTo(indent);
|
out << "\n" << IndentTo(indent);
|
||||||
else
|
else
|
||||||
out << str[i];
|
WriteCodePoint(out, codePoint);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -108,11 +269,15 @@ namespace YAML
|
|||||||
{
|
{
|
||||||
unsigned curIndent = out.col();
|
unsigned curIndent = out.col();
|
||||||
out << "#" << Indentation(postCommentIndent);
|
out << "#" << Indentation(postCommentIndent);
|
||||||
for(std::size_t i=0;i<str.size();i++) {
|
int codePoint;
|
||||||
if(str[i] == '\n')
|
for(std::string::const_iterator i = str.begin();
|
||||||
|
GetNextCodePointAndAdvance(codePoint, i, str.end());
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if(codePoint == '\n')
|
||||||
out << "\n" << IndentTo(curIndent) << "#" << Indentation(postCommentIndent);
|
out << "\n" << IndentTo(curIndent) << "#" << Indentation(postCommentIndent);
|
||||||
else
|
else
|
||||||
out << str[i];
|
WriteCodePoint(out, codePoint);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -120,25 +285,13 @@ namespace YAML
|
|||||||
bool WriteAlias(ostream& out, const std::string& str)
|
bool WriteAlias(ostream& out, const std::string& str)
|
||||||
{
|
{
|
||||||
out << "*";
|
out << "*";
|
||||||
for(std::size_t i=0;i<str.size();i++) {
|
return WriteAliasName(out, str);
|
||||||
if(!IsPrintable(str[i]) || str[i] == ' ' || str[i] == '\t' || str[i] == '\n' || str[i] == '\r')
|
|
||||||
return false;
|
|
||||||
|
|
||||||
out << str[i];
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WriteAnchor(ostream& out, const std::string& str)
|
bool WriteAnchor(ostream& out, const std::string& str)
|
||||||
{
|
{
|
||||||
out << "&";
|
out << "&";
|
||||||
for(std::size_t i=0;i<str.size();i++) {
|
return WriteAliasName(out, str);
|
||||||
if(!IsPrintable(str[i]) || str[i] == ' ' || str[i] == '\t' || str[i] == '\n' || str[i] == '\r')
|
|
||||||
return false;
|
|
||||||
|
|
||||||
out << str[i];
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,9 +11,9 @@ namespace YAML
|
|||||||
{
|
{
|
||||||
namespace Utils
|
namespace Utils
|
||||||
{
|
{
|
||||||
bool WriteString(ostream& out, const std::string& str, bool inFlow);
|
bool WriteString(ostream& out, const std::string& str, bool inFlow, bool escapeNonAscii);
|
||||||
bool WriteSingleQuotedString(ostream& out, const std::string& str);
|
bool WriteSingleQuotedString(ostream& out, const std::string& str);
|
||||||
bool WriteDoubleQuotedString(ostream& out, const std::string& str);
|
bool WriteDoubleQuotedString(ostream& out, const std::string& str, bool escapeNonAscii);
|
||||||
bool WriteLiteralString(ostream& out, const std::string& str, int indent);
|
bool WriteLiteralString(ostream& out, const std::string& str, int indent);
|
||||||
bool WriteComment(ostream& out, const std::string& str, int postCommentIndent);
|
bool WriteComment(ostream& out, const std::string& str, int postCommentIndent);
|
||||||
bool WriteAlias(ostream& out, const std::string& str);
|
bool WriteAlias(ostream& out, const std::string& str);
|
||||||
|
@@ -28,9 +28,9 @@ namespace YAML
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Str(char ch)
|
std::string Str(unsigned ch)
|
||||||
{
|
{
|
||||||
return std::string("") + ch;
|
return std::string(1, static_cast<char>(ch));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escape
|
// Escape
|
||||||
|
@@ -26,7 +26,12 @@ namespace YAML
|
|||||||
const RegEx Alpha = RegEx('a', 'z') || RegEx('A', 'Z');
|
const RegEx Alpha = RegEx('a', 'z') || RegEx('A', 'Z');
|
||||||
const RegEx AlphaNumeric = Alpha || Digit;
|
const RegEx AlphaNumeric = Alpha || Digit;
|
||||||
const RegEx Hex = Digit || RegEx('A', 'F') || RegEx('a', 'f');
|
const RegEx Hex = Digit || RegEx('A', 'F') || RegEx('a', 'f');
|
||||||
const RegEx Printable = RegEx(0x20, 0x7E);
|
// Valid Unicode code points that are not part of c-printable (YAML 1.2, sec. 5.1)
|
||||||
|
const RegEx NotPrintable = RegEx(0) ||
|
||||||
|
RegEx("\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x7F", REGEX_OR) ||
|
||||||
|
RegEx(0x0E, 0x1F) ||
|
||||||
|
(RegEx('\xC2') + (RegEx('\x80', '\x84') || RegEx('\x86', '\x9F')));
|
||||||
|
const RegEx Utf8_ByteOrderMark = RegEx("\xEF\xBB\xBF");
|
||||||
|
|
||||||
// actual tags
|
// actual tags
|
||||||
|
|
||||||
|
@@ -8,33 +8,38 @@
|
|||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
Parser::Parser(std::istream& in): m_pScanner(0)
|
Parser::Parser()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Parser::Parser(std::istream& in)
|
||||||
{
|
{
|
||||||
Load(in);
|
Load(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
Parser::~Parser()
|
Parser::~Parser()
|
||||||
{
|
{
|
||||||
delete m_pScanner;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Parser::operator bool() const
|
Parser::operator bool() const
|
||||||
{
|
{
|
||||||
return !m_pScanner->empty();
|
return m_pScanner.get() && !m_pScanner->empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::Load(std::istream& in)
|
void Parser::Load(std::istream& in)
|
||||||
{
|
{
|
||||||
delete m_pScanner;
|
m_pScanner.reset(new Scanner(in));
|
||||||
m_pScanner = new Scanner(in);
|
|
||||||
m_state.Reset();
|
m_state.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNextDocument
|
// GetNextDocument
|
||||||
// . Reads the next document in the queue (of tokens).
|
// . Reads the next document in the queue (of tokens).
|
||||||
// . Throws a ParserException on error.
|
// . Throws a ParserException on error.
|
||||||
void Parser::GetNextDocument(Node& document)
|
bool Parser::GetNextDocument(Node& document)
|
||||||
{
|
{
|
||||||
|
if(!m_pScanner.get())
|
||||||
|
return false;
|
||||||
|
|
||||||
// clear node
|
// clear node
|
||||||
document.Clear();
|
document.Clear();
|
||||||
|
|
||||||
@@ -43,14 +48,14 @@ namespace YAML
|
|||||||
|
|
||||||
// we better have some tokens in the queue
|
// we better have some tokens in the queue
|
||||||
if(m_pScanner->empty())
|
if(m_pScanner->empty())
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
// first eat doc start (optional)
|
// first eat doc start (optional)
|
||||||
if(m_pScanner->peek().type == Token::DOC_START)
|
if(m_pScanner->peek().type == Token::DOC_START)
|
||||||
m_pScanner->pop();
|
m_pScanner->pop();
|
||||||
|
|
||||||
// now parse our root node
|
// now parse our root node
|
||||||
document.Parse(m_pScanner, m_state);
|
document.Parse(m_pScanner.get(), m_state);
|
||||||
|
|
||||||
// and finally eat any doc ends we see
|
// and finally eat any doc ends we see
|
||||||
while(!m_pScanner->empty() && m_pScanner->peek().type == Token::DOC_END)
|
while(!m_pScanner->empty() && m_pScanner->peek().type == Token::DOC_END)
|
||||||
@@ -58,6 +63,8 @@ namespace YAML
|
|||||||
|
|
||||||
// clear anchors from the scanner, which are no longer relevant
|
// clear anchors from the scanner, which are no longer relevant
|
||||||
m_pScanner->ClearAnchors();
|
m_pScanner->ClearAnchors();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseDirectives
|
// ParseDirectives
|
||||||
@@ -126,6 +133,9 @@ namespace YAML
|
|||||||
|
|
||||||
void Parser::PrintTokens(std::ostream& out)
|
void Parser::PrintTokens(std::ostream& out)
|
||||||
{
|
{
|
||||||
|
if(!m_pScanner.get())
|
||||||
|
return;
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
if(m_pScanner->empty())
|
if(m_pScanner->empty())
|
||||||
break;
|
break;
|
||||||
|
@@ -287,7 +287,7 @@ namespace YAML
|
|||||||
params.end = (InFlowContext() ? Exp::EndScalarInFlow : Exp::EndScalar) || (Exp::BlankOrBreak + Exp::Comment);
|
params.end = (InFlowContext() ? Exp::EndScalarInFlow : Exp::EndScalar) || (Exp::BlankOrBreak + Exp::Comment);
|
||||||
params.eatEnd = false;
|
params.eatEnd = false;
|
||||||
params.indent = (InFlowContext() ? 0 : GetTopIndent() + 1);
|
params.indent = (InFlowContext() ? 0 : GetTopIndent() + 1);
|
||||||
params.fold = FOLD_BLOCK;
|
params.fold = FOLD_FLOW;
|
||||||
params.eatLeadingWhitespace = true;
|
params.eatLeadingWhitespace = true;
|
||||||
params.trimTrailingSpaces = true;
|
params.trimTrailingSpaces = true;
|
||||||
params.chomp = STRIP;
|
params.chomp = STRIP;
|
||||||
|
@@ -11,9 +11,8 @@ int main(int argc, char **argv)
|
|||||||
std::istream& input = (argc > 1 ? fin : std::cin);
|
std::istream& input = (argc > 1 ? fin : std::cin);
|
||||||
try {
|
try {
|
||||||
YAML::Parser parser(input);
|
YAML::Parser parser(input);
|
||||||
while(parser) {
|
|
||||||
YAML::Node doc;
|
YAML::Node doc;
|
||||||
parser.GetNextDocument(doc);
|
while(parser.GetNextDocument(doc)) {
|
||||||
YAML::Emitter emitter;
|
YAML::Emitter emitter;
|
||||||
emitter << doc;
|
emitter << doc;
|
||||||
std::cout << emitter.c_str() << "\n";
|
std::cout << emitter.c_str() << "\n";
|
||||||
|
@@ -448,6 +448,26 @@ namespace Test
|
|||||||
desiredOutput = "- ~\n-\n null value: ~\n ~: null key";
|
desiredOutput = "- ~\n-\n null value: ~\n ~: null key";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
out << YAML::DoubleQuoted << "\x24 \xC2\xA2 \xE2\x82\xAC \xF0\xA4\xAD\xA2";
|
||||||
|
desiredOutput = "\"\x24 \xC2\xA2 \xE2\x82\xAC \xF0\xA4\xAD\xA2\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// incorrect emitting
|
// incorrect emitting
|
||||||
|
|
||||||
@@ -609,6 +629,9 @@ namespace Test
|
|||||||
RunEmitterTest(&Emitter::SimpleGlobalSettings, "simple global settings", passed, total);
|
RunEmitterTest(&Emitter::SimpleGlobalSettings, "simple global settings", passed, total);
|
||||||
RunEmitterTest(&Emitter::ComplexGlobalSettings, "complex global settings", passed, total);
|
RunEmitterTest(&Emitter::ComplexGlobalSettings, "complex global settings", passed, total);
|
||||||
RunEmitterTest(&Emitter::Null, "null", 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);
|
||||||
|
|
||||||
RunEmitterErrorTest(&Emitter::ExtraEndSeq, "extra EndSeq", passed, total);
|
RunEmitterErrorTest(&Emitter::ExtraEndSeq, "extra EndSeq", passed, total);
|
||||||
RunEmitterErrorTest(&Emitter::ExtraEndMap, "extra EndMap", passed, total);
|
RunEmitterErrorTest(&Emitter::ExtraEndMap, "extra EndMap", passed, total);
|
||||||
|
@@ -17,6 +17,12 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#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)
|
||||||
|
#define PARSE(doc, input) \
|
||||||
|
std::stringstream stream(input);\
|
||||||
|
YAML::Parser parser(stream);\
|
||||||
|
YAML::Node doc;\
|
||||||
|
parser.GetNextDocument(doc)
|
||||||
|
#define PARSE_NEXT(doc) parser.GetNextDocument(doc)
|
||||||
|
|
||||||
namespace Test {
|
namespace Test {
|
||||||
namespace {
|
namespace {
|
||||||
@@ -47,11 +53,8 @@ namespace Test {
|
|||||||
"- Mark McGwire\n"
|
"- Mark McGwire\n"
|
||||||
"- Sammy Sosa\n"
|
"- Sammy Sosa\n"
|
||||||
"- Ken Griffey";
|
"- Ken Griffey";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 3);
|
YAML_ASSERT(doc.size() == 3);
|
||||||
YAML_ASSERT(doc[0] == "Mark McGwire");
|
YAML_ASSERT(doc[0] == "Mark McGwire");
|
||||||
YAML_ASSERT(doc[1] == "Sammy Sosa");
|
YAML_ASSERT(doc[1] == "Sammy Sosa");
|
||||||
@@ -65,11 +68,8 @@ namespace Test {
|
|||||||
"hr: 65 # Home runs\n"
|
"hr: 65 # Home runs\n"
|
||||||
"avg: 0.278 # Batting average\n"
|
"avg: 0.278 # Batting average\n"
|
||||||
"rbi: 147 # Runs Batted In";
|
"rbi: 147 # Runs Batted In";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 3);
|
YAML_ASSERT(doc.size() == 3);
|
||||||
YAML_ASSERT(doc["hr"] == "65");
|
YAML_ASSERT(doc["hr"] == "65");
|
||||||
YAML_ASSERT(doc["avg"] == "0.278");
|
YAML_ASSERT(doc["avg"] == "0.278");
|
||||||
@@ -88,11 +88,8 @@ namespace Test {
|
|||||||
"- New York Mets\n"
|
"- New York Mets\n"
|
||||||
"- Chicago Cubs\n"
|
"- Chicago Cubs\n"
|
||||||
"- Atlanta Braves";
|
"- Atlanta Braves";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc["american"].size() == 3);
|
YAML_ASSERT(doc["american"].size() == 3);
|
||||||
YAML_ASSERT(doc["american"][0] == "Boston Red Sox");
|
YAML_ASSERT(doc["american"][0] == "Boston Red Sox");
|
||||||
@@ -117,11 +114,8 @@ namespace Test {
|
|||||||
" name: Sammy Sosa\n"
|
" name: Sammy Sosa\n"
|
||||||
" hr: 63\n"
|
" hr: 63\n"
|
||||||
" avg: 0.288";
|
" avg: 0.288";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc[0].size() == 3);
|
YAML_ASSERT(doc[0].size() == 3);
|
||||||
YAML_ASSERT(doc[0]["name"] == "Mark McGwire");
|
YAML_ASSERT(doc[0]["name"] == "Mark McGwire");
|
||||||
@@ -141,11 +135,8 @@ namespace Test {
|
|||||||
"- [name , hr, avg ]\n"
|
"- [name , hr, avg ]\n"
|
||||||
"- [Mark McGwire, 65, 0.278]\n"
|
"- [Mark McGwire, 65, 0.278]\n"
|
||||||
"- [Sammy Sosa , 63, 0.288]";
|
"- [Sammy Sosa , 63, 0.288]";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 3);
|
YAML_ASSERT(doc.size() == 3);
|
||||||
YAML_ASSERT(doc[0].size() == 3);
|
YAML_ASSERT(doc[0].size() == 3);
|
||||||
YAML_ASSERT(doc[0][0] == "name");
|
YAML_ASSERT(doc[0][0] == "name");
|
||||||
@@ -171,11 +162,8 @@ namespace Test {
|
|||||||
" hr: 63,\n"
|
" hr: 63,\n"
|
||||||
" avg: 0.288\n"
|
" avg: 0.288\n"
|
||||||
" }";
|
" }";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc["Mark McGwire"].size() == 2);
|
YAML_ASSERT(doc["Mark McGwire"].size() == 2);
|
||||||
YAML_ASSERT(doc["Mark McGwire"]["hr"] == "65");
|
YAML_ASSERT(doc["Mark McGwire"]["hr"] == "65");
|
||||||
@@ -200,17 +188,14 @@ namespace Test {
|
|||||||
"---\n"
|
"---\n"
|
||||||
"- Chicago Cubs\n"
|
"- Chicago Cubs\n"
|
||||||
"- St Louis Cardinals";
|
"- St Louis Cardinals";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 3);
|
YAML_ASSERT(doc.size() == 3);
|
||||||
YAML_ASSERT(doc[0] == "Mark McGwire");
|
YAML_ASSERT(doc[0] == "Mark McGwire");
|
||||||
YAML_ASSERT(doc[1] == "Sammy Sosa");
|
YAML_ASSERT(doc[1] == "Sammy Sosa");
|
||||||
YAML_ASSERT(doc[2] == "Ken Griffey");
|
YAML_ASSERT(doc[2] == "Ken Griffey");
|
||||||
|
|
||||||
parser.GetNextDocument(doc);
|
PARSE_NEXT(doc);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc[0] == "Chicago Cubs");
|
YAML_ASSERT(doc[0] == "Chicago Cubs");
|
||||||
YAML_ASSERT(doc[1] == "St Louis Cardinals");
|
YAML_ASSERT(doc[1] == "St Louis Cardinals");
|
||||||
@@ -231,17 +216,14 @@ namespace Test {
|
|||||||
"player: Sammy Sosa\n"
|
"player: Sammy Sosa\n"
|
||||||
"action: grand slam\n"
|
"action: grand slam\n"
|
||||||
"...";
|
"...";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 3);
|
YAML_ASSERT(doc.size() == 3);
|
||||||
YAML_ASSERT(doc["time"] == "20:03:20");
|
YAML_ASSERT(doc["time"] == "20:03:20");
|
||||||
YAML_ASSERT(doc["player"] == "Sammy Sosa");
|
YAML_ASSERT(doc["player"] == "Sammy Sosa");
|
||||||
YAML_ASSERT(doc["action"] == "strike (miss)");
|
YAML_ASSERT(doc["action"] == "strike (miss)");
|
||||||
|
|
||||||
parser.GetNextDocument(doc);
|
PARSE_NEXT(doc);
|
||||||
YAML_ASSERT(doc.size() == 3);
|
YAML_ASSERT(doc.size() == 3);
|
||||||
YAML_ASSERT(doc["time"] == "20:03:47");
|
YAML_ASSERT(doc["time"] == "20:03:47");
|
||||||
YAML_ASSERT(doc["player"] == "Sammy Sosa");
|
YAML_ASSERT(doc["player"] == "Sammy Sosa");
|
||||||
@@ -261,11 +243,8 @@ namespace Test {
|
|||||||
" # 1998 rbi ranking\n"
|
" # 1998 rbi ranking\n"
|
||||||
" - Sammy Sosa\n"
|
" - Sammy Sosa\n"
|
||||||
" - Ken Griffey";
|
" - Ken Griffey";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc["hr"].size() == 2);
|
YAML_ASSERT(doc["hr"].size() == 2);
|
||||||
YAML_ASSERT(doc["hr"][0] == "Mark McGwire");
|
YAML_ASSERT(doc["hr"][0] == "Mark McGwire");
|
||||||
@@ -288,11 +267,8 @@ namespace Test {
|
|||||||
"rbi:\n"
|
"rbi:\n"
|
||||||
" - *SS # Subsequent occurrence\n"
|
" - *SS # Subsequent occurrence\n"
|
||||||
" - Ken Griffey";
|
" - Ken Griffey";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc["hr"].size() == 2);
|
YAML_ASSERT(doc["hr"].size() == 2);
|
||||||
YAML_ASSERT(doc["hr"][0] == "Mark McGwire");
|
YAML_ASSERT(doc["hr"][0] == "Mark McGwire");
|
||||||
@@ -331,11 +307,8 @@ namespace Test {
|
|||||||
" Atlanta Braves ]\n"
|
" Atlanta Braves ]\n"
|
||||||
": [ 2001-07-02, 2001-08-12,\n"
|
": [ 2001-07-02, 2001-08-12,\n"
|
||||||
" 2001-08-14 ]";
|
" 2001-08-14 ]";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc[Pair("Detroit Tigers", "Chicago cubs")].size() == 1);
|
YAML_ASSERT(doc[Pair("Detroit Tigers", "Chicago cubs")].size() == 1);
|
||||||
YAML_ASSERT(doc[Pair("Detroit Tigers", "Chicago cubs")][0] == "2001-07-23");
|
YAML_ASSERT(doc[Pair("Detroit Tigers", "Chicago cubs")][0] == "2001-07-23");
|
||||||
@@ -358,11 +331,8 @@ namespace Test {
|
|||||||
" quantity: 4\n"
|
" quantity: 4\n"
|
||||||
"- item : Big Shoes\n"
|
"- item : Big Shoes\n"
|
||||||
" quantity: 1";
|
" quantity: 1";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 3);
|
YAML_ASSERT(doc.size() == 3);
|
||||||
YAML_ASSERT(doc[0].size() == 2);
|
YAML_ASSERT(doc[0].size() == 2);
|
||||||
YAML_ASSERT(doc[0]["item"] == "Super Hoop");
|
YAML_ASSERT(doc[0]["item"] == "Super Hoop");
|
||||||
@@ -384,11 +354,8 @@ namespace Test {
|
|||||||
"--- |\n"
|
"--- |\n"
|
||||||
" \\//||\\/||\n"
|
" \\//||\\/||\n"
|
||||||
" // || ||__";
|
" // || ||__";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc ==
|
YAML_ASSERT(doc ==
|
||||||
"\\//||\\/||\n"
|
"\\//||\\/||\n"
|
||||||
"// || ||__");
|
"// || ||__");
|
||||||
@@ -403,11 +370,8 @@ namespace Test {
|
|||||||
" Mark McGwire's\n"
|
" Mark McGwire's\n"
|
||||||
" year was crippled\n"
|
" year was crippled\n"
|
||||||
" by a knee injury.";
|
" by a knee injury.";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc == "Mark McGwire's year was crippled by a knee injury.");
|
YAML_ASSERT(doc == "Mark McGwire's year was crippled by a knee injury.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -424,11 +388,8 @@ namespace Test {
|
|||||||
" 0.288 Batting Average\n"
|
" 0.288 Batting Average\n"
|
||||||
" \n"
|
" \n"
|
||||||
" What a year!";
|
" What a year!";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc ==
|
YAML_ASSERT(doc ==
|
||||||
"Sammy Sosa completed another fine season with great stats.\n\n"
|
"Sammy Sosa completed another fine season with great stats.\n\n"
|
||||||
" 63 Home Runs\n"
|
" 63 Home Runs\n"
|
||||||
@@ -448,11 +409,8 @@ namespace Test {
|
|||||||
"stats: |\n"
|
"stats: |\n"
|
||||||
" 65 Home Runs\n"
|
" 65 Home Runs\n"
|
||||||
" 0.278 Batting Average\n";
|
" 0.278 Batting Average\n";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 3);
|
YAML_ASSERT(doc.size() == 3);
|
||||||
YAML_ASSERT(doc["name"] == "Mark McGwire");
|
YAML_ASSERT(doc["name"] == "Mark McGwire");
|
||||||
YAML_ASSERT(doc["accomplishment"] == "Mark set a major league home run record in 1998.\n");
|
YAML_ASSERT(doc["accomplishment"] == "Mark set a major league home run record in 1998.\n");
|
||||||
@@ -471,13 +429,10 @@ namespace Test {
|
|||||||
"single: '\"Howdy!\" he cried.'\n"
|
"single: '\"Howdy!\" he cried.'\n"
|
||||||
"quoted: ' # Not a ''comment''.'\n"
|
"quoted: ' # Not a ''comment''.'\n"
|
||||||
"tie-fighter: '|\\-*-/|'";
|
"tie-fighter: '|\\-*-/|'";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 6);
|
YAML_ASSERT(doc.size() == 6);
|
||||||
YAML_ASSERT(doc["unicode"] == "Sosa did fine.\u263A");
|
YAML_ASSERT(doc["unicode"] == "Sosa did fine.\xe2\x98\xba");
|
||||||
YAML_ASSERT(doc["control"] == "\b1998\t1999\t2000\n");
|
YAML_ASSERT(doc["control"] == "\b1998\t1999\t2000\n");
|
||||||
YAML_ASSERT(doc["hex esc"] == "\x0d\x0a is \r\n");
|
YAML_ASSERT(doc["hex esc"] == "\x0d\x0a is \r\n");
|
||||||
YAML_ASSERT(doc["single"] == "\"Howdy!\" he cried.");
|
YAML_ASSERT(doc["single"] == "\"Howdy!\" he cried.");
|
||||||
@@ -496,11 +451,8 @@ namespace Test {
|
|||||||
"\n"
|
"\n"
|
||||||
"quoted: \"So does this\n"
|
"quoted: \"So does this\n"
|
||||||
" quoted scalar.\\n\"";
|
" quoted scalar.\\n\"";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc["plain"] == "This unquoted scalar spans many lines.");
|
YAML_ASSERT(doc["plain"] == "This unquoted scalar spans many lines.");
|
||||||
YAML_ASSERT(doc["quoted"] == "So does this quoted scalar.\n");
|
YAML_ASSERT(doc["quoted"] == "So does this quoted scalar.\n");
|
||||||
@@ -542,11 +494,8 @@ namespace Test {
|
|||||||
" Late afternoon is best.\n"
|
" Late afternoon is best.\n"
|
||||||
" Backup contact is Nancy\n"
|
" Backup contact is Nancy\n"
|
||||||
" Billsmer @ 338-4338.";
|
" Billsmer @ 338-4338.";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 8);
|
YAML_ASSERT(doc.size() == 8);
|
||||||
YAML_ASSERT(doc["invoice"] == 34843);
|
YAML_ASSERT(doc["invoice"] == 34843);
|
||||||
YAML_ASSERT(doc["date"] == "2001-01-23");
|
YAML_ASSERT(doc["date"] == "2001-01-23");
|
||||||
@@ -613,23 +562,20 @@ namespace Test {
|
|||||||
" line: 58\n"
|
" line: 58\n"
|
||||||
" code: |-\n"
|
" code: |-\n"
|
||||||
" foo = bar";
|
" foo = bar";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 3);
|
YAML_ASSERT(doc.size() == 3);
|
||||||
YAML_ASSERT(doc["Time"] == "2001-11-23 15:01:42 -5");
|
YAML_ASSERT(doc["Time"] == "2001-11-23 15:01:42 -5");
|
||||||
YAML_ASSERT(doc["User"] == "ed");
|
YAML_ASSERT(doc["User"] == "ed");
|
||||||
YAML_ASSERT(doc["Warning"] == "This is an error message for the log file");
|
YAML_ASSERT(doc["Warning"] == "This is an error message for the log file");
|
||||||
|
|
||||||
parser.GetNextDocument(doc);
|
PARSE_NEXT(doc);
|
||||||
YAML_ASSERT(doc.size() == 3);
|
YAML_ASSERT(doc.size() == 3);
|
||||||
YAML_ASSERT(doc["Time"] == "2001-11-23 15:02:31 -5");
|
YAML_ASSERT(doc["Time"] == "2001-11-23 15:02:31 -5");
|
||||||
YAML_ASSERT(doc["User"] == "ed");
|
YAML_ASSERT(doc["User"] == "ed");
|
||||||
YAML_ASSERT(doc["Warning"] == "A slightly different error message.");
|
YAML_ASSERT(doc["Warning"] == "A slightly different error message.");
|
||||||
|
|
||||||
parser.GetNextDocument(doc);
|
PARSE_NEXT(doc);
|
||||||
YAML_ASSERT(doc.size() == 4);
|
YAML_ASSERT(doc.size() == 4);
|
||||||
YAML_ASSERT(doc["Date"] == "2001-11-23 15:03:17 -5");
|
YAML_ASSERT(doc["Date"] == "2001-11-23 15:03:17 -5");
|
||||||
YAML_ASSERT(doc["User"] == "ed");
|
YAML_ASSERT(doc["User"] == "ed");
|
||||||
@@ -659,11 +605,8 @@ namespace Test {
|
|||||||
" ? sky\n"
|
" ? sky\n"
|
||||||
" : blue\n"
|
" : blue\n"
|
||||||
" sea : green";
|
" sea : green";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc["sequence"].size() == 2);
|
YAML_ASSERT(doc["sequence"].size() == 2);
|
||||||
YAML_ASSERT(doc["sequence"][0] == "one");
|
YAML_ASSERT(doc["sequence"][0] == "one");
|
||||||
@@ -680,11 +623,8 @@ namespace Test {
|
|||||||
std::string input =
|
std::string input =
|
||||||
"sequence: [ one, two, ]\n"
|
"sequence: [ one, two, ]\n"
|
||||||
"mapping: { sky: blue, sea: green }";
|
"mapping: { sky: blue, sea: green }";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc["sequence"].size() == 2);
|
YAML_ASSERT(doc["sequence"].size() == 2);
|
||||||
YAML_ASSERT(doc["sequence"][0] == "one");
|
YAML_ASSERT(doc["sequence"][0] == "one");
|
||||||
@@ -703,11 +643,8 @@ namespace Test {
|
|||||||
std::string input =
|
std::string input =
|
||||||
"anchored: !local &anchor value\n"
|
"anchored: !local &anchor value\n"
|
||||||
"alias: *anchor";
|
"alias: *anchor";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc["anchored"] == "value"); // TODO: assert tag
|
YAML_ASSERT(doc["anchored"] == "value"); // TODO: assert tag
|
||||||
YAML_ASSERT(doc["alias"] == "value");
|
YAML_ASSERT(doc["alias"] == "value");
|
||||||
@@ -724,11 +661,8 @@ namespace Test {
|
|||||||
"folded: >\n"
|
"folded: >\n"
|
||||||
" some\n"
|
" some\n"
|
||||||
" text\n";
|
" text\n";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc["literal"] == "some\ntext\n");
|
YAML_ASSERT(doc["literal"] == "some\ntext\n");
|
||||||
YAML_ASSERT(doc["folded"] == "some text\n");
|
YAML_ASSERT(doc["folded"] == "some text\n");
|
||||||
@@ -741,11 +675,8 @@ namespace Test {
|
|||||||
std::string input =
|
std::string input =
|
||||||
"single: 'text'\n"
|
"single: 'text'\n"
|
||||||
"double: \"text\"";
|
"double: \"text\"";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc["single"] == "text");
|
YAML_ASSERT(doc["single"] == "text");
|
||||||
YAML_ASSERT(doc["double"] == "text");
|
YAML_ASSERT(doc["double"] == "text");
|
||||||
@@ -762,11 +693,8 @@ namespace Test {
|
|||||||
"|\n"
|
"|\n"
|
||||||
" Line break (no glyph)\n"
|
" Line break (no glyph)\n"
|
||||||
" Line break (glyphed)\n";
|
" Line break (glyphed)\n";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc == "Line break (no glyph)\nLine break (glyphed)\n");
|
YAML_ASSERT(doc == "Line break (no glyph)\nLine break (glyphed)\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -781,11 +709,8 @@ namespace Test {
|
|||||||
" void main() {\n"
|
" void main() {\n"
|
||||||
" \tprintf(\"Hello, world!\\n\");\n"
|
" \tprintf(\"Hello, world!\\n\");\n"
|
||||||
" }";
|
" }";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc["quoted"] == "Quoted\t");
|
YAML_ASSERT(doc["quoted"] == "Quoted\t");
|
||||||
YAML_ASSERT(doc["block"] ==
|
YAML_ASSERT(doc["block"] ==
|
||||||
@@ -804,12 +729,9 @@ namespace Test {
|
|||||||
"\\n \\r \\t \\v \\0 \\\n"
|
"\\n \\r \\t \\v \\0 \\\n"
|
||||||
"\\ \\_ \\N \\L \\P \\\n"
|
"\\ \\_ \\N \\L \\P \\\n"
|
||||||
"\\x41 \\u0041 \\U00000041\"";
|
"\\x41 \\u0041 \\U00000041\"";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
YAML_ASSERT(doc == "Fun with \x5C \x22 \x07 \x08 \x1B \x0C \x0A \x0D \x09 \x0B " + std::string("\x00", 1) + " \x20 \xA0 \x85 \u2028 \u2029 A A A");
|
PARSE(doc, input);
|
||||||
|
YAML_ASSERT(doc == "Fun with \x5C \x22 \x07 \x08 \x1B \x0C \x0A \x0D \x09 \x0B " + std::string("\x00", 1) + " \x20 \xA0 \x85 \xe2\x80\xa8 \xe2\x80\xa9 A A A");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -850,11 +772,8 @@ namespace Test {
|
|||||||
" Also by two, # are neither\n"
|
" Also by two, # are neither\n"
|
||||||
" \tStill by two # content nor\n"
|
" \tStill by two # content nor\n"
|
||||||
" ] # indentation.";
|
" ] # indentation.";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 1);
|
YAML_ASSERT(doc.size() == 1);
|
||||||
YAML_ASSERT(doc["Not indented"].size() == 2);
|
YAML_ASSERT(doc["Not indented"].size() == 2);
|
||||||
YAML_ASSERT(doc["Not indented"]["By one space"] == "By four\n spaces\n");
|
YAML_ASSERT(doc["Not indented"]["By one space"] == "By four\n spaces\n");
|
||||||
@@ -873,11 +792,8 @@ namespace Test {
|
|||||||
": -\tb\n"
|
": -\tb\n"
|
||||||
" - -\tc\n"
|
" - -\tc\n"
|
||||||
" - d";
|
" - d";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 1);
|
YAML_ASSERT(doc.size() == 1);
|
||||||
YAML_ASSERT(doc["a"].size() == 2);
|
YAML_ASSERT(doc["a"].size() == 2);
|
||||||
YAML_ASSERT(doc["a"][0] == "b");
|
YAML_ASSERT(doc["a"][0] == "b");
|
||||||
@@ -894,11 +810,8 @@ namespace Test {
|
|||||||
"- foo:\t bar\n"
|
"- foo:\t bar\n"
|
||||||
"- - baz\n"
|
"- - baz\n"
|
||||||
" -\tbaz";
|
" -\tbaz";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc[0].size() == 1);
|
YAML_ASSERT(doc[0].size() == 1);
|
||||||
YAML_ASSERT(doc[0]["foo"] == "bar");
|
YAML_ASSERT(doc[0]["foo"] == "bar");
|
||||||
@@ -919,11 +832,8 @@ namespace Test {
|
|||||||
"block: |\n"
|
"block: |\n"
|
||||||
" text\n"
|
" text\n"
|
||||||
" \tlines\n";
|
" \tlines\n";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 3);
|
YAML_ASSERT(doc.size() == 3);
|
||||||
YAML_ASSERT(doc["plain"] == "text lines");
|
YAML_ASSERT(doc["plain"] == "text lines");
|
||||||
YAML_ASSERT(doc["quoted"] == "text lines");
|
YAML_ASSERT(doc["quoted"] == "text lines");
|
||||||
@@ -942,11 +852,8 @@ namespace Test {
|
|||||||
"Chomping: |\n"
|
"Chomping: |\n"
|
||||||
" Clipped empty lines\n"
|
" Clipped empty lines\n"
|
||||||
" ";
|
" ";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc["Folding"] == "Empty line\nas a line feed");
|
YAML_ASSERT(doc["Folding"] == "Empty line\nas a line feed");
|
||||||
YAML_ASSERT(doc["Chomping"] == "Clipped empty lines\n");
|
YAML_ASSERT(doc["Chomping"] == "Clipped empty lines\n");
|
||||||
@@ -964,11 +871,8 @@ namespace Test {
|
|||||||
"\n"
|
"\n"
|
||||||
" as\n"
|
" as\n"
|
||||||
" space";
|
" space";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc == "trimmed\n\n\nas space");
|
YAML_ASSERT(doc == "trimmed\n\n\nas space");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -983,11 +887,8 @@ namespace Test {
|
|||||||
" \t bar\n"
|
" \t bar\n"
|
||||||
"\n"
|
"\n"
|
||||||
" baz\n";
|
" baz\n";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc == "foo \n\n\t bar\n\nbaz\n");
|
YAML_ASSERT(doc == "foo \n\n\t bar\n\nbaz\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1003,11 +904,8 @@ namespace Test {
|
|||||||
"\n"
|
"\n"
|
||||||
" baz\n"
|
" baz\n"
|
||||||
"\"";
|
"\"";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc == " foo\nbar\nbaz ");
|
YAML_ASSERT(doc == " foo\nbar\nbaz ");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1018,11 +916,8 @@ namespace Test {
|
|||||||
std::string input =
|
std::string input =
|
||||||
"key: # Comment\n"
|
"key: # Comment\n"
|
||||||
" value";
|
" value";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 1);
|
YAML_ASSERT(doc.size() == 1);
|
||||||
YAML_ASSERT(doc["key"] == "value");
|
YAML_ASSERT(doc["key"] == "value");
|
||||||
return true;
|
return true;
|
||||||
@@ -1050,11 +945,8 @@ namespace Test {
|
|||||||
" # lines\n"
|
" # lines\n"
|
||||||
" value\n"
|
" value\n"
|
||||||
"\n";
|
"\n";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 1);
|
YAML_ASSERT(doc.size() == 1);
|
||||||
YAML_ASSERT(doc["key"] == "value");
|
YAML_ASSERT(doc["key"] == "value");
|
||||||
return true;
|
return true;
|
||||||
@@ -1089,11 +981,8 @@ namespace Test {
|
|||||||
" 65\n"
|
" 65\n"
|
||||||
" avg: # Average\n"
|
" avg: # Average\n"
|
||||||
" 0.278";
|
" 0.278";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
StringMap key;
|
StringMap key;
|
||||||
key._["first"] = "Sammy";
|
key._["first"] = "Sammy";
|
||||||
key._["last"] = "Sosa";
|
key._["last"] = "Sosa";
|
||||||
@@ -1113,11 +1002,8 @@ namespace Test {
|
|||||||
std::string input =
|
std::string input =
|
||||||
"First occurrence: &anchor Value\n"
|
"First occurrence: &anchor Value\n"
|
||||||
"Second occurrence: *anchor";
|
"Second occurrence: *anchor";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc["First occurrence"] == "Value");
|
YAML_ASSERT(doc["First occurrence"] == "Value");
|
||||||
YAML_ASSERT(doc["Second occurrence"] == "Value");
|
YAML_ASSERT(doc["Second occurrence"] == "Value");
|
||||||
@@ -1132,11 +1018,8 @@ namespace Test {
|
|||||||
"Second occurrence: *anchor\n"
|
"Second occurrence: *anchor\n"
|
||||||
"Override anchor: &anchor Bar\n"
|
"Override anchor: &anchor Bar\n"
|
||||||
"Reuse anchor: *anchor";
|
"Reuse anchor: *anchor";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 4);
|
YAML_ASSERT(doc.size() == 4);
|
||||||
YAML_ASSERT(doc["First occurrence"] == "Foo");
|
YAML_ASSERT(doc["First occurrence"] == "Foo");
|
||||||
YAML_ASSERT(doc["Second occurrence"] == "Foo");
|
YAML_ASSERT(doc["Second occurrence"] == "Foo");
|
||||||
@@ -1153,11 +1036,8 @@ namespace Test {
|
|||||||
" foo : !!str,\n"
|
" foo : !!str,\n"
|
||||||
" !!str : bar,\n"
|
" !!str : bar,\n"
|
||||||
"}";
|
"}";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(doc["foo"] == ""); // TODO: check tag
|
YAML_ASSERT(doc["foo"] == ""); // TODO: check tag
|
||||||
YAML_ASSERT(doc[""] == "bar");
|
YAML_ASSERT(doc[""] == "bar");
|
||||||
@@ -1172,11 +1052,8 @@ namespace Test {
|
|||||||
" ? foo :,\n"
|
" ? foo :,\n"
|
||||||
" : bar,\n"
|
" : bar,\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 2);
|
YAML_ASSERT(doc.size() == 2);
|
||||||
YAML_ASSERT(IsNull(doc["foo"]));
|
YAML_ASSERT(IsNull(doc["foo"]));
|
||||||
YAML_ASSERT(doc[YAML::Null] == "bar");
|
YAML_ASSERT(doc[YAML::Null] == "bar");
|
||||||
@@ -1190,17 +1067,146 @@ namespace Test {
|
|||||||
"\"implicit block key\" : [\n"
|
"\"implicit block key\" : [\n"
|
||||||
" \"implicit flow key\" : value,\n"
|
" \"implicit flow key\" : value,\n"
|
||||||
" ]";
|
" ]";
|
||||||
std::stringstream stream(input);
|
|
||||||
YAML::Parser parser(stream);
|
|
||||||
YAML::Node doc;
|
|
||||||
parser.GetNextDocument(doc);
|
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
YAML_ASSERT(doc.size() == 1);
|
YAML_ASSERT(doc.size() == 1);
|
||||||
YAML_ASSERT(doc["implicit block key"].size() == 1);
|
YAML_ASSERT(doc["implicit block key"].size() == 1);
|
||||||
YAML_ASSERT(doc["implicit block key"][0].size() == 1);
|
YAML_ASSERT(doc["implicit block key"][0].size() == 1);
|
||||||
YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"] == "value");
|
YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"] == "value");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 7.5
|
||||||
|
TEST DoubleQuotedLineBreaks()
|
||||||
|
{
|
||||||
|
std::string input =
|
||||||
|
"\"folded \n"
|
||||||
|
"to a space,\t\n"
|
||||||
|
" \n"
|
||||||
|
"to a line feed, or \t\\\n"
|
||||||
|
" \\ \tnon-content\"";
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
|
YAML_ASSERT(doc == "folded to a space,\nto a line feed, or \t \tnon-content");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7.6
|
||||||
|
TEST DoubleQuotedLines()
|
||||||
|
{
|
||||||
|
std::string input =
|
||||||
|
"\" 1st non-empty\n"
|
||||||
|
"\n"
|
||||||
|
" 2nd non-empty \n"
|
||||||
|
"\t3rd non-empty \"";
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
|
YAML_ASSERT(doc == " 1st non-empty\n2nd non-empty 3rd non-empty ");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7.7
|
||||||
|
TEST SingleQuotedCharacters()
|
||||||
|
{
|
||||||
|
std::string input = " 'here''s to \"quotes\"'";
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
|
YAML_ASSERT(doc == "here's to \"quotes\"");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7.8
|
||||||
|
TEST SingleQuotedImplicitKeys()
|
||||||
|
{
|
||||||
|
std::string input =
|
||||||
|
"'implicit block key' : [\n"
|
||||||
|
" 'implicit flow key' : value,\n"
|
||||||
|
" ]";
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
|
YAML_ASSERT(doc.size() == 1);
|
||||||
|
YAML_ASSERT(doc["implicit block key"].size() == 1);
|
||||||
|
YAML_ASSERT(doc["implicit block key"][0].size() == 1);
|
||||||
|
YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"] == "value");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7.9
|
||||||
|
TEST SingleQuotedLines()
|
||||||
|
{
|
||||||
|
std::string input =
|
||||||
|
"' 1st non-empty\n"
|
||||||
|
"\n"
|
||||||
|
" 2nd non-empty \n"
|
||||||
|
"\t3rd non-empty '";
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
|
YAML_ASSERT(doc == " 1st non-empty\n2nd non-empty 3rd non-empty ");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7.10
|
||||||
|
TEST PlainCharacters()
|
||||||
|
{
|
||||||
|
std::string input =
|
||||||
|
"# Outside flow collection:\n"
|
||||||
|
"- ::vector\n"
|
||||||
|
"- \": - ()\"\n"
|
||||||
|
"- Up, up, and away!\n"
|
||||||
|
"- -123\n"
|
||||||
|
"- http://example.com/foo#bar\n"
|
||||||
|
"# Inside flow collection:\n"
|
||||||
|
"- [ ::vector,\n"
|
||||||
|
" \": - ()\",\n"
|
||||||
|
" \"Up, up, and away!\",\n"
|
||||||
|
" -123,\n"
|
||||||
|
" http://example.com/foo#bar ]";
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
|
YAML_ASSERT(doc.size() == 6);
|
||||||
|
YAML_ASSERT(doc[0] == "::vector");
|
||||||
|
YAML_ASSERT(doc[1] == ": - ()");
|
||||||
|
YAML_ASSERT(doc[2] == "Up, up, and away!");
|
||||||
|
YAML_ASSERT(doc[3] == -123);
|
||||||
|
YAML_ASSERT(doc[4] == "http://example.com/foo#bar");
|
||||||
|
YAML_ASSERT(doc[5].size() == 5);
|
||||||
|
YAML_ASSERT(doc[5][0] == "::vector");
|
||||||
|
YAML_ASSERT(doc[5][1] == ": - ()");
|
||||||
|
YAML_ASSERT(doc[5][2] == "Up, up, and away!");
|
||||||
|
YAML_ASSERT(doc[5][3] == -123);
|
||||||
|
YAML_ASSERT(doc[5][4] == "http://example.com/foo#bar");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7.11
|
||||||
|
TEST PlainImplicitKeys()
|
||||||
|
{
|
||||||
|
std::string input =
|
||||||
|
"implicit block key : [\n"
|
||||||
|
" implicit flow key : value,\n"
|
||||||
|
" ]";
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
|
YAML_ASSERT(doc.size() == 1);
|
||||||
|
YAML_ASSERT(doc["implicit block key"].size() == 1);
|
||||||
|
YAML_ASSERT(doc["implicit block key"][0].size() == 1);
|
||||||
|
YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"] == "value");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7.12
|
||||||
|
TEST PlainLines()
|
||||||
|
{
|
||||||
|
std::string input =
|
||||||
|
"1st non-empty\n"
|
||||||
|
"\n"
|
||||||
|
" 2nd non-empty \n"
|
||||||
|
"\t3rd non-empty";
|
||||||
|
|
||||||
|
PARSE(doc, input);
|
||||||
|
YAML_ASSERT(doc == "1st non-empty\n2nd non-empty 3rd non-empty");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RunSpecTests()
|
bool RunSpecTests()
|
||||||
@@ -1257,6 +1263,14 @@ namespace Test {
|
|||||||
RunSpecTest(&Spec::EmptyNodes, "7.2", "Empty Nodes", passed, total);
|
RunSpecTest(&Spec::EmptyNodes, "7.2", "Empty Nodes", passed, total);
|
||||||
RunSpecTest(&Spec::CompletelyEmptyNodes, "7.3", "Completely Empty Nodes", passed, total);
|
RunSpecTest(&Spec::CompletelyEmptyNodes, "7.3", "Completely Empty Nodes", passed, total);
|
||||||
RunSpecTest(&Spec::DoubleQuotedImplicitKeys, "7.4", "Double Quoted Implicit Keys", 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);
|
||||||
|
|
||||||
std::cout << "Spec tests: " << passed << "/" << total << " passed\n";
|
std::cout << "Spec tests: " << passed << "/" << total << " passed\n";
|
||||||
return passed == total;
|
return passed == total;
|
||||||
|
Reference in New Issue
Block a user