Commit 3ddfeff4 authored by Jesse Beder's avatar Jesse Beder
Browse files

Added seq gen emitter tests

parent fdfffb09
...@@ -52,8 +52,31 @@ def scalar(value, tag='', anchor='', anchor_id=0): ...@@ -52,8 +52,31 @@ def scalar(value, tag='', anchor='', anchor_id=0):
def comment(value): def comment(value):
return {'emit': 'YAML::Comment("%s")' % value, 'handle': ''} return {'emit': 'YAML::Comment("%s")' % value, 'handle': ''}
def seq_start(tag='', anchor='', anchor_id=0):
emit = []
if tag:
emit += ['YAML::VerbatimTag("%s")' % encode(tag)]
if anchor:
emit += ['YAML::Anchor("%s")' % encode(anchor)]
if tag:
out_tag = encode(tag)
else:
out_tag = '?'
emit += ['YAML::BeginSeq']
return {'emit': emit, 'handle': 'SEQ_START("%s", %s)' % (out_tag, anchor_id)}
def seq_end():
return {'emit': 'YAML::EndSeq', 'handle': 'SEQ_END()'}
def gen_templates(): def gen_templates():
yield [[doc_start(), doc_start(True)], [scalar('foo'), scalar('foo\n')], [doc_end(), doc_end(True)]] yield [[doc_start(), doc_start(True)],
[scalar('foo'), scalar('foo\n'), scalar('foo', 'tag'), scalar('foo', '', 'anchor', 1)],
[doc_end(), doc_end(True)]]
yield [[doc_start(), doc_start(True)],
[seq_start()],
[[], [scalar('foo')], [scalar('foo', 'tag')], [scalar('foo', '', 'anchor', 1)], [scalar('foo', 'tag', 'anchor', 1)], [scalar('foo'), scalar('bar')], [scalar('foo', 'tag', 'anchor', 1), scalar('bar', 'tag', 'other', 2)]],
[seq_end()],
[doc_end(), doc_end(True)]]
def expand(template): def expand(template):
if len(template) == 0: if len(template) == 0:
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment