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

Run clang-format

parent 3355bbb3
#ifndef YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define YAML_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
......
......@@ -2,53 +2,48 @@
#include "yaml-cpp/node/impl.h"
#include <algorithm>
namespace
{
// we're not gonna mess with the mess that is all the isupper/etc. functions
bool IsLower(char ch) { return 'a' <= ch && ch <= 'z'; }
bool IsUpper(char ch) { return 'A' <= ch && ch <= 'Z'; }
char ToLower(char ch) { return IsUpper(ch) ? ch + 'a' - 'A' : ch; }
namespace {
// we're not gonna mess with the mess that is all the isupper/etc. functions
bool IsLower(char ch) { return 'a' <= ch && ch <= 'z'; }
bool IsUpper(char ch) { return 'A' <= ch && ch <= 'Z'; }
char ToLower(char ch) { return IsUpper(ch) ? ch + 'a' - 'A' : ch; }
std::string tolower(const std::string& str)
{
std::string tolower(const std::string& str) {
std::string s(str);
std::transform(s.begin(), s.end(), s.begin(), ToLower);
return s;
}
}
template <typename T>
bool IsEntirely(const std::string& str, T func)
{
for(std::size_t i=0;i<str.size();i++)
if(!func(str[i]))
template <typename T>
bool IsEntirely(const std::string& str, T func) {
for (std::size_t i = 0; i < str.size(); i++)
if (!func(str[i]))
return false;
return true;
}
}
// IsFlexibleCase
// . Returns true if 'str' is:
// . UPPERCASE
// . lowercase
// . Capitalized
bool IsFlexibleCase(const std::string& str)
{
if(str.empty())
// IsFlexibleCase
// . Returns true if 'str' is:
// . UPPERCASE
// . lowercase
// . Capitalized
bool IsFlexibleCase(const std::string& str) {
if (str.empty())
return true;
if(IsEntirely(str, IsLower))
if (IsEntirely(str, IsLower))
return true;
bool firstcaps = IsUpper(str[0]);
std::string rest = str.substr(1);
return firstcaps && (IsEntirely(rest, IsLower) || IsEntirely(rest, IsUpper));
}
}
}
namespace YAML
{
bool convert<bool>::decode(const Node& node, bool& rhs) {
if(!node.IsScalar())
namespace YAML {
bool convert<bool>::decode(const Node& node, bool& rhs) {
if (!node.IsScalar())
return false;
// we can't use iostream bool extraction operators as they don't
......@@ -56,28 +51,23 @@ namespace YAML
// http://yaml.org/type/bool.html)
static const struct {
std::string truename, falsename;
} names[] = {
{ "y", "n" },
{ "yes", "no" },
{ "true", "false" },
{ "on", "off" },
};
} names[] = {{"y", "n"}, {"yes", "no"}, {"true", "false"}, {"on", "off"}, };
if(!IsFlexibleCase(node.Scalar()))
if (!IsFlexibleCase(node.Scalar()))
return false;
for(unsigned i=0;i<sizeof(names)/sizeof(names[0]);i++) {
if(names[i].truename == tolower(node.Scalar())) {
for (unsigned i = 0; i < sizeof(names) / sizeof(names[0]); i++) {
if (names[i].truename == tolower(node.Scalar())) {
rhs = true;
return true;
}
if(names[i].falsename == tolower(node.Scalar())) {
if (names[i].falsename == tolower(node.Scalar())) {
rhs = false;
return true;
}
}
return false;
}
}
}
......@@ -3,27 +3,23 @@
#include "yaml-cpp/emitter.h"
#include "nodeevents.h"
namespace YAML
{
Emitter& operator << (Emitter& out, const Node& node)
{
namespace YAML {
Emitter& operator<<(Emitter& out, const Node& node) {
EmitFromEvents emitFromEvents(out);
NodeEvents events(node);
events.Emit(emitFromEvents);
return out;
}
}
std::ostream& operator << (std::ostream& out, const Node& node)
{
std::ostream& operator<<(std::ostream& out, const Node& node) {
Emitter emitter(out);
emitter << node;
return out;
}
}
std::string Dump(const Node& node)
{
std::string Dump(const Node& node) {
Emitter emitter;
emitter << node;
return emitter.c_str();
}
}
}
#include "yaml-cpp/node/detail/memory.h"
#include "yaml-cpp/node/detail/node.h"
namespace YAML
{
namespace detail
{
void memory_holder::merge(memory_holder& rhs)
{
if(m_pMemory == rhs.m_pMemory)
namespace YAML {
namespace detail {
void memory_holder::merge(memory_holder& rhs) {
if (m_pMemory == rhs.m_pMemory)
return;
m_pMemory->merge(*rhs.m_pMemory);
rhs.m_pMemory = m_pMemory;
}
}
node& memory::create_node()
{
node& memory::create_node() {
shared_node pNode(new node);
m_nodes.insert(pNode);
return *pNode;
}
}
void memory::merge(const memory& rhs)
{
void memory::merge(const memory& rhs) {
m_nodes.insert(rhs.m_nodes.begin(), rhs.m_nodes.end());
}
}
}
}
}
......@@ -2,13 +2,11 @@
#include "nodebuilder.h"
#include "nodeevents.h"
namespace YAML
{
Node Clone(const Node& node)
{
namespace YAML {
Node Clone(const Node& node) {
NodeEvents events(node);
NodeBuilder builder;
events.Emit(builder);
return builder.Root();
}
}
}
......@@ -4,39 +4,33 @@
#include "yaml-cpp/exceptions.h"
#include <sstream>
namespace YAML
{
namespace detail
{
std::string node_data::empty_scalar;
node_data::node_data(): m_isDefined(false), m_type(NodeType::Null), m_seqSize(0)
{
}
namespace YAML {
namespace detail {
std::string node_data::empty_scalar;
node_data::node_data()
: m_isDefined(false), m_type(NodeType::Null), m_seqSize(0) {}
void node_data::mark_defined()
{
if(m_type == NodeType::Undefined)
void node_data::mark_defined() {
if (m_type == NodeType::Undefined)
m_type = NodeType::Null;
m_isDefined = true;
}
}
void node_data::set_type(NodeType::value type)
{
if(type == NodeType::Undefined) {
void node_data::set_type(NodeType::value type) {
if (type == NodeType::Undefined) {
m_type = type;
m_isDefined = false;
return;
}
m_isDefined = true;
if(type == m_type)
if (type == m_type)
return;
m_type = type;
switch(m_type) {
switch (m_type) {
case NodeType::Null:
break;
case NodeType::Scalar:
......@@ -52,123 +46,125 @@ namespace YAML
assert(false);
break;
}
}
}
void node_data::set_tag(const std::string& tag)
{
m_tag = tag;
}
void node_data::set_tag(const std::string& tag) { m_tag = tag; }
void node_data::set_null()
{
void node_data::set_null() {
m_isDefined = true;
m_type = NodeType::Null;
}
}
void node_data::set_scalar(const std::string& scalar)
{
void node_data::set_scalar(const std::string& scalar) {
m_isDefined = true;
m_type = NodeType::Scalar;
m_scalar = scalar;
}
}
// size/iterator
std::size_t node_data::size() const
{
if(!m_isDefined)
// size/iterator
std::size_t node_data::size() const {
if (!m_isDefined)
return 0;
switch(m_type) {
case NodeType::Sequence: compute_seq_size(); return m_seqSize;
case NodeType::Map: compute_map_size(); return m_map.size() - m_undefinedPairs.size();
switch (m_type) {
case NodeType::Sequence:
compute_seq_size();
return m_seqSize;
case NodeType::Map:
compute_map_size();
return m_map.size() - m_undefinedPairs.size();
default:
return 0;
}
return 0;
}
}
void node_data::compute_seq_size() const
{
while(m_seqSize < m_sequence.size() && m_sequence[m_seqSize]->is_defined())
void node_data::compute_seq_size() const {
while (m_seqSize < m_sequence.size() && m_sequence[m_seqSize]->is_defined())
m_seqSize++;
}
}
void node_data::compute_map_size() const
{
void node_data::compute_map_size() const {
kv_pairs::iterator it = m_undefinedPairs.begin();
while(it != m_undefinedPairs.end()) {
while (it != m_undefinedPairs.end()) {
kv_pairs::iterator jt = boost::next(it);
if(it->first->is_defined() && it->second->is_defined())
if (it->first->is_defined() && it->second->is_defined())
m_undefinedPairs.erase(it);
it = jt;
}
}
}
const_node_iterator node_data::begin() const
{
if(!m_isDefined)
const_node_iterator node_data::begin() const {
if (!m_isDefined)
return const_node_iterator();
switch(m_type) {
case NodeType::Sequence: return const_node_iterator(m_sequence.begin());
case NodeType::Map: return const_node_iterator(m_map.begin(), m_map.end());
default: return const_node_iterator();
}
switch (m_type) {
case NodeType::Sequence:
return const_node_iterator(m_sequence.begin());
case NodeType::Map:
return const_node_iterator(m_map.begin(), m_map.end());
default:
return const_node_iterator();
}
}
node_iterator node_data::begin()
{
if(!m_isDefined)
node_iterator node_data::begin() {
if (!m_isDefined)
return node_iterator();
switch(m_type) {
case NodeType::Sequence: return node_iterator(m_sequence.begin());
case NodeType::Map: return node_iterator(m_map.begin(), m_map.end());
default: return node_iterator();
}
switch (m_type) {
case NodeType::Sequence:
return node_iterator(m_sequence.begin());
case NodeType::Map:
return node_iterator(m_map.begin(), m_map.end());
default:
return node_iterator();
}
}
const_node_iterator node_data::end() const
{
if(!m_isDefined)
const_node_iterator node_data::end() const {
if (!m_isDefined)
return const_node_iterator();
switch(m_type) {
case NodeType::Sequence: return const_node_iterator(m_sequence.end());
case NodeType::Map: return const_node_iterator(m_map.end(), m_map.end());
default: return const_node_iterator();
}
switch (m_type) {
case NodeType::Sequence:
return const_node_iterator(m_sequence.end());
case NodeType::Map:
return const_node_iterator(m_map.end(), m_map.end());
default:
return const_node_iterator();
}
}
node_iterator node_data::end()
{
if(!m_isDefined)
node_iterator node_data::end() {
if (!m_isDefined)
return node_iterator();
switch(m_type) {
case NodeType::Sequence: return node_iterator(m_sequence.end());
case NodeType::Map: return node_iterator(m_map.end(), m_map.end());
default: return node_iterator();
}
switch (m_type) {
case NodeType::Sequence:
return node_iterator(m_sequence.end());
case NodeType::Map:
return node_iterator(m_map.end(), m_map.end());
default:
return node_iterator();
}
}
// sequence
void node_data::push_back(node& node, shared_memory_holder /* pMemory */)
{
if(m_type == NodeType::Undefined || m_type == NodeType::Null) {
// sequence
void node_data::push_back(node& node, shared_memory_holder /* pMemory */) {
if (m_type == NodeType::Undefined || m_type == NodeType::Null) {
m_type = NodeType::Sequence;
reset_sequence();
}
if(m_type != NodeType::Sequence)
if (m_type != NodeType::Sequence)
throw BadPushback();
m_sequence.push_back(&node);
}
}
void node_data::insert(node& key, node& value, shared_memory_holder pMemory)
{
switch(m_type) {
void node_data::insert(node& key, node& value, shared_memory_holder pMemory) {
switch (m_type) {
case NodeType::Map:
break;
case NodeType::Undefined:
......@@ -181,25 +177,23 @@ namespace YAML
}
insert_map_pair(key, value);
}
}
// indexing
node& node_data::get(node& key, shared_memory_holder pMemory) const
{
if(m_type != NodeType::Map)
// indexing
node& node_data::get(node& key, shared_memory_holder pMemory) const {
if (m_type != NodeType::Map)
return pMemory->create_node();
for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) {
if(it->first->is(key))
for (node_map::const_iterator it = m_map.begin(); it != m_map.end(); ++it) {
if (it->first->is(key))
return *it->second;
}
return pMemory->create_node();
}
}
node& node_data::get(node& key, shared_memory_holder pMemory)
{
switch(m_type) {
node& node_data::get(node& key, shared_memory_holder pMemory) {
switch (m_type) {
case NodeType::Map:
break;
case NodeType::Undefined:
......@@ -211,53 +205,48 @@ namespace YAML
throw BadSubscript();
}
for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) {
if(it->first->is(key))
for (node_map::const_iterator it = m_map.begin(); it != m_map.end(); ++it) {
if (it->first->is(key))
return *it->second;
}
node& value = pMemory->create_node();
insert_map_pair(key, value);
return value;
}
}
bool node_data::remove(node& key, shared_memory_holder /* pMemory */)
{
if(m_type != NodeType::Map)
bool node_data::remove(node& key, shared_memory_holder /* pMemory */) {
if (m_type != NodeType::Map)
return false;
for(node_map::iterator it=m_map.begin();it!=m_map.end();++it) {
if(it->first->is(key)) {
for (node_map::iterator it = m_map.begin(); it != m_map.end(); ++it) {
if (it->first->is(key)) {
m_map.erase(it);
return true;
}
}
return false;
}
}
void node_data::reset_sequence()
{
void node_data::reset_sequence() {
m_sequence.clear();
m_seqSize = 0;
}
}
void node_data::reset_map()
{
void node_data::reset_map() {
m_map.clear();
m_undefinedPairs.clear();
}
}
void node_data::insert_map_pair(node& key, node& value)
{
void node_data::insert_map_pair(node& key, node& value) {
m_map[&key] = &value;
if(!key.is_defined() || !value.is_defined())
if (!key.is_defined() || !value.is_defined())
m_undefinedPairs.push_back(kv_pair(&key, &value));
}
}
void node_data::convert_to_map(shared_memory_holder pMemory)
{
switch(m_type) {
void node_data::convert_to_map(shared_memory_holder pMemory) {
switch (m_type) {
case NodeType::Undefined:
case NodeType::Null:
reset_map();
......@@ -272,14 +261,13 @@ namespace YAML
assert(false);
break;
}
}
}
void node_data::convert_sequence_to_map(shared_memory_holder pMemory)
{
void node_data::convert_sequence_to_map(shared_memory_holder pMemory) {
assert(m_type == NodeType::Sequence);
reset_map();
for(std::size_t i=0;i<m_sequence.size();i++) {
for (std::size_t i = 0; i < m_sequence.size(); i++) {
std::stringstream stream;
stream << i;
......@@ -290,6 +278,6 @@ namespace YAML
reset_sequence();
m_type = NodeType::Map;
}
}
}
}
}
......@@ -4,103 +4,88 @@
#include "yaml-cpp/node/impl.h"
#include <cassert>
namespace YAML
{
NodeBuilder::NodeBuilder(): m_pMemory(new detail::memory_holder), m_pRoot(0), m_mapDepth(0)
{
namespace YAML {
NodeBuilder::NodeBuilder()
: m_pMemory(new detail::memory_holder), m_pRoot(0), m_mapDepth(0) {
m_anchors.push_back(0); // since the anchors start at 1
}
}
NodeBuilder::~NodeBuilder()
{
}
NodeBuilder::~NodeBuilder() {}
Node NodeBuilder::Root()
{
if(!m_pRoot)
Node NodeBuilder::Root() {
if (!m_pRoot)
return Node();
return Node(*m_pRoot, m_pMemory);
}
}
void NodeBuilder::OnDocumentStart(const Mark&)
{
}
void NodeBuilder::OnDocumentStart(const Mark&) {}
void NodeBuilder::OnDocumentEnd()
{
}
void NodeBuilder::OnDocumentEnd() {}
void NodeBuilder::OnNull(const Mark& /* mark */, anchor_t anchor)
{
void NodeBuilder::OnNull(const Mark& /* mark */, anchor_t anchor) {
detail::node& node = Push(anchor);
node.set_null();
Pop();
}
}
void NodeBuilder::OnAlias(const Mark& /* mark */, anchor_t anchor)
{
void NodeBuilder::OnAlias(const Mark& /* mark */, anchor_t anchor) {
detail::node& node = *m_anchors[anchor];
Push(node);
Pop();
}
}
void NodeBuilder::OnScalar(const Mark& /* mark */, const std::string& tag, anchor_t anchor, const std::string& value)
{
void NodeBuilder::OnScalar(const Mark& /* mark */, const std::string& tag,
anchor_t anchor, const std::string& value) {
detail::node& node = Push(anchor);
node.set_scalar(value);
node.set_tag(tag);
Pop();
}
}
void NodeBuilder::OnSequenceStart(const Mark& /* mark */, const std::string& tag, anchor_t anchor)
{
void NodeBuilder::OnSequenceStart(const Mark& /* mark */,
const std::string& tag, anchor_t anchor) {
detail::node& node = Push(anchor);
node.set_tag(tag);
node.set_type(NodeType::Sequence);
}
}
void NodeBuilder::OnSequenceEnd()
{
Pop();
}
void NodeBuilder::OnSequenceEnd() { Pop(); }
void NodeBuilder::OnMapStart(const Mark& /* mark */, const std::string& tag, anchor_t anchor)
{
void NodeBuilder::OnMapStart(const Mark& /* mark */, const std::string& tag,
anchor_t anchor) {
detail::node& node = Push(anchor);
node.set_type(NodeType::Map);
node.set_tag(tag);
m_mapDepth++;
}
}
void NodeBuilder::OnMapEnd()
{
void NodeBuilder::OnMapEnd() {
assert(m_mapDepth > 0);
m_mapDepth--;
Pop();
}
}
detail::node& NodeBuilder::Push(anchor_t anchor)
{
detail::node& NodeBuilder::Push(anchor_t anchor) {
detail::node& node = m_pMemory->create_node();
RegisterAnchor(anchor, node);
Push(node);
return node;
}
}
void NodeBuilder::Push(detail::node& node)
{
const bool needsKey = (!m_stack.empty() && m_stack.back()->type() == NodeType::Map && m_keys.size() < m_mapDepth);
void NodeBuilder::Push(detail::node& node) {
const bool needsKey =
(!m_stack.empty() && m_stack.back()->type() == NodeType::Map &&
m_keys.size() < m_mapDepth);
m_stack.push_back(&node);
if(needsKey)
if (needsKey)
m_keys.push_back(PushedKey(&node, false));
}
}
void NodeBuilder::Pop()
{
void NodeBuilder::Pop() {
assert(!m_stack.empty());
if(m_stack.size() == 1) {
if (m_stack.size() == 1) {
m_pRoot = m_stack[0];
m_stack.pop_back();
return;
......@@ -111,12 +96,12 @@ namespace YAML
detail::node& collection = *m_stack.back();
if(collection.type() == NodeType::Sequence) {
if (collection.type() == NodeType::Sequence) {
collection.push_back(node, m_pMemory);
} else if(collection.type() == NodeType::Map) {
} else if (collection.type() == NodeType::Map) {
assert(!m_keys.empty());
PushedKey& key = m_keys.back();
if(key.second) {
if (key.second) {
collection.insert(*key.first, node, m_pMemory);
m_keys.pop_back();
} else {
......@@ -126,13 +111,12 @@ namespace YAML
assert(false);
m_stack.clear();
}
}
}
void NodeBuilder::RegisterAnchor(anchor_t anchor, detail::node& node)
{
if(anchor) {
void NodeBuilder::RegisterAnchor(anchor_t anchor, detail::node& node) {
if (anchor) {
assert(anchor == m_anchors.size());
m_anchors.push_back(&node);
}
}
}
}
#ifndef NODE_NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODE_NODEBUILDER_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
......@@ -9,12 +11,10 @@
#include "yaml-cpp/node/ptr.h"
#include <vector>
namespace YAML
{
class Node;
namespace YAML {
class Node;
class NodeBuilder: public EventHandler
{
class NodeBuilder : public EventHandler {
public:
NodeBuilder();
virtual ~NodeBuilder();
......@@ -26,12 +26,15 @@ namespace YAML
virtual void OnNull(const Mark& mark, anchor_t anchor);
virtual void OnAlias(const Mark& mark, anchor_t anchor);
virtual void OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value);
virtual void OnScalar(const Mark& mark, const std::string& tag,
anchor_t anchor, const std::string& value);
virtual void OnSequenceStart(const Mark& mark, const std::string& tag, anchor_t anchor);
virtual void OnSequenceStart(const Mark& mark, const std::string& tag,
anchor_t anchor);
virtual void OnSequenceEnd();
virtual void OnMapStart(const Mark& mark, const std::string& tag, anchor_t anchor);
virtual void OnMapStart(const Mark& mark, const std::string& tag,
anchor_t anchor);
virtual void OnMapEnd();
private:
......@@ -42,17 +45,16 @@ namespace YAML
private:
detail::shared_memory_holder m_pMemory;
detail::node *m_pRoot;
detail::node* m_pRoot;
typedef std::vector<detail::node *> Nodes;
typedef std::vector<detail::node*> Nodes;
Nodes m_stack;
Nodes m_anchors;
typedef std::pair<detail::node *, bool> PushedKey;
typedef std::pair<detail::node*, bool> PushedKey;
std::vector<PushedKey> m_keys;
std::size_t m_mapDepth;
};
};
}
#endif // NODE_NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
......@@ -4,61 +4,58 @@
#include "yaml-cpp/eventhandler.h"
#include "yaml-cpp/mark.h"
namespace YAML
{
void NodeEvents::AliasManager::RegisterReference(const detail::node& node)
{
namespace YAML {
void NodeEvents::AliasManager::RegisterReference(const detail::node& node) {
m_anchorByIdentity.insert(std::make_pair(node.ref(), _CreateNewAnchor()));
}
}
anchor_t NodeEvents::AliasManager::LookupAnchor(const detail::node& node) const
{
anchor_t NodeEvents::AliasManager::LookupAnchor(const detail::node& node)
const {
AnchorByIdentity::const_iterator it = m_anchorByIdentity.find(node.ref());
if(it == m_anchorByIdentity.end())
if (it == m_anchorByIdentity.end())
return 0;
return it->second;
}
}
NodeEvents::NodeEvents(const Node& node): m_pMemory(node.m_pMemory), m_root(node.m_pNode)
{
if(m_root)
NodeEvents::NodeEvents(const Node& node)
: m_pMemory(node.m_pMemory), m_root(node.m_pNode) {
if (m_root)
Setup(*m_root);
}
}
void NodeEvents::Setup(const detail::node& node)
{
void NodeEvents::Setup(const detail::node& node) {
int& refCount = m_refCount[node.ref()];
refCount++;
if(refCount > 1)
if (refCount > 1)
return;
if(node.type() == NodeType::Sequence) {
for(detail::const_node_iterator it=node.begin();it!=node.end();++it)
if (node.type() == NodeType::Sequence) {
for (detail::const_node_iterator it = node.begin(); it != node.end(); ++it)
Setup(**it);
} else if(node.type() == NodeType::Map) {
for(detail::const_node_iterator it=node.begin();it!=node.end();++it) {
} else if (node.type() == NodeType::Map) {
for (detail::const_node_iterator it = node.begin(); it != node.end();
++it) {
Setup(*it->first);
Setup(*it->second);
}
}
}
}
void NodeEvents::Emit(EventHandler& handler)
{
void NodeEvents::Emit(EventHandler& handler) {
AliasManager am;
handler.OnDocumentStart(Mark());
if(m_root)
if (m_root)
Emit(*m_root, handler, am);
handler.OnDocumentEnd();
}
}
void NodeEvents::Emit(const detail::node& node, EventHandler& handler, AliasManager& am) const
{
void NodeEvents::Emit(const detail::node& node, EventHandler& handler,
AliasManager& am) const {
anchor_t anchor = NullAnchor;
if(IsAliased(node)) {
if (IsAliased(node)) {
anchor = am.LookupAnchor(node);
if(anchor) {
if (anchor) {
handler.OnAlias(Mark(), anchor);
return;
}
......@@ -67,7 +64,7 @@ namespace YAML
anchor = am.LookupAnchor(node);
}
switch(node.type()) {
switch (node.type()) {
case NodeType::Undefined:
break;
case NodeType::Null:
......@@ -78,24 +75,25 @@ namespace YAML
break;
case NodeType::Sequence:
handler.OnSequenceStart(Mark(), node.tag(), anchor);
for(detail::const_node_iterator it=node.begin();it!=node.end();++it)
for (detail::const_node_iterator it = node.begin(); it != node.end();
++it)
Emit(**it, handler, am);
handler.OnSequenceEnd();
break;
case NodeType::Map:
handler.OnMapStart(Mark(), node.tag(), anchor);
for(detail::const_node_iterator it=node.begin();it!=node.end();++it) {
for (detail::const_node_iterator it = node.begin(); it != node.end();
++it) {
Emit(*it->first, handler, am);
Emit(*it->second, handler, am);
}
handler.OnMapEnd();
break;
}
}
}
bool NodeEvents::IsAliased(const detail::node& node) const
{
bool NodeEvents::IsAliased(const detail::node& node) const {
RefCount::const_iterator it = m_refCount.find(node.ref());
return it != m_refCount.end() && it->second > 1;
}
}
}
#ifndef NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODE_NODEEVENTS_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
......@@ -10,13 +12,11 @@
#include <map>
#include <vector>
namespace YAML
{
class EventHandler;
class Node;
namespace YAML {
class EventHandler;
class Node;
class NodeEvents
{
class NodeEvents {
public:
explicit NodeEvents(const Node& node);
......@@ -25,7 +25,7 @@ namespace YAML
private:
class AliasManager {
public:
AliasManager(): m_curAnchor(0) {}
AliasManager() : m_curAnchor(0) {}
void RegisterReference(const detail::node& node);
anchor_t LookupAnchor(const detail::node& node) const;
......@@ -41,17 +41,17 @@ namespace YAML
};
void Setup(const detail::node& node);
void Emit(const detail::node& node, EventHandler& handler, AliasManager& am) const;
void Emit(const detail::node& node, EventHandler& handler,
AliasManager& am) const;
bool IsAliased(const detail::node& node) const;
private:
detail::shared_memory_holder m_pMemory;
detail::node* m_root;
typedef std::map<const detail::node_ref *, int> RefCount;
typedef std::map<const detail::node_ref*, int> RefCount;
RefCount m_refCount;
};
};
}
#endif // NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
......@@ -2,55 +2,52 @@
#include <cstring>
#include <iostream>
namespace YAML
{
ostream_wrapper::ostream_wrapper(): m_buffer(1), m_pStream(0), m_pos(0), m_row(0), m_col(0), m_comment(false)
{
}
ostream_wrapper::ostream_wrapper(std::ostream& stream): m_pStream(&stream), m_pos(0), m_row(0), m_col(0), m_comment(false)
{
}
ostream_wrapper::~ostream_wrapper()
{
}
void ostream_wrapper::write(const std::string& str)
{
if(m_pStream) {
namespace YAML {
ostream_wrapper::ostream_wrapper()
: m_buffer(1),
m_pStream(0),
m_pos(0),
m_row(0),
m_col(0),
m_comment(false) {}
ostream_wrapper::ostream_wrapper(std::ostream& stream)
: m_pStream(&stream), m_pos(0), m_row(0), m_col(0), m_comment(false) {}
ostream_wrapper::~ostream_wrapper() {}
void ostream_wrapper::write(const std::string& str) {
if (m_pStream) {
m_pStream->write(str.c_str(), str.size());
} else {
m_buffer.resize(std::max(m_buffer.size(), m_pos + str.size() + 1));
std::copy(str.begin(), str.end(), &m_buffer[m_pos]);
}
for(std::size_t i=0;i<str.size();i++)
for (std::size_t i = 0; i < str.size(); i++)
update_pos(str[i]);
}
}
void ostream_wrapper::write(const char *str, std::size_t size)
{
if(m_pStream) {
void ostream_wrapper::write(const char* str, std::size_t size) {
if (m_pStream) {
m_pStream->write(str, size);
} else {
m_buffer.resize(std::max(m_buffer.size(), m_pos + size + 1));
std::copy(str, str + size, &m_buffer[m_pos]);
}
for(std::size_t i=0;i<size;i++)
for (std::size_t i = 0; i < size; i++)
update_pos(str[i]);
}
}
void ostream_wrapper::update_pos(char ch)
{
void ostream_wrapper::update_pos(char ch) {
m_pos++;
m_col++;
if(ch == '\n') {
if (ch == '\n') {
m_row++;
m_col = 0;
m_comment = false;
}
}
}
}
......@@ -7,62 +7,61 @@
#include <fstream>
#include <sstream>
namespace YAML
{
Node Load(const std::string& input) {
namespace YAML {
Node Load(const std::string& input) {
std::stringstream stream(input);
return Load(stream);
}
}
Node Load(const char *input) {
Node Load(const char* input) {
std::stringstream stream(input);
return Load(stream);
}
}
Node Load(std::istream& input) {
Node Load(std::istream& input) {
Parser parser(input);
NodeBuilder builder;
if(!parser.HandleNextDocument(builder))
if (!parser.HandleNextDocument(builder))
return Node();
return builder.Root();
}
}
Node LoadFile(const std::string& filename) {
Node LoadFile(const std::string& filename) {
std::ifstream fin(filename.c_str());
if(!fin)
if (!fin)
throw BadFile();
return Load(fin);
}
}
std::vector<Node> LoadAll(const std::string& input) {
std::vector<Node> LoadAll(const std::string& input) {
std::stringstream stream(input);
return LoadAll(stream);
}
}
std::vector<Node> LoadAll(const char *input) {
std::vector<Node> LoadAll(const char* input) {
std::stringstream stream(input);
return LoadAll(stream);
}
}
std::vector<Node> LoadAll(std::istream& input) {
std::vector<Node> LoadAll(std::istream& input) {
std::vector<Node> docs;
Parser parser(input);
while(1) {
while (1) {
NodeBuilder builder;
if(!parser.HandleNextDocument(builder))
if (!parser.HandleNextDocument(builder))
break;
docs.push_back(builder.Root());
}
return docs;
}
}
std::vector<Node> LoadAllFromFile(const std::string& filename) {
std::vector<Node> LoadAllFromFile(const std::string& filename) {
std::ifstream fin(filename.c_str());
if(!fin)
if (!fin)
throw BadFile();
return LoadAll(fin);
}
}
}
......@@ -3,18 +3,17 @@
#include "yaml-cpp/yaml.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";
......@@ -22,9 +21,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";
......@@ -33,35 +32,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";
......@@ -70,9 +71,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";
......@@ -82,20 +83,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;
......@@ -106,9 +108,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";
......@@ -121,10 +123,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";
......@@ -138,10 +141,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";
......@@ -152,10 +156,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";
......@@ -165,10 +168,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";
......@@ -179,10 +181,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;
......@@ -192,10 +193,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";
......@@ -206,34 +206,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";
......@@ -243,10 +246,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;
......@@ -258,10 +260,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;
......@@ -272,20 +273,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;
......@@ -296,101 +295,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";
......@@ -398,24 +389,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";
......@@ -467,13 +455,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);
......@@ -481,128 +475,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;
......@@ -612,194 +619,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;
......@@ -831,10 +841,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;
......@@ -844,27 +853,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 << ':';
......@@ -874,46 +881,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;
......@@ -936,20 +938,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;
......@@ -957,50 +957,49 @@ 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 {
void RunEmitterTest(void (*test)(YAML::Emitter&, std::string&), const std::string& name, int& passed, int& total) {
namespace {
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 {
YAML::Node node = YAML::Load(output);
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";
}
......@@ -1010,63 +1009,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);
......@@ -1087,67 +1088,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);
......@@ -1159,6 +1195,5 @@ namespace Test
std::cout << "Emitter tests: " << passed << "/" << total << " passed\n";
return passed == total;
}
}
}
......@@ -9,60 +9,60 @@
#endif
namespace {
struct TEST {
TEST(): ok(false) {}
TEST(bool ok_): ok(ok_) {}
TEST(const char *error_): ok(false), error(error_) {}
TEST(const std::string& error_): ok(false), error(error_) {}
struct TEST {
TEST() : ok(false) {}
TEST(bool ok_) : ok(ok_) {}
TEST(const char* error_) : ok(false), error(error_) {}
TEST(const std::string& error_) : ok(false), error(error_) {}
bool ok;
std::string error;
};
}
#define YAML_ASSERT(cond)\
do {\
if(!(cond))\
return " Assert failed: " #cond;\
} while(false)
#define YAML_ASSERT_THROWS(cond, exc)\
do {\
try {\
(cond);\
return " Expression did not throw: " #cond;\
} catch(const exc&) {\
} catch(const std::runtime_error& e) {\
std::stringstream stream;\
stream << " Expression threw runtime error ther than " #exc ":\n " #cond "\n " << e.what();\
return stream.str();\
} catch(...) {\
return " Expression threw unknown exception, other than " #exc ":\n " #cond;\
}\
} while(false)
namespace Test
{
namespace Node
{
TEST SimpleScalar()
{
};
}
#define YAML_ASSERT(cond) \
do { \
if (!(cond)) \
return " Assert failed: " #cond; \
} while (false)
#define YAML_ASSERT_THROWS(cond, exc) \
do { \
try { \
(cond); \
return " Expression did not throw: " #cond; \
} \
catch (const exc&) { \
} \
catch (const std::runtime_error& e) { \
std::stringstream stream; \
stream << " Expression threw runtime error ther than " #exc \
":\n " #cond "\n " << e.what(); \
return stream.str(); \
} \
catch (...) { \
return " Expression threw unknown exception, other than " #exc \
":\n " #cond; \
} \
} while (false)
namespace Test {
namespace Node {
TEST SimpleScalar() {
YAML::Node node = YAML::Node("Hello, World!");
YAML_ASSERT(node.IsScalar());
YAML_ASSERT(node.as<std::string>() == "Hello, World!");
return true;
}
}
TEST IntScalar()
{
TEST IntScalar() {
YAML::Node node = YAML::Node(15);
YAML_ASSERT(node.IsScalar());
YAML_ASSERT(node.as<int>() == 15);
return true;
}
}
TEST SimpleAppendSequence()
{
TEST SimpleAppendSequence() {
YAML::Node node;
node.push_back(10);
node.push_back("foo");
......@@ -74,10 +74,9 @@ namespace Test
YAML_ASSERT(node[2].as<std::string>() == "monkey");
YAML_ASSERT(node.IsSequence());
return true;
}
}
TEST SimpleAssignSequence()
{
TEST SimpleAssignSequence() {
YAML::Node node;
node[0] = 10;
node[1] = "foo";
......@@ -89,20 +88,18 @@ namespace Test
YAML_ASSERT(node[2].as<std::string>() == "monkey");
YAML_ASSERT(node.IsSequence());
return true;
}
}
TEST SimpleMap()
{
TEST SimpleMap() {
YAML::Node node;
node["key"] = "value";
YAML_ASSERT(node.IsMap());
YAML_ASSERT(node["key"].as<std::string>() == "value");
YAML_ASSERT(node.size() == 1);
return true;
}
}
TEST MapWithUndefinedValues()
{
TEST MapWithUndefinedValues() {
YAML::Node node;
node["key"] = "value";
node["undefined"];
......@@ -115,23 +112,21 @@ namespace Test
YAML_ASSERT(node.size() == 2);
return true;
}
}
TEST MapIteratorWithUndefinedValues()
{
TEST MapIteratorWithUndefinedValues() {
YAML::Node node;
node["key"] = "value";
node["undefined"];
std::size_t count = 0;
for(YAML::const_iterator it=node.begin();it!=node.end();++it)
for (YAML::const_iterator it = node.begin(); it != node.end(); ++it)
count++;
YAML_ASSERT(count == 1);
return true;
}
}
TEST SimpleSubkeys()
{
TEST SimpleSubkeys() {
YAML::Node node;
node["device"]["udid"] = "12345";
node["device"]["name"] = "iPhone";
......@@ -142,10 +137,9 @@ namespace Test
YAML_ASSERT(node["device"]["os"].as<std::string>() == "4.0");
YAML_ASSERT(node["username"].as<std::string>() == "monkey");
return true;
}
}
TEST StdVector()
{
TEST StdVector() {
std::vector<int> primes;
primes.push_back(2);
primes.push_back(3);
......@@ -158,10 +152,9 @@ namespace Test
node["primes"] = primes;
YAML_ASSERT(node["primes"].as<std::vector<int> >() == primes);
return true;
}
}
TEST StdList()
{
TEST StdList() {
std::list<int> primes;
primes.push_back(2);
primes.push_back(3);
......@@ -174,10 +167,9 @@ namespace Test
node["primes"] = primes;
YAML_ASSERT(node["primes"].as<std::list<int> >() == primes);
return true;
}
}
TEST StdMap()
{
TEST StdMap() {
std::map<int, int> squares;
squares[0] = 0;
squares[1] = 1;
......@@ -189,10 +181,9 @@ namespace Test
node["squares"] = squares;
YAML_ASSERT((node["squares"].as<std::map<int, int> >() == squares));
return true;
}
}
TEST StdPair()
{
TEST StdPair() {
std::pair<int, std::string> p;
p.first = 5;
p.second = "five";
......@@ -201,10 +192,9 @@ namespace Test
node["pair"] = p;
YAML_ASSERT((node["pair"].as<std::pair<int, std::string> >() == p));
return true;
}
}
TEST SimpleAlias()
{
TEST SimpleAlias() {
YAML::Node node;
node["foo"] = "value";
node["bar"] = node["foo"];
......@@ -213,10 +203,9 @@ namespace Test
YAML_ASSERT(node["foo"] == node["bar"]);
YAML_ASSERT(node.size() == 2);
return true;
}
}
TEST AliasAsKey()
{
TEST AliasAsKey() {
YAML::Node node;
node["foo"] = "value";
YAML::Node value = node["foo"];
......@@ -226,10 +215,9 @@ namespace Test
YAML_ASSERT(node["value"].as<std::string>() == "foo");
YAML_ASSERT(node.size() == 2);
return true;
}
}
TEST SelfReferenceSequence()
{
TEST SelfReferenceSequence() {
YAML::Node node;
node[0] = node;
YAML_ASSERT(node.IsSequence());
......@@ -238,10 +226,9 @@ namespace Test
YAML_ASSERT(node[0][0] == node);
YAML_ASSERT(node[0][0] == node[0]);
return true;
}
}
TEST ValueSelfReferenceMap()
{
TEST ValueSelfReferenceMap() {
YAML::Node node;
node["key"] = node;
YAML_ASSERT(node.IsMap());
......@@ -250,20 +237,18 @@ namespace Test
YAML_ASSERT(node["key"]["key"] == node);
YAML_ASSERT(node["key"]["key"] == node["key"]);
return true;
}
}
TEST KeySelfReferenceMap()
{
TEST KeySelfReferenceMap() {
YAML::Node node;
node[node] = "value";
YAML_ASSERT(node.IsMap());
YAML_ASSERT(node.size() == 1);
YAML_ASSERT(node[node].as<std::string>() == "value");
return true;
}
}
TEST SelfReferenceMap()
{
TEST SelfReferenceMap() {
YAML::Node node;
node[node] = node;
YAML_ASSERT(node.IsMap());
......@@ -272,10 +257,9 @@ namespace Test
YAML_ASSERT(node[node][node] == node);
YAML_ASSERT(node[node][node] == node[node]);
return true;
}
}
TEST TempMapVariable()
{
TEST TempMapVariable() {
YAML::Node node;
YAML::Node tmp = node["key"];
tmp = "value";
......@@ -283,10 +267,9 @@ namespace Test
YAML_ASSERT(node.size() == 1);
YAML_ASSERT(node["key"].as<std::string>() == "value");
return true;
}
}
TEST TempMapVariableAlias()
{
TEST TempMapVariableAlias() {
YAML::Node node;
YAML::Node tmp = node["key"];
tmp = node["other"];
......@@ -297,36 +280,32 @@ namespace Test
YAML_ASSERT(node["other"].as<std::string>() == "value");
YAML_ASSERT(node["other"] == node["key"]);
return true;
}
}
TEST Bool()
{
TEST Bool() {
YAML::Node node;
node[true] = false;
YAML_ASSERT(node.IsMap());
YAML_ASSERT(node[true].as<bool>() == false);
return true;
}
}
TEST AutoBoolConversion()
{
TEST AutoBoolConversion() {
YAML::Node node;
node["foo"] = "bar";
YAML_ASSERT(static_cast<bool>(node["foo"]));
YAML_ASSERT(!node["monkey"]);
YAML_ASSERT(!!node["foo"]);
return true;
}
}
TEST Reassign()
{
TEST Reassign() {
YAML::Node node = YAML::Load("foo");
node = YAML::Node();
return true;
}
}
TEST FallbackValues()
{
TEST FallbackValues() {
YAML::Node node = YAML::Load("foo: bar\nx: 2");
YAML_ASSERT(node["foo"].as<std::string>() == "bar");
YAML_ASSERT(node["foo"].as<std::string>("hello") == "bar");
......@@ -335,10 +314,9 @@ namespace Test
YAML_ASSERT(node["x"].as<int>(5) == 2);
YAML_ASSERT(node["y"].as<int>(5) == 5);
return true;
}
}
TEST NumericConversion()
{
TEST NumericConversion() {
YAML::Node node = YAML::Load("[1.5, 1, .nan, .inf, -.inf, 0x15, 015]");
YAML_ASSERT(node[0].as<float>() == 1.5f);
YAML_ASSERT(node[0].as<double>() == 1.5);
......@@ -351,90 +329,99 @@ namespace Test
YAML_ASSERT(node[5].as<int>() == 21);
YAML_ASSERT(node[6].as<int>() == 13);
return true;
}
}
TEST Binary()
{
YAML::Node node = YAML::Load("[!!binary \"SGVsbG8sIFdvcmxkIQ==\", !!binary \"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4K\"]");
YAML_ASSERT(node[0].as<YAML::Binary>() == YAML::Binary(reinterpret_cast<const unsigned char*>("Hello, World!"), 13));
YAML_ASSERT(node[1].as<YAML::Binary>() == 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));
TEST Binary() {
YAML::Node node = YAML::Load(
"[!!binary \"SGVsbG8sIFdvcmxkIQ==\", !!binary "
"\"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieS"
"B0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIG"
"x1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbi"
"B0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZG"
"dlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS"
"4K\"]");
YAML_ASSERT(node[0].as<YAML::Binary>() ==
YAML::Binary(
reinterpret_cast<const unsigned char*>("Hello, World!"), 13));
YAML_ASSERT(node[1].as<YAML::Binary>() ==
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));
return true;
}
}
TEST IterateSequence()
{
TEST IterateSequence() {
YAML::Node node = YAML::Load("[1, 3, 5, 7]");
int seq[] = {1, 3, 5, 7};
int i=0;
for(YAML::const_iterator it=node.begin();it!=node.end();++it) {
int i = 0;
for (YAML::const_iterator it = node.begin(); it != node.end(); ++it) {
YAML_ASSERT(i < 4);
int x = seq[i++];
YAML_ASSERT(it->as<int>() == x);
}
YAML_ASSERT(i == 4);
return true;
}
}
TEST IterateMap()
{
TEST IterateMap() {
YAML::Node node = YAML::Load("{a: A, b: B, c: C}");
int i=0;
for(YAML::const_iterator it=node.begin();it!=node.end();++it) {
int i = 0;
for (YAML::const_iterator it = node.begin(); it != node.end(); ++it) {
YAML_ASSERT(i < 3);
i++;
YAML_ASSERT(it->first.as<char>() + 'A' - 'a' == it->second.as<char>());
}
YAML_ASSERT(i == 3);
return true;
}
}
#ifdef BOOST_FOREACH
TEST ForEach()
{
TEST ForEach() {
YAML::Node node = YAML::Load("[1, 3, 5, 7]");
int seq[] = {1, 3, 5, 7};
int i = 0;
BOOST_FOREACH(const YAML::Node &item, node) {
BOOST_FOREACH(const YAML::Node & item, node) {
int x = seq[i++];
YAML_ASSERT(item.as<int>() == x);
}
return true;
}
}
TEST ForEachMap()
{
TEST ForEachMap() {
YAML::Node node = YAML::Load("{a: A, b: B, c: C}");
BOOST_FOREACH(const YAML::const_iterator::value_type &p, node) {
BOOST_FOREACH(const YAML::const_iterator::value_type & p, node) {
YAML_ASSERT(p.first.as<char>() + 'A' - 'a' == p.second.as<char>());
}
return true;
}
}
#endif
TEST CloneScalar()
{
TEST CloneScalar() {
YAML::Node node = YAML::Load("!foo monkey");
YAML::Node clone = Clone(node);
YAML_ASSERT(!(node == clone));
YAML_ASSERT(node.as<std::string>() == clone.as<std::string>());
YAML_ASSERT(node.Tag() == clone.Tag());
return true;
}
}
TEST CloneSeq()
{
TEST CloneSeq() {
YAML::Node node = YAML::Load("[1, 3, 5, 7]");
YAML::Node clone = Clone(node);
YAML_ASSERT(!(node == clone));
YAML_ASSERT(clone.Type() == YAML::NodeType::Sequence);
YAML_ASSERT(node.size() == clone.size());
for(std::size_t i=0;i<node.size();i++)
for (std::size_t i = 0; i < node.size(); i++)
YAML_ASSERT(node[i].as<int>() == clone[i].as<int>());
return true;
}
}
TEST CloneMap()
{
TEST CloneMap() {
YAML::Node node = YAML::Load("{foo: bar}");
YAML::Node clone = Clone(node);
YAML_ASSERT(!(node == clone));
......@@ -442,10 +429,9 @@ namespace Test
YAML_ASSERT(node.size() == clone.size());
YAML_ASSERT(node["foo"].as<std::string>() == clone["foo"].as<std::string>());
return true;
}
}
TEST CloneAlias()
{
TEST CloneAlias() {
YAML::Node node = YAML::Load("&foo [*foo]");
YAML::Node clone = Clone(node);
YAML_ASSERT(!(node == clone));
......@@ -453,10 +439,9 @@ namespace Test
YAML_ASSERT(node.size() == clone.size());
YAML_ASSERT(clone == clone[0]);
return true;
}
}
TEST ForceInsertIntoMap()
{
TEST ForceInsertIntoMap() {
YAML::Node node;
node["a"] = "b";
node.force_insert("x", "y");
......@@ -466,23 +451,23 @@ namespace Test
bool ab = false;
bool a5 = false;
bool xy = false;
for(YAML::const_iterator it=node.begin();it!=node.end();++it) {
if(it->first.as<std::string>() == "a") {
if(it->second.as<std::string>() == "b")
for (YAML::const_iterator it = node.begin(); it != node.end(); ++it) {
if (it->first.as<std::string>() == "a") {
if (it->second.as<std::string>() == "b")
ab = true;
else if(it->second.as<std::string>() == "5")
else if (it->second.as<std::string>() == "5")
a5 = true;
} else if(it->first.as<std::string>() == "x" && it->second.as<std::string>() == "y")
} else if (it->first.as<std::string>() == "x" &&
it->second.as<std::string>() == "y")
xy = true;
}
YAML_ASSERT(ab);
YAML_ASSERT(a5);
YAML_ASSERT(xy);
return true;
}
}
TEST ResetNode()
{
TEST ResetNode() {
YAML::Node node = YAML::Load("[1, 2, 3]");
YAML_ASSERT(!node.IsNull());
YAML::Node other = node;
......@@ -493,10 +478,9 @@ namespace Test
YAML_ASSERT(!node.IsNull());
YAML_ASSERT(other == node);
return true;
}
}
TEST DereferenceIteratorError()
{
TEST DereferenceIteratorError() {
YAML::Node node = YAML::Load("[{a: b}, 1, 2]");
YAML_ASSERT_THROWS(node.begin()->first.as<int>(), YAML::InvalidNode);
YAML_ASSERT((*node.begin()).IsMap() == true);
......@@ -504,63 +488,65 @@ namespace Test
YAML_ASSERT_THROWS((*node.begin()->begin()).IsDefined(), YAML::InvalidNode);
YAML_ASSERT_THROWS(node.begin()->begin()->IsDefined(), YAML::InvalidNode);
return true;
}
}
TEST FloatingPrecision()
{
TEST FloatingPrecision() {
const double x = 0.123456789;
YAML::Node node = YAML::Node(x);
YAML_ASSERT(node.as<double>() == x);
return true;
}
}
TEST EmitEmptyNode()
{
TEST EmitEmptyNode() {
YAML::Node node;
YAML::Emitter emitter;
emitter << node;
YAML_ASSERT(std::string(emitter.c_str()) == "");
return true;
}
}
TEST SpaceChar()
{
TEST SpaceChar() {
YAML::Node node = YAML::Node(' ');
YAML_ASSERT(node.as<char>() == ' ');
return true;
}
}
}
}
void RunNodeTest(TEST (*test)(), const std::string& name, int& passed, int& total) {
void RunNodeTest(TEST (*test)(), const std::string& name, int& passed,
int& total) {
TEST ret;
try {
ret = test();
} catch(const std::exception& e) {
}
catch (const std::exception& e) {
ret.ok = false;
ret.error = e.what();
}
if(ret.ok) {
if (ret.ok) {
passed++;
} else {
std::cout << "Node test failed: " << name << "\n";
if(ret.error != "")
if (ret.error != "")
std::cout << ret.error << "\n";
}
total++;
}
}
bool RunNodeTests()
{
bool RunNodeTests() {
int passed = 0;
int total = 0;
RunNodeTest(&Node::SimpleScalar, "simple scalar", passed, total);
RunNodeTest(&Node::IntScalar, "int scalar", passed, total);
RunNodeTest(&Node::SimpleAppendSequence, "simple append sequence", passed, total);
RunNodeTest(&Node::SimpleAssignSequence, "simple assign sequence", passed, total);
RunNodeTest(&Node::SimpleAppendSequence, "simple append sequence", passed,
total);
RunNodeTest(&Node::SimpleAssignSequence, "simple assign sequence", passed,
total);
RunNodeTest(&Node::SimpleMap, "simple map", passed, total);
RunNodeTest(&Node::MapWithUndefinedValues, "map with undefined values", passed, total);
RunNodeTest(&Node::MapIteratorWithUndefinedValues, "map iterator with undefined values", passed, total);
RunNodeTest(&Node::MapWithUndefinedValues, "map with undefined values",
passed, total);
RunNodeTest(&Node::MapIteratorWithUndefinedValues,
"map iterator with undefined values", passed, total);
RunNodeTest(&Node::SimpleSubkeys, "simple subkey", passed, total);
RunNodeTest(&Node::StdVector, "std::vector", passed, total);
RunNodeTest(&Node::StdList, "std::list", passed, total);
......@@ -568,12 +554,16 @@ namespace Test
RunNodeTest(&Node::StdPair, "std::pair", passed, total);
RunNodeTest(&Node::SimpleAlias, "simple alias", passed, total);
RunNodeTest(&Node::AliasAsKey, "alias as key", passed, total);
RunNodeTest(&Node::SelfReferenceSequence, "self reference sequence", passed, total);
RunNodeTest(&Node::ValueSelfReferenceMap, "value self reference map", passed, total);
RunNodeTest(&Node::KeySelfReferenceMap, "key self reference map", passed, total);
RunNodeTest(&Node::SelfReferenceSequence, "self reference sequence", passed,
total);
RunNodeTest(&Node::ValueSelfReferenceMap, "value self reference map", passed,
total);
RunNodeTest(&Node::KeySelfReferenceMap, "key self reference map", passed,
total);
RunNodeTest(&Node::SelfReferenceMap, "self reference map", passed, total);
RunNodeTest(&Node::TempMapVariable, "temp map variable", passed, total);
RunNodeTest(&Node::TempMapVariableAlias, "temp map variable alias", passed, total);
RunNodeTest(&Node::TempMapVariableAlias, "temp map variable alias", passed,
total);
RunNodeTest(&Node::Bool, "bool", passed, total);
RunNodeTest(&Node::AutoBoolConversion, "auto bool conversion", passed, total);
RunNodeTest(&Node::Reassign, "reassign", passed, total);
......@@ -590,14 +580,16 @@ namespace Test
RunNodeTest(&Node::CloneSeq, "clone seq", passed, total);
RunNodeTest(&Node::CloneMap, "clone map", passed, total);
RunNodeTest(&Node::CloneAlias, "clone alias", passed, total);
RunNodeTest(&Node::ForceInsertIntoMap, "force insert into map", passed, total);
RunNodeTest(&Node::ForceInsertIntoMap, "force insert into map", passed,
total);
RunNodeTest(&Node::ResetNode, "reset node", passed, total);
RunNodeTest(&Node::DereferenceIteratorError, "dereference iterator error", passed, total);
RunNodeTest(&Node::DereferenceIteratorError, "dereference iterator error",
passed, total);
RunNodeTest(&Node::FloatingPrecision, "floating precision", passed, total);
RunNodeTest(&Node::EmitEmptyNode, "emit empty node", passed, total);
RunNodeTest(&Node::SpaceChar, "space char", passed, total);
std::cout << "Node tests: " << passed << "/" << total << " passed\n";
return passed == total;
}
}
}
#include "parsertests.h"
namespace Test {
bool RunParserTests()
{
return true;
}
bool RunParserTests() { return true; }
}
......@@ -3,14 +3,16 @@
#include "yaml-cpp/yaml.h"
#include <iostream>
#define YAML_ASSERT(cond) do { if(!(cond)) return " Assert failed: " #cond; } while(false)
namespace Test
{
namespace Spec
{
// 2.1
TEST SeqScalars() {
#define YAML_ASSERT(cond) \
do { \
if (!(cond)) \
return " Assert failed: " #cond; \
} while (false)
namespace Test {
namespace Spec {
// 2.1
TEST SeqScalars() {
YAML::Node doc = YAML::Load(ex2_1);
YAML_ASSERT(doc.IsSequence());
YAML_ASSERT(doc.size() == 3);
......@@ -18,10 +20,10 @@ namespace Test
YAML_ASSERT(doc[1].as<std::string>() == "Sammy Sosa");
YAML_ASSERT(doc[2].as<std::string>() == "Ken Griffey");
return true;
}
}
// 2.2
TEST MappingScalarsToScalars() {
// 2.2
TEST MappingScalarsToScalars() {
YAML::Node doc = YAML::Load(ex2_2);
YAML_ASSERT(doc.IsMap());
YAML_ASSERT(doc.size() == 3);
......@@ -29,10 +31,10 @@ namespace Test
YAML_ASSERT(doc["avg"].as<std::string>() == "0.278");
YAML_ASSERT(doc["rbi"].as<std::string>() == "147");
return true;
}
}
// 2.3
TEST MappingScalarsToSequences() {
// 2.3
TEST MappingScalarsToSequences() {
YAML::Node doc = YAML::Load(ex2_3);
YAML_ASSERT(doc.IsMap());
YAML_ASSERT(doc.size() == 2);
......@@ -45,10 +47,10 @@ namespace Test
YAML_ASSERT(doc["national"][1].as<std::string>() == "Chicago Cubs");
YAML_ASSERT(doc["national"][2].as<std::string>() == "Atlanta Braves");
return true;
}
}
// 2.4
TEST SequenceOfMappings() {
// 2.4
TEST SequenceOfMappings() {
YAML::Node doc = YAML::Load(ex2_4);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc[0].size() == 3);
......@@ -60,10 +62,10 @@ namespace Test
YAML_ASSERT(doc[1]["hr"].as<std::string>() == "63");
YAML_ASSERT(doc[1]["avg"].as<std::string>() == "0.288");
return true;
}
}
// 2.5
TEST SequenceOfSequences() {
// 2.5
TEST SequenceOfSequences() {
YAML::Node doc = YAML::Load(ex2_5);
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc[0].size() == 3);
......@@ -79,10 +81,10 @@ namespace Test
YAML_ASSERT(doc[2][1].as<std::string>() == "63");
YAML_ASSERT(doc[2][2].as<std::string>() == "0.288");
return true;
}
}
// 2.6
TEST MappingOfMappings() {
// 2.6
TEST MappingOfMappings() {
YAML::Node doc = YAML::Load(ex2_6);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc["Mark McGwire"].size() == 2);
......@@ -92,10 +94,10 @@ namespace Test
YAML_ASSERT(doc["Sammy Sosa"]["hr"].as<std::string>() == "63");
YAML_ASSERT(doc["Sammy Sosa"]["avg"].as<std::string>() == "0.288");
return true;
}
}
// 2.7
TEST TwoDocumentsInAStream() {
// 2.7
TEST TwoDocumentsInAStream() {
std::vector<YAML::Node> docs = YAML::LoadAll(ex2_7);
YAML_ASSERT(docs.size() == 2);
......@@ -114,10 +116,10 @@ namespace Test
YAML_ASSERT(doc[1].as<std::string>() == "St Louis Cardinals");
}
return true;
}
}
// 2.8
TEST PlayByPlayFeed() {
// 2.8
TEST PlayByPlayFeed() {
std::vector<YAML::Node> docs = YAML::LoadAll(ex2_8);
YAML_ASSERT(docs.size() == 2);
......@@ -137,10 +139,10 @@ namespace Test
YAML_ASSERT(doc["action"].as<std::string>() == "grand slam");
}
return true;
}
}
// 2.9
TEST SingleDocumentWithTwoComments() {
// 2.9
TEST SingleDocumentWithTwoComments() {
YAML::Node doc = YAML::Load(ex2_9);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc["hr"].size() == 2);
......@@ -150,10 +152,10 @@ namespace Test
YAML_ASSERT(doc["rbi"][0].as<std::string>() == "Sammy Sosa");
YAML_ASSERT(doc["rbi"][1].as<std::string>() == "Ken Griffey");
return true;
}
}
// 2.10
TEST SimpleAnchor() {
// 2.10
TEST SimpleAnchor() {
YAML::Node doc = YAML::Load(ex2_10);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc["hr"].size() == 2);
......@@ -163,10 +165,10 @@ namespace Test
YAML_ASSERT(doc["rbi"][0].as<std::string>() == "Sammy Sosa");
YAML_ASSERT(doc["rbi"][1].as<std::string>() == "Ken Griffey");
return true;
}
}
// 2.11
TEST MappingBetweenSequences() {
// 2.11
TEST MappingBetweenSequences() {
YAML::Node doc = YAML::Load(ex2_11);
std::vector<std::string> tigers_cubs;
......@@ -177,7 +179,6 @@ namespace Test
yankees_braves.push_back("New York Yankees");
yankees_braves.push_back("Atlanta Braves");
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc[tigers_cubs].size() == 1);
YAML_ASSERT(doc[tigers_cubs][0].as<std::string>() == "2001-07-23");
......@@ -186,10 +187,10 @@ namespace Test
YAML_ASSERT(doc[yankees_braves][1].as<std::string>() == "2001-08-12");
YAML_ASSERT(doc[yankees_braves][2].as<std::string>() == "2001-08-14");
return true;
}
}
// 2.12
TEST CompactNestedMapping() {
// 2.12
TEST CompactNestedMapping() {
YAML::Node doc = YAML::Load(ex2_12);
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc[0].size() == 2);
......@@ -202,26 +203,27 @@ namespace Test
YAML_ASSERT(doc[2]["item"].as<std::string>() == "Big Shoes");
YAML_ASSERT(doc[2]["quantity"].as<int>() == 1);
return true;
}
}
// 2.13
TEST InLiteralsNewlinesArePreserved() {
// 2.13
TEST InLiteralsNewlinesArePreserved() {
YAML::Node doc = YAML::Load(ex2_13);
YAML_ASSERT(doc.as<std::string>() ==
"\\//||\\/||\n"
"// || ||__");
return true;
}
}
// 2.14
TEST InFoldedScalarsNewlinesBecomeSpaces() {
// 2.14
TEST InFoldedScalarsNewlinesBecomeSpaces() {
YAML::Node doc = YAML::Load(ex2_14);
YAML_ASSERT(doc.as<std::string>() == "Mark McGwire's year was crippled by a knee injury.");
YAML_ASSERT(doc.as<std::string>() ==
"Mark McGwire's year was crippled by a knee injury.");
return true;
}
}
// 2.15
TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines() {
// 2.15
TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines() {
YAML::Node doc = YAML::Load(ex2_15);
YAML_ASSERT(doc.as<std::string>() ==
"Sammy Sosa completed another fine season with great stats.\n\n"
......@@ -229,20 +231,22 @@ namespace Test
" 0.288 Batting Average\n\n"
"What a year!");
return true;
}
}
// 2.16
TEST IndentationDeterminesScope() {
// 2.16
TEST IndentationDeterminesScope() {
YAML::Node doc = YAML::Load(ex2_16);
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc["name"].as<std::string>() == "Mark McGwire");
YAML_ASSERT(doc["accomplishment"].as<std::string>() == "Mark set a major league home run record in 1998.\n");
YAML_ASSERT(doc["stats"].as<std::string>() == "65 Home Runs\n0.278 Batting Average\n");
YAML_ASSERT(doc["accomplishment"].as<std::string>() ==
"Mark set a major league home run record in 1998.\n");
YAML_ASSERT(doc["stats"].as<std::string>() ==
"65 Home Runs\n0.278 Batting Average\n");
return true;
}
}
// 2.17
TEST QuotedScalars() {
// 2.17
TEST QuotedScalars() {
YAML::Node doc = YAML::Load(ex2_17);
YAML_ASSERT(doc.size() == 6);
YAML_ASSERT(doc["unicode"].as<std::string>() == "Sosa did fine.\xe2\x98\xba");
......@@ -252,21 +256,23 @@ namespace Test
YAML_ASSERT(doc["quoted"].as<std::string>() == " # Not a 'comment'.");
YAML_ASSERT(doc["tie-fighter"].as<std::string>() == "|\\-*-/|");
return true;
}
}
// 2.18
TEST MultiLineFlowScalars() {
// 2.18
TEST MultiLineFlowScalars() {
YAML::Node doc = YAML::Load(ex2_18);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc["plain"].as<std::string>() == "This unquoted scalar spans many lines.");
YAML_ASSERT(doc["quoted"].as<std::string>() == "So does this quoted scalar.\n");
YAML_ASSERT(doc["plain"].as<std::string>() ==
"This unquoted scalar spans many lines.");
YAML_ASSERT(doc["quoted"].as<std::string>() ==
"So does this quoted scalar.\n");
return true;
}
}
// TODO: 2.19 - 2.22 schema tags
// TODO: 2.19 - 2.22 schema tags
// 2.23
TEST VariousExplicitTags() {
// 2.23
TEST VariousExplicitTags() {
YAML::Node doc = YAML::Load(ex2_23);
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc["not-date"].Tag() == "tag:yaml.org,2002:str");
......@@ -276,19 +282,17 @@ namespace Test
"R0lGODlhDAAMAIQAAP//9/X\n"
"17unp5WZmZgAAAOfn515eXv\n"
"Pz7Y6OjuDg4J+fn5OTk6enp\n"
"56enmleECcgggoBADs=\n"
);
"56enmleECcgggoBADs=\n");
YAML_ASSERT(doc["application specific tag"].Tag() == "!something");
YAML_ASSERT(doc["application specific tag"].as<std::string>() ==
"The semantics of the tag\n"
"above may be different for\n"
"different documents."
);
"different documents.");
return true;
}
}
// 2.24
TEST GlobalTags() {
// 2.24
TEST GlobalTags() {
YAML::Node doc = YAML::Load(ex2_24);
YAML_ASSERT(doc.Tag() == "tag:clarkevans.com,2002:shape");
YAML_ASSERT(doc.size() == 3);
......@@ -314,10 +318,10 @@ namespace Test
YAML_ASSERT(doc[2]["color"].as<std::string>() == "0xFFEEBB");
YAML_ASSERT(doc[2]["text"].as<std::string>() == "Pretty vector drawing.");
return true;
}
}
// 2.25
TEST UnorderedSets() {
// 2.25
TEST UnorderedSets() {
YAML::Node doc = YAML::Load(ex2_25);
YAML_ASSERT(doc.Tag() == "tag:yaml.org,2002:set");
YAML_ASSERT(doc.size() == 3);
......@@ -325,10 +329,10 @@ namespace Test
YAML_ASSERT(doc["Sammy Sosa"].IsNull());
YAML_ASSERT(doc["Ken Griffey"].IsNull());
return true;
}
}
// 2.26
TEST OrderedMappings() {
// 2.26
TEST OrderedMappings() {
YAML::Node doc = YAML::Load(ex2_26);
YAML_ASSERT(doc.Tag() == "tag:yaml.org,2002:omap");
YAML_ASSERT(doc.size() == 3);
......@@ -339,10 +343,10 @@ namespace Test
YAML_ASSERT(doc[2].size() == 1);
YAML_ASSERT(doc[2]["Ken Griffey"].as<int>() == 58);
return true;
}
}
// 2.27
TEST Invoice() {
// 2.27
TEST Invoice() {
YAML::Node doc = YAML::Load(ex2_27);
YAML_ASSERT(doc.Tag() == "tag:clarkevans.com,2002:invoice");
YAML_ASSERT(doc.size() == 8);
......@@ -352,37 +356,45 @@ namespace Test
YAML_ASSERT(doc["bill-to"]["given"].as<std::string>() == "Chris");
YAML_ASSERT(doc["bill-to"]["family"].as<std::string>() == "Dumars");
YAML_ASSERT(doc["bill-to"]["address"].size() == 4);
YAML_ASSERT(doc["bill-to"]["address"]["lines"].as<std::string>() == "458 Walkman Dr.\nSuite #292\n");
YAML_ASSERT(doc["bill-to"]["address"]["city"].as<std::string>() == "Royal Oak");
YAML_ASSERT(doc["bill-to"]["address"]["lines"].as<std::string>() ==
"458 Walkman Dr.\nSuite #292\n");
YAML_ASSERT(doc["bill-to"]["address"]["city"].as<std::string>() ==
"Royal Oak");
YAML_ASSERT(doc["bill-to"]["address"]["state"].as<std::string>() == "MI");
YAML_ASSERT(doc["bill-to"]["address"]["postal"].as<std::string>() == "48046");
YAML_ASSERT(doc["ship-to"].size() == 3);
YAML_ASSERT(doc["ship-to"]["given"].as<std::string>() == "Chris");
YAML_ASSERT(doc["ship-to"]["family"].as<std::string>() == "Dumars");
YAML_ASSERT(doc["ship-to"]["address"].size() == 4);
YAML_ASSERT(doc["ship-to"]["address"]["lines"].as<std::string>() == "458 Walkman Dr.\nSuite #292\n");
YAML_ASSERT(doc["ship-to"]["address"]["city"].as<std::string>() == "Royal Oak");
YAML_ASSERT(doc["ship-to"]["address"]["lines"].as<std::string>() ==
"458 Walkman Dr.\nSuite #292\n");
YAML_ASSERT(doc["ship-to"]["address"]["city"].as<std::string>() ==
"Royal Oak");
YAML_ASSERT(doc["ship-to"]["address"]["state"].as<std::string>() == "MI");
YAML_ASSERT(doc["ship-to"]["address"]["postal"].as<std::string>() == "48046");
YAML_ASSERT(doc["product"].size() == 2);
YAML_ASSERT(doc["product"][0].size() == 4);
YAML_ASSERT(doc["product"][0]["sku"].as<std::string>() == "BL394D");
YAML_ASSERT(doc["product"][0]["quantity"].as<int>() == 4);
YAML_ASSERT(doc["product"][0]["description"].as<std::string>() == "Basketball");
YAML_ASSERT(doc["product"][0]["description"].as<std::string>() ==
"Basketball");
YAML_ASSERT(doc["product"][0]["price"].as<std::string>() == "450.00");
YAML_ASSERT(doc["product"][1].size() == 4);
YAML_ASSERT(doc["product"][1]["sku"].as<std::string>() == "BL4438H");
YAML_ASSERT(doc["product"][1]["quantity"].as<int>() == 1);
YAML_ASSERT(doc["product"][1]["description"].as<std::string>() == "Super Hoop");
YAML_ASSERT(doc["product"][1]["description"].as<std::string>() ==
"Super Hoop");
YAML_ASSERT(doc["product"][1]["price"].as<std::string>() == "2392.00");
YAML_ASSERT(doc["tax"].as<std::string>() == "251.42");
YAML_ASSERT(doc["total"].as<std::string>() == "4443.52");
YAML_ASSERT(doc["comments"].as<std::string>() == "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.");
YAML_ASSERT(
doc["comments"].as<std::string>() ==
"Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.");
return true;
}
}
// 2.28
TEST LogFile() {
// 2.28
TEST LogFile() {
std::vector<YAML::Node> docs = YAML::LoadAll(ex2_28);
YAML_ASSERT(docs.size() == 3);
......@@ -391,7 +403,8 @@ namespace Test
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc["Time"].as<std::string>() == "2001-11-23 15:01:42 -5");
YAML_ASSERT(doc["User"].as<std::string>() == "ed");
YAML_ASSERT(doc["Warning"].as<std::string>() == "This is an error message for the log file");
YAML_ASSERT(doc["Warning"].as<std::string>() ==
"This is an error message for the log file");
}
{
......@@ -399,7 +412,8 @@ namespace Test
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc["Time"].as<std::string>() == "2001-11-23 15:02:31 -5");
YAML_ASSERT(doc["User"].as<std::string>() == "ed");
YAML_ASSERT(doc["Warning"].as<std::string>() == "A slightly different error message.");
YAML_ASSERT(doc["Warning"].as<std::string>() ==
"A slightly different error message.");
}
{
......@@ -412,19 +426,20 @@ namespace Test
YAML_ASSERT(doc["Stack"][0].size() == 3);
YAML_ASSERT(doc["Stack"][0]["file"].as<std::string>() == "TopClass.py");
YAML_ASSERT(doc["Stack"][0]["line"].as<std::string>() == "23");
YAML_ASSERT(doc["Stack"][0]["code"].as<std::string>() == "x = MoreObject(\"345\\n\")\n");
YAML_ASSERT(doc["Stack"][0]["code"].as<std::string>() ==
"x = MoreObject(\"345\\n\")\n");
YAML_ASSERT(doc["Stack"][1].size() == 3);
YAML_ASSERT(doc["Stack"][1]["file"].as<std::string>() == "MoreClass.py");
YAML_ASSERT(doc["Stack"][1]["line"].as<std::string>() == "58");
YAML_ASSERT(doc["Stack"][1]["code"].as<std::string>() == "foo = bar");
}
return true;
}
}
// TODO: 5.1 - 5.2 BOM
// TODO: 5.1 - 5.2 BOM
// 5.3
TEST BlockStructureIndicators() {
// 5.3
TEST BlockStructureIndicators() {
YAML::Node doc = YAML::Load(ex5_3);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc["sequence"].size() == 2);
......@@ -434,10 +449,10 @@ namespace Test
YAML_ASSERT(doc["mapping"]["sky"].as<std::string>() == "blue");
YAML_ASSERT(doc["mapping"]["sea"].as<std::string>() == "green");
return true;
}
}
// 5.4
TEST FlowStructureIndicators() {
// 5.4
TEST FlowStructureIndicators() {
YAML::Node doc = YAML::Load(ex5_4);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc["sequence"].size() == 2);
......@@ -447,54 +462,56 @@ namespace Test
YAML_ASSERT(doc["mapping"]["sky"].as<std::string>() == "blue");
YAML_ASSERT(doc["mapping"]["sea"].as<std::string>() == "green");
return true;
}
}
// 5.5
TEST CommentIndicator() {
// 5.5
TEST CommentIndicator() {
YAML::Node doc = YAML::Load(ex5_5);
YAML_ASSERT(doc.IsNull());
return true;
}
}
// 5.6
TEST NodePropertyIndicators() {
// 5.6
TEST NodePropertyIndicators() {
YAML::Node doc = YAML::Load(ex5_6);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc["anchored"].as<std::string>() == "value"); // TODO: assert tag
YAML_ASSERT(doc["anchored"].as<std::string>() ==
"value"); // TODO: assert tag
YAML_ASSERT(doc["alias"].as<std::string>() == "value");
return true;
}
}
// 5.7
TEST BlockScalarIndicators() {
// 5.7
TEST BlockScalarIndicators() {
YAML::Node doc = YAML::Load(ex5_7);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc["literal"].as<std::string>() == "some\ntext\n");
YAML_ASSERT(doc["folded"].as<std::string>() == "some text\n");
return true;
}
}
// 5.8
TEST QuotedScalarIndicators() {
// 5.8
TEST QuotedScalarIndicators() {
YAML::Node doc = YAML::Load(ex5_8);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc["single"].as<std::string>() == "text");
YAML_ASSERT(doc["double"].as<std::string>() == "text");
return true;
}
}
// 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() {
YAML::Node doc = YAML::Load(ex5_11);
YAML_ASSERT(doc.as<std::string>() == "Line break (no glyph)\nLine break (glyphed)\n");
YAML_ASSERT(doc.as<std::string>() ==
"Line break (no glyph)\nLine break (glyphed)\n");
return true;
}
}
// 5.12
TEST TabsAndSpaces() {
// 5.12
TEST TabsAndSpaces() {
YAML::Node doc = YAML::Load(ex5_12);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc["quoted"].as<std::string>() == "Quoted\t");
......@@ -503,42 +520,50 @@ namespace Test
"\tprintf(\"Hello, world!\\n\");\n"
"}");
return true;
}
}
// 5.13
TEST EscapedCharacters() {
// 5.13
TEST EscapedCharacters() {
YAML::Node doc = YAML::Load(ex5_13);
YAML_ASSERT(doc.as<std::string>() == "Fun with \x5C \x22 \x07 \x08 \x1B \x0C \x0A \x0D \x09 \x0B " + std::string("\x00", 1) + " \x20 \xA0 \x85 \xe2\x80\xa8 \xe2\x80\xa9 A A A");
YAML_ASSERT(doc.as<std::string>() ==
"Fun with \x5C \x22 \x07 \x08 \x1B \x0C \x0A \x0D \x09 \x0B " +
std::string("\x00", 1) +
" \x20 \xA0 \x85 \xe2\x80\xa8 \xe2\x80\xa9 A A A");
return true;
}
}
// 5.14
TEST InvalidEscapedCharacters() {
// 5.14
TEST InvalidEscapedCharacters() {
try {
YAML::Load(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 false;
}
}
// 6.1
TEST IndentationSpaces() {
// 6.1
TEST IndentationSpaces() {
YAML::Node doc = YAML::Load(ex6_1);
YAML_ASSERT(doc.size() == 1);
YAML_ASSERT(doc["Not indented"].size() == 2);
YAML_ASSERT(doc["Not indented"]["By one space"].as<std::string>() == "By four\n spaces\n");
YAML_ASSERT(doc["Not indented"]["By one space"].as<std::string>() ==
"By four\n spaces\n");
YAML_ASSERT(doc["Not indented"]["Flow style"].size() == 3);
YAML_ASSERT(doc["Not indented"]["Flow style"][0].as<std::string>() == "By two");
YAML_ASSERT(doc["Not indented"]["Flow style"][1].as<std::string>() == "Also by two");
YAML_ASSERT(doc["Not indented"]["Flow style"][2].as<std::string>() == "Still by two");
YAML_ASSERT(doc["Not indented"]["Flow style"][0].as<std::string>() ==
"By two");
YAML_ASSERT(doc["Not indented"]["Flow style"][1].as<std::string>() ==
"Also by two");
YAML_ASSERT(doc["Not indented"]["Flow style"][2].as<std::string>() ==
"Still by two");
return true;
}
}
// 6.2
TEST IndentationIndicators() {
// 6.2
TEST IndentationIndicators() {
YAML::Node doc = YAML::Load(ex6_2);
YAML_ASSERT(doc.size() == 1);
YAML_ASSERT(doc["a"].size() == 2);
......@@ -547,10 +572,10 @@ namespace Test
YAML_ASSERT(doc["a"][1][0].as<std::string>() == "c");
YAML_ASSERT(doc["a"][1][1].as<std::string>() == "d");
return true;
}
}
// 6.3
TEST SeparationSpaces() {
// 6.3
TEST SeparationSpaces() {
YAML::Node doc = YAML::Load(ex6_3);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc[0].size() == 1);
......@@ -559,73 +584,73 @@ namespace Test
YAML_ASSERT(doc[1][0].as<std::string>() == "baz");
YAML_ASSERT(doc[1][1].as<std::string>() == "baz");
return true;
}
}
// 6.4
TEST LinePrefixes() {
// 6.4
TEST LinePrefixes() {
YAML::Node doc = YAML::Load(ex6_4);
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc["plain"].as<std::string>() == "text lines");
YAML_ASSERT(doc["quoted"].as<std::string>() == "text lines");
YAML_ASSERT(doc["block"].as<std::string>() == "text\n \tlines\n");
return true;
}
}
// 6.5
TEST EmptyLines() {
// 6.5
TEST EmptyLines() {
YAML::Node doc = YAML::Load(ex6_5);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc["Folding"].as<std::string>() == "Empty line\nas a line feed");
YAML_ASSERT(doc["Chomping"].as<std::string>() == "Clipped empty lines\n");
return true;
}
}
// 6.6
TEST LineFolding() {
// 6.6
TEST LineFolding() {
YAML::Node doc = YAML::Load(ex6_6);
YAML_ASSERT(doc.as<std::string>() == "trimmed\n\n\nas space");
return true;
}
}
// 6.7
TEST BlockFolding() {
// 6.7
TEST BlockFolding() {
YAML::Node doc = YAML::Load(ex6_7);
YAML_ASSERT(doc.as<std::string>() == "foo \n\n\t bar\n\nbaz\n");
return true;
}
}
// 6.8
TEST FlowFolding() {
// 6.8
TEST FlowFolding() {
YAML::Node doc = YAML::Load(ex6_8);
YAML_ASSERT(doc.as<std::string>() == " foo\nbar\nbaz ");
return true;
}
}
// 6.9
TEST SeparatedComment() {
// 6.9
TEST SeparatedComment() {
YAML::Node doc = YAML::Load(ex6_9);
YAML_ASSERT(doc.size() == 1);
YAML_ASSERT(doc["key"].as<std::string>() == "value");
return true;
}
}
// 6.10
TEST CommentLines() {
// 6.10
TEST CommentLines() {
YAML::Node doc = YAML::Load(ex6_10);
YAML_ASSERT(doc.IsNull());
return true;
}
}
// 6.11
TEST MultiLineComments() {
// 6.11
TEST MultiLineComments() {
YAML::Node doc = YAML::Load(ex6_11);
YAML_ASSERT(doc.size() == 1);
YAML_ASSERT(doc["key"].as<std::string>() == "value");
return true;
}
}
// 6.12
TEST SeparationSpacesII() {
// 6.12
TEST SeparationSpacesII() {
YAML::Node doc = YAML::Load(ex6_12);
std::map<std::string, std::string> sammy;
......@@ -637,58 +662,60 @@ namespace Test
YAML_ASSERT(doc[sammy]["hr"].as<int>() == 65);
YAML_ASSERT(doc[sammy]["avg"].as<std::string>() == "0.278");
return true;
}
}
// 6.13
TEST ReservedDirectives() {
// 6.13
TEST ReservedDirectives() {
YAML::Node doc = YAML::Load(ex6_13);
YAML_ASSERT(doc.as<std::string>() == "foo");
return true;
}
}
// 6.14
TEST YAMLDirective() {
// 6.14
TEST YAMLDirective() {
YAML::Node doc = YAML::Load(ex6_14);
YAML_ASSERT(doc.as<std::string>() == "foo");
return true;
}
}
// 6.15
TEST InvalidRepeatedYAMLDirective() {
// 6.15
TEST InvalidRepeatedYAMLDirective() {
try {
YAML::Load(ex6_15);
} catch(const YAML::ParserException& e) {
}
catch (const YAML::ParserException& e) {
YAML_ASSERT(e.msg == YAML::ErrorMsg::REPEATED_YAML_DIRECTIVE);
return true;
}
return " No exception was thrown";
}
}
// 6.16
TEST TagDirective() {
// 6.16
TEST TagDirective() {
YAML::Node doc = YAML::Load(ex6_16);
YAML_ASSERT(doc.Tag() == "tag:yaml.org,2002:str");
YAML_ASSERT(doc.as<std::string>() == "foo");
return true;
}
}
// 6.17
TEST InvalidRepeatedTagDirective() {
// 6.17
TEST InvalidRepeatedTagDirective() {
try {
YAML::Load(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() {
std::vector<YAML::Node> docs = YAML::LoadAll(ex6_18);
YAML_ASSERT(docs.size() == 2);
......@@ -704,26 +731,26 @@ namespace Test
YAML_ASSERT(doc.as<std::string>() == "bar");
}
return true;
}
}
// 6.19
TEST SecondaryTagHandle() {
// 6.19
TEST SecondaryTagHandle() {
YAML::Node doc = YAML::Load(ex6_19);
YAML_ASSERT(doc.Tag() == "tag:example.com,2000:app/int");
YAML_ASSERT(doc.as<std::string>() == "1 - 3");
return true;
}
}
// 6.20
TEST TagHandles() {
// 6.20
TEST TagHandles() {
YAML::Node doc = YAML::Load(ex6_20);
YAML_ASSERT(doc.Tag() == "tag:example.com,2000:app/foo");
YAML_ASSERT(doc.as<std::string>() == "bar");
return true;
}
}
// 6.21
TEST LocalTagPrefix() {
// 6.21
TEST LocalTagPrefix() {
std::vector<YAML::Node> docs = YAML::LoadAll(ex6_21);
YAML_ASSERT(docs.size() == 2);
......@@ -739,56 +766,57 @@ namespace Test
YAML_ASSERT(doc.as<std::string>() == "green");
}
return true;
}
}
// 6.22
TEST GlobalTagPrefix() {
// 6.22
TEST GlobalTagPrefix() {
YAML::Node doc = YAML::Load(ex6_22);
YAML_ASSERT(doc.size() == 1);
YAML_ASSERT(doc[0].Tag() == "tag:example.com,2000:app/foo");
YAML_ASSERT(doc[0].as<std::string>() == "bar");
return true;
}
}
// 6.23
TEST NodeProperties() {
// 6.23
TEST NodeProperties() {
YAML::Node doc = YAML::Load(ex6_23);
YAML_ASSERT(doc.size() == 2);
for(YAML::const_iterator it=doc.begin();it!=doc.end();++it) {
if(it->first.as<std::string>() == "foo") {
for (YAML::const_iterator it = doc.begin(); it != doc.end(); ++it) {
if (it->first.as<std::string>() == "foo") {
YAML_ASSERT(it->first.Tag() == "tag:yaml.org,2002:str");
YAML_ASSERT(it->second.Tag() == "tag:yaml.org,2002:str");
YAML_ASSERT(it->second.as<std::string>() == "bar");
} else if(it->first.as<std::string>() == "baz") {
} else if (it->first.as<std::string>() == "baz") {
YAML_ASSERT(it->second.as<std::string>() == "foo");
} else
return " unknown key";
}
return true;
}
}
// 6.24
TEST VerbatimTags() {
// 6.24
TEST VerbatimTags() {
YAML::Node doc = YAML::Load(ex6_24);
YAML_ASSERT(doc.size() == 1);
for(YAML::const_iterator it=doc.begin();it!=doc.end();++it) {
for (YAML::const_iterator it = doc.begin(); it != doc.end(); ++it) {
YAML_ASSERT(it->first.Tag() == "tag:yaml.org,2002:str");
YAML_ASSERT(it->first.as<std::string>() == "foo");
YAML_ASSERT(it->second.Tag() == "!bar");
YAML_ASSERT(it->second.as<std::string>() == "baz");
}
return true;
}
}
// 6.25
TEST InvalidVerbatimTags() {
// 6.25
TEST InvalidVerbatimTags() {
YAML::Node doc = YAML::Load(ex6_25);
return " not implemented yet"; // TODO: check tags (but we probably will say these are valid, I think)
}
return " not implemented yet"; // TODO: check tags (but we probably will say
// these are valid, I think)
}
// 6.26
TEST TagShorthands() {
// 6.26
TEST TagShorthands() {
YAML::Node doc = YAML::Load(ex6_26);
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc[0].Tag() == "!local");
......@@ -798,47 +826,49 @@ namespace Test
YAML_ASSERT(doc[2].Tag() == "tag:example.com,2000:app/tag%21");
YAML_ASSERT(doc[2].as<std::string>() == "baz");
return true;
}
}
// 6.27
TEST InvalidTagShorthands() {
// 6.27
TEST InvalidTagShorthands() {
bool threw = false;
try {
YAML::Load(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";
YAML::Load(ex6_27b); // TODO: should we reject this one (since !h! is not declared)?
YAML::Load(
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() {
YAML::Node doc = YAML::Load(ex6_28);
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc[0].as<std::string>() == "12"); // TODO: check tags. How?
YAML_ASSERT(doc[1].as<int>() == 12);
YAML_ASSERT(doc[2].as<std::string>() == "12");
return true;
}
}
// 6.29
TEST NodeAnchors() {
// 6.29
TEST NodeAnchors() {
YAML::Node doc = YAML::Load(ex6_29);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc["First occurrence"].as<std::string>() == "Value");
YAML_ASSERT(doc["Second occurrence"].as<std::string>() == "Value");
return true;
}
}
// 7.1
TEST AliasNodes() {
// 7.1
TEST AliasNodes() {
YAML::Node doc = YAML::Load(ex7_1);
YAML_ASSERT(doc.size() == 4);
YAML_ASSERT(doc["First occurrence"].as<std::string>() == "Foo");
......@@ -846,84 +876,89 @@ namespace Test
YAML_ASSERT(doc["Override anchor"].as<std::string>() == "Bar");
YAML_ASSERT(doc["Reuse anchor"].as<std::string>() == "Bar");
return true;
}
}
// 7.2
TEST EmptyNodes() {
// 7.2
TEST EmptyNodes() {
YAML::Node doc = YAML::Load(ex7_2);
YAML_ASSERT(doc.size() == 2);
for(YAML::const_iterator it=doc.begin();it!=doc.end();++it) {
if(it->first.as<std::string>() == "foo") {
for (YAML::const_iterator it = doc.begin(); it != doc.end(); ++it) {
if (it->first.as<std::string>() == "foo") {
YAML_ASSERT(it->second.Tag() == "tag:yaml.org,2002:str");
YAML_ASSERT(it->second.as<std::string>() == "");
} else if(it->first.as<std::string>() == "") {
} else if (it->first.as<std::string>() == "") {
YAML_ASSERT(it->first.Tag() == "tag:yaml.org,2002:str");
YAML_ASSERT(it->second.as<std::string>() == "bar");
} else
return " unexpected key";
}
return true;
}
}
// 7.3
TEST CompletelyEmptyNodes() {
// 7.3
TEST CompletelyEmptyNodes() {
YAML::Node doc = YAML::Load(ex7_3);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc["foo"].IsNull());
YAML_ASSERT(doc[YAML::Null].as<std::string>() == "bar");
return true;
}
}
// 7.4
TEST DoubleQuotedImplicitKeys() {
// 7.4
TEST DoubleQuotedImplicitKeys() {
YAML::Node doc = YAML::Load(ex7_4);
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"].as<std::string>() == "value");
YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"]
.as<std::string>() == "value");
return true;
}
}
// 7.5
TEST DoubleQuotedLineBreaks() {
// 7.5
TEST DoubleQuotedLineBreaks() {
YAML::Node doc = YAML::Load(ex7_5);
YAML_ASSERT(doc.as<std::string>() == "folded to a space,\nto a line feed, or \t \tnon-content");
YAML_ASSERT(doc.as<std::string>() ==
"folded to a space,\nto a line feed, or \t \tnon-content");
return true;
}
}
// 7.6
TEST DoubleQuotedLines() {
// 7.6
TEST DoubleQuotedLines() {
YAML::Node doc = YAML::Load(ex7_6);
YAML_ASSERT(doc.as<std::string>() == " 1st non-empty\n2nd non-empty 3rd non-empty ");
YAML_ASSERT(doc.as<std::string>() ==
" 1st non-empty\n2nd non-empty 3rd non-empty ");
return true;
}
}
// 7.7
TEST SingleQuotedCharacters() {
// 7.7
TEST SingleQuotedCharacters() {
YAML::Node doc = YAML::Load(ex7_7);
YAML_ASSERT(doc.as<std::string>() == "here's to \"quotes\"");
return true;
}
}
// 7.8
TEST SingleQuotedImplicitKeys() {
// 7.8
TEST SingleQuotedImplicitKeys() {
YAML::Node doc = YAML::Load(ex7_8);
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"].as<std::string>() == "value");
YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"]
.as<std::string>() == "value");
return true;
}
}
// 7.9
TEST SingleQuotedLines() {
// 7.9
TEST SingleQuotedLines() {
YAML::Node doc = YAML::Load(ex7_9);
YAML_ASSERT(doc.as<std::string>() == " 1st non-empty\n2nd non-empty 3rd non-empty ");
YAML_ASSERT(doc.as<std::string>() ==
" 1st non-empty\n2nd non-empty 3rd non-empty ");
return true;
}
}
// 7.10
TEST PlainCharacters() {
// 7.10
TEST PlainCharacters() {
YAML::Node doc = YAML::Load(ex7_10);
YAML_ASSERT(doc.size() == 6);
YAML_ASSERT(doc[0].as<std::string>() == "::vector");
......@@ -938,27 +973,29 @@ namespace Test
YAML_ASSERT(doc[5][3].as<int>() == -123);
YAML_ASSERT(doc[5][4].as<std::string>() == "http://example.com/foo#bar");
return true;
}
}
// 7.11
TEST PlainImplicitKeys() {
// 7.11
TEST PlainImplicitKeys() {
YAML::Node doc = YAML::Load(ex7_11);
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"].as<std::string>() == "value");
YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"]
.as<std::string>() == "value");
return true;
}
}
// 7.12
TEST PlainLines() {
// 7.12
TEST PlainLines() {
YAML::Node doc = YAML::Load(ex7_12);
YAML_ASSERT(doc.as<std::string>() == "1st non-empty\n2nd non-empty 3rd non-empty");
YAML_ASSERT(doc.as<std::string>() ==
"1st non-empty\n2nd non-empty 3rd non-empty");
return true;
}
}
// 7.13
TEST FlowSequence() {
// 7.13
TEST FlowSequence() {
YAML::Node doc = YAML::Load(ex7_13);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc[0].size() == 2);
......@@ -968,10 +1005,10 @@ namespace Test
YAML_ASSERT(doc[1][0].as<std::string>() == "three");
YAML_ASSERT(doc[1][1].as<std::string>() == "four");
return true;
}
}
// 7.14
TEST FlowSequenceEntries() {
// 7.14
TEST FlowSequenceEntries() {
YAML::Node doc = YAML::Load(ex7_14);
YAML_ASSERT(doc.size() == 5);
YAML_ASSERT(doc[0].as<std::string>() == "double quoted");
......@@ -982,10 +1019,10 @@ namespace Test
YAML_ASSERT(doc[4].size() == 1);
YAML_ASSERT(doc[4]["single"].as<std::string>() == "pair");
return true;
}
}
// 7.15
TEST FlowMappings() {
// 7.15
TEST FlowMappings() {
YAML::Node doc = YAML::Load(ex7_15);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc[0].size() == 2);
......@@ -995,20 +1032,20 @@ namespace Test
YAML_ASSERT(doc[1]["five"].as<std::string>() == "six");
YAML_ASSERT(doc[1]["seven"].as<std::string>() == "eight");
return true;
}
}
// 7.16
TEST FlowMappingEntries() {
// 7.16
TEST FlowMappingEntries() {
YAML::Node doc = YAML::Load(ex7_16);
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc["explicit"].as<std::string>() == "entry");
YAML_ASSERT(doc["implicit"].as<std::string>() == "entry");
YAML_ASSERT(doc[YAML::Null].IsNull());
return true;
}
}
// 7.17
TEST FlowMappingSeparateValues() {
// 7.17
TEST FlowMappingSeparateValues() {
YAML::Node doc = YAML::Load(ex7_17);
YAML_ASSERT(doc.size() == 4);
YAML_ASSERT(doc["unquoted"].as<std::string>() == "separate");
......@@ -1016,38 +1053,38 @@ namespace Test
YAML_ASSERT(doc["omitted value"].IsNull());
YAML_ASSERT(doc[YAML::Null].as<std::string>() == "omitted key");
return true;
}
}
// 7.18
TEST FlowMappingAdjacentValues() {
// 7.18
TEST FlowMappingAdjacentValues() {
YAML::Node doc = YAML::Load(ex7_18);
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc["adjacent"].as<std::string>() == "value");
YAML_ASSERT(doc["readable"].as<std::string>() == "value");
YAML_ASSERT(doc["empty"].IsNull());
return true;
}
}
// 7.19
TEST SinglePairFlowMappings() {
// 7.19
TEST SinglePairFlowMappings() {
YAML::Node doc = YAML::Load(ex7_19);
YAML_ASSERT(doc.size() == 1);
YAML_ASSERT(doc[0].size() == 1);
YAML_ASSERT(doc[0]["foo"].as<std::string>() == "bar");
return true;
}
}
// 7.20
TEST SinglePairExplicitEntry() {
// 7.20
TEST SinglePairExplicitEntry() {
YAML::Node doc = YAML::Load(ex7_20);
YAML_ASSERT(doc.size() == 1);
YAML_ASSERT(doc[0].size() == 1);
YAML_ASSERT(doc[0]["foo bar"].as<std::string>() == "baz");
return true;
}
}
// 7.21
TEST SinglePairImplicitEntries() {
// 7.21
TEST SinglePairImplicitEntries() {
YAML::Node doc = YAML::Load(ex7_21);
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc[0].size() == 1);
......@@ -1063,23 +1100,24 @@ namespace Test
key["JSON"] = "like";
YAML_ASSERT(doc[2][0][key].as<std::string>() == "adjacent");
return true;
}
}
// 7.22
TEST InvalidImplicitKeys() {
// 7.22
TEST InvalidImplicitKeys() {
try {
YAML::Load(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() {
YAML::Node doc = YAML::Load(ex7_23);
YAML_ASSERT(doc.size() == 5);
YAML_ASSERT(doc[0].size() == 2);
......@@ -1091,10 +1129,10 @@ namespace Test
YAML_ASSERT(doc[3].as<char>() == 'b');
YAML_ASSERT(doc[4].as<std::string>() == "c");
return true;
}
}
// 7.24
TEST FlowNodes() {
// 7.24
TEST FlowNodes() {
YAML::Node doc = YAML::Load(ex7_24);
YAML_ASSERT(doc.size() == 5);
YAML_ASSERT(doc[0].Tag() == "tag:yaml.org,2002:str");
......@@ -1105,10 +1143,10 @@ namespace Test
YAML_ASSERT(doc[4].Tag() == "tag:yaml.org,2002:str");
YAML_ASSERT(doc[4].as<std::string>() == "");
return true;
}
}
// 8.1
TEST BlockScalarHeader() {
// 8.1
TEST BlockScalarHeader() {
YAML::Node doc = YAML::Load(ex8_1);
YAML_ASSERT(doc.size() == 4);
YAML_ASSERT(doc[0].as<std::string>() == "literal\n");
......@@ -1116,10 +1154,10 @@ namespace Test
YAML_ASSERT(doc[2].as<std::string>() == "keep\n\n");
YAML_ASSERT(doc[3].as<std::string>() == " strip");
return true;
}
}
// 8.2
TEST BlockIndentationHeader() {
// 8.2
TEST BlockIndentationHeader() {
YAML::Node doc = YAML::Load(ex8_2);
YAML_ASSERT(doc.size() == 4);
YAML_ASSERT(doc[0].as<std::string>() == "detected\n");
......@@ -1127,139 +1165,157 @@ namespace Test
YAML_ASSERT(doc[2].as<std::string>() == " explicit\n");
YAML_ASSERT(doc[3].as<std::string>() == "\t\ndetected\n");
return true;
}
}
// 8.3
TEST InvalidBlockScalarIndentationIndicators() {
// 8.3
TEST InvalidBlockScalarIndentationIndicators() {
{
bool threw = false;
try {
YAML::Load(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 {
YAML::Load(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 {
YAML::Load(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() {
YAML::Node doc = YAML::Load(ex8_4);
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc["strip"].as<std::string>() == "text");
YAML_ASSERT(doc["clip"].as<std::string>() == "text\n");
YAML_ASSERT(doc["keep"].as<std::string>() == "text\n");
return true;
}
}
// 8.5
TEST ChompingTrailingLines() {
// 8.5
TEST ChompingTrailingLines() {
YAML::Node doc = YAML::Load(ex8_5);
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc["strip"].as<std::string>() == "# text");
YAML_ASSERT(doc["clip"].as<std::string>() == "# text\n");
YAML_ASSERT(doc["keep"].as<std::string>() == "# text\n"); // Note: I believe this is a bug in the YAML spec - it should be "# text\n\n"
YAML_ASSERT(doc["keep"].as<std::string>() == "# text\n"); // Note: I believe
// this is a bug in
// the YAML spec -
// it should be "#
// text\n\n"
return true;
}
}
// 8.6
TEST EmptyScalarChomping() {
// 8.6
TEST EmptyScalarChomping() {
YAML::Node doc = YAML::Load(ex8_6);
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc["strip"].as<std::string>() == "");
YAML_ASSERT(doc["clip"].as<std::string>() == "");
YAML_ASSERT(doc["keep"].as<std::string>() == "\n");
return true;
}
}
// 8.7
TEST LiteralScalar() {
// 8.7
TEST LiteralScalar() {
YAML::Node doc = YAML::Load(ex8_7);
YAML_ASSERT(doc.as<std::string>() == "literal\n\ttext\n");
return true;
}
}
// 8.8
TEST LiteralContent() {
// 8.8
TEST LiteralContent() {
YAML::Node doc = YAML::Load(ex8_8);
YAML_ASSERT(doc.as<std::string>() == "\n\nliteral\n \n\ntext\n");
return true;
}
}
// 8.9
TEST FoldedScalar() {
// 8.9
TEST FoldedScalar() {
YAML::Node doc = YAML::Load(ex8_9);
YAML_ASSERT(doc.as<std::string>() == "folded text\n");
return true;
}
}
// 8.10
TEST FoldedLines() {
// 8.10
TEST FoldedLines() {
YAML::Node doc = YAML::Load(ex8_10);
YAML_ASSERT(doc.as<std::string>() == "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n");
YAML_ASSERT(doc.as<std::string>() ==
"\nfolded line\nnext line\n * bullet\n\n * list\n * "
"lines\n\nlast line\n");
return true;
}
}
// 8.11
TEST MoreIndentedLines() {
// 8.11
TEST MoreIndentedLines() {
YAML::Node doc = YAML::Load(ex8_11);
YAML_ASSERT(doc.as<std::string>() == "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n");
YAML_ASSERT(doc.as<std::string>() ==
"\nfolded line\nnext line\n * bullet\n\n * list\n * "
"lines\n\nlast line\n");
return true;
}
}
// 8.12
TEST EmptySeparationLines() {
// 8.12
TEST EmptySeparationLines() {
YAML::Node doc = YAML::Load(ex8_12);
YAML_ASSERT(doc.as<std::string>() == "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n");
YAML_ASSERT(doc.as<std::string>() ==
"\nfolded line\nnext line\n * bullet\n\n * list\n * "
"lines\n\nlast line\n");
return true;
}
}
// 8.13
TEST FinalEmptyLines() {
// 8.13
TEST FinalEmptyLines() {
YAML::Node doc = YAML::Load(ex8_13);
YAML_ASSERT(doc.as<std::string>() == "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n");
YAML_ASSERT(doc.as<std::string>() ==
"\nfolded line\nnext line\n * bullet\n\n * list\n * "
"lines\n\nlast line\n");
return true;
}
}
// 8.14
TEST BlockSequence() {
// 8.14
TEST BlockSequence() {
YAML::Node doc = YAML::Load(ex8_14);
YAML_ASSERT(doc.size() == 1);
YAML_ASSERT(doc["block sequence"].size() == 2);
......@@ -1267,10 +1323,10 @@ namespace Test
YAML_ASSERT(doc["block sequence"][1].size() == 1);
YAML_ASSERT(doc["block sequence"][1]["two"].as<std::string>() == "three");
return true;
}
}
// 8.15
TEST BlockSequenceEntryTypes() {
// 8.15
TEST BlockSequenceEntryTypes() {
YAML::Node doc = YAML::Load(ex8_15);
YAML_ASSERT(doc.size() == 4);
YAML_ASSERT(doc[0].IsNull());
......@@ -1281,19 +1337,19 @@ namespace Test
YAML_ASSERT(doc[3].size() == 1);
YAML_ASSERT(doc[3]["one"].as<std::string>() == "two");
return true;
}
}
// 8.16
TEST BlockMappings() {
// 8.16
TEST BlockMappings() {
YAML::Node doc = YAML::Load(ex8_16);
YAML_ASSERT(doc.size() == 1);
YAML_ASSERT(doc["block mapping"].size() == 1);
YAML_ASSERT(doc["block mapping"]["key"].as<std::string>() == "value");
return true;
}
}
// 8.17
TEST ExplicitBlockMappingEntries() {
// 8.17
TEST ExplicitBlockMappingEntries() {
YAML::Node doc = YAML::Load(ex8_17);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc["explicit key"].IsNull());
......@@ -1301,10 +1357,10 @@ namespace Test
YAML_ASSERT(doc["block key\n"][0].as<std::string>() == "one");
YAML_ASSERT(doc["block key\n"][1].as<std::string>() == "two");
return true;
}
}
// 8.18
TEST ImplicitBlockMappingEntries() {
// 8.18
TEST ImplicitBlockMappingEntries() {
YAML::Node doc = YAML::Load(ex8_18);
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc["plain key"].as<std::string>() == "in-line value");
......@@ -1312,10 +1368,10 @@ namespace Test
YAML_ASSERT(doc["quoted key"].size() == 1);
YAML_ASSERT(doc["quoted key"][0].as<std::string>() == "entry");
return true;
}
}
// 8.19
TEST CompactBlockMappings() {
// 8.19
TEST CompactBlockMappings() {
YAML::Node doc = YAML::Load(ex8_19);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc[0].size() == 1);
......@@ -1326,10 +1382,10 @@ namespace Test
YAML_ASSERT(doc[1][key].size() == 1);
YAML_ASSERT(doc[1][key]["moon"].as<std::string>() == "white");
return true;
}
}
// 8.20
TEST BlockNodeTypes() {
// 8.20
TEST BlockNodeTypes() {
YAML::Node doc = YAML::Load(ex8_20);
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc[0].as<std::string>() == "flow in block");
......@@ -1337,20 +1393,24 @@ namespace Test
YAML_ASSERT(doc[2].size() == 1);
YAML_ASSERT(doc[2]["foo"].as<std::string>() == "bar");
return true;
}
}
// 8.21
TEST BlockScalarNodes() {
// 8.21
TEST BlockScalarNodes() {
YAML::Node doc = YAML::Load(ex8_21);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc["literal"].as<std::string>() == "value"); // Note: I believe this is a bug in the YAML spec - it should be "value\n"
YAML_ASSERT(doc["literal"].as<std::string>() == "value"); // Note: I believe
// this is a bug in
// the YAML spec -
// it should be
// "value\n"
YAML_ASSERT(doc["folded"].as<std::string>() == "value");
YAML_ASSERT(doc["folded"].Tag() == "!foo");
return true;
}
}
// 8.22
TEST BlockCollectionNodes() {
// 8.22
TEST BlockCollectionNodes() {
YAML::Node doc = YAML::Load(ex8_22);
YAML_ASSERT(doc.size() == 2);
YAML_ASSERT(doc["sequence"].size() == 2);
......@@ -1360,6 +1420,6 @@ namespace Test
YAML_ASSERT(doc["mapping"].size() == 1);
YAML_ASSERT(doc["mapping"]["foo"].as<std::string>() == "bar");
return true;
}
}
}
}
}
#ifndef NODETESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODETESTS_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 RunNodeTests();
bool RunNodeTests();
}
#endif // NODETESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A6666
......@@ -9,25 +9,22 @@
#include <vector>
#include <iostream>
namespace Test
{
void RunAll()
{
namespace Test {
void RunAll() {
bool passed = true;
if(!RunParserTests())
if (!RunParserTests())
passed = false;
if(!RunEmitterTests())
if (!RunEmitterTests())
passed = false;
if(!RunSpecTests())
if (!RunSpecTests())
passed = false;
if(!RunNodeTests())
if (!RunNodeTests())
passed = false;
if(passed)
if (passed)
std::cout << "All tests passed!\n";
}
}
}
......@@ -9,7 +9,7 @@ struct Params {
std::string fileName;
};
Params ParseArgs(int argc, char **argv) {
Params ParseArgs(int argc, char** argv) {
Params p;
std::vector<std::string> args(argv + 1, argv + argc);
......@@ -17,38 +17,39 @@ Params ParseArgs(int argc, char **argv) {
return p;
}
class NullEventHandler: public YAML::EventHandler
{
public:
class NullEventHandler : public YAML::EventHandler {
public:
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 parse(std::istream& input)
{
void parse(std::istream& input) {
try {
YAML::Node doc = YAML::Load(input);
std::cout << doc << "\n";
} catch(const YAML::Exception& e) {
}
catch (const YAML::Exception& e) {
std::cerr << e.what() << "\n";
}
}
int main(int argc, char **argv)
{
int main(int argc, char** argv) {
Params p = ParseArgs(argc, argv);
if(argc > 1) {
if (argc > 1) {
std::ifstream fin;
fin.open(argv[1]);
parse(fin);
......
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