From 90f48fd0350e95f3261caebbc46b7bbe7c61c1df Mon Sep 17 00:00:00 2001 From: beder Date: Fri, 20 Jan 2012 23:36:08 -0600 Subject: [PATCH] Began new-api branch, and removed all traces of the old api from this branch --- CMakeLists.txt | 34 +- include/yaml-cpp/old-api/aliasmanager.h | 34 - include/yaml-cpp/old-api/conversion.h | 75 -- include/yaml-cpp/old-api/iterator.h | 40 - include/yaml-cpp/old-api/ltnode.h | 18 - include/yaml-cpp/old-api/node.h | 135 --- include/yaml-cpp/old-api/nodeimpl.h | 85 -- include/yaml-cpp/old-api/nodereadimpl.h | 86 -- include/yaml-cpp/old-api/nodeutil.h | 62 - include/yaml-cpp/old-api/stlnode.h | 38 - include/yaml-cpp/yaml.h.cmake | 34 - src/null.cpp | 11 - src/old-api/aliasmanager.cpp | 29 - src/old-api/conversion.cpp | 89 -- src/old-api/iterator.cpp | 103 -- src/old-api/iterpriv.h | 33 - src/old-api/node.cpp | 269 ----- src/old-api/nodebuilder.cpp | 145 --- src/old-api/nodebuilder.h | 61 - src/old-api/nodeownership.cpp | 31 - src/old-api/nodeownership.h | 39 - src/parser.cpp | 16 - test/CMakeLists.txt | 7 +- test/emittertests.cpp | 8 - test/old-api/parsertests.cpp | 1221 ------------------- test/old-api/spectests.cpp | 1456 ----------------------- test/tests.cpp | 4 +- util/parse.cpp | 10 - 28 files changed, 9 insertions(+), 4164 deletions(-) delete mode 100644 include/yaml-cpp/old-api/aliasmanager.h delete mode 100644 include/yaml-cpp/old-api/conversion.h delete mode 100644 include/yaml-cpp/old-api/iterator.h delete mode 100644 include/yaml-cpp/old-api/ltnode.h delete mode 100644 include/yaml-cpp/old-api/node.h delete mode 100644 include/yaml-cpp/old-api/nodeimpl.h delete mode 100644 include/yaml-cpp/old-api/nodereadimpl.h delete mode 100644 include/yaml-cpp/old-api/nodeutil.h delete mode 100644 include/yaml-cpp/old-api/stlnode.h delete mode 100644 include/yaml-cpp/yaml.h.cmake delete mode 100644 src/old-api/aliasmanager.cpp delete mode 100644 src/old-api/conversion.cpp delete mode 100644 src/old-api/iterator.cpp delete mode 100644 src/old-api/iterpriv.h delete mode 100644 src/old-api/node.cpp delete mode 100644 src/old-api/nodebuilder.cpp delete mode 100644 src/old-api/nodebuilder.h delete mode 100644 src/old-api/nodeownership.cpp delete mode 100644 src/old-api/nodeownership.h delete mode 100644 test/old-api/parsertests.cpp delete mode 100644 test/old-api/spectests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 16d2931..21e4fd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,8 +22,8 @@ include(CheckCXXCompilerFlag) project(YAML_CPP) set(YAML_CPP_VERSION_MAJOR "0") -set(YAML_CPP_VERSION_MINOR "2") -set(YAML_CPP_VERSION_PATCH "7") +set(YAML_CPP_VERSION_MINOR "5") +set(YAML_CPP_VERSION_PATCH "0") set(YAML_CPP_VERSION "${YAML_CPP_VERSION_MAJOR}.${YAML_CPP_VERSION_MINOR}.${YAML_CPP_VERSION_PATCH}") enable_testing() @@ -35,7 +35,6 @@ enable_testing() ## Project stuff option(YAML_CPP_BUILD_TOOLS "Enable testing and parse tools" ON) option(YAML_CPP_BUILD_CONTRIB "Enable contrib stuff in library" ON) -option(YAML_CPP_BUILD_OLD_API "Enable building the old API" ON) ## Build options # --> General @@ -52,15 +51,6 @@ option(APPLE_UNIVERSAL_BIN "Apple: Build universal binary" OFF) option(MSVC_SHARED_RT "MSVC: Build with shared runtime libs (/MD)" ON) option(MSVC_STHREADED_RT "MSVC: Build with single-threaded static runtime libs (/ML until VS .NET 2003)" OFF) -### -### Configure the main header -### -if(YAML_CPP_BUILD_OLD_API) - set(API_DEFINE "#define YAML_CPP_OLD_API") -endif() - -configure_file(${YAML_CPP_SOURCE_DIR}/include/yaml-cpp/yaml.h.cmake ${YAML_CPP_SOURCE_DIR}/include/yaml-cpp/yaml.h @ONLY) - ### ### Sources, headers, directories and libs ### @@ -71,31 +61,21 @@ file(GLOB new_api_sources "src/node/[a-zA-Z]*.cpp" "src/node/detail/[a-zA-Z]*.cpp" ) -file(GLOB old_api_sources "src/old-api/[a-zA-Z]*.cpp") file(GLOB common_public_headers "include/yaml-cpp/[a-zA-Z]*.h") file(GLOB new_api_public_headers "include/yaml-cpp/node/[a-zA-Z]*.h" "include/yaml-cpp/node/detail/[a-zA-Z]*.h" ) -file(GLOB old_api_public_headers "include/yaml-cpp/old-api/[a-zA-Z]*.h") file(GLOB common_private_headers "src/[a-zA-Z]*.h") file(GLOB new_api_private_headers "src/node/[a-zA-Z]*.h") -file(GLOB old_api_private_headers "src/old-api/[a-zA-Z]*.h") -if(YAML_CPP_BUILD_OLD_API) - list(APPEND sources ${common_sources} ${old_api_sources}) - list(APPEND public_headers ${common_public_headers} ${old_api_public_headers}) - list(APPEND private_headers ${common_private_headers} ${old_api_private_headers}) - add_definitions(-DYAML_CPP_OLD_API) -else() - find_package(Boost REQUIRED) - include_directories(${Boost_INCLUDE_DIRS}) - list(APPEND sources ${common_sources} ${new_api_sources}) - list(APPEND public_headers ${common_public_headers} ${new_api_public_headers}) - list(APPEND private_headers ${common_private_headers} ${new_api_private_headers}) -endif() +find_package(Boost REQUIRED) +include_directories(${Boost_INCLUDE_DIRS}) +list(APPEND sources ${common_sources} ${new_api_sources}) +list(APPEND public_headers ${common_public_headers} ${new_api_public_headers}) +list(APPEND private_headers ${common_private_headers} ${new_api_private_headers}) if(YAML_CPP_BUILD_CONTRIB) file(GLOB contrib_sources "src/contrib/[a-zA-Z]*.cpp") diff --git a/include/yaml-cpp/old-api/aliasmanager.h b/include/yaml-cpp/old-api/aliasmanager.h deleted file mode 100644 index e90c93d..0000000 --- a/include/yaml-cpp/old-api/aliasmanager.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef ALIASMANAGER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 -#define ALIASMANAGER_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 -#pragma once -#endif - -#include "yaml-cpp/anchor.h" -#include - -namespace YAML -{ - class Node; - - class AliasManager - { - public: - AliasManager(); - - void RegisterReference(const Node& node); - anchor_t LookupAnchor(const Node& node) const; - - private: - anchor_t _CreateNewAnchor(); - - private: - typedef std::map AnchorByIdentity; - AnchorByIdentity m_anchorByIdentity; - - anchor_t m_curAnchor; - }; -} - -#endif // ALIASMANAGER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/include/yaml-cpp/old-api/conversion.h b/include/yaml-cpp/old-api/conversion.h deleted file mode 100644 index 1b557b5..0000000 --- a/include/yaml-cpp/old-api/conversion.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef CONVERSION_H_62B23520_7C8E_11DE_8A39_0800200C9A66 -#define CONVERSION_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 -#pragma once -#endif - - -#include "yaml-cpp/null.h" -#include "yaml-cpp/traits.h" -#include -#include -#include - -namespace YAML -{ - // traits for conversion - - template - struct is_scalar_convertible { enum { value = is_numeric::value }; }; - - template<> struct is_scalar_convertible { enum { value = true }; }; - template<> struct is_scalar_convertible { enum { value = true }; }; - template<> struct is_scalar_convertible<_Null> { enum { value = true }; }; - - // actual conversion - - inline bool Convert(const std::string& input, std::string& output) { - output = input; - return true; - } - - YAML_CPP_API bool Convert(const std::string& input, bool& output); - YAML_CPP_API bool Convert(const std::string& input, _Null& output); - - inline bool IsInfinity(const std::string& input) { - return input == ".inf" || input == ".Inf" || input == ".INF" || input == "+.inf" || input == "+.Inf" || input == "+.INF"; - } - - inline bool IsNegativeInfinity(const std::string& input) { - return input == "-.inf" || input == "-.Inf" || input == "-.INF"; - } - - inline bool IsNaN(const std::string& input) { - return input == ".nan" || input == ".NaN" || input == ".NAN"; - } - - - template - inline bool Convert(const std::string& input, T& output, typename enable_if >::type * = 0) { - std::stringstream stream(input); - stream.unsetf(std::ios::dec); - if((stream >> output) && (stream >> std::ws).eof()) - return true; - - if(std::numeric_limits::has_infinity) { - if(IsInfinity(input)) { - output = std::numeric_limits::infinity(); - return true; - } else if(IsNegativeInfinity(input)) { - output = -std::numeric_limits::infinity(); - return true; - } - } - - if(std::numeric_limits::has_quiet_NaN && IsNaN(input)) { - output = std::numeric_limits::quiet_NaN(); - return true; - } - - return false; - } -} - -#endif // CONVERSION_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/include/yaml-cpp/old-api/iterator.h b/include/yaml-cpp/old-api/iterator.h deleted file mode 100644 index 400ee34..0000000 --- a/include/yaml-cpp/old-api/iterator.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 -#define ITERATOR_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 -#pragma once -#endif - -#include "yaml-cpp/dll.h" -#include - -namespace YAML -{ - class Node; - struct IterPriv; - - class YAML_CPP_API Iterator - { - public: - Iterator(); - Iterator(std::auto_ptr pData); - Iterator(const Iterator& rhs); - ~Iterator(); - - Iterator& operator = (const Iterator& rhs); - Iterator& operator ++ (); - Iterator operator ++ (int); - const Node& operator * () const; - const Node *operator -> () const; - const Node& first() const; - const Node& second() const; - - friend YAML_CPP_API bool operator == (const Iterator& it, const Iterator& jt); - friend YAML_CPP_API bool operator != (const Iterator& it, const Iterator& jt); - - private: - std::auto_ptr m_pData; - }; -} - -#endif // ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/include/yaml-cpp/old-api/ltnode.h b/include/yaml-cpp/old-api/ltnode.h deleted file mode 100644 index 30b4f95..0000000 --- a/include/yaml-cpp/old-api/ltnode.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef LTNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 -#define LTNODE_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 -#pragma once -#endif - - -namespace YAML -{ - class Node; - - struct ltnode { - bool operator()(const Node *pNode1, const Node *pNode2) const; - }; -} - -#endif // LTNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/include/yaml-cpp/old-api/node.h b/include/yaml-cpp/old-api/node.h deleted file mode 100644 index 607d9f0..0000000 --- a/include/yaml-cpp/old-api/node.h +++ /dev/null @@ -1,135 +0,0 @@ -#ifndef NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 -#define NODE_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 -#pragma once -#endif - - -#include "yaml-cpp/dll.h" -#include "yaml-cpp/exceptions.h" -#include "yaml-cpp/mark.h" -#include "yaml-cpp/noncopyable.h" -#include "yaml-cpp/old-api/conversion.h" -#include "yaml-cpp/old-api/iterator.h" -#include "yaml-cpp/old-api/ltnode.h" -#include -#include -#include -#include -#include - -namespace YAML -{ - class AliasManager; - class Content; - class NodeOwnership; - class Scanner; - class Emitter; - class EventHandler; - - struct NodeType { enum value { Null, Scalar, Sequence, Map }; }; - - class YAML_CPP_API Node: private noncopyable - { - public: - friend class NodeOwnership; - friend class NodeBuilder; - - Node(); - ~Node(); - - void Clear(); - std::auto_ptr Clone() const; - void EmitEvents(EventHandler& eventHandler) const; - void EmitEvents(AliasManager& am, EventHandler& eventHandler) const; - - NodeType::value Type() const { return m_type; } - bool IsAliased() const; - - // file location of start of this node - const Mark GetMark() const { return m_mark; } - - // accessors - Iterator begin() const; - Iterator end() const; - std::size_t size() const; - - // extraction of scalars - bool GetScalar(std::string& s) const; - - // we can specialize this for other values - template - bool Read(T& value) const; - - template - const T to() const; - - template - friend YAML_CPP_API typename enable_if >::type operator >> (const Node& node, T& value); - - // retrieval for maps and sequences - template - const Node *FindValue(const T& key) const; - - template - const Node& operator [] (const T& key) const; - - // specific to maps - const Node *FindValue(const char *key) const; - const Node *FindValue(char *key) const; - const Node& operator [] (const char *key) const; - const Node& operator [] (char *key) const; - - // for tags - const std::string& Tag() const { return m_tag; } - - // emitting - friend YAML_CPP_API Emitter& operator << (Emitter& out, const Node& node); - - // ordering - int Compare(const Node& rhs) const; - friend bool operator < (const Node& n1, const Node& n2); - - private: - explicit Node(NodeOwnership& owner); - Node& CreateNode(); - - void Init(NodeType::value type, const Mark& mark, const std::string& tag); - - void MarkAsAliased(); - void SetScalarData(const std::string& data); - void Append(Node& node); - void Insert(Node& key, Node& value); - - // helper for sequences - template friend struct _FindFromNodeAtIndex; - const Node *FindAtIndex(std::size_t i) const; - - // helper for maps - template - const Node& GetValue(const T& key) const; - - template - const Node *FindValueForKey(const T& key) const; - - private: - std::auto_ptr m_pOwnership; - - Mark m_mark; - std::string m_tag; - - typedef std::vector node_seq; - typedef std::map node_map; - - NodeType::value m_type; - std::string m_scalarData; - node_seq m_seqData; - node_map m_mapData; - }; -} - -#include "yaml-cpp/old-api/nodeimpl.h" -#include "yaml-cpp/old-api/nodereadimpl.h" - -#endif // NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/include/yaml-cpp/old-api/nodeimpl.h b/include/yaml-cpp/old-api/nodeimpl.h deleted file mode 100644 index 7534e04..0000000 --- a/include/yaml-cpp/old-api/nodeimpl.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 -#define NODEIMPL_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 -#pragma once -#endif - - -#include "yaml-cpp/old-api/nodeutil.h" -#include - -namespace YAML -{ - // implementation of templated things - template - inline const T Node::to() const { - T value; - *this >> value; - return value; - } - - template - inline typename enable_if >::type operator >> (const Node& node, T& value) { - if(!ConvertScalar(node, value)) - throw InvalidScalar(node.m_mark); - } - - template - inline const Node *Node::FindValue(const T& key) const { - switch(m_type) { - case NodeType::Null: - case NodeType::Scalar: - throw BadDereference(); - case NodeType::Sequence: - return FindFromNodeAtIndex(*this, key); - case NodeType::Map: - return FindValueForKey(key); - } - assert(false); - throw BadDereference(); - } - - template - inline const Node *Node::FindValueForKey(const T& key) const { - for(Iterator it=begin();it!=end();++it) { - T t; - if(it.first().Read(t)) { - if(key == t) - return &it.second(); - } - } - - return 0; - } - - template - inline const Node& Node::GetValue(const T& key) const { - if(const Node *pValue = FindValue(key)) - return *pValue; - throw MakeTypedKeyNotFound(m_mark, key); - } - - template - inline const Node& Node::operator [] (const T& key) const { - return GetValue(key); - } - - inline const Node *Node::FindValue(const char *key) const { - return FindValue(std::string(key)); - } - - inline const Node *Node::FindValue(char *key) const { - return FindValue(std::string(key)); - } - - inline const Node& Node::operator [] (const char *key) const { - return GetValue(std::string(key)); - } - - inline const Node& Node::operator [] (char *key) const { - return GetValue(std::string(key)); - } -} - -#endif // NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/include/yaml-cpp/old-api/nodereadimpl.h b/include/yaml-cpp/old-api/nodereadimpl.h deleted file mode 100644 index 6838dc5..0000000 --- a/include/yaml-cpp/old-api/nodereadimpl.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef NODEREADIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 -#define NODEREADIMPL_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 -#pragma once -#endif - - -namespace YAML -{ - // implementation for Node::Read - // (the goal is to call ConvertScalar if we can, and fall back to operator >> if not) - // thanks to litb from stackoverflow.com - // http://stackoverflow.com/questions/1386183/how-to-call-a-templated-function-if-it-exists-and-something-else-otherwise/1386390#1386390 - - // Note: this doesn't work on gcc 3.2, but does on gcc 3.4 and above. I'm not sure about 3.3. - -#if __GNUC__ && (__GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ <= 3)) - // trick doesn't work? Just fall back to ConvertScalar. - // This means that we can't use any user-defined types as keys in a map - template - inline bool Node::Read(T& value) const { - return ConvertScalar(*this, value); - } -#else - // usual case: the trick! - template - struct read_impl; - - // ConvertScalar available - template<> - struct read_impl { - template - static bool read(const Node& node, T& value) { - return ConvertScalar(node, value); - } - }; - - // ConvertScalar not available - template<> - struct read_impl { - template - static bool read(const Node& node, T& value) { - try { - node >> value; - } catch(const Exception&) { - return false; - } - return true; - } - }; - - namespace fallback { - // sizeof > 1 - struct flag { char c[2]; }; - flag Convert(...); - - int operator,(flag, flag); - - template - char operator,(flag, T const&); - - char operator,(int, flag); - int operator,(char, flag); - } - - template - inline bool Node::Read(T& value) const { - using namespace fallback; - - return read_impl::read(*this, value); - } -#endif // done with trick - - // the main conversion function - template - inline bool ConvertScalar(const Node& node, T& value) { - std::string scalar; - if(!node.GetScalar(scalar)) - return false; - - return Convert(scalar, value); - } -} - -#endif // NODEREADIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/include/yaml-cpp/old-api/nodeutil.h b/include/yaml-cpp/old-api/nodeutil.h deleted file mode 100644 index d0c01d2..0000000 --- a/include/yaml-cpp/old-api/nodeutil.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef NODEUTIL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 -#define NODEUTIL_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 -#pragma once -#endif - - -namespace YAML -{ - template - struct is_same_type { - enum { value = false }; - }; - - template - struct is_same_type { - enum { value = true }; - }; - - template - struct is_index_type_with_check { - enum { value = false }; - }; - - template <> struct is_index_type_with_check { enum { value = true }; }; - -#define MAKE_INDEX_TYPE(Type) \ - template <> struct is_index_type_with_check::value> { enum { value = true }; } - - MAKE_INDEX_TYPE(int); - MAKE_INDEX_TYPE(unsigned); - MAKE_INDEX_TYPE(short); - MAKE_INDEX_TYPE(unsigned short); - MAKE_INDEX_TYPE(long); - MAKE_INDEX_TYPE(unsigned long); - -#undef MAKE_INDEX_TYPE - - template - struct is_index_type: public is_index_type_with_check {}; - - // messing around with template stuff to get the right overload for operator [] for a sequence - template - struct _FindFromNodeAtIndex { - const Node *pRet; - _FindFromNodeAtIndex(const Node&, const T&): pRet(0) {} - }; - - template - struct _FindFromNodeAtIndex { - const Node *pRet; - _FindFromNodeAtIndex(const Node& node, const T& key): pRet(node.FindAtIndex(static_cast(key))) {} - }; - - template - inline const Node *FindFromNodeAtIndex(const Node& node, const T& key) { - return _FindFromNodeAtIndex::value>(node, key).pRet; - } -} - -#endif // NODEUTIL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/include/yaml-cpp/old-api/stlnode.h b/include/yaml-cpp/old-api/stlnode.h deleted file mode 100644 index 40d4ae7..0000000 --- a/include/yaml-cpp/old-api/stlnode.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef STLNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 -#define STLNODE_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 -#pragma once -#endif - - -#include -#include - -namespace YAML -{ - template - void operator >> (const Node& node, std::vector& v) - { - v.clear(); - v.resize(node.size()); - for(unsigned i=0;i> v[i]; - } - - - template - void operator >> (const Node& node, std::map& m) - { - m.clear(); - for(Iterator it=node.begin();it!=node.end();++it) { - K k; - V v; - it.first() >> k; - it.second() >> v; - m[k] = v; - } - } -} - -#endif // STLNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/include/yaml-cpp/yaml.h.cmake b/include/yaml-cpp/yaml.h.cmake deleted file mode 100644 index 1c93755..0000000 --- a/include/yaml-cpp/yaml.h.cmake +++ /dev/null @@ -1,34 +0,0 @@ -#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 -#pragma once -#endif - -#undef YAML_CPP_OLD_API -@API_DEFINE@ - -#include "yaml-cpp/parser.h" -#include "yaml-cpp/emitter.h" -#include "yaml-cpp/stlemitter.h" -#include "yaml-cpp/exceptions.h" - -#ifdef YAML_CPP_OLD_API - -#include "yaml-cpp/old-api/node.h" -#include "yaml-cpp/old-api/stlnode.h" -#include "yaml-cpp/old-api/iterator.h" - -#else - -#include "yaml-cpp/node/node.h" -#include "yaml-cpp/node/impl.h" -#include "yaml-cpp/node/convert.h" -#include "yaml-cpp/node/iterator.h" -#include "yaml-cpp/node/detail/impl.h" -#include "yaml-cpp/node/parse.h" -#include "yaml-cpp/node/emit.h" - -#endif // YAML_CPP_OLD_API - -#endif // YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/src/null.cpp b/src/null.cpp index 61a634b..37f3197 100644 --- a/src/null.cpp +++ b/src/null.cpp @@ -1,17 +1,6 @@ #include "yaml-cpp/null.h" -#ifdef YAML_CPP_OLD_API -#include "yaml-cpp/old-api/node.h" -#endif - namespace YAML { _Null Null; - -#ifdef YAML_CPP_OLD_API - bool IsNull(const Node& node) - { - return node.Read(Null); - } -#endif } diff --git a/src/old-api/aliasmanager.cpp b/src/old-api/aliasmanager.cpp deleted file mode 100644 index f400612..0000000 --- a/src/old-api/aliasmanager.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "yaml-cpp/old-api/aliasmanager.h" -#include "yaml-cpp/old-api/node.h" -#include -#include - -namespace YAML -{ - AliasManager::AliasManager(): m_curAnchor(0) - { - } - - void AliasManager::RegisterReference(const Node& node) - { - m_anchorByIdentity.insert(std::make_pair(&node, _CreateNewAnchor())); - } - - anchor_t AliasManager::LookupAnchor(const Node& node) const - { - AnchorByIdentity::const_iterator it = m_anchorByIdentity.find(&node); - if(it == m_anchorByIdentity.end()) - return 0; - return it->second; - } - - anchor_t AliasManager::_CreateNewAnchor() - { - return ++m_curAnchor; - } -} diff --git a/src/old-api/conversion.cpp b/src/old-api/conversion.cpp deleted file mode 100644 index 0c67dfd..0000000 --- a/src/old-api/conversion.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "yaml-cpp/old-api/conversion.h" -#include - -//////////////////////////////////////////////////////////////// -// Specializations for converting a string to specific types - -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 s(str); - std::transform(s.begin(), s.end(), s.begin(), ToLower); - return s; - } - - template - bool IsEntirely(const std::string& str, T func) - { - for(std::size_t i=0;i pData): m_pData(pData) - { - } - - Iterator::Iterator(const Iterator& rhs): m_pData(new IterPriv(*rhs.m_pData)) - { - } - - Iterator& Iterator::operator = (const Iterator& rhs) - { - if(this == &rhs) - return *this; - - m_pData.reset(new IterPriv(*rhs.m_pData)); - return *this; - } - - Iterator::~Iterator() - { - } - - Iterator& Iterator::operator ++ () - { - if(m_pData->type == IterPriv::IT_SEQ) - ++m_pData->seqIter; - else if(m_pData->type == IterPriv::IT_MAP) - ++m_pData->mapIter; - - return *this; - } - - Iterator Iterator::operator ++ (int) - { - Iterator temp = *this; - - if(m_pData->type == IterPriv::IT_SEQ) - ++m_pData->seqIter; - else if(m_pData->type == IterPriv::IT_MAP) - ++m_pData->mapIter; - - return temp; - } - - const Node& Iterator::operator * () const - { - if(m_pData->type == IterPriv::IT_SEQ) - return **m_pData->seqIter; - - throw BadDereference(); - } - - const Node *Iterator::operator -> () const - { - if(m_pData->type == IterPriv::IT_SEQ) - return *m_pData->seqIter; - - throw BadDereference(); - } - - const Node& Iterator::first() const - { - if(m_pData->type == IterPriv::IT_MAP) - return *m_pData->mapIter->first; - - throw BadDereference(); - } - - const Node& Iterator::second() const - { - if(m_pData->type == IterPriv::IT_MAP) - return *m_pData->mapIter->second; - - throw BadDereference(); - } - - bool operator == (const Iterator& it, const Iterator& jt) - { - if(it.m_pData->type != jt.m_pData->type) - return false; - - if(it.m_pData->type == IterPriv::IT_SEQ) - return it.m_pData->seqIter == jt.m_pData->seqIter; - else if(it.m_pData->type == IterPriv::IT_MAP) - return it.m_pData->mapIter == jt.m_pData->mapIter; - - return true; - } - - bool operator != (const Iterator& it, const Iterator& jt) - { - return !(it == jt); - } -} diff --git a/src/old-api/iterpriv.h b/src/old-api/iterpriv.h deleted file mode 100644 index a1b07bc..0000000 --- a/src/old-api/iterpriv.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef ITERPRIV_H_62B23520_7C8E_11DE_8A39_0800200C9A66 -#define ITERPRIV_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 -#pragma once -#endif - - -#include "yaml-cpp/old-api/ltnode.h" -#include -#include - -namespace YAML -{ - class Node; - - // IterPriv - // . The implementation for iterators - essentially a union of sequence and map iterators. - struct IterPriv - { - IterPriv(): type(IT_NONE) {} - IterPriv(std::vector ::const_iterator it): type(IT_SEQ), seqIter(it) {} - IterPriv(std::map ::const_iterator it): type(IT_MAP), mapIter(it) {} - - enum ITER_TYPE { IT_NONE, IT_SEQ, IT_MAP }; - ITER_TYPE type; - - std::vector ::const_iterator seqIter; - std::map ::const_iterator mapIter; - }; -} - -#endif // ITERPRIV_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/src/old-api/node.cpp b/src/old-api/node.cpp deleted file mode 100644 index c7be61a..0000000 --- a/src/old-api/node.cpp +++ /dev/null @@ -1,269 +0,0 @@ -#include "yaml-cpp/old-api/node.h" -#include "yaml-cpp/old-api/aliasmanager.h" -#include "yaml-cpp/emitfromevents.h" -#include "yaml-cpp/emitter.h" -#include "yaml-cpp/eventhandler.h" -#include "old-api/iterpriv.h" -#include "old-api/nodebuilder.h" -#include "old-api/nodeownership.h" -#include "scanner.h" -#include "tag.h" -#include "token.h" -#include -#include - -namespace YAML -{ - bool ltnode::operator()(const Node *pNode1, const Node *pNode2) const { - return *pNode1 < *pNode2; - } - - Node::Node(): m_pOwnership(new NodeOwnership), m_type(NodeType::Null) - { - } - - Node::Node(NodeOwnership& owner): m_pOwnership(new NodeOwnership(&owner)), m_type(NodeType::Null) - { - } - - Node::~Node() - { - Clear(); - } - - void Node::Clear() - { - m_pOwnership.reset(new NodeOwnership); - m_type = NodeType::Null; - m_tag.clear(); - m_scalarData.clear(); - m_seqData.clear(); - m_mapData.clear(); - } - - bool Node::IsAliased() const - { - return m_pOwnership->IsAliased(*this); - } - - Node& Node::CreateNode() - { - return m_pOwnership->Create(); - } - - std::auto_ptr Node::Clone() const - { - std::auto_ptr pNode(new Node); - NodeBuilder nodeBuilder(*pNode); - EmitEvents(nodeBuilder); - return pNode; - } - - void Node::EmitEvents(EventHandler& eventHandler) const - { - eventHandler.OnDocumentStart(m_mark); - AliasManager am; - EmitEvents(am, eventHandler); - eventHandler.OnDocumentEnd(); - } - - void Node::EmitEvents(AliasManager& am, EventHandler& eventHandler) const - { - anchor_t anchor = NullAnchor; - if(IsAliased()) { - anchor = am.LookupAnchor(*this); - if(anchor) { - eventHandler.OnAlias(m_mark, anchor); - return; - } - - am.RegisterReference(*this); - anchor = am.LookupAnchor(*this); - } - - switch(m_type) { - case NodeType::Null: - eventHandler.OnNull(m_mark, anchor); - break; - case NodeType::Scalar: - eventHandler.OnScalar(m_mark, m_tag, anchor, m_scalarData); - break; - case NodeType::Sequence: - eventHandler.OnSequenceStart(m_mark, m_tag, anchor); - for(std::size_t i=0;iEmitEvents(am, eventHandler); - eventHandler.OnSequenceEnd(); - break; - case NodeType::Map: - eventHandler.OnMapStart(m_mark, m_tag, anchor); - for(node_map::const_iterator it=m_mapData.begin();it!=m_mapData.end();++it) { - it->first->EmitEvents(am, eventHandler); - it->second->EmitEvents(am, eventHandler); - } - eventHandler.OnMapEnd(); - break; - } - } - - void Node::Init(NodeType::value type, const Mark& mark, const std::string& tag) - { - Clear(); - m_mark = mark; - m_type = type; - m_tag = tag; - } - - void Node::MarkAsAliased() - { - m_pOwnership->MarkAsAliased(*this); - } - - void Node::SetScalarData(const std::string& data) - { - assert(m_type == NodeType::Scalar); // TODO: throw? - m_scalarData = data; - } - - void Node::Append(Node& node) - { - assert(m_type == NodeType::Sequence); // TODO: throw? - m_seqData.push_back(&node); - } - - void Node::Insert(Node& key, Node& value) - { - assert(m_type == NodeType::Map); // TODO: throw? - m_mapData[&key] = &value; - } - - // begin - // Returns an iterator to the beginning of this (sequence or map). - Iterator Node::begin() const - { - switch(m_type) { - case NodeType::Null: - case NodeType::Scalar: - return Iterator(); - case NodeType::Sequence: - return Iterator(std::auto_ptr(new IterPriv(m_seqData.begin()))); - case NodeType::Map: - return Iterator(std::auto_ptr(new IterPriv(m_mapData.begin()))); - } - - assert(false); - return Iterator(); - } - - // end - // . Returns an iterator to the end of this (sequence or map). - Iterator Node::end() const - { - switch(m_type) { - case NodeType::Null: - case NodeType::Scalar: - return Iterator(); - case NodeType::Sequence: - return Iterator(std::auto_ptr(new IterPriv(m_seqData.end()))); - case NodeType::Map: - return Iterator(std::auto_ptr(new IterPriv(m_mapData.end()))); - } - - assert(false); - return Iterator(); - } - - // size - // . Returns the size of a sequence or map node - // . Otherwise, returns zero. - std::size_t Node::size() const - { - switch(m_type) { - case NodeType::Null: - case NodeType::Scalar: - return 0; - case NodeType::Sequence: - return m_seqData.size(); - case NodeType::Map: - return m_mapData.size(); - } - - assert(false); - return 0; - } - - const Node *Node::FindAtIndex(std::size_t i) const - { - if(m_type == NodeType::Sequence) - return m_seqData[i]; - return 0; - } - - bool Node::GetScalar(std::string& s) const - { - switch(m_type) { - case NodeType::Null: - s = "~"; - return true; - case NodeType::Scalar: - s = m_scalarData; - return true; - case NodeType::Sequence: - case NodeType::Map: - return false; - } - - assert(false); - return false; - } - - Emitter& operator << (Emitter& out, const Node& node) - { - EmitFromEvents emitFromEvents(out); - node.EmitEvents(emitFromEvents); - return out; - } - - int Node::Compare(const Node& rhs) const - { - if(m_type != rhs.m_type) - return rhs.m_type - m_type; - - switch(m_type) { - case NodeType::Null: - return 0; - case NodeType::Scalar: - return m_scalarData.compare(rhs.m_scalarData); - case NodeType::Sequence: - if(m_seqData.size() < rhs.m_seqData.size()) - return 1; - else if(m_seqData.size() > rhs.m_seqData.size()) - return -1; - for(std::size_t i=0;iCompare(*rhs.m_seqData[i])) - return cmp; - return 0; - case NodeType::Map: - if(m_mapData.size() < rhs.m_mapData.size()) - return 1; - else if(m_mapData.size() > rhs.m_mapData.size()) - return -1; - node_map::const_iterator it = m_mapData.begin(); - node_map::const_iterator jt = rhs.m_mapData.begin(); - for(;it!=m_mapData.end() && jt!=rhs.m_mapData.end();it++, jt++) { - if(int cmp = it->first->Compare(*jt->first)) - return cmp; - if(int cmp = it->second->Compare(*jt->second)) - return cmp; - } - return 0; - } - - assert(false); - return 0; - } - - bool operator < (const Node& n1, const Node& n2) - { - return n1.Compare(n2) < 0; - } -} diff --git a/src/old-api/nodebuilder.cpp b/src/old-api/nodebuilder.cpp deleted file mode 100644 index f863d7c..0000000 --- a/src/old-api/nodebuilder.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#include "old-api/nodebuilder.h" -#include "yaml-cpp/mark.h" -#include "yaml-cpp/old-api/node.h" -#include - -namespace YAML -{ - NodeBuilder::NodeBuilder(Node& root): m_root(root), m_initializedRoot(false), m_finished(false) - { - m_root.Clear(); - m_anchors.push_back(0); // since the anchors start at 1 - } - - NodeBuilder::~NodeBuilder() - { - } - - void NodeBuilder::OnDocumentStart(const Mark&) - { - } - - void NodeBuilder::OnDocumentEnd() - { - assert(m_finished); - } - - void NodeBuilder::OnNull(const Mark& mark, anchor_t anchor) - { - Node& node = Push(anchor); - node.Init(NodeType::Null, mark, ""); - Pop(); - } - - void NodeBuilder::OnAlias(const Mark& /*mark*/, anchor_t anchor) - { - Node& node = *m_anchors[anchor]; - Insert(node); - node.MarkAsAliased(); - } - - void NodeBuilder::OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value) - { - Node& node = Push(anchor); - node.Init(NodeType::Scalar, mark, tag); - node.SetScalarData(value); - Pop(); - } - - void NodeBuilder::OnSequenceStart(const Mark& mark, const std::string& tag, anchor_t anchor) - { - Node& node = Push(anchor); - node.Init(NodeType::Sequence, mark, tag); - } - - void NodeBuilder::OnSequenceEnd() - { - Pop(); - } - - void NodeBuilder::OnMapStart(const Mark& mark, const std::string& tag, anchor_t anchor) - { - Node& node = Push(anchor); - node.Init(NodeType::Map, mark, tag); - m_didPushKey.push(false); - } - - void NodeBuilder::OnMapEnd() - { - m_didPushKey.pop(); - Pop(); - } - - Node& NodeBuilder::Push(anchor_t anchor) - { - Node& node = Push(); - RegisterAnchor(anchor, node); - return node; - } - - Node& NodeBuilder::Push() - { - if(!m_initializedRoot) { - m_initializedRoot = true; - return m_root; - } - - Node& node = m_root.CreateNode(); - m_stack.push(&node); - return node; - } - - Node& NodeBuilder::Top() - { - return m_stack.empty() ? m_root : *m_stack.top(); - } - - void NodeBuilder::Pop() - { - assert(!m_finished); - if(m_stack.empty()) { - m_finished = true; - return; - } - - Node& node = *m_stack.top(); - m_stack.pop(); - Insert(node); - } - - void NodeBuilder::Insert(Node& node) - { - Node& curTop = Top(); - switch(curTop.Type()) { - case NodeType::Null: - case NodeType::Scalar: - assert(false); - break; - case NodeType::Sequence: - curTop.Append(node); - break; - case NodeType::Map: - assert(!m_didPushKey.empty()); - if(m_didPushKey.top()) { - assert(!m_pendingKeys.empty()); - - Node& key = *m_pendingKeys.top(); - m_pendingKeys.pop(); - curTop.Insert(key, node); - m_didPushKey.top() = false; - } else { - m_pendingKeys.push(&node); - m_didPushKey.top() = true; - } - break; - } - } - - void NodeBuilder::RegisterAnchor(anchor_t anchor, Node& node) - { - if(anchor) { - assert(anchor == m_anchors.size()); - m_anchors.push_back(&node); - } - } -} diff --git a/src/old-api/nodebuilder.h b/src/old-api/nodebuilder.h deleted file mode 100644 index 9c1d16a..0000000 --- a/src/old-api/nodebuilder.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 -#define 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 -#pragma once -#endif - -#include "yaml-cpp/eventhandler.h" -#include -#include -#include -#include - -namespace YAML -{ - class Node; - - class NodeBuilder: public EventHandler - { - public: - explicit NodeBuilder(Node& root); - virtual ~NodeBuilder(); - - virtual void OnDocumentStart(const Mark& mark); - virtual void OnDocumentEnd(); - - 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 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 OnMapEnd(); - - private: - Node& Push(anchor_t anchor); - Node& Push(); - Node& Top(); - void Pop(); - - void Insert(Node& node); - void RegisterAnchor(anchor_t anchor, Node& node); - - private: - Node& m_root; - bool m_initializedRoot; - bool m_finished; - - std::stack m_stack; - std::stack m_pendingKeys; - std::stack m_didPushKey; - - typedef std::vector Anchors; - Anchors m_anchors; - }; -} - -#endif // NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 - diff --git a/src/old-api/nodeownership.cpp b/src/old-api/nodeownership.cpp deleted file mode 100644 index 44bb818..0000000 --- a/src/old-api/nodeownership.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "old-api/nodeownership.h" -#include "yaml-cpp/old-api/node.h" - -namespace YAML -{ - NodeOwnership::NodeOwnership(NodeOwnership *pOwner): m_pOwner(pOwner) - { - if(!m_pOwner) - m_pOwner = this; - } - - NodeOwnership::~NodeOwnership() - { - } - - Node& NodeOwnership::_Create() - { - m_nodes.push_back(std::auto_ptr(new Node)); - return m_nodes.back(); - } - - void NodeOwnership::_MarkAsAliased(const Node& node) - { - m_aliasedNodes.insert(&node); - } - - bool NodeOwnership::_IsAliased(const Node& node) const - { - return m_aliasedNodes.count(&node) > 0; - } -} diff --git a/src/old-api/nodeownership.h b/src/old-api/nodeownership.h deleted file mode 100644 index 6987081..0000000 --- a/src/old-api/nodeownership.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef NODE_OWNERSHIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66 -#define NODE_OWNERSHIP_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 -#pragma once -#endif - - -#include "yaml-cpp/noncopyable.h" -#include "ptr_vector.h" -#include - -namespace YAML -{ - class Node; - - class NodeOwnership: private noncopyable - { - public: - explicit NodeOwnership(NodeOwnership *pOwner = 0); - ~NodeOwnership(); - - Node& Create() { return m_pOwner->_Create(); } - void MarkAsAliased(const Node& node) { m_pOwner->_MarkAsAliased(node); } - bool IsAliased(const Node& node) const { return m_pOwner->_IsAliased(node); } - - private: - Node& _Create(); - void _MarkAsAliased(const Node& node); - bool _IsAliased(const Node& node) const; - - private: - ptr_vector m_nodes; - std::set m_aliasedNodes; - NodeOwnership *m_pOwner; - }; -} - -#endif // NODE_OWNERSHIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/src/parser.cpp b/src/parser.cpp index 8f2725e..7861ec1 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -9,11 +9,6 @@ #include #include -#ifdef YAML_CPP_OLD_API -#include "yaml-cpp/old-api/node.h" -#include "old-api/nodebuilder.h" -#endif - namespace YAML { Parser::Parser() @@ -58,17 +53,6 @@ namespace YAML return true; } -#ifdef YAML_CPP_OLD_API - // GetNextDocument - // . Reads the next document in the queue (of tokens). - // . Throws a ParserException on error. - bool Parser::GetNextDocument(Node& document) - { - NodeBuilder builder(document); - return HandleNextDocument(builder); - } -#endif - // ParseDirectives // . Reads any directives that are next in the queue. void Parser::ParseDirectives() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0749a99..98777be 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,13 +1,8 @@ file(GLOB test_headers [a-z]*.h) file(GLOB test_sources [a-z]*.cpp) -file(GLOB test_old_api_sources old-api/[a-z]*.cpp) file(GLOB test_new_api_sources new-api/[a-z]*.cpp) -if(YAML_CPP_BUILD_OLD_API) - list(APPEND test_sources ${test_old_api_sources}) -else() - list(APPEND test_sources ${test_new_api_sources}) -endif() +list(APPEND test_sources ${test_new_api_sources}) include_directories(${YAML_CPP_SOURCE_DIR}/test) diff --git a/test/emittertests.cpp b/test/emittertests.cpp index 40271fd..f16d25a 100644 --- a/test/emittertests.cpp +++ b/test/emittertests.cpp @@ -1008,15 +1008,7 @@ namespace Test if(output == desiredOutput) { try { -#ifdef YAML_CPP_OLD_API - std::stringstream stream(output); - YAML::Parser parser; - YAML::Node node; - parser.GetNextDocument(node); -#else YAML::Node node = YAML::Load(output); -#endif - passed++; } catch(const YAML::Exception& e) { std::cout << "Emitter test failed: " << name << "\n"; diff --git a/test/old-api/parsertests.cpp b/test/old-api/parsertests.cpp deleted file mode 100644 index 7145e15..0000000 --- a/test/old-api/parsertests.cpp +++ /dev/null @@ -1,1221 +0,0 @@ -#include "tests.h" -#include "yaml-cpp/yaml.h" -#include -#include -#include - -namespace Test -{ - namespace Parser { - void SimpleScalar(std::string& inputScalar, std::string& desiredOutput) - { - inputScalar = "Hello, World!"; - desiredOutput = "Hello, World!"; - } - - void MultiLineScalar(std::string& inputScalar, std::string& desiredOutput) - { - inputScalar = - "normal scalar, but\n" - "over several lines"; - desiredOutput = "normal scalar, but over several lines"; - } - - void LiteralScalar(std::string& inputScalar, std::string& desiredOutput) - { - inputScalar = - "|\n" - " literal scalar - so we can draw ASCII:\n" - " \n" - " - -\n" - " | - |\n" - " -----\n"; - desiredOutput = - "literal scalar - so we can draw ASCII:\n" - "\n" - " - -\n" - " | - |\n" - " -----\n"; - } - - void FoldedScalar(std::string& inputScalar, std::string& desiredOutput) - { - inputScalar = - ">\n" - " and a folded scalar... so we\n" - " can just keep writing various\n" - " things. And if we want to keep indentation:\n" - " \n" - " we just indent a little\n" - " see, this stays indented"; - desiredOutput = - "and a folded scalar... so we" - " can just keep writing various" - " things. And if we want to keep indentation:\n" - "\n" - " we just indent a little\n" - " see, this stays indented"; - } - - void ChompedFoldedScalar(std::string& inputScalar, std::string& desiredOutput) - { - inputScalar = - ">-\n" - " Here's a folded scalar\n" - " that gets chomped."; - desiredOutput = - "Here's a folded scalar" - " that gets chomped."; - } - - void ChompedLiteralScalar(std::string& inputScalar, std::string& desiredOutput) - { - inputScalar = - "|-\n" - " Here's a literal scalar\n" - " that gets chomped."; - desiredOutput = - "Here's a literal scalar\n" - "that gets chomped."; - } - - void FoldedScalarWithIndent(std::string& inputScalar, std::string& desiredOutput) - { - inputScalar = - ">2\n" - " Here's a folded scalar\n" - " that starts with some indentation."; - desiredOutput = - " Here's a folded scalar\n" - "that starts with some indentation."; - } - - void ColonScalar(std::string& inputScalar, std::string& desiredOutput) - { - inputScalar = "::vector"; - desiredOutput = "::vector"; - } - - void QuotedScalar(std::string& inputScalar, std::string& desiredOutput) - { - inputScalar = "\": - ()\""; - desiredOutput = ": - ()"; - } - - void CommaScalar(std::string& inputScalar, std::string& desiredOutput) - { - inputScalar = "Up, up, and away!"; - desiredOutput = "Up, up, and away!"; - } - - void DashScalar(std::string& inputScalar, std::string& desiredOutput) - { - inputScalar = "-123"; - desiredOutput = "-123"; - } - - void URLScalar(std::string& inputScalar, std::string& desiredOutput) - { - inputScalar = "http://example.com/foo#bar"; - desiredOutput = "http://example.com/foo#bar"; - } - - bool SimpleSeq() - { - std::string input = - "- eggs\n" - "- bread\n" - "- milk"; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - std::string output; - if(doc[0].to() != "eggs") - return false; - if(doc[1].to() != "bread") - return false; - if(doc[2].to() != "milk") - return false; - - return true; - } - - bool SimpleMap() - { - std::string input = - "name: Prince Fielder\n" - "position: 1B\n" - "bats: L"; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - std::string output; - doc["name"] >> output; - if(output != "Prince Fielder") - return false; - doc["position"] >> output; - if(output != "1B") - return false; - doc["bats"] >> output; - if(output != "L") - return false; - - return true; - } - - bool FlowSeq() - { - std::string input = "[ 2 , 3, 5 , 7, 11]"; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - int output; - doc[0] >> output; - if(output != 2) - return false; - doc[1] >> output; - if(output != 3) - return false; - doc[2] >> output; - if(output != 5) - return false; - doc[3] >> output; - if(output != 7) - return false; - doc[4] >> output; - if(output != 11) - return false; - - return true; - } - - bool FlowMap() - { - std::string input = "{hr: 65, avg: 0.278}"; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - std::string output; - doc["hr"] >> output; - if(output != "65") - return false; - doc["avg"] >> output; - if(output != "0.278") - return false; - - return true; - } - - bool FlowMapWithOmittedKey() - { - std::string input = "{: omitted key}"; - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - std::string output; - doc[YAML::Null] >> output; - if(output != "omitted key") - return false; - - return true; - } - - bool FlowMapWithOmittedValue() - { - std::string input = "{a: b, c:, d:}"; - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - std::string output; - doc["a"] >> output; - if(output != "b") - return false; - if(!IsNull(doc["c"])) - return false; - if(!IsNull(doc["d"])) - return false; - - return true; - } - - bool FlowMapWithSoloEntry() - { - std::string input = "{a: b, c, d: e}"; - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - std::string output; - doc["a"] >> output; - if(output != "b") - return false; - if(!IsNull(doc["c"])) - return false; - doc["d"] >> output; - if(output != "e") - return false; - - return true; - } - - bool FlowMapEndingWithSoloEntry() - { - std::string input = "{a: b, c}"; - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - std::string output; - doc["a"] >> output; - if(output != "b") - return false; - if(!IsNull(doc["c"])) - return false; - - return true; - } - - bool QuotedSimpleKeys() - { - std::string KeyValue[3] = { "\"double\": double\n", "'single': single\n", "plain: plain\n" }; - - int perm[3] = { 0, 1, 2 }; - do { - std::string input = KeyValue[perm[0]] + KeyValue[perm[1]] + KeyValue[perm[2]]; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - std::string output; - doc["double"] >> output; - if(output != "double") - return false; - doc["single"] >> output; - if(output != "single") - return false; - doc["plain"] >> output; - if(output != "plain") - return false; - } while(std::next_permutation(perm, perm + 3)); - - return true; - } - - bool CompressedMapAndSeq() - { - std::string input = "key:\n- one\n- two"; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - const YAML::Node& seq = doc["key"]; - if(seq.size() != 2) - return false; - - std::string output; - seq[0] >> output; - if(output != "one") - return false; - seq[1] >> output; - if(output != "two") - return false; - - return true; - } - - bool NullBlockSeqEntry() - { - std::string input = "- hello\n-\n- world"; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - std::string output; - doc[0] >> output; - if(output != "hello") - return false; - if(!IsNull(doc[1])) - return false; - doc[2] >> output; - if(output != "world") - return false; - - return true; - } - - bool NullBlockMapKey() - { - std::string input = ": empty key"; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - std::string output; - doc[YAML::Null] >> output; - if(output != "empty key") - return false; - - return true; - } - - bool NullBlockMapValue() - { - std::string input = "empty value:"; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - if(!IsNull(doc["empty value"])) - return false; - - return true; - } - - bool SimpleAlias() - { - std::string input = "- &alias test\n- *alias"; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - std::string output; - doc[0] >> output; - if(output != "test") - return false; - - doc[1] >> output; - if(output != "test") - return false; - - if(doc.size() != 2) - return false; - - return true; - } - - bool AliasWithNull() - { - std::string input = "- &alias\n- *alias"; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - if(!IsNull(doc[0])) - return false; - - if(!IsNull(doc[1])) - return false; - - if(doc.size() != 2) - return false; - - return true; - } - - bool AnchorInSimpleKey() - { - std::string input = "- &a b: c\n- *a"; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - if(doc.size() != 2) - return false; - - std::string output; - doc[0]["b"] >> output; - if(output != "c") - return false; - - doc[1] >> output; - if(output != "b") - return false; - - return true; - } - - bool AliasAsSimpleKey() - { - std::string input = "- &a b\n- *a : c"; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - if(doc.size() != 2) - return false; - - std::string output; - doc[0] >> output; - if(output != "b") - return false; - - doc[1]["b"] >> output; - if(output != "c") - return false; - - return true; - } - - bool ExplicitDoc() - { - std::string input = "---\n- one\n- two"; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - if(doc.size() != 2) - return false; - - std::string output; - doc[0] >> output; - if(output != "one") - return false; - doc[1] >> output; - if(output != "two") - return false; - - return true; - } - - bool MultipleDocs() - { - std::string input = "---\nname: doc1\n---\nname: doc2"; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - std::string output; - doc["name"] >> output; - if(output != "doc1") - return false; - - if(!parser) - return false; - - parser.GetNextDocument(doc); - doc["name"] >> output; - if(output != "doc2") - return false; - - return true; - } - - bool ExplicitEndDoc() - { - std::string input = "- one\n- two\n...\n..."; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - if(doc.size() != 2) - return false; - - std::string output; - doc[0] >> output; - if(output != "one") - return false; - doc[1] >> output; - if(output != "two") - return false; - - return true; - } - - bool MultipleDocsWithSomeExplicitIndicators() - { - std::string input = - "- one\n- two\n...\n" - "---\nkey: value\n...\n...\n" - "- three\n- four\n" - "---\nkey: value"; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - std::string output; - - parser.GetNextDocument(doc); - if(doc.size() != 2) - return false; - doc[0] >> output; - if(output != "one") - return false; - doc[1] >> output; - if(output != "two") - return false; - - parser.GetNextDocument(doc); - doc["key"] >> output; - if(output != "value") - return false; - - parser.GetNextDocument(doc); - if(doc.size() != 2) - return false; - doc[0] >> output; - if(output != "three") - return false; - doc[1] >> output; - if(output != "four") - return false; - - parser.GetNextDocument(doc); - doc["key"] >> output; - if(output != "value") - return false; - - return true; - } - - bool BlockKeyWithNullValue() - { - std::string input = - "key:\n" - "just a key: value"; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - - parser.GetNextDocument(doc); - if(doc.size() != 2) - return false; - if(!IsNull(doc["key"])) - return false; - if(doc["just a key"].to() != "value") - return false; - - return true; - } - - bool Bases() - { - std::string input = - "- 15\n" - "- 0x10\n" - "- 030\n" - "- 0xffffffff\n"; - - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - - parser.GetNextDocument(doc); - if(doc.size() != 4) - return false; - if(doc[0].to() != 15) - return false; - if(doc[1].to() != 0x10) - return false; - if(doc[2].to() != 030) - return false; - if(doc[3].to() != 0xffffffff) - return false; - return true; - } - - bool KeyNotFound() - { - std::string input = "key: value"; - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - try { - doc["bad key"]; - } catch(const YAML::Exception& e) { - if(e.msg != std::string(YAML::ErrorMsg::KEY_NOT_FOUND) + ": bad key") - throw; - } - - try { - doc[5]; - } catch(const YAML::Exception& e) { - if(e.msg != std::string(YAML::ErrorMsg::KEY_NOT_FOUND) + ": 5") - throw; - } - - try { - doc[2.5]; - } catch(const YAML::Exception& e) { - if(e.msg != std::string(YAML::ErrorMsg::KEY_NOT_FOUND) + ": 2.5") - throw; - } - - return true; - } - - bool DuplicateKey() - { - std::string input = "{a: 1, b: 2, c: 3, a: 4}"; - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - if(doc["a"].to() != 4) - return false; - if(doc["b"].to() != 2) - return false; - if(doc["c"].to() != 3) - return false; - return true; - } - - void PrepareNodeForTagExam(YAML::Node& doc, const std::string& input) - { - std::stringstream stream(input); - YAML::Parser parser(stream); - parser.GetNextDocument(doc); - } - - struct TagMismatch: public std::exception { - TagMismatch(const std::string& actualTag, const std::string& expectedTag) { - std::stringstream output; - output << "Tag has value \"" << actualTag << "\" but \"" << expectedTag << "\" was expected"; - what_ = output.str(); - } - virtual ~TagMismatch() throw() {} - virtual const char *what() const throw() { return what_.c_str(); } - - private: - std::string what_; - }; - - bool ExpectedTagValue(YAML::Node& node, const char* tag) - { - if(node.Tag() == tag) - return true; - - throw TagMismatch(node.Tag(), tag); - } - - bool DefaultPlainScalarTag() - { - YAML::Node node; - PrepareNodeForTagExam(node, "--- 12"); - - return ExpectedTagValue(node, "?"); - } - - bool DefaultSingleQuotedScalarTag() - { - YAML::Node node; - PrepareNodeForTagExam(node, "--- '12'"); - - return ExpectedTagValue(node, "!"); - } - - bool ExplicitNonSpecificPlainScalarTag() - { - YAML::Node node; - PrepareNodeForTagExam(node, "--- ! 12"); - - return ExpectedTagValue(node, "!"); - } - - bool BasicLocalTag() - { - YAML::Node node; - PrepareNodeForTagExam(node, "--- !foo 12"); - - return ExpectedTagValue(node, "!foo"); - } - - bool VerbatimLocalTag() - { - YAML::Node node; - PrepareNodeForTagExam(node, "--- ! 12"); - - return ExpectedTagValue(node, "!foo"); - } - - bool StandardShortcutTag() - { - YAML::Node node; - PrepareNodeForTagExam(node, "--- !!int 12"); - - return ExpectedTagValue(node, "tag:yaml.org,2002:int"); - } - - bool VerbatimURITag() - { - YAML::Node node; - PrepareNodeForTagExam(node, "--- ! 12"); - - return ExpectedTagValue(node, "tag:yaml.org,2002:int"); - } - - bool DefaultSequenceTag() - { - YAML::Node node; - PrepareNodeForTagExam(node, "--- [12]"); - - return ExpectedTagValue(node, "?"); - } - - bool ExplicitNonSpecificSequenceTag() - { - YAML::Node node; - PrepareNodeForTagExam(node, "--- ! [12]"); - - return ExpectedTagValue(node, "!"); - } - - bool Infinity() - { - std::string input = - "- .inf\n" - "- .Inf\n" - "- .INF\n" - "- +.inf\n" - "- +.Inf\n" - "- +.INF\n" - "- -.inf\n" - "- -.Inf\n" - "- -.INF\n"; - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - for(unsigned i=0;i() != (i < 6 ? +1 : -1) * std::numeric_limits::infinity()) - return false; - for(unsigned i=0;i() != (i < 6 ? +1 : -1) * std::numeric_limits::infinity()) - return false; - for(unsigned i=0;i() != (i < 6 ? +1 : -1) * std::numeric_limits::infinity()) - return false; - return true; - } - - bool NaN() - { - std::string input = - "- .nan\n" - "- .NaN\n" - "- .NAN\n"; - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - for(unsigned i=0;i> d; - if(d == d) - return false; - } - for(unsigned i=0;i> d; - if(d == d) - return false; - } - for(unsigned i=0;i> d; - if(d == d) - return false; - } - return true; - } - - bool NonConstKey() - { - std::string input = "{a: 1}"; - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - std::vector key(2); - key[0] = 'a'; - key[1] = '\0'; - if(doc[&key[0]].to() != 1) - return false; - return true; - } - - bool SingleChar() - { - std::string input = "5"; - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - return doc.to() == 5; - } - - bool QuotedNewline() - { - std::string input = "foo: \"\\n\""; - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - return doc["foo"].to() == "\n"; - } - - bool DoubleAsInt() - { - std::string input = "1.5"; - std::stringstream stream(input); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - - try { - doc.to(); - } catch(const YAML::InvalidScalar& e) { - return true; - } - - return false; - } - } - - namespace { - void RunScalarParserTest(void (*test)(std::string&, std::string&), const std::string& name, int& passed, int& total) { - std::string error; - std::string inputScalar, desiredOutput; - std::string output; - bool ok = true; - try { - test(inputScalar, desiredOutput); - std::stringstream stream(inputScalar); - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - doc >> output; - } catch(const YAML::Exception& e) { - ok = false; - error = e.what(); - } - if(ok && output == desiredOutput) { - passed++; - } else { - std::cout << "Parser test failed: " << name << "\n"; - if(error != "") - std::cout << "Caught exception: " << error << "\n"; - else { - std::cout << "Output:\n" << output << "<<<\n"; - std::cout << "Desired output:\n" << desiredOutput << "<<<\n"; - } - } - total++; - } - - void RunParserTest(bool (*test)(), const std::string& name, int& passed, int& total) { - std::string error; - bool ok = true; - try { - ok = test(); - } catch(const YAML::Exception& e) { - ok = false; - error = e.what(); - } catch(const Parser::TagMismatch& e) { - ok = false; - error = e.what(); - } - if(ok) { - passed++; - } else { - std::cout << "Parser test failed: " << name << "\n"; - if(error != "") - std::cout << " Caught exception: " << error << "\n"; - } - total++; - } - - typedef void (*EncodingFn)(std::ostream&, int); - - inline char Byte(int ch) - { - return static_cast(static_cast(static_cast(ch))); - } - - void EncodeToUtf8(std::ostream& stream, int ch) - { - if (ch <= 0x7F) - { - stream << Byte(ch); - } - else if (ch <= 0x7FF) - { - stream << Byte(0xC0 | (ch >> 6)); - stream << Byte(0x80 | (ch & 0x3F)); - } - else if (ch <= 0xFFFF) - { - stream << Byte(0xE0 | (ch >> 12)); - stream << Byte(0x80 | ((ch >> 6) & 0x3F)); - stream << Byte(0x80 | (ch & 0x3F)); - } - else if (ch <= 0x1FFFFF) - { - stream << Byte(0xF0 | (ch >> 18)); - stream << Byte(0x80 | ((ch >> 12) & 0x3F)); - stream << Byte(0x80 | ((ch >> 6) & 0x3F)); - stream << Byte(0x80 | (ch & 0x3F)); - } - } - - bool SplitUtf16HighChar(std::ostream& stream, EncodingFn encoding, int ch) - { - int biasedValue = ch - 0x10000; - if (biasedValue < 0) - { - return false; - } - int high = 0xD800 | (biasedValue >> 10); - int low = 0xDC00 | (biasedValue & 0x3FF); - encoding(stream, high); - encoding(stream, low); - return true; - } - - void EncodeToUtf16LE(std::ostream& stream, int ch) - { - if (!SplitUtf16HighChar(stream, &EncodeToUtf16LE, ch)) - { - stream << Byte(ch & 0xFF) << Byte(ch >> 8); - } - } - - void EncodeToUtf16BE(std::ostream& stream, int ch) - { - if (!SplitUtf16HighChar(stream, &EncodeToUtf16BE, ch)) - { - stream << Byte(ch >> 8) << Byte(ch & 0xFF); - } - } - - void EncodeToUtf32LE(std::ostream& stream, int ch) - { - stream << Byte(ch & 0xFF) << Byte((ch >> 8) & 0xFF) - << Byte((ch >> 16) & 0xFF) << Byte((ch >> 24) & 0xFF); - } - - void EncodeToUtf32BE(std::ostream& stream, int ch) - { - stream << Byte((ch >> 24) & 0xFF) << Byte((ch >> 16) & 0xFF) - << Byte((ch >> 8) & 0xFF) << Byte(ch & 0xFF); - } - - class EncodingTester - { - public: - EncodingTester(EncodingFn encoding, bool declareEncoding) - { - if (declareEncoding) - { - encoding(m_yaml, 0xFEFF); - } - - AddEntry(encoding, 0x0021, 0x007E); // Basic Latin - AddEntry(encoding, 0x00A1, 0x00FF); // Latin-1 Supplement - AddEntry(encoding, 0x0660, 0x06FF); // Arabic (largest contiguous block) - - // CJK unified ideographs (multiple lines) - AddEntry(encoding, 0x4E00, 0x4EFF); - AddEntry(encoding, 0x4F00, 0x4FFF); - AddEntry(encoding, 0x5000, 0x51FF); // 512 character line - AddEntry(encoding, 0x5200, 0x54FF); // 768 character line - AddEntry(encoding, 0x5500, 0x58FF); // 1024 character line - - AddEntry(encoding, 0x103A0, 0x103C3); // Old Persian - - m_yaml.seekg(0, std::ios::beg); - } - - std::istream& stream() {return m_yaml;} - const std::vector& entries() {return m_entries;} - - private: - std::stringstream m_yaml; - std::vector m_entries; - - void AddEntry(EncodingFn encoding, int startCh, int endCh) - { - encoding(m_yaml, '-'); - encoding(m_yaml, ' '); - encoding(m_yaml, '|'); - encoding(m_yaml, '\n'); - encoding(m_yaml, ' '); - encoding(m_yaml, ' '); - - std::stringstream entry; - for (int ch = startCh; ch <= endCh; ++ch) - { - encoding(m_yaml, ch); - EncodeToUtf8(entry, ch); - } - encoding(m_yaml, '\n'); - - m_entries.push_back(entry.str()); - } - }; - - void RunEncodingTest(EncodingFn encoding, bool declareEncoding, const std::string& name, int& passed, int& total) - { - EncodingTester tester(encoding, declareEncoding); - std::string error; - bool ok = true; - try { - YAML::Parser parser(tester.stream()); - YAML::Node doc; - parser.GetNextDocument(doc); - - YAML::Iterator itNode = doc.begin(); - std::vector::const_iterator itEntry = tester.entries().begin(); - for (; (itNode != doc.end()) && (itEntry != tester.entries().end()); ++itNode, ++itEntry) - { - std::string stScalarValue; - if (!itNode->GetScalar(stScalarValue) && (stScalarValue == *itEntry)) - { - break; - } - } - - if ((itNode != doc.end()) || (itEntry != tester.entries().end())) - { - ok = false; - } - } catch(const YAML::Exception& e) { - ok = false; - error = e.msg; - } - if(ok) { - passed++; - } else { - std::cout << "Parser test failed: " << name << "\n"; - if(error != "") - std::cout << " Caught exception: " << error << "\n"; - } - total++; - } - } - - bool RunParserTests() - { - int passed = 0; - int total = 0; - RunScalarParserTest(&Parser::SimpleScalar, "simple scalar", passed, total); - RunScalarParserTest(&Parser::MultiLineScalar, "multi-line scalar", passed, total); - RunScalarParserTest(&Parser::LiteralScalar, "literal scalar", passed, total); - RunScalarParserTest(&Parser::FoldedScalar, "folded scalar", passed, total); - RunScalarParserTest(&Parser::ChompedFoldedScalar, "chomped folded scalar", passed, total); - RunScalarParserTest(&Parser::ChompedLiteralScalar, "chomped literal scalar", passed, total); - RunScalarParserTest(&Parser::FoldedScalarWithIndent, "folded scalar with indent", passed, total); - RunScalarParserTest(&Parser::ColonScalar, "colon scalar", passed, total); - RunScalarParserTest(&Parser::QuotedScalar, "quoted scalar", passed, total); - RunScalarParserTest(&Parser::CommaScalar, "comma scalar", passed, total); - RunScalarParserTest(&Parser::DashScalar, "dash scalar", passed, total); - RunScalarParserTest(&Parser::URLScalar, "url scalar", passed, total); - - RunParserTest(&Parser::SimpleSeq, "simple seq", passed, total); - RunParserTest(&Parser::SimpleMap, "simple map", passed, total); - RunParserTest(&Parser::FlowSeq, "flow seq", passed, total); - RunParserTest(&Parser::FlowMap, "flow map", passed, total); - RunParserTest(&Parser::FlowMapWithOmittedKey, "flow map with omitted key", passed, total); - RunParserTest(&Parser::FlowMapWithOmittedValue, "flow map with omitted value", passed, total); - RunParserTest(&Parser::FlowMapWithSoloEntry, "flow map with solo entry", passed, total); - RunParserTest(&Parser::FlowMapEndingWithSoloEntry, "flow map ending with solo entry", passed, total); - RunParserTest(&Parser::QuotedSimpleKeys, "quoted simple keys", passed, total); - RunParserTest(&Parser::CompressedMapAndSeq, "compressed map and seq", passed, total); - RunParserTest(&Parser::NullBlockSeqEntry, "null block seq entry", passed, total); - RunParserTest(&Parser::NullBlockMapKey, "null block map key", passed, total); - RunParserTest(&Parser::NullBlockMapValue, "null block map value", passed, total); - RunParserTest(&Parser::SimpleAlias, "simple alias", passed, total); - RunParserTest(&Parser::AliasWithNull, "alias with null", passed, total); - RunParserTest(&Parser::AnchorInSimpleKey, "anchor in simple key", passed, total); - RunParserTest(&Parser::AliasAsSimpleKey, "alias as simple key", passed, total); - RunParserTest(&Parser::ExplicitDoc, "explicit doc", passed, total); - RunParserTest(&Parser::MultipleDocs, "multiple docs", passed, total); - RunParserTest(&Parser::ExplicitEndDoc, "explicit end doc", passed, total); - RunParserTest(&Parser::MultipleDocsWithSomeExplicitIndicators, "multiple docs with some explicit indicators", passed, total); - RunParserTest(&Parser::BlockKeyWithNullValue, "block key with null value", passed, total); - RunParserTest(&Parser::Bases, "bases", passed, total); - RunParserTest(&Parser::KeyNotFound, "key not found", passed, total); - RunParserTest(&Parser::DuplicateKey, "duplicate key", passed, total); - RunParserTest(&Parser::DefaultPlainScalarTag, "default plain scalar tag", passed, total); - RunParserTest(&Parser::DefaultSingleQuotedScalarTag, "default single-quoted scalar tag", passed, total); - RunParserTest(&Parser::ExplicitNonSpecificPlainScalarTag, "explicit, non-specific plain scalar tag", passed, total); - RunParserTest(&Parser::BasicLocalTag, "basic local tag", passed, total); - RunParserTest(&Parser::VerbatimLocalTag, "verbatim local tag", passed, total); - RunParserTest(&Parser::StandardShortcutTag, "standard shortcut tag", passed, total); - RunParserTest(&Parser::VerbatimURITag, "verbatim URI tag", passed, total); - RunParserTest(&Parser::DefaultPlainScalarTag, "default plain scalar tag", passed, total); - RunParserTest(&Parser::DefaultSequenceTag, "default sequence tag", passed, total); - RunParserTest(&Parser::ExplicitNonSpecificSequenceTag, "explicit, non-specific sequence tag", passed, total); - RunParserTest(&Parser::Infinity, "infinity", passed, total); - RunParserTest(&Parser::NaN, "NaN", passed, total); - RunParserTest(&Parser::NonConstKey, "non const key", passed, total); - RunParserTest(&Parser::SingleChar, "single char", passed, total); - RunParserTest(&Parser::QuotedNewline, "quoted newline", passed, total); - RunParserTest(&Parser::DoubleAsInt, "double as int", passed, total); - - RunEncodingTest(&EncodeToUtf8, false, "UTF-8, no BOM", passed, total); - RunEncodingTest(&EncodeToUtf8, true, "UTF-8 with BOM", passed, total); - RunEncodingTest(&EncodeToUtf16LE, false, "UTF-16LE, no BOM", passed, total); - RunEncodingTest(&EncodeToUtf16LE, true, "UTF-16LE with BOM", passed, total); - RunEncodingTest(&EncodeToUtf16BE, false, "UTF-16BE, no BOM", passed, total); - RunEncodingTest(&EncodeToUtf16BE, true, "UTF-16BE with BOM", passed, total); - RunEncodingTest(&EncodeToUtf32LE, false, "UTF-32LE, no BOM", passed, total); - RunEncodingTest(&EncodeToUtf32LE, true, "UTF-32LE with BOM", passed, total); - RunEncodingTest(&EncodeToUtf32BE, false, "UTF-32BE, no BOM", passed, total); - RunEncodingTest(&EncodeToUtf32BE, true, "UTF-32BE with BOM", passed, total); - - std::cout << "Parser tests: " << passed << "/" << total << " passed\n"; - return passed == total; - } -} - diff --git a/test/old-api/spectests.cpp b/test/old-api/spectests.cpp deleted file mode 100644 index fb5505b..0000000 --- a/test/old-api/spectests.cpp +++ /dev/null @@ -1,1456 +0,0 @@ -#include "spectests.h" -#include "specexamples.h" -#include "yaml-cpp/yaml.h" -#include -#include -#include -#include - -#define YAML_ASSERT(cond) do { if(!(cond)) return " Assert failed: " #cond; } while(false) -#define PARSE(doc, input) \ - std::stringstream stream(input);\ - YAML::Parser parser(stream);\ - YAML::Node doc;\ - parser.GetNextDocument(doc) -#define PARSE_NEXT(doc) parser.GetNextDocument(doc) - -namespace Test { - namespace Spec { - // 2.1 - TEST SeqScalars() { - PARSE(doc, ex2_1); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc[0].to() == "Mark McGwire"); - YAML_ASSERT(doc[1].to() == "Sammy Sosa"); - YAML_ASSERT(doc[2].to() == "Ken Griffey"); - return true; - } - - // 2.2 - TEST MappingScalarsToScalars() { - PARSE(doc, ex2_2); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc["hr"].to() == "65"); - YAML_ASSERT(doc["avg"].to() == "0.278"); - YAML_ASSERT(doc["rbi"].to() == "147"); - return true; - } - - // 2.3 - TEST MappingScalarsToSequences() { - PARSE(doc, ex2_3); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc["american"].size() == 3); - YAML_ASSERT(doc["american"][0].to() == "Boston Red Sox"); - YAML_ASSERT(doc["american"][1].to() == "Detroit Tigers"); - YAML_ASSERT(doc["american"][2].to() == "New York Yankees"); - YAML_ASSERT(doc["national"].size() == 3); - YAML_ASSERT(doc["national"][0].to() == "New York Mets"); - YAML_ASSERT(doc["national"][1].to() == "Chicago Cubs"); - YAML_ASSERT(doc["national"][2].to() == "Atlanta Braves"); - return true; - } - - // 2.4 - TEST SequenceOfMappings() - { - PARSE(doc, ex2_4); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc[0].size() == 3); - YAML_ASSERT(doc[0]["name"].to() == "Mark McGwire"); - YAML_ASSERT(doc[0]["hr"].to() == "65"); - YAML_ASSERT(doc[0]["avg"].to() == "0.278"); - YAML_ASSERT(doc[1].size() == 3); - YAML_ASSERT(doc[1]["name"].to() == "Sammy Sosa"); - YAML_ASSERT(doc[1]["hr"].to() == "63"); - YAML_ASSERT(doc[1]["avg"].to() == "0.288"); - return true; - } - - // 2.5 - TEST SequenceOfSequences() - { - PARSE(doc, ex2_5); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc[0].size() == 3); - YAML_ASSERT(doc[0][0].to() == "name"); - YAML_ASSERT(doc[0][1].to() == "hr"); - YAML_ASSERT(doc[0][2].to() == "avg"); - YAML_ASSERT(doc[1].size() == 3); - YAML_ASSERT(doc[1][0].to() == "Mark McGwire"); - YAML_ASSERT(doc[1][1].to() == "65"); - YAML_ASSERT(doc[1][2].to() == "0.278"); - YAML_ASSERT(doc[2].size() == 3); - YAML_ASSERT(doc[2][0].to() == "Sammy Sosa"); - YAML_ASSERT(doc[2][1].to() == "63"); - YAML_ASSERT(doc[2][2].to() == "0.288"); - return true; - } - - // 2.6 - TEST MappingOfMappings() - { - PARSE(doc, ex2_6); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc["Mark McGwire"].size() == 2); - YAML_ASSERT(doc["Mark McGwire"]["hr"].to() == "65"); - YAML_ASSERT(doc["Mark McGwire"]["avg"].to() == "0.278"); - YAML_ASSERT(doc["Sammy Sosa"].size() == 2); - YAML_ASSERT(doc["Sammy Sosa"]["hr"].to() == "63"); - YAML_ASSERT(doc["Sammy Sosa"]["avg"].to() == "0.288"); - return true; - } - - // 2.7 - TEST TwoDocumentsInAStream() - { - PARSE(doc, ex2_7); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc[0].to() == "Mark McGwire"); - YAML_ASSERT(doc[1].to() == "Sammy Sosa"); - YAML_ASSERT(doc[2].to() == "Ken Griffey"); - - PARSE_NEXT(doc); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc[0].to() == "Chicago Cubs"); - YAML_ASSERT(doc[1].to() == "St Louis Cardinals"); - return true; - } - - // 2.8 - TEST PlayByPlayFeed() - { - PARSE(doc, ex2_8); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc["time"].to() == "20:03:20"); - YAML_ASSERT(doc["player"].to() == "Sammy Sosa"); - YAML_ASSERT(doc["action"].to() == "strike (miss)"); - - PARSE_NEXT(doc); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc["time"].to() == "20:03:47"); - YAML_ASSERT(doc["player"].to() == "Sammy Sosa"); - YAML_ASSERT(doc["action"].to() == "grand slam"); - return true; - } - - // 2.9 - TEST SingleDocumentWithTwoComments() - { - PARSE(doc, ex2_9); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc["hr"].size() == 2); - YAML_ASSERT(doc["hr"][0].to() == "Mark McGwire"); - YAML_ASSERT(doc["hr"][1].to() == "Sammy Sosa"); - YAML_ASSERT(doc["rbi"].size() == 2); - YAML_ASSERT(doc["rbi"][0].to() == "Sammy Sosa"); - YAML_ASSERT(doc["rbi"][1].to() == "Ken Griffey"); - return true; - } - - // 2.10 - TEST SimpleAnchor() - { - PARSE(doc, ex2_10); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc["hr"].size() == 2); - YAML_ASSERT(doc["hr"][0].to() == "Mark McGwire"); - YAML_ASSERT(doc["hr"][1].to() == "Sammy Sosa"); - YAML_ASSERT(doc["rbi"].size() == 2); - YAML_ASSERT(doc["rbi"][0].to() == "Sammy Sosa"); - YAML_ASSERT(doc["rbi"][1].to() == "Ken Griffey"); - return true; - } - - struct Pair { - Pair() {} - Pair(const std::string& f, const std::string& s): first(f), second(s) {} - std::string first, second; - }; - - bool operator == (const Pair& p, const Pair& q) { - return p.first == q.first && p.second == q.second; - } - - void operator >> (const YAML::Node& node, Pair& p) { - node[0] >> p.first; - node[1] >> p.second; - } - - // 2.11 - TEST MappingBetweenSequences() - { - PARSE(doc, ex2_11); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc[Pair("Detroit Tigers", "Chicago cubs")].size() == 1); - YAML_ASSERT(doc[Pair("Detroit Tigers", "Chicago cubs")][0].to() == "2001-07-23"); - YAML_ASSERT(doc[Pair("New York Yankees", "Atlanta Braves")].size() == 3); - YAML_ASSERT(doc[Pair("New York Yankees", "Atlanta Braves")][0].to() == "2001-07-02"); - YAML_ASSERT(doc[Pair("New York Yankees", "Atlanta Braves")][1].to() == "2001-08-12"); - YAML_ASSERT(doc[Pair("New York Yankees", "Atlanta Braves")][2].to() == "2001-08-14"); - return true; - } - - // 2.12 - TEST CompactNestedMapping() - { - PARSE(doc, ex2_12); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc[0].size() == 2); - YAML_ASSERT(doc[0]["item"].to() == "Super Hoop"); - YAML_ASSERT(doc[0]["quantity"].to() == 1); - YAML_ASSERT(doc[1].size() == 2); - YAML_ASSERT(doc[1]["item"].to() == "Basketball"); - YAML_ASSERT(doc[1]["quantity"].to() == 4); - YAML_ASSERT(doc[2].size() == 2); - YAML_ASSERT(doc[2]["item"].to() == "Big Shoes"); - YAML_ASSERT(doc[2]["quantity"].to() == 1); - return true; - } - - // 2.13 - TEST InLiteralsNewlinesArePreserved() - { - PARSE(doc, ex2_13); - YAML_ASSERT(doc.to() == - "\\//||\\/||\n" - "// || ||__"); - return true; - } - - // 2.14 - TEST InFoldedScalarsNewlinesBecomeSpaces() - { - PARSE(doc, ex2_14); - YAML_ASSERT(doc.to() == "Mark McGwire's year was crippled by a knee injury."); - return true; - } - - // 2.15 - TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines() - { - PARSE(doc, ex2_15); - YAML_ASSERT(doc.to() == - "Sammy Sosa completed another fine season with great stats.\n\n" - " 63 Home Runs\n" - " 0.288 Batting Average\n\n" - "What a year!"); - return true; - } - - // 2.16 - TEST IndentationDeterminesScope() - { - PARSE(doc, ex2_16); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc["name"].to() == "Mark McGwire"); - YAML_ASSERT(doc["accomplishment"].to() == "Mark set a major league home run record in 1998.\n"); - YAML_ASSERT(doc["stats"].to() == "65 Home Runs\n0.278 Batting Average\n"); - return true; - } - - // 2.17 - TEST QuotedScalars() - { - PARSE(doc, ex2_17); - YAML_ASSERT(doc.size() == 6); - YAML_ASSERT(doc["unicode"].to() == "Sosa did fine.\xe2\x98\xba"); - YAML_ASSERT(doc["control"].to() == "\b1998\t1999\t2000\n"); - YAML_ASSERT(doc["hex esc"].to() == "\x0d\x0a is \r\n"); - YAML_ASSERT(doc["single"].to() == "\"Howdy!\" he cried."); - YAML_ASSERT(doc["quoted"].to() == " # Not a 'comment'."); - YAML_ASSERT(doc["tie-fighter"].to() == "|\\-*-/|"); - return true; - } - - // 2.18 - TEST MultiLineFlowScalars() - { - PARSE(doc, ex2_18); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc["plain"].to() == "This unquoted scalar spans many lines."); - YAML_ASSERT(doc["quoted"].to() == "So does this quoted scalar.\n"); - return true; - } - - // TODO: 2.19 - 2.22 schema tags - - // 2.23 - TEST VariousExplicitTags() - { - PARSE(doc, ex2_23); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc["not-date"].Tag() == "tag:yaml.org,2002:str"); - YAML_ASSERT(doc["not-date"].to() == "2002-04-28"); - YAML_ASSERT(doc["picture"].Tag() == "tag:yaml.org,2002:binary"); - YAML_ASSERT(doc["picture"].to() == - "R0lGODlhDAAMAIQAAP//9/X\n" - "17unp5WZmZgAAAOfn515eXv\n" - "Pz7Y6OjuDg4J+fn5OTk6enp\n" - "56enmleECcgggoBADs=\n" - ); - YAML_ASSERT(doc["application specific tag"].Tag() == "!something"); - YAML_ASSERT(doc["application specific tag"].to() == - "The semantics of the tag\n" - "above may be different for\n" - "different documents." - ); - return true; - } - - // 2.24 - TEST GlobalTags() - { - PARSE(doc, ex2_24); - YAML_ASSERT(doc.Tag() == "tag:clarkevans.com,2002:shape"); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc[0].Tag() == "tag:clarkevans.com,2002:circle"); - YAML_ASSERT(doc[0].size() == 2); - YAML_ASSERT(doc[0]["center"].size() == 2); - YAML_ASSERT(doc[0]["center"]["x"].to() == 73); - YAML_ASSERT(doc[0]["center"]["y"].to() == 129); - YAML_ASSERT(doc[0]["radius"].to() == 7); - YAML_ASSERT(doc[1].Tag() == "tag:clarkevans.com,2002:line"); - YAML_ASSERT(doc[1].size() == 2); - YAML_ASSERT(doc[1]["start"].size() == 2); - YAML_ASSERT(doc[1]["start"]["x"].to() == 73); - YAML_ASSERT(doc[1]["start"]["y"].to() == 129); - YAML_ASSERT(doc[1]["finish"].size() == 2); - YAML_ASSERT(doc[1]["finish"]["x"].to() == 89); - YAML_ASSERT(doc[1]["finish"]["y"].to() == 102); - YAML_ASSERT(doc[2].Tag() == "tag:clarkevans.com,2002:label"); - YAML_ASSERT(doc[2].size() == 3); - YAML_ASSERT(doc[2]["start"].size() == 2); - YAML_ASSERT(doc[2]["start"]["x"].to() == 73); - YAML_ASSERT(doc[2]["start"]["y"].to() == 129); - YAML_ASSERT(doc[2]["color"].to() == "0xFFEEBB"); - YAML_ASSERT(doc[2]["text"].to() == "Pretty vector drawing."); - return true; - } - - // 2.25 - TEST UnorderedSets() - { - PARSE(doc, ex2_25); - YAML_ASSERT(doc.Tag() == "tag:yaml.org,2002:set"); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(IsNull(doc["Mark McGwire"])); - YAML_ASSERT(IsNull(doc["Sammy Sosa"])); - YAML_ASSERT(IsNull(doc["Ken Griffey"])); - return true; - } - - // 2.26 - TEST OrderedMappings() - { - PARSE(doc, ex2_26); - YAML_ASSERT(doc.Tag() == "tag:yaml.org,2002:omap"); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc[0].size() == 1); - YAML_ASSERT(doc[0]["Mark McGwire"].to() == 65); - YAML_ASSERT(doc[1].size() == 1); - YAML_ASSERT(doc[1]["Sammy Sosa"].to() == 63); - YAML_ASSERT(doc[2].size() == 1); - YAML_ASSERT(doc[2]["Ken Griffey"].to() == 58); - return true; - } - - // 2.27 - TEST Invoice() - { - PARSE(doc, ex2_27); - YAML_ASSERT(doc.Tag() == "tag:clarkevans.com,2002:invoice"); - YAML_ASSERT(doc.size() == 8); - YAML_ASSERT(doc["invoice"].to() == 34843); - YAML_ASSERT(doc["date"].to() == "2001-01-23"); - YAML_ASSERT(doc["bill-to"].size() == 3); - YAML_ASSERT(doc["bill-to"]["given"].to() == "Chris"); - YAML_ASSERT(doc["bill-to"]["family"].to() == "Dumars"); - YAML_ASSERT(doc["bill-to"]["address"].size() == 4); - YAML_ASSERT(doc["bill-to"]["address"]["lines"].to() == "458 Walkman Dr.\nSuite #292\n"); - YAML_ASSERT(doc["bill-to"]["address"]["city"].to() == "Royal Oak"); - YAML_ASSERT(doc["bill-to"]["address"]["state"].to() == "MI"); - YAML_ASSERT(doc["bill-to"]["address"]["postal"].to() == "48046"); - YAML_ASSERT(doc["ship-to"].size() == 3); - YAML_ASSERT(doc["ship-to"]["given"].to() == "Chris"); - YAML_ASSERT(doc["ship-to"]["family"].to() == "Dumars"); - YAML_ASSERT(doc["ship-to"]["address"].size() == 4); - YAML_ASSERT(doc["ship-to"]["address"]["lines"].to() == "458 Walkman Dr.\nSuite #292\n"); - YAML_ASSERT(doc["ship-to"]["address"]["city"].to() == "Royal Oak"); - YAML_ASSERT(doc["ship-to"]["address"]["state"].to() == "MI"); - YAML_ASSERT(doc["ship-to"]["address"]["postal"].to() == "48046"); - YAML_ASSERT(doc["product"].size() == 2); - YAML_ASSERT(doc["product"][0].size() == 4); - YAML_ASSERT(doc["product"][0]["sku"].to() == "BL394D"); - YAML_ASSERT(doc["product"][0]["quantity"].to() == 4); - YAML_ASSERT(doc["product"][0]["description"].to() == "Basketball"); - YAML_ASSERT(doc["product"][0]["price"].to() == "450.00"); - YAML_ASSERT(doc["product"][1].size() == 4); - YAML_ASSERT(doc["product"][1]["sku"].to() == "BL4438H"); - YAML_ASSERT(doc["product"][1]["quantity"].to() == 1); - YAML_ASSERT(doc["product"][1]["description"].to() == "Super Hoop"); - YAML_ASSERT(doc["product"][1]["price"].to() == "2392.00"); - YAML_ASSERT(doc["tax"].to() == "251.42"); - YAML_ASSERT(doc["total"].to() == "4443.52"); - YAML_ASSERT(doc["comments"].to() == "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338."); - return true; - } - - // 2.28 - TEST LogFile() - { - PARSE(doc, ex2_28); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc["Time"].to() == "2001-11-23 15:01:42 -5"); - YAML_ASSERT(doc["User"].to() == "ed"); - YAML_ASSERT(doc["Warning"].to() == "This is an error message for the log file"); - - PARSE_NEXT(doc); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc["Time"].to() == "2001-11-23 15:02:31 -5"); - YAML_ASSERT(doc["User"].to() == "ed"); - YAML_ASSERT(doc["Warning"].to() == "A slightly different error message."); - - PARSE_NEXT(doc); - YAML_ASSERT(doc.size() == 4); - YAML_ASSERT(doc["Date"].to() == "2001-11-23 15:03:17 -5"); - YAML_ASSERT(doc["User"].to() == "ed"); - YAML_ASSERT(doc["Fatal"].to() == "Unknown variable \"bar\""); - YAML_ASSERT(doc["Stack"].size() == 2); - YAML_ASSERT(doc["Stack"][0].size() == 3); - YAML_ASSERT(doc["Stack"][0]["file"].to() == "TopClass.py"); - YAML_ASSERT(doc["Stack"][0]["line"].to() == "23"); - YAML_ASSERT(doc["Stack"][0]["code"].to() == "x = MoreObject(\"345\\n\")\n"); - YAML_ASSERT(doc["Stack"][1].size() == 3); - YAML_ASSERT(doc["Stack"][1]["file"].to() == "MoreClass.py"); - YAML_ASSERT(doc["Stack"][1]["line"].to() == "58"); - YAML_ASSERT(doc["Stack"][1]["code"].to() == "foo = bar"); - return true; - } - - // TODO: 5.1 - 5.2 BOM - - // 5.3 - TEST BlockStructureIndicators() - { - PARSE(doc, ex5_3); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc["sequence"].size() == 2); - YAML_ASSERT(doc["sequence"][0].to() == "one"); - YAML_ASSERT(doc["sequence"][1].to() == "two"); - YAML_ASSERT(doc["mapping"].size() == 2); - YAML_ASSERT(doc["mapping"]["sky"].to() == "blue"); - YAML_ASSERT(doc["mapping"]["sea"].to() == "green"); - return true; - } - - // 5.4 - TEST FlowStructureIndicators() - { - PARSE(doc, ex5_4); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc["sequence"].size() == 2); - YAML_ASSERT(doc["sequence"][0].to() == "one"); - YAML_ASSERT(doc["sequence"][1].to() == "two"); - YAML_ASSERT(doc["mapping"].size() == 2); - YAML_ASSERT(doc["mapping"]["sky"].to() == "blue"); - YAML_ASSERT(doc["mapping"]["sea"].to() == "green"); - return true; - } - - // 5.5 - TEST CommentIndicator() - { - PARSE(doc, ex5_5); - YAML_ASSERT(doc.size() == 0); - return true; - } - - // 5.6 - TEST NodePropertyIndicators() - { - PARSE(doc, ex5_6); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc["anchored"].to() == "value"); // TODO: assert tag - YAML_ASSERT(doc["alias"].to() == "value"); - return true; - } - - // 5.7 - TEST BlockScalarIndicators() - { - PARSE(doc, ex5_7); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc["literal"].to() == "some\ntext\n"); - YAML_ASSERT(doc["folded"].to() == "some text\n"); - return true; - } - - // 5.8 - TEST QuotedScalarIndicators() - { - PARSE(doc, ex5_8); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc["single"].to() == "text"); - YAML_ASSERT(doc["double"].to() == "text"); - return true; - } - - // TODO: 5.9 directive - // TODO: 5.10 reserved indicator - - // 5.11 - TEST LineBreakCharacters() - { - PARSE(doc, ex5_11); - YAML_ASSERT(doc.to() == "Line break (no glyph)\nLine break (glyphed)\n"); - return true; - } - - // 5.12 - TEST TabsAndSpaces() - { - PARSE(doc, ex5_12); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc["quoted"].to() == "Quoted\t"); - YAML_ASSERT(doc["block"].to() == - "void main() {\n" - "\tprintf(\"Hello, world!\\n\");\n" - "}"); - return true; - } - - // 5.13 - TEST EscapedCharacters() - { - PARSE(doc, ex5_13); - YAML_ASSERT(doc.to() == "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() - { - std::stringstream stream(ex5_14); - try { - YAML::Parser parser(stream); - YAML::Node doc; - parser.GetNextDocument(doc); - } catch(const YAML::ParserException& e) { - YAML_ASSERT(e.msg == std::string(YAML::ErrorMsg::INVALID_ESCAPE) + "c"); - return true; - } - - return false; - } - - // 6.1 - TEST IndentationSpaces() - { - PARSE(doc, ex6_1); - YAML_ASSERT(doc.size() == 1); - YAML_ASSERT(doc["Not indented"].size() == 2); - YAML_ASSERT(doc["Not indented"]["By one space"].to() == "By four\n spaces\n"); - YAML_ASSERT(doc["Not indented"]["Flow style"].size() == 3); - YAML_ASSERT(doc["Not indented"]["Flow style"][0].to() == "By two"); - YAML_ASSERT(doc["Not indented"]["Flow style"][1].to() == "Also by two"); - YAML_ASSERT(doc["Not indented"]["Flow style"][2].to() == "Still by two"); - return true; - } - - // 6.2 - TEST IndentationIndicators() - { - PARSE(doc, ex6_2); - YAML_ASSERT(doc.size() == 1); - YAML_ASSERT(doc["a"].size() == 2); - YAML_ASSERT(doc["a"][0].to() == "b"); - YAML_ASSERT(doc["a"][1].size() == 2); - YAML_ASSERT(doc["a"][1][0].to() == "c"); - YAML_ASSERT(doc["a"][1][1].to() == "d"); - return true; - } - - // 6.3 - TEST SeparationSpaces() - { - PARSE(doc, ex6_3); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc[0].size() == 1); - YAML_ASSERT(doc[0]["foo"].to() == "bar"); - YAML_ASSERT(doc[1].size() == 2); - YAML_ASSERT(doc[1][0].to() == "baz"); - YAML_ASSERT(doc[1][1].to() == "baz"); - return true; - } - - // 6.4 - TEST LinePrefixes() - { - PARSE(doc, ex6_4); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc["plain"].to() == "text lines"); - YAML_ASSERT(doc["quoted"].to() == "text lines"); - YAML_ASSERT(doc["block"].to() == "text\n \tlines\n"); - return true; - } - - // 6.5 - TEST EmptyLines() - { - PARSE(doc, ex6_5); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc["Folding"].to() == "Empty line\nas a line feed"); - YAML_ASSERT(doc["Chomping"].to() == "Clipped empty lines\n"); - return true; - } - - // 6.6 - TEST LineFolding() - { - PARSE(doc, ex6_6); - YAML_ASSERT(doc.to() == "trimmed\n\n\nas space"); - return true; - } - - // 6.7 - TEST BlockFolding() - { - PARSE(doc, ex6_7); - YAML_ASSERT(doc.to() == "foo \n\n\t bar\n\nbaz\n"); - return true; - } - - // 6.8 - TEST FlowFolding() - { - PARSE(doc, ex6_8); - YAML_ASSERT(doc.to() == " foo\nbar\nbaz "); - return true; - } - - // 6.9 - TEST SeparatedComment() - { - PARSE(doc, ex6_9); - YAML_ASSERT(doc.size() == 1); - YAML_ASSERT(doc["key"].to() == "value"); - return true; - } - - // 6.10 - TEST CommentLines() - { - PARSE(doc, ex6_10); - YAML_ASSERT(doc.size() == 0); - return true; - } - - // 6.11 - TEST MultiLineComments() - { - PARSE(doc, ex6_11); - YAML_ASSERT(doc.size() == 1); - YAML_ASSERT(doc["key"].to() == "value"); - return true; - } - - struct StringMap { - typedef std::map Map; - Map _; - }; - - bool operator == (const StringMap& m, const StringMap& n) { - return m._ == n._; - } - - void operator >> (const YAML::Node& node, StringMap& m) { - m._.clear(); - for(YAML::Iterator it=node.begin();it!=node.end();++it) { - std::string key = it.first().to(); - std::string value = it.second().to(); - m._[key] = value; - } - } - - - // 6.12 - TEST SeparationSpacesII() - { - PARSE(doc, ex6_12); - std::map key; - key["first"] = "Sammy"; - key["last"] = "Sosa"; - YAML_ASSERT(doc.size() == 1); - YAML_ASSERT(doc[key].size() == 2); - YAML_ASSERT(doc[key]["hr"].to() == 65); - YAML_ASSERT(doc[key]["avg"].to() == "0.278"); - return true; - } - - // 6.13 - TEST ReservedDirectives() - { - PARSE(doc, ex6_13); - return true; - } - - // 6.14 - TEST YAMLDirective() - { - PARSE(doc, ex6_14); - return true; - } - - // 6.15 - TEST InvalidRepeatedYAMLDirective() - { - try { - PARSE(doc, ex6_15); - } catch(const YAML::ParserException& e) { - if(e.msg == YAML::ErrorMsg::REPEATED_YAML_DIRECTIVE) - return true; - - throw; - } - - return " No exception was thrown"; - } - - // 6.16 - TEST TagDirective() - { - PARSE(doc, ex6_16); - YAML_ASSERT(doc.Tag() == "tag:yaml.org,2002:str"); - YAML_ASSERT(doc.to() == "foo"); - return true; - } - - // 6.17 - TEST InvalidRepeatedTagDirective() - { - try { - PARSE(doc, ex6_17); - } 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() - { - PARSE(doc, ex6_18); - YAML_ASSERT(doc.Tag() == "!foo"); - YAML_ASSERT(doc.to() == "bar"); - - PARSE_NEXT(doc); - YAML_ASSERT(doc.Tag() == "tag:example.com,2000:app/foo"); - YAML_ASSERT(doc.to() == "bar"); - return true; - } - - // 6.19 - TEST SecondaryTagHandle() - { - PARSE(doc, ex6_19); - YAML_ASSERT(doc.Tag() == "tag:example.com,2000:app/int"); - YAML_ASSERT(doc.to() == "1 - 3"); - return true; - } - - // 6.20 - TEST TagHandles() - { - PARSE(doc, ex6_20); - YAML_ASSERT(doc.Tag() == "tag:example.com,2000:app/foo"); - YAML_ASSERT(doc.to() == "bar"); - return true; - } - - // 6.21 - TEST LocalTagPrefix() - { - PARSE(doc, ex6_21); - YAML_ASSERT(doc.Tag() == "!my-light"); - YAML_ASSERT(doc.to() == "fluorescent"); - - PARSE_NEXT(doc); - YAML_ASSERT(doc.Tag() == "!my-light"); - YAML_ASSERT(doc.to() == "green"); - return true; - } - - // 6.22 - TEST GlobalTagPrefix() - { - PARSE(doc, ex6_22); - YAML_ASSERT(doc.size() == 1); - YAML_ASSERT(doc[0].Tag() == "tag:example.com,2000:app/foo"); - YAML_ASSERT(doc[0].to() == "bar"); - return true; - } - - // 6.23 - TEST NodeProperties() - { - PARSE(doc, ex6_23); - YAML_ASSERT(doc.size() == 2); - for(YAML::Iterator it=doc.begin();it!=doc.end();++it) { - if(it.first().to() == "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().to() == "bar"); - } else if(it.first().to() == "baz") { - YAML_ASSERT(it.second().to() == "foo"); - } else - return " unknown key"; - } - - return true; - } - - // 6.24 - TEST VerbatimTags() - { - PARSE(doc, ex6_24); - YAML_ASSERT(doc.size() == 1); - for(YAML::Iterator it=doc.begin();it!=doc.end();++it) { - YAML_ASSERT(it.first().Tag() == "tag:yaml.org,2002:str"); - YAML_ASSERT(it.first().to() == "foo"); - YAML_ASSERT(it.second().Tag() == "!bar"); - YAML_ASSERT(it.second().to() == "baz"); - } - return true; - } - - // 6.25 - TEST InvalidVerbatimTags() - { - PARSE(doc, ex6_25); - return " not implemented yet"; // TODO: check tags (but we probably will say these are valid, I think) - } - - // 6.26 - TEST TagShorthands() - { - PARSE(doc, ex6_26); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc[0].Tag() == "!local"); - YAML_ASSERT(doc[0].to() == "foo"); - YAML_ASSERT(doc[1].Tag() == "tag:yaml.org,2002:str"); - YAML_ASSERT(doc[1].to() == "bar"); - YAML_ASSERT(doc[2].Tag() == "tag:example.com,2000:app/tag%21"); - YAML_ASSERT(doc[2].to() == "baz"); - return true; - } - - // 6.27 - TEST InvalidTagShorthands() - { - bool threw = false; - try { - PARSE(doc, ex6_27a); - } catch(const YAML::ParserException& e) { - threw = true; - if(e.msg != YAML::ErrorMsg::TAG_WITH_NO_SUFFIX) - throw; - } - - if(!threw) - return " No exception was thrown for a tag with no suffix"; - - PARSE(doc, ex6_27b); // TODO: should we reject this one (since !h! is not declared)? - return " not implemented yet"; - } - - // 6.28 - TEST NonSpecificTags() - { - PARSE(doc, ex6_28); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc[0].to() == "12"); // TODO: check tags. How? - YAML_ASSERT(doc[1].to() == 12); - YAML_ASSERT(doc[2].to() == "12"); - return true; - } - - // 6.29 - TEST NodeAnchors() - { - PARSE(doc, ex6_29); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc["First occurrence"].to() == "Value"); - YAML_ASSERT(doc["Second occurrence"].to() == "Value"); - return true; - } - - // 7.1 - TEST AliasNodes() - { - PARSE(doc, ex7_1); - YAML_ASSERT(doc.size() == 4); - YAML_ASSERT(doc["First occurrence"].to() == "Foo"); - YAML_ASSERT(doc["Second occurrence"].to() == "Foo"); - YAML_ASSERT(doc["Override anchor"].to() == "Bar"); - YAML_ASSERT(doc["Reuse anchor"].to() == "Bar"); - return true; - } - - // 7.2 - TEST EmptyNodes() - { - PARSE(doc, ex7_2); - YAML_ASSERT(doc.size() == 2); - for(YAML::Iterator it=doc.begin();it!=doc.end();++it) { - if(it.first().to() == "foo") { - YAML_ASSERT(it.second().Tag() == "tag:yaml.org,2002:str"); - YAML_ASSERT(it.second().to() == ""); - } else if(it.first().to() == "") { - YAML_ASSERT(it.first().Tag() == "tag:yaml.org,2002:str"); - YAML_ASSERT(it.second().to() == "bar"); - } else - return " unexpected key"; - } - return true; - } - - // 7.3 - TEST CompletelyEmptyNodes() - { - PARSE(doc, ex7_3); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(IsNull(doc["foo"])); - YAML_ASSERT(doc[YAML::Null].to() == "bar"); - return true; - } - - // 7.4 - TEST DoubleQuotedImplicitKeys() - { - PARSE(doc, 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"].to() == "value"); - return true; - } - - // 7.5 - TEST DoubleQuotedLineBreaks() - { - PARSE(doc, ex7_5); - YAML_ASSERT(doc.to() == "folded to a space,\nto a line feed, or \t \tnon-content"); - return true; - } - - // 7.6 - TEST DoubleQuotedLines() - { - PARSE(doc, ex7_6); - YAML_ASSERT(doc.to() == " 1st non-empty\n2nd non-empty 3rd non-empty "); - return true; - } - - // 7.7 - TEST SingleQuotedCharacters() - { - PARSE(doc, ex7_7); - YAML_ASSERT(doc.to() == "here's to \"quotes\""); - return true; - } - - // 7.8 - TEST SingleQuotedImplicitKeys() - { - PARSE(doc, 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"].to() == "value"); - return true; - } - - // 7.9 - TEST SingleQuotedLines() - { - PARSE(doc, ex7_9); - YAML_ASSERT(doc.to() == " 1st non-empty\n2nd non-empty 3rd non-empty "); - return true; - } - - // 7.10 - TEST PlainCharacters() - { - PARSE(doc, ex7_10); - YAML_ASSERT(doc.size() == 6); - YAML_ASSERT(doc[0].to() == "::vector"); - YAML_ASSERT(doc[1].to() == ": - ()"); - YAML_ASSERT(doc[2].to() == "Up, up, and away!"); - YAML_ASSERT(doc[3].to() == -123); - YAML_ASSERT(doc[4].to() == "http://example.com/foo#bar"); - YAML_ASSERT(doc[5].size() == 5); - YAML_ASSERT(doc[5][0].to() == "::vector"); - YAML_ASSERT(doc[5][1].to() == ": - ()"); - YAML_ASSERT(doc[5][2].to() == "Up, up, and away!"); - YAML_ASSERT(doc[5][3].to() == -123); - YAML_ASSERT(doc[5][4].to() == "http://example.com/foo#bar"); - return true; - } - - // 7.11 - TEST PlainImplicitKeys() - { - PARSE(doc, 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"].to() == "value"); - return true; - } - - // 7.12 - TEST PlainLines() - { - PARSE(doc, ex7_12); - YAML_ASSERT(doc.to() == "1st non-empty\n2nd non-empty 3rd non-empty"); - return true; - } - - // 7.13 - TEST FlowSequence() - { - PARSE(doc, ex7_13); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc[0].size() == 2); - YAML_ASSERT(doc[0][0].to() == "one"); - YAML_ASSERT(doc[0][1].to() == "two"); - YAML_ASSERT(doc[1].size() == 2); - YAML_ASSERT(doc[1][0].to() == "three"); - YAML_ASSERT(doc[1][1].to() == "four"); - return true; - } - - // 7.14 - TEST FlowSequenceEntries() - { - PARSE(doc, ex7_14); - YAML_ASSERT(doc.size() == 5); - YAML_ASSERT(doc[0].to() == "double quoted"); - YAML_ASSERT(doc[1].to() == "single quoted"); - YAML_ASSERT(doc[2].to() == "plain text"); - YAML_ASSERT(doc[3].size() == 1); - YAML_ASSERT(doc[3][0].to() == "nested"); - YAML_ASSERT(doc[4].size() == 1); - YAML_ASSERT(doc[4]["single"].to() == "pair"); - return true; - } - - // 7.15 - TEST FlowMappings() - { - PARSE(doc, ex7_15); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc[0].size() == 2); - YAML_ASSERT(doc[0]["one"].to() == "two"); - YAML_ASSERT(doc[0]["three"].to() == "four"); - YAML_ASSERT(doc[1].size() == 2); - YAML_ASSERT(doc[1]["five"].to() == "six"); - YAML_ASSERT(doc[1]["seven"].to() == "eight"); - return true; - } - - // 7.16 - TEST FlowMappingEntries() - { - PARSE(doc, ex7_16); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc["explicit"].to() == "entry"); - YAML_ASSERT(doc["implicit"].to() == "entry"); - YAML_ASSERT(IsNull(doc[YAML::Null])); - return true; - } - - // 7.17 - TEST FlowMappingSeparateValues() - { - PARSE(doc, ex7_17); - YAML_ASSERT(doc.size() == 4); - YAML_ASSERT(doc["unquoted"].to() == "separate"); - YAML_ASSERT(IsNull(doc["http://foo.com"])); - YAML_ASSERT(IsNull(doc["omitted value"])); - YAML_ASSERT(doc[YAML::Null].to() == "omitted key"); - return true; - } - - // 7.18 - TEST FlowMappingAdjacentValues() - { - PARSE(doc, ex7_18); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc["adjacent"].to() == "value"); - YAML_ASSERT(doc["readable"].to() == "value"); - YAML_ASSERT(IsNull(doc["empty"])); - return true; - } - - // 7.19 - TEST SinglePairFlowMappings() - { - PARSE(doc, ex7_19); - YAML_ASSERT(doc.size() == 1); - YAML_ASSERT(doc[0].size() == 1); - YAML_ASSERT(doc[0]["foo"].to() == "bar"); - return true; - } - - // 7.20 - TEST SinglePairExplicitEntry() - { - PARSE(doc, ex7_20); - YAML_ASSERT(doc.size() == 1); - YAML_ASSERT(doc[0].size() == 1); - YAML_ASSERT(doc[0]["foo bar"].to() == "baz"); - return true; - } - - // 7.21 - TEST SinglePairImplicitEntries() - { - PARSE(doc, ex7_21); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc[0].size() == 1); - YAML_ASSERT(doc[0][0].size() == 1); - YAML_ASSERT(doc[0][0]["YAML"].to() == "separate"); - YAML_ASSERT(doc[1].size() == 1); - YAML_ASSERT(doc[1][0].size() == 1); - YAML_ASSERT(doc[1][0][YAML::Null].to() == "empty key entry"); - YAML_ASSERT(doc[2].size() == 1); - YAML_ASSERT(doc[2][0].size() == 1); - StringMap key; - key._["JSON"] = "like"; - YAML_ASSERT(doc[2][0][key].to() == "adjacent"); - return true; - } - - // 7.22 - TEST InvalidImplicitKeys() - { - try { - PARSE(doc, ex7_22); - } 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() - { - PARSE(doc, ex7_23); - YAML_ASSERT(doc.size() == 5); - YAML_ASSERT(doc[0].size() == 2); - YAML_ASSERT(doc[0][0].to() == "a"); - YAML_ASSERT(doc[0][1].to() == "b"); - YAML_ASSERT(doc[1].size() == 1); - YAML_ASSERT(doc[1]["a"].to() == "b"); - YAML_ASSERT(doc[2].to() == "a"); - YAML_ASSERT(doc[3].to() == 'b'); - YAML_ASSERT(doc[4].to() == "c"); - return true; - } - - // 7.24 - TEST FlowNodes() - { - PARSE(doc, ex7_24); - YAML_ASSERT(doc.size() == 5); - YAML_ASSERT(doc[0].Tag() == "tag:yaml.org,2002:str"); - YAML_ASSERT(doc[0].to() == "a"); - YAML_ASSERT(doc[1].to() == 'b'); - YAML_ASSERT(doc[2].to() == "c"); - YAML_ASSERT(doc[3].to() == "c"); - YAML_ASSERT(doc[4].Tag() == "tag:yaml.org,2002:str"); - YAML_ASSERT(doc[4].to() == ""); - return true; - } - - // 8.1 - TEST BlockScalarHeader() - { - PARSE(doc, ex8_1); - YAML_ASSERT(doc.size() == 4); - YAML_ASSERT(doc[0].to() == "literal\n"); - YAML_ASSERT(doc[1].to() == " folded\n"); - YAML_ASSERT(doc[2].to() == "keep\n\n"); - YAML_ASSERT(doc[3].to() == " strip"); - return true; - } - - // 8.2 - TEST BlockIndentationHeader() - { - PARSE(doc, ex8_2); - YAML_ASSERT(doc.size() == 4); - YAML_ASSERT(doc[0].to() == "detected\n"); - YAML_ASSERT(doc[1].to() == "\n\n# detected\n"); - YAML_ASSERT(doc[2].to() == " explicit\n"); - YAML_ASSERT(doc[3].to() == "\t\ndetected\n"); - return true; - } - - // 8.3 - TEST InvalidBlockScalarIndentationIndicators() - { - { - bool threw = false; - try { - PARSE(doc, ex8_3a); - } 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"; - } - - { - bool threw = false; - try { - PARSE(doc, ex8_3b); - } 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"; - } - - { - bool threw = false; - try { - PARSE(doc, ex8_3c); - } 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"; - } - - return true; - } - - // 8.4 - TEST ChompingFinalLineBreak() - { - PARSE(doc, ex8_4); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc["strip"].to() == "text"); - YAML_ASSERT(doc["clip"].to() == "text\n"); - YAML_ASSERT(doc["keep"].to() == "text\n"); - return true; - } - - // 8.5 - TEST ChompingTrailingLines() - { - PARSE(doc, ex8_5); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc["strip"].to() == "# text"); - YAML_ASSERT(doc["clip"].to() == "# text\n"); - YAML_ASSERT(doc["keep"].to() == "# 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() - { - PARSE(doc, ex8_6); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc["strip"].to() == ""); - YAML_ASSERT(doc["clip"].to() == ""); - YAML_ASSERT(doc["keep"].to() == "\n"); - return true; - } - - // 8.7 - TEST LiteralScalar() - { - PARSE(doc, ex8_7); - YAML_ASSERT(doc.to() == "literal\n\ttext\n"); - return true; - } - - // 8.8 - TEST LiteralContent() - { - PARSE(doc, ex8_8); - YAML_ASSERT(doc.to() == "\n\nliteral\n \n\ntext\n"); - return true; - } - - // 8.9 - TEST FoldedScalar() - { - PARSE(doc, ex8_9); - YAML_ASSERT(doc.to() == "folded text\n"); - return true; - } - - // 8.10 - TEST FoldedLines() - { - PARSE(doc, ex8_10); - YAML_ASSERT(doc.to() == "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n"); - return true; - } - - // 8.11 - TEST MoreIndentedLines() - { - return true; // same as 8.10 - } - - // 8.12 - TEST EmptySeparationLines() - { - return true; // same as 8.10 - } - - // 8.13 - TEST FinalEmptyLines() - { - return true; // same as 8.10 - } - - // 8.14 - TEST BlockSequence() - { - PARSE(doc, ex8_14); - YAML_ASSERT(doc.size() == 1); - YAML_ASSERT(doc["block sequence"].size() == 2); - YAML_ASSERT(doc["block sequence"][0].to() == "one"); - YAML_ASSERT(doc["block sequence"][1].size() == 1); - YAML_ASSERT(doc["block sequence"][1]["two"].to() == "three"); - return true; - } - - // 8.15 - TEST BlockSequenceEntryTypes() - { - PARSE(doc, ex8_15); - YAML_ASSERT(doc.size() == 4); - YAML_ASSERT(YAML::IsNull(doc[0])); - YAML_ASSERT(doc[1].to() == "block node\n"); - YAML_ASSERT(doc[2].size() == 2); - YAML_ASSERT(doc[2][0].to() == "one"); - YAML_ASSERT(doc[2][1].to() == "two"); - YAML_ASSERT(doc[3].size() == 1); - YAML_ASSERT(doc[3]["one"].to() == "two"); - return true; - } - - // 8.16 - TEST BlockMappings() - { - PARSE(doc, ex8_16); - YAML_ASSERT(doc.size() == 1); - YAML_ASSERT(doc["block mapping"].size() == 1); - YAML_ASSERT(doc["block mapping"]["key"].to() == "value"); - return true; - } - - // 8.17 - TEST ExplicitBlockMappingEntries() - { - PARSE(doc, ex8_17); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(IsNull(doc["explicit key"])); - YAML_ASSERT(doc["block key\n"].size() == 2); - YAML_ASSERT(doc["block key\n"][0].to() == "one"); - YAML_ASSERT(doc["block key\n"][1].to() == "two"); - return true; - } - - // 8.18 - TEST ImplicitBlockMappingEntries() - { - PARSE(doc, ex8_18); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc["plain key"].to() == "in-line value"); - YAML_ASSERT(IsNull(doc[YAML::Null])); - YAML_ASSERT(doc["quoted key"].size() == 1); - YAML_ASSERT(doc["quoted key"][0].to() == "entry"); - return true; - } - - // 8.19 - TEST CompactBlockMappings() - { - PARSE(doc, ex8_19); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc[0].size() == 1); - YAML_ASSERT(doc[0]["sun"].to() == "yellow"); - YAML_ASSERT(doc[1].size() == 1); - std::map key; - key["earth"] = "blue"; - YAML_ASSERT(doc[1][key].size() == 1); - YAML_ASSERT(doc[1][key]["moon"].to() == "white"); - return true; - } - - // 8.20 - TEST BlockNodeTypes() - { - PARSE(doc, ex8_20); - YAML_ASSERT(doc.size() == 3); - YAML_ASSERT(doc[0].to() == "flow in block"); - YAML_ASSERT(doc[1].to() == "Block scalar\n"); - YAML_ASSERT(doc[2].size() == 1); - YAML_ASSERT(doc[2]["foo"].to() == "bar"); - return true; - } - - // 8.21 - TEST BlockScalarNodes() - { - PARSE(doc, ex8_21); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc["literal"].to() == "value"); // Note: I believe this is a bug in the YAML spec - it should be "value\n" - YAML_ASSERT(doc["folded"].to() == "value"); - YAML_ASSERT(doc["folded"].Tag() == "!foo"); - return true; - } - - // 8.22 - TEST BlockCollectionNodes() - { - PARSE(doc, ex8_22); - YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc["sequence"].size() == 2); - YAML_ASSERT(doc["sequence"][0].to() == "entry"); - YAML_ASSERT(doc["sequence"][1].size() == 1); - YAML_ASSERT(doc["sequence"][1][0].to() == "nested"); - YAML_ASSERT(doc["mapping"].size() == 1); - YAML_ASSERT(doc["mapping"]["foo"].to() == "bar"); - return true; - } - } -} diff --git a/test/tests.cpp b/test/tests.cpp index 9f77569..efe82fc 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -23,11 +23,9 @@ namespace Test if(!RunSpecTests()) passed = false; -#ifndef YAML_CPP_OLD_API if(!RunNodeTests()) passed = false; -#endif - + if(passed) std::cout << "All tests passed!\n"; } diff --git a/util/parse.cpp b/util/parse.cpp index 1187fd3..ca112e0 100644 --- a/util/parse.cpp +++ b/util/parse.cpp @@ -37,18 +37,8 @@ public: void parse(std::istream& input) { try { -#ifdef YAML_CPP_OLD_API - YAML::Parser parser(input); - YAML::Node doc; - while(parser.GetNextDocument(doc)) { - YAML::Emitter emitter; - emitter << doc; - std::cout << emitter.c_str() << "\n"; - } -#else YAML::Node doc = YAML::Load(input); std::cout << doc << "\n"; -#endif } catch(const YAML::Exception& e) { std::cerr << e.what() << "\n"; }