diff options
| author | Stefan Boberg <[email protected]> | 2026-02-23 11:19:52 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-02-23 11:19:52 +0100 |
| commit | 9aac0fd369b87e965fb34b5168646387de7ea1cd (patch) | |
| tree | 367a820685a829adbab31cd1374b1af2cece4b7e /thirdparty/ryml/test/test_suite | |
| parent | changed command names and descriptions to use class members instead of string... (diff) | |
| download | zen-9aac0fd369b87e965fb34b5168646387de7ea1cd.tar.xz zen-9aac0fd369b87e965fb34b5168646387de7ea1cd.zip | |
implement yaml generation (#774)
this implements a yaml generation strategy similar to the JSON generation where we just build a string instead of building a ryml tree.
This also removes the dependency on ryml for reduced binary/build times.
Diffstat (limited to 'thirdparty/ryml/test/test_suite')
6 files changed, 0 insertions, 1233 deletions
diff --git a/thirdparty/ryml/test/test_suite/test_suite_common.hpp b/thirdparty/ryml/test/test_suite/test_suite_common.hpp deleted file mode 100644 index 9cfd89f1f..000000000 --- a/thirdparty/ryml/test/test_suite/test_suite_common.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef C4_YML_TEST_SUITE_COMMON_HPP_ -#define C4_YML_TEST_SUITE_COMMON_HPP_ - -#ifndef RYML_SINGLE_HEADER -#include <c4/yml/std/std.hpp> -#include <c4/yml/tree.hpp> -#include <c4/yml/parse.hpp> -#include <c4/yml/emit.hpp> -#include <c4/yml/detail/print.hpp> -#include <c4/yml/detail/checks.hpp> -#endif - -#include <c4/fs/fs.hpp> -#include <c4/log/log.hpp> - -#include "test_case.hpp" -#include <gtest/gtest.h> - -#define RYML_NFO (0 || RYML_DBG) - -#if RYML_NFO -#define _nfo_print_tree(title, tree) do { c4::log("{}:{}: " title ":", __FILE__, __LINE__); print_tree(tree); c4::yml::emit(tree, stdout); fflush(stdout); } while(0) -#define _nfo_logf(fmt, ...) do { c4::log("{}:{}: " fmt , __FILE__, __LINE__, __VA_ARGS__); fflush(stdout); } while(0) -#define _nfo_log(fmt) do { c4::log("{}:{}: " fmt , __FILE__, __LINE__); fflush(stdout); } while(0) -#define _nfo_printf(...) printf(__VA_ARGS__) -#else -#define _nfo_print_tree(title, tree) -#define _nfo_logf(fmt, ...) -#define _nfo_log(fmt) -#define _nfo_printf(...) -#endif -#define _nfo_llogf(fmt, ...) _nfo_logf("line[{}]: '{}': " fmt, linenum, line, __VA_ARGS__) -#define _nfo_llog(fmt) _nfo_logf("line[{}]: '{}': " fmt, linenum, line) - - -namespace c4 { -namespace yml { - - -} // namespace yml -} // namespace c4 - - -#endif /* C4_YML_TEST_SUITE_COMMON_HPP_ */ diff --git a/thirdparty/ryml/test/test_suite/test_suite_events.cpp b/thirdparty/ryml/test/test_suite/test_suite_events.cpp deleted file mode 100644 index b359421b5..000000000 --- a/thirdparty/ryml/test/test_suite/test_suite_events.cpp +++ /dev/null @@ -1,607 +0,0 @@ -#include "test_suite_events.hpp" -#include "test_suite_common.hpp" -#ifndef RYML_SINGLE_HEADER -#include <c4/yml/detail/stack.hpp> -#endif - -namespace c4 { -namespace yml { - -namespace /*anon*/ { - -struct ScalarType -{ - typedef enum { - PLAIN = 0, - SQUOTED, - DQUOTED, - LITERAL, - FOLDED - } ScalarType_e; - - ScalarType_e val = PLAIN; - bool operator== (ScalarType_e v) const { return val == v; } - bool operator!= (ScalarType_e v) const { return val != v; } - ScalarType& operator= (ScalarType_e v) { val = v; return *this; } - - csubstr to_str() const - { - switch(val) - { - case ScalarType::PLAIN: return csubstr("PLAIN"); - case ScalarType::SQUOTED: return csubstr("SQUOTED"); - case ScalarType::DQUOTED: return csubstr("DQUOTED"); - case ScalarType::LITERAL: return csubstr("LITERAL"); - case ScalarType::FOLDED: return csubstr("FOLDED"); - } - C4_ERROR(""); - return csubstr(""); - } - - bool is_quoted() const { return val == ScalarType::SQUOTED || val == ScalarType::DQUOTED; } -}; - - -struct OptionalScalar -{ - csubstr val = {}; - bool was_set = false; - inline operator csubstr() const { return get(); } - inline operator bool() const { return was_set; } - void operator= (csubstr v) { val = v; was_set = true; } - csubstr get() const { RYML_ASSERT(was_set); return val; } -}; - -#if RYML_NFO -size_t to_chars(c4::substr buf, OptionalScalar const& s) -{ - if(!s) - return 0u; - if(s.val.len <= buf.len) - memcpy(buf.str, s.val.str, s.val.len); - return s.val.len; -} -#endif - -csubstr filtered_scalar(csubstr str, ScalarType scalar_type, Tree *tree) -{ - (void)scalar_type; - csubstr tokens[] = {R"(\n)", R"(\t)", R"(\\)"}; - if(!str.first_of_any_iter(std::begin(tokens), std::end(tokens))) - return str; - substr buf = tree->alloc_arena(str.len); // we are going to always replace with less characters - size_t strpos = 0; - size_t bufpos = 0; - auto append_str = [&](size_t pos){ - csubstr rng = str.range(strpos, pos); - memcpy(buf.str + bufpos, rng.str, rng.len); - bufpos += rng.len; - strpos = pos; - }; - size_t i; - auto append_chars = [&](csubstr s, size_t skipstr){ - memcpy(buf.str + bufpos, s.str, s.len); - bufpos += s.len; - i += skipstr - 1; // incremented at the loop - strpos += skipstr; - }; - for(i = 0; i < str.len; ++i) - { - char curr = str[i]; - char next1 = i+1 < str.len ? str[i+1] : '\0'; - if(curr == '\\') - { - if(next1 == '\\') - { - char next2 = i+2 < str.len ? str[i+2] : '\0'; - if(next2 == 'n') - { - append_str(i); - append_chars(R"(\n)", 3u); // '\\n' -> '\n' - } - else if(next2 == 't') - { - append_str(i); - append_chars(R"(\t)", 3u); // '\\t' -> '\t' - } - else - { - append_str(i); - append_chars(R"(\)", 2u); // '\\' -> '\' - } - } - else if(next1 == 'n') - { - append_str(i); - append_chars("\n", 2u); - } - else if(next1 == 't') - { - append_str(i); - append_chars("\t", 2u); - } - } - } - append_str(str.len); - buf = buf.first(bufpos); - _nfo_logf("filtering: result=~~~{}~~~", buf); - return buf; -} - -struct Scalar -{ - OptionalScalar scalar = {}; - OptionalScalar anchor = {}; - OptionalScalar ref = {}; - OptionalScalar tag = {}; - ScalarType type = {}; - inline operator bool() const { if(anchor || tag) { RYML_ASSERT(scalar); } return scalar.was_set; } - void add_key_props(Tree *tree, size_t node) const - { - if(ref) - { - _nfo_logf("node[{}]: set key ref: '{}'", node, ref); - tree->set_key_ref(node, ref); - } - if(anchor) - { - _nfo_logf("node[{}]: set key anchor: '{}'", node, anchor); - tree->set_key_anchor(node, anchor); - } - if(tag) - { - csubstr ntag = normalize_tag(tag); - _nfo_logf("node[{}]: set key tag: '{}' -> '{}'", node, tag, ntag); - tree->set_key_tag(node, ntag); - } - if(type.is_quoted()) - { - _nfo_logf("node[{}]: set key as quoted", node); - tree->_add_flags(node, KEYQUO); - } - } - void add_val_props(Tree *tree, size_t node) const - { - if(ref) - { - _nfo_logf("node[{}]: set val ref: '{}'", node, ref); - tree->set_val_ref(node, ref); - } - if(anchor) - { - _nfo_logf("node[{}]: set val anchor: '{}'", node, anchor); - tree->set_val_anchor(node, anchor); - } - if(tag) - { - csubstr ntag = normalize_tag(tag); - _nfo_logf("node[{}]: set val tag: '{}' -> '{}'", node, tag, ntag); - tree->set_val_tag(node, ntag); - } - if(type.is_quoted()) - { - _nfo_logf("node[{}]: set val as quoted", node); - tree->_add_flags(node, VALQUO); - } - } - csubstr filtered_scalar(Tree *tree) const - { - return ::c4::yml::filtered_scalar(scalar, type, tree); - } -}; - -csubstr parse_anchor_and_tag(csubstr tokens, OptionalScalar *anchor, OptionalScalar *tag) -{ - *anchor = OptionalScalar{}; - *tag = OptionalScalar{}; - if(tokens.begins_with('&')) - { - size_t pos = tokens.first_of(' '); - if(pos == (size_t)csubstr::npos) - { - *anchor = tokens.sub(1); - tokens = {}; - } - else - { - *anchor = tokens.first(pos).sub(1); - tokens = tokens.right_of(pos); - } - _nfo_logf("anchor: {}", *anchor); - } - if(tokens.begins_with('<')) - { - size_t pos = tokens.find('>'); - RYML_ASSERT(pos != (size_t)csubstr::npos); - *tag = tokens.first(pos + 1); - tokens = tokens.right_of(pos).triml(' '); - _nfo_logf("tag: {}", *tag); - } - return tokens; -} - -} // namespace /*anon*/ - -void EventsParser::parse(csubstr src, Tree *C4_RESTRICT tree_) -{ - struct ParseLevel { size_t tree_node; }; - detail::stack<ParseLevel> m_stack = {}; - Tree &C4_RESTRICT tree = *tree_; - size_t linenum = 0; - Scalar key = {}; - _nfo_logf("parsing events! src:\n{}", src); - for(csubstr line : src.split('\n')) - { - line = line.trimr('\r'); - line = line.triml(' '); - _nfo_printf("\n\n-----------------------\n"); - _nfo_llog(""); - _nfo_logf("line[{}]: top={} type={}", linenum, m_stack.empty() ? tree.root_id() : m_stack.top().tree_node, NodeType::type_str(tree.type(m_stack.empty() ? tree.root_id() : m_stack.top().tree_node))); - if(line.begins_with("=VAL ")) - { - line = line.stripl("=VAL "); - ASSERT_GE(m_stack.size(), 0u); - Scalar curr = {}; - line = parse_anchor_and_tag(line, &curr.anchor, &curr.tag); - if(line.begins_with('"')) - { - _nfo_llog("double-quoted scalar!"); - curr.scalar = line.sub(1); - curr.type = ScalarType::DQUOTED; - } - else if(line.begins_with('\'')) - { - _nfo_llog("single-quoted scalar!"); - curr.scalar = line.sub(1); - curr.type = ScalarType::SQUOTED; - } - else if(line.begins_with('|')) - { - _nfo_llog("block literal scalar!"); - curr.scalar = line.sub(1); - curr.type = ScalarType::LITERAL; - } - else if(line.begins_with('>')) - { - _nfo_llog("block folded scalar!"); - curr.scalar = line.sub(1); - curr.type = ScalarType::FOLDED; - } - else - { - _nfo_llog("plain scalar"); - ASSERT_TRUE(line.begins_with(':')); - curr.scalar = line.sub(1); - } - _nfo_logf("parsed scalar: '{}'", curr.scalar); - if(m_stack.empty()) - { - _nfo_log("stack was empty, pushing root as DOC..."); - //tree._p(tree.root_id())->m_type.add(DOC); - m_stack.push({tree.root_id()}); - } - ParseLevel &top = m_stack.top(); - if(tree.is_seq(top.tree_node)) - { - _nfo_logf("is seq! seq_id={}", top.tree_node); - ASSERT_FALSE(key); - ASSERT_TRUE(curr); - _nfo_logf("seq[{}]: adding child", top.tree_node); - size_t node = tree.append_child(top.tree_node); - NodeType_e as_doc = tree.is_stream(top.tree_node) ? DOC : NOTYPE; - _nfo_logf("seq[{}]: child={} val='{}' as_doc=", top.tree_node, node, curr.scalar, NodeType::type_str(as_doc)); - tree.to_val(node, curr.filtered_scalar(&tree), as_doc); - curr.add_val_props(&tree, node); - } - else if(tree.is_map(top.tree_node)) - { - _nfo_logf("is map! map_id={}", top.tree_node); - if(!key) - { - _nfo_logf("store key='{}' anchor='{}' tag='{}' type={}", curr.scalar, curr.anchor, curr.tag, curr.type.to_str()); - key = curr; - } - else - { - _nfo_logf("map[{}]: adding child", top.tree_node); - size_t node = tree.append_child(top.tree_node); - NodeType_e as_doc = tree.is_stream(top.tree_node) ? DOC : NOTYPE; - _nfo_logf("map[{}]: child={} key='{}' val='{}' as_doc={}", top.tree_node, node, key.scalar, curr.scalar, NodeType::type_str(as_doc)); - tree.to_keyval(node, key.filtered_scalar(&tree), curr.filtered_scalar(&tree), as_doc); - key.add_key_props(&tree, node); - curr.add_val_props(&tree, node); - _nfo_logf("clear key='{}'", key.scalar); - key = {}; - } - } - else - { - _nfo_logf("setting tree_node={} to DOCVAL...", top.tree_node); - tree.to_val(top.tree_node, curr.filtered_scalar(&tree), DOC); - curr.add_val_props(&tree, top.tree_node); - } - } - else if(line.begins_with("=ALI ")) - { - csubstr alias = line.stripl("=ALI "); - _nfo_logf("REF token: {}", alias); - ParseLevel top = m_stack.top(); - if(tree.is_seq(top.tree_node)) - { - _nfo_logf("node[{}] is seq: set {} as val ref", top.tree_node, alias); - ASSERT_FALSE(key); - size_t node = tree.append_child(top.tree_node); - tree.to_val(node, alias); - tree.set_val_ref(node, alias); - } - else if(tree.is_map(top.tree_node)) - { - if(key) - { - _nfo_logf("node[{}] is map and key '{}' is pending: set {} as val ref", top.tree_node, key.scalar, alias); - size_t node = tree.append_child(top.tree_node); - tree.to_keyval(node, key.filtered_scalar(&tree), alias); - key.add_key_props(&tree, node); - tree.set_val_ref(node, alias); - _nfo_logf("clear key='{}'", key); - key = {}; - } - else - { - _nfo_logf("node[{}] is map and no key is pending: save {} as key ref", top.tree_node, alias); - key.scalar = alias; - key.ref = alias; - } - } - else - { - C4_ERROR("ALI event requires map or seq"); - } - } - else if(line.begins_with("+SEQ")) - { - _nfo_log("pushing SEQ"); - OptionalScalar anchor = {}; - OptionalScalar tag = {}; - csubstr more_tokens = line.stripl("+SEQ").triml(' '); - if(more_tokens.begins_with('[')) - { - ASSERT_TRUE(more_tokens.begins_with("[]")); - more_tokens = more_tokens.offs(2, 0).triml(' '); - } - parse_anchor_and_tag(more_tokens, &anchor, &tag); - size_t node = tree.root_id(); - if(m_stack.empty()) - { - _nfo_log("stack was empty, set root to SEQ"); - tree._add_flags(node, SEQ); - m_stack.push({node}); - ASSERT_FALSE(key); // for the key to exist, the parent must exist and be a map - } - else - { - size_t parent = m_stack.top().tree_node; - _nfo_logf("stack was not empty. parent={}", parent); - ASSERT_NE(parent, (size_t)NONE); - NodeType more_flags = NOTYPE; - if(tree.is_doc(parent) && !(tree.is_seq(parent) || tree.is_map(parent))) - { - _nfo_logf("set node to parent={}, add DOC", parent); - node = parent; - more_flags.add(DOC); - } - else - { - _nfo_logf("add child to parent={}", parent); - node = tree.append_child(parent); - m_stack.push({node}); - _nfo_logf("add child to parent={}: child={}", parent, node); - } - if(key) - { - _nfo_logf("has key, set to keyseq: parent={} child={} key='{}'", parent, node, key); - ASSERT_EQ(tree.is_map(parent) || node == parent, true); - tree.to_seq(node, key.filtered_scalar(&tree), more_flags); - key.add_key_props(&tree, node); - _nfo_logf("clear key='{}'", key.scalar); - key = {}; - } - else - { - if(tree.is_map(parent)) - { - _nfo_logf("has null key, set to keyseq: parent={} child={}", parent, node); - ASSERT_EQ(tree.is_map(parent) || node == parent, true); - tree.to_seq(node, csubstr{}, more_flags); - } - else - { - _nfo_logf("no key, set to seq: parent={} child={}", parent, node); - tree.to_seq(node, more_flags); - } - } - } - if(tag) - tree.set_val_tag(node, normalize_tag(tag)); - if(anchor) - tree.set_val_anchor(node, anchor); - } - else if(line.begins_with("+MAP")) - { - _nfo_log("pushing MAP"); - OptionalScalar anchor = {}; - OptionalScalar tag = {}; - csubstr more_tokens = line.stripl("+MAP").triml(' '); - if(more_tokens.begins_with('{')) - { - ASSERT_TRUE(more_tokens.begins_with("{}")); - more_tokens = more_tokens.offs(2, 0).triml(' '); - } - parse_anchor_and_tag(more_tokens, &anchor, &tag); - size_t node = tree.root_id(); - if(m_stack.empty()) - { - _nfo_log("stack was empty, set root to MAP"); - tree._add_flags(node, MAP); - m_stack.push({node}); - ASSERT_FALSE(key); // for the key to exist, the parent must exist and be a map - } - else - { - size_t parent = m_stack.top().tree_node; - _nfo_logf("stack was not empty. parent={}", parent); - ASSERT_NE(parent, (size_t)NONE); - NodeType more_flags = NOTYPE; - if(tree.is_doc(parent) && !(tree.is_seq(parent) || tree.is_map(parent))) - { - _nfo_logf("set node to parent={}, add DOC", parent); - node = parent; - more_flags.add(DOC); - } - else - { - _nfo_logf("add child to parent={}", parent); - node = tree.append_child(parent); - m_stack.push({node}); - _nfo_logf("add child to parent={}: child={}", parent, node); - } - if(key) - { - _nfo_logf("has key, set to keymap: parent={} child={} key='{}'", parent, node, key); - ASSERT_EQ(tree.is_map(parent) || node == parent, true); - tree.to_map(node, key.filtered_scalar(&tree), more_flags); - key.add_key_props(&tree, node); - _nfo_logf("clear key='{}'", key.scalar); - key = {}; - } - else - { - if(tree.is_map(parent)) - { - _nfo_logf("has null key, set to keymap: parent={} child={}", parent, node); - ASSERT_EQ(tree.is_map(parent) || node == parent, true); - tree.to_map(node, csubstr{}, more_flags); - } - else - { - _nfo_logf("no key, set to map: parent={} child={}", parent, node); - tree.to_map(node, more_flags); - } - } - } - if(tag) - tree.set_val_tag(node, normalize_tag(tag)); - if(anchor) - tree.set_val_anchor(node, anchor); - } - else if(line.begins_with("-SEQ")) - { - _nfo_logf("popping SEQ, empty={}", m_stack.empty()); - size_t node; - if(m_stack.empty()) - node = tree.root_id(); - else - node = m_stack.pop().tree_node; - ASSERT_TRUE(tree.is_seq(node)) << "node=" << node; - } - else if(line.begins_with("-MAP")) - { - _nfo_logf("popping MAP, empty={}", m_stack.empty()); - size_t node; - if(m_stack.empty()) - node = tree.root_id(); - else - node = m_stack.pop().tree_node; - ASSERT_TRUE(tree.is_map(node)) << "node=" << node; - } - else if(line.begins_with("+DOC")) - { - csubstr rem = line.stripl("+DOC").triml(' '); - _nfo_logf("pushing DOC: {}", rem); - size_t node = tree.root_id(); - auto is_sep = rem.first_of_any("---\n", "--- ", "---\r") || rem.ends_with("---"); - ASSERT_EQ(key, false); // for the key to exist, the parent must exist and be a map - if(m_stack.empty()) - { - _nfo_log("stack was empty"); - ASSERT_EQ(node, tree.root_id()); - if(tree.is_stream(node)) - { - _nfo_log("there is already a stream, append a DOC"); - node = tree.append_child(node); - tree.to_doc(node); - m_stack.push({node}); - } - else if(is_sep) - { - _nfo_logf("separator was specified: {}", rem); - if((!tree.is_container(node)) && (!tree.is_doc(node))) - { - tree._add_flags(node, STREAM); - node = tree.append_child(node); - _nfo_logf("create STREAM at {} and add DOC child={}", tree.root_id(), node); - tree.to_doc(node); - m_stack.push({node}); - } - else - { - _nfo_log("rearrange root as STREAM"); - tree.set_root_as_stream(); - node = tree.append_child(tree.root_id()); - _nfo_logf("added doc as STREAM child: {}", node); - tree.to_doc(node); - m_stack.push({node}); - } - } - else - { - if(tree.is_doc(node)) - { - _nfo_log("rearrange root as STREAM"); - tree.set_root_as_stream(); - m_stack.push({node}); - } - } - } - else - { - size_t parent = m_stack.top().tree_node; - _nfo_logf("add DOC to parent={}", parent); - ASSERT_NE(parent, (size_t)NONE); - node = tree.append_child(parent); - _nfo_logf("child DOC={}", node); - tree.to_doc(node); - m_stack.push({node}); - } - } - else if(line.begins_with("-DOC")) - { - _nfo_log("popping DOC"); - if(!m_stack.empty()) - m_stack.pop(); - } - else if(line.begins_with("+STR")) - { - ASSERT_EQ(m_stack.size(), 0u); - } - else if(line.begins_with("-STR")) - { - ASSERT_LE(m_stack.size(), 1u); - if(!m_stack.empty()) - m_stack.pop(); - } - else if(line.empty()) - { - // nothing to do - } - else - { - C4_ERROR("unknown event: '%.*s'", (int)line.len, line.str); - } - linenum++; - } -} - - -} // namespace yml -} // namespace c4 diff --git a/thirdparty/ryml/test/test_suite/test_suite_events.hpp b/thirdparty/ryml/test/test_suite/test_suite_events.hpp deleted file mode 100644 index 3b3cdbffb..000000000 --- a/thirdparty/ryml/test/test_suite/test_suite_events.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef C4_YML_TEST_SUITE_EVENTS_HPP_ -#define C4_YML_TEST_SUITE_EVENTS_HPP_ - -#ifdef RYML_SINGLE_HEADER -#include <ryml_all.hpp> -#else -#include <c4/yml/tree.hpp> -#endif - -namespace c4 { -namespace yml { - -struct EventsParser -{ - void parse(csubstr src, Tree *C4_RESTRICT tree); -}; - -size_t emit_events(substr buf, Tree const& C4_RESTRICT tree); - -template<class CharContainer> -void emit_events(CharContainer *container, Tree const& C4_RESTRICT tree) -{ - size_t ret = emit_events(to_substr(*container), tree); - if(ret > container->size()) - { - container->resize(ret); - ret = emit_events(to_substr(*container), tree); - C4_CHECK(ret == container->size()); - } - container->resize(ret); -} - -template<class CharContainer> -CharContainer emit_events(Tree const& C4_RESTRICT tree) -{ - CharContainer result; - emit_events(&result, tree); - return result; -} - -} // namespace yml -} // namespace c4 - - -#endif /* C4_YML_TEST_SUITE_EVENTS_HPP_ */ diff --git a/thirdparty/ryml/test/test_suite/test_suite_events_emitter.cpp b/thirdparty/ryml/test/test_suite/test_suite_events_emitter.cpp deleted file mode 100644 index 6c22b1e6e..000000000 --- a/thirdparty/ryml/test/test_suite/test_suite_events_emitter.cpp +++ /dev/null @@ -1,289 +0,0 @@ -#ifndef RYML_SINGLE_HEADER -#include <c4/yml/std/string.hpp> -#endif -#include "test_suite_events.hpp" - -namespace c4 { -namespace yml { - -struct EventsEmitter -{ - substr buf; - size_t pos; - std::string tagbuf; - Tree const* C4_RESTRICT m_tree; - EventsEmitter(Tree const& tree, substr buf_) : buf(buf_), pos(), m_tree(&tree) {} - void emit_tag(csubstr tag, size_t node); - void emit_scalar(csubstr val, bool quoted); - void emit_key_anchor_tag(size_t node); - void emit_val_anchor_tag(size_t node); - void emit_events(size_t node); - void emit_doc(size_t node); - void emit_events(); - template<size_t N> - C4_ALWAYS_INLINE void pr(const char (&s)[N]) - { - if(pos + N-1 <= buf.len) - memcpy(buf.str + pos, s, N-1); - pos += N-1; - } - C4_ALWAYS_INLINE void pr(csubstr s) - { - if(pos + s.len <= buf.len) - memcpy(buf.str + pos, s.str, s.len); - pos += s.len; - } - C4_ALWAYS_INLINE void pr(char c) - { - if(pos + 1 <= buf.len) - buf[pos] = c; - ++pos; - } - C4_ALWAYS_INLINE size_t emit_to_esc(csubstr val, size_t prev, size_t i, char c) - { - pr(val.range(prev, i)); - pr('\\'); - pr(c); - return i+1; - } - C4_ALWAYS_INLINE size_t emit_to_esc(csubstr val, size_t prev, size_t i, csubstr repl) - { - pr(val.range(prev, i)); - pr(repl); - return i+1; - } -}; - -void EventsEmitter::emit_scalar(csubstr val, bool quoted) -{ - constexpr const char openchar[] = {':', '\''}; - pr(openchar[quoted]); - size_t prev = 0; - uint8_t const* C4_RESTRICT s = (uint8_t const* C4_RESTRICT) val.str; - for(size_t i = 0; i < val.len; ++i) - { - switch(s[i]) - { - case UINT8_C(0x0a): // \n - prev = emit_to_esc(val, prev, i, 'n'); break; - case UINT8_C(0x5c): // '\\' - prev = emit_to_esc(val, prev, i, '\\'); break; - case UINT8_C(0x09): // \t - prev = emit_to_esc(val, prev, i, 't'); break; - case UINT8_C(0x0d): // \r - prev = emit_to_esc(val, prev, i, 'r'); break; - case UINT8_C(0x00): // \0 - prev = emit_to_esc(val, prev, i, '0'); break; - case UINT8_C(0x0c): // \f (form feed) - prev = emit_to_esc(val, prev, i, 'f'); break; - case UINT8_C(0x08): // \b (backspace) - prev = emit_to_esc(val, prev, i, 'b'); break; - case UINT8_C(0x07): // \a (bell) - prev = emit_to_esc(val, prev, i, 'a'); break; - case UINT8_C(0x0b): // \v (vertical tab) - prev = emit_to_esc(val, prev, i, 'v'); break; - case UINT8_C(0x1b): // \e (escape) - prev = emit_to_esc(val, prev, i, "\\e"); break; - case UINT8_C(0xc2): - if(i+1 < val.len) - { - uint8_t np1 = s[i+1]; - if(np1 == UINT8_C(0xa0)) - prev = 1u + emit_to_esc(val, prev, i++, "\\_"); - else if(np1 == UINT8_C(0x85)) - prev = 1u + emit_to_esc(val, prev, i++, "\\N"); - } - break; - case UINT8_C(0xe2): - if(i+2 < val.len) - { - if(s[i+1] == UINT8_C(0x80)) - { - if(s[i+2] == UINT8_C(0xa8)) - { - prev = 2u + emit_to_esc(val, prev, i, "\\L"); - i += 2u; - } - else if(s[i+2] == UINT8_C(0xa9)) - { - prev = 2u + emit_to_esc(val, prev, i, "\\P"); - i += 2u; - } - } - } - break; - } - } - pr(val.sub(prev)); // print remaining portion -} - -void EventsEmitter::emit_tag(csubstr tag, size_t node) -{ - size_t tagsize = m_tree->resolve_tag(to_substr(tagbuf), tag, node); - if(tagsize) - { - if(tagsize > tagbuf.size()) - { - tagbuf.resize(tagsize); - tagsize = m_tree->resolve_tag(to_substr(tagbuf), tag, node); - } - pr(to_substr(tagbuf).first(tagsize)); - } - else - { - csubstr ntag = normalize_tag_long(tag); - if(ntag.begins_with('<')) - { - pr(ntag); - } - else - { - pr('<'); - pr(ntag); - pr('>'); - } - } -} - -void EventsEmitter::emit_key_anchor_tag(size_t node) -{ - if(m_tree->has_key_anchor(node)) - { - pr(" &"); - pr(m_tree->key_anchor(node)); - } - if(m_tree->has_key_tag(node)) - { - pr(' '); - emit_tag(m_tree->key_tag(node), node); - } -} - -void EventsEmitter::emit_val_anchor_tag(size_t node) -{ - if(m_tree->has_val_anchor(node)) - { - pr(" &"); - pr(m_tree->val_anchor(node)); - } - if(m_tree->has_val_tag(node)) - { - pr(' '); - emit_tag(m_tree->val_tag(node), node); - } -} - -void EventsEmitter::emit_events(size_t node) -{ - if(m_tree->has_key(node)) - { - if(m_tree->is_key_ref(node)) - { - csubstr k = m_tree->key(node); - if(k != "<<") - { - pr("=ALI "); - pr(k); - pr('\n'); - } - else - { - pr("=VAL :"); - pr(k); - pr('\n'); - } - } - else - { - pr("=VAL"); - emit_key_anchor_tag(node); - pr(' '); - emit_scalar(m_tree->key(node), m_tree->is_key_quoted(node)); - pr('\n'); - } - } - if(m_tree->has_val(node)) - { - if(m_tree->is_val_ref(node)) - { - pr("=ALI "); - pr(m_tree->val(node)); - pr('\n'); - } - else - { - pr("=VAL"); - emit_val_anchor_tag(node); - pr(' '); - emit_scalar(m_tree->val(node), m_tree->is_val_quoted(node)); - pr('\n'); - } - } - else if(m_tree->is_map(node)) - { - pr("+MAP"); - emit_val_anchor_tag(node); - pr('\n'); - for(size_t child = m_tree->first_child(node); child != NONE; child = m_tree->next_sibling(child)) - emit_events(child); - pr("-MAP\n"); - } - else if(m_tree->is_seq(node)) - { - pr("+SEQ"); - emit_val_anchor_tag(node); - pr('\n'); - for(size_t child = m_tree->first_child(node); child != NONE; child = m_tree->next_sibling(child)) - emit_events(child); - pr("-SEQ\n"); - } -} - -void EventsEmitter::emit_doc(size_t node) -{ - if(m_tree->type(node) == NOTYPE) - return; - if(m_tree->has_parent(node)) - pr("+DOC ---"); // parent must be a stream - else - pr("+DOC"); - if(m_tree->is_val(node)) - { - pr("\n=VAL"); - emit_val_anchor_tag(node); - pr(' '); - emit_scalar(m_tree->val(node), m_tree->is_val_quoted(node)); - pr('\n'); - } - else - { - pr('\n'); - emit_events(node); - } - pr("-DOC\n"); -} - -void EventsEmitter::emit_events() -{ - pr("+STR\n"); - if(!m_tree->empty()) - { - size_t root = m_tree->root_id(); - if(m_tree->is_stream(root)) - for(size_t node = m_tree->first_child(root); node != NONE; node = m_tree->next_sibling(node)) - emit_doc(node); - else - emit_doc(root); - } - pr("-STR\n"); -} - -size_t emit_events(substr buf, Tree const& C4_RESTRICT tree) -{ - EventsEmitter e(tree, buf); - e.emit_events(); - return e.pos; -} - -} // namespace yml -} // namespace c4 diff --git a/thirdparty/ryml/test/test_suite/test_suite_parts.cpp b/thirdparty/ryml/test/test_suite/test_suite_parts.cpp deleted file mode 100644 index 5caaafeab..000000000 --- a/thirdparty/ryml/test/test_suite/test_suite_parts.cpp +++ /dev/null @@ -1,220 +0,0 @@ -#include "./test_suite_parts.hpp" - -namespace c4 { -namespace yml { - - -// To see the test case contents, refer to this URL: -// https://github.com/yaml/yaml-test-suite/tree/master/src -constexpr const AllowedFailure allowed_failures[] = { - - // g++-5 does not like creating a csubstr directly from the literal. - // so we use this macro to remove cruft from the code: - #define _(testcase, reason) AllowedFailure{csubstr(testcase), csubstr(reason)} - - //------------------------------------------------------------------------- - // SECTION 1. Known issues, TODO - // - // These tests are temporarily skipped, and cover issues that must be fixed. - - // double quoted scalars - _("G4RS-in_json" , "special characters must be emitted in double quoted style"), - _("G4RS-in_yaml" , "special characters must be emitted in double quoted style"), - _("G4RS-out_yaml" , "special characters must be emitted in double quoted style"), - // other - _("UKK6_01-in_yaml" , "fails to parse double :: in UNK state"), - - - //------------------------------------------------------------------------- - // SECTION 2. Expected errors that fail to materialize. - - // maps - _("236B-error" , "should not accept final scalar in a map"), - _("7MNF-error" , "should not accept final scalar in a map"), - _("62EZ-error" , "should not accept invalid block mapping key on same line as previous key"), - _("9CWY-error" , "should not accept final scalar in a map"), - _("CXX2-error" , "should not accept mapping with anchor on document start line"), - _("DK95_06-error" , "should not accept tab indentation"), - _("GDY7-error" , "should not accept comment that looks like a mapping key"), - _("D49Q-error" , "should not accept multiline single quoted implicit keys"), - _("DK4H-error" , "should not accept implicit key followed by newline"), - _("JY7Z-error" , "should not accept trailing content that looks like a mapping"), - _("SU74-error" , "should not accept anchor and alias as mapping key"), - _("T833-error" , "should not accept flow mapping missing a separating comma"), - _("VJP3_00-error" , "should not accept flow collections over many lines"), - _("Y79Y_006-error", "should not accept tab after ?"), - _("Y79Y_007-error", "should not accept tab after :"), - _("Y79Y_008-error", "should not accept tab after ?"), - _("Y79Y_009-error", "should not accept tab after ?"), - _("ZCZ6-error" , "should not accept invalid mapping in plain single line value"), - // seqs - _("5U3A-error" , "should not accept opening a sequence on same line as map key"), - _("6JTT-error" , "should not accept flow sequence without terminating ]"), - _("9C9N-error" , "should not accept non-indented flow sequence"), - _("9JBA-error" , "should not accept comment after flow seq terminating ]"), - _("9MAG-error" , "should not accept flow sequence with invalid comma at the beginning"), - _("CTN5-error" , "should not accept flow sequence with missing elements"), - _("CVW2-error" , "should not accept flow sequence with comment after ,"), - _("G5U8-error" , "should not accept [-, -]"), - _("KS4U-error" , "should not accept item after end of flow sequence"), - _("P2EQ-error" , "should not accept sequence item on same line as previous item"), - _("YJV2-error" , "should not accept [-]"), - _("Y79Y_003-error", "should not accept leading tabs in seq elmt"), - _("Y79Y_004-error", "should not accept tab after -"), - _("Y79Y_005-error", "should not accept tab after -"), - // block scalars - _("2G84_00-error" , "should not accept the block literal spec"), - _("2G84_01-error" , "should not accept the block literal spec"), - _("5LLU-error" , "should not accept folded scalar with wrong indented line after spaces only"), - _("S4GJ-error" , "should not accept text after block scalar indicator"), - _("S98Z-error" , "should not accept block scalar with more spaces than first content line"), - _("X4QW-error" , "should not accept comment without whitespace after block scalar indicator"), - _("Y79Y_000-error", "should not accept leading tabs in the block scalar"), - // quoted scalars - _("55WF-error" , "should not accept invalid escape in double quoted scalar"), - _("7LBH-error" , "should not accept multiline double quoted implicit keys"), - _("DK95_01-error", "should not accept leading tabs in double quoted multiline scalar"), - _("HRE5-error" , "should not accept double quoted scalar with escaped single quote"), - _("JKF3-error" , "should not accept multiline unindented double quoted scalar"), - _("QB6E-error" , "should not accept indented multiline quoted scalar"), - _("RXY3-error" , "should not accept document-end marker in single quoted string"), - _("SU5Z-error" , "should not accept comment without whitespace after double quoted scalar"), - // plain scalars - _("8XDJ-error" , "should not accept comment in multiline scalar"), - _("CML9-error" , "should not accept comment inside flow scalar"), - // documents/streams - _("3HFZ-error" , "should not accept scalar after ..."), - _("5TRB-error" , "should not accept document-end marker in double quoted string"), - _("9MMA-error" , "should not accept empty doc after %YAML directive"), - _("9MQT_01-error", "should not accept scalars after ..."), - _("B63P-error" , "should not accept directive without doc"), - _("EB22-error" , "should not accept missing document-end marker before directive"), - _("H7TQ-error" , "should not accept extra words after directive"), - _("MUS6_00-error", "should not accept #... at the end of %YAML directive"), - _("MUS6_01-error", "should not accept #... at the end of %YAML directive"), - _("N782-error" , "should not accept document markers in flow style"), - _("RHX7-error" , "should not accept directive without document end marker"), - _("SF5V-error" , "should not accept duplicate YAML directive"), - // anchors - _("4EJS-error" , "should not accept double anchor for scalar"), - _("4JVG-error" , "should not accept double anchor for scalar"), - _("SY6V-error" , "should not accept anchor before sequence entry on same line"), - // tags - _("9HCY-error" , "should not accept tag directive in non-doc scope"), - _("BU8L-error" , "should not accept node properties spread over multiple lines"), - _("LHL4-error" , "should not accept tag"), - _("U99R-error" , "should not accept comma in a tag"), - _("QLJ7-error" , "tag directives should apply only to the next doc (?)"), - - - //------------------------------------------------------------------------- - // SECTION 3. Deliberate ryml limitations. - // - // These tests are skipped because they cover parts of YAML that - // are deliberately not implemented by ryml. - - #ifndef RYML_WITH_TAB_TOKENS // -<tab> or :<tab> are supported only when the above macro is defined - _("A2M4-in_yaml-events" , "tabs tokens"), - _("6BCT-in_yaml" , "tabs tokens"), - _("J3BT-in_yaml-events" , "tabs tokens"), - _("Y79Y_010-in_yaml-events", "tabs tokens"), - #endif - // container keys are not supported - _("4FJ6-in_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("4FJ6-out_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("6BFJ-in_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("6BFJ-out_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("6PBE-in_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("6PBE-out_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("6PBE-emit_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("9MMW-in_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("9MMW-out_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("KK5P-in_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("KK5P-out_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("KZN9-in_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("KZN9-out_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("LX3P-in_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("LX3P-out_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("M2N8_00-in_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("M2N8_00-out_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("M2N8_01-in_yaml-events" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("M2N8_01-out_yaml-events", "only scalar keys allowed (keys cannot be maps or seqs)"), - _("M5DY-in_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("M5DY-out_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("Q9WF-in_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("Q9WF-out_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("RZP5-in_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("RZP5-out_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("SBG9-in_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("SBG9-out_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("V9D5-in_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("V9D5-out_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("X38W-in_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("X38W-out_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("XW4D-in_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - _("XW4D-out_yaml" , "only scalar keys allowed (keys cannot be maps or seqs)"), - // anchors with : are not supported - _("2SXE-in_yaml-events" , "weird characters in anchors, anchors must not end with :"), - // malformed json in the test spec - _("35KP-in_json" , "malformed JSON from multiple documents"), - _("5TYM-in_json" , "malformed JSON from multiple documents"), - _("6XDY-in_json" , "malformed JSON from multiple documents"), - _("6WLZ-in_json" , "malformed JSON from multiple documents"), - _("6ZKB-in_json" , "malformed JSON from multiple documents"), - _("7Z25-in_json" , "malformed JSON from multiple documents"), - _("9DXL-in_json" , "malformed JSON from multiple documents"), - _("9KAX-in_json" , "malformed JSON from multiple documents"), - _("9WXW-in_json" , "malformed JSON from multiple documents"), - _("JHB9-in_json" , "malformed JSON from multiple documents"), - _("KSS4-in_json" , "malformed JSON from multiple documents"), - _("L383-in_json" , "malformed JSON from multiple documents"), - _("M7A3-in_json" , "malformed JSON from multiple documents"), - _("RZT7-in_json" , "malformed JSON from multiple documents"), - _("U9NS-in_json" , "malformed JSON from multiple documents"), - _("W4TN-in_json" , "malformed JSON from multiple documents"), - // malformed test spec? - _("4ABK-out_yaml-events" , "out-yaml contains null, while in-yaml and events contain empty scalars"), - _("4WA9-out_yaml-events" , "out-yaml test spec is missing a --- document token, which is required in the events"), - _("652Z-out_yaml-events" , "out-yaml test spec is missing a --- document token, which is required in the events"), - _("6CA3-emit_yaml" , "out-yaml test spec is missing a --- document token, which is required in the events"), - _("6FWR-out_yaml-events" , "out-yaml test spec is missing a --- document token, which is required in the events"), - _("6WPF-out_yaml-events" , "out-yaml test spec is missing a --- document token, which is required in the events"), - _("9TFX-out_yaml-events" , "out-yaml test spec is missing a --- document token, which is required in the events"), - _("B3HG-out_yaml-events" , "out-yaml test spec is missing a --- document token, which is required in the events"), - _("DK95_00-emit_yaml-events", "out-yaml test spec is missing a --- document token, which is required in the events"), - _("DK95_02-emit_yaml-events", "out-yaml test spec is missing a --- document token, which is required in the events"), - _("DK95_03-emit_yaml-events", "out-yaml test spec is missing a --- document token, which is required in the events"), - _("DK95_04-emit_yaml-events", "out-yaml test spec is missing a --- document token, which is required in the events"), - _("DK95_05-emit_yaml-events", "out-yaml test spec is missing a --- document token, which is required in the events"), - _("DK95_06-emit_yaml-events", "out-yaml test spec is missing a --- document token, which is required in the events"), - _("DK95_07-emit_yaml-events", "out-yaml test spec is missing a --- document token, which is required in the events"), - _("DK95_08-emit_yaml-events", "out-yaml test spec is missing a --- document token, which is required in the events"), - _("EX5H-out_yaml-events" , "out-yaml test spec is missing a --- document token, which is required in the events"), - _("EXG3-out_yaml-events" , "out-yaml test spec is missing a --- document token, which is required in the events"), - _("L24T_00-emit_yaml-events", "out-yaml test spec is missing a --- document token, which is required in the events"), - _("L24T_01-emit_yaml-events", "out-yaml test spec is missing a --- document token, which is required in the events"), - _("M6YH-out_yaml-events" , "out-yaml test spec is missing a --- document token, which is required in the events"), - _("Q8AD-out_yaml-events" , "out-yaml test spec is missing a --- document token, which is required in the events"), - _("T26H-out_yaml-events" , "out-yaml test spec is missing a --- document token, which is required in the events"), - _("T4YY-out_yaml-events" , "out-yaml test spec is missing a --- document token, which is required in the events"), - _("T5N4-out_yaml-events" , "out-yaml test spec is missing a --- document token, which is required in the events"), - _("VJP3_01-out_yaml-events" , "out-yaml test spec is missing a --- document token, which is required in the events"), - - #undef _ -}; - - -cspan<AllowedFailure> g_allowed_failures = allowed_failures; - -AllowedFailure is_failure_expected(csubstr casename) -{ - RYML_CHECK(casename.not_empty()); - for(AllowedFailure const& af : g_allowed_failures) - if(af.test_name == casename || casename.begins_with(af.test_name)) - return af; - return {}; -} - - -} // namespace c4 -} // namespace yml diff --git a/thirdparty/ryml/test/test_suite/test_suite_parts.hpp b/thirdparty/ryml/test/test_suite/test_suite_parts.hpp deleted file mode 100644 index 9092313ba..000000000 --- a/thirdparty/ryml/test/test_suite/test_suite_parts.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef C4_YML_TEST_SUITE_PARTS_HPP_ -#define C4_YML_TEST_SUITE_PARTS_HPP_ - -#ifdef RYML_SINGLE_HEADER -#include <ryml_all.hpp> -#else -#include <c4/yml/common.hpp> -#include <c4/span.hpp> -#endif -#include <c4/log/log.hpp> - -namespace c4 { -namespace yml { - -struct AllowedFailure -{ - csubstr test_name; - csubstr reason; - operator bool() const { return !test_name.empty(); } -}; - -AllowedFailure is_failure_expected(csubstr casename); - -} // namespace c4 -} // namespace yml - - -#endif /* C4_YML_TEST_SUITE_PARTS_HPP_ */ |