#include "./test_lib/test_engine.hpp"

// WARNING: don't use raw string literals -- g++4.8 cannot accept them
// as macro arguments

RYML_DEFINE_TEST_MAIN()

namespace c4 {
namespace yml {


//static constexpr const bool multiline = true;
static constexpr const bool singleline = false;


//-----------------------------------------------------------------------------

ENGINE_TEST(SeqIMap0Ref,
            "[val0,val1,{key: val2},wtf]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "=VAL :val0\n"
            "=VAL :val1\n"
            "+MAP {}\n"
            "=VAL :key\n"
            "=VAL :val2\n"
            "-MAP\n"
            "=VAL :wtf\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.set_val_scalar_plain("val0"));
    ___(ps.add_sibling());
    ___(ps.set_val_scalar_plain("val1"));
    ___(ps.add_sibling());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_scalar_plain("key"));
    ___(ps.set_val_scalar_plain("val2"));
    ___(ps.end_map_flow(singleline));
    ___(ps.add_sibling());
    ___(ps.set_val_scalar_plain("wtf"));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap1,
            "[val0,val1,key: val2,wtf]"
            ,
            "[val0,val1,{key: val2},wtf]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "=VAL :val0\n"
            "=VAL :val1\n"
            "+MAP {}\n"
            "=VAL :key\n"
            "=VAL :val2\n"
            "-MAP\n"
            "=VAL :wtf\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.set_val_scalar_plain("val0"));
    ___(ps.add_sibling());
    ___(ps.set_val_scalar_plain("val1"));
    ___(ps.add_sibling());
        // first this is read as a val because the parent is read as a
        // seq...
    ___(ps.set_val_scalar_plain("key"));
        // ... then this will create a flow map, and move the existing
        // val to the key of the first child
    ___(ps.actually_val_is_first_key_of_new_map_flow());
    ___(ps.set_val_scalar_plain("val2"));
    ___(ps.end_map_flow(singleline));
    ___(ps.add_sibling());
    ___(ps.set_val_scalar_plain("wtf"));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap2,
            "[val0,val1,key: [foo: bar],wtf]"
            ,
            "[val0,val1,{key: [{foo: bar}]},wtf]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "=VAL :val0\n"
            "=VAL :val1\n"
            "+MAP {}\n"
            "=VAL :key\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :foo\n"
            "=VAL :bar\n"
            "-MAP\n"
            "-SEQ\n"
            "-MAP\n"
            "=VAL :wtf\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
      ___(ps.set_val_scalar_plain("val0"));
      ___(ps.add_sibling());
      ___(ps.set_val_scalar_plain("val1"));
      ___(ps.add_sibling());
      ___(ps.set_val_scalar_plain("key"));
      ___(ps.actually_val_is_first_key_of_new_map_flow());
        ___(ps.begin_seq_val_flow());
        ___(ps.set_val_scalar_plain("foo"));
        ___(ps.actually_val_is_first_key_of_new_map_flow());
        ___(ps.set_val_scalar_plain("bar"));
        ___(ps.end_map_flow(singleline));
        ___(ps.end_seq_flow(singleline));
      ___(ps.end_map_flow(singleline));
      ___(ps.add_sibling());
      ___(ps.set_val_scalar_plain("wtf"));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}


ENGINE_TEST(SeqIMap2Nested,
            "[val: [0: [1: [2: [3: [4: [5: [6: 7]]]]]]], :]"
            ,
            "[{val: [{0: [{1: [{2: [{3: [{4: [{5: [{6: 7}]}]}]}]}]}]}]},{: }]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :val\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :0\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :1\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :2\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :3\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :4\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :5\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :6\n"
            "=VAL :7\n"
            "-MAP\n"
            "-SEQ\n"
            "-MAP\n"
            "-SEQ\n"
            "-MAP\n"
            "-SEQ\n"
            "-MAP\n"
            "-SEQ\n"
            "-MAP\n"
            "-SEQ\n"
            "-MAP\n"
            "-SEQ\n"
            "-MAP\n"
            "-SEQ\n"
            "-MAP\n"
            "+MAP {}\n"
            "=VAL :\n"
            "=VAL :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
      ___(ps.begin_seq_val_flow());
        ___(ps.set_val_scalar_plain("val"));
        ___(ps.actually_val_is_first_key_of_new_map_flow());
          ___(ps.begin_seq_val_flow());
            ___(ps.set_val_scalar_plain("0"));
            ___(ps.actually_val_is_first_key_of_new_map_flow());
              ___(ps.begin_seq_val_flow());
                ___(ps.set_val_scalar_plain("1"));
                ___(ps.actually_val_is_first_key_of_new_map_flow());
                  ___(ps.begin_seq_val_flow());
                    ___(ps.set_val_scalar_plain("2"));
                    ___(ps.actually_val_is_first_key_of_new_map_flow());
                      ___(ps.begin_seq_val_flow());
                        ___(ps.set_val_scalar_plain("3"));
                        ___(ps.actually_val_is_first_key_of_new_map_flow());
                          ___(ps.begin_seq_val_flow());
                            ___(ps.set_val_scalar_plain("4"));
                            ___(ps.actually_val_is_first_key_of_new_map_flow());
                              ___(ps.begin_seq_val_flow());
                                ___(ps.set_val_scalar_plain("5"));
                                ___(ps.actually_val_is_first_key_of_new_map_flow());
                                  ___(ps.begin_seq_val_flow());
                                    ___(ps.set_val_scalar_plain("6"));
                                    ___(ps.actually_val_is_first_key_of_new_map_flow());
                                      ___(ps.set_val_scalar_plain("7"));
                                    ___(ps.end_map_flow(singleline));
                                  ___(ps.end_seq_flow(singleline));
                                ___(ps.end_map_flow(singleline));
                              ___(ps.end_seq_flow(singleline));
                            ___(ps.end_map_flow(singleline));
                          ___(ps.end_seq_flow(singleline));
                        ___(ps.end_map_flow(singleline));
                      ___(ps.end_seq_flow(singleline));
                    ___(ps.end_map_flow(singleline));
                  ___(ps.end_seq_flow(singleline));
                ___(ps.end_map_flow(singleline));
              ___(ps.end_seq_flow(singleline));
            ___(ps.end_map_flow(singleline));
          ___(ps.end_seq_flow(singleline));
        ___(ps.end_map_flow(singleline));
        ___(ps.add_sibling());
        ___(ps.set_val_scalar_plain_empty());
        ___(ps.actually_val_is_first_key_of_new_map_flow());
          ___(ps.set_val_scalar_plain_empty());
        ___(ps.end_map_flow(singleline));
      ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}


ENGINE_TEST(SeqIMap3EmptyKey,
            "[val0, : wtf]"
            ,
            "[val0,{: wtf}]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "=VAL :val0\n"
            "+MAP {}\n"
            "=VAL :\n"
            "=VAL :wtf\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.set_val_scalar_plain("val0"));
    ___(ps.add_sibling());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.actually_val_is_first_key_of_new_map_flow());
    ___(ps.set_val_scalar_plain("wtf"));
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap3EmptyVal,
            "[val0, wtf: ]"
            ,
            "[val0,{wtf: }]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "=VAL :val0\n"
            "+MAP {}\n"
            "=VAL :wtf\n"
            "=VAL :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.set_val_scalar_plain("val0"));
    ___(ps.add_sibling());
    ___(ps.set_val_scalar_plain("wtf"));
    ___(ps.actually_val_is_first_key_of_new_map_flow());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap3EmptyKeyVal,
            "[val0, : ]"
            ,
            "[val0,{: }]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "=VAL :val0\n"
            "+MAP {}\n"
            "=VAL :\n"
            "=VAL :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.set_val_scalar_plain("val0"));
    ___(ps.add_sibling());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.actually_val_is_first_key_of_new_map_flow());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap3EmptyKeyValNested,
            "[val0: val1, : ]"
            ,
            "[{val0: val1},{: }]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :val0\n"
            "=VAL :val1\n"
            "-MAP\n"
            "+MAP {}\n"
            "=VAL :\n"
            "=VAL :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.set_val_scalar_plain("val0"));
    ___(ps.actually_val_is_first_key_of_new_map_flow());
    ___(ps.set_val_scalar_plain("val1"));
    ___(ps.end_map_flow(singleline));
    ___(ps.add_sibling());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.actually_val_is_first_key_of_new_map_flow());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap3EmptyKeyValNested2,
            "[val0: [val1: val2], : ]"
            ,
            "[{val0: [{val1: val2}]},{: }]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :val0\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :val1\n"
            "=VAL :val2\n"
            "-MAP\n"
            "-SEQ\n"
            "-MAP\n"
            "+MAP {}\n"
            "=VAL :\n"
            "=VAL :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.set_val_scalar_plain("val0"));
    ___(ps.actually_val_is_first_key_of_new_map_flow());
    ___(ps.begin_seq_val_flow());
    ___(ps.set_val_scalar_plain("val1"));
    ___(ps.actually_val_is_first_key_of_new_map_flow());
    ___(ps.set_val_scalar_plain("val2"));
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_map_flow(singleline));
    ___(ps.add_sibling());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.actually_val_is_first_key_of_new_map_flow());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap4Ref,
            "[val0,val1,[rat,rot],wtf]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "=VAL :val0\n"
            "=VAL :val1\n"
            "+SEQ []\n"
            "=VAL :rat\n"
            "=VAL :rot\n"
            "-SEQ\n"
            "=VAL :wtf\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.set_val_scalar_plain("val0"));
    ___(ps.add_sibling());
    ___(ps.set_val_scalar_plain("val1"));
    ___(ps.add_sibling());
    ___(ps.begin_seq_val_flow());
    ___(ps.set_val_scalar_plain("rat"));
    ___(ps.add_sibling());
    ___(ps.set_val_scalar_plain("rot"));
    ___(ps.end_seq_flow(singleline));
    ___(ps.add_sibling());
    ___(ps.set_val_scalar_plain("wtf"));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap4,
            HAS_CONTAINER_KEYS, Location(20,1,21)
            ,
            "[val0,val1,[rat,rot]: [foo: bar],wtf]"
            ,
            "[val0,val1,{[rat,rot]: [{foo: bar}]},wtf]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "=VAL :val0\n"
            "=VAL :val1\n"
            "+MAP {}\n"
            "+SEQ []\n"
            "=VAL :rat\n"
            "=VAL :rot\n"
            "-SEQ\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :foo\n"
            "=VAL :bar\n"
            "-MAP\n"
            "-SEQ\n"
            "-MAP\n"
            "=VAL :wtf\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.set_val_scalar_plain("val0"));
    ___(ps.add_sibling());
    ___(ps.set_val_scalar_plain("val1"));
    ___(ps.add_sibling());
    ___(ps.begin_map_val_flow());
      ___(ps.begin_seq_key_flow());
      ___(ps.set_val_scalar_plain("rat"));
      ___(ps.add_sibling());
      ___(ps.set_val_scalar_plain("rot"));
      ___(ps.end_seq_flow(singleline));
      ___(ps.begin_seq_val_flow());
        ___(ps.begin_map_val_flow());
          ___(ps.set_key_scalar_plain("foo"));
          ___(ps.set_val_scalar_plain("bar"));
        ___(ps.end_map_flow(singleline));
      ___(ps.end_seq_flow(singleline));
    ___(ps.end_map_flow(singleline));
    ___(ps.add_sibling());
    ___(ps.set_val_scalar_plain("wtf"));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap4_actually,
            HAS_CONTAINER_KEYS, Location(20,1,21),
            "[val0,val1,[rat,rot]: [foo: bar],wtf]"
            ,
            "[val0,val1,{[rat,rot]: [{foo: bar}]},wtf]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "=VAL :val0\n"
            "=VAL :val1\n"
            "+MAP {}\n"
            "+SEQ []\n"
            "=VAL :rat\n"
            "=VAL :rot\n"
            "-SEQ\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :foo\n"
            "=VAL :bar\n"
            "-MAP\n"
            "-SEQ\n"
            "-MAP\n"
            "=VAL :wtf\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
       ___(ps.set_val_scalar_plain("val0"));
       ___(ps.add_sibling());
       ___(ps.set_val_scalar_plain("val1"));
       ___(ps.add_sibling());
       ___(ps.begin_seq_val_flow());
           ___(ps.set_val_scalar_plain("rat"));
           ___(ps.add_sibling());
           ___(ps.set_val_scalar_plain("rot"));
       ___(ps.end_seq_flow(singleline));
       ___(ps.actually_val_is_first_key_of_new_map_flow());
           ___(ps.begin_seq_val_flow());
               ___(ps.set_val_scalar_plain("foo"));
               ___(ps.actually_val_is_first_key_of_new_map_flow());
                   ___(ps.set_val_scalar_plain("bar"));
               ___(ps.end_map_flow(singleline));
           ___(ps.end_seq_flow(singleline));
       ___(ps.end_map_flow(singleline));
       ___(ps.add_sibling());
       ___(ps.set_val_scalar_plain("wtf"));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}


//-----------------------------------------------------------------------------

ENGINE_TEST(SeqIMap5Squo,
            "[a: &anchor 'b']"
            ,
            "[{a: &anchor 'b'}]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :a\n"
            "=VAL &anchor 'b\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_scalar_plain("a"));
    ___(ps.set_val_anchor("anchor"));
    ___(ps.set_val_scalar_squoted("b"));
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap5Dquo,
            "[a: &anchor \"b\"]"
            ,
            "[{a: &anchor \"b\"}]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :a\n"
            "=VAL &anchor \"b\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_scalar_plain("a"));
    ___(ps.set_val_anchor("anchor"));
    ___(ps.set_val_scalar_dquoted("b"));
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap5Ref,
            "[a: *ref]"
            ,
            "[{a: *ref}]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :a\n"
            "=ALI *ref\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_scalar_plain("a"));
    ___(ps.set_val_ref("*ref"));
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap5QmrkNone0,
            "[? ,]"
            ,
            "[{: }]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :\n"
            "=VAL :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap5QmrkNone1,
            "[? ]"
            ,
            "[{: }]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :\n"
            "=VAL :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap5QmrkSquo1,
            "[? &anchor 'squo' ]"
            ,
            "[{&anchor 'squo': }]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL &anchor 'squo\n"
            "=VAL :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_anchor("anchor"));
    ___(ps.set_key_scalar_squoted("squo"));
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap5QmrkDquo1,
            "[? &anchor \"dquo\" ]"
            ,
            "[{&anchor \"dquo\": }]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL &anchor \"dquo\n"
            "=VAL :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_anchor("anchor"));
    ___(ps.set_key_scalar_dquoted("dquo"));
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap5QmrkRef1,
            "[? a: *ref]"
            ,
            "[{a: *ref}]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :a\n"
            "=ALI *ref\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_scalar_plain("a"));
    ___(ps.set_val_ref("*ref"));
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap5QmrkRef2,
            "[? *ref : b]"
            ,
            "[{*ref : b}]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=ALI *ref\n"
            "=VAL :b\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_ref("*ref"));
    ___(ps.set_val_scalar_plain("b"));
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}
ENGINE_TEST(SeqIMap5QmrkRef2_1,
            "[? *ref: : b]"
            ,
            "[{*ref: : b}]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=ALI *ref:\n"
            "=VAL :b\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_ref("*ref:"));
    ___(ps.set_val_scalar_plain("b"));
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap5QmrkSeq,
            HAS_CONTAINER_KEYS,
            "[? &anchor [a, seq]: ]"
            ,
            "[{&anchor [a, seq]: }]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "+SEQ [] &anchor\n"
            "=VAL :a\n"
            "=VAL :seq\n"
            "-SEQ\n"
            "=VAL :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.set_key_tag("!tag"));
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_anchor("anchor"));
    ___(ps.begin_seq_key_flow());
    ___(ps.set_val_scalar_plain("a"));
    ___(ps.set_val_scalar_plain("seq"));
    ___(ps.end_seq_flow(singleline));
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(SeqIMap5QmrkMap,
            HAS_CONTAINER_KEYS,
            "[? &anchor {a: map}: ]"
            ,
            "[{&anchor {a: map}: }]"
            ,
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "+MAP {} &anchor\n"
            "=VAL :a\n"
            "=VAL :map\n"
            "-MAP\n"
            "=VAL :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.set_key_tag("!tag"));
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_anchor("anchor"));
    ___(ps.begin_map_key_flow());
    ___(ps.set_key_scalar_plain("a"));
    ___(ps.set_val_scalar_plain("map"));
    ___(ps.end_map_flow(singleline));
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

//-----------------------------------------------------------------------------

ENGINE_TEST_ERRLOC(SeqIMapColonNextLineAfterPlain0, Location(2,3),
                   "[ key"       "\n"
                   "  : value ]"       "\n")
ENGINE_TEST_ERRLOC(SeqIMapColonNextLineAfterPlain1, Location(2,3),
                   "[ key  "       "\n"
                   "  : value ]"       "\n")
ENGINE_TEST_ERRLOC(SeqIMapColonNextLineAfterPlain2, Location(2,3),
                   "[ key # comment"   "\n"
                   "  : value ]"       "\n")

ENGINE_TEST_ERRLOC(SeqIMapColonNextLineAfterSquo0, Location(2,3),
                   "[ 'key'"       "\n"
                   "  : value ]"       "\n")
ENGINE_TEST_ERRLOC(SeqIMapColonNextLineAfterSquo1, Location(2,3),
                   "[ 'key'  "       "\n"
                   "  : value ]"       "\n")
ENGINE_TEST_ERRLOC(SeqIMapColonNextLineAfterSquo2, Location(2,3),
                   "[ 'key' # comment"   "\n"
                   "  : value ]"       "\n")

ENGINE_TEST_ERRLOC(SeqIMapColonNextLineAfterDquo0, Location(2,3),
                   "[ \"key\""       "\n"
                   "  : value ]"       "\n")
ENGINE_TEST_ERRLOC(SeqIMapColonNextLineAfterDquo1, Location(2,3),
                   "[ \"key\"  "       "\n"
                   "  : value ]"       "\n")
ENGINE_TEST_ERRLOC(SeqIMapColonNextLineAfterDquo2, Location(2,3),
                   "[ \"key\" # comment"   "\n"
                   "  : value ]"       "\n")

ENGINE_TEST_ERRLOC_(SeqIMapColonNextLineAfterSeq0, HAS_CONTAINER_KEYS,
                    Location(2,3),
                   "[ [seq]"   "\n"
                   "  : value ]"       "\n")
ENGINE_TEST_ERRLOC_(SeqIMapColonNextLineAfterSeq1, HAS_CONTAINER_KEYS,
                    Location(2,3),
                   "[ [seq]  "   "\n"
                   "  : value ]"       "\n")
ENGINE_TEST_ERRLOC_(SeqIMapColonNextLineAfterSeq2, HAS_CONTAINER_KEYS,
                    Location(2,3),
                   "[ [seq] # comment"   "\n"
                   "  : value ]"       "\n")

ENGINE_TEST_ERRLOC_(SeqIMapColonNextLineAfterMap0, HAS_CONTAINER_KEYS,
                    Location(2,3),
                   "[ {map: yes}"   "\n"
                   "  : value ]"       "\n")
ENGINE_TEST_ERRLOC_(SeqIMapColonNextLineAfterMap1, HAS_CONTAINER_KEYS,
                    Location(2,3),
                   "[ {map: yes}  "   "\n"
                   "  : value ]"       "\n")
ENGINE_TEST_ERRLOC_(SeqIMapColonNextLineAfterMap2, HAS_CONTAINER_KEYS,
                    Location(2,3),
                   "[ {map: yes} # comment"   "\n"
                   "  : value ]"       "\n")


//-----------------------------------------------------------------------------

ENGINE_TEST(TagPlacementTerminatingColonFlow3SeqK,
            "[!tag30: :,!tag31: :]\n"
            ,
            "[{!tag30: : },{!tag31: : }]"
            ,
            ""
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL <!tag30:> :\n"
            "=VAL :\n"
            "-MAP\n"
            "+MAP {}\n"
            "=VAL <!tag31:> :\n"
            "=VAL :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_tag("!tag30:"));
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.add_sibling());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_tag("!tag31:"));
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(TagPlacementTerminatingColonFlow3SeqK1,
            "[&anch30: !tag30: :,&anch31: !tag31: :]\n"
            ,
            "[{&anch30: !tag30: : },{&anch31: !tag31: : }]"
            ,
            ""
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL &anch30: <!tag30:> :\n"
            "=VAL :\n"
            "-MAP\n"
            "+MAP {}\n"
            "=VAL &anch31: <!tag31:> :\n"
            "=VAL :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_anchor("anch30:"));
    ___(ps.set_key_tag("!tag30:"));
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.add_sibling());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_anchor("anch31:"));
    ___(ps.set_key_tag("!tag31:"));
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(TagPlacementTerminatingColonFlow3SeqK2,
            "[!tag30: &anch30: :,!tag31: &anch31: :]\n"
            ,
            "[{&anch30: !tag30: : },{&anch31: !tag31: : }]"
            ,
            ""
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL &anch30: <!tag30:> :\n"
            "=VAL :\n"
            "-MAP\n"
            "+MAP {}\n"
            "=VAL &anch31: <!tag31:> :\n"
            "=VAL :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_anchor("anch30:"));
    ___(ps.set_key_tag("!tag30:"));
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.add_sibling());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_anchor("anch31:"));
    ___(ps.set_key_tag("!tag31:"));
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(TagPlacementTerminatingColonFlow3SeqK3,
            "[&anch30: :,&anch31: :]\n"
            ,
            "[{&anch30: : },{&anch31: : }]"
            ,
            ""
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL &anch30: :\n"
            "=VAL :\n"
            "-MAP\n"
            "+MAP {}\n"
            "=VAL &anch31: :\n"
            "=VAL :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_anchor("anch30:"));
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.add_sibling());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_anchor("anch31:"));
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(TagPlacementTerminatingColonFlow5SeqV1,
            "[: !tag50:,: !tag51:]"
            ,
            "[{: !tag50: },{: !tag51: }]"
            ,
            ""
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :\n"
            "=VAL <!tag50:> :\n"
            "-MAP\n"
            "+MAP {}\n"
            "=VAL :\n"
            "=VAL <!tag51:> :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_tag("!tag50:"));
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.add_sibling());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_tag("!tag51:"));
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(TagPlacementTerminatingColonFlow5SeqV2,
            "[: &anch50: !tag50:,: &anch51: !tag51:]"
            ,
            "[{: &anch50: !tag50: },{: &anch51: !tag51: }]"
            ,
            ""
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :\n"
            "=VAL &anch50: <!tag50:> :\n"
            "-MAP\n"
            "+MAP {}\n"
            "=VAL :\n"
            "=VAL &anch51: <!tag51:> :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_anchor("anch50:"));
    ___(ps.set_val_tag("!tag50:"));
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.add_sibling());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_anchor("anch51:"));
    ___(ps.set_val_tag("!tag51:"));
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(TagPlacementTerminatingColonFlow5SeqV3,
            "[: !tag50: &anch50:,: !tag51: &anch51:]"
            ,
            "[{: &anch50: !tag50: },{: &anch51: !tag51: }]"
            ,
            ""
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :\n"
            "=VAL &anch50: <!tag50:> :\n"
            "-MAP\n"
            "+MAP {}\n"
            "=VAL :\n"
            "=VAL &anch51: <!tag51:> :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_anchor("anch50:"));
    ___(ps.set_val_tag("!tag50:"));
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.add_sibling());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_anchor("anch51:"));
    ___(ps.set_val_tag("!tag51:"));
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

ENGINE_TEST(TagPlacementTerminatingColonFlow5SeqV4,
            "[: &anch50:,: &anch51:]"
            ,
            "[{: &anch50: },{: &anch51: }]"
            ,
            ""
            "+STR\n"
            "+DOC\n"
            "+SEQ []\n"
            "+MAP {}\n"
            "=VAL :\n"
            "=VAL &anch50: :\n"
            "-MAP\n"
            "+MAP {}\n"
            "=VAL :\n"
            "=VAL &anch51: :\n"
            "-MAP\n"
            "-SEQ\n"
            "-DOC\n"
            "-STR\n")
{
    ___(ps.begin_stream());
    ___(ps.begin_doc());
    ___(ps.begin_seq_val_flow());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_anchor("anch50:"));
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.add_sibling());
    ___(ps.begin_map_val_flow());
    ___(ps.set_key_scalar_plain_empty());
    ___(ps.set_val_anchor("anch51:"));
    ___(ps.set_val_scalar_plain_empty());
    ___(ps.end_map_flow(singleline));
    ___(ps.end_seq_flow(singleline));
    ___(ps.end_doc());
    ___(ps.end_stream());
}

} // namespace yml
} // namespace c4


//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

// this is needed to use the test case library

#ifndef RYML_SINGLE_HEADER
#include "c4/substr.hpp"
#endif

namespace c4 {
namespace yml {
struct Case;
Case const* get_case(csubstr /*name*/)
{
    return nullptr;
}
} // namespace yml
} // namespace c4
