diff --git a/Makefile.config.in b/Makefile.config.in index 3100d2073..d25ff3e98 100644 --- a/Makefile.config.in +++ b/Makefile.config.in @@ -28,6 +28,7 @@ LOWDOWN_LIBS = @LOWDOWN_LIBS@ OPENSSL_LIBS = @OPENSSL_LIBS@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_VERSION = @PACKAGE_VERSION@ +RYML_LIBS = @RYML_LIBS@ SHELL = @bash@ SODIUM_LIBS = @SODIUM_LIBS@ SQLITE3_LIBS = @SQLITE3_LIBS@ diff --git a/configure.ac b/configure.ac index 198198dea..cf17d6acd 100644 --- a/configure.ac +++ b/configure.ac @@ -269,6 +269,29 @@ AS_CASE(["$readline_flavor"], [AC_MSG_ERROR([bad value "$readline_flavor" for --with-readline-flavor, must be one of: editline, readline])]) PKG_CHECK_MODULES([EDITLINE], [$readline_flavor_pc], [CXXFLAGS="$EDITLINE_CFLAGS $CXXFLAGS"]) +# Look for rapidyaml. +have_ryml= +AC_ARG_ENABLE([ryml], AS_HELP_STRING([--disable-ryml], [Do not enable rapidyaml and disable builtins.fromYAML]), [], [have_ryml=1]) +AC_ARG_VAR([RYML_CPPFLAGS], [C/C++ preprocessor flags for RAPIDYAML]) +AC_ARG_VAR([RYML_LDFLAGS], [linker flags for RAPIDYAML]) +if test "x$have_ryml" != "x"; then + AC_LANG_PUSH([C++]) + # append RYML_CPPFLAGS to CXXFLAGS because CPPFLAGS are not passed to the C++ compiler + CXXFLAGS="$RYML_CPPFLAGS $CXXFLAGS" + LDFLAGS="$RYML_LDFLAGS $RYML_LDFLAGS" + LIBS="-lryml $LIBS" + AC_CHECK_HEADERS([ryml.hpp], [true], + [AC_MSG_ERROR([Header of libryml is not found.])]) + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ + #include + ]], [[ryml::Tree tree;]])], + [AC_DEFINE([HAVE_RYML], [1], [Use rapidyaml]) + AC_SUBST(RYML_LIBS, [-lryml])], + [AC_MSG_ERROR([libryml is not found.])]) + AC_LANG_POP([C++]) +fi +AC_SUBST(HAVE_RYML, [$have_ryml]) + # Look for libsodium. PKG_CHECK_MODULES([SODIUM], [libsodium], [CXXFLAGS="$SODIUM_CFLAGS $CXXFLAGS"]) diff --git a/package.nix b/package.nix index 8ab184667..b8d86e73a 100644 --- a/package.nix +++ b/package.nix @@ -31,6 +31,7 @@ , openssl , pkg-config , rapidcheck +, rapidyaml , sqlite , toml11 , unixtools @@ -224,6 +225,7 @@ in { libgit2 libsodium openssl + rapidyaml sqlite toml11 xz diff --git a/packaging/dependencies.nix b/packaging/dependencies.nix index e5f4c0f91..03d939728 100644 --- a/packaging/dependencies.nix +++ b/packaging/dependencies.nix @@ -164,6 +164,26 @@ scope: { ''; }); + rapidyaml = pkgs.rapidyaml.overrideAttrs(old: let + version = "0.7.2"; + hash = "sha256-vAYafhWo9xavM2j+mT3OGcX7ZSS25mieR/3b79BO+jA="; + in { + inherit version; + + src = pkgs.fetchFromGitHub { + inherit hash; + owner = "biojppm"; + repo = old.pname; + rev = "v${version}"; + fetchSubmodules = true; + }; + + cmakeFlags = [ + "-DRYML_WITH_TAB_TOKENS=ON" + ]; + }); + + # TODO change in Nixpkgs, Windows works fine. First commit of # https://github.com/NixOS/nixpkgs/pull/322977 backported will fix. toml11 = pkgs.toml11.overrideAttrs (old: { diff --git a/src/libexpr/json-to-value-sax.hh b/src/libexpr/json-to-value-sax.hh new file mode 100644 index 000000000..c994a82fb --- /dev/null +++ b/src/libexpr/json-to-value-sax.hh @@ -0,0 +1,17 @@ +#pragma once +///@file + +#include +#include + +#include "json-to-value.hh" + +/** + * json_sax and unique_ptr require the inclusion of json.hpp, so this header shall not be included by other headers + **/ + +namespace nix { + +std::unique_ptr> makeJSONSaxParser(EvalState & s, Value & v); + +} diff --git a/src/libexpr/json-to-value.cc b/src/libexpr/json-to-value.cc index 9ac56541a..9f552a218 100644 --- a/src/libexpr/json-to-value.cc +++ b/src/libexpr/json-to-value.cc @@ -1,10 +1,8 @@ -#include "json-to-value.hh" +#include "json-to-value-sax.hh" #include "value.hh" #include "eval.hh" #include -#include -#include using json = nlohmann::json; @@ -12,7 +10,7 @@ namespace nix { // for more information, refer to // https://github.com/nlohmann/json/blob/master/include/nlohmann/detail/input/json_sax.hpp -class JSONSax : nlohmann::json_sax { +class JSONSax : public nlohmann::json_sax { class JSONState { protected: std::unique_ptr parent; @@ -80,6 +78,7 @@ class JSONSax : nlohmann::json_sax { public: JSONSax(EvalState & state, Value & v) : state(state), rs(new JSONState(&v)) {}; + virtual ~JSONSax() = default; bool null() override { @@ -177,4 +176,8 @@ void parseJSON(EvalState & state, const std::string_view & s_, Value & v) throw JSONParseError("Invalid JSON Value"); } +std::unique_ptr> makeJSONSaxParser(EvalState & state, Value & v) { + return { std::make_unique(state, v) }; +} + } diff --git a/src/libexpr/local.mk b/src/libexpr/local.mk index 68518e184..d8d0e46ec 100644 --- a/src/libexpr/local.mk +++ b/src/libexpr/local.mk @@ -20,7 +20,7 @@ libexpr_CXXFLAGS += \ libexpr_LIBS = libutil libstore libfetchers -libexpr_LDFLAGS += -lboost_context $(THREAD_LDFLAGS) +libexpr_LDFLAGS += -lboost_context $(RYML_LIBS) $(THREAD_LDFLAGS) ifdef HOST_LINUX libexpr_LDFLAGS += -ldl endif diff --git a/src/libexpr/meson.build b/src/libexpr/meson.build index 4d8a38b43..8eace9c6d 100644 --- a/src/libexpr/meson.build +++ b/src/libexpr/meson.build @@ -56,6 +56,18 @@ if bdw_gc.found() endif configdata.set('HAVE_BOEHMGC', bdw_gc.found().to_int()) +ryml = dependency( + 'ryml', + version : '>=0.7.1', + method : 'cmake', + include_type : 'system', + required : false, +) +if ryml.found() + deps_other += ryml + configdata.set('HAVE_RYML', 1) +endif + toml11 = dependency( 'toml11', version : '>=3.7.0', @@ -172,6 +184,7 @@ headers = [config_h] + files( 'gc-small-vector.hh', 'get-drvs.hh', 'json-to-value.hh', + 'json-to-value-sax.hh', # internal: 'lexer-helpers.hh', 'nixexpr.hh', 'parser-state.hh', diff --git a/src/libexpr/package.nix b/src/libexpr/package.nix index 4d10079ff..81c6747e6 100644 --- a/src/libexpr/package.nix +++ b/src/libexpr/package.nix @@ -16,6 +16,7 @@ , boost , boehmgc , nlohmann_json +, rapidyaml , toml11 # Configuration Options @@ -70,6 +71,7 @@ mkMesonDerivation (finalAttrs: { ]; buildInputs = [ + rapidyaml toml11 ]; diff --git a/src/libexpr/primops/fromYAML.cc b/src/libexpr/primops/fromYAML.cc new file mode 100644 index 000000000..f064257f9 --- /dev/null +++ b/src/libexpr/primops/fromYAML.cc @@ -0,0 +1,392 @@ +#ifdef HAVE_RYML + +# include "primops.hh" +# include "eval-inline.hh" + +# include +# include +# include + +namespace { + +using namespace nix; + +/** + * Equality check of a compile time C-string *lhs* and another string *rhs*. + * Only call this function, if both strings have the same length. + */ +template +inline bool isEqualSameLengthStr(const char * rhs, const char lhs[N + 1]) +{ + bool result = true; + for (size_t i = 0; i < N; i++) { + result &= rhs[i] == lhs[i]; + } + return result; +} + +inline bool isNull(ryml::csubstr val) +{ + size_t len = val.size(); + return len == 0 || (len == 1 && val[0] == '~') + || (len == 4 && (val[0] == 'n' || val[0] == 'N') + && (isEqualSameLengthStr<3>(&val[1], "ull") || isEqualSameLengthStr<4>(&val[0], "NULL"))); +} + +bool isInt_1_2(ryml::csubstr val) +{ + bool result = val.is_integer(); + // ryml::from_chars accepts signed binary, octal and hexadecimal integers + // YAML 1.2 defines unsigned octal and hexadecimal integers (lower-case identifiers) + if (result && val.size() >= 3 + && ((val.begins_with_any("+-") && val.sub(2, 1).begins_with_any("xXoObB")) + || val.sub(1, 1).begins_with_any("XObB"))) { + result = false; + } + return result; +} + +/** + * Tries to parse a string into a floating point number according to the YAML 1.2 core schema, wrapping ryml::from_chars + */ +std::optional parseFloat(std::optional isInt, ryml::csubstr val) +{ + std::optional maybe_float; + NixFloat _float; + size_t len = val.size(); + // first character has to match [0-9+-.] + if (isInt.value_or(false)) { + NixInt::Inner _int; + if (len == 2 && isEqualSameLengthStr<2>(&val[0], "-0")) { + // valid int, so that it would be parsed as 0.0 otherwise + maybe_float = -0.0; + } else if (ryml::from_chars(val.sub(val[0] == '+'), &_int)) { + maybe_float.emplace(_int); + } + } else if (len >= 1 && val[0] >= '+' && val[0] <= '9' && val[0] != ',' && val[0] != '/') { + size_t skip = val[0] == '+' || val[0] == '-'; + if ((len == skip + 4) && val[skip + 0] == '.') { + auto sub = &val[skip + 1]; + if (skip == 0 + && (isEqualSameLengthStr<3>(sub, "nan") + || (sub[0] == 'N' && (sub[1] == 'a' || sub[1] == 'A') && sub[2] == 'N'))) { + maybe_float = std::numeric_limits::quiet_NaN(); + } else if ( + ((sub[0] == 'i' || sub[0] == 'I') && isEqualSameLengthStr<2>(sub + 1, "nf")) + || isEqualSameLengthStr<3>(sub, "INF")) { + NixFloat inf = std::numeric_limits::infinity(); + maybe_float = val[0] == '-' ? -inf : inf; + } + } + auto sub = &val[0] + 1; + if (len == skip + 3 && (isEqualSameLengthStr<3>(sub, "nan") || isEqualSameLengthStr<3>(sub, "inf"))) { + // ryml::from_chars converts "nan" and "inf" + } else if ( + !maybe_float && ((!isInt && val.is_number()) || (isInt && val.is_real())) + && val.sub(1, std::min(size_t(2), len - 1)).first_of("xXoObB") == ryml::npos + && ryml::from_chars(val.sub(val[0] == '+'), &_float)) { + // isInt => !*isInt because of (isInt && *isInt) == false) + maybe_float = _float; + } + } + return maybe_float; +} + +std::optional parseBool_1_2(ryml::csubstr val) +{ + std::optional _bool; + size_t len = val.size(); + if (len == 4 && (val[0] == 't' || val[0] == 'T')) { + if (isEqualSameLengthStr<3>(&val[1], "rue") || isEqualSameLengthStr<4>(&val[0], "TRUE")) { + _bool = true; + } + } else if (len == 5 && (val[0] == 'f' || val[0] == 'F')) { + if (isEqualSameLengthStr<4>(&val[1], "alse") || isEqualSameLengthStr<5>(&val[0], "FALSE")) { + _bool = false; + } + } + return _bool; +} + +std::optional parseBool_1_1(ryml::csubstr val) +{ + std::optional _bool; + switch (val.size()) { + case 1: + if (val[0] == 'n' || val[0] == 'N') { + _bool = false; + } else if (val[0] == 'y' || val[0] == 'Y') { + _bool = true; + } + break; + case 2: + // "no" or "on" + if (isEqualSameLengthStr<2>(&val[0], "no") || (val[0] == 'N' && (val[1] == 'o' || val[1] == 'O'))) { + _bool = false; + } else if (isEqualSameLengthStr<2>(&val[0], "on") || (val[0] == 'O' && (val[1] == 'n' || val[1] == 'N'))) { + _bool = true; + } + break; + case 3: + // "off" or "yes" + if (isEqualSameLengthStr<3>(&val[0], "off") + || (val[0] == 'O' && (isEqualSameLengthStr<2>(&val[1], "ff") || isEqualSameLengthStr<2>(&val[1], "FF")))) { + _bool = false; + } else if ( + isEqualSameLengthStr<3>(&val[0], "yes") + || (val[0] == 'Y' && (isEqualSameLengthStr<2>(&val[1], "es") || isEqualSameLengthStr<2>(&val[1], "ES")))) { + _bool = true; + } + break; + case 4: + case 5: + _bool = parseBool_1_2(val); + break; + default: + break; + } + return _bool; +} + +struct FromYAMLContext +{ + struct ParserOptions + { + bool useBoolYAML1_1 = false; + + ParserOptions(FromYAMLContext &, const Bindings *); + }; + + EvalState & state; + const PosIdx pos; + const std::string_view yaml; + const ParserOptions options; + + FromYAMLContext(EvalState &, PosIdx, std::string_view, const Bindings *); + + inline std::optional parseBool(ryml::csubstr val) const + { + std::optional result; + if (options.useBoolYAML1_1) { + result = parseBool_1_1(val); + } else { + result = parseBool_1_2(val); + } + return result; + } + + template + void throwError [[noreturn]] (const char * c_fs, const Args &... args) const + { + std::string fs = "while parsing the YAML string ''%1%'':\n\n"; + fs += c_fs; + throw EvalError(state, ErrorInfo{.msg = fmt(fs, yaml, args...), .pos = state.positions[pos]}); + } + + void visitYAMLNode(Value & v, ryml::ConstNodeRef t, bool isTopNode = false); +}; + +FromYAMLContext::FromYAMLContext(EvalState & state, PosIdx pos, std::string_view yaml, const Bindings * options) + : state(state) + , pos(pos) + , yaml(yaml) + , options(*this, options) +{ +} + +FromYAMLContext::ParserOptions::ParserOptions(FromYAMLContext & context, const Bindings * options) +{ + auto symbol = context.state.symbols.create("useBoolYAML1_1"); + const Attr * useBoolYAML1_1 = options->get(symbol); + if (useBoolYAML1_1) { + this->useBoolYAML1_1 = + context.state.forceBool(*useBoolYAML1_1->value, {}, "while evaluating the attribute \"useBoolYAML1_1\""); + } +} + +void s_error [[noreturn]] (const char * msg, size_t len, ryml::Location, void * fromYAMLContext) +{ + auto context = static_cast(fromYAMLContext); + if (context) { + context->throwError("%2%", std::string_view(msg, len)); + } else { + throw Error({.msg = fmt("failed assertion in rapidyaml library:\n\n%1%", std::string_view(msg, len))}); + } +} + +/** + * Parse YAML according to the YAML 1.2 core schema by default + * The behaviour can be modified by the FromYAMLOptions object in FromYAMLContext + */ +void FromYAMLContext::visitYAMLNode(Value & v, ryml::ConstNodeRef t, bool isTopNode) +{ + ryml::csubstr valTagStr; + auto valTag = ryml::TAG_NONE; + bool valTagCustom = t.has_val_tag(); + bool valTagNonSpecificStr = false; + if (valTagCustom) { + valTagStr = t.val_tag(); + if (!(valTagNonSpecificStr = valTagStr == "!")) { + valTag = ryml::to_tag(valTagStr); + valTagCustom = valTag == ryml::TAG_NONE; + if (valTagCustom) { + auto fs = "Error: Nix has no support for the unknown tag ''%2%'' in node ''%3%''"; + throwError(fs, valTagStr, t); + } + } + } + if (t.is_map()) { + if (valTag != ryml::TAG_NONE && valTag != ryml::TAG_MAP) { + auto fs = "Error: Nix parsed ''%2%'' as map and only supported is the tag ''!!map'', but ''%3%'' was used"; + throwError(fs, t, valTagStr); + } + auto attrs = state.buildBindings(t.num_children()); + + for (ryml::ConstNodeRef child : t.children()) { + auto key = child.key(); + if (child.has_key_tag()) { + auto tag = ryml::to_tag(child.key_tag()); + if (tag != ryml::TAG_NONE && tag != ryml::TAG_STR) { + auto fs = "Error: Nix supports string keys only, but the key ''%2%'' has the tag ''%3%''"; + throwError(fs, child.key(), child.key_tag()); + } + } else if (child.is_key_plain() && isNull(key)) { + auto fs = "Error: Nix supports string keys only, but the map ''%2%'' contains a null-key"; + throwError(fs, t); + } + visitYAMLNode(attrs.alloc({key.begin(), key.size()}), child); + } + + v.mkAttrs(attrs); + Symbol key; + // enforce uniqueness of keys + for (const auto & attr : *attrs.alreadySorted()) { + if (key == attr.name) { + auto fs = "Error: Non-unique key %2% after deserializing the map ''%3%''"; + throwError(fs, state.symbols[key], t); + } + key = attr.name; + } + } else if (t.is_seq()) { + if (valTag != ryml::TAG_NONE && valTag != ryml::TAG_SEQ) { + auto fs = + "Error: Nix parsed ''%2%'' as sequence and only supported is the tag ''!!seq'', but ''%3%'' was used"; + throwError(fs, t, valTagStr); + } + ListBuilder list(state, t.num_children()); + + bool isStream = t.is_stream(); + size_t i = 0; + for (ryml::ConstNodeRef child : t.children()) { + // a stream of documents is handled as sequence, too + visitYAMLNode(*(list[i++] = state.allocValue()), child, isTopNode && isStream); + } + v.mkList(list); + } else if (t.has_val()) { + auto val = t.val(); + bool isPlain = t.is_val_plain(); + bool isEmpty = isPlain && val.empty(); + if (isTopNode && isEmpty) { + throwError("Error: Empty document (plain empty scalars outside of collection)%2%", ""); + } + if (valTagNonSpecificStr) { + valTag = ryml::TAG_STR; + } + + auto scalarTypeCheck = [=](ryml::YamlTag_e tag) { return valTag == ryml::TAG_NONE ? isPlain : valTag == tag; }; + + // Caution: ryml::from_chars converts integers into booleans and also it might ignore trailing chars. + // Furthermore it doesn't accept a leading '+' character in integers + std::optional isInt; + std::optional _bool; + std::optional _float; + NixInt::Inner _int; + bool trim = valTag == ryml::TAG_NULL || valTag == ryml::TAG_BOOL || valTag == ryml::TAG_INT + || valTag == ryml::TAG_FLOAT; + auto vs = trim ? val.trim("\n\t ") : val; + if (scalarTypeCheck(ryml::TAG_NULL) && isNull(vs)) { + v.mkNull(); + } else if (scalarTypeCheck(ryml::TAG_BOOL) && (_bool = parseBool(vs))) { + v.mkBool(*_bool); + } else if ( + scalarTypeCheck(ryml::TAG_INT) && *(isInt = isInt_1_2(vs)) + && ryml::from_chars(vs.sub(vs[0] == '+'), &_int)) { + v.mkInt(_int); + } else if ( + ((valTag == ryml::TAG_FLOAT && (isInt = isInt_1_2(vs))) || (valTag == ryml::TAG_NONE && isPlain)) + && (_float = parseFloat(isInt, vs))) { + // if the value is tagged with !!float, then isInt_1_2 evaluation is enforced because the int regex is not a + // subset of the float regex... + v.mkFloat(*_float); + } else if ((valTag == ryml::TAG_NONE && !valTagCustom) || valTag == ryml::TAG_STR) { + std::string_view value(val.begin(), val.size()); + v.mkString(value); + } else { + throwError("Error: Value ''%2%'' with tag ''%3%'' is invalid", val, valTagStr); + } + } else { + auto val = t.has_val() ? t.val() : ""; + auto fs = "BUG: Encountered unreachable code while parsing ''%2%'' with tag ''%3%''"; + throwError(fs, val, valTagStr); + } +} + +} /* namespace */ + +namespace nix { + +static RegisterPrimOp primop_fromYAML( + {.name = "__fromYAML", + .args = {"e", "attrset"}, + .doc = R"( + Convert a YAML 1.2 string *e* to a Nix value, if a conversion is possible. + The second argument is an attribute set with optional parameters for the parser. + For example, + + ```nix + builtins.fromYAML ''{x: [1, 2, 3], y: !!str null, z: null}'' {} + ``` + + returns the value `{ x = [ 1 2 3 ]; y = "null"; z = null; }`. + + Maps are converted to attribute sets, but only strings are supported as keys. + + Scalars are converted to the type specified by their optional value tag. Parsing fails if a conversion is not possible. + Nix does not support all data types defined by the different YAML specs, e.g. Nix has no binary and timestamp data types. + Thus the types and tags defined by the YAML 1.2 core schema are used exclusively, i.e. untagged timestamps are parsed as strings. + Using any other tag fails. + A stream with multiple documents is mapped to a list except when the stream contains a single document. + + Supported optional parameters in *attrset*: + - useBoolYAML1_1 :: bool ? false: When enabled booleans are parsed according to the YAML 1.1 spec, which matches more values than YAML 1.2. + This option improves compatibility because many applications and configs are still using YAML 1.1 features. + )", + .fun = + [](EvalState & state, const PosIdx pos, Value ** args, Value & val) { + auto yaml = state.forceStringNoCtx( + *args[0], pos, "while evaluating the first argument passed to builtins.fromYAML"); + state.forceAttrs(*args[1], pos, "while evaluating the second argument passed to builtins.fromYAML"); + auto options = args[1]->attrs(); + + FromYAMLContext context(state, pos, yaml, options); + ryml::Callbacks callbacks; + callbacks.m_error = s_error; + ryml::set_callbacks(callbacks); + callbacks.m_user_data = &context; + ryml::EventHandlerTree evth(callbacks); + ryml::Parser parser(&evth); + ryml::Tree tree = ryml::parse_in_arena(&parser, ryml::csubstr(yaml.begin(), yaml.size())); + tree.resolve(); // resolve references + tree.resolve_tags(); + + auto root = tree.crootref(); + if (root.is_stream() && root.num_children() == 1 && root.child(0).is_doc()) { + root = root.child(0); + } + context.visitYAMLNode(val, root, true); + }, + .experimentalFeature = Xp::FromYaml}); + +} /* namespace nix */ + +#endif diff --git a/src/libexpr/primops/meson.build b/src/libexpr/primops/meson.build index f910fe237..830125a5f 100644 --- a/src/libexpr/primops/meson.build +++ b/src/libexpr/primops/meson.build @@ -9,4 +9,5 @@ sources += files( 'fetchMercurial.cc', 'fetchTree.cc', 'fromTOML.cc', + 'fromYAML.cc', ) diff --git a/src/libutil/experimental-features.cc b/src/libutil/experimental-features.cc index a0c955816..93dc91c5f 100644 --- a/src/libutil/experimental-features.cc +++ b/src/libutil/experimental-features.cc @@ -24,7 +24,7 @@ struct ExperimentalFeatureDetails * feature, we either have no issue at all if few features are not added * at the end of the list, or a proper merge conflict if they are. */ -constexpr size_t numXpFeatures = 1 + static_cast(Xp::PipeOperators); +constexpr size_t numXpFeatures = 1 + static_cast(Xp::FromYaml); constexpr std::array xpFeatureDetails = {{ { @@ -302,6 +302,10 @@ constexpr std::array xpFeatureDetails )", .trackingUrl = "https://github.com/NixOS/nix/milestone/55", }, + { + .tag = Xp::FromYaml, + .name = "from-yaml", + }, }}; static_assert( diff --git a/src/libutil/experimental-features.hh b/src/libutil/experimental-features.hh index 412bf0886..166ee19d8 100644 --- a/src/libutil/experimental-features.hh +++ b/src/libutil/experimental-features.hh @@ -37,6 +37,7 @@ enum struct ExperimentalFeature MountedSSHStore, VerifiedFetches, PipeOperators, + FromYaml, }; /** diff --git a/tests/unit/libexpr/compose-yaml-test-suite.sh b/tests/unit/libexpr/compose-yaml-test-suite.sh new file mode 100755 index 000000000..96c57dca4 --- /dev/null +++ b/tests/unit/libexpr/compose-yaml-test-suite.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +testclass="FromYAMLTest" +testmethod="execYAMLTest" + +if [ -z "$1" ]; then + echo "Usage: $0 PathToYamlTestSuiteRepository" + echo + echo "This script processes test cases from the yaml-test-suite repository (https://github.com/yaml/yaml-test-suite) and converts them into gtest tests for 'builtins.fromYAML'." + exit 1 +fi + +echo "/* Generated by $(basename "$0") */" +echo +echo "#pragma once" +echo + +for f in "$1"/src/*.yaml; do + testname="$(basename "${f}" .yaml)" + echo "static constexpr std::string_view T_${testname} = R\"RAW(" + cat "${f}" + case "${testname}" in + "4ABK") + cat << EOL + json: | + { + "unquoted": "separate", + "http://foo.com": null, + "omitted value": null + } +EOL + ;; +# "SM9W") +# echo " # not JSON compatible due to null key" +# echo " fail: true" +# ;; +# "UKK6") +# echo " # empty document" +# echo " fail: true" +# ;; + *) + ;; + esac + echo ")RAW\";" + echo +done + +echo "namespace {" +echo "using namespace nix;" +echo +for f in "$1"/src/*.yaml; do + testname="$(basename "${f}" .yaml)" + ignore="false" + skip="false" + throw_comment="" + # shellcheck disable=SC2221,SC2222 + case "${testname}" in + "H7TQ"|"MUS6"|"ZYU8") + echo "/** This test is ignored because these tests are not required to fail and rapidyaml ignores the YAML version string." + ignore="true" + ;; + "3HFZ"|"4EJS"|"5TRB"|"5U3A"|"7LBH"|"9C9N"|"9MQT"|"CVW2"|"CXX2"|"D49Q"|"DK4H"|"DK95"|"G5U8"|"JKF3"|"N782"|"QB6E"|"QLJ7"|"RXY3"|"S4GJ"|"S98Z"|"SY6V"|"VJP3"|"X4QW"|"Y79Y"|"YJV2"|"ZCZ6"|"ZL4Z"|"ZXT5"|"3HFZ"|"4EJS"|"5TRB"|"5U3A"|"7LBH"|"9C9N"|"9MQT"|"CVW2"|"CXX2"|"D49Q"|"DK4H"|"DK95"|"G5U8"|"JKF3"|"N782"|"QB6E"|"QLJ7"|"RXY3"|"S4GJ"|"S98Z"|"SY6V"|"VJP3"|"X4QW"|"Y79Y"|"YJV2"|"ZCZ6"|"ZL4Z"|"ZXT5") + skip="true" + ;; + "565N") + throw_comment="nix has no binary data type" + ;; + "5TYM"|"6CK3"|"6WLZ"|"7FWL"|"9WXW"|"C4HZ"|"CC74"|"CUP7"|"M5C3"|"P76L"|"UGM3"|"Z67P"|"Z9M4") + throw_comment="usage of unknown tags" + ;; + "2XXW"|"J7PZ") + throw_comment="usage of optional tag like !!set and !!omap (not implemented)" + ;; + esac + echo "TEST_F(${testclass}, T_${testname})" + echo "{" + if [ -n "${throw_comment}" ]; then + echo " EXPECT_THROW(${testmethod}(T_${testname}), EvalError) << \"${throw_comment}\";" + else + if [ "${skip}" = "true" ]; then + echo " GTEST_SKIP() << \"Reason: Invalid yaml is parsed successfully\";" + fi + echo " ${testmethod}(T_${testname});" + fi + echo "}" + [[ "${ignore}" = "true" ]] && echo "*/" + echo +done +echo "} /* namespace */" diff --git a/tests/unit/libexpr/meson.build b/tests/unit/libexpr/meson.build index 21c321334..dfdbc74fe 100644 --- a/tests/unit/libexpr/meson.build +++ b/tests/unit/libexpr/meson.build @@ -67,6 +67,7 @@ sources = files( 'value/context.cc', 'value/print.cc', 'value/value.cc', + 'yaml.cc' ) include_dirs = [include_directories('.')] diff --git a/tests/unit/libexpr/yaml-test-suite.hh b/tests/unit/libexpr/yaml-test-suite.hh new file mode 100644 index 000000000..082c4342e --- /dev/null +++ b/tests/unit/libexpr/yaml-test-suite.hh @@ -0,0 +1,13628 @@ +/* Generated by compose-yaml-test-suite.sh */ + +#pragma once + +static constexpr std::string_view T_229Q = R"RAW( +--- +- name: Spec Example 2.4. Sequence of Mappings + from: http://www.yaml.org/spec/1.2/spec.html#id2760193 + tags: sequence mapping spec + yaml: | + - + name: Mark McGwire + hr: 65 + avg: 0.278 + - + name: Sammy Sosa + hr: 63 + avg: 0.288 + tree: | + +STR + +DOC + +SEQ + +MAP + =VAL :name + =VAL :Mark McGwire + =VAL :hr + =VAL :65 + =VAL :avg + =VAL :0.278 + -MAP + +MAP + =VAL :name + =VAL :Sammy Sosa + =VAL :hr + =VAL :63 + =VAL :avg + =VAL :0.288 + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "name": "Mark McGwire", + "hr": 65, + "avg": 0.278 + }, + { + "name": "Sammy Sosa", + "hr": 63, + "avg": 0.288 + } + ] + dump: | + - name: Mark McGwire + hr: 65 + avg: 0.278 + - name: Sammy Sosa + hr: 63 + avg: 0.288 +)RAW"; + +static constexpr std::string_view T_236B = R"RAW( +--- +- name: Invalid value after mapping + from: '@perlpunk' + tags: error mapping + fail: true + yaml: | + foo: + bar + invalid + tree: | + +STR + +DOC + +MAP + =VAL :foo + =VAL :bar +)RAW"; + +static constexpr std::string_view T_26DV = R"RAW( +--- +- name: Whitespace around colon in mappings + from: '@perlpunk' + tags: alias mapping whitespace + yaml: | + "top1" :␣ + "key1" : &alias1 scalar1 + 'top2' :␣ + 'key2' : &alias2 scalar2 + top3: &node3␣ + *alias1 : scalar3 + top4:␣ + *alias2 : scalar4 + top5 :␣␣␣␣ + scalar5 + top6:␣ + &anchor6 'key6' : scalar6 + tree: | + +STR + +DOC + +MAP + =VAL "top1 + +MAP + =VAL "key1 + =VAL &alias1 :scalar1 + -MAP + =VAL 'top2 + +MAP + =VAL 'key2 + =VAL &alias2 :scalar2 + -MAP + =VAL :top3 + +MAP &node3 + =ALI *alias1 + =VAL :scalar3 + -MAP + =VAL :top4 + +MAP + =ALI *alias2 + =VAL :scalar4 + -MAP + =VAL :top5 + =VAL :scalar5 + =VAL :top6 + +MAP + =VAL &anchor6 'key6 + =VAL :scalar6 + -MAP + -MAP + -DOC + -STR + json: | + { + "top1": { + "key1": "scalar1" + }, + "top2": { + "key2": "scalar2" + }, + "top3": { + "scalar1": "scalar3" + }, + "top4": { + "scalar2": "scalar4" + }, + "top5": "scalar5", + "top6": { + "key6": "scalar6" + } + } + dump: | + "top1": + "key1": &alias1 scalar1 + 'top2': + 'key2': &alias2 scalar2 + top3: &node3 + *alias1 : scalar3 + top4: + *alias2 : scalar4 + top5: scalar5 + top6: + &anchor6 'key6': scalar6 +)RAW"; + +static constexpr std::string_view T_27NA = R"RAW( +--- +- name: Spec Example 5.9. Directive Indicator + from: http://www.yaml.org/spec/1.2/spec.html#id2774058 + tags: spec directive 1.3-err + yaml: | + %YAML 1.2 + --- text + tree: | + +STR + +DOC --- + =VAL :text + -DOC + -STR + json: | + "text" + dump: | + --- text +)RAW"; + +static constexpr std::string_view T_2AUY = R"RAW( +--- +- name: Tags in Block Sequence + from: NimYAML tests + tags: tag sequence + yaml: |2 + - !!str a + - b + - !!int 42 + - d + tree: | + +STR + +DOC + +SEQ + =VAL :a + =VAL :b + =VAL :42 + =VAL :d + -SEQ + -DOC + -STR + json: | + [ + "a", + "b", + 42, + "d" + ] + dump: | + - !!str a + - b + - !!int 42 + - d +)RAW"; + +static constexpr std::string_view T_2CMS = R"RAW( +--- +- name: Invalid mapping in plain multiline + from: '@perlpunk' + tags: error mapping + fail: true + yaml: | + this + is + invalid: x + tree: | + +STR + +DOC +)RAW"; + +static constexpr std::string_view T_2EBW = R"RAW( +--- +- name: Allowed characters in keys + from: '@perlpunk' + tags: mapping scalar + yaml: | + a!"#$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~: safe + ?foo: safe question mark + :foo: safe colon + -foo: safe dash + this is#not: a comment + tree: | + +STR + +DOC + +MAP + =VAL :a!"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~ + =VAL :safe + =VAL :?foo + =VAL :safe question mark + =VAL ::foo + =VAL :safe colon + =VAL :-foo + =VAL :safe dash + =VAL :this is#not + =VAL :a comment + -MAP + -DOC + -STR + json: | + { + "a!\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~": "safe", + "?foo": "safe question mark", + ":foo": "safe colon", + "-foo": "safe dash", + "this is#not": "a comment" + } + dump: | + a!"#$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~: safe + ?foo: safe question mark + :foo: safe colon + -foo: safe dash + this is#not: a comment +)RAW"; + +static constexpr std::string_view T_2G84 = R"RAW( +--- +- name: Literal modifers + from: '@ingydotnet' + tags: literal scalar + fail: true + yaml: | + --- |0 + tree: | + +STR + +DOC --- + +- fail: true + yaml: | + --- |10 + +- yaml: | + --- |1-∎ + tree: | + +STR + +DOC --- + =VAL | + -DOC + -STR + json: | + "" + emit: | + --- "" + +- yaml: | + --- |1+∎ + tree: | + +STR + +DOC --- + =VAL | + -DOC + -STR + emit: | + --- "" +)RAW"; + +static constexpr std::string_view T_2JQS = R"RAW( +--- +- name: Block Mapping with Missing Keys + from: NimYAML tests + tags: duplicate-key mapping empty-key + yaml: | + : a + : b + tree: | + +STR + +DOC + +MAP + =VAL : + =VAL :a + =VAL : + =VAL :b + -MAP + -DOC + -STR +)RAW"; + +static constexpr std::string_view T_2LFX = R"RAW( +--- +- name: Spec Example 6.13. Reserved Directives [1.3] + from: 6LVF, modified for YAML 1.3 + tags: spec directive header double 1.3-mod + yaml: | + %FOO bar baz # Should be ignored + # with a warning. + --- + "foo" + tree: | + +STR + +DOC --- + =VAL "foo + -DOC + -STR + json: | + "foo" + dump: | + --- + "foo" + emit: | + --- "foo" +)RAW"; + +static constexpr std::string_view T_2SXE = R"RAW( +--- +- name: Anchors With Colon in Name + from: Mailing List Discussion + tags: alias edge mapping 1.3-err + yaml: | + &a: key: &a value + foo: + *a: + tree: | + +STR + +DOC + +MAP + =VAL &a: :key + =VAL &a :value + =VAL :foo + =ALI *a: + -MAP + -DOC + -STR + json: | + { + "key": "value", + "foo": "key" + } + dump: | + &a: key: &a value + foo: *a: +)RAW"; + +static constexpr std::string_view T_2XXW = R"RAW( +--- +- name: Spec Example 2.25. Unordered Sets + from: http://www.yaml.org/spec/1.2/spec.html#id2761758 + tags: spec mapping unknown-tag explicit-key + yaml: | + # Sets are represented as a + # Mapping where each key is + # associated with a null value + --- !!set + ? Mark McGwire + ? Sammy Sosa + ? Ken Griff + tree: | + +STR + +DOC --- + +MAP + =VAL :Mark McGwire + =VAL : + =VAL :Sammy Sosa + =VAL : + =VAL :Ken Griff + =VAL : + -MAP + -DOC + -STR + json: | + { + "Mark McGwire": null, + "Sammy Sosa": null, + "Ken Griff": null + } + dump: | + --- !!set + Mark McGwire: + Sammy Sosa: + Ken Griff: +)RAW"; + +static constexpr std::string_view T_33X3 = R"RAW( +--- +- name: Three explicit integers in a block sequence + from: IRC + tags: sequence tag + yaml: | + --- + - !!int 1 + - !!int -2 + - !!int 33 + tree: | + +STR + +DOC --- + +SEQ + =VAL :1 + =VAL :-2 + =VAL :33 + -SEQ + -DOC + -STR + json: | + [ + 1, + -2, + 33 + ] + dump: | + --- + - !!int 1 + - !!int -2 + - !!int 33 +)RAW"; + +static constexpr std::string_view T_35KP = R"RAW( +--- +- name: Tags for Root Objects + from: NimYAML tests + tags: explicit-key header mapping tag + yaml: | + --- !!map + ? a + : b + --- !!seq + - !!str c + --- !!str + d + e + tree: | + +STR + +DOC --- + +MAP + =VAL :a + =VAL :b + -MAP + -DOC + +DOC --- + +SEQ + =VAL :c + -SEQ + -DOC + +DOC --- + =VAL :d e + -DOC + -STR + json: | + { + "a": "b" + } + [ + "c" + ] + "d e" + dump: | + --- !!map + a: b + --- !!seq + - !!str c + --- !!str d e +)RAW"; + +static constexpr std::string_view T_36F6 = R"RAW( +--- +- name: Multiline plain scalar with empty line + from: '@perlpunk' + tags: mapping scalar + yaml: | + --- + plain: a + b + + c + tree: | + +STR + +DOC --- + +MAP + =VAL :plain + =VAL :a b\nc + -MAP + -DOC + -STR + json: | + { + "plain": "a b\nc" + } + dump: | + --- + plain: 'a b + + c' +)RAW"; + +static constexpr std::string_view T_3ALJ = R"RAW( +--- +- name: Block Sequence in Block Sequence + from: NimYAML tests + tags: sequence + yaml: | + - - s1_i1 + - s1_i2 + - s2 + tree: | + +STR + +DOC + +SEQ + +SEQ + =VAL :s1_i1 + =VAL :s1_i2 + -SEQ + =VAL :s2 + -SEQ + -DOC + -STR + json: | + [ + [ + "s1_i1", + "s1_i2" + ], + "s2" + ] +)RAW"; + +static constexpr std::string_view T_3GZX = R"RAW( +--- +- name: Spec Example 7.1. Alias Nodes + from: http://www.yaml.org/spec/1.2/spec.html#id2786448 + tags: mapping spec alias + yaml: | + First occurrence: &anchor Foo + Second occurrence: *anchor + Override anchor: &anchor Bar + Reuse anchor: *anchor + tree: | + +STR + +DOC + +MAP + =VAL :First occurrence + =VAL &anchor :Foo + =VAL :Second occurrence + =ALI *anchor + =VAL :Override anchor + =VAL &anchor :Bar + =VAL :Reuse anchor + =ALI *anchor + -MAP + -DOC + -STR + json: | + { + "First occurrence": "Foo", + "Second occurrence": "Foo", + "Override anchor": "Bar", + "Reuse anchor": "Bar" + } +)RAW"; + +static constexpr std::string_view T_3HFZ = R"RAW( +--- +- name: Invalid content after document end marker + from: '@perlpunk' + tags: error footer + fail: true + yaml: | + --- + key: value + ... invalid + tree: | + +STR + +DOC --- + +MAP + =VAL :key + =VAL :value + -MAP + -DOC ... +)RAW"; + +static constexpr std::string_view T_3MYT = R"RAW( +--- +- name: Plain Scalar looking like key, comment, anchor and tag + from: https://gist.github.com/anonymous/a98d50ce42a59b1e999552bea7a31f57 via @ingydotnet + tags: scalar + yaml: | + --- + k:#foo + &a !t s + tree: | + +STR + +DOC --- + =VAL :k:#foo &a !t s + -DOC + -STR + json: | + "k:#foo &a !t s" + dump: | + --- k:#foo &a !t s +)RAW"; + +static constexpr std::string_view T_3R3P = R"RAW( +--- +- name: Single block sequence with anchor + from: '@perlpunk' + tags: anchor sequence + yaml: | + &sequence + - a + tree: | + +STR + +DOC + +SEQ &sequence + =VAL :a + -SEQ + -DOC + -STR + json: | + [ + "a" + ] + dump: | + &sequence + - a +)RAW"; + +static constexpr std::string_view T_3RLN = R"RAW( +--- +- name: Leading tabs in double quoted + from: '@ingydotnet' + tags: double whitespace + yaml: | + "1 leading + \ttab" + tree: | + +STR + +DOC + =VAL "1 leading \ttab + -DOC + -STR + json: | + "1 leading \ttab" + emit: | + "1 leading \ttab" + +- yaml: | + "2 leading + \———»tab" + tree: | + +STR + +DOC + =VAL "2 leading \ttab + -DOC + -STR + json: | + "2 leading \ttab" + emit: | + "2 leading \ttab" + +- yaml: | + "3 leading + ————»tab" + tree: | + +STR + +DOC + =VAL "3 leading tab + -DOC + -STR + json: | + "3 leading tab" + emit: | + "3 leading tab" + +- yaml: | + "4 leading + \t tab" + tree: | + +STR + +DOC + =VAL "4 leading \t tab + -DOC + -STR + json: | + "4 leading \t tab" + emit: | + "4 leading \t tab" + +- yaml: | + "5 leading + \———» tab" + tree: | + +STR + +DOC + =VAL "5 leading \t tab + -DOC + -STR + json: | + "5 leading \t tab" + emit: | + "5 leading \t tab" + +- yaml: | + "6 leading + ————» tab" + tree: | + +STR + +DOC + =VAL "6 leading tab + -DOC + -STR + json: | + "6 leading tab" + emit: | + "6 leading tab" +)RAW"; + +static constexpr std::string_view T_3UYS = R"RAW( +--- +- name: Escaped slash in double quotes + from: '@perlpunk' + tags: double + yaml: | + escaped slash: "a\/b" + tree: | + +STR + +DOC + +MAP + =VAL :escaped slash + =VAL "a/b + -MAP + -DOC + -STR + json: | + { + "escaped slash": "a/b" + } + dump: | + escaped slash: "a/b" +)RAW"; + +static constexpr std::string_view T_4ABK = R"RAW( +--- +- name: Flow Mapping Separate Values + from: http://www.yaml.org/spec/1.2/spec.html#id2791704 + tags: flow mapping + yaml: | + { + unquoted : "separate", + http://foo.com, + omitted value:, + } + tree: | + +STR + +DOC + +MAP {} + =VAL :unquoted + =VAL "separate + =VAL :http://foo.com + =VAL : + =VAL :omitted value + =VAL : + -MAP + -DOC + -STR + dump: | + unquoted: "separate" + http://foo.com: null + omitted value: null + json: | + { + "unquoted": "separate", + "http://foo.com": null, + "omitted value": null + } +)RAW"; + +static constexpr std::string_view T_4CQQ = R"RAW( +--- +- name: Spec Example 2.18. Multi-line Flow Scalars + from: http://www.yaml.org/spec/1.2/spec.html#id2761268 + tags: spec scalar + yaml: | + plain: + This unquoted scalar + spans many lines. + + quoted: "So does this + quoted scalar.\n" + tree: | + +STR + +DOC + +MAP + =VAL :plain + =VAL :This unquoted scalar spans many lines. + =VAL :quoted + =VAL "So does this quoted scalar.\n + -MAP + -DOC + -STR + json: | + { + "plain": "This unquoted scalar spans many lines.", + "quoted": "So does this quoted scalar.\n" + } + dump: | + plain: This unquoted scalar spans many lines. + quoted: "So does this quoted scalar.\n" +)RAW"; + +static constexpr std::string_view T_4EJS = R"RAW( +--- +- name: Invalid tabs as indendation in a mapping + from: https://github.com/nodeca/js-yaml/issues/80 + tags: error mapping whitespace + fail: true + yaml: | + --- + a: + ———»b: + ———»———»c: value + tree: | + +STR + +DOC --- + +MAP + =VAL :a +)RAW"; + +static constexpr std::string_view T_4FJ6 = R"RAW( +--- +- name: Nested implicit complex keys + from: '@perlpunk' + tags: complex-key flow mapping sequence + yaml: | + --- + [ + [ a, [ [[b,c]]: d, e]]: 23 + ] + tree: | + +STR + +DOC --- + +SEQ [] + +MAP {} + +SEQ [] + =VAL :a + +SEQ [] + +MAP {} + +SEQ [] + +SEQ [] + =VAL :b + =VAL :c + -SEQ + -SEQ + =VAL :d + -MAP + =VAL :e + -SEQ + -SEQ + =VAL :23 + -MAP + -SEQ + -DOC + -STR + dump: | + --- + - ? - a + - - ? - - b + - c + : d + - e + : 23 +)RAW"; + +static constexpr std::string_view T_4GC6 = R"RAW( +--- +- name: Spec Example 7.7. Single Quoted Characters + from: http://www.yaml.org/spec/1.2/spec.html#id2788307 + tags: spec scalar 1.3-err + yaml: | + 'here''s to "quotes"' + tree: | + +STR + +DOC + =VAL 'here's to "quotes" + -DOC + -STR + json: | + "here's to \"quotes\"" +)RAW"; + +static constexpr std::string_view T_4H7K = R"RAW( +--- +- name: Flow sequence with invalid extra closing bracket + from: '@perlpunk' + tags: error flow sequence + fail: true + yaml: | + --- + [ a, b, c ] ] + tree: | + +STR + +DOC --- + +SEQ + =VAL :a + =VAL :b + =VAL :c + -SEQ + -DOC +)RAW"; + +static constexpr std::string_view T_4HVU = R"RAW( +--- +- name: Wrong indendation in Sequence + from: '@perlpunk' + tags: error sequence indent + fail: true + yaml: | + key: + - ok + - also ok + - wrong + tree: | + +STR + +DOC + +MAP + =VAL :key + +SEQ + =VAL :ok + =VAL :also ok + -SEQ +)RAW"; + +static constexpr std::string_view T_4JVG = R"RAW( +--- +- name: Scalar value with two anchors + from: '@perlpunk' + tags: anchor error mapping + fail: true + yaml: | + top1: &node1 + &k1 key1: val1 + top2: &node2 + &v2 val2 + tree: | + +STR + +DOC + +MAP + =VAL :top1 + +MAP &node1 + =VAL &k1 :key1 + =VAL :val1 + -MAP + =VAL :top2 +)RAW"; + +static constexpr std::string_view T_4MUZ = R"RAW( +--- +- name: Flow mapping colon on line after key + from: '@ingydotnet' + tags: flow mapping + yaml: | + {"foo" + : "bar"} + tree: | + +STR + +DOC + +MAP {} + =VAL "foo + =VAL "bar + -MAP + -DOC + -STR + json: | + { + "foo": "bar" + } + emit: | + "foo": "bar" + +- yaml: | + {"foo" + : bar} + tree: | + +STR + +DOC + +MAP {} + =VAL "foo + =VAL :bar + -MAP + -DOC + -STR + emit: | + "foo": bar + +- yaml: | + {foo + : bar} + tree: | + +STR + +DOC + +MAP {} + =VAL :foo + =VAL :bar + -MAP + -DOC + -STR + json: | + { + "foo": "bar" + } + emit: | + foo: bar +)RAW"; + +static constexpr std::string_view T_4Q9F = R"RAW( +--- +- name: Folded Block Scalar [1.3] + from: TS54, modified for YAML 1.3 + tags: folded scalar 1.3-mod whitespace + yaml: | + --- > + ab + cd + ␣ + ef + + + gh + tree: | + +STR + +DOC --- + =VAL >ab cd\nef\n\ngh\n + -DOC + -STR + json: | + "ab cd\nef\n\ngh\n" + dump: | + --- > + ab cd + + ef + + + gh +)RAW"; + +static constexpr std::string_view T_4QFQ = R"RAW( +--- +- name: Spec Example 8.2. Block Indentation Indicator [1.3] + from: R4YG, modified for YAML 1.3 + tags: spec literal folded scalar libyaml-err 1.3-mod whitespace + yaml: | + - | + detected + - > + ␣ + ␣␣ + # detected + - |1 + explicit + - > + detected + tree: | + +STR + +DOC + +SEQ + =VAL |detected\n + =VAL >\n\n# detected\n + =VAL | explicit\n + =VAL >detected\n + -SEQ + -DOC + -STR + json: | + [ + "detected\n", + "\n\n# detected\n", + " explicit\n", + "detected\n" + ] + emit: | + - | + detected + - >2 + + + # detected + - |2 + explicit + - > + detected +)RAW"; + +static constexpr std::string_view T_4RWC = R"RAW( +--- +- name: Trailing spaces after flow collection + tags: flow whitespace + from: '@ingydotnet' + yaml: |2 + [1, 2, 3]␣␣ + ␣␣∎ + tree: | + +STR + +DOC + +SEQ [] + =VAL :1 + =VAL :2 + =VAL :3 + -SEQ + -DOC + -STR + json: | + [ + 1, + 2, + 3 + ] + dump: | + - 1 + - 2 + - 3 +)RAW"; + +static constexpr std::string_view T_4UYU = R"RAW( +--- +- name: Colon in Double Quoted String + from: NimYAML tests + tags: mapping scalar 1.3-err + yaml: | + "foo: bar\": baz" + tree: | + +STR + +DOC + =VAL "foo: bar": baz + -DOC + -STR + json: | + "foo: bar\": baz" +)RAW"; + +static constexpr std::string_view T_4V8U = R"RAW( +--- +- name: Plain scalar with backslashes + from: '@perlpunk' + tags: scalar + yaml: | + --- + plain\value\with\backslashes + tree: | + +STR + +DOC --- + =VAL :plain\\value\\with\\backslashes + -DOC + -STR + json: | + "plain\\value\\with\\backslashes" + dump: | + --- plain\value\with\backslashes +)RAW"; + +static constexpr std::string_view T_4WA9 = R"RAW( +--- +- name: Literal scalars + from: '@ingydotnet' + tags: indent literal + yaml: | + - aaa: |2 + xxx + bbb: | + xxx + tree: | + +STR + +DOC + +SEQ + +MAP + =VAL :aaa + =VAL |xxx\n + =VAL :bbb + =VAL |xxx\n + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "aaa" : "xxx\n", + "bbb" : "xxx\n" + } + ] + dump: | + --- + - aaa: | + xxx + bbb: | + xxx + emit: | + - aaa: | + xxx + bbb: | + xxx +)RAW"; + +static constexpr std::string_view T_4ZYM = R"RAW( +--- +- name: Spec Example 6.4. Line Prefixes + from: http://www.yaml.org/spec/1.2/spec.html#id2778720 + tags: spec scalar literal double upto-1.2 whitespace + yaml: | + plain: text + lines + quoted: "text + —»lines" + block: | + text + »lines + tree: | + +STR + +DOC + +MAP + =VAL :plain + =VAL :text lines + =VAL :quoted + =VAL "text lines + =VAL :block + =VAL |text\n \tlines\n + -MAP + -DOC + -STR + json: | + { + "plain": "text lines", + "quoted": "text lines", + "block": "text\n \tlines\n" + } + dump: | + plain: text lines + quoted: "text lines" + block: "text\n \tlines\n" + emit: | + plain: text lines + quoted: "text lines" + block: | + text + »lines +)RAW"; + +static constexpr std::string_view T_52DL = R"RAW( +--- +- name: Explicit Non-Specific Tag [1.3] + from: 8MK2, modified for YAML 1.3 + tags: tag 1.3-mod + yaml: | + --- + ! a + tree: | + +STR + +DOC --- + =VAL :a + -DOC + -STR + json: | + "a" + dump: | + --- ! a +)RAW"; + +static constexpr std::string_view T_54T7 = R"RAW( +--- +- name: Flow Mapping + from: https://github.com/ingydotnet/yaml-pegex-pm/blob/master/test/mapping.tml + tags: flow mapping + yaml: | + {foo: you, bar: far} + tree: | + +STR + +DOC + +MAP {} + =VAL :foo + =VAL :you + =VAL :bar + =VAL :far + -MAP + -DOC + -STR + json: | + { + "foo": "you", + "bar": "far" + } + dump: | + foo: you + bar: far +)RAW"; + +static constexpr std::string_view T_55WF = R"RAW( +--- +- name: Invalid escape in double quoted string + from: '@perlpunk' + tags: error double + fail: true + yaml: | + --- + "\." + tree: | + +STR + +DOC --- +)RAW"; + +static constexpr std::string_view T_565N = R"RAW( +--- +- name: Construct Binary + from: https://github.com/yaml/pyyaml/blob/master/tests/data/construct-binary-py2.data + tags: tag unknown-tag + yaml: | + canonical: !!binary "\ + R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5\ + OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+\ + +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC\ + AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=" + generic: !!binary | + R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5 + OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+ + +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC + AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs= + description: + The binary value above is a tiny arrow encoded as a gif image. + tree: | + +STR + +DOC + +MAP + =VAL :canonical + =VAL "R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs= + =VAL :generic + =VAL |R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5\nOTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+\n+f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC\nAgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=\n + =VAL :description + =VAL :The binary value above is a tiny arrow encoded as a gif image. + -MAP + -DOC + -STR + json: | + { + "canonical": "R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=", + "generic": "R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5\nOTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+\n+f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC\nAgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=\n", + "description": "The binary value above is a tiny arrow encoded as a gif image." + } +)RAW"; + +static constexpr std::string_view T_57H4 = R"RAW( +--- +- name: Spec Example 8.22. Block Collection Nodes + from: http://www.yaml.org/spec/1.2/spec.html#id2800008 + tags: sequence mapping tag + yaml: | + sequence: !!seq + - entry + - !!seq + - nested + mapping: !!map + foo: bar + tree: | + +STR + +DOC + +MAP + =VAL :sequence + +SEQ + =VAL :entry + +SEQ + =VAL :nested + -SEQ + -SEQ + =VAL :mapping + +MAP + =VAL :foo + =VAL :bar + -MAP + -MAP + -DOC + -STR + json: | + { + "sequence": [ + "entry", + [ + "nested" + ] + ], + "mapping": { + "foo": "bar" + } + } + dump: | + sequence: !!seq + - entry + - !!seq + - nested + mapping: !!map + foo: bar +)RAW"; + +static constexpr std::string_view T_58MP = R"RAW( +--- +- name: Flow mapping edge cases + from: '@ingydotnet' + tags: edge flow mapping + yaml: | + {x: :x} + tree: | + +STR + +DOC + +MAP {} + =VAL :x + =VAL ::x + -MAP + -DOC + -STR + json: | + { + "x": ":x" + } + dump: | + x: :x +)RAW"; + +static constexpr std::string_view T_5BVJ = R"RAW( +--- +- name: Spec Example 5.7. Block Scalar Indicators + from: http://www.yaml.org/spec/1.2/spec.html#id2773653 + tags: spec literal folded scalar + yaml: | + literal: | + some + text + folded: > + some + text + tree: | + +STR + +DOC + +MAP + =VAL :literal + =VAL |some\ntext\n + =VAL :folded + =VAL >some text\n + -MAP + -DOC + -STR + json: | + { + "literal": "some\ntext\n", + "folded": "some text\n" + } + dump: | + literal: | + some + text + folded: > + some text +)RAW"; + +static constexpr std::string_view T_5C5M = R"RAW( +--- +- name: Spec Example 7.15. Flow Mappings + from: http://www.yaml.org/spec/1.2/spec.html#id2791018 + tags: spec flow mapping + yaml: | + - { one : two , three: four , } + - {five: six,seven : eight} + tree: | + +STR + +DOC + +SEQ + +MAP {} + =VAL :one + =VAL :two + =VAL :three + =VAL :four + -MAP + +MAP {} + =VAL :five + =VAL :six + =VAL :seven + =VAL :eight + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "one": "two", + "three": "four" + }, + { + "five": "six", + "seven": "eight" + } + ] + dump: | + - one: two + three: four + - five: six + seven: eight +)RAW"; + +static constexpr std::string_view T_5GBF = R"RAW( +--- +- name: Spec Example 6.5. Empty Lines + from: http://www.yaml.org/spec/1.2/spec.html#id2778971 + tags: double literal spec scalar upto-1.2 whitespace + yaml: | + Folding: + "Empty line + » + as a line feed" + Chomping: | + Clipped empty lines + ␣ + ↵ + tree: | + +STR + +DOC + +MAP + =VAL :Folding + =VAL "Empty line\nas a line feed + =VAL :Chomping + =VAL |Clipped empty lines\n + -MAP + -DOC + -STR + json: | + { + "Folding": "Empty line\nas a line feed", + "Chomping": "Clipped empty lines\n" + } + dump: | + Folding: "Empty line\nas a line feed" + Chomping: | + Clipped empty lines +)RAW"; + +static constexpr std::string_view T_5KJE = R"RAW( +--- +- name: Spec Example 7.13. Flow Sequence + from: http://www.yaml.org/spec/1.2/spec.html#id2790506 + tags: spec flow sequence + yaml: | + - [ one, two, ] + - [three ,four] + tree: | + +STR + +DOC + +SEQ + +SEQ [] + =VAL :one + =VAL :two + -SEQ + +SEQ [] + =VAL :three + =VAL :four + -SEQ + -SEQ + -DOC + -STR + json: | + [ + [ + "one", + "two" + ], + [ + "three", + "four" + ] + ] + dump: | + - - one + - two + - - three + - four +)RAW"; + +static constexpr std::string_view T_5LLU = R"RAW( +--- +- name: Block scalar with wrong indented line after spaces only + from: '@perlpunk' + tags: error folded whitespace + fail: true + yaml: | + block scalar: > + ␣ + ␣␣ + ␣␣␣ + invalid + tree: | + +STR + +DOC + +MAP + =VAL :block scalar +)RAW"; + +static constexpr std::string_view T_5MUD = R"RAW( +--- +- name: Colon and adjacent value on next line + from: '@perlpunk' + tags: double flow mapping + yaml: | + --- + { "foo" + :bar } + tree: | + +STR + +DOC --- + +MAP {} + =VAL "foo + =VAL :bar + -MAP + -DOC + -STR + json: | + { + "foo": "bar" + } + dump: | + --- + "foo": bar +)RAW"; + +static constexpr std::string_view T_5NYZ = R"RAW( +--- +- name: Spec Example 6.9. Separated Comment + from: http://www.yaml.org/spec/1.2/spec.html#id2780342 + tags: mapping spec comment + yaml: | + key: # Comment + value + tree: | + +STR + +DOC + +MAP + =VAL :key + =VAL :value + -MAP + -DOC + -STR + json: | + { + "key": "value" + } + dump: | + key: value +)RAW"; + +static constexpr std::string_view T_5T43 = R"RAW( +--- +- name: Colon at the beginning of adjacent flow scalar + from: '@perlpunk' + tags: flow mapping scalar + yaml: | + - { "key":value } + - { "key"::value } + tree: | + +STR + +DOC + +SEQ + +MAP {} + =VAL "key + =VAL :value + -MAP + +MAP {} + =VAL "key + =VAL ::value + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "key": "value" + }, + { + "key": ":value" + } + ] + dump: | + - key: value + - key: :value + emit: | + - "key": value + - "key": :value +)RAW"; + +static constexpr std::string_view T_5TRB = R"RAW( +--- +- name: Invalid document-start marker in doublequoted tring + from: '@perlpunk' + tags: header double error + fail: true + yaml: | + --- + " + --- + " + tree: | + +STR + +DOC --- +)RAW"; + +static constexpr std::string_view T_5TYM = R"RAW( +--- +- name: Spec Example 6.21. Local Tag Prefix + from: http://www.yaml.org/spec/1.2/spec.html#id2783499 + tags: local-tag spec directive tag + yaml: | + %TAG !m! !my- + --- # Bulb here + !m!light fluorescent + ... + %TAG !m! !my- + --- # Color here + !m!light green + tree: | + +STR + +DOC --- + =VAL :fluorescent + -DOC ... + +DOC --- + =VAL :green + -DOC + -STR + json: | + "fluorescent" + "green" +)RAW"; + +static constexpr std::string_view T_5U3A = R"RAW( +--- +- name: Sequence on same Line as Mapping Key + from: '@perlpunk' + tags: error sequence mapping + fail: true + yaml: | + key: - a + - b + tree: | + +STR + +DOC + +MAP + =VAL :key +)RAW"; + +static constexpr std::string_view T_5WE3 = R"RAW( +--- +- name: Spec Example 8.17. Explicit Block Mapping Entries + from: http://www.yaml.org/spec/1.2/spec.html#id2798425 + tags: explicit-key spec mapping comment literal sequence + yaml: | + ? explicit key # Empty value + ? | + block key + : - one # Explicit compact + - two # block value + tree: | + +STR + +DOC + +MAP + =VAL :explicit key + =VAL : + =VAL |block key\n + +SEQ + =VAL :one + =VAL :two + -SEQ + -MAP + -DOC + -STR + json: | + { + "explicit key": null, + "block key\n": [ + "one", + "two" + ] + } + dump: | + explicit key: + ? | + block key + : - one + - two +)RAW"; + +static constexpr std::string_view T_62EZ = R"RAW( +--- +- name: Invalid block mapping key on same line as previous key + from: '@perlpunk' + tags: error flow mapping + fail: true + yaml: | + --- + x: { y: z }in: valid + tree: | + +STR + +DOC --- + +MAP + =VAL :x + +MAP {} + =VAL :y + =VAL :z + -MAP +)RAW"; + +static constexpr std::string_view T_652Z = R"RAW( +--- +- name: Question mark at start of flow key + from: '@ingydotnet' + tags: flow + yaml: | + { ?foo: bar, + bar: 42 + } + tree: | + +STR + +DOC + +MAP {} + =VAL :?foo + =VAL :bar + =VAL :bar + =VAL :42 + -MAP + -DOC + -STR + json: | + { + "?foo" : "bar", + "bar" : 42 + } + dump: | + --- + ?foo: bar + bar: 42 + emit: | + ?foo: bar + bar: 42 +)RAW"; + +static constexpr std::string_view T_65WH = R"RAW( +--- +- name: Single Entry Block Sequence + from: https://github.com/ingydotnet/yaml-pegex-pm/blob/master/test/sequence.tml + tags: sequence + yaml: | + - foo + tree: | + +STR + +DOC + +SEQ + =VAL :foo + -SEQ + -DOC + -STR + json: | + [ + "foo" + ] +)RAW"; + +static constexpr std::string_view T_6BCT = R"RAW( +--- +- name: Spec Example 6.3. Separation Spaces + from: http://www.yaml.org/spec/1.2/spec.html#id2778394 + tags: spec libyaml-err sequence whitespace upto-1.2 + yaml: | + - foo:—» bar + - - baz + -»baz + tree: | + +STR + +DOC + +SEQ + +MAP + =VAL :foo + =VAL :bar + -MAP + +SEQ + =VAL :baz + =VAL :baz + -SEQ + -SEQ + -DOC + -STR + json: | + [ + { + "foo": "bar" + }, + [ + "baz", + "baz" + ] + ] + dump: | + - foo: bar + - - baz + - baz +)RAW"; + +static constexpr std::string_view T_6BFJ = R"RAW( +--- +- name: Mapping, key and flow sequence item anchors + from: '@perlpunk' + tags: anchor complex-key flow mapping sequence + yaml: | + --- + &mapping + &key [ &item a, b, c ]: value + tree: | + +STR + +DOC --- + +MAP &mapping + +SEQ [] &key + =VAL &item :a + =VAL :b + =VAL :c + -SEQ + =VAL :value + -MAP + -DOC + -STR + dump: | + --- &mapping + ? &key + - &item a + - b + - c + : value +)RAW"; + +static constexpr std::string_view T_6CA3 = R"RAW( +--- +- name: Tab indented top flow + from: '@ingydotnet' + tags: indent whitespace + yaml: | + ————»[ + ————»] + tree: | + +STR + +DOC + +SEQ [] + -SEQ + -DOC + -STR + json: | + [] + emit: | + --- [] +)RAW"; + +static constexpr std::string_view T_6CK3 = R"RAW( +--- +- name: Spec Example 6.26. Tag Shorthands + from: http://www.yaml.org/spec/1.2/spec.html#id2785009 + tags: spec tag local-tag + yaml: | + %TAG !e! tag:example.com,2000:app/ + --- + - !local foo + - !!str bar + - !e!tag%21 baz + tree: | + +STR + +DOC --- + +SEQ + =VAL :foo + =VAL :bar + =VAL :baz + -SEQ + -DOC + -STR + json: | + [ + "foo", + "bar", + "baz" + ] +)RAW"; + +static constexpr std::string_view T_6FWR = R"RAW( +--- +- name: Block Scalar Keep + from: NimYAML tests + tags: literal scalar whitespace + yaml: | + --- |+ + ab + ␣ + ␣␣ + ... + tree: | + +STR + +DOC --- + =VAL |ab\n\n \n + -DOC ... + -STR + json: | + "ab\n\n \n" + dump: | + "ab\n\n \n" + ... + emit: | + --- | + ab + + ␣␣␣ + ... +)RAW"; + +static constexpr std::string_view T_6H3V = R"RAW( +--- +- name: Backslashes in singlequotes + from: '@perlpunk' + tags: scalar single + yaml: | + 'foo: bar\': baz' + tree: | + +STR + +DOC + +MAP + =VAL 'foo: bar\\ + =VAL :baz' + -MAP + -DOC + -STR + json: | + { + "foo: bar\\": "baz'" + } + dump: | + 'foo: bar\': baz' +)RAW"; + +static constexpr std::string_view T_6HB6 = R"RAW( +--- +- name: Spec Example 6.1. Indentation Spaces + from: http://www.yaml.org/spec/1.2/spec.html#id2777865 + tags: comment flow spec indent upto-1.2 whitespace + yaml: |2 + # Leading comment line spaces are + # neither content nor indentation. + ␣␣␣␣ + Not indented: + By one space: | + By four + spaces + Flow style: [ # Leading spaces + By two, # in flow style + Also by two, # are neither + —»Still by two # content nor + ] # indentation. + tree: | + +STR + +DOC + +MAP + =VAL :Not indented + +MAP + =VAL :By one space + =VAL |By four\n spaces\n + =VAL :Flow style + +SEQ [] + =VAL :By two + =VAL :Also by two + =VAL :Still by two + -SEQ + -MAP + -MAP + -DOC + -STR + json: | + { + "Not indented": { + "By one space": "By four\n spaces\n", + "Flow style": [ + "By two", + "Also by two", + "Still by two" + ] + } + } + dump: | + Not indented: + By one space: | + By four + spaces + Flow style: + - By two + - Also by two + - Still by two +)RAW"; + +static constexpr std::string_view T_6JQW = R"RAW( +--- +- name: Spec Example 2.13. In literals, newlines are preserved + from: http://www.yaml.org/spec/1.2/spec.html#id2759963 + tags: spec scalar literal comment + yaml: | + # ASCII Art + --- | + \//||\/|| + // || ||__ + tree: | + +STR + +DOC --- + =VAL |\\//||\\/||\n// || ||__\n + -DOC + -STR + json: | + "\\//||\\/||\n// || ||__\n" + dump: | + --- | + \//||\/|| + // || ||__ +)RAW"; + +static constexpr std::string_view T_6JTT = R"RAW( +--- +- name: Flow sequence without closing bracket + from: '@perlpunk' + tags: error flow sequence + fail: true + yaml: | + --- + [ [ a, b, c ] + tree: | + +STR + +DOC --- + +SEQ [] + +SEQ [] + =VAL :a + =VAL :b + =VAL :c + -SEQ +)RAW"; + +static constexpr std::string_view T_6JWB = R"RAW( +--- +- name: Tags for Block Objects + from: NimYAML tests + tags: mapping sequence tag + yaml: | + foo: !!seq + - !!str a + - !!map + key: !!str value + tree: | + +STR + +DOC + +MAP + =VAL :foo + +SEQ + =VAL :a + +MAP + =VAL :key + =VAL :value + -MAP + -SEQ + -MAP + -DOC + -STR + json: | + { + "foo": [ + "a", + { + "key": "value" + } + ] + } + dump: | + foo: !!seq + - !!str a + - !!map + key: !!str value +)RAW"; + +static constexpr std::string_view T_6KGN = R"RAW( +--- +- name: Anchor for empty node + from: https://github.com/nodeca/js-yaml/issues/301 + tags: alias anchor + yaml: | + --- + a: &anchor + b: *anchor + tree: | + +STR + +DOC --- + +MAP + =VAL :a + =VAL &anchor : + =VAL :b + =ALI *anchor + -MAP + -DOC + -STR + json: | + { + "a": null, + "b": null + } + dump: | + --- + a: &anchor + b: *anchor +)RAW"; + +static constexpr std::string_view T_6LVF = R"RAW( +--- +- name: Spec Example 6.13. Reserved Directives + from: http://www.yaml.org/spec/1.2/spec.html#id2781445 + tags: spec directive header double 1.3-err + yaml: | + %FOO bar baz # Should be ignored + # with a warning. + --- "foo" + tree: | + +STR + +DOC --- + =VAL "foo + -DOC + -STR + json: | + "foo" + dump: | + --- "foo" +)RAW"; + +static constexpr std::string_view T_6M2F = R"RAW( +--- +- name: Aliases in Explicit Block Mapping + from: NimYAML tests + tags: alias explicit-key empty-key + yaml: | + ? &a a + : &b b + : *a + tree: | + +STR + +DOC + +MAP + =VAL &a :a + =VAL &b :b + =VAL : + =ALI *a + -MAP + -DOC + -STR + dump: | + &a a: &b b + : *a +)RAW"; + +static constexpr std::string_view T_6PBE = R"RAW( +--- +- name: Zero-indented sequences in explicit mapping keys + from: '@perlpunk' + tags: explicit-key mapping sequence + yaml: | + --- + ? + - a + - b + : + - c + - d + tree: | + +STR + +DOC --- + +MAP + +SEQ + =VAL :a + =VAL :b + -SEQ + +SEQ + =VAL :c + =VAL :d + -SEQ + -MAP + -DOC + -STR + emit: | + --- + ? - a + - b + : - c + - d +)RAW"; + +static constexpr std::string_view T_6S55 = R"RAW( +--- +- name: Invalid scalar at the end of sequence + from: '@perlpunk' + tags: error mapping sequence + fail: true + yaml: | + key: + - bar + - baz + invalid + tree: | + +STR + +DOC + +MAP + =VAL :key + +SEQ + =VAL :bar + =VAL :baz +)RAW"; + +static constexpr std::string_view T_6SLA = R"RAW( +--- +- name: Allowed characters in quoted mapping key + from: '@perlpunk' + tags: mapping single double + yaml: | + "foo\nbar:baz\tx \\$%^&*()x": 23 + 'x\ny:z\tx $%^&*()x': 24 + tree: | + +STR + +DOC + +MAP + =VAL "foo\nbar:baz\tx \\$%^&*()x + =VAL :23 + =VAL 'x\\ny:z\\tx $%^&*()x + =VAL :24 + -MAP + -DOC + -STR + json: | + { + "foo\nbar:baz\tx \\$%^&*()x": 23, + "x\\ny:z\\tx $%^&*()x": 24 + } + dump: | + ? "foo\nbar:baz\tx \\$%^&*()x" + : 23 + 'x\ny:z\tx $%^&*()x': 24 +)RAW"; + +static constexpr std::string_view T_6VJK = R"RAW( +--- +- name: Spec Example 2.15. Folded newlines are preserved for "more indented" and blank lines + from: http://www.yaml.org/spec/1.2/spec.html#id2761056 + tags: spec folded scalar 1.3-err + yaml: | + > + Sammy Sosa completed another + fine season with great stats. + + 63 Home Runs + 0.288 Batting Average + + What a year! + tree: | + +STR + +DOC + =VAL >Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n + -DOC + -STR + json: | + "Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n" + dump: | + > + Sammy Sosa completed another fine season with great stats. + + 63 Home Runs + 0.288 Batting Average + + What a year! +)RAW"; + +static constexpr std::string_view T_6WLZ = R"RAW( +--- +- name: Spec Example 6.18. Primary Tag Handle [1.3] + from: 9WXW, modified for YAML 1.3 + tags: local-tag spec directive tag 1.3-mod + yaml: | + # Private + --- + !foo "bar" + ... + # Global + %TAG ! tag:example.com,2000:app/ + --- + !foo "bar" + tree: | + +STR + +DOC --- + =VAL "bar + -DOC ... + +DOC --- + =VAL "bar + -DOC + -STR + json: | + "bar" + "bar" + dump: | + --- + !foo "bar" + ... + --- ! + "bar" + emit: | + --- !foo "bar" + ... + --- ! "bar" +)RAW"; + +static constexpr std::string_view T_6WPF = R"RAW( +--- +- name: Spec Example 6.8. Flow Folding [1.3] + from: TL85, modified for YAML 1.3 + tags: double spec whitespace scalar 1.3-mod + yaml: | + --- + " + foo␣ + ␣ + bar + + baz + " + tree: | + +STR + +DOC --- + =VAL " foo\nbar\nbaz␣ + -DOC + -STR + json: | + " foo\nbar\nbaz " + dump: | + " foo\nbar\nbaz " + emit: | + --- " foo\nbar\nbaz " +)RAW"; + +static constexpr std::string_view T_6XDY = R"RAW( +--- +- name: Two document start markers + from: '@perlpunk' + tags: header + yaml: | + --- + --- + tree: | + +STR + +DOC --- + =VAL : + -DOC + +DOC --- + =VAL : + -DOC + -STR + json: | + null + null + dump: | + --- + --- +)RAW"; + +static constexpr std::string_view T_6ZKB = R"RAW( +--- +- name: Spec Example 9.6. Stream + from: http://www.yaml.org/spec/1.2/spec.html#id2801896 + tags: spec header 1.3-err + yaml: | + Document + --- + # Empty + ... + %YAML 1.2 + --- + matches %: 20 + tree: | + +STR + +DOC + =VAL :Document + -DOC + +DOC --- + =VAL : + -DOC ... + +DOC --- + +MAP + =VAL :matches % + =VAL :20 + -MAP + -DOC + -STR + json: | + "Document" + null + { + "matches %": 20 + } + emit: | + Document + --- + ... + %YAML 1.2 + --- + matches %: 20 +)RAW"; + +static constexpr std::string_view T_735Y = R"RAW( +--- +- name: Spec Example 8.20. Block Node Types + from: http://www.yaml.org/spec/1.2/spec.html#id2799426 + tags: comment double spec folded tag + yaml: | + - + "flow in block" + - > + Block scalar + - !!map # Block collection + foo : bar + tree: | + +STR + +DOC + +SEQ + =VAL "flow in block + =VAL >Block scalar\n + +MAP + =VAL :foo + =VAL :bar + -MAP + -SEQ + -DOC + -STR + json: | + [ + "flow in block", + "Block scalar\n", + { + "foo": "bar" + } + ] + dump: | + - "flow in block" + - > + Block scalar + - !!map + foo: bar +)RAW"; + +static constexpr std::string_view T_74H7 = R"RAW( +--- +- name: Tags in Implicit Mapping + from: NimYAML tests + tags: tag mapping + yaml: | + !!str a: b + c: !!int 42 + e: !!str f + g: h + !!str 23: !!bool false + tree: | + +STR + +DOC + +MAP + =VAL :a + =VAL :b + =VAL :c + =VAL :42 + =VAL :e + =VAL :f + =VAL :g + =VAL :h + =VAL :23 + =VAL :false + -MAP + -DOC + -STR + json: | + { + "a": "b", + "c": 42, + "e": "f", + "g": "h", + "23": false + } + dump: | + !!str a: b + c: !!int 42 + e: !!str f + g: h + !!str 23: !!bool false +)RAW"; + +static constexpr std::string_view T_753E = R"RAW( +--- +- name: Block Scalar Strip [1.3] + from: MYW6, modified for YAML 1.3 + tags: literal scalar 1.3-mod whitespace + yaml: | + --- |- + ab + ␣ + ␣ + ... + tree: | + +STR + +DOC --- + =VAL |ab + -DOC ... + -STR + json: | + "ab" + dump: | + --- |- + ab + ... +)RAW"; + +static constexpr std::string_view T_7A4E = R"RAW( +--- +- name: Spec Example 7.6. Double Quoted Lines + from: http://www.yaml.org/spec/1.2/spec.html#id2787994 + tags: spec scalar upto-1.2 whitespace + yaml: | + " 1st non-empty + + 2nd non-empty␣ + ———»3rd non-empty " + tree: | + +STR + +DOC + =VAL " 1st non-empty\n2nd non-empty 3rd non-empty␣ + -DOC + -STR + json: | + " 1st non-empty\n2nd non-empty 3rd non-empty " + dump: | + " 1st non-empty\n2nd non-empty 3rd non-empty " +)RAW"; + +static constexpr std::string_view T_7BMT = R"RAW( +--- +- name: Node and Mapping Key Anchors [1.3] + from: U3XV, modified for YAML 1.3 + tags: anchor comment mapping 1.3-mod + yaml: | + --- + top1: &node1 + &k1 key1: one + top2: &node2 # comment + key2: two + top3: + &k3 key3: three + top4: &node4 + &k4 key4: four + top5: &node5 + key5: five + top6: &val6 + six + top7: + &val7 seven + tree: | + +STR + +DOC --- + +MAP + =VAL :top1 + +MAP &node1 + =VAL &k1 :key1 + =VAL :one + -MAP + =VAL :top2 + +MAP &node2 + =VAL :key2 + =VAL :two + -MAP + =VAL :top3 + +MAP + =VAL &k3 :key3 + =VAL :three + -MAP + =VAL :top4 + +MAP &node4 + =VAL &k4 :key4 + =VAL :four + -MAP + =VAL :top5 + +MAP &node5 + =VAL :key5 + =VAL :five + -MAP + =VAL :top6 + =VAL &val6 :six + =VAL :top7 + =VAL &val7 :seven + -MAP + -DOC + -STR + json: | + { + "top1": { + "key1": "one" + }, + "top2": { + "key2": "two" + }, + "top3": { + "key3": "three" + }, + "top4": { + "key4": "four" + }, + "top5": { + "key5": "five" + }, + "top6": "six", + "top7": "seven" + } + dump: | + --- + top1: &node1 + &k1 key1: one + top2: &node2 + key2: two + top3: + &k3 key3: three + top4: &node4 + &k4 key4: four + top5: &node5 + key5: five + top6: &val6 six + top7: &val7 seven +)RAW"; + +static constexpr std::string_view T_7BUB = R"RAW( +--- +- name: Spec Example 2.10. Node for “Sammy Sosa” appears twice in this document + from: http://www.yaml.org/spec/1.2/spec.html#id2760658 + tags: mapping sequence spec alias + yaml: | + --- + hr: + - Mark McGwire + # Following node labeled SS + - &SS Sammy Sosa + rbi: + - *SS # Subsequent occurrence + - Ken Griffey + tree: | + +STR + +DOC --- + +MAP + =VAL :hr + +SEQ + =VAL :Mark McGwire + =VAL &SS :Sammy Sosa + -SEQ + =VAL :rbi + +SEQ + =ALI *SS + =VAL :Ken Griffey + -SEQ + -MAP + -DOC + -STR + json: | + { + "hr": [ + "Mark McGwire", + "Sammy Sosa" + ], + "rbi": [ + "Sammy Sosa", + "Ken Griffey" + ] + } + dump: | + --- + hr: + - Mark McGwire + - &SS Sammy Sosa + rbi: + - *SS + - Ken Griffey +)RAW"; + +static constexpr std::string_view T_7FWL = R"RAW( +--- +- name: Spec Example 6.24. Verbatim Tags + from: http://www.yaml.org/spec/1.2/spec.html#id2784370 + tags: mapping spec tag unknown-tag + yaml: | + ! foo : + ! baz + tree: | + +STR + +DOC + +MAP + =VAL :foo + =VAL :baz + -MAP + -DOC + -STR + json: | + { + "foo": "baz" + } + dump: | + !!str foo: !bar baz +)RAW"; + +static constexpr std::string_view T_7LBH = R"RAW( +--- +- name: Multiline double quoted implicit keys + from: '@perlpunk' + tags: error double + fail: true + yaml: | + "a\nb": 1 + "c + d": 1 + tree: | + +STR + +DOC + +MAP + =VAL "a\nb + =VAL :1 +)RAW"; + +static constexpr std::string_view T_7MNF = R"RAW( +--- +- name: Missing colon + from: '@perlpunk' + tags: error mapping + fail: true + yaml: | + top1: + key1: val1 + top2 + tree: | + +STR + +DOC + +MAP + =VAL :top1 + +MAP + =VAL :key1 + =VAL :val1 + -MAP +)RAW"; + +static constexpr std::string_view T_7T8X = R"RAW( +--- +- name: Spec Example 8.10. Folded Lines - 8.13. Final Empty Lines + from: http://www.yaml.org/spec/1.2/spec.html#id2796543 + tags: spec folded scalar comment 1.3-err + yaml: | + > + + folded + line + + next + line + * bullet + + * list + * lines + + last + line + + # Comment + tree: | + +STR + +DOC + =VAL >\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n + -DOC + -STR + json: | + "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n" + dump: | + > + + folded line + + next line + * bullet + + * list + * lines + + last line +)RAW"; + +static constexpr std::string_view T_7TMG = R"RAW( +--- +- name: Comment in flow sequence before comma + from: '@perlpunk' + tags: comment flow sequence + yaml: | + --- + [ word1 + # comment + , word2] + tree: | + +STR + +DOC --- + +SEQ [] + =VAL :word1 + =VAL :word2 + -SEQ + -DOC + -STR + json: | + [ + "word1", + "word2" + ] + dump: | + --- + - word1 + - word2 +)RAW"; + +static constexpr std::string_view T_7W2P = R"RAW( +--- +- name: Block Mapping with Missing Values + from: NimYAML tests + tags: explicit-key mapping + yaml: | + ? a + ? b + c: + tree: | + +STR + +DOC + +MAP + =VAL :a + =VAL : + =VAL :b + =VAL : + =VAL :c + =VAL : + -MAP + -DOC + -STR + json: | + { + "a": null, + "b": null, + "c": null + } + dump: | + a: + b: + c: +)RAW"; + +static constexpr std::string_view T_7Z25 = R"RAW( +--- +- name: Bare document after document end marker + from: '@perlpunk' + tags: footer + yaml: | + --- + scalar1 + ... + key: value + tree: | + +STR + +DOC --- + =VAL :scalar1 + -DOC ... + +DOC + +MAP + =VAL :key + =VAL :value + -MAP + -DOC + -STR + json: | + "scalar1" + { + "key": "value" + } + dump: | + --- scalar1 + ... + key: value +)RAW"; + +static constexpr std::string_view T_7ZZ5 = R"RAW( +--- +- name: Empty flow collections + from: '@perlpunk' + tags: flow mapping sequence + yaml: | + --- + nested sequences: + - - - [] + - - - {} + key1: [] + key2: {} + tree: | + +STR + +DOC --- + +MAP + =VAL :nested sequences + +SEQ + +SEQ + +SEQ + +SEQ [] + -SEQ + -SEQ + -SEQ + +SEQ + +SEQ + +MAP {} + -MAP + -SEQ + -SEQ + -SEQ + =VAL :key1 + +SEQ [] + -SEQ + =VAL :key2 + +MAP {} + -MAP + -MAP + -DOC + -STR + json: | + { + "nested sequences": [ + [ + [ + [] + ] + ], + [ + [ + {} + ] + ] + ], + "key1": [], + "key2": {} + } + dump: | + --- + nested sequences: + - - - [] + - - - {} + key1: [] + key2: {} +)RAW"; + +static constexpr std::string_view T_82AN = R"RAW( +--- +- name: Three dashes and content without space + from: '@perlpunk' + tags: scalar 1.3-err + yaml: | + ---word1 + word2 + tree: | + +STR + +DOC + =VAL :---word1 word2 + -DOC + -STR + json: | + "---word1 word2" + dump: | + '---word1 word2' +)RAW"; + +static constexpr std::string_view T_87E4 = R"RAW( +--- +- name: Spec Example 7.8. Single Quoted Implicit Keys + from: http://www.yaml.org/spec/1.2/spec.html#id2788496 + tags: spec flow sequence mapping + yaml: | + 'implicit block key' : [ + 'implicit flow key' : value, + ] + tree: | + +STR + +DOC + +MAP + =VAL 'implicit block key + +SEQ [] + +MAP {} + =VAL 'implicit flow key + =VAL :value + -MAP + -SEQ + -MAP + -DOC + -STR + json: | + { + "implicit block key": [ + { + "implicit flow key": "value" + } + ] + } + dump: | + 'implicit block key': + - 'implicit flow key': value +)RAW"; + +static constexpr std::string_view T_8CWC = R"RAW( +--- +- name: Plain mapping key ending with colon + from: '@perlpunk' + tags: mapping scalar + yaml: | + --- + key ends with two colons::: value + tree: | + +STR + +DOC --- + +MAP + =VAL :key ends with two colons:: + =VAL :value + -MAP + -DOC + -STR + json: | + { + "key ends with two colons::": "value" + } + dump: | + --- + 'key ends with two colons::': value +)RAW"; + +static constexpr std::string_view T_8G76 = R"RAW( +--- +- name: Spec Example 6.10. Comment Lines + from: http://www.yaml.org/spec/1.2/spec.html#id2780544 + tags: spec comment empty scalar whitespace + yaml: |2 + # Comment + ␣␣␣ + ↵ + ↵ + tree: | + +STR + -STR + json: '' + dump: '' +)RAW"; + +static constexpr std::string_view T_8KB6 = R"RAW( +--- +- name: Multiline plain flow mapping key without value + from: '@perlpunk' + tags: flow mapping + yaml: | + --- + - { single line, a: b} + - { multi + line, a: b} + tree: | + +STR + +DOC --- + +SEQ + +MAP {} + =VAL :single line + =VAL : + =VAL :a + =VAL :b + -MAP + +MAP {} + =VAL :multi line + =VAL : + =VAL :a + =VAL :b + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "single line": null, + "a": "b" + }, + { + "multi line": null, + "a": "b" + } + ] + dump: | + --- + - single line: + a: b + - multi line: + a: b +)RAW"; + +static constexpr std::string_view T_8MK2 = R"RAW( +--- +- name: Explicit Non-Specific Tag + from: NimYAML tests + tags: tag 1.3-err + yaml: | + ! a + tree: | + +STR + +DOC + =VAL :a + -DOC + -STR + json: | + "a" +)RAW"; + +static constexpr std::string_view T_8QBE = R"RAW( +--- +- name: Block Sequence in Block Mapping + from: NimYAML tests + tags: mapping sequence + yaml: | + key: + - item1 + - item2 + tree: | + +STR + +DOC + +MAP + =VAL :key + +SEQ + =VAL :item1 + =VAL :item2 + -SEQ + -MAP + -DOC + -STR + json: | + { + "key": [ + "item1", + "item2" + ] + } + dump: | + key: + - item1 + - item2 +)RAW"; + +static constexpr std::string_view T_8UDB = R"RAW( +--- +- name: Spec Example 7.14. Flow Sequence Entries + from: http://www.yaml.org/spec/1.2/spec.html#id2790726 + tags: spec flow sequence + yaml: | + [ + "double + quoted", 'single + quoted', + plain + text, [ nested ], + single: pair, + ] + tree: | + +STR + +DOC + +SEQ [] + =VAL "double quoted + =VAL 'single quoted + =VAL :plain text + +SEQ [] + =VAL :nested + -SEQ + +MAP {} + =VAL :single + =VAL :pair + -MAP + -SEQ + -DOC + -STR + json: | + [ + "double quoted", + "single quoted", + "plain text", + [ + "nested" + ], + { + "single": "pair" + } + ] + dump: | + - "double quoted" + - 'single quoted' + - plain text + - - nested + - single: pair +)RAW"; + +static constexpr std::string_view T_8XDJ = R"RAW( +--- +- name: Comment in plain multiline value + from: https://gist.github.com/anonymous/deeb1ace28d5bf21fb56d80c13e2dc69 via @ingydotnet + tags: error comment scalar + fail: true + yaml: | + key: word1 + # xxx + word2 + tree: | + +STR + +DOC + +MAP + =VAL :key + =VAL :word1 +)RAW"; + +static constexpr std::string_view T_8XYN = R"RAW( +--- +- name: Anchor with unicode character + from: https://github.com/yaml/pyyaml/issues/94 + tags: anchor + yaml: | + --- + - &😁 unicode anchor + tree: | + +STR + +DOC --- + +SEQ + =VAL &😁 :unicode anchor + -SEQ + -DOC + -STR + json: | + [ + "unicode anchor" + ] + dump: | + --- + - &😁 unicode anchor +)RAW"; + +static constexpr std::string_view T_93JH = R"RAW( +--- +- name: Block Mappings in Block Sequence + from: NimYAML tests + tags: mapping sequence + yaml: |2 + - key: value + key2: value2 + - + key3: value3 + tree: | + +STR + +DOC + +SEQ + +MAP + =VAL :key + =VAL :value + =VAL :key2 + =VAL :value2 + -MAP + +MAP + =VAL :key3 + =VAL :value3 + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "key": "value", + "key2": "value2" + }, + { + "key3": "value3" + } + ] + dump: | + - key: value + key2: value2 + - key3: value3 +)RAW"; + +static constexpr std::string_view T_93WF = R"RAW( +--- +- name: Spec Example 6.6. Line Folding [1.3] + from: K527, modified for YAML 1.3 + tags: folded spec whitespace scalar 1.3-mod + yaml: | + --- >- + trimmed + ␣␣ + ␣ + + as + space + tree: | + +STR + +DOC --- + =VAL >trimmed\n\n\nas space + -DOC + -STR + json: | + "trimmed\n\n\nas space" + dump: | + --- >- + trimmed + + + + as space +)RAW"; + +static constexpr std::string_view T_96L6 = R"RAW( +--- +- name: Spec Example 2.14. In the folded scalars, newlines become spaces + from: http://www.yaml.org/spec/1.2/spec.html#id2761032 + tags: spec folded scalar + yaml: | + --- > + Mark McGwire's + year was crippled + by a knee injury. + tree: | + +STR + +DOC --- + =VAL >Mark McGwire's year was crippled by a knee injury.\n + -DOC + -STR + json: | + "Mark McGwire's year was crippled by a knee injury.\n" + dump: | + --- > + Mark McGwire's year was crippled by a knee injury. +)RAW"; + +static constexpr std::string_view T_96NN = R"RAW( +--- +- name: Leading tab content in literals + from: '@ingydotnet' + tags: indent literal whitespace + yaml: | + foo: |- + ——»bar + tree: | + +STR + +DOC + +MAP + =VAL :foo + =VAL |\tbar + -MAP + -DOC + -STR + json: | + {"foo":"\tbar"} + dump: | + foo: |- + ——»bar + +- yaml: | + foo: |- + ——»bar∎ +)RAW"; + +static constexpr std::string_view T_98YD = R"RAW( +--- +- name: Spec Example 5.5. Comment Indicator + from: http://www.yaml.org/spec/1.2/spec.html#id2773032 + tags: spec comment empty + yaml: | + # Comment only. + tree: | + +STR + -STR + json: '' + dump: '' +)RAW"; + +static constexpr std::string_view T_9BXH = R"RAW( +--- +- name: Multiline doublequoted flow mapping key without value + from: '@perlpunk' + tags: double flow mapping + yaml: | + --- + - { "single line", a: b} + - { "multi + line", a: b} + tree: | + +STR + +DOC --- + +SEQ + +MAP {} + =VAL "single line + =VAL : + =VAL :a + =VAL :b + -MAP + +MAP {} + =VAL "multi line + =VAL : + =VAL :a + =VAL :b + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "single line": null, + "a": "b" + }, + { + "multi line": null, + "a": "b" + } + ] + dump: | + --- + - "single line": + a: b + - "multi line": + a: b +)RAW"; + +static constexpr std::string_view T_9C9N = R"RAW( +--- +- name: Wrong indented flow sequence + from: '@perlpunk' + tags: error flow indent sequence + fail: true + yaml: | + --- + flow: [a, + b, + c] + tree: | + +STR + +DOC --- + +MAP + =VAL :flow + +SEQ [] + =VAL :a +)RAW"; + +static constexpr std::string_view T_9CWY = R"RAW( +--- +- name: Invalid scalar at the end of mapping + from: '@perlpunk' + tags: error mapping sequence + fail: true + yaml: | + key: + - item1 + - item2 + invalid + tree: | + +STR + +DOC + +MAP + =VAL :key + +SEQ + =VAL :item1 + =VAL :item2 + -SEQ +)RAW"; + +static constexpr std::string_view T_9DXL = R"RAW( +--- +- name: Spec Example 9.6. Stream [1.3] + from: 6ZKB, modified for YAML 1.3 + tags: spec header 1.3-mod + yaml: | + Mapping: Document + --- + # Empty + ... + %YAML 1.2 + --- + matches %: 20 + tree: | + +STR + +DOC + +MAP + =VAL :Mapping + =VAL :Document + -MAP + -DOC + +DOC --- + =VAL : + -DOC ... + +DOC --- + +MAP + =VAL :matches % + =VAL :20 + -MAP + -DOC + -STR + json: | + { + "Mapping": "Document" + } + null + { + "matches %": 20 + } + emit: | + Mapping: Document + --- + ... + %YAML 1.2 + --- + matches %: 20 +)RAW"; + +static constexpr std::string_view T_9FMG = R"RAW( +--- +- name: Multi-level Mapping Indent + from: https://github.com/ingydotnet/yaml-pegex-pm/blob/master/test/indent.tml + tags: mapping indent + yaml: | + a: + b: + c: d + e: + f: g + h: i + tree: | + +STR + +DOC + +MAP + =VAL :a + +MAP + =VAL :b + +MAP + =VAL :c + =VAL :d + -MAP + =VAL :e + +MAP + =VAL :f + =VAL :g + -MAP + -MAP + =VAL :h + =VAL :i + -MAP + -DOC + -STR + json: | + { + "a": { + "b": { + "c": "d" + }, + "e": { + "f": "g" + } + }, + "h": "i" + } +)RAW"; + +static constexpr std::string_view T_9HCY = R"RAW( +--- +- name: Need document footer before directives + from: '@ingydotnet' + tags: directive error footer tag unknown-tag + fail: true + yaml: | + !foo "bar" + %TAG ! tag:example.com,2000:app/ + --- + !foo "bar" + tree: | + +STR + +DOC + =VAL "bar +)RAW"; + +static constexpr std::string_view T_9J7A = R"RAW( +--- +- name: Simple Mapping Indent + from: https://github.com/ingydotnet/yaml-pegex-pm/blob/master/test/indent.tml + tags: simple mapping indent + yaml: | + foo: + bar: baz + tree: | + +STR + +DOC + +MAP + =VAL :foo + +MAP + =VAL :bar + =VAL :baz + -MAP + -MAP + -DOC + -STR + json: | + { + "foo": { + "bar": "baz" + } + } +)RAW"; + +static constexpr std::string_view T_9JBA = R"RAW( +--- +- name: Invalid comment after end of flow sequence + from: '@perlpunk' + tags: comment error flow sequence + fail: true + yaml: | + --- + [ a, b, c, ]#invalid + tree: | + +STR + +DOC --- + +SEQ [] + =VAL :a + =VAL :b + =VAL :c + -SEQ +)RAW"; + +static constexpr std::string_view T_9KAX = R"RAW( +--- +- name: Various combinations of tags and anchors + from: '@perlpunk' + tags: anchor mapping 1.3-err tag + yaml: | + --- + &a1 + !!str + scalar1 + --- + !!str + &a2 + scalar2 + --- + &a3 + !!str scalar3 + --- + &a4 !!map + &a5 !!str key5: value4 + --- + a6: 1 + &anchor6 b6: 2 + --- + !!map + &a8 !!str key8: value7 + --- + !!map + !!str &a10 key10: value9 + --- + !!str &a11 + value11 + tree: | + +STR + +DOC --- + =VAL &a1 :scalar1 + -DOC + +DOC --- + =VAL &a2 :scalar2 + -DOC + +DOC --- + =VAL &a3 :scalar3 + -DOC + +DOC --- + +MAP &a4 + =VAL &a5 :key5 + =VAL :value4 + -MAP + -DOC + +DOC --- + +MAP + =VAL :a6 + =VAL :1 + =VAL &anchor6 :b6 + =VAL :2 + -MAP + -DOC + +DOC --- + +MAP + =VAL &a8 :key8 + =VAL :value7 + -MAP + -DOC + +DOC --- + +MAP + =VAL &a10 :key10 + =VAL :value9 + -MAP + -DOC + +DOC --- + =VAL &a11 :value11 + -DOC + -STR + json: | + "scalar1" + "scalar2" + "scalar3" + { + "key5": "value4" + } + { + "a6": 1, + "b6": 2 + } + { + "key8": "value7" + } + { + "key10": "value9" + } + "value11" + dump: | + --- &a1 !!str scalar1 + --- &a2 !!str scalar2 + --- &a3 !!str scalar3 + --- &a4 !!map + &a5 !!str key5: value4 + --- + a6: 1 + &anchor6 b6: 2 + --- !!map + &a8 !!str key8: value7 + --- !!map + &a10 !!str key10: value9 + --- &a11 !!str value11 +)RAW"; + +static constexpr std::string_view T_9KBC = R"RAW( +--- +- name: Mapping starting at --- line + from: https://gist.github.com/anonymous/c728390e92ec93fb371ac77f21435cca via @ingydotnet + tags: error header mapping + fail: true + yaml: | + --- key1: value1 + key2: value2 + tree: | + +STR + +DOC --- +)RAW"; + +static constexpr std::string_view T_9MAG = R"RAW( +--- +- name: Flow sequence with invalid comma at the beginning + from: '@perlpunk' + tags: error flow sequence + fail: true + yaml: | + --- + [ , a, b, c ] + tree: | + +STR + +DOC --- + +SEQ [] +)RAW"; + +static constexpr std::string_view T_9MMA = R"RAW( +--- +- name: Directive by itself with no document + from: '@ingydotnet' + tags: error directive + fail: true + yaml: | + %YAML 1.2 + tree: | + +STR +)RAW"; + +static constexpr std::string_view T_9MMW = R"RAW( +--- +- name: Single Pair Implicit Entries + from: '@perlpunk, Spec Example 7.21' + tags: flow mapping sequence + yaml: | + - [ YAML : separate ] + - [ "JSON like":adjacent ] + - [ {JSON: like}:adjacent ] + tree: | + +STR + +DOC + +SEQ + +SEQ [] + +MAP {} + =VAL :YAML + =VAL :separate + -MAP + -SEQ + +SEQ [] + +MAP {} + =VAL "JSON like + =VAL :adjacent + -MAP + -SEQ + +SEQ [] + +MAP {} + +MAP {} + =VAL :JSON + =VAL :like + -MAP + =VAL :adjacent + -MAP + -SEQ + -SEQ + -DOC + -STR + dump: | + - - YAML: separate + - - "JSON like": adjacent + - - ? JSON: like + : adjacent +)RAW"; + +static constexpr std::string_view T_9MQT = R"RAW( +--- +- name: Scalar doc with '...' in content + from: '@ingydotnet' + tags: double scalar + yaml: | + --- "a + ...x + b" + tree: | + +STR + +DOC --- + =VAL "a ...x b + -DOC + -STR + json: | + "a ...x b" + dump: | + --- a ...x b + emit: | + --- "a ...x b" + +- fail: true + yaml: | + --- "a + ... x + b" + tree: | + +STR + +DOC --- + dump: null + emit: null +)RAW"; + +static constexpr std::string_view T_9SA2 = R"RAW( +--- +- name: Multiline double quoted flow mapping key + from: '@perlpunk' + tags: double flow mapping + yaml: | + --- + - { "single line": value} + - { "multi + line": value} + tree: | + +STR + +DOC --- + +SEQ + +MAP {} + =VAL "single line + =VAL :value + -MAP + +MAP {} + =VAL "multi line + =VAL :value + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "single line": "value" + }, + { + "multi line": "value" + } + ] + dump: | + --- + - "single line": value + - "multi line": value +)RAW"; + +static constexpr std::string_view T_9SHH = R"RAW( +--- +- name: Spec Example 5.8. Quoted Scalar Indicators + from: http://www.yaml.org/spec/1.2/spec.html#id2773890 + tags: spec scalar + yaml: | + single: 'text' + double: "text" + tree: | + +STR + +DOC + +MAP + =VAL :single + =VAL 'text + =VAL :double + =VAL "text + -MAP + -DOC + -STR + json: | + { + "single": "text", + "double": "text" + } +)RAW"; + +static constexpr std::string_view T_9TFX = R"RAW( +--- +- name: Spec Example 7.6. Double Quoted Lines [1.3] + from: 7A4E, modified for YAML 1.3 + tags: double spec scalar whitespace 1.3-mod + yaml: | + --- + " 1st non-empty + + 2nd non-empty␣ + 3rd non-empty " + tree: | + +STR + +DOC --- + =VAL " 1st non-empty\n2nd non-empty 3rd non-empty␣ + -DOC + -STR + json: | + " 1st non-empty\n2nd non-empty 3rd non-empty " + dump: | + " 1st non-empty\n2nd non-empty 3rd non-empty " + emit: | + --- " 1st non-empty\n2nd non-empty 3rd non-empty " +)RAW"; + +static constexpr std::string_view T_9U5K = R"RAW( +--- +- name: Spec Example 2.12. Compact Nested Mapping + from: http://www.yaml.org/spec/1.2/spec.html#id2760821 + tags: spec mapping sequence + yaml: | + --- + # Products purchased + - item : Super Hoop + quantity: 1 + - item : Basketball + quantity: 4 + - item : Big Shoes + quantity: 1 + tree: | + +STR + +DOC --- + +SEQ + +MAP + =VAL :item + =VAL :Super Hoop + =VAL :quantity + =VAL :1 + -MAP + +MAP + =VAL :item + =VAL :Basketball + =VAL :quantity + =VAL :4 + -MAP + +MAP + =VAL :item + =VAL :Big Shoes + =VAL :quantity + =VAL :1 + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "item": "Super Hoop", + "quantity": 1 + }, + { + "item": "Basketball", + "quantity": 4 + }, + { + "item": "Big Shoes", + "quantity": 1 + } + ] + dump: | + --- + - item: Super Hoop + quantity: 1 + - item: Basketball + quantity: 4 + - item: Big Shoes + quantity: 1 +)RAW"; + +static constexpr std::string_view T_9WXW = R"RAW( +--- +- name: Spec Example 6.18. Primary Tag Handle + from: http://www.yaml.org/spec/1.2/spec.html#id2782728 + tags: local-tag spec directive tag unknown-tag 1.3-err + yaml: | + # Private + !foo "bar" + ... + # Global + %TAG ! tag:example.com,2000:app/ + --- + !foo "bar" + tree: | + +STR + +DOC + =VAL "bar + -DOC ... + +DOC --- + =VAL "bar + -DOC + -STR + json: | + "bar" + "bar" + dump: | + !foo "bar" + ... + --- ! "bar" +)RAW"; + +static constexpr std::string_view T_9YRD = R"RAW( +--- +- name: Multiline Scalar at Top Level + from: NimYAML tests + tags: scalar whitespace 1.3-err + yaml: | + a + b␣␣ + c + d + + e + tree: | + +STR + +DOC + =VAL :a b c d\ne + -DOC + -STR + json: | + "a b c d\ne" + dump: | + 'a b c d + + e' +)RAW"; + +static constexpr std::string_view T_A2M4 = R"RAW( +--- +- name: Spec Example 6.2. Indentation Indicators + from: http://www.yaml.org/spec/1.2/spec.html#id2778101 + tags: explicit-key spec libyaml-err indent whitespace sequence upto-1.2 + yaml: | + ? a + : -»b + - -—»c + - d + tree: | + +STR + +DOC + +MAP + =VAL :a + +SEQ + =VAL :b + +SEQ + =VAL :c + =VAL :d + -SEQ + -SEQ + -MAP + -DOC + -STR + json: | + { + "a": [ + "b", + [ + "c", + "d" + ] + ] + } + dump: | + a: + - b + - - c + - d +)RAW"; + +static constexpr std::string_view T_A6F9 = R"RAW( +--- +- name: Spec Example 8.4. Chomping Final Line Break + from: http://www.yaml.org/spec/1.2/spec.html#id2795034 + tags: spec literal scalar + yaml: | + strip: |- + text + clip: | + text + keep: |+ + text + tree: | + +STR + +DOC + +MAP + =VAL :strip + =VAL |text + =VAL :clip + =VAL |text\n + =VAL :keep + =VAL |text\n + -MAP + -DOC + -STR + json: | + { + "strip": "text", + "clip": "text\n", + "keep": "text\n" + } + dump: | + strip: |- + text + clip: | + text + keep: | + text +)RAW"; + +static constexpr std::string_view T_A984 = R"RAW( +--- +- name: Multiline Scalar in Mapping + from: NimYAML tests + tags: scalar + yaml: | + a: b + c + d: + e + f + tree: | + +STR + +DOC + +MAP + =VAL :a + =VAL :b c + =VAL :d + =VAL :e f + -MAP + -DOC + -STR + json: | + { + "a": "b c", + "d": "e f" + } + dump: | + a: b c + d: e f +)RAW"; + +static constexpr std::string_view T_AB8U = R"RAW( +--- +- name: Sequence entry that looks like two with wrong indentation + from: '@perlpunk' + tags: scalar sequence + yaml: | + - single multiline + - sequence entry + tree: | + +STR + +DOC + +SEQ + =VAL :single multiline - sequence entry + -SEQ + -DOC + -STR + json: | + [ + "single multiline - sequence entry" + ] + dump: | + - single multiline - sequence entry +)RAW"; + +static constexpr std::string_view T_AVM7 = R"RAW( +--- +- name: Empty Stream + from: https://github.com/ingydotnet/yaml-pegex-pm/blob/master/test/misc.tml + tags: edge + yaml: | + ∎ + tree: | + +STR + -STR + json: '' +)RAW"; + +static constexpr std::string_view T_AZ63 = R"RAW( +--- +- name: Sequence With Same Indentation as Parent Mapping + from: NimYAML tests + tags: indent mapping sequence + yaml: | + one: + - 2 + - 3 + four: 5 + tree: | + +STR + +DOC + +MAP + =VAL :one + +SEQ + =VAL :2 + =VAL :3 + -SEQ + =VAL :four + =VAL :5 + -MAP + -DOC + -STR + json: | + { + "one": [ + 2, + 3 + ], + "four": 5 + } +)RAW"; + +static constexpr std::string_view T_AZW3 = R"RAW( +--- +- name: Lookahead test cases + from: NimYAML tests + tags: mapping edge + yaml: | + - bla"keks: foo + - bla]keks: foo + tree: | + +STR + +DOC + +SEQ + +MAP + =VAL :bla"keks + =VAL :foo + -MAP + +MAP + =VAL :bla]keks + =VAL :foo + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "bla\"keks": "foo" + }, + { + "bla]keks": "foo" + } + ] +)RAW"; + +static constexpr std::string_view T_B3HG = R"RAW( +--- +- name: Spec Example 8.9. Folded Scalar [1.3] + from: G992, modified for YAML 1.3 + tags: spec folded scalar 1.3-mod + yaml: | + --- > + folded + text + ↵ + ↵ + tree: | + +STR + +DOC --- + =VAL >folded text\n + -DOC + -STR + json: | + "folded text\n" + dump: | + > + folded text + emit: | + --- > + folded text +)RAW"; + +static constexpr std::string_view T_B63P = R"RAW( +--- +- name: Directive without document + from: AdaYaml tests + tags: error directive document + fail: true + yaml: | + %YAML 1.2 + ... + tree: | + +STR +)RAW"; + +static constexpr std::string_view T_BD7L = R"RAW( +--- +- name: Invalid mapping after sequence + from: '@perlpunk' + tags: error mapping sequence + fail: true + yaml: | + - item1 + - item2 + invalid: x + tree: | + +STR + +DOC + +SEQ + =VAL :item1 + =VAL :item2 +)RAW"; + +static constexpr std::string_view T_BEC7 = R"RAW( +--- +- name: Spec Example 6.14. “YAML” directive + from: http://www.yaml.org/spec/1.2/spec.html#id2781929 + tags: spec directive + yaml: | + %YAML 1.3 # Attempt parsing + # with a warning + --- + "foo" + tree: | + +STR + +DOC --- + =VAL "foo + -DOC + -STR + json: | + "foo" + dump: | + --- "foo" +)RAW"; + +static constexpr std::string_view T_BF9H = R"RAW( +--- +- name: Trailing comment in multiline plain scalar + from: '@perlpunk' + tags: comment error scalar + fail: true + yaml: | + --- + plain: a + b # end of scalar + c + tree: | + +STR + +DOC --- + +MAP + =VAL :plain + =VAL :a b +)RAW"; + +static constexpr std::string_view T_BS4K = R"RAW( +--- +- name: Comment between plain scalar lines + from: https://gist.github.com/anonymous/269f16d582fdd30a7dcf8c9249c5da7f via @ingydotnet + tags: error scalar + fail: true + yaml: | + word1 # comment + word2 + tree: | + +STR + +DOC + =VAL :word1 + -DOC +)RAW"; + +static constexpr std::string_view T_BU8L = R"RAW( +--- +- name: Node Anchor and Tag on Seperate Lines + from: https://gist.github.com/anonymous/f192e7dab6da31831f264dbf1947cb83 via @ingydotnet + tags: anchor indent 1.3-err tag + yaml: | + key: &anchor + !!map + a: b + tree: | + +STR + +DOC + +MAP + =VAL :key + +MAP &anchor + =VAL :a + =VAL :b + -MAP + -MAP + -DOC + -STR + json: | + { + "key": { + "a": "b" + } + } + dump: | + key: &anchor !!map + a: b +)RAW"; + +static constexpr std::string_view T_C2DT = R"RAW( +--- +- name: Spec Example 7.18. Flow Mapping Adjacent Values + from: http://www.yaml.org/spec/1.2/spec.html#id2792073 + tags: spec flow mapping + yaml: | + { + "adjacent":value, + "readable": value, + "empty": + } + tree: | + +STR + +DOC + +MAP {} + =VAL "adjacent + =VAL :value + =VAL "readable + =VAL :value + =VAL "empty + =VAL : + -MAP + -DOC + -STR + json: | + { + "adjacent": "value", + "readable": "value", + "empty": null + } + dump: | + "adjacent": value + "readable": value + "empty": +)RAW"; + +static constexpr std::string_view T_C2SP = R"RAW( +--- +- name: Flow Mapping Key on two lines + from: '@perlpunk' + tags: error flow mapping + fail: true + yaml: | + [23 + ]: 42 + tree: | + +STR + +DOC + +SEQ [] + =VAL :23 +)RAW"; + +static constexpr std::string_view T_C4HZ = R"RAW( +--- +- name: Spec Example 2.24. Global Tags + from: http://www.yaml.org/spec/1.2/spec.html#id2761719 + tags: spec tag alias directive local-tag + yaml: | + %TAG ! tag:clarkevans.com,2002: + --- !shape + # Use the ! handle for presenting + # tag:clarkevans.com,2002:circle + - !circle + center: &ORIGIN {x: 73, y: 129} + radius: 7 + - !line + start: *ORIGIN + finish: { x: 89, y: 102 } + - !label + start: *ORIGIN + color: 0xFFEEBB + text: Pretty vector drawing. + tree: | + +STR + +DOC --- + +SEQ + +MAP + =VAL :center + +MAP {} &ORIGIN + =VAL :x + =VAL :73 + =VAL :y + =VAL :129 + -MAP + =VAL :radius + =VAL :7 + -MAP + +MAP + =VAL :start + =ALI *ORIGIN + =VAL :finish + +MAP {} + =VAL :x + =VAL :89 + =VAL :y + =VAL :102 + -MAP + -MAP + +MAP + =VAL :start + =ALI *ORIGIN + =VAL :color + =VAL :0xFFEEBB + =VAL :text + =VAL :Pretty vector drawing. + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "center": { + "x": 73, + "y": 129 + }, + "radius": 7 + }, + { + "start": { + "x": 73, + "y": 129 + }, + "finish": { + "x": 89, + "y": 102 + } + }, + { + "start": { + "x": 73, + "y": 129 + }, + "color": 16772795, + "text": "Pretty vector drawing." + } + ] + dump: | + --- ! + - ! + center: &ORIGIN + x: 73 + y: 129 + radius: 7 + - ! + start: *ORIGIN + finish: + x: 89 + y: 102 + - ! + start: *ORIGIN + color: 0xFFEEBB + text: Pretty vector drawing. +)RAW"; + +static constexpr std::string_view T_CC74 = R"RAW( +--- +- name: Spec Example 6.20. Tag Handles + from: http://www.yaml.org/spec/1.2/spec.html#id2783195 + tags: spec directive tag unknown-tag + yaml: | + %TAG !e! tag:example.com,2000:app/ + --- + !e!foo "bar" + tree: | + +STR + +DOC --- + =VAL "bar + -DOC + -STR + json: | + "bar" + dump: | + --- ! "bar" +)RAW"; + +static constexpr std::string_view T_CFD4 = R"RAW( +--- +- name: Empty implicit key in single pair flow sequences + from: '@perlpunk' + tags: empty-key flow sequence + yaml: | + - [ : empty key ] + - [: another empty key] + tree: | + +STR + +DOC + +SEQ + +SEQ [] + +MAP {} + =VAL : + =VAL :empty key + -MAP + -SEQ + +SEQ [] + +MAP {} + =VAL : + =VAL :another empty key + -MAP + -SEQ + -SEQ + -DOC + -STR + dump: | + - - : empty key + - - : another empty key +)RAW"; + +static constexpr std::string_view T_CML9 = R"RAW( +--- +- name: Missing comma in flow + from: ihttps://gist.github.com/anonymous/4ba3365607cc14b4f656e391b45bf4f4 via @ingydotnet + tags: error flow comment + fail: true + yaml: | + key: [ word1 + # xxx + word2 ] + tree: | + +STR + +DOC + +MAP + =VAL :key + +SEQ [] + =VAL :word1 +)RAW"; + +static constexpr std::string_view T_CN3R = R"RAW( +--- +- name: Various location of anchors in flow sequence + from: '@perlpunk' + tags: anchor flow mapping sequence + yaml: | + &flowseq [ + a: b, + &c c: d, + { &e e: f }, + &g { g: h } + ] + tree: | + +STR + +DOC + +SEQ [] &flowseq + +MAP {} + =VAL :a + =VAL :b + -MAP + +MAP {} + =VAL &c :c + =VAL :d + -MAP + +MAP {} + =VAL &e :e + =VAL :f + -MAP + +MAP {} &g + =VAL :g + =VAL :h + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "a": "b" + }, + { + "c": "d" + }, + { + "e": "f" + }, + { + "g": "h" + } + ] + dump: | + &flowseq + - a: b + - &c c: d + - &e e: f + - &g + g: h +)RAW"; + +static constexpr std::string_view T_CPZ3 = R"RAW( +--- +- name: Doublequoted scalar starting with a tab + from: '@perlpunk' + tags: double scalar + yaml: | + --- + tab: "\tstring" + tree: | + +STR + +DOC --- + +MAP + =VAL :tab + =VAL "\tstring + -MAP + -DOC + -STR + json: | + { + "tab": "\tstring" + } + dump: | + --- + tab: "\tstring" +)RAW"; + +static constexpr std::string_view T_CQ3W = R"RAW( +--- +- name: Double quoted string without closing quote + from: '@perlpunk' + tags: error double + fail: true + yaml: | + --- + key: "missing closing quote + tree: | + +STR + +DOC --- + +MAP + =VAL :key +)RAW"; + +static constexpr std::string_view T_CT4Q = R"RAW( +--- +- name: Spec Example 7.20. Single Pair Explicit Entry + from: http://www.yaml.org/spec/1.2/spec.html#id2792424 + tags: explicit-key spec flow mapping + yaml: | + [ + ? foo + bar : baz + ] + tree: | + +STR + +DOC + +SEQ [] + +MAP {} + =VAL :foo bar + =VAL :baz + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "foo bar": "baz" + } + ] + dump: | + - foo bar: baz +)RAW"; + +static constexpr std::string_view T_CTN5 = R"RAW( +--- +- name: Flow sequence with invalid extra comma + from: '@perlpunk' + tags: error flow sequence + fail: true + yaml: | + --- + [ a, b, c, , ] + tree: | + +STR + +DOC --- + +SEQ [] + =VAL :a + =VAL :b + =VAL :c +)RAW"; + +static constexpr std::string_view T_CUP7 = R"RAW( +--- +- name: Spec Example 5.6. Node Property Indicators + from: http://www.yaml.org/spec/1.2/spec.html#id2773402 + tags: local-tag spec tag alias + yaml: | + anchored: !local &anchor value + alias: *anchor + tree: | + +STR + +DOC + +MAP + =VAL :anchored + =VAL &anchor :value + =VAL :alias + =ALI *anchor + -MAP + -DOC + -STR + json: | + { + "anchored": "value", + "alias": "value" + } + dump: | + anchored: &anchor !local value + alias: *anchor +)RAW"; + +static constexpr std::string_view T_CVW2 = R"RAW( +--- +- name: Invalid comment after comma + from: '@perlpunk' + tags: comment error flow sequence + fail: true + yaml: | + --- + [ a, b, c,#invalid + ] + tree: | + +STR + +DOC --- + +SEQ [] + =VAL :a + =VAL :b + =VAL :c +)RAW"; + +static constexpr std::string_view T_CXX2 = R"RAW( +--- +- name: Mapping with anchor on document start line + from: '@perlpunk' + tags: anchor error header mapping + fail: true + yaml: | + --- &anchor a: b + tree: | + +STR + +DOC --- +)RAW"; + +static constexpr std::string_view T_D49Q = R"RAW( +--- +- name: Multiline single quoted implicit keys + from: '@perlpunk' + tags: error single mapping + fail: true + yaml: | + 'a\nb': 1 + 'c + d': 1 + tree: | + +STR + +DOC + +MAP + =VAL 'a\\nb + =VAL :1 +)RAW"; + +static constexpr std::string_view T_D83L = R"RAW( +--- +- name: Block scalar indicator order + from: '@perlpunk' + tags: indent literal + yaml: | + - |2- + explicit indent and chomp + - |-2 + chomp and explicit indent + tree: | + +STR + +DOC + +SEQ + =VAL |explicit indent and chomp + =VAL |chomp and explicit indent + -SEQ + -DOC + -STR + json: | + [ + "explicit indent and chomp", + "chomp and explicit indent" + ] + dump: | + - |- + explicit indent and chomp + - |- + chomp and explicit indent +)RAW"; + +static constexpr std::string_view T_D88J = R"RAW( +--- +- name: Flow Sequence in Block Mapping + from: NimYAML tests + tags: flow sequence mapping + yaml: | + a: [b, c] + tree: | + +STR + +DOC + +MAP + =VAL :a + +SEQ [] + =VAL :b + =VAL :c + -SEQ + -MAP + -DOC + -STR + json: | + { + "a": [ + "b", + "c" + ] + } + dump: | + a: + - b + - c +)RAW"; + +static constexpr std::string_view T_D9TU = R"RAW( +--- +- name: Single Pair Block Mapping + from: https://github.com/ingydotnet/yaml-pegex-pm/blob/master/test/mapping.tml + tags: simple mapping + yaml: | + foo: bar + tree: | + +STR + +DOC + +MAP + =VAL :foo + =VAL :bar + -MAP + -DOC + -STR + json: | + { + "foo": "bar" + } +)RAW"; + +static constexpr std::string_view T_DBG4 = R"RAW( +--- +- name: Spec Example 7.10. Plain Characters + from: http://www.yaml.org/spec/1.2/spec.html#id2789510 + tags: spec flow sequence scalar + yaml: | + # Outside flow collection: + - ::vector + - ": - ()" + - Up, up, and away! + - -123 + - http://example.com/foo#bar + # Inside flow collection: + - [ ::vector, + ": - ()", + "Up, up and away!", + -123, + http://example.com/foo#bar ] + tree: | + +STR + +DOC + +SEQ + =VAL :::vector + =VAL ": - () + =VAL :Up, up, and away! + =VAL :-123 + =VAL :http://example.com/foo#bar + +SEQ [] + =VAL :::vector + =VAL ": - () + =VAL "Up, up and away! + =VAL :-123 + =VAL :http://example.com/foo#bar + -SEQ + -SEQ + -DOC + -STR + json: | + [ + "::vector", + ": - ()", + "Up, up, and away!", + -123, + "http://example.com/foo#bar", + [ + "::vector", + ": - ()", + "Up, up and away!", + -123, + "http://example.com/foo#bar" + ] + ] + dump: | + - ::vector + - ": - ()" + - Up, up, and away! + - -123 + - http://example.com/foo#bar + - - ::vector + - ": - ()" + - "Up, up and away!" + - -123 + - http://example.com/foo#bar +)RAW"; + +static constexpr std::string_view T_DC7X = R"RAW( +--- +- name: Various trailing tabs + from: '@perlpunk' + tags: comment whitespace + yaml: | + a: b———» + seq:———» + - a———» + c: d———»#X + tree: | + +STR + +DOC + +MAP + =VAL :a + =VAL :b + =VAL :seq + +SEQ + =VAL :a + -SEQ + =VAL :c + =VAL :d + -MAP + -DOC + -STR + json: | + { + "a": "b", + "seq": [ + "a" + ], + "c": "d" + } + dump: | + a: b + seq: + - a + c: d +)RAW"; + +static constexpr std::string_view T_DE56 = R"RAW( +--- +- name: Trailing tabs in double quoted + from: '@ingydotnet' + tags: double whitespace + yaml: | + "1 trailing\t + tab" + tree: | + +STR + +DOC + =VAL "1 trailing\t tab + -DOC + -STR + json: | + "1 trailing\t tab" + dump: | + "1 trailing\t tab" + +- yaml: | + "2 trailing\t␣␣ + tab" + tree: | + +STR + +DOC + =VAL "2 trailing\t tab + -DOC + -STR + json: | + "2 trailing\t tab" + dump: | + "2 trailing\t tab" + +- yaml: | + "3 trailing\————» + tab" + tree: | + +STR + +DOC + =VAL "3 trailing\t tab + -DOC + -STR + json: | + "3 trailing\t tab" + dump: | + "3 trailing\t tab" + +- yaml: | + "4 trailing\————»␣␣ + tab" + tree: | + +STR + +DOC + =VAL "4 trailing\t tab + -DOC + -STR + json: | + "4 trailing\t tab" + dump: | + "4 trailing\t tab" + +- yaml: | + "5 trailing—» + tab" + tree: | + +STR + +DOC + =VAL "5 trailing tab + -DOC + -STR + json: | + "5 trailing tab" + dump: | + "5 trailing tab" + +- yaml: | + "6 trailing—»␣␣ + tab" + tree: | + +STR + +DOC + =VAL "6 trailing tab + -DOC + -STR + json: | + "6 trailing tab" + dump: | + "6 trailing tab" +)RAW"; + +static constexpr std::string_view T_DFF7 = R"RAW( +--- +- name: Spec Example 7.16. Flow Mapping Entries + from: http://www.yaml.org/spec/1.2/spec.html#id2791260 + tags: explicit-key spec flow mapping + yaml: | + { + ? explicit: entry, + implicit: entry, + ? + } + tree: | + +STR + +DOC + +MAP {} + =VAL :explicit + =VAL :entry + =VAL :implicit + =VAL :entry + =VAL : + =VAL : + -MAP + -DOC + -STR + dump: | + explicit: entry + implicit: entry + : +)RAW"; + +static constexpr std::string_view T_DHP8 = R"RAW( +--- +- name: Flow Sequence + from: https://github.com/ingydotnet/yaml-pegex-pm/blob/master/test/sequence.tml + tags: flow sequence + yaml: | + [foo, bar, 42] + tree: | + +STR + +DOC + +SEQ [] + =VAL :foo + =VAL :bar + =VAL :42 + -SEQ + -DOC + -STR + json: | + [ + "foo", + "bar", + 42 + ] + dump: | + - foo + - bar + - 42 +)RAW"; + +static constexpr std::string_view T_DK3J = R"RAW( +--- +- name: Zero indented block scalar with line that looks like a comment + from: '@perlpunk' + tags: comment folded scalar + yaml: | + --- > + line1 + # no comment + line3 + tree: | + +STR + +DOC --- + =VAL >line1 # no comment line3\n + -DOC + -STR + json: | + "line1 # no comment line3\n" + dump: | + --- > + line1 # no comment line3 +)RAW"; + +static constexpr std::string_view T_DK4H = R"RAW( +--- +- name: Implicit key followed by newline + from: '@perlpunk' + tags: error flow mapping sequence + fail: true + yaml: | + --- + [ key + : value ] + tree: | + +STR + +DOC --- + +SEQ [] + =VAL :key +)RAW"; + +static constexpr std::string_view T_DK95 = R"RAW( +--- +- name: Tabs that look like indentation + from: '@ingydotnet' + tags: indent whitespace + yaml: | + foo: + ———»bar + tree: | + +STR + +DOC + +MAP + =VAL :foo + =VAL :bar + -MAP + -DOC + -STR + json: | + { + "foo" : "bar" + } + emit: | + --- + foo: bar + +- fail: true + yaml: | + foo: "bar + ————»baz" + tree: | + +STR + +DOC + +MAP + =VAL :foo + +- yaml: | + foo: "bar + ——»baz" + tree: | + +STR + +DOC + +MAP + =VAL :foo + =VAL "bar baz + -MAP + -DOC + -STR + json: | + { + "foo" : "bar baz" + } + emit: | + --- + foo: "bar baz" + +- yaml: |2 + ———» + foo: 1 + tree: | + +STR + +DOC + +MAP + =VAL :foo + =VAL :1 + -MAP + -DOC + -STR + json: | + { + "foo" : 1 + } + emit: | + --- + foo: 1 + +- yaml: | + foo: 1 + ————» + bar: 2 + tree: | + +STR + +DOC + +MAP + =VAL :foo + =VAL :1 + =VAL :bar + =VAL :2 + -MAP + -DOC + -STR + json: | + { + "foo" : 1, + "bar" : 2 + } + emit: | + --- + foo: 1 + bar: 2 + +- yaml: | + foo: 1 + ———» + bar: 2 + tree: | + +STR + +DOC + +MAP + =VAL :foo + =VAL :1 + =VAL :bar + =VAL :2 + -MAP + -DOC + -STR + json: | + { + "foo" : 1, + "bar" : 2 + } + emit: | + --- + foo: 1 + bar: 2 + +- fail: true + yaml: | + foo: + a: 1 + ——»b: 2 + tree: | + +STR + +DOC + +MAP + =VAL :foo + +MAP + =VAL :a + =VAL :1 + +- yaml: | + %YAML 1.2 + ————» + --- + tree: | + +STR + +DOC --- + =VAL : + -DOC + -STR + json: | + null + emit: | + --- null + +- yaml: | + foo: "bar + ———» ——» baz ——» ——» " + tree: | + +STR + +DOC + +MAP + =VAL :foo + =VAL "bar baz \t \t␣ + -MAP + -DOC + -STR + json: | + { + "foo" : "bar baz \t \t " + } + emit: | + --- + foo: "bar baz \t \t " +)RAW"; + +static constexpr std::string_view T_DMG6 = R"RAW( +--- +- name: Wrong indendation in Map + from: '@perlpunk' + tags: error mapping indent + fail: true + yaml: | + key: + ok: 1 + wrong: 2 + tree: | + +STR + +DOC + +MAP + =VAL :key + +MAP + =VAL :ok + =VAL :1 + -MAP +)RAW"; + +static constexpr std::string_view T_DWX9 = R"RAW( +--- +- name: Spec Example 8.8. Literal Content + from: http://www.yaml.org/spec/1.2/spec.html#id2796118 + tags: spec literal scalar comment whitespace 1.3-err + yaml: | + | + ␣ + ␣␣ + literal + ␣␣␣ + ␣␣ + text + + # Comment + tree: | + +STR + +DOC + =VAL |\n\nliteral\n \n\ntext\n + -DOC + -STR + json: | + "\n\nliteral\n \n\ntext\n" + dump: | + "\n\nliteral\n \n\ntext\n" + emit: | + | + + + literal + ␣␣␣ + + text +)RAW"; + +static constexpr std::string_view T_E76Z = R"RAW( +--- +- name: Aliases in Implicit Block Mapping + from: NimYAML tests + tags: mapping alias + yaml: | + &a a: &b b + *b : *a + tree: | + +STR + +DOC + +MAP + =VAL &a :a + =VAL &b :b + =ALI *b + =ALI *a + -MAP + -DOC + -STR + json: | + { + "a": "b", + "b": "a" + } + dump: | + &a a: &b b + *b : *a +)RAW"; + +static constexpr std::string_view T_EB22 = R"RAW( +--- +- name: Missing document-end marker before directive + from: '@perlpunk' + tags: error directive footer + fail: true + yaml: | + --- + scalar1 # comment + %YAML 1.2 + --- + scalar2 + tree: | + +STR + +DOC --- + =VAL :scalar1 + -DOC +)RAW"; + +static constexpr std::string_view T_EHF6 = R"RAW( +--- +- name: Tags for Flow Objects + from: NimYAML tests + tags: tag flow mapping sequence + yaml: | + !!map { + k: !!seq + [ a, !!str b] + } + tree: | + +STR + +DOC + +MAP {} + =VAL :k + +SEQ [] + =VAL :a + =VAL :b + -SEQ + -MAP + -DOC + -STR + json: | + { + "k": [ + "a", + "b" + ] + } + dump: | + !!map + k: !!seq + - a + - !!str b +)RAW"; + +static constexpr std::string_view T_EW3V = R"RAW( +--- +- name: Wrong indendation in mapping + from: '@perlpunk' + tags: error mapping indent + fail: true + yaml: | + k1: v1 + k2: v2 + tree: | + +STR + +DOC + +MAP + =VAL :k1 +)RAW"; + +static constexpr std::string_view T_EX5H = R"RAW( +--- +- name: Multiline Scalar at Top Level [1.3] + from: 9YRD, modified for YAML 1.3 + tags: scalar whitespace 1.3-mod + yaml: | + --- + a + b␣␣ + c + d + + e + tree: | + +STR + +DOC --- + =VAL :a b c d\ne + -DOC + -STR + json: | + "a b c d\ne" + dump: | + 'a b c d + + e' + emit: | + --- a b c d + + e +)RAW"; + +static constexpr std::string_view T_EXG3 = R"RAW( +--- +- name: Three dashes and content without space [1.3] + from: 82AN, modified for YAML 1.3 + tags: scalar 1.3-mod + yaml: | + --- + ---word1 + word2 + tree: | + +STR + +DOC --- + =VAL :---word1 word2 + -DOC + -STR + json: | + "---word1 word2" + dump: | + '---word1 word2' + emit: | + --- '---word1 word2' +)RAW"; + +static constexpr std::string_view T_F2C7 = R"RAW( +--- +- name: Anchors and Tags + from: NimYAML tests + tags: anchor tag + yaml: |2 + - &a !!str a + - !!int 2 + - !!int &c 4 + - &d d + tree: | + +STR + +DOC + +SEQ + =VAL &a :a + =VAL :2 + =VAL &c :4 + =VAL &d :d + -SEQ + -DOC + -STR + json: | + [ + "a", + 2, + 4, + "d" + ] + dump: | + - &a !!str a + - !!int 2 + - &c !!int 4 + - &d d +)RAW"; + +static constexpr std::string_view T_F3CP = R"RAW( +--- +- name: Nested flow collections on one line + from: '@perlpunk' + tags: flow mapping sequence + yaml: | + --- + { a: [b, c, { d: [e, f] } ] } + tree: | + +STR + +DOC --- + +MAP {} + =VAL :a + +SEQ [] + =VAL :b + =VAL :c + +MAP {} + =VAL :d + +SEQ [] + =VAL :e + =VAL :f + -SEQ + -MAP + -SEQ + -MAP + -DOC + -STR + json: | + { + "a": [ + "b", + "c", + { + "d": [ + "e", + "f" + ] + } + ] + } + dump: | + --- + a: + - b + - c + - d: + - e + - f +)RAW"; + +static constexpr std::string_view T_F6MC = R"RAW( +--- +- name: More indented lines at the beginning of folded block scalars + from: '@perlpunk' + tags: folded indent + yaml: | + --- + a: >2 + more indented + regular + b: >2 + + + more indented + regular + tree: | + +STR + +DOC --- + +MAP + =VAL :a + =VAL > more indented\nregular\n + =VAL :b + =VAL >\n\n more indented\nregular\n + -MAP + -DOC + -STR + json: | + { + "a": " more indented\nregular\n", + "b": "\n\n more indented\nregular\n" + } + emit: | + --- + a: >2 + more indented + regular + b: >2 + + + more indented + regular +)RAW"; + +static constexpr std::string_view T_F8F9 = R"RAW( +--- +- name: Spec Example 8.5. Chomping Trailing Lines + from: http://www.yaml.org/spec/1.2/spec.html#id2795435 + tags: spec literal scalar comment + yaml: |2 + # Strip + # Comments: + strip: |- + # text + ␣␣ + # Clip + # comments: + + clip: | + # text + ␣ + # Keep + # comments: + + keep: |+ + # text + + # Trail + # comments. + tree: | + +STR + +DOC + +MAP + =VAL :strip + =VAL |# text + =VAL :clip + =VAL |# text\n + =VAL :keep + =VAL |# text\n\n + -MAP + -DOC + -STR + json: | + { + "strip": "# text", + "clip": "# text\n", + "keep": "# text\n\n" + } + dump: | + strip: |- + # text + clip: | + # text + keep: |+ + # text + + ... +)RAW"; + +static constexpr std::string_view T_FBC9 = R"RAW( +--- +- name: Allowed characters in plain scalars + from: '@perlpunk' + tags: scalar + yaml: | + safe: a!"#$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~ + !"#$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~ + safe question mark: ?foo + safe colon: :foo + safe dash: -foo + tree: | + +STR + +DOC + +MAP + =VAL :safe + =VAL :a!"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~ !"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~ + =VAL :safe question mark + =VAL :?foo + =VAL :safe colon + =VAL ::foo + =VAL :safe dash + =VAL :-foo + -MAP + -DOC + -STR + json: | + { + "safe": "a!\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~ !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~", + "safe question mark": "?foo", + "safe colon": ":foo", + "safe dash": "-foo" + } + dump: | + safe: a!"#$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~ !"#$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~ + safe question mark: ?foo + safe colon: :foo + safe dash: -foo +)RAW"; + +static constexpr std::string_view T_FH7J = R"RAW( +--- +- name: Tags on Empty Scalars + from: NimYAML tests + tags: tag scalar + yaml: | + - !!str + - + !!null : a + b: !!str + - !!str : !!null + tree: | + +STR + +DOC + +SEQ + =VAL : + +MAP + =VAL : + =VAL :a + =VAL :b + =VAL : + -MAP + +MAP + =VAL : + =VAL : + -MAP + -SEQ + -DOC + -STR + dump: | + - !!str + - !!null : a + b: !!str + - !!str : !!null +)RAW"; + +static constexpr std::string_view T_FP8R = R"RAW( +--- +- name: Zero indented block scalar + from: '@perlpunk' + tags: folded indent scalar + yaml: | + --- > + line1 + line2 + line3 + tree: | + +STR + +DOC --- + =VAL >line1 line2 line3\n + -DOC + -STR + json: | + "line1 line2 line3\n" + dump: | + --- > + line1 line2 line3 +)RAW"; + +static constexpr std::string_view T_FQ7F = R"RAW( +--- +- name: Spec Example 2.1. Sequence of Scalars + from: http://www.yaml.org/spec/1.2/spec.html#id2759963 + tags: spec sequence + yaml: | + - Mark McGwire + - Sammy Sosa + - Ken Griffey + tree: | + +STR + +DOC + +SEQ + =VAL :Mark McGwire + =VAL :Sammy Sosa + =VAL :Ken Griffey + -SEQ + -DOC + -STR + json: | + [ + "Mark McGwire", + "Sammy Sosa", + "Ken Griffey" + ] + toke: | + SEQ-MARK 0 1 1 1 + WS-SPACE 1 1 1 2 + TEXT-VAL 2 12 1 3 :Mark McGwire + WS-NEWLN 14 1 1 15 + SEQ-MARK 15 1 2 1 + WS-SPACE 1 1 1 2 + TEXT-VAL 2 12 1 3 :Sammy Sosa + WS-NEWLN 14 1 1 15 +)RAW"; + +static constexpr std::string_view T_FRK4 = R"RAW( +--- +- name: Spec Example 7.3. Completely Empty Flow Nodes + from: http://www.yaml.org/spec/1.2/spec.html#id2786868 + tags: empty-key explicit-key spec flow mapping + yaml: | + { + ? foo :, + : bar, + } + tree: | + +STR + +DOC + +MAP {} + =VAL :foo + =VAL : + =VAL : + =VAL :bar + -MAP + -DOC + -STR +)RAW"; + +static constexpr std::string_view T_FTA2 = R"RAW( +--- +- name: Single block sequence with anchor and explicit document start + from: '@perlpunk' + tags: anchor header sequence + yaml: | + --- &sequence + - a + tree: | + +STR + +DOC --- + +SEQ &sequence + =VAL :a + -SEQ + -DOC + -STR + json: | + [ + "a" + ] + dump: | + --- &sequence + - a +)RAW"; + +static constexpr std::string_view T_FUP4 = R"RAW( +--- +- name: Flow Sequence in Flow Sequence + from: NimYAML tests + tags: sequence flow + yaml: | + [a, [b, c]] + tree: | + +STR + +DOC + +SEQ [] + =VAL :a + +SEQ [] + =VAL :b + =VAL :c + -SEQ + -SEQ + -DOC + -STR + json: | + [ + "a", + [ + "b", + "c" + ] + ] + dump: | + - a + - - b + - c +)RAW"; + +static constexpr std::string_view T_G4RS = R"RAW( +--- +- name: Spec Example 2.17. Quoted Scalars + from: http://www.yaml.org/spec/1.2/spec.html#id2761245 + tags: spec scalar + yaml: | + unicode: "Sosa did fine.\u263A" + control: "\b1998\t1999\t2000\n" + hex esc: "\x0d\x0a is \r\n" + + single: '"Howdy!" he cried.' + quoted: ' # Not a ''comment''.' + tie-fighter: '|\-*-/|' + tree: | + +STR + +DOC + +MAP + =VAL :unicode + =VAL "Sosa did fine.☺ + =VAL :control + =VAL "\b1998\t1999\t2000\n + =VAL :hex esc + =VAL "\r\n is \r\n + =VAL :single + =VAL '"Howdy!" he cried. + =VAL :quoted + =VAL ' # Not a 'comment'. + =VAL :tie-fighter + =VAL '|\\-*-/| + -MAP + -DOC + -STR + json: | + { + "unicode": "Sosa did fine.☺", + "control": "\b1998\t1999\t2000\n", + "hex esc": "\r\n is \r\n", + "single": "\"Howdy!\" he cried.", + "quoted": " # Not a 'comment'.", + "tie-fighter": "|\\-*-/|" + } + dump: | + unicode: "Sosa did fine.\u263A" + control: "\b1998\t1999\t2000\n" + hex esc: "\r\n is \r\n" + single: '"Howdy!" he cried.' + quoted: ' # Not a ''comment''.' + tie-fighter: '|\-*-/|' +)RAW"; + +static constexpr std::string_view T_G5U8 = R"RAW( +--- +- name: Plain dashes in flow sequence + from: '@ingydotnet' + tags: flow sequence + fail: true + yaml: | + --- + - [-, -] + tree: | + +STR + +DOC --- + +SEQ + +SEQ [] +)RAW"; + +static constexpr std::string_view T_G7JE = R"RAW( +--- +- name: Multiline implicit keys + from: '@perlpunk' + tags: error mapping + fail: true + yaml: | + a\nb: 1 + c + d: 1 + tree: | + +STR + +DOC + +MAP + =VAL :a\\nb + =VAL :1 +)RAW"; + +static constexpr std::string_view T_G992 = R"RAW( +--- +- name: Spec Example 8.9. Folded Scalar + from: http://www.yaml.org/spec/1.2/spec.html#id2796371 + tags: spec folded scalar 1.3-err + yaml: | + > + folded + text + ↵ + ↵ + tree: | + +STR + +DOC + =VAL >folded text\n + -DOC + -STR + json: | + "folded text\n" + dump: | + > + folded text +)RAW"; + +static constexpr std::string_view T_G9HC = R"RAW( +--- +- name: Invalid anchor in zero indented sequence + from: '@perlpunk' + tags: anchor error sequence + fail: true + yaml: | + --- + seq: + &anchor + - a + - b + tree: | + +STR + +DOC --- + +MAP + =VAL :seq +)RAW"; + +static constexpr std::string_view T_GDY7 = R"RAW( +--- +- name: Comment that looks like a mapping key + from: '@perlpunk' + tags: comment error mapping + fail: true + yaml: | + key: value + this is #not a: key + tree: | + +STR + +DOC + +MAP + =VAL :key + =VAL :value +)RAW"; + +static constexpr std::string_view T_GH63 = R"RAW( +--- +- name: Mixed Block Mapping (explicit to implicit) + from: NimYAML tests + tags: explicit-key mapping + yaml: | + ? a + : 1.3 + fifteen: d + tree: | + +STR + +DOC + +MAP + =VAL :a + =VAL :1.3 + =VAL :fifteen + =VAL :d + -MAP + -DOC + -STR + json: | + { + "a": 1.3, + "fifteen": "d" + } + dump: | + a: 1.3 + fifteen: d +)RAW"; + +static constexpr std::string_view T_GT5M = R"RAW( +--- +- name: Node anchor in sequence + from: '@perlpunk' + tags: anchor error sequence + fail: true + yaml: | + - item1 + &node + - item2 + tree: | + +STR + +DOC + +SEQ + =VAL :item1 +)RAW"; + +static constexpr std::string_view T_H2RW = R"RAW( +--- +- name: Blank lines + from: IRC discussion with leont + tags: comment literal scalar whitespace + yaml: | + foo: 1 + + bar: 2 + ␣␣␣␣ + text: | + a + ␣␣␣␣ + b + + c + ␣ + d + tree: | + +STR + +DOC + +MAP + =VAL :foo + =VAL :1 + =VAL :bar + =VAL :2 + =VAL :text + =VAL |a\n \nb\n\nc\n\nd\n + -MAP + -DOC + -STR + json: | + { + "foo": 1, + "bar": 2, + "text": "a\n \nb\n\nc\n\nd\n" + } + dump: | + foo: 1 + bar: 2 + text: "a\n \nb\n\nc\n\nd\n" + emit: | + foo: 1 + bar: 2 + text: | + a + ␣␣␣␣ + b + + c + + d +)RAW"; + +static constexpr std::string_view T_H3Z8 = R"RAW( +--- +- name: Literal unicode + from: '@perlpunk' + tags: scalar + yaml: | + --- + wanted: love ♥ and peace ☮ + tree: | + +STR + +DOC --- + +MAP + =VAL :wanted + =VAL :love ♥ and peace ☮ + -MAP + -DOC + -STR + json: | + { + "wanted": "love ♥ and peace ☮" + } + dump: | + --- + wanted: "love \u2665 and peace \u262E" +)RAW"; + +static constexpr std::string_view T_H7J7 = R"RAW( +--- +- name: Node anchor not indented + from: https://gist.github.com/anonymous/f192e7dab6da31831f264dbf1947cb83 via @ingydotnet + tags: anchor error indent tag + fail: true + yaml: | + key: &x + !!map + a: b + tree: | + +STR + +DOC + +MAP + =VAL :key + =VAL &x : +)RAW"; + +static constexpr std::string_view T_H7TQ = R"RAW( +--- +- name: Extra words on %YAML directive + from: '@ingydotnet' + tags: directive + fail: true + yaml: | + %YAML 1.2 foo + --- + tree: | + +STR +)RAW"; + +static constexpr std::string_view T_HM87 = R"RAW( +--- +- name: Scalars in flow start with syntax char + from: '@ingydotnet' + tags: flow scalar + yaml: | + [:x] + tree: | + +STR + +DOC + +SEQ [] + =VAL ::x + -SEQ + -DOC + -STR + json: | + [ + ":x" + ] + dump: | + - :x + +- yaml: | + [?x] + tree: | + +STR + +DOC + +SEQ [] + =VAL :?x + -SEQ + -DOC + -STR + json: | + [ + "?x" + ] + dump: | + - ?x +)RAW"; + +static constexpr std::string_view T_HMK4 = R"RAW( +--- +- name: Spec Example 2.16. Indentation determines scope + from: http://www.yaml.org/spec/1.2/spec.html#id2761083 + tags: spec folded literal + yaml: | + name: Mark McGwire + accomplishment: > + Mark set a major league + home run record in 1998. + stats: | + 65 Home Runs + 0.278 Batting Average + tree: | + +STR + +DOC + +MAP + =VAL :name + =VAL :Mark McGwire + =VAL :accomplishment + =VAL >Mark set a major league home run record in 1998.\n + =VAL :stats + =VAL |65 Home Runs\n0.278 Batting Average\n + -MAP + -DOC + -STR + json: | + { + "name": "Mark McGwire", + "accomplishment": "Mark set a major league home run record in 1998.\n", + "stats": "65 Home Runs\n0.278 Batting Average\n" + } + dump: | + name: Mark McGwire + accomplishment: > + Mark set a major league home run record in 1998. + stats: | + 65 Home Runs + 0.278 Batting Average +)RAW"; + +static constexpr std::string_view T_HMQ5 = R"RAW( +--- +- name: Spec Example 6.23. Node Properties + from: http://www.yaml.org/spec/1.2/spec.html#id2783940 + tags: spec tag alias + yaml: | + !!str &a1 "foo": + !!str bar + &a2 baz : *a1 + tree: | + +STR + +DOC + +MAP + =VAL &a1 "foo + =VAL :bar + =VAL &a2 :baz + =ALI *a1 + -MAP + -DOC + -STR + json: | + { + "foo": "bar", + "baz": "foo" + } + dump: | + &a1 !!str "foo": !!str bar + &a2 baz: *a1 +)RAW"; + +static constexpr std::string_view T_HRE5 = R"RAW( +--- +- name: Double quoted scalar with escaped single quote + from: https://github.com/yaml/libyaml/issues/68 + tags: double error single + fail: true + yaml: | + --- + double: "quoted \' scalar" + tree: | + +STR + +DOC --- + +MAP + =VAL :double +)RAW"; + +static constexpr std::string_view T_HS5T = R"RAW( +--- +- name: Spec Example 7.12. Plain Lines + from: http://www.yaml.org/spec/1.2/spec.html#id2789986 + tags: spec scalar whitespace upto-1.2 + yaml: | + 1st non-empty + + 2nd non-empty␣ + ———»3rd non-empty + tree: | + +STR + +DOC + =VAL :1st non-empty\n2nd non-empty 3rd non-empty + -DOC + -STR + json: | + "1st non-empty\n2nd non-empty 3rd non-empty" + dump: | + '1st non-empty + + 2nd non-empty 3rd non-empty' +)RAW"; + +static constexpr std::string_view T_HU3P = R"RAW( +--- +- name: Invalid Mapping in plain scalar + from: https://gist.github.com/anonymous/d305fd8e54cfe7a484088c91a8a2e533 via @ingydotnet + tags: error mapping scalar + fail: true + yaml: | + key: + word1 word2 + no: key + tree: | + +STR + +DOC + +MAP + =VAL :key +)RAW"; + +static constexpr std::string_view T_HWV9 = R"RAW( +--- +- name: Document-end marker + from: '@perlpunk' + tags: footer + yaml: | + ... + tree: | + +STR + -STR + json: '' + dump: '' +)RAW"; + +static constexpr std::string_view T_J3BT = R"RAW( +--- +- name: Spec Example 5.12. Tabs and Spaces + from: http://www.yaml.org/spec/1.2/spec.html#id2775350 + tags: spec whitespace upto-1.2 + yaml: | + # Tabs and spaces + quoted: "Quoted ———»" + block:—»| + void main() { + —»printf("Hello, world!\n"); + } + tree: | + +STR + +DOC + +MAP + =VAL :quoted + =VAL "Quoted \t + =VAL :block + =VAL |void main() {\n\tprintf("Hello, world!\\n");\n}\n + -MAP + -DOC + -STR + json: | + { + "quoted": "Quoted \t", + "block": "void main() {\n\tprintf(\"Hello, world!\\n\");\n}\n" + } + dump: | + quoted: "Quoted \t" + block: | + void main() { + —»printf("Hello, world!\n"); + } +)RAW"; + +static constexpr std::string_view T_J5UC = R"RAW( +--- +- name: Multiple Pair Block Mapping + from: https://github.com/ingydotnet/yaml-pegex-pm/blob/master/test/mapping.tml + tags: mapping + yaml: | + foo: blue + bar: arrr + baz: jazz + tree: | + +STR + +DOC + +MAP + =VAL :foo + =VAL :blue + =VAL :bar + =VAL :arrr + =VAL :baz + =VAL :jazz + -MAP + -DOC + -STR + json: | + { + "foo": "blue", + "bar": "arrr", + "baz": "jazz" + } +)RAW"; + +static constexpr std::string_view T_J7PZ = R"RAW( +--- +- name: Spec Example 2.26. Ordered Mappings + from: http://www.yaml.org/spec/1.2/spec.html#id2761780 + tags: spec mapping tag unknown-tag + yaml: | + # The !!omap tag is one of the optional types + # introduced for YAML 1.1. In 1.2, it is not + # part of the standard tags and should not be + # enabled by default. + # Ordered maps are represented as + # A sequence of mappings, with + # each mapping having one key + --- !!omap + - Mark McGwire: 65 + - Sammy Sosa: 63 + - Ken Griffy: 58 + tree: | + +STR + +DOC --- + +SEQ + +MAP + =VAL :Mark McGwire + =VAL :65 + -MAP + +MAP + =VAL :Sammy Sosa + =VAL :63 + -MAP + +MAP + =VAL :Ken Griffy + =VAL :58 + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "Mark McGwire": 65 + }, + { + "Sammy Sosa": 63 + }, + { + "Ken Griffy": 58 + } + ] + dump: | + --- !!omap + - Mark McGwire: 65 + - Sammy Sosa: 63 + - Ken Griffy: 58 +)RAW"; + +static constexpr std::string_view T_J7VC = R"RAW( +--- +- name: Empty Lines Between Mapping Elements + from: NimYAML tests + tags: whitespace mapping + yaml: | + one: 2 + + + three: 4 + tree: | + +STR + +DOC + +MAP + =VAL :one + =VAL :2 + =VAL :three + =VAL :4 + -MAP + -DOC + -STR + json: | + { + "one": 2, + "three": 4 + } + dump: | + one: 2 + three: 4 +)RAW"; + +static constexpr std::string_view T_J9HZ = R"RAW( +--- +- name: Spec Example 2.9. Single Document with Two Comments + from: http://www.yaml.org/spec/1.2/spec.html#id2760633 + tags: mapping sequence spec comment + yaml: | + --- + hr: # 1998 hr ranking + - Mark McGwire + - Sammy Sosa + rbi: + # 1998 rbi ranking + - Sammy Sosa + - Ken Griffey + tree: | + +STR + +DOC --- + +MAP + =VAL :hr + +SEQ + =VAL :Mark McGwire + =VAL :Sammy Sosa + -SEQ + =VAL :rbi + +SEQ + =VAL :Sammy Sosa + =VAL :Ken Griffey + -SEQ + -MAP + -DOC + -STR + json: | + { + "hr": [ + "Mark McGwire", + "Sammy Sosa" + ], + "rbi": [ + "Sammy Sosa", + "Ken Griffey" + ] + } + dump: | + --- + hr: + - Mark McGwire + - Sammy Sosa + rbi: + - Sammy Sosa + - Ken Griffey +)RAW"; + +static constexpr std::string_view T_JEF9 = R"RAW( +--- +- name: Trailing whitespace in streams + from: '@ingydotnet' + tags: literal + yaml: | + - |+ + ↵ + ↵ + tree: | + +STR + +DOC + +SEQ + =VAL |\n\n + -SEQ + -DOC + -STR + json: | + [ + "\n\n" + ] + dump: | + - |+ + ↵ + ↵ + ... + +- yaml: | + - |+ + ␣␣␣ + tree: | + +STR + +DOC + +SEQ + =VAL |\n + -SEQ + -DOC + -STR + json: | + [ + "\n" + ] + dump: | + - |+ + + ... + +- yaml: | + - |+ + ␣␣␣∎ + dump: | + - |+ + + ... +)RAW"; + +static constexpr std::string_view T_JHB9 = R"RAW( +--- +- name: Spec Example 2.7. Two Documents in a Stream + from: http://www.yaml.org/spec/1.2/spec.html#id2760493 + tags: spec header + yaml: | + # Ranking of 1998 home runs + --- + - Mark McGwire + - Sammy Sosa + - Ken Griffey + + # Team ranking + --- + - Chicago Cubs + - St Louis Cardinals + tree: | + +STR + +DOC --- + +SEQ + =VAL :Mark McGwire + =VAL :Sammy Sosa + =VAL :Ken Griffey + -SEQ + -DOC + +DOC --- + +SEQ + =VAL :Chicago Cubs + =VAL :St Louis Cardinals + -SEQ + -DOC + -STR + json: | + [ + "Mark McGwire", + "Sammy Sosa", + "Ken Griffey" + ] + [ + "Chicago Cubs", + "St Louis Cardinals" + ] + dump: | + --- + - Mark McGwire + - Sammy Sosa + - Ken Griffey + --- + - Chicago Cubs + - St Louis Cardinals +)RAW"; + +static constexpr std::string_view T_JKF3 = R"RAW( +--- +- name: Multiline unidented double quoted block key + from: '@ingydotnet' + tags: indent + fail: true + yaml: | + - - "bar + bar": x + tree: | + +STR + +DOC + +SEQ + +SEQ +)RAW"; + +static constexpr std::string_view T_JQ4R = R"RAW( +--- +- name: Spec Example 8.14. Block Sequence + from: http://www.yaml.org/spec/1.2/spec.html#id2797596 + tags: mapping spec sequence + yaml: | + block sequence: + - one + - two : three + tree: | + +STR + +DOC + +MAP + =VAL :block sequence + +SEQ + =VAL :one + +MAP + =VAL :two + =VAL :three + -MAP + -SEQ + -MAP + -DOC + -STR + json: | + { + "block sequence": [ + "one", + { + "two": "three" + } + ] + } + dump: | + block sequence: + - one + - two: three +)RAW"; + +static constexpr std::string_view T_JR7V = R"RAW( +--- +- name: Question marks in scalars + from: '@perlpunk' + tags: flow scalar + yaml: | + - a?string + - another ? string + - key: value? + - [a?string] + - [another ? string] + - {key: value? } + - {key: value?} + - {key?: value } + tree: | + +STR + +DOC + +SEQ + =VAL :a?string + =VAL :another ? string + +MAP + =VAL :key + =VAL :value? + -MAP + +SEQ [] + =VAL :a?string + -SEQ + +SEQ [] + =VAL :another ? string + -SEQ + +MAP {} + =VAL :key + =VAL :value? + -MAP + +MAP {} + =VAL :key + =VAL :value? + -MAP + +MAP {} + =VAL :key? + =VAL :value + -MAP + -SEQ + -DOC + -STR + json: | + [ + "a?string", + "another ? string", + { + "key": "value?" + }, + [ + "a?string" + ], + [ + "another ? string" + ], + { + "key": "value?" + }, + { + "key": "value?" + }, + { + "key?": "value" + } + ] + dump: | + - a?string + - another ? string + - key: value? + - - a?string + - - another ? string + - key: value? + - key: value? + - key?: value +)RAW"; + +static constexpr std::string_view T_JS2J = R"RAW( +--- +- name: Spec Example 6.29. Node Anchors + from: http://www.yaml.org/spec/1.2/spec.html#id2785977 + tags: spec alias + yaml: | + First occurrence: &anchor Value + Second occurrence: *anchor + tree: | + +STR + +DOC + +MAP + =VAL :First occurrence + =VAL &anchor :Value + =VAL :Second occurrence + =ALI *anchor + -MAP + -DOC + -STR + json: | + { + "First occurrence": "Value", + "Second occurrence": "Value" + } +)RAW"; + +static constexpr std::string_view T_JTV5 = R"RAW( +--- +- name: Block Mapping with Multiline Scalars + from: NimYAML tests + tags: explicit-key mapping scalar + yaml: | + ? a + true + : null + d + ? e + 42 + tree: | + +STR + +DOC + +MAP + =VAL :a true + =VAL :null d + =VAL :e 42 + =VAL : + -MAP + -DOC + -STR + json: | + { + "a true": "null d", + "e 42": null + } + dump: | + a true: null d + e 42: +)RAW"; + +static constexpr std::string_view T_JY7Z = R"RAW( +--- +- name: Trailing content that looks like a mapping + from: '@perlpunk' + tags: error mapping double + fail: true + yaml: | + key1: "quoted1" + key2: "quoted2" no key: nor value + key3: "quoted3" + tree: | + +STR + +DOC + +MAP + =VAL :key1 + =VAL "quoted1 + =VAL :key2 + =VAL "quoted2 +)RAW"; + +static constexpr std::string_view T_K3WX = R"RAW( +--- +- name: Colon and adjacent value after comment on next line + from: + tags: comment flow mapping + yaml: | + --- + { "foo" # comment + :bar } + tree: | + +STR + +DOC --- + +MAP {} + =VAL "foo + =VAL :bar + -MAP + -DOC + -STR + json: | + { + "foo": "bar" + } + dump: | + --- + "foo": bar +)RAW"; + +static constexpr std::string_view T_K4SU = R"RAW( +--- +- name: Multiple Entry Block Sequence + from: https://github.com/ingydotnet/yaml-pegex-pm/blob/master/test/sequence.tml + tags: sequence + yaml: | + - foo + - bar + - 42 + tree: | + +STR + +DOC + +SEQ + =VAL :foo + =VAL :bar + =VAL :42 + -SEQ + -DOC + -STR + json: | + [ + "foo", + "bar", + 42 + ] +)RAW"; + +static constexpr std::string_view T_K527 = R"RAW( +--- +- name: Spec Example 6.6. Line Folding + from: http://www.yaml.org/spec/1.2/spec.html#id2779289 + tags: folded spec whitespace scalar 1.3-err + yaml: | + >- + trimmed + ␣␣ + ␣ + + as + space + tree: | + +STR + +DOC + =VAL >trimmed\n\n\nas space + -DOC + -STR + json: | + "trimmed\n\n\nas space" + dump: | + >- + trimmed + + + + as space +)RAW"; + +static constexpr std::string_view T_K54U = R"RAW( +--- +- name: Tab after document header + from: '@perlpunk' + tags: header whitespace + yaml: | + ---»scalar + tree: | + +STR + +DOC --- + =VAL :scalar + -DOC + -STR + json: | + "scalar" + dump: | + --- scalar + ... +)RAW"; + +static constexpr std::string_view T_K858 = R"RAW( +--- +- name: Spec Example 8.6. Empty Scalar Chomping + from: http://www.yaml.org/spec/1.2/spec.html#id2795596 + tags: spec folded literal whitespace + yaml: | + strip: >- + + clip: > + + keep: |+ + ↵ + tree: | + +STR + +DOC + +MAP + =VAL :strip + =VAL > + =VAL :clip + =VAL > + =VAL :keep + =VAL |\n + -MAP + -DOC + -STR + json: | + { + "strip": "", + "clip": "", + "keep": "\n" + } + dump: | + strip: "" + clip: "" + keep: |2+ + + ... +)RAW"; + +static constexpr std::string_view T_KH5V = R"RAW( +--- +- name: Inline tabs in double quoted + from: '@ingydotnet' + tags: double whitespace + yaml: | + "1 inline\ttab" + tree: | + +STR + +DOC + =VAL "1 inline\ttab + -DOC + -STR + json: | + "1 inline\ttab" + +- yaml: | + "2 inline\——»tab" + tree: | + +STR + +DOC + =VAL "2 inline\ttab + -DOC + -STR + json: | + "2 inline\ttab" + dump: | + "2 inline\ttab" + +- yaml: | + "3 inline———»tab" + tree: | + +STR + +DOC + =VAL "3 inline\ttab + -DOC + -STR + json: | + "3 inline\ttab" + dump: | + "3 inline\ttab" +)RAW"; + +static constexpr std::string_view T_KK5P = R"RAW( +--- +- name: Various combinations of explicit block mappings + from: '@perlpunk' + tags: explicit-key mapping sequence + yaml: | + complex1: + ? - a + complex2: + ? - a + : b + complex3: + ? - a + : > + b + complex4: + ? > + a + : + complex5: + ? - a + : - b + tree: | + +STR + +DOC + +MAP + =VAL :complex1 + +MAP + +SEQ + =VAL :a + -SEQ + =VAL : + -MAP + =VAL :complex2 + +MAP + +SEQ + =VAL :a + -SEQ + =VAL :b + -MAP + =VAL :complex3 + +MAP + +SEQ + =VAL :a + -SEQ + =VAL >b\n + -MAP + =VAL :complex4 + +MAP + =VAL >a\n + =VAL : + -MAP + =VAL :complex5 + +MAP + +SEQ + =VAL :a + -SEQ + +SEQ + =VAL :b + -SEQ + -MAP + -MAP + -DOC + -STR + dump: | + complex1: + ? - a + : + complex2: + ? - a + : b + complex3: + ? - a + : > + b + complex4: + ? > + a + : + complex5: + ? - a + : - b +)RAW"; + +static constexpr std::string_view T_KMK3 = R"RAW( +--- +- name: Block Submapping + from: https://github.com/ingydotnet/yaml-pegex-pm/blob/master/test/mapping.tml + tags: mapping + yaml: | + foo: + bar: 1 + baz: 2 + tree: | + +STR + +DOC + +MAP + =VAL :foo + +MAP + =VAL :bar + =VAL :1 + -MAP + =VAL :baz + =VAL :2 + -MAP + -DOC + -STR + json: | + { + "foo": { + "bar": 1 + }, + "baz": 2 + } +)RAW"; + +static constexpr std::string_view T_KS4U = R"RAW( +--- +- name: Invalid item after end of flow sequence + from: '@perlpunk' + tags: error flow sequence + fail: true + yaml: | + --- + [ + sequence item + ] + invalid item + tree: | + +STR + +DOC --- + +SEQ [] + =VAL :sequence item + -SEQ +)RAW"; + +static constexpr std::string_view T_KSS4 = R"RAW( +--- +- name: Scalars on --- line + from: '@perlpunk' + tags: anchor header scalar 1.3-err + yaml: | + --- "quoted + string" + --- &node foo + tree: | + +STR + +DOC --- + =VAL "quoted string + -DOC + +DOC --- + =VAL &node :foo + -DOC + -STR + json: | + "quoted string" + "foo" + dump: | + --- "quoted string" + --- &node foo + ... + emit: | + --- "quoted string" + --- &node foo +)RAW"; + +static constexpr std::string_view T_L24T = R"RAW( +--- +- name: Trailing line of spaces + from: '@ingydotnet' + tags: whitespace + yaml: | + foo: | + x + ␣␣␣ + tree: | + +STR + +DOC + +MAP + =VAL :foo + =VAL |x\n \n + -MAP + -DOC + -STR + json: | + { + "foo" : "x\n \n" + } + emit: | + --- + foo: "x\n \n" + +- yaml: | + foo: | + x + ␣␣␣∎ + tree: | + +STR + +DOC + +MAP + =VAL :foo + =VAL |x\n \n + -MAP + -DOC + -STR + json: | + { + "foo" : "x\n \n" + } + emit: | + --- + foo: "x\n \n" +)RAW"; + +static constexpr std::string_view T_L383 = R"RAW( +--- +- name: Two scalar docs with trailing comments + from: '@ingydotnet' + tags: comment + yaml: | + --- foo # comment + --- foo # comment + tree: | + +STR + +DOC --- + =VAL :foo + -DOC + +DOC --- + =VAL :foo + -DOC + -STR + json: | + "foo" + "foo" + dump: | + --- foo + --- foo +)RAW"; + +static constexpr std::string_view T_L94M = R"RAW( +--- +- name: Tags in Explicit Mapping + from: NimYAML tests + tags: explicit-key tag mapping + yaml: | + ? !!str a + : !!int 47 + ? c + : !!str d + tree: | + +STR + +DOC + +MAP + =VAL :a + =VAL :47 + =VAL :c + =VAL :d + -MAP + -DOC + -STR + json: | + { + "a": 47, + "c": "d" + } + dump: | + !!str a: !!int 47 + c: !!str d +)RAW"; + +static constexpr std::string_view T_L9U5 = R"RAW( +--- +- name: Spec Example 7.11. Plain Implicit Keys + from: http://www.yaml.org/spec/1.2/spec.html#id2789794 + tags: spec flow mapping + yaml: | + implicit block key : [ + implicit flow key : value, + ] + tree: | + +STR + +DOC + +MAP + =VAL :implicit block key + +SEQ [] + +MAP {} + =VAL :implicit flow key + =VAL :value + -MAP + -SEQ + -MAP + -DOC + -STR + json: | + { + "implicit block key": [ + { + "implicit flow key": "value" + } + ] + } + dump: | + implicit block key: + - implicit flow key: value +)RAW"; + +static constexpr std::string_view T_LE5A = R"RAW( +--- +- name: Spec Example 7.24. Flow Nodes + from: http://www.yaml.org/spec/1.2/spec.html#id2793490 + tags: spec tag alias + yaml: | + - !!str "a" + - 'b' + - &anchor "c" + - *anchor + - !!str + tree: | + +STR + +DOC + +SEQ + =VAL "a + =VAL 'b + =VAL &anchor "c + =ALI *anchor + =VAL : + -SEQ + -DOC + -STR + json: | + [ + "a", + "b", + "c", + "c", + "" + ] +)RAW"; + +static constexpr std::string_view T_LHL4 = R"RAW( +--- +- name: Invalid tag + from: '@perlpunk' + tags: error tag + fail: true + yaml: | + --- + !invalid{}tag scalar + tree: | + +STR + +DOC --- +)RAW"; + +static constexpr std::string_view T_LP6E = R"RAW( +--- +- name: Whitespace After Scalars in Flow + from: NimYAML tests + tags: flow scalar whitespace + yaml: | + - [a, b , c ] + - { "a" : b + , c : 'd' , + e : "f" + } + - [ ] + tree: | + +STR + +DOC + +SEQ + +SEQ [] + =VAL :a + =VAL :b + =VAL :c + -SEQ + +MAP {} + =VAL "a + =VAL :b + =VAL :c + =VAL 'd + =VAL :e + =VAL "f + -MAP + +SEQ [] + -SEQ + -SEQ + -DOC + -STR + json: | + [ + [ + "a", + "b", + "c" + ], + { + "a": "b", + "c": "d", + "e": "f" + }, + [] + ] + dump: | + - - a + - b + - c + - "a": b + c: 'd' + e: "f" + - [] +)RAW"; + +static constexpr std::string_view T_LQZ7 = R"RAW( +--- +- name: Spec Example 7.4. Double Quoted Implicit Keys + from: http://www.yaml.org/spec/1.2/spec.html#id2787420 + tags: spec scalar flow + yaml: | + "implicit block key" : [ + "implicit flow key" : value, + ] + tree: | + +STR + +DOC + +MAP + =VAL "implicit block key + +SEQ [] + +MAP {} + =VAL "implicit flow key + =VAL :value + -MAP + -SEQ + -MAP + -DOC + -STR + json: | + { + "implicit block key": [ + { + "implicit flow key": "value" + } + ] + } + dump: | + "implicit block key": + - "implicit flow key": value +)RAW"; + +static constexpr std::string_view T_LX3P = R"RAW( +--- +- name: Implicit Flow Mapping Key on one line + from: '@perlpunk' + tags: complex-key mapping flow sequence 1.3-err + yaml: | + [flow]: block + tree: | + +STR + +DOC + +MAP + +SEQ [] + =VAL :flow + -SEQ + =VAL :block + -MAP + -DOC + -STR + dump: | + ? - flow + : block +)RAW"; + +static constexpr std::string_view T_M29M = R"RAW( +--- +- name: Literal Block Scalar + from: NimYAML tests + tags: literal scalar whitespace + yaml: | + a: | + ab + ␣ + cd + ef + ␣ + + ... + tree: | + +STR + +DOC + +MAP + =VAL :a + =VAL |ab\n\ncd\nef\n + -MAP + -DOC ... + -STR + json: | + { + "a": "ab\n\ncd\nef\n" + } + dump: | + a: | + ab + + cd + ef + ... +)RAW"; + +static constexpr std::string_view T_M2N8 = R"RAW( +--- +- name: Question mark edge cases + from: '@ingydotnet' + tags: edge empty-key + yaml: | + - ? : x + tree: | + +STR + +DOC + +SEQ + +MAP + +MAP + =VAL : + =VAL :x + -MAP + =VAL : + -MAP + -SEQ + -DOC + -STR + dump: | + - ? : x + : + +- yaml: | + ? []: x + tree: | + +STR + +DOC + +MAP + +MAP + +SEQ [] + -SEQ + =VAL :x + -MAP + =VAL : + -MAP + -DOC + -STR + dump: | + ? []: x + : +)RAW"; + +static constexpr std::string_view T_M5C3 = R"RAW( +--- +- name: Spec Example 8.21. Block Scalar Nodes + from: http://www.yaml.org/spec/1.2/spec.html#id2799693 + tags: indent spec literal folded tag local-tag 1.3-err + yaml: | + literal: |2 + value + folded: + !foo + >1 + value + tree: | + +STR + +DOC + +MAP + =VAL :literal + =VAL |value\n + =VAL :folded + =VAL >value\n + -MAP + -DOC + -STR + json: | + { + "literal": "value\n", + "folded": "value\n" + } + dump: | + literal: | + value + folded: !foo > + value +)RAW"; + +static constexpr std::string_view T_M5DY = R"RAW( +--- +- name: Spec Example 2.11. Mapping between Sequences + from: http://www.yaml.org/spec/1.2/spec.html#id2760799 + tags: complex-key explicit-key spec mapping sequence + yaml: | + ? - Detroit Tigers + - Chicago cubs + : + - 2001-07-23 + + ? [ New York Yankees, + Atlanta Braves ] + : [ 2001-07-02, 2001-08-12, + 2001-08-14 ] + tree: | + +STR + +DOC + +MAP + +SEQ + =VAL :Detroit Tigers + =VAL :Chicago cubs + -SEQ + +SEQ + =VAL :2001-07-23 + -SEQ + +SEQ [] + =VAL :New York Yankees + =VAL :Atlanta Braves + -SEQ + +SEQ [] + =VAL :2001-07-02 + =VAL :2001-08-12 + =VAL :2001-08-14 + -SEQ + -MAP + -DOC + -STR + dump: | + ? - Detroit Tigers + - Chicago cubs + : - 2001-07-23 + ? - New York Yankees + - Atlanta Braves + : - 2001-07-02 + - 2001-08-12 + - 2001-08-14 +)RAW"; + +static constexpr std::string_view T_M6YH = R"RAW( +--- +- name: Block sequence indentation + from: '@ingydotnet' + tags: indent + yaml: | + - | + x + - + foo: bar + - + - 42 + tree: | + +STR + +DOC + +SEQ + =VAL |x\n + +MAP + =VAL :foo + =VAL :bar + -MAP + +SEQ + =VAL :42 + -SEQ + -SEQ + -DOC + -STR + json: | + [ + "x\n", + { + "foo" : "bar" + }, + [ + 42 + ] + ] + dump: | + - | + x + - foo: bar + - - 42 +)RAW"; + +static constexpr std::string_view T_M7A3 = R"RAW( +--- +- name: Spec Example 9.3. Bare Documents + from: http://www.yaml.org/spec/1.2/spec.html#id2801226 + tags: spec footer 1.3-err + yaml: | + Bare + document + ... + # No document + ... + | + %!PS-Adobe-2.0 # Not the first line + tree: | + +STR + +DOC + =VAL :Bare document + -DOC ... + +DOC + =VAL |%!PS-Adobe-2.0 # Not the first line\n + -DOC + -STR + json: | + "Bare document" + "%!PS-Adobe-2.0 # Not the first line\n" + emit: | + Bare document + ... + | + %!PS-Adobe-2.0 # Not the first line +)RAW"; + +static constexpr std::string_view T_M7NX = R"RAW( +--- +- name: Nested flow collections + from: '@perlpunk' + tags: flow mapping sequence + yaml: | + --- + { + a: [ + b, c, { + d: [e, f] + } + ] + } + tree: | + +STR + +DOC --- + +MAP {} + =VAL :a + +SEQ [] + =VAL :b + =VAL :c + +MAP {} + =VAL :d + +SEQ [] + =VAL :e + =VAL :f + -SEQ + -MAP + -SEQ + -MAP + -DOC + -STR + json: | + { + "a": [ + "b", + "c", + { + "d": [ + "e", + "f" + ] + } + ] + } + dump: | + --- + a: + - b + - c + - d: + - e + - f +)RAW"; + +static constexpr std::string_view T_M9B4 = R"RAW( +--- +- name: Spec Example 8.7. Literal Scalar + from: http://www.yaml.org/spec/1.2/spec.html#id2795789 + tags: spec literal scalar whitespace 1.3-err + yaml: | + | + literal + ——»text + ↵ + ↵ + tree: | + +STR + +DOC + =VAL |literal\n\ttext\n + -DOC + -STR + json: | + "literal\n\ttext\n" + dump: | + | + literal + —»text +)RAW"; + +static constexpr std::string_view T_MJS9 = R"RAW( +--- +- name: Spec Example 6.7. Block Folding + from: http://www.yaml.org/spec/1.2/spec.html#id2779603 + tags: folded spec scalar whitespace 1.3-err + yaml: | + > + foo␣ + ␣ + —» bar + + baz + tree: | + +STR + +DOC + =VAL >foo \n\n\t bar\n\nbaz\n + -DOC + -STR + json: | + "foo \n\n\t bar\n\nbaz\n" + dump: | + "foo \n\n\t bar\n\nbaz\n" +)RAW"; + +static constexpr std::string_view T_MUS6 = R"RAW( +- name: Directive variants + from: '@ingydotnet' + tags: directive + also: ZYU8 + fail: true + yaml: | + %YAML 1.1#... + --- + tree: | + +STR + +- fail: true + yaml: | + %YAML 1.2 + --- + %YAML 1.2 + --- + dump: null + +- yaml: | + %YAML 1.1 + --- + tree: | + +STR + +DOC --- + =VAL : + -DOC + -STR + json: | + null + dump: | + --- + +- yaml: | + %YAML ——» 1.1 + --- + +- yaml: | + %YAML 1.1 # comment + --- + +- note: These 2 are reserved directives + yaml: | + %YAM 1.1 + --- + +- yaml: | + %YAMLL 1.1 + --- +)RAW"; + +static constexpr std::string_view T_MXS3 = R"RAW( +--- +- name: Flow Mapping in Block Sequence + from: NimYAML tests + tags: mapping sequence flow + yaml: | + - {a: b} + tree: | + +STR + +DOC + +SEQ + +MAP {} + =VAL :a + =VAL :b + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "a": "b" + } + ] + dump: | + - a: b +)RAW"; + +static constexpr std::string_view T_MYW6 = R"RAW( +--- +- name: Block Scalar Strip + from: NimYAML tests + tags: literal scalar whitespace 1.3-err + yaml: | + |- + ab + ␣ + ␣ + ... + tree: | + +STR + +DOC + =VAL |ab + -DOC ... + -STR + json: | + "ab" + dump: | + |- + ab + ... +)RAW"; + +static constexpr std::string_view T_MZX3 = R"RAW( +--- +- name: Non-Specific Tags on Scalars + from: NimYAML tests + tags: folded scalar + yaml: | + - plain + - "double quoted" + - 'single quoted' + - > + block + - plain again + tree: | + +STR + +DOC + +SEQ + =VAL :plain + =VAL "double quoted + =VAL 'single quoted + =VAL >block\n + =VAL :plain again + -SEQ + -DOC + -STR + json: | + [ + "plain", + "double quoted", + "single quoted", + "block\n", + "plain again" + ] +)RAW"; + +static constexpr std::string_view T_N4JP = R"RAW( +--- +- name: Bad indentation in mapping + from: '@perlpunk' + tags: error mapping indent double + fail: true + yaml: | + map: + key1: "quoted1" + key2: "bad indentation" + tree: | + +STR + +DOC + +MAP + =VAL :map + +MAP + =VAL :key1 + =VAL "quoted1 + -MAP +)RAW"; + +static constexpr std::string_view T_N782 = R"RAW( +--- +- name: Invalid document markers in flow style + from: NimYAML tests + tags: flow edge header footer error + fail: true + yaml: | + [ + --- , + ... + ] + tree: | + +STR + +DOC + +SEQ [] +)RAW"; + +static constexpr std::string_view T_NAT4 = R"RAW( +--- +- name: Various empty or newline only quoted strings + from: '@perlpunk' + tags: double scalar single whitespace + yaml: | + --- + a: ' + ' + b: '␣␣ + ' + c: " + " + d: "␣␣ + " + e: ' + + ' + f: " + + " + g: ' + + + ' + h: " + + + " + tree: | + +STR + +DOC --- + +MAP + =VAL :a + =VAL '␣ + =VAL :b + =VAL '␣ + =VAL :c + =VAL "␣ + =VAL :d + =VAL "␣ + =VAL :e + =VAL '\n + =VAL :f + =VAL "\n + =VAL :g + =VAL '\n\n + =VAL :h + =VAL "\n\n + -MAP + -DOC + -STR + json: | + { + "a": " ", + "b": " ", + "c": " ", + "d": " ", + "e": "\n", + "f": "\n", + "g": "\n\n", + "h": "\n\n" + } + emit: | + --- + a: ' ' + b: ' ' + c: " " + d: " " + e: ' + + ' + f: "\n" + g: ' + + + ' + h: "\n\n" +)RAW"; + +static constexpr std::string_view T_NB6Z = R"RAW( +--- +- name: Multiline plain value with tabs on empty lines + from: '@perlpunk' + tags: scalar whitespace + yaml: | + key: + value + with + —» + tabs + tree: | + +STR + +DOC + +MAP + =VAL :key + =VAL :value with\ntabs + -MAP + -DOC + -STR + json: | + { + "key": "value with\ntabs" + } + dump: | + key: 'value with + + tabs' +)RAW"; + +static constexpr std::string_view T_NHX8 = R"RAW( +--- +- name: Empty Lines at End of Document + from: NimYAML tests + tags: empty-key whitespace + yaml: | + : + ↵ + ↵ + tree: | + +STR + +DOC + +MAP + =VAL : + =VAL : + -MAP + -DOC + -STR + emit: | + : +)RAW"; + +static constexpr std::string_view T_NJ66 = R"RAW( +--- +- name: Multiline plain flow mapping key + from: '@perlpunk' + tags: flow mapping + yaml: | + --- + - { single line: value} + - { multi + line: value} + tree: | + +STR + +DOC --- + +SEQ + +MAP {} + =VAL :single line + =VAL :value + -MAP + +MAP {} + =VAL :multi line + =VAL :value + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "single line": "value" + }, + { + "multi line": "value" + } + ] + dump: | + --- + - single line: value + - multi line: value +)RAW"; + +static constexpr std::string_view T_NKF9 = R"RAW( +--- +- name: Empty keys in block and flow mapping + from: '@perlpunk' + tags: empty-key mapping + yaml: | + --- + key: value + : empty key + --- + { + key: value, : empty key + } + --- + # empty key and value + : + --- + # empty key and value + { : } + tree: | + +STR + +DOC --- + +MAP + =VAL :key + =VAL :value + =VAL : + =VAL :empty key + -MAP + -DOC + +DOC --- + +MAP {} + =VAL :key + =VAL :value + =VAL : + =VAL :empty key + -MAP + -DOC + +DOC --- + +MAP + =VAL : + =VAL : + -MAP + -DOC + +DOC --- + +MAP {} + =VAL : + =VAL : + -MAP + -DOC + -STR + emit: | + --- + key: value + : empty key + --- + key: value + : empty key + --- + : + --- + : +)RAW"; + +static constexpr std::string_view T_NP9H = R"RAW( +--- +- name: Spec Example 7.5. Double Quoted Line Breaks + from: http://www.yaml.org/spec/1.2/spec.html#id2787745 + tags: double spec scalar whitespace upto-1.2 + yaml: | + "folded␣ + to a space,» + ␣ + to a line feed, or »\ + \ »non-content" + tree: | + +STR + +DOC + =VAL "folded to a space,\nto a line feed, or \t \tnon-content + -DOC + -STR + json: | + "folded to a space,\nto a line feed, or \t \tnon-content" + dump: | + "folded to a space,\nto a line feed, or \t \tnon-content" +)RAW"; + +static constexpr std::string_view T_P2AD = R"RAW( +--- +- name: Spec Example 8.1. Block Scalar Header + from: http://www.yaml.org/spec/1.2/spec.html#id2793888 + tags: spec literal folded comment scalar + yaml: | + - | # Empty header↓ + literal + - >1 # Indentation indicator↓ + folded + - |+ # Chomping indicator↓ + keep + + - >1- # Both indicators↓ + strip + tree: | + +STR + +DOC + +SEQ + =VAL |literal\n + =VAL > folded\n + =VAL |keep\n\n + =VAL > strip + -SEQ + -DOC + -STR + json: | + [ + "literal\n", + " folded\n", + "keep\n\n", + " strip" + ] + dump: | + - | + literal + - >2 + folded + - |+ + keep + + - >2- + strip +)RAW"; + +static constexpr std::string_view T_P2EQ = R"RAW( +--- +- name: Invalid sequene item on same line as previous item + from: '@perlpunk' + tags: error flow mapping sequence + fail: true + yaml: | + --- + - { y: z }- invalid + tree: | + +STR + +DOC --- + +SEQ + +MAP {} + =VAL :y + =VAL :z + -MAP +)RAW"; + +static constexpr std::string_view T_P76L = R"RAW( +--- +- name: Spec Example 6.19. Secondary Tag Handle + from: http://www.yaml.org/spec/1.2/spec.html#id2782940 + tags: spec header tag unknown-tag + yaml: | + %TAG !! tag:example.com,2000:app/ + --- + !!int 1 - 3 # Interval, not integer + tree: | + +STR + +DOC --- + =VAL :1 - 3 + -DOC + -STR + json: | + "1 - 3" + dump: | + --- ! 1 - 3 +)RAW"; + +static constexpr std::string_view T_P94K = R"RAW( +--- +- name: Spec Example 6.11. Multi-Line Comments + from: http://www.yaml.org/spec/1.2/spec.html#id2780696 + tags: spec comment + yaml: | + key: # Comment + # lines + value + ↵ + ↵ + tree: | + +STR + +DOC + +MAP + =VAL :key + =VAL :value + -MAP + -DOC + -STR + json: | + { + "key": "value" + } + dump: | + key: value +)RAW"; + +static constexpr std::string_view T_PBJ2 = R"RAW( +--- +- name: Spec Example 2.3. Mapping Scalars to Sequences + from: http://www.yaml.org/spec/1.2/spec.html#id2759963 + tags: spec mapping sequence + yaml: | + american: + - Boston Red Sox + - Detroit Tigers + - New York Yankees + national: + - New York Mets + - Chicago Cubs + - Atlanta Braves + tree: | + +STR + +DOC + +MAP + =VAL :american + +SEQ + =VAL :Boston Red Sox + =VAL :Detroit Tigers + =VAL :New York Yankees + -SEQ + =VAL :national + +SEQ + =VAL :New York Mets + =VAL :Chicago Cubs + =VAL :Atlanta Braves + -SEQ + -MAP + -DOC + -STR + json: | + { + "american": [ + "Boston Red Sox", + "Detroit Tigers", + "New York Yankees" + ], + "national": [ + "New York Mets", + "Chicago Cubs", + "Atlanta Braves" + ] + } + dump: | + american: + - Boston Red Sox + - Detroit Tigers + - New York Yankees + national: + - New York Mets + - Chicago Cubs + - Atlanta Braves +)RAW"; + +static constexpr std::string_view T_PRH3 = R"RAW( +--- +- name: Spec Example 7.9. Single Quoted Lines + from: http://www.yaml.org/spec/1.2/spec.html#id2788756 + tags: single spec scalar whitespace upto-1.2 + yaml: | + ' 1st non-empty + + 2nd non-empty␣ + ———»3rd non-empty ' + tree: | + +STR + +DOC + =VAL ' 1st non-empty\n2nd non-empty 3rd non-empty␣ + -DOC + -STR + json: | + " 1st non-empty\n2nd non-empty 3rd non-empty " + dump: | + ' 1st non-empty + + 2nd non-empty 3rd non-empty ' + emit: | + ' 1st non-empty + + 2nd non-empty 3rd non-empty ' +)RAW"; + +static constexpr std::string_view T_PUW8 = R"RAW( +--- +- name: Document start on last line + from: '@perlpunk' + tags: header + yaml: | + --- + a: b + --- + tree: | + +STR + +DOC --- + +MAP + =VAL :a + =VAL :b + -MAP + -DOC + +DOC --- + =VAL : + -DOC + -STR + json: | + { + "a": "b" + } + null + dump: | + --- + a: b + --- + ... +)RAW"; + +static constexpr std::string_view T_PW8X = R"RAW( +--- +- name: Anchors on Empty Scalars + from: NimYAML tests + tags: anchor explicit-key + yaml: | + - &a + - a + - + &a : a + b: &b + - + &c : &a + - + ? &d + - + ? &e + : &a + tree: | + +STR + +DOC + +SEQ + =VAL &a : + =VAL :a + +MAP + =VAL &a : + =VAL :a + =VAL :b + =VAL &b : + -MAP + +MAP + =VAL &c : + =VAL &a : + -MAP + +MAP + =VAL &d : + =VAL : + -MAP + +MAP + =VAL &e : + =VAL &a : + -MAP + -SEQ + -DOC + -STR + dump: | + - &a + - a + - &a : a + b: &b + - &c : &a + - &d : + - &e : &a +)RAW"; + +static constexpr std::string_view T_Q4CL = R"RAW( +--- +- name: Trailing content after quoted value + from: '@perlpunk' + tags: error mapping double + fail: true + yaml: | + key1: "quoted1" + key2: "quoted2" trailing content + key3: "quoted3" + tree: | + +STR + +DOC + +MAP + =VAL :key1 + =VAL "quoted1 + =VAL :key2 + =VAL "quoted2 +)RAW"; + +static constexpr std::string_view T_Q5MG = R"RAW( +--- +- name: Tab at beginning of line followed by a flow mapping + from: IRC + tags: flow whitespace + yaml: | + ———»{} + tree: | + +STR + +DOC + +MAP {} + -MAP + -DOC + -STR + json: | + {} + dump: | + {} +)RAW"; + +static constexpr std::string_view T_Q88A = R"RAW( +--- +- name: Spec Example 7.23. Flow Content + from: http://www.yaml.org/spec/1.2/spec.html#id2793163 + tags: spec flow sequence mapping + yaml: | + - [ a, b ] + - { a: b } + - "a" + - 'b' + - c + tree: | + +STR + +DOC + +SEQ + +SEQ [] + =VAL :a + =VAL :b + -SEQ + +MAP {} + =VAL :a + =VAL :b + -MAP + =VAL "a + =VAL 'b + =VAL :c + -SEQ + -DOC + -STR + json: | + [ + [ + "a", + "b" + ], + { + "a": "b" + }, + "a", + "b", + "c" + ] + dump: | + - - a + - b + - a: b + - "a" + - 'b' + - c +)RAW"; + +static constexpr std::string_view T_Q8AD = R"RAW( +--- +- name: Spec Example 7.5. Double Quoted Line Breaks [1.3] + from: NP9H, modified for YAML 1.3 + tags: double spec scalar whitespace 1.3-mod + yaml: | + --- + "folded␣ + to a space, + ␣ + to a line feed, or »\ + \ »non-content" + tree: | + +STR + +DOC --- + =VAL "folded to a space,\nto a line feed, or \t \tnon-content + -DOC + -STR + json: | + "folded to a space,\nto a line feed, or \t \tnon-content" + dump: | + "folded to a space,\nto a line feed, or \t \tnon-content" + emit: | + --- "folded to a space,\nto a line feed, or \t \tnon-content" +)RAW"; + +static constexpr std::string_view T_Q9WF = R"RAW( +--- +- name: Spec Example 6.12. Separation Spaces + from: http://www.yaml.org/spec/1.2/spec.html#id2780989 + tags: complex-key flow spec comment whitespace 1.3-err + yaml: | + { first: Sammy, last: Sosa }: + # Statistics: + hr: # Home runs + 65 + avg: # Average + 0.278 + tree: | + +STR + +DOC + +MAP + +MAP {} + =VAL :first + =VAL :Sammy + =VAL :last + =VAL :Sosa + -MAP + +MAP + =VAL :hr + =VAL :65 + =VAL :avg + =VAL :0.278 + -MAP + -MAP + -DOC + -STR + dump: | + ? first: Sammy + last: Sosa + : hr: 65 + avg: 0.278 +)RAW"; + +static constexpr std::string_view T_QB6E = R"RAW( +--- +- name: Wrong indented multiline quoted scalar + from: '@perlpunk' + tags: double error indent + fail: true + yaml: | + --- + quoted: "a + b + c" + tree: | + +STR + +DOC --- + +MAP + =VAL :quoted +)RAW"; + +static constexpr std::string_view T_QF4Y = R"RAW( +--- +- name: Spec Example 7.19. Single Pair Flow Mappings + from: http://www.yaml.org/spec/1.2/spec.html#id2792291 + tags: spec flow mapping + yaml: | + [ + foo: bar + ] + tree: | + +STR + +DOC + +SEQ [] + +MAP {} + =VAL :foo + =VAL :bar + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "foo": "bar" + } + ] + dump: | + - foo: bar +)RAW"; + +static constexpr std::string_view T_QLJ7 = R"RAW( +--- +- name: Tag shorthand used in documents but only defined in the first + from: IRC + tags: error directive tag + fail: true + yaml: | + %TAG !prefix! tag:example.com,2011: + --- !prefix!A + a: b + --- !prefix!B + c: d + --- !prefix!C + e: f + tree: | + +STR + +DOC --- + +MAP + =VAL :a + =VAL :b + -MAP + -DOC + +DOC --- +)RAW"; + +static constexpr std::string_view T_QT73 = R"RAW( +--- +- name: Comment and document-end marker + from: '@perlpunk' + tags: comment footer + yaml: | + # comment + ... + tree: | + +STR + -STR + json: '' + dump: '' +)RAW"; + +static constexpr std::string_view T_R4YG = R"RAW( +--- +- name: Spec Example 8.2. Block Indentation Indicator + from: http://www.yaml.org/spec/1.2/spec.html#id2794311 + tags: spec literal folded scalar whitespace libyaml-err upto-1.2 + yaml: | + - | + detected + - > + ␣ + ␣␣ + # detected + - |1 + explicit + - > + ——» + detected + tree: | + +STR + +DOC + +SEQ + =VAL |detected\n + =VAL >\n\n# detected\n + =VAL | explicit\n + =VAL >\t\ndetected\n + -SEQ + -DOC + -STR + json: | + [ + "detected\n", + "\n\n# detected\n", + " explicit\n", + "\t\ndetected\n" + ] + dump: | + - | + detected + - >2 + + + # detected + - |2 + explicit + - "\t\ndetected\n" +)RAW"; + +static constexpr std::string_view T_R52L = R"RAW( +--- +- name: Nested flow mapping sequence and mappings + from: '@perlpunk' + tags: flow mapping sequence + yaml: | + --- + { top1: [item1, {key2: value2}, item3], top2: value2 } + tree: | + +STR + +DOC --- + +MAP {} + =VAL :top1 + +SEQ [] + =VAL :item1 + +MAP {} + =VAL :key2 + =VAL :value2 + -MAP + =VAL :item3 + -SEQ + =VAL :top2 + =VAL :value2 + -MAP + -DOC + -STR + json: | + { + "top1": [ + "item1", + { + "key2": "value2" + }, + "item3" + ], + "top2": "value2" + } + dump: | + --- + top1: + - item1 + - key2: value2 + - item3 + top2: value2 +)RAW"; + +static constexpr std::string_view T_RHX7 = R"RAW( +--- +- name: YAML directive without document end marker + from: '@perlpunk' + tags: directive error + fail: true + yaml: | + --- + key: value + %YAML 1.2 + --- + tree: | + +STR + +DOC --- + +MAP + =VAL :key + =VAL :value +)RAW"; + +static constexpr std::string_view T_RLU9 = R"RAW( +--- +- name: Sequence Indent + from: https://github.com/ingydotnet/yaml-pegex-pm/blob/master/test/indent.tml + tags: sequence indent + yaml: | + foo: + - 42 + bar: + - 44 + tree: | + +STR + +DOC + +MAP + =VAL :foo + +SEQ + =VAL :42 + -SEQ + =VAL :bar + +SEQ + =VAL :44 + -SEQ + -MAP + -DOC + -STR + json: | + { + "foo": [ + 42 + ], + "bar": [ + 44 + ] + } + dump: | + foo: + - 42 + bar: + - 44 +)RAW"; + +static constexpr std::string_view T_RR7F = R"RAW( +--- +- name: Mixed Block Mapping (implicit to explicit) + from: NimYAML tests + tags: explicit-key mapping + yaml: | + a: 4.2 + ? d + : 23 + tree: | + +STR + +DOC + +MAP + =VAL :a + =VAL :4.2 + =VAL :d + =VAL :23 + -MAP + -DOC + -STR + json: | + { + "d": 23, + "a": 4.2 + } + dump: | + a: 4.2 + d: 23 +)RAW"; + +static constexpr std::string_view T_RTP8 = R"RAW( +--- +- name: Spec Example 9.2. Document Markers + from: http://www.yaml.org/spec/1.2/spec.html#id2800866 + tags: spec header footer + yaml: | + %YAML 1.2 + --- + Document + ... # Suffix + tree: | + +STR + +DOC --- + =VAL :Document + -DOC ... + -STR + json: | + "Document" + dump: | + --- Document + ... +)RAW"; + +static constexpr std::string_view T_RXY3 = R"RAW( +--- +- name: Invalid document-end marker in single quoted string + from: '@perlpunk' + tags: footer single error + fail: true + yaml: | + --- + ' + ... + ' + tree: | + +STR + +DOC --- +)RAW"; + +static constexpr std::string_view T_RZP5 = R"RAW( +--- +- name: Various Trailing Comments [1.3] + from: XW4D, modified for YAML 1.3 + tags: anchor comment folded mapping 1.3-mod + yaml: | + a: "double + quotes" # lala + b: plain + value # lala + c : #lala + d + ? # lala + - seq1 + : # lala + - #lala + seq2 + e: &node # lala + - x: y + block: > # lala + abcde + tree: | + +STR + +DOC + +MAP + =VAL :a + =VAL "double quotes + =VAL :b + =VAL :plain value + =VAL :c + =VAL :d + +SEQ + =VAL :seq1 + -SEQ + +SEQ + =VAL :seq2 + -SEQ + =VAL :e + +SEQ &node + +MAP + =VAL :x + =VAL :y + -MAP + -SEQ + =VAL :block + =VAL >abcde\n + -MAP + -DOC + -STR + dump: | + a: "double quotes" + b: plain value + c: d + ? - seq1 + : - seq2 + e: &node + - x: y + block: > + abcde +)RAW"; + +static constexpr std::string_view T_RZT7 = R"RAW( +--- +- name: Spec Example 2.28. Log File + from: http://www.yaml.org/spec/1.2/spec.html#id2761866 + tags: spec header literal mapping sequence + yaml: | + --- + Time: 2001-11-23 15:01:42 -5 + User: ed + Warning: + This is an error message + for the log file + --- + Time: 2001-11-23 15:02:31 -5 + User: ed + Warning: + A slightly different error + message. + --- + Date: 2001-11-23 15:03:17 -5 + User: ed + Fatal: + Unknown variable "bar" + Stack: + - file: TopClass.py + line: 23 + code: | + x = MoreObject("345\n") + - file: MoreClass.py + line: 58 + code: |- + foo = bar + tree: | + +STR + +DOC --- + +MAP + =VAL :Time + =VAL :2001-11-23 15:01:42 -5 + =VAL :User + =VAL :ed + =VAL :Warning + =VAL :This is an error message for the log file + -MAP + -DOC + +DOC --- + +MAP + =VAL :Time + =VAL :2001-11-23 15:02:31 -5 + =VAL :User + =VAL :ed + =VAL :Warning + =VAL :A slightly different error message. + -MAP + -DOC + +DOC --- + +MAP + =VAL :Date + =VAL :2001-11-23 15:03:17 -5 + =VAL :User + =VAL :ed + =VAL :Fatal + =VAL :Unknown variable "bar" + =VAL :Stack + +SEQ + +MAP + =VAL :file + =VAL :TopClass.py + =VAL :line + =VAL :23 + =VAL :code + =VAL |x = MoreObject("345\\n")\n + -MAP + +MAP + =VAL :file + =VAL :MoreClass.py + =VAL :line + =VAL :58 + =VAL :code + =VAL |foo = bar + -MAP + -SEQ + -MAP + -DOC + -STR + json: | + { + "Time": "2001-11-23 15:01:42 -5", + "User": "ed", + "Warning": "This is an error message for the log file" + } + { + "Time": "2001-11-23 15:02:31 -5", + "User": "ed", + "Warning": "A slightly different error message." + } + { + "Date": "2001-11-23 15:03:17 -5", + "User": "ed", + "Fatal": "Unknown variable \"bar\"", + "Stack": [ + { + "file": "TopClass.py", + "line": 23, + "code": "x = MoreObject(\"345\\n\")\n" + }, + { + "file": "MoreClass.py", + "line": 58, + "code": "foo = bar" + } + ] + } + dump: | + --- + Time: 2001-11-23 15:01:42 -5 + User: ed + Warning: This is an error message for the log file + --- + Time: 2001-11-23 15:02:31 -5 + User: ed + Warning: A slightly different error message. + --- + Date: 2001-11-23 15:03:17 -5 + User: ed + Fatal: Unknown variable "bar" + Stack: + - file: TopClass.py + line: 23 + code: | + x = MoreObject("345\n") + - file: MoreClass.py + line: 58 + code: |- + foo = bar +)RAW"; + +static constexpr std::string_view T_S3PD = R"RAW( +--- +- name: Spec Example 8.18. Implicit Block Mapping Entries + from: http://www.yaml.org/spec/1.2/spec.html#id2798896 + tags: empty-key spec mapping + yaml: | + plain key: in-line value + : # Both empty + "quoted key": + - entry + tree: | + +STR + +DOC + +MAP + =VAL :plain key + =VAL :in-line value + =VAL : + =VAL : + =VAL "quoted key + +SEQ + =VAL :entry + -SEQ + -MAP + -DOC + -STR + emit: | + plain key: in-line value + : + "quoted key": + - entry +)RAW"; + +static constexpr std::string_view T_S4GJ = R"RAW( +--- +- name: Invalid text after block scalar indicator + from: '@perlpunk' + tags: error folded + fail: true + yaml: | + --- + folded: > first line + second line + tree: | + +STR + +DOC --- + +MAP + =VAL :folded +)RAW"; + +static constexpr std::string_view T_S4JQ = R"RAW( +--- +- name: Spec Example 6.28. Non-Specific Tags + from: http://www.yaml.org/spec/1.2/spec.html#id2785512 + tags: spec tag + yaml: | + # Assuming conventional resolution: + - "12" + - 12 + - ! 12 + tree: | + +STR + +DOC + +SEQ + =VAL "12 + =VAL :12 + =VAL :12 + -SEQ + -DOC + -STR + json: | + [ + "12", + 12, + "12" + ] + dump: | + - "12" + - 12 + - ! 12 +)RAW"; + +static constexpr std::string_view T_S4T7 = R"RAW( +--- +- name: Document with footer + from: https://github.com/ingydotnet/yaml-pegex-pm/blob/master/test/footer.tml + tags: mapping footer + yaml: | + aaa: bbb + ... + tree: | + +STR + +DOC + +MAP + =VAL :aaa + =VAL :bbb + -MAP + -DOC ... + -STR + json: | + { + "aaa": "bbb" + } +)RAW"; + +static constexpr std::string_view T_S7BG = R"RAW( +--- +- name: Colon followed by comma + from: '@perlpunk' + tags: scalar + yaml: | + --- + - :, + tree: | + +STR + +DOC --- + +SEQ + =VAL ::, + -SEQ + -DOC + -STR + json: | + [ + ":," + ] + dump: | + --- + - :, +)RAW"; + +static constexpr std::string_view T_S98Z = R"RAW( +--- +- name: Block scalar with more spaces than first content line + from: '@perlpunk' + tags: error folded comment scalar whitespace + fail: true + yaml: | + empty block scalar: > + ␣ + ␣␣ + ␣␣␣ + # comment + tree: | + +STR + +DOC + +MAP + =VAL :empty block scalar +)RAW"; + +static constexpr std::string_view T_S9E8 = R"RAW( +--- +- name: Spec Example 5.3. Block Structure Indicators + from: http://www.yaml.org/spec/1.2/spec.html#id2772312 + tags: explicit-key spec mapping sequence + yaml: | + sequence: + - one + - two + mapping: + ? sky + : blue + sea : green + tree: | + +STR + +DOC + +MAP + =VAL :sequence + +SEQ + =VAL :one + =VAL :two + -SEQ + =VAL :mapping + +MAP + =VAL :sky + =VAL :blue + =VAL :sea + =VAL :green + -MAP + -MAP + -DOC + -STR + json: | + { + "sequence": [ + "one", + "two" + ], + "mapping": { + "sky": "blue", + "sea": "green" + } + } + dump: | + sequence: + - one + - two + mapping: + sky: blue + sea: green +)RAW"; + +static constexpr std::string_view T_SBG9 = R"RAW( +--- +- name: Flow Sequence in Flow Mapping + from: NimYAML tests + tags: complex-key sequence mapping flow + yaml: | + {a: [b, c], [d, e]: f} + tree: | + +STR + +DOC + +MAP {} + =VAL :a + +SEQ [] + =VAL :b + =VAL :c + -SEQ + +SEQ [] + =VAL :d + =VAL :e + -SEQ + =VAL :f + -MAP + -DOC + -STR + dump: | + a: + - b + - c + ? - d + - e + : f +)RAW"; + +static constexpr std::string_view T_SF5V = R"RAW( +--- +- name: Duplicate YAML directive + from: '@perlpunk' + tags: directive error + fail: true + yaml: | + %YAML 1.2 + %YAML 1.2 + --- + tree: | + +STR +)RAW"; + +static constexpr std::string_view T_SKE5 = R"RAW( +--- +- name: Anchor before zero indented sequence + from: '@perlpunk' + tags: anchor indent sequence + yaml: | + --- + seq: + &anchor + - a + - b + tree: | + +STR + +DOC --- + +MAP + =VAL :seq + +SEQ &anchor + =VAL :a + =VAL :b + -SEQ + -MAP + -DOC + -STR + json: | + { + "seq": [ + "a", + "b" + ] + } + dump: | + --- + seq: &anchor + - a + - b +)RAW"; + +static constexpr std::string_view T_SM9W = R"RAW( +--- +- name: Single character streams + from: '@ingydotnet' + tags: sequence + yaml: | + -∎ + tree: | + +STR + +DOC + +SEQ + =VAL : + -SEQ + -DOC + -STR + json: | + [null] + dump: | + - + +- tags: mapping + yaml: | + :∎ + tree: | + +STR + +DOC + +MAP + =VAL : + =VAL : + -MAP + -DOC + -STR + json: null + dump: | + : +)RAW"; + +static constexpr std::string_view T_SR86 = R"RAW( +--- +- name: Anchor plus Alias + from: '@perlpunk' + tags: alias error + fail: true + yaml: | + key1: &a value + key2: &b *a + tree: | + +STR + +DOC + +MAP + =VAL :key1 + =VAL &a :value + =VAL :key2 +)RAW"; + +static constexpr std::string_view T_SSW6 = R"RAW( +--- +- name: Spec Example 7.7. Single Quoted Characters [1.3] + from: 4GC6, modified for YAML 1.3 + tags: spec scalar single 1.3-mod + yaml: | + --- + 'here''s to "quotes"' + tree: | + +STR + +DOC --- + =VAL 'here's to "quotes" + -DOC + -STR + json: | + "here's to \"quotes\"" + dump: | + --- 'here''s to "quotes"' +)RAW"; + +static constexpr std::string_view T_SU5Z = R"RAW( +--- +- name: Comment without whitespace after doublequoted scalar + from: '@perlpunk' + tags: comment error double whitespace + fail: true + yaml: | + key: "value"# invalid comment + tree: | + +STR + +DOC + +MAP + =VAL :key + =VAL "value +)RAW"; + +static constexpr std::string_view T_SU74 = R"RAW( +--- +- name: Anchor and alias as mapping key + from: '@perlpunk' + tags: error anchor alias mapping + fail: true + yaml: | + key1: &alias value1 + &b *alias : value2 + tree: | + +STR + +DOC + +MAP + =VAL :key1 + =VAL &alias :value1 +)RAW"; + +static constexpr std::string_view T_SY6V = R"RAW( +--- +- name: Anchor before sequence entry on same line + from: '@perlpunk' + tags: anchor error sequence + fail: true + yaml: | + &anchor - sequence entry + tree: | + +STR +)RAW"; + +static constexpr std::string_view T_SYW4 = R"RAW( +--- +- name: Spec Example 2.2. Mapping Scalars to Scalars + from: http://www.yaml.org/spec/1.2/spec.html#id2759963 + tags: spec scalar comment + yaml: | + hr: 65 # Home runs + avg: 0.278 # Batting average + rbi: 147 # Runs Batted In + tree: | + +STR + +DOC + +MAP + =VAL :hr + =VAL :65 + =VAL :avg + =VAL :0.278 + =VAL :rbi + =VAL :147 + -MAP + -DOC + -STR + json: | + { + "hr": 65, + "avg": 0.278, + "rbi": 147 + } + dump: | + hr: 65 + avg: 0.278 + rbi: 147 +)RAW"; + +static constexpr std::string_view T_T26H = R"RAW( +--- +- name: Spec Example 8.8. Literal Content [1.3] + from: DWX9, modified for YAML 1.3 + tags: spec literal scalar comment whitespace 1.3-mod + yaml: | + --- | + ␣ + ␣␣ + literal + ␣␣␣ + ␣␣ + text + + # Comment + tree: | + +STR + +DOC --- + =VAL |\n\nliteral\n \n\ntext\n + -DOC + -STR + json: | + "\n\nliteral\n \n\ntext\n" + dump: | + "\n\nliteral\n \n\ntext\n" + emit: | + --- | + + + literal + ␣␣␣ + + text +)RAW"; + +static constexpr std::string_view T_T4YY = R"RAW( +--- +- name: Spec Example 7.9. Single Quoted Lines [1.3] + from: PRH3, modified for YAML 1.3 + tags: single spec scalar whitespace 1.3-mod + yaml: | + --- + ' 1st non-empty + + 2nd non-empty␣ + 3rd non-empty ' + tree: | + +STR + +DOC --- + =VAL ' 1st non-empty\n2nd non-empty 3rd non-empty␣ + -DOC + -STR + json: | + " 1st non-empty\n2nd non-empty 3rd non-empty " + dump: | + ' 1st non-empty + + 2nd non-empty 3rd non-empty ' + emit: | + --- ' 1st non-empty + + 2nd non-empty 3rd non-empty ' +)RAW"; + +static constexpr std::string_view T_T5N4 = R"RAW( +--- +- name: Spec Example 8.7. Literal Scalar [1.3] + from: M9B4, modified for YAML 1.3 + tags: spec literal scalar whitespace 1.3-mod + yaml: | + --- | + literal + ——»text + ↵ + ↵ + tree: | + +STR + +DOC --- + =VAL |literal\n\ttext\n + -DOC + -STR + json: | + "literal\n\ttext\n" + dump: | + "literal\n\ttext\n" + emit: | + --- | + literal + —»text +)RAW"; + +static constexpr std::string_view T_T833 = R"RAW( +--- +- name: Flow mapping missing a separating comma + from: '@perlpunk' + tags: error flow mapping + fail: true + yaml: | + --- + { + foo: 1 + bar: 2 } + tree: | + +STR + +DOC --- + +MAP + =VAL :foo +)RAW"; + +static constexpr std::string_view T_TD5N = R"RAW( +--- +- name: Invalid scalar after sequence + from: '@perlpunk' + tags: error sequence scalar + fail: true + yaml: | + - item1 + - item2 + invalid + tree: | + +STR + +DOC + +SEQ + =VAL :item1 + =VAL :item2 +)RAW"; + +static constexpr std::string_view T_TE2A = R"RAW( +--- +- name: Spec Example 8.16. Block Mappings + from: http://www.yaml.org/spec/1.2/spec.html#id2798147 + tags: spec mapping + yaml: | + block mapping: + key: value + tree: | + +STR + +DOC + +MAP + =VAL :block mapping + +MAP + =VAL :key + =VAL :value + -MAP + -MAP + -DOC + -STR + json: | + { + "block mapping": { + "key": "value" + } + } + dump: | + block mapping: + key: value +)RAW"; + +static constexpr std::string_view T_TL85 = R"RAW( +--- +- name: Spec Example 6.8. Flow Folding + from: http://www.yaml.org/spec/1.2/spec.html#id2779950 + tags: double spec whitespace scalar upto-1.2 + yaml: | + " + foo␣ + ␣ + —» bar + + baz + " + tree: | + +STR + +DOC + =VAL " foo\nbar\nbaz␣ + -DOC + -STR + json: | + " foo\nbar\nbaz " + dump: | + " foo\nbar\nbaz " +)RAW"; + +static constexpr std::string_view T_TS54 = R"RAW( +--- +- name: Folded Block Scalar + from: NimYAML tests + tags: folded scalar 1.3-err + yaml: | + > + ab + cd + ␣ + ef + + + gh + tree: | + +STR + +DOC + =VAL >ab cd\nef\n\ngh\n + -DOC + -STR + json: | + "ab cd\nef\n\ngh\n" + dump: | + > + ab cd + + ef + + + gh +)RAW"; + +static constexpr std::string_view T_U3C3 = R"RAW( +--- +- name: Spec Example 6.16. “TAG” directive + from: http://www.yaml.org/spec/1.2/spec.html#id2782252 + tags: spec header tag + yaml: | + %TAG !yaml! tag:yaml.org,2002: + --- + !yaml!str "foo" + tree: | + +STR + +DOC --- + =VAL "foo + -DOC + -STR + json: | + "foo" + dump: | + --- !!str "foo" +)RAW"; + +static constexpr std::string_view T_U3XV = R"RAW( +--- +- name: Node and Mapping Key Anchors + from: '@perlpunk' + tags: anchor comment 1.3-err + yaml: | + --- + top1: &node1 + &k1 key1: one + top2: &node2 # comment + key2: two + top3: + &k3 key3: three + top4: + &node4 + &k4 key4: four + top5: + &node5 + key5: five + top6: &val6 + six + top7: + &val7 seven + tree: | + +STR + +DOC --- + +MAP + =VAL :top1 + +MAP &node1 + =VAL &k1 :key1 + =VAL :one + -MAP + =VAL :top2 + +MAP &node2 + =VAL :key2 + =VAL :two + -MAP + =VAL :top3 + +MAP + =VAL &k3 :key3 + =VAL :three + -MAP + =VAL :top4 + +MAP &node4 + =VAL &k4 :key4 + =VAL :four + -MAP + =VAL :top5 + +MAP &node5 + =VAL :key5 + =VAL :five + -MAP + =VAL :top6 + =VAL &val6 :six + =VAL :top7 + =VAL &val7 :seven + -MAP + -DOC + -STR + json: | + { + "top1": { + "key1": "one" + }, + "top2": { + "key2": "two" + }, + "top3": { + "key3": "three" + }, + "top4": { + "key4": "four" + }, + "top5": { + "key5": "five" + }, + "top6": "six", + "top7": "seven" + } + dump: | + --- + top1: &node1 + &k1 key1: one + top2: &node2 + key2: two + top3: + &k3 key3: three + top4: &node4 + &k4 key4: four + top5: &node5 + key5: five + top6: &val6 six + top7: &val7 seven +)RAW"; + +static constexpr std::string_view T_U44R = R"RAW( +--- +- name: Bad indentation in mapping (2) + from: '@perlpunk' + tags: error mapping indent double + fail: true + yaml: | + map: + key1: "quoted1" + key2: "bad indentation" + tree: | + +STR + +DOC + +MAP + =VAL :map + +MAP + =VAL :key1 + =VAL "quoted1 +)RAW"; + +static constexpr std::string_view T_U99R = R"RAW( +--- +- name: Invalid comma in tag + from: '@perlpunk' + tags: error tag + fail: true + yaml: | + - !!str, xxx + tree: | + +STR + +DOC + +SEQ +)RAW"; + +static constexpr std::string_view T_U9NS = R"RAW( +--- +- name: Spec Example 2.8. Play by Play Feed from a Game + from: http://www.yaml.org/spec/1.2/spec.html#id2760519 + tags: spec header + yaml: | + --- + time: 20:03:20 + player: Sammy Sosa + action: strike (miss) + ... + --- + time: 20:03:47 + player: Sammy Sosa + action: grand slam + ... + tree: | + +STR + +DOC --- + +MAP + =VAL :time + =VAL :20:03:20 + =VAL :player + =VAL :Sammy Sosa + =VAL :action + =VAL :strike (miss) + -MAP + -DOC ... + +DOC --- + +MAP + =VAL :time + =VAL :20:03:47 + =VAL :player + =VAL :Sammy Sosa + =VAL :action + =VAL :grand slam + -MAP + -DOC ... + -STR + json: | + { + "time": "20:03:20", + "player": "Sammy Sosa", + "action": "strike (miss)" + } + { + "time": "20:03:47", + "player": "Sammy Sosa", + "action": "grand slam" + } +)RAW"; + +static constexpr std::string_view T_UDM2 = R"RAW( +--- +- name: Plain URL in flow mapping + from: https://github.com/yaml/libyaml/pull/28 + tags: flow scalar + yaml: | + - { url: http://example.org } + tree: | + +STR + +DOC + +SEQ + +MAP {} + =VAL :url + =VAL :http://example.org + -MAP + -SEQ + -DOC + -STR + json: | + [ + { + "url": "http://example.org" + } + ] + dump: | + - url: http://example.org +)RAW"; + +static constexpr std::string_view T_UDR7 = R"RAW( +--- +- name: Spec Example 5.4. Flow Collection Indicators + from: http://www.yaml.org/spec/1.2/spec.html#id2772813 + tags: spec flow sequence mapping + yaml: | + sequence: [ one, two, ] + mapping: { sky: blue, sea: green } + tree: | + +STR + +DOC + +MAP + =VAL :sequence + +SEQ [] + =VAL :one + =VAL :two + -SEQ + =VAL :mapping + +MAP {} + =VAL :sky + =VAL :blue + =VAL :sea + =VAL :green + -MAP + -MAP + -DOC + -STR + json: | + { + "sequence": [ + "one", + "two" + ], + "mapping": { + "sky": "blue", + "sea": "green" + } + } + dump: | + sequence: + - one + - two + mapping: + sky: blue + sea: green +)RAW"; + +static constexpr std::string_view T_UGM3 = R"RAW( +--- +- name: Spec Example 2.27. Invoice + from: http://www.yaml.org/spec/1.2/spec.html#id2761823 + tags: spec tag literal mapping sequence alias unknown-tag + yaml: | + --- ! + invoice: 34843 + date : 2001-01-23 + bill-to: &id001 + given : Chris + family : Dumars + address: + lines: | + 458 Walkman Dr. + Suite #292 + city : Royal Oak + state : MI + postal : 48046 + ship-to: *id001 + product: + - sku : BL394D + quantity : 4 + description : Basketball + price : 450.00 + - sku : BL4438H + quantity : 1 + description : Super Hoop + price : 2392.00 + tax : 251.42 + total: 4443.52 + comments: + Late afternoon is best. + Backup contact is Nancy + Billsmer @ 338-4338. + tree: | + +STR + +DOC --- + +MAP + =VAL :invoice + =VAL :34843 + =VAL :date + =VAL :2001-01-23 + =VAL :bill-to + +MAP &id001 + =VAL :given + =VAL :Chris + =VAL :family + =VAL :Dumars + =VAL :address + +MAP + =VAL :lines + =VAL |458 Walkman Dr.\nSuite #292\n + =VAL :city + =VAL :Royal Oak + =VAL :state + =VAL :MI + =VAL :postal + =VAL :48046 + -MAP + -MAP + =VAL :ship-to + =ALI *id001 + =VAL :product + +SEQ + +MAP + =VAL :sku + =VAL :BL394D + =VAL :quantity + =VAL :4 + =VAL :description + =VAL :Basketball + =VAL :price + =VAL :450.00 + -MAP + +MAP + =VAL :sku + =VAL :BL4438H + =VAL :quantity + =VAL :1 + =VAL :description + =VAL :Super Hoop + =VAL :price + =VAL :2392.00 + -MAP + -SEQ + =VAL :tax + =VAL :251.42 + =VAL :total + =VAL :4443.52 + =VAL :comments + =VAL :Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338. + -MAP + -DOC + -STR + json: | + { + "invoice": 34843, + "date": "2001-01-23", + "bill-to": { + "given": "Chris", + "family": "Dumars", + "address": { + "lines": "458 Walkman Dr.\nSuite #292\n", + "city": "Royal Oak", + "state": "MI", + "postal": 48046 + } + }, + "ship-to": { + "given": "Chris", + "family": "Dumars", + "address": { + "lines": "458 Walkman Dr.\nSuite #292\n", + "city": "Royal Oak", + "state": "MI", + "postal": 48046 + } + }, + "product": [ + { + "sku": "BL394D", + "quantity": 4, + "description": "Basketball", + "price": 450 + }, + { + "sku": "BL4438H", + "quantity": 1, + "description": "Super Hoop", + "price": 2392 + } + ], + "tax": 251.42, + "total": 4443.52, + "comments": "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338." + } + dump: | + --- ! + invoice: 34843 + date: 2001-01-23 + bill-to: &id001 + given: Chris + family: Dumars + address: + lines: | + 458 Walkman Dr. + Suite #292 + city: Royal Oak + state: MI + postal: 48046 + ship-to: *id001 + product: + - sku: BL394D + quantity: 4 + description: Basketball + price: 450.00 + - sku: BL4438H + quantity: 1 + description: Super Hoop + price: 2392.00 + tax: 251.42 + total: 4443.52 + comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338. +)RAW"; + +static constexpr std::string_view T_UKK6 = R"RAW( +--- +- name: Syntax character edge cases + from: '@ingydotnet' + tags: edge empty-key + yaml: | + - : + tree: | + +STR + +DOC + +SEQ + +MAP + =VAL : + =VAL : + -MAP + -SEQ + -DOC + -STR + +- yaml: | + :: + tree: | + +STR + +DOC + +MAP + =VAL :: + =VAL : + -MAP + -DOC + -STR + json: | + { + ":": null + } + +- yaml: | + ! + tree: | + +STR + +DOC + =VAL : + -DOC + -STR + json: null +)RAW"; + +static constexpr std::string_view T_UT92 = R"RAW( +--- +- name: Spec Example 9.4. Explicit Documents + from: http://www.yaml.org/spec/1.2/spec.html#id2801448 + tags: flow spec header footer comment + yaml: | + --- + { matches + % : 20 } + ... + --- + # Empty + ... + tree: | + +STR + +DOC --- + +MAP {} + =VAL :matches % + =VAL :20 + -MAP + -DOC ... + +DOC --- + =VAL : + -DOC ... + -STR + json: | + { + "matches %": 20 + } + null + dump: | + --- + matches %: 20 + ... + --- + ... +)RAW"; + +static constexpr std::string_view T_UV7Q = R"RAW( +--- +- name: Legal tab after indentation + from: '@ingydotnet' + tags: indent whitespace + yaml: | + x: + - x + ——»x + tree: | + +STR + +DOC + +MAP + =VAL :x + +SEQ + =VAL :x x + -SEQ + -MAP + -DOC + -STR + json: | + { + "x": [ + "x x" + ] + } + dump: | + x: + - x x +)RAW"; + +static constexpr std::string_view T_V55R = R"RAW( +--- +- name: Aliases in Block Sequence + from: NimYAML tests + tags: alias sequence + yaml: | + - &a a + - &b b + - *a + - *b + tree: | + +STR + +DOC + +SEQ + =VAL &a :a + =VAL &b :b + =ALI *a + =ALI *b + -SEQ + -DOC + -STR + json: | + [ + "a", + "b", + "a", + "b" + ] +)RAW"; + +static constexpr std::string_view T_V9D5 = R"RAW( +--- +- name: Spec Example 8.19. Compact Block Mappings + from: http://www.yaml.org/spec/1.2/spec.html#id2799091 + tags: complex-key explicit-key spec mapping + yaml: | + - sun: yellow + - ? earth: blue + : moon: white + tree: | + +STR + +DOC + +SEQ + +MAP + =VAL :sun + =VAL :yellow + -MAP + +MAP + +MAP + =VAL :earth + =VAL :blue + -MAP + +MAP + =VAL :moon + =VAL :white + -MAP + -MAP + -SEQ + -DOC + -STR +)RAW"; + +static constexpr std::string_view T_VJP3 = R"RAW( +--- +- name: Flow collections over many lines + from: '@ingydotnet' + tags: flow indent + fail: true + yaml: | + k: { + k + : + v + } + tree: | + +STR + +DOC + +MAP + =VAL :k + +MAP {} + +- yaml: | + k: { + k + : + v + } + tree: | + +STR + +DOC + +MAP + =VAL :k + +MAP {} + =VAL :k + =VAL :v + -MAP + -MAP + -DOC + -STR + json: | + { + "k" : { + "k" : "v" + } + } + dump: | + --- + k: + k: v + emit: | + k: + k: v +)RAW"; + +static constexpr std::string_view T_W42U = R"RAW( +--- +- name: Spec Example 8.15. Block Sequence Entry Types + from: http://www.yaml.org/spec/1.2/spec.html#id2797944 + tags: comment spec literal sequence + yaml: | + - # Empty + - | + block node + - - one # Compact + - two # sequence + - one: two # Compact mapping + tree: | + +STR + +DOC + +SEQ + =VAL : + =VAL |block node\n + +SEQ + =VAL :one + =VAL :two + -SEQ + +MAP + =VAL :one + =VAL :two + -MAP + -SEQ + -DOC + -STR + json: | + [ + null, + "block node\n", + [ + "one", + "two" + ], + { + "one": "two" + } + ] + dump: | + - + - | + block node + - - one + - two + - one: two +)RAW"; + +static constexpr std::string_view T_W4TN = R"RAW( +--- +- name: Spec Example 9.5. Directives Documents + from: http://www.yaml.org/spec/1.2/spec.html#id2801606 + tags: spec header footer 1.3-err + yaml: | + %YAML 1.2 + --- | + %!PS-Adobe-2.0 + ... + %YAML 1.2 + --- + # Empty + ... + tree: | + +STR + +DOC --- + =VAL |%!PS-Adobe-2.0\n + -DOC ... + +DOC --- + =VAL : + -DOC ... + -STR + json: | + "%!PS-Adobe-2.0\n" + null + dump: | + --- | + %!PS-Adobe-2.0 + ... + --- + ... +)RAW"; + +static constexpr std::string_view T_W5VH = R"RAW( +--- +- name: Allowed characters in alias + from: '@perlpunk' + tags: alias 1.3-err + yaml: | + a: &:@*!$": scalar a + b: *:@*!$": + tree: | + +STR + +DOC + +MAP + =VAL :a + =VAL &:@*!$": :scalar a + =VAL :b + =ALI *:@*!$": + -MAP + -DOC + -STR + json: | + { + "a": "scalar a", + "b": "scalar a" + } +)RAW"; + +static constexpr std::string_view T_W9L4 = R"RAW( +--- +- name: Literal block scalar with more spaces in first line + from: '@perlpunk' + tags: error literal whitespace + fail: true + yaml: | + --- + block scalar: | + ␣␣␣␣␣ + more spaces at the beginning + are invalid + tree: | + +STR + +DOC --- + +MAP + =VAL :block scalar +)RAW"; + +static constexpr std::string_view T_WZ62 = R"RAW( +--- +- name: Spec Example 7.2. Empty Content + from: http://www.yaml.org/spec/1.2/spec.html#id2786720 + tags: spec flow scalar tag + yaml: | + { + foo : !!str, + !!str : bar, + } + tree: | + +STR + +DOC + +MAP {} + =VAL :foo + =VAL : + =VAL : + =VAL :bar + -MAP + -DOC + -STR + json: | + { + "foo": "", + "": "bar" + } + dump: | + foo: !!str + !!str : bar +)RAW"; + +static constexpr std::string_view T_X38W = R"RAW( +--- +- name: Aliases in Flow Objects + from: NimYAML tests + tags: alias complex-key flow + yaml: | + { &a [a, &b b]: *b, *a : [c, *b, d]} + tree: | + +STR + +DOC + +MAP {} + +SEQ [] &a + =VAL :a + =VAL &b :b + -SEQ + =ALI *b + =ALI *a + +SEQ [] + =VAL :c + =ALI *b + =VAL :d + -SEQ + -MAP + -DOC + -STR + dump: | + ? &a + - a + - &b b + : *b + *a : + - c + - *b + - d +)RAW"; + +static constexpr std::string_view T_X4QW = R"RAW( +--- +- name: Comment without whitespace after block scalar indicator + from: '@perlpunk' + tags: folded comment error whitespace + fail: true + yaml: | + block: ># comment + scalar + tree: | + +STR + +DOC + +MAP + =VAL :block +)RAW"; + +static constexpr std::string_view T_X8DW = R"RAW( +--- +- name: Explicit key and value seperated by comment + from: '@perlpunk' + tags: comment explicit-key mapping + yaml: | + --- + ? key + # comment + : value + tree: | + +STR + +DOC --- + +MAP + =VAL :key + =VAL :value + -MAP + -DOC + -STR + json: | + { + "key": "value" + } + dump: | + --- + key: value +)RAW"; + +static constexpr std::string_view T_XLQ9 = R"RAW( +--- +- name: Multiline scalar that looks like a YAML directive + from: '@perlpunk' + tags: directive scalar + yaml: | + --- + scalar + %YAML 1.2 + tree: | + +STR + +DOC --- + =VAL :scalar %YAML 1.2 + -DOC + -STR + json: | + "scalar %YAML 1.2" + dump: | + --- scalar %YAML 1.2 + ... +)RAW"; + +static constexpr std::string_view T_XV9V = R"RAW( +--- +- name: Spec Example 6.5. Empty Lines [1.3] + from: 5GBF, modified for YAML 1.3 + tags: literal spec scalar 1.3-mod + yaml: | + Folding: + "Empty line + + as a line feed" + Chomping: | + Clipped empty lines + ␣ + ↵ + tree: | + +STR + +DOC + +MAP + =VAL :Folding + =VAL "Empty line\nas a line feed + =VAL :Chomping + =VAL |Clipped empty lines\n + -MAP + -DOC + -STR + json: | + { + "Folding": "Empty line\nas a line feed", + "Chomping": "Clipped empty lines\n" + } + dump: | + Folding: "Empty line\nas a line feed" + Chomping: | + Clipped empty lines +)RAW"; + +static constexpr std::string_view T_XW4D = R"RAW( +--- +- name: Various Trailing Comments + from: '@perlpunk' + tags: comment explicit-key folded 1.3-err + yaml: | + a: "double + quotes" # lala + b: plain + value # lala + c : #lala + d + ? # lala + - seq1 + : # lala + - #lala + seq2 + e: + &node # lala + - x: y + block: > # lala + abcde + tree: | + +STR + +DOC + +MAP + =VAL :a + =VAL "double quotes + =VAL :b + =VAL :plain value + =VAL :c + =VAL :d + +SEQ + =VAL :seq1 + -SEQ + +SEQ + =VAL :seq2 + -SEQ + =VAL :e + +SEQ &node + +MAP + =VAL :x + =VAL :y + -MAP + -SEQ + =VAL :block + =VAL >abcde\n + -MAP + -DOC + -STR + dump: | + a: "double quotes" + b: plain value + c: d + ? - seq1 + : - seq2 + e: &node + - x: y + block: > + abcde +)RAW"; + +static constexpr std::string_view T_Y2GN = R"RAW( +--- +- name: Anchor with colon in the middle + from: '@perlpunk' + tags: anchor + yaml: | + --- + key: &an:chor value + tree: | + +STR + +DOC --- + +MAP + =VAL :key + =VAL &an:chor :value + -MAP + -DOC + -STR + json: | + { + "key": "value" + } + dump: | + --- + key: &an:chor value +)RAW"; + +static constexpr std::string_view T_Y79Y = R"RAW( +--- +- name: Tabs in various contexts + from: '@ingydotnet' + tags: whitespace + fail: true + yaml: | + foo: | + ————» + bar: 1 + tree: | + +STR + +DOC + +MAP + =VAL :foo + +- yaml: | + foo: | + ———» + bar: 1 + tree: | + +STR + +DOC + +MAP + =VAL :foo + =VAL |\t\n + =VAL :bar + =VAL :1 + -MAP + -DOC + -STR + json: | + { + "foo": "\t\n", + "bar": 1 + } + dump: | + foo: | + ———» + bar: 1 + +- yaml: | + - [ + ————» + foo + ] + tree: | + +STR + +DOC + +SEQ + +SEQ [] + =VAL :foo + -SEQ + -SEQ + -DOC + -STR + json: | + [ + [ + "foo" + ] + ] + dump: | + - - foo + +- fail: true + yaml: | + - [ + ————»foo, + foo + ] + tree: | + +STR + +DOC + +SEQ + +SEQ [] + json: null + +- fail: true + yaml: | + -———»- + +- fail: true + yaml: | + - ——»- + +- fail: true + yaml: | + ?———»- + +- fail: true + yaml: | + ? - + :———»- + +- fail: true + yaml: | + ?———»key: + +- fail: true + yaml: | + ? key: + :———»key: + +- yaml: | + -———»-1 + tree: | + +STR + +DOC + +SEQ + =VAL :-1 + -SEQ + -DOC + -STR + json: | + [ + -1 + ] + dump: | + - -1 +)RAW"; + +static constexpr std::string_view T_YD5X = R"RAW( +--- +- name: Spec Example 2.5. Sequence of Sequences + from: http://www.yaml.org/spec/1.2/spec.html#id2760351 + tags: spec sequence + yaml: | + - [name , hr, avg ] + - [Mark McGwire, 65, 0.278] + - [Sammy Sosa , 63, 0.288] + tree: | + +STR + +DOC + +SEQ + +SEQ [] + =VAL :name + =VAL :hr + =VAL :avg + -SEQ + +SEQ [] + =VAL :Mark McGwire + =VAL :65 + =VAL :0.278 + -SEQ + +SEQ [] + =VAL :Sammy Sosa + =VAL :63 + =VAL :0.288 + -SEQ + -SEQ + -DOC + -STR + json: | + [ + [ + "name", + "hr", + "avg" + ], + [ + "Mark McGwire", + 65, + 0.278 + ], + [ + "Sammy Sosa", + 63, + 0.288 + ] + ] + dump: | + - - name + - hr + - avg + - - Mark McGwire + - 65 + - 0.278 + - - Sammy Sosa + - 63 + - 0.288 +)RAW"; + +static constexpr std::string_view T_YJV2 = R"RAW( +--- +- name: Dash in flow sequence + from: '@ingydotnet' + tags: flow sequence + fail: true + yaml: | + [-] + tree: | + +STR + +DOC + +SEQ [] +)RAW"; + +static constexpr std::string_view T_Z67P = R"RAW( +--- +- name: Spec Example 8.21. Block Scalar Nodes [1.3] + from: M5C3, modified for YAML 1.3 + tags: indent spec literal folded tag local-tag 1.3-mod + yaml: | + literal: |2 + value + folded: !foo >1 + value + tree: | + +STR + +DOC + +MAP + =VAL :literal + =VAL |value\n + =VAL :folded + =VAL >value\n + -MAP + -DOC + -STR + json: | + { + "literal": "value\n", + "folded": "value\n" + } + dump: | + literal: | + value + folded: !foo > + value +)RAW"; + +static constexpr std::string_view T_Z9M4 = R"RAW( +--- +- name: Spec Example 6.22. Global Tag Prefix + from: http://www.yaml.org/spec/1.2/spec.html#id2783726 + tags: spec header tag unknown-tag + yaml: | + %TAG !e! tag:example.com,2000:app/ + --- + - !e!foo "bar" + tree: | + +STR + +DOC --- + +SEQ + =VAL "bar + -SEQ + -DOC + -STR + json: | + [ + "bar" + ] + dump: | + --- + - ! "bar" +)RAW"; + +static constexpr std::string_view T_ZCZ6 = R"RAW( +--- +- name: Invalid mapping in plain single line value + from: https://gist.github.com/anonymous/0c8db51d151baf8113205ba3ce71d1b4 via @ingydotnet + tags: error mapping scalar + fail: true + yaml: | + a: b: c: d + tree: | + +STR + +DOC + +MAP + =VAL :a +)RAW"; + +static constexpr std::string_view T_ZF4X = R"RAW( +--- +- name: Spec Example 2.6. Mapping of Mappings + from: http://www.yaml.org/spec/1.2/spec.html#id2760372 + tags: flow spec mapping + yaml: | + Mark McGwire: {hr: 65, avg: 0.278} + Sammy Sosa: { + hr: 63, + avg: 0.288 + } + tree: | + +STR + +DOC + +MAP + =VAL :Mark McGwire + +MAP {} + =VAL :hr + =VAL :65 + =VAL :avg + =VAL :0.278 + -MAP + =VAL :Sammy Sosa + +MAP {} + =VAL :hr + =VAL :63 + =VAL :avg + =VAL :0.288 + -MAP + -MAP + -DOC + -STR + json: | + { + "Mark McGwire": { + "hr": 65, + "avg": 0.278 + }, + "Sammy Sosa": { + "hr": 63, + "avg": 0.288 + } + } + dump: | + Mark McGwire: + hr: 65 + avg: 0.278 + Sammy Sosa: + hr: 63 + avg: 0.288 +)RAW"; + +static constexpr std::string_view T_ZH7C = R"RAW( +--- +- name: Anchors in Mapping + from: NimYAML tests + tags: anchor mapping + yaml: | + &a a: b + c: &d d + tree: | + +STR + +DOC + +MAP + =VAL &a :a + =VAL :b + =VAL :c + =VAL &d :d + -MAP + -DOC + -STR + json: | + { + "a": "b", + "c": "d" + } +)RAW"; + +static constexpr std::string_view T_ZK9H = R"RAW( +--- +- name: Nested top level flow mapping + from: '@perlpunk' + tags: flow indent mapping sequence + yaml: | + { key: [[[ + value + ]]] + } + tree: | + +STR + +DOC + +MAP {} + =VAL :key + +SEQ [] + +SEQ [] + +SEQ [] + =VAL :value + -SEQ + -SEQ + -SEQ + -MAP + -DOC + -STR + json: | + { + "key": [ + [ + [ + "value" + ] + ] + ] + } + dump: | + key: + - - - value +)RAW"; + +static constexpr std::string_view T_ZL4Z = R"RAW( +--- +- name: Invalid nested mapping + from: '@perlpunk' + tags: error mapping + fail: true + yaml: | + --- + a: 'b': c + tree: | + +STR + +DOC --- + +MAP + =VAL :a + =VAL 'b +)RAW"; + +static constexpr std::string_view T_ZVH3 = R"RAW( +--- +- name: Wrong indented sequence item + from: '@perlpunk' + tags: error sequence indent + fail: true + yaml: | + - key: value + - item1 + tree: | + +STR + +DOC + +SEQ + +MAP + =VAL :key + =VAL :value + -MAP +)RAW"; + +static constexpr std::string_view T_ZWK4 = R"RAW( +--- +- name: Key with anchor after missing explicit mapping value + from: '@perlpunk' + tags: anchor explicit-key mapping + yaml: | + --- + a: 1 + ? b + &anchor c: 3 + tree: | + +STR + +DOC --- + +MAP + =VAL :a + =VAL :1 + =VAL :b + =VAL : + =VAL &anchor :c + =VAL :3 + -MAP + -DOC + -STR + json: | + { + "a": 1, + "b": null, + "c": 3 + } + dump: | + --- + a: 1 + b: + &anchor c: 3 +)RAW"; + +static constexpr std::string_view T_ZXT5 = R"RAW( +--- +- name: Implicit key followed by newline and adjacent value + from: '@perlpunk' + tags: error flow mapping sequence + fail: true + yaml: | + [ "key" + :value ] + tree: | + +STR + +DOC + +SEQ [] + =VAL "key +)RAW"; + +static constexpr std::string_view T_ZYU8 = R"RAW( +--- +- skip: true + note: The following cases are valid YAML according to the 1.2 productions but + not at all usefully valid. We don't want to encourage parsers to support + them when we'll likely make them invalid later. + also: MU58 + name: Directive variants + from: '@ingydotnet' + tags: directive + yaml: | + %YAML1.1 + --- + tree: | + +STR + +DOC --- + =VAL : + -DOC + -STR + json: | + null + +- yaml: | + %*** + --- + +- yaml: | + %YAML 1.1 1.2 + --- + +- yaml: | + %YAML 1.12345 + --- +)RAW"; + +namespace { +using namespace nix; + +TEST_F(FromYAMLTest, T_229Q) +{ + execYAMLTest(T_229Q); +} + +TEST_F(FromYAMLTest, T_236B) +{ + execYAMLTest(T_236B); +} + +TEST_F(FromYAMLTest, T_26DV) +{ + execYAMLTest(T_26DV); +} + +TEST_F(FromYAMLTest, T_27NA) +{ + execYAMLTest(T_27NA); +} + +TEST_F(FromYAMLTest, T_2AUY) +{ + execYAMLTest(T_2AUY); +} + +TEST_F(FromYAMLTest, T_2CMS) +{ + execYAMLTest(T_2CMS); +} + +TEST_F(FromYAMLTest, T_2EBW) +{ + execYAMLTest(T_2EBW); +} + +TEST_F(FromYAMLTest, T_2G84) +{ + execYAMLTest(T_2G84); +} + +TEST_F(FromYAMLTest, T_2JQS) +{ + execYAMLTest(T_2JQS); +} + +TEST_F(FromYAMLTest, T_2LFX) +{ + execYAMLTest(T_2LFX); +} + +TEST_F(FromYAMLTest, T_2SXE) +{ + execYAMLTest(T_2SXE); +} + +TEST_F(FromYAMLTest, T_2XXW) +{ + EXPECT_THROW(execYAMLTest(T_2XXW), EvalError) << "usage of optional tag like !!set and !!omap (not implemented)"; +} + +TEST_F(FromYAMLTest, T_33X3) +{ + execYAMLTest(T_33X3); +} + +TEST_F(FromYAMLTest, T_35KP) +{ + execYAMLTest(T_35KP); +} + +TEST_F(FromYAMLTest, T_36F6) +{ + execYAMLTest(T_36F6); +} + +TEST_F(FromYAMLTest, T_3ALJ) +{ + execYAMLTest(T_3ALJ); +} + +TEST_F(FromYAMLTest, T_3GZX) +{ + execYAMLTest(T_3GZX); +} + +TEST_F(FromYAMLTest, T_3HFZ) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_3HFZ); +} + +TEST_F(FromYAMLTest, T_3MYT) +{ + execYAMLTest(T_3MYT); +} + +TEST_F(FromYAMLTest, T_3R3P) +{ + execYAMLTest(T_3R3P); +} + +TEST_F(FromYAMLTest, T_3RLN) +{ + execYAMLTest(T_3RLN); +} + +TEST_F(FromYAMLTest, T_3UYS) +{ + execYAMLTest(T_3UYS); +} + +TEST_F(FromYAMLTest, T_4ABK) +{ + execYAMLTest(T_4ABK); +} + +TEST_F(FromYAMLTest, T_4CQQ) +{ + execYAMLTest(T_4CQQ); +} + +TEST_F(FromYAMLTest, T_4EJS) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_4EJS); +} + +TEST_F(FromYAMLTest, T_4FJ6) +{ + execYAMLTest(T_4FJ6); +} + +TEST_F(FromYAMLTest, T_4GC6) +{ + execYAMLTest(T_4GC6); +} + +TEST_F(FromYAMLTest, T_4H7K) +{ + execYAMLTest(T_4H7K); +} + +TEST_F(FromYAMLTest, T_4HVU) +{ + execYAMLTest(T_4HVU); +} + +TEST_F(FromYAMLTest, T_4JVG) +{ + execYAMLTest(T_4JVG); +} + +TEST_F(FromYAMLTest, T_4MUZ) +{ + execYAMLTest(T_4MUZ); +} + +TEST_F(FromYAMLTest, T_4Q9F) +{ + execYAMLTest(T_4Q9F); +} + +TEST_F(FromYAMLTest, T_4QFQ) +{ + execYAMLTest(T_4QFQ); +} + +TEST_F(FromYAMLTest, T_4RWC) +{ + execYAMLTest(T_4RWC); +} + +TEST_F(FromYAMLTest, T_4UYU) +{ + execYAMLTest(T_4UYU); +} + +TEST_F(FromYAMLTest, T_4V8U) +{ + execYAMLTest(T_4V8U); +} + +TEST_F(FromYAMLTest, T_4WA9) +{ + execYAMLTest(T_4WA9); +} + +TEST_F(FromYAMLTest, T_4ZYM) +{ + execYAMLTest(T_4ZYM); +} + +TEST_F(FromYAMLTest, T_52DL) +{ + execYAMLTest(T_52DL); +} + +TEST_F(FromYAMLTest, T_54T7) +{ + execYAMLTest(T_54T7); +} + +TEST_F(FromYAMLTest, T_55WF) +{ + execYAMLTest(T_55WF); +} + +TEST_F(FromYAMLTest, T_565N) +{ + EXPECT_THROW(execYAMLTest(T_565N), EvalError) << "nix has no binary data type"; +} + +TEST_F(FromYAMLTest, T_57H4) +{ + execYAMLTest(T_57H4); +} + +TEST_F(FromYAMLTest, T_58MP) +{ + execYAMLTest(T_58MP); +} + +TEST_F(FromYAMLTest, T_5BVJ) +{ + execYAMLTest(T_5BVJ); +} + +TEST_F(FromYAMLTest, T_5C5M) +{ + execYAMLTest(T_5C5M); +} + +TEST_F(FromYAMLTest, T_5GBF) +{ + execYAMLTest(T_5GBF); +} + +TEST_F(FromYAMLTest, T_5KJE) +{ + execYAMLTest(T_5KJE); +} + +TEST_F(FromYAMLTest, T_5LLU) +{ + execYAMLTest(T_5LLU); +} + +TEST_F(FromYAMLTest, T_5MUD) +{ + execYAMLTest(T_5MUD); +} + +TEST_F(FromYAMLTest, T_5NYZ) +{ + execYAMLTest(T_5NYZ); +} + +TEST_F(FromYAMLTest, T_5T43) +{ + execYAMLTest(T_5T43); +} + +TEST_F(FromYAMLTest, T_5TRB) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_5TRB); +} + +TEST_F(FromYAMLTest, T_5TYM) +{ + EXPECT_THROW(execYAMLTest(T_5TYM), EvalError) << "usage of unknown tags"; +} + +TEST_F(FromYAMLTest, T_5U3A) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_5U3A); +} + +TEST_F(FromYAMLTest, T_5WE3) +{ + execYAMLTest(T_5WE3); +} + +TEST_F(FromYAMLTest, T_62EZ) +{ + execYAMLTest(T_62EZ); +} + +TEST_F(FromYAMLTest, T_652Z) +{ + execYAMLTest(T_652Z); +} + +TEST_F(FromYAMLTest, T_65WH) +{ + execYAMLTest(T_65WH); +} + +TEST_F(FromYAMLTest, T_6BCT) +{ + execYAMLTest(T_6BCT); +} + +TEST_F(FromYAMLTest, T_6BFJ) +{ + execYAMLTest(T_6BFJ); +} + +TEST_F(FromYAMLTest, T_6CA3) +{ + execYAMLTest(T_6CA3); +} + +TEST_F(FromYAMLTest, T_6CK3) +{ + EXPECT_THROW(execYAMLTest(T_6CK3), EvalError) << "usage of unknown tags"; +} + +TEST_F(FromYAMLTest, T_6FWR) +{ + execYAMLTest(T_6FWR); +} + +TEST_F(FromYAMLTest, T_6H3V) +{ + execYAMLTest(T_6H3V); +} + +TEST_F(FromYAMLTest, T_6HB6) +{ + execYAMLTest(T_6HB6); +} + +TEST_F(FromYAMLTest, T_6JQW) +{ + execYAMLTest(T_6JQW); +} + +TEST_F(FromYAMLTest, T_6JTT) +{ + execYAMLTest(T_6JTT); +} + +TEST_F(FromYAMLTest, T_6JWB) +{ + execYAMLTest(T_6JWB); +} + +TEST_F(FromYAMLTest, T_6KGN) +{ + execYAMLTest(T_6KGN); +} + +TEST_F(FromYAMLTest, T_6LVF) +{ + execYAMLTest(T_6LVF); +} + +TEST_F(FromYAMLTest, T_6M2F) +{ + execYAMLTest(T_6M2F); +} + +TEST_F(FromYAMLTest, T_6PBE) +{ + execYAMLTest(T_6PBE); +} + +TEST_F(FromYAMLTest, T_6S55) +{ + execYAMLTest(T_6S55); +} + +TEST_F(FromYAMLTest, T_6SLA) +{ + execYAMLTest(T_6SLA); +} + +TEST_F(FromYAMLTest, T_6VJK) +{ + execYAMLTest(T_6VJK); +} + +TEST_F(FromYAMLTest, T_6WLZ) +{ + EXPECT_THROW(execYAMLTest(T_6WLZ), EvalError) << "usage of unknown tags"; +} + +TEST_F(FromYAMLTest, T_6WPF) +{ + execYAMLTest(T_6WPF); +} + +TEST_F(FromYAMLTest, T_6XDY) +{ + execYAMLTest(T_6XDY); +} + +TEST_F(FromYAMLTest, T_6ZKB) +{ + execYAMLTest(T_6ZKB); +} + +TEST_F(FromYAMLTest, T_735Y) +{ + execYAMLTest(T_735Y); +} + +TEST_F(FromYAMLTest, T_74H7) +{ + execYAMLTest(T_74H7); +} + +TEST_F(FromYAMLTest, T_753E) +{ + execYAMLTest(T_753E); +} + +TEST_F(FromYAMLTest, T_7A4E) +{ + execYAMLTest(T_7A4E); +} + +TEST_F(FromYAMLTest, T_7BMT) +{ + execYAMLTest(T_7BMT); +} + +TEST_F(FromYAMLTest, T_7BUB) +{ + execYAMLTest(T_7BUB); +} + +TEST_F(FromYAMLTest, T_7FWL) +{ + EXPECT_THROW(execYAMLTest(T_7FWL), EvalError) << "usage of unknown tags"; +} + +TEST_F(FromYAMLTest, T_7LBH) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_7LBH); +} + +TEST_F(FromYAMLTest, T_7MNF) +{ + execYAMLTest(T_7MNF); +} + +TEST_F(FromYAMLTest, T_7T8X) +{ + execYAMLTest(T_7T8X); +} + +TEST_F(FromYAMLTest, T_7TMG) +{ + execYAMLTest(T_7TMG); +} + +TEST_F(FromYAMLTest, T_7W2P) +{ + execYAMLTest(T_7W2P); +} + +TEST_F(FromYAMLTest, T_7Z25) +{ + execYAMLTest(T_7Z25); +} + +TEST_F(FromYAMLTest, T_7ZZ5) +{ + execYAMLTest(T_7ZZ5); +} + +TEST_F(FromYAMLTest, T_82AN) +{ + execYAMLTest(T_82AN); +} + +TEST_F(FromYAMLTest, T_87E4) +{ + execYAMLTest(T_87E4); +} + +TEST_F(FromYAMLTest, T_8CWC) +{ + execYAMLTest(T_8CWC); +} + +TEST_F(FromYAMLTest, T_8G76) +{ + execYAMLTest(T_8G76); +} + +TEST_F(FromYAMLTest, T_8KB6) +{ + execYAMLTest(T_8KB6); +} + +TEST_F(FromYAMLTest, T_8MK2) +{ + execYAMLTest(T_8MK2); +} + +TEST_F(FromYAMLTest, T_8QBE) +{ + execYAMLTest(T_8QBE); +} + +TEST_F(FromYAMLTest, T_8UDB) +{ + execYAMLTest(T_8UDB); +} + +TEST_F(FromYAMLTest, T_8XDJ) +{ + execYAMLTest(T_8XDJ); +} + +TEST_F(FromYAMLTest, T_8XYN) +{ + execYAMLTest(T_8XYN); +} + +TEST_F(FromYAMLTest, T_93JH) +{ + execYAMLTest(T_93JH); +} + +TEST_F(FromYAMLTest, T_93WF) +{ + execYAMLTest(T_93WF); +} + +TEST_F(FromYAMLTest, T_96L6) +{ + execYAMLTest(T_96L6); +} + +TEST_F(FromYAMLTest, T_96NN) +{ + execYAMLTest(T_96NN); +} + +TEST_F(FromYAMLTest, T_98YD) +{ + execYAMLTest(T_98YD); +} + +TEST_F(FromYAMLTest, T_9BXH) +{ + execYAMLTest(T_9BXH); +} + +TEST_F(FromYAMLTest, T_9C9N) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_9C9N); +} + +TEST_F(FromYAMLTest, T_9CWY) +{ + execYAMLTest(T_9CWY); +} + +TEST_F(FromYAMLTest, T_9DXL) +{ + execYAMLTest(T_9DXL); +} + +TEST_F(FromYAMLTest, T_9FMG) +{ + execYAMLTest(T_9FMG); +} + +TEST_F(FromYAMLTest, T_9HCY) +{ + execYAMLTest(T_9HCY); +} + +TEST_F(FromYAMLTest, T_9J7A) +{ + execYAMLTest(T_9J7A); +} + +TEST_F(FromYAMLTest, T_9JBA) +{ + execYAMLTest(T_9JBA); +} + +TEST_F(FromYAMLTest, T_9KAX) +{ + execYAMLTest(T_9KAX); +} + +TEST_F(FromYAMLTest, T_9KBC) +{ + execYAMLTest(T_9KBC); +} + +TEST_F(FromYAMLTest, T_9MAG) +{ + execYAMLTest(T_9MAG); +} + +TEST_F(FromYAMLTest, T_9MMA) +{ + execYAMLTest(T_9MMA); +} + +TEST_F(FromYAMLTest, T_9MMW) +{ + execYAMLTest(T_9MMW); +} + +TEST_F(FromYAMLTest, T_9MQT) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_9MQT); +} + +TEST_F(FromYAMLTest, T_9SA2) +{ + execYAMLTest(T_9SA2); +} + +TEST_F(FromYAMLTest, T_9SHH) +{ + execYAMLTest(T_9SHH); +} + +TEST_F(FromYAMLTest, T_9TFX) +{ + execYAMLTest(T_9TFX); +} + +TEST_F(FromYAMLTest, T_9U5K) +{ + execYAMLTest(T_9U5K); +} + +TEST_F(FromYAMLTest, T_9WXW) +{ + EXPECT_THROW(execYAMLTest(T_9WXW), EvalError) << "usage of unknown tags"; +} + +TEST_F(FromYAMLTest, T_9YRD) +{ + execYAMLTest(T_9YRD); +} + +TEST_F(FromYAMLTest, T_A2M4) +{ + execYAMLTest(T_A2M4); +} + +TEST_F(FromYAMLTest, T_A6F9) +{ + execYAMLTest(T_A6F9); +} + +TEST_F(FromYAMLTest, T_A984) +{ + execYAMLTest(T_A984); +} + +TEST_F(FromYAMLTest, T_AB8U) +{ + execYAMLTest(T_AB8U); +} + +TEST_F(FromYAMLTest, T_AVM7) +{ + execYAMLTest(T_AVM7); +} + +TEST_F(FromYAMLTest, T_AZ63) +{ + execYAMLTest(T_AZ63); +} + +TEST_F(FromYAMLTest, T_AZW3) +{ + execYAMLTest(T_AZW3); +} + +TEST_F(FromYAMLTest, T_B3HG) +{ + execYAMLTest(T_B3HG); +} + +TEST_F(FromYAMLTest, T_B63P) +{ + execYAMLTest(T_B63P); +} + +TEST_F(FromYAMLTest, T_BD7L) +{ + execYAMLTest(T_BD7L); +} + +TEST_F(FromYAMLTest, T_BEC7) +{ + execYAMLTest(T_BEC7); +} + +TEST_F(FromYAMLTest, T_BF9H) +{ + execYAMLTest(T_BF9H); +} + +TEST_F(FromYAMLTest, T_BS4K) +{ + execYAMLTest(T_BS4K); +} + +TEST_F(FromYAMLTest, T_BU8L) +{ + execYAMLTest(T_BU8L); +} + +TEST_F(FromYAMLTest, T_C2DT) +{ + execYAMLTest(T_C2DT); +} + +TEST_F(FromYAMLTest, T_C2SP) +{ + execYAMLTest(T_C2SP); +} + +TEST_F(FromYAMLTest, T_C4HZ) +{ + EXPECT_THROW(execYAMLTest(T_C4HZ), EvalError) << "usage of unknown tags"; +} + +TEST_F(FromYAMLTest, T_CC74) +{ + EXPECT_THROW(execYAMLTest(T_CC74), EvalError) << "usage of unknown tags"; +} + +TEST_F(FromYAMLTest, T_CFD4) +{ + execYAMLTest(T_CFD4); +} + +TEST_F(FromYAMLTest, T_CML9) +{ + execYAMLTest(T_CML9); +} + +TEST_F(FromYAMLTest, T_CN3R) +{ + execYAMLTest(T_CN3R); +} + +TEST_F(FromYAMLTest, T_CPZ3) +{ + execYAMLTest(T_CPZ3); +} + +TEST_F(FromYAMLTest, T_CQ3W) +{ + execYAMLTest(T_CQ3W); +} + +TEST_F(FromYAMLTest, T_CT4Q) +{ + execYAMLTest(T_CT4Q); +} + +TEST_F(FromYAMLTest, T_CTN5) +{ + execYAMLTest(T_CTN5); +} + +TEST_F(FromYAMLTest, T_CUP7) +{ + EXPECT_THROW(execYAMLTest(T_CUP7), EvalError) << "usage of unknown tags"; +} + +TEST_F(FromYAMLTest, T_CVW2) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_CVW2); +} + +TEST_F(FromYAMLTest, T_CXX2) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_CXX2); +} + +TEST_F(FromYAMLTest, T_D49Q) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_D49Q); +} + +TEST_F(FromYAMLTest, T_D83L) +{ + execYAMLTest(T_D83L); +} + +TEST_F(FromYAMLTest, T_D88J) +{ + execYAMLTest(T_D88J); +} + +TEST_F(FromYAMLTest, T_D9TU) +{ + execYAMLTest(T_D9TU); +} + +TEST_F(FromYAMLTest, T_DBG4) +{ + execYAMLTest(T_DBG4); +} + +TEST_F(FromYAMLTest, T_DC7X) +{ + execYAMLTest(T_DC7X); +} + +TEST_F(FromYAMLTest, T_DE56) +{ + execYAMLTest(T_DE56); +} + +TEST_F(FromYAMLTest, T_DFF7) +{ + execYAMLTest(T_DFF7); +} + +TEST_F(FromYAMLTest, T_DHP8) +{ + execYAMLTest(T_DHP8); +} + +TEST_F(FromYAMLTest, T_DK3J) +{ + execYAMLTest(T_DK3J); +} + +TEST_F(FromYAMLTest, T_DK4H) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_DK4H); +} + +TEST_F(FromYAMLTest, T_DK95) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_DK95); +} + +TEST_F(FromYAMLTest, T_DMG6) +{ + execYAMLTest(T_DMG6); +} + +TEST_F(FromYAMLTest, T_DWX9) +{ + execYAMLTest(T_DWX9); +} + +TEST_F(FromYAMLTest, T_E76Z) +{ + execYAMLTest(T_E76Z); +} + +TEST_F(FromYAMLTest, T_EB22) +{ + execYAMLTest(T_EB22); +} + +TEST_F(FromYAMLTest, T_EHF6) +{ + execYAMLTest(T_EHF6); +} + +TEST_F(FromYAMLTest, T_EW3V) +{ + execYAMLTest(T_EW3V); +} + +TEST_F(FromYAMLTest, T_EX5H) +{ + execYAMLTest(T_EX5H); +} + +TEST_F(FromYAMLTest, T_EXG3) +{ + execYAMLTest(T_EXG3); +} + +TEST_F(FromYAMLTest, T_F2C7) +{ + execYAMLTest(T_F2C7); +} + +TEST_F(FromYAMLTest, T_F3CP) +{ + execYAMLTest(T_F3CP); +} + +TEST_F(FromYAMLTest, T_F6MC) +{ + execYAMLTest(T_F6MC); +} + +TEST_F(FromYAMLTest, T_F8F9) +{ + execYAMLTest(T_F8F9); +} + +TEST_F(FromYAMLTest, T_FBC9) +{ + execYAMLTest(T_FBC9); +} + +TEST_F(FromYAMLTest, T_FH7J) +{ + execYAMLTest(T_FH7J); +} + +TEST_F(FromYAMLTest, T_FP8R) +{ + execYAMLTest(T_FP8R); +} + +TEST_F(FromYAMLTest, T_FQ7F) +{ + execYAMLTest(T_FQ7F); +} + +TEST_F(FromYAMLTest, T_FRK4) +{ + execYAMLTest(T_FRK4); +} + +TEST_F(FromYAMLTest, T_FTA2) +{ + execYAMLTest(T_FTA2); +} + +TEST_F(FromYAMLTest, T_FUP4) +{ + execYAMLTest(T_FUP4); +} + +TEST_F(FromYAMLTest, T_G4RS) +{ + execYAMLTest(T_G4RS); +} + +TEST_F(FromYAMLTest, T_G5U8) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_G5U8); +} + +TEST_F(FromYAMLTest, T_G7JE) +{ + execYAMLTest(T_G7JE); +} + +TEST_F(FromYAMLTest, T_G992) +{ + execYAMLTest(T_G992); +} + +TEST_F(FromYAMLTest, T_G9HC) +{ + execYAMLTest(T_G9HC); +} + +TEST_F(FromYAMLTest, T_GDY7) +{ + execYAMLTest(T_GDY7); +} + +TEST_F(FromYAMLTest, T_GH63) +{ + execYAMLTest(T_GH63); +} + +TEST_F(FromYAMLTest, T_GT5M) +{ + execYAMLTest(T_GT5M); +} + +TEST_F(FromYAMLTest, T_H2RW) +{ + execYAMLTest(T_H2RW); +} + +TEST_F(FromYAMLTest, T_H3Z8) +{ + execYAMLTest(T_H3Z8); +} + +TEST_F(FromYAMLTest, T_H7J7) +{ + execYAMLTest(T_H7J7); +} + +/** This test is ignored because these tests are not required to fail and rapidyaml ignores the YAML version string. +TEST_F(FromYAMLTest, T_H7TQ) +{ + execYAMLTest(T_H7TQ); +} +*/ + +TEST_F(FromYAMLTest, T_HM87) +{ + execYAMLTest(T_HM87); +} + +TEST_F(FromYAMLTest, T_HMK4) +{ + execYAMLTest(T_HMK4); +} + +TEST_F(FromYAMLTest, T_HMQ5) +{ + execYAMLTest(T_HMQ5); +} + +TEST_F(FromYAMLTest, T_HRE5) +{ + execYAMLTest(T_HRE5); +} + +TEST_F(FromYAMLTest, T_HS5T) +{ + execYAMLTest(T_HS5T); +} + +TEST_F(FromYAMLTest, T_HU3P) +{ + execYAMLTest(T_HU3P); +} + +TEST_F(FromYAMLTest, T_HWV9) +{ + execYAMLTest(T_HWV9); +} + +TEST_F(FromYAMLTest, T_J3BT) +{ + execYAMLTest(T_J3BT); +} + +TEST_F(FromYAMLTest, T_J5UC) +{ + execYAMLTest(T_J5UC); +} + +TEST_F(FromYAMLTest, T_J7PZ) +{ + EXPECT_THROW(execYAMLTest(T_J7PZ), EvalError) << "usage of optional tag like !!set and !!omap (not implemented)"; +} + +TEST_F(FromYAMLTest, T_J7VC) +{ + execYAMLTest(T_J7VC); +} + +TEST_F(FromYAMLTest, T_J9HZ) +{ + execYAMLTest(T_J9HZ); +} + +TEST_F(FromYAMLTest, T_JEF9) +{ + execYAMLTest(T_JEF9); +} + +TEST_F(FromYAMLTest, T_JHB9) +{ + execYAMLTest(T_JHB9); +} + +TEST_F(FromYAMLTest, T_JKF3) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_JKF3); +} + +TEST_F(FromYAMLTest, T_JQ4R) +{ + execYAMLTest(T_JQ4R); +} + +TEST_F(FromYAMLTest, T_JR7V) +{ + execYAMLTest(T_JR7V); +} + +TEST_F(FromYAMLTest, T_JS2J) +{ + execYAMLTest(T_JS2J); +} + +TEST_F(FromYAMLTest, T_JTV5) +{ + execYAMLTest(T_JTV5); +} + +TEST_F(FromYAMLTest, T_JY7Z) +{ + execYAMLTest(T_JY7Z); +} + +TEST_F(FromYAMLTest, T_K3WX) +{ + execYAMLTest(T_K3WX); +} + +TEST_F(FromYAMLTest, T_K4SU) +{ + execYAMLTest(T_K4SU); +} + +TEST_F(FromYAMLTest, T_K527) +{ + execYAMLTest(T_K527); +} + +TEST_F(FromYAMLTest, T_K54U) +{ + execYAMLTest(T_K54U); +} + +TEST_F(FromYAMLTest, T_K858) +{ + execYAMLTest(T_K858); +} + +TEST_F(FromYAMLTest, T_KH5V) +{ + execYAMLTest(T_KH5V); +} + +TEST_F(FromYAMLTest, T_KK5P) +{ + execYAMLTest(T_KK5P); +} + +TEST_F(FromYAMLTest, T_KMK3) +{ + execYAMLTest(T_KMK3); +} + +TEST_F(FromYAMLTest, T_KS4U) +{ + execYAMLTest(T_KS4U); +} + +TEST_F(FromYAMLTest, T_KSS4) +{ + execYAMLTest(T_KSS4); +} + +TEST_F(FromYAMLTest, T_L24T) +{ + execYAMLTest(T_L24T); +} + +TEST_F(FromYAMLTest, T_L383) +{ + execYAMLTest(T_L383); +} + +TEST_F(FromYAMLTest, T_L94M) +{ + execYAMLTest(T_L94M); +} + +TEST_F(FromYAMLTest, T_L9U5) +{ + execYAMLTest(T_L9U5); +} + +TEST_F(FromYAMLTest, T_LE5A) +{ + execYAMLTest(T_LE5A); +} + +TEST_F(FromYAMLTest, T_LHL4) +{ + execYAMLTest(T_LHL4); +} + +TEST_F(FromYAMLTest, T_LP6E) +{ + execYAMLTest(T_LP6E); +} + +TEST_F(FromYAMLTest, T_LQZ7) +{ + execYAMLTest(T_LQZ7); +} + +TEST_F(FromYAMLTest, T_LX3P) +{ + execYAMLTest(T_LX3P); +} + +TEST_F(FromYAMLTest, T_M29M) +{ + execYAMLTest(T_M29M); +} + +TEST_F(FromYAMLTest, T_M2N8) +{ + execYAMLTest(T_M2N8); +} + +TEST_F(FromYAMLTest, T_M5C3) +{ + EXPECT_THROW(execYAMLTest(T_M5C3), EvalError) << "usage of unknown tags"; +} + +TEST_F(FromYAMLTest, T_M5DY) +{ + execYAMLTest(T_M5DY); +} + +TEST_F(FromYAMLTest, T_M6YH) +{ + execYAMLTest(T_M6YH); +} + +TEST_F(FromYAMLTest, T_M7A3) +{ + execYAMLTest(T_M7A3); +} + +TEST_F(FromYAMLTest, T_M7NX) +{ + execYAMLTest(T_M7NX); +} + +TEST_F(FromYAMLTest, T_M9B4) +{ + execYAMLTest(T_M9B4); +} + +TEST_F(FromYAMLTest, T_MJS9) +{ + execYAMLTest(T_MJS9); +} + +/** This test is ignored because these tests are not required to fail and rapidyaml ignores the YAML version string. +TEST_F(FromYAMLTest, T_MUS6) +{ + execYAMLTest(T_MUS6); +} +*/ + +TEST_F(FromYAMLTest, T_MXS3) +{ + execYAMLTest(T_MXS3); +} + +TEST_F(FromYAMLTest, T_MYW6) +{ + execYAMLTest(T_MYW6); +} + +TEST_F(FromYAMLTest, T_MZX3) +{ + execYAMLTest(T_MZX3); +} + +TEST_F(FromYAMLTest, T_N4JP) +{ + execYAMLTest(T_N4JP); +} + +TEST_F(FromYAMLTest, T_N782) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_N782); +} + +TEST_F(FromYAMLTest, T_NAT4) +{ + execYAMLTest(T_NAT4); +} + +TEST_F(FromYAMLTest, T_NB6Z) +{ + execYAMLTest(T_NB6Z); +} + +TEST_F(FromYAMLTest, T_NHX8) +{ + execYAMLTest(T_NHX8); +} + +TEST_F(FromYAMLTest, T_NJ66) +{ + execYAMLTest(T_NJ66); +} + +TEST_F(FromYAMLTest, T_NKF9) +{ + execYAMLTest(T_NKF9); +} + +TEST_F(FromYAMLTest, T_NP9H) +{ + execYAMLTest(T_NP9H); +} + +TEST_F(FromYAMLTest, T_P2AD) +{ + execYAMLTest(T_P2AD); +} + +TEST_F(FromYAMLTest, T_P2EQ) +{ + execYAMLTest(T_P2EQ); +} + +TEST_F(FromYAMLTest, T_P76L) +{ + EXPECT_THROW(execYAMLTest(T_P76L), EvalError) << "usage of unknown tags"; +} + +TEST_F(FromYAMLTest, T_P94K) +{ + execYAMLTest(T_P94K); +} + +TEST_F(FromYAMLTest, T_PBJ2) +{ + execYAMLTest(T_PBJ2); +} + +TEST_F(FromYAMLTest, T_PRH3) +{ + execYAMLTest(T_PRH3); +} + +TEST_F(FromYAMLTest, T_PUW8) +{ + execYAMLTest(T_PUW8); +} + +TEST_F(FromYAMLTest, T_PW8X) +{ + execYAMLTest(T_PW8X); +} + +TEST_F(FromYAMLTest, T_Q4CL) +{ + execYAMLTest(T_Q4CL); +} + +TEST_F(FromYAMLTest, T_Q5MG) +{ + execYAMLTest(T_Q5MG); +} + +TEST_F(FromYAMLTest, T_Q88A) +{ + execYAMLTest(T_Q88A); +} + +TEST_F(FromYAMLTest, T_Q8AD) +{ + execYAMLTest(T_Q8AD); +} + +TEST_F(FromYAMLTest, T_Q9WF) +{ + execYAMLTest(T_Q9WF); +} + +TEST_F(FromYAMLTest, T_QB6E) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_QB6E); +} + +TEST_F(FromYAMLTest, T_QF4Y) +{ + execYAMLTest(T_QF4Y); +} + +TEST_F(FromYAMLTest, T_QLJ7) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_QLJ7); +} + +TEST_F(FromYAMLTest, T_QT73) +{ + execYAMLTest(T_QT73); +} + +TEST_F(FromYAMLTest, T_R4YG) +{ + execYAMLTest(T_R4YG); +} + +TEST_F(FromYAMLTest, T_R52L) +{ + execYAMLTest(T_R52L); +} + +TEST_F(FromYAMLTest, T_RHX7) +{ + execYAMLTest(T_RHX7); +} + +TEST_F(FromYAMLTest, T_RLU9) +{ + execYAMLTest(T_RLU9); +} + +TEST_F(FromYAMLTest, T_RR7F) +{ + execYAMLTest(T_RR7F); +} + +TEST_F(FromYAMLTest, T_RTP8) +{ + execYAMLTest(T_RTP8); +} + +TEST_F(FromYAMLTest, T_RXY3) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_RXY3); +} + +TEST_F(FromYAMLTest, T_RZP5) +{ + execYAMLTest(T_RZP5); +} + +TEST_F(FromYAMLTest, T_RZT7) +{ + execYAMLTest(T_RZT7); +} + +TEST_F(FromYAMLTest, T_S3PD) +{ + execYAMLTest(T_S3PD); +} + +TEST_F(FromYAMLTest, T_S4GJ) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_S4GJ); +} + +TEST_F(FromYAMLTest, T_S4JQ) +{ + execYAMLTest(T_S4JQ); +} + +TEST_F(FromYAMLTest, T_S4T7) +{ + execYAMLTest(T_S4T7); +} + +TEST_F(FromYAMLTest, T_S7BG) +{ + execYAMLTest(T_S7BG); +} + +TEST_F(FromYAMLTest, T_S98Z) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_S98Z); +} + +TEST_F(FromYAMLTest, T_S9E8) +{ + execYAMLTest(T_S9E8); +} + +TEST_F(FromYAMLTest, T_SBG9) +{ + execYAMLTest(T_SBG9); +} + +TEST_F(FromYAMLTest, T_SF5V) +{ + execYAMLTest(T_SF5V); +} + +TEST_F(FromYAMLTest, T_SKE5) +{ + execYAMLTest(T_SKE5); +} + +TEST_F(FromYAMLTest, T_SM9W) +{ + execYAMLTest(T_SM9W); +} + +TEST_F(FromYAMLTest, T_SR86) +{ + execYAMLTest(T_SR86); +} + +TEST_F(FromYAMLTest, T_SSW6) +{ + execYAMLTest(T_SSW6); +} + +TEST_F(FromYAMLTest, T_SU5Z) +{ + execYAMLTest(T_SU5Z); +} + +TEST_F(FromYAMLTest, T_SU74) +{ + execYAMLTest(T_SU74); +} + +TEST_F(FromYAMLTest, T_SY6V) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_SY6V); +} + +TEST_F(FromYAMLTest, T_SYW4) +{ + execYAMLTest(T_SYW4); +} + +TEST_F(FromYAMLTest, T_T26H) +{ + execYAMLTest(T_T26H); +} + +TEST_F(FromYAMLTest, T_T4YY) +{ + execYAMLTest(T_T4YY); +} + +TEST_F(FromYAMLTest, T_T5N4) +{ + execYAMLTest(T_T5N4); +} + +TEST_F(FromYAMLTest, T_T833) +{ + execYAMLTest(T_T833); +} + +TEST_F(FromYAMLTest, T_TD5N) +{ + execYAMLTest(T_TD5N); +} + +TEST_F(FromYAMLTest, T_TE2A) +{ + execYAMLTest(T_TE2A); +} + +TEST_F(FromYAMLTest, T_TL85) +{ + execYAMLTest(T_TL85); +} + +TEST_F(FromYAMLTest, T_TS54) +{ + execYAMLTest(T_TS54); +} + +TEST_F(FromYAMLTest, T_U3C3) +{ + execYAMLTest(T_U3C3); +} + +TEST_F(FromYAMLTest, T_U3XV) +{ + execYAMLTest(T_U3XV); +} + +TEST_F(FromYAMLTest, T_U44R) +{ + execYAMLTest(T_U44R); +} + +TEST_F(FromYAMLTest, T_U99R) +{ + execYAMLTest(T_U99R); +} + +TEST_F(FromYAMLTest, T_U9NS) +{ + execYAMLTest(T_U9NS); +} + +TEST_F(FromYAMLTest, T_UDM2) +{ + execYAMLTest(T_UDM2); +} + +TEST_F(FromYAMLTest, T_UDR7) +{ + execYAMLTest(T_UDR7); +} + +TEST_F(FromYAMLTest, T_UGM3) +{ + EXPECT_THROW(execYAMLTest(T_UGM3), EvalError) << "usage of unknown tags"; +} + +TEST_F(FromYAMLTest, T_UKK6) +{ + execYAMLTest(T_UKK6); +} + +TEST_F(FromYAMLTest, T_UT92) +{ + execYAMLTest(T_UT92); +} + +TEST_F(FromYAMLTest, T_UV7Q) +{ + execYAMLTest(T_UV7Q); +} + +TEST_F(FromYAMLTest, T_V55R) +{ + execYAMLTest(T_V55R); +} + +TEST_F(FromYAMLTest, T_V9D5) +{ + execYAMLTest(T_V9D5); +} + +TEST_F(FromYAMLTest, T_VJP3) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_VJP3); +} + +TEST_F(FromYAMLTest, T_W42U) +{ + execYAMLTest(T_W42U); +} + +TEST_F(FromYAMLTest, T_W4TN) +{ + execYAMLTest(T_W4TN); +} + +TEST_F(FromYAMLTest, T_W5VH) +{ + execYAMLTest(T_W5VH); +} + +TEST_F(FromYAMLTest, T_W9L4) +{ + execYAMLTest(T_W9L4); +} + +TEST_F(FromYAMLTest, T_WZ62) +{ + execYAMLTest(T_WZ62); +} + +TEST_F(FromYAMLTest, T_X38W) +{ + execYAMLTest(T_X38W); +} + +TEST_F(FromYAMLTest, T_X4QW) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_X4QW); +} + +TEST_F(FromYAMLTest, T_X8DW) +{ + execYAMLTest(T_X8DW); +} + +TEST_F(FromYAMLTest, T_XLQ9) +{ + execYAMLTest(T_XLQ9); +} + +TEST_F(FromYAMLTest, T_XV9V) +{ + execYAMLTest(T_XV9V); +} + +TEST_F(FromYAMLTest, T_XW4D) +{ + execYAMLTest(T_XW4D); +} + +TEST_F(FromYAMLTest, T_Y2GN) +{ + execYAMLTest(T_Y2GN); +} + +TEST_F(FromYAMLTest, T_Y79Y) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_Y79Y); +} + +TEST_F(FromYAMLTest, T_YD5X) +{ + execYAMLTest(T_YD5X); +} + +TEST_F(FromYAMLTest, T_YJV2) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_YJV2); +} + +TEST_F(FromYAMLTest, T_Z67P) +{ + EXPECT_THROW(execYAMLTest(T_Z67P), EvalError) << "usage of unknown tags"; +} + +TEST_F(FromYAMLTest, T_Z9M4) +{ + EXPECT_THROW(execYAMLTest(T_Z9M4), EvalError) << "usage of unknown tags"; +} + +TEST_F(FromYAMLTest, T_ZCZ6) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_ZCZ6); +} + +TEST_F(FromYAMLTest, T_ZF4X) +{ + execYAMLTest(T_ZF4X); +} + +TEST_F(FromYAMLTest, T_ZH7C) +{ + execYAMLTest(T_ZH7C); +} + +TEST_F(FromYAMLTest, T_ZK9H) +{ + execYAMLTest(T_ZK9H); +} + +TEST_F(FromYAMLTest, T_ZL4Z) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_ZL4Z); +} + +TEST_F(FromYAMLTest, T_ZVH3) +{ + execYAMLTest(T_ZVH3); +} + +TEST_F(FromYAMLTest, T_ZWK4) +{ + execYAMLTest(T_ZWK4); +} + +TEST_F(FromYAMLTest, T_ZXT5) +{ + GTEST_SKIP() << "Reason: Invalid yaml is parsed successfully"; + execYAMLTest(T_ZXT5); +} + +/** This test is ignored because these tests are not required to fail and rapidyaml ignores the YAML version string. +TEST_F(FromYAMLTest, T_ZYU8) +{ + execYAMLTest(T_ZYU8); +} +*/ + +} /* namespace */ diff --git a/tests/unit/libexpr/yaml.cc b/tests/unit/libexpr/yaml.cc new file mode 100644 index 000000000..70a50324b --- /dev/null +++ b/tests/unit/libexpr/yaml.cc @@ -0,0 +1,377 @@ +#ifdef HAVE_RYML + +# include +# include "tests/libexpr.hh" +# include "primops.hh" + +// access to the json sax parser is required +# include "json-to-value-sax.hh" + +namespace { +using namespace nix; +using FromYAMLFun = Value(EvalState &, Value, std::optional); + +/** + * replacement of non-ascii unicode characters, which indicate the presence of certain characters that would be + * otherwise hard to read + */ +std::string replaceUnicodePlaceholders(std::string_view str) +{ + constexpr std::string_view eop("\xe2\x88\x8e"); + constexpr std::string_view filler{"\xe2\x80\x94"}; + constexpr std::string_view space{"\xe2\x90\xa3"}; + constexpr std::string_view newLine{"\xe2\x86\xb5"}; + constexpr std::string_view tab("\xc2\xbb"); + auto data = str.begin(); + std::string::size_type last = 0; + const std::string::size_type size = str.size(); + std::string ret; + ret.reserve(size); + for (std::string::size_type i = 0; i < size; i++) { + if ((str[i] & 0xc0) == 0xc0) { + char replaceWith = '\0'; + std::string::size_type seqSize = 1; + std::string::size_type remSize = size - i; + if (remSize >= 3 && (filler.find(data + i, 0, 3) != eop.find(data + i, 0, 3))) { + seqSize = 3; + } else if (remSize >= 3 && space.find(data + i, 0, 3) != space.npos) { + replaceWith = ' '; + seqSize = 3; + } else if (remSize >= 3 && newLine.find(data + i, 0, 3) != newLine.npos) { + seqSize = 3; + } else if (remSize >= 2 && tab.find(data + i, 0, 2) != tab.npos) { + replaceWith = '\t'; + seqSize = 2; + } else { + continue; + } + ret.append(str, last, i - last); + if (replaceWith != '\0') { + ret.append(&replaceWith, 1); + } + last = i + seqSize; + i += seqSize - 1; + } + } + ret.append(str.begin() + last, str.size() - last); + return ret; +} + +bool parseJSON(EvalState & state, std::istream & s_, Value & v) +{ + auto parser = makeJSONSaxParser(state, v); + return nlohmann::json::sax_parse(s_, parser.get(), nlohmann::json::input_format_t::json, false); +} + +Value parseJSONStream(EvalState & state, std::string_view json, std::function fromYAML) +{ + std::stringstream ss; + ss << json; + std::list list; + Value root, refJson; + std::streampos start = 0; + try { + while (ss.peek() != EOF && json.size() - ss.tellg() > 1) { + parseJSON(state, ss, refJson); + list.emplace_back(refJson); + // sanity check: builtins.fromJSON and builtins.fromYAML should return the same result when applied to a + // JSON string + root.mkString(std::string_view(json.begin() + start, ss.tellg() - start)); + Value rymlJson = fromYAML(state, root, {}); + EXPECT_EQ(printValue(state, refJson), printValue(state, rymlJson)); + start = ss.tellg() + std::streampos(1); + } + } catch (const std::exception & e) { + } + if (list.size() == 1) { + root = *list.begin(); + } else { + ListBuilder list_builder(state, list.size()); + size_t i = 0; + for (auto val : list) { + *(list_builder[i++] = state.allocValue()) = val; + } + root.mkList(list_builder); + } + return root; +} + +} /* namespace */ + +namespace nix { +// Testing the conversion from YAML + +class FromYAMLTest : public LibExprTest +{ +protected: + static std::function getFromYAML() + { + static std::function fromYAML = []() { + for (const auto & primOp : *RegisterPrimOp::primOps) { + if (primOp.name == "__fromYAML") { + auto primOpFun = primOp.fun; + std::function function = + [=](EvalState & state, Value yaml, std::optional options) { + Value emptyOptions, result; + auto bindings = state.buildBindings(0); + emptyOptions.mkAttrs(bindings); + Value * args[3] = {&yaml, options ? &*options : &emptyOptions, nullptr}; + primOpFun(state, noPos, args, result); + return result; + }; + return function; + } + } + ADD_FAILURE() << "The experimental feature \"fromYAML\" is not available"; + return std::function(); + }(); + return fromYAML; + } + + Value parseYAML(const char * str, std::optional options = {}) + { + Value test; + test.mkString(str); + return getFromYAML()(state, test, options); + } + + void execYAMLTest(std::string_view test) + { + auto fromYAML = getFromYAML(); + Value testVal; + testVal.mkString(test); + Value testCases = fromYAML(state, testVal, {}); + size_t ctr = 0; + std::string_view testName; + Value * json = nullptr; + for (auto testCase : testCases.listItems()) { + bool fail = false; + std::string_view yamlRaw; + for (auto attr = testCase->attrs()->begin(); attr != testCase->attrs()->end(); attr++) { + auto name = state.symbols[attr->name]; + if (name == "json") { + json = attr->value; + } else if (name == "yaml") { + yamlRaw = attr->value->string_view(); + } else if (name == "fail") { + fail = attr->value->boolean(); + } else if (name == "name") { + testName = attr->value->string_view(); + } + } + // extract expected result + Value jsonVal; + bool noJSON = !json || json->type() != nString; + if (!noJSON) { + std::string_view jsonStr = json->string_view(); + // Test cases with "json: ''" are parsed as empty JSON and test cases with the value of the "json" node + // being a block scalar, have no JSON representation, if the block scalar contains the line "null" + // (indentation 0) + noJSON = jsonStr.empty() + || (jsonStr != "null" && (jsonStr.starts_with("null") || jsonStr.ends_with("null"))) + || jsonStr.find("\nnull\n") != std::string_view::npos; + if (!noJSON) { + jsonVal = parseJSONStream(state, jsonStr, fromYAML); + } + } + // extract the YAML to be parsed + std::string yamlStr = replaceUnicodePlaceholders(yamlRaw); + Value yaml, yamlVal; + yaml.mkString(yamlStr); + if (noJSON) { + EXPECT_THROW(yamlVal = fromYAML(state, yaml, {}), EvalError) + << "Testcase #" << ctr + << ": YAML has no JSON representation because of empty document or null key, parsed \"" + << printValue(state, yamlVal) << "\":\n" + << yamlRaw; + } else if (!fail) { + yamlVal = fromYAML(state, yaml, {}); + EXPECT_EQ(printValue(state, yamlVal), printValue(state, jsonVal)) + << "Testcase #" << ctr << ": Parsed YAML does not match expected JSON result:\n" + << yamlRaw; + } else { + EXPECT_THROW(yamlVal = fromYAML(state, yaml, {}), EvalError) + << "Testcase #" << ctr << " (" << testName << "): Parsing YAML has to throw an exception, but \"" + << printValue(state, yamlVal) << "\" was parsed:\n" + << yamlRaw; + } + ctr++; + } + } +}; + +TEST_F(FromYAMLTest, NoContent) +{ + EXPECT_THROW(parseYAML(""), EvalError); +} + +TEST_F(FromYAMLTest, Null) +{ + Value val = parseYAML("[ null, Null, NULL, ~, ]"); + for (auto item : val.listItems()) { + EXPECT_EQ(item->type(), nNull); + } +} + +TEST_F(FromYAMLTest, NaN) +{ + const char * nans[] = {".nan", ".NaN", ".NAN"}; + for (auto str : nans) { + Value val = parseYAML(str); + ASSERT_EQ(val.type(), nFloat); + NixFloat _float = val.fpoint(); + EXPECT_NE(_float, _float) << "'" << str << "' shall be parsed as NaN"; + } + const char * strings[] = {"nan", "+nan", "-nan", "+.nan", "-.nan"}; + for (auto str : strings) { + Value val = parseYAML(str); + ASSERT_EQ(val.type(), nString) << "'" << str << "' shall not be converted to a floating point type"; + EXPECT_EQ(val.string_view(), std::string_view(str)); + } +} + +TEST_F(FromYAMLTest, Inf) +{ + NixFloat inf = std::numeric_limits::infinity(); + Value val = parseYAML("[ .INF, .Inf, .inf, +.INF, +.Inf, +.inf ]"); + for (auto item : val.listItems()) { + ASSERT_EQ(item->type(), nFloat); + EXPECT_EQ(item->fpoint(), inf); + } + val = parseYAML("[ -.INF, -.Inf, -.inf ]"); + for (auto item : val.listItems()) { + ASSERT_EQ(item->type(), nFloat); + EXPECT_EQ(item->fpoint(), -inf); + } + val = parseYAML("inf"); + ASSERT_EQ(val.type(), nString) << "'inf' shall not be converted to a floating point type"; + EXPECT_EQ(val.string_view(), "inf"); +} + +TEST_F(FromYAMLTest, Int) +{ + Value val = parseYAML("[ 1, +1, 0x1, 0o1 ]"); + for (auto item : val.listItems()) { + ASSERT_EQ(item->type(), nInt); + EXPECT_EQ(item->integer(), NixInt(1)); + } + + const char * strings[] = {"+", "0b1", "0B1", "0O1", "0X1", "+0b1", "-0b1", "+0o1", "-0o1", "+0x1", "-0x1"}; + for (auto str : strings) { + Value val = parseYAML(str); + ASSERT_EQ(val.type(), nString) << "'" << str << "' shall not be converted to an integer"; + EXPECT_EQ(val.string_view(), str); + } +} + +TEST_F(FromYAMLTest, Float) +{ + Value val = parseYAML("[ !!float 1, !!float 0x1, !!float 0o1, 1., +1., .1e1, +.1e1, 1.0, 10e-1, 10.e-1 ]"); + for (auto item : val.listItems()) { + ASSERT_EQ(item->type(), nFloat); + EXPECT_EQ(item->fpoint(), 1.); + } + val = parseYAML("!!float -0"); + ASSERT_EQ(val.type(), nFloat); + EXPECT_EQ(1. / val.fpoint(), 1. / -0.) << "\"!!float -0\" shall be parsed as -0.0"; + + const char * strings[] = {"0x1.", "0X1.", "0b1.", "0B1.", "0o1.", "0O1"}; + for (auto str : strings) { + Value val = parseYAML(str); + ASSERT_EQ(val.type(), nString) << "'" << str << "' shall not be converted to a float"; + EXPECT_EQ(val.string_view(), str); + } +} + +TEST_F(FromYAMLTest, TrueYAML1_2) +{ + Value val = parseYAML("[ true, True, TRUE ]"); + for (auto item : val.listItems()) { + ASSERT_EQ(item->type(), nBool); + EXPECT_TRUE(item->boolean()); + } + const char * strings[] = {"y", "Y", "on", "On", "ON", "yes", "Yes", "YES"}; + for (auto str : strings) { + Value val = parseYAML(str); + ASSERT_EQ(val.type(), nString) << "'" << str << "' shall not be converted to a boolean"; + EXPECT_EQ(val.string_view(), std::string_view(str)); + } +} + +TEST_F(FromYAMLTest, TrueYAML1_1) +{ + Value options; + auto bindings = state.buildBindings(1); + bindings.alloc("useBoolYAML1_1").mkBool(true); + options.mkAttrs(bindings); + + Value val = parseYAML("[ true, True, TRUE, y, Y, on, On, ON, yes, Yes, YES ]", options); + for (auto item : val.listItems()) { + ASSERT_EQ(item->type(), nBool); + EXPECT_TRUE(item->boolean()); + } +} + +TEST_F(FromYAMLTest, FalseYAML1_2) +{ + Value val = parseYAML("[ false, False, FALSE ]"); + for (auto item : val.listItems()) { + ASSERT_EQ(item->type(), nBool); + EXPECT_FALSE(item->boolean()); + } + const char * strings[] = {"n", "N", "no", "No", "NO", "off", "Off", "OFF"}; + for (auto str : strings) { + Value val = parseYAML(str); + ASSERT_EQ(val.type(), nString) << "'" << str << "' shall not be converted to a boolean"; + EXPECT_EQ(val.string_view(), std::string_view(str)); + } +} + +TEST_F(FromYAMLTest, FalseYAML1_1) +{ + Value options; + auto bindings = state.buildBindings(1); + bindings.alloc("useBoolYAML1_1").mkBool(true); + options.mkAttrs(bindings); + + Value val = parseYAML("[ false, False, FALSE, n, N, no, No, NO, off, Off, OFF ]", options); + for (auto item : val.listItems()) { + ASSERT_EQ(item->type(), nBool); + EXPECT_FALSE(item->boolean()); + } +} + +TEST_F(FromYAMLTest, QuotedString) +{ + const char * strings[] = { + "\"null\"", + "\"~\"", + "\"\"", + "\".inf\"", + "\"+.inf\"", + "\"-.inf\"", + "\".nan\"", + "\"true\"", + "\"false\"", + "\"1\"", + "\"+1\"", + "\"-1\"", + "\"1.0\""}; + for (auto str : strings) { + Value val = parseYAML(str); + ASSERT_EQ(val.type(), nString) << "'" << str << "' shall be parsed as string"; + EXPECT_EQ(val.string_view(), std::string_view(&str[1], strlen(str) - 2)); + } +} + +TEST_F(FromYAMLTest, Map) +{ + EXPECT_THROW(parseYAML("{ \"2\": 2, 2: null }"), EvalError) << "non-unique keys"; +} + +} /* namespace nix */ + +// include auto-generated header +# include "./yaml-test-suite.hh" + +#endif