mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 04:41:16 +00:00
Updated emitter test script, and moved handler macros to own include file
This commit is contained in:
@@ -5,13 +5,52 @@ import hashlib
|
||||
NS = 'Emitter'
|
||||
EVENT_COUNT = 5
|
||||
|
||||
EVENTS = [
|
||||
{'emit': 'YAML::DocStart', 'handle': 'DOC_START()'},
|
||||
{'emit': 'YAML::DocEnd', 'handle': 'DOC_END()'},
|
||||
]
|
||||
def encode_stream(line):
|
||||
for c in line:
|
||||
if c == '\n':
|
||||
yield '\\n'
|
||||
elif c == '"':
|
||||
yield '\\"'
|
||||
elif c == '\t':
|
||||
yield '\\t'
|
||||
elif ord(c) < 0x20:
|
||||
yield '\\x' + hex(ord(c))
|
||||
else:
|
||||
yield c
|
||||
|
||||
def encode(line):
|
||||
return ''.join(encode_stream(line))
|
||||
|
||||
def doc_start(implicit=False):
|
||||
if implicit:
|
||||
return {'emit': '', 'handle': 'DOC_START()'}
|
||||
else:
|
||||
return {'emit': 'YAML::DocStart', 'handle': 'DOC_START()'}
|
||||
|
||||
def doc_end(implicit=False):
|
||||
if implicit:
|
||||
return {'emit': '', 'handle': 'DOC_END()'}
|
||||
else:
|
||||
return {'emit': 'YAML::DocEnd', 'handle': 'DOC_END()'}
|
||||
|
||||
def scalar(value, tag='', anchor='', anchor_id=0):
|
||||
emit = []
|
||||
if tag:
|
||||
emit += ['YAML::VerbatimTag("%s")' % encode(tag)]
|
||||
if anchor:
|
||||
emit += ['YAML::Anchor("%s")' % encode(anchor)]
|
||||
emit += ['"%s"' % encode(value)]
|
||||
return {'emit': emit, 'handle': 'SCALAR("%s", %s, "%s")' % (encode(tag), anchor_id, encode(value))}
|
||||
|
||||
def gen_outlines():
|
||||
yield [doc_start(), scalar('foo\n'), doc_end()]
|
||||
yield [doc_start(True), scalar('foo\n'), doc_end()]
|
||||
yield [doc_start(), scalar('foo\n'), doc_end(True)]
|
||||
yield [doc_start(True), scalar('foo\n'), doc_end(True)]
|
||||
|
||||
def gen_events():
|
||||
pass
|
||||
for events in gen_outlines():
|
||||
yield events
|
||||
|
||||
def gen_tests():
|
||||
for events in gen_events():
|
||||
@@ -23,11 +62,14 @@ def create_emitter_tests(out):
|
||||
out.write('namespace %s {\n' % NS)
|
||||
|
||||
for test in gen_tests():
|
||||
out.write('TEST %s(YAML::Emitter& out)\n' % test['name'])
|
||||
out.write('inline TEST %s(YAML::Emitter& out)\n' % test['name'])
|
||||
out.write('{\n')
|
||||
for event in test['events']:
|
||||
emit = event['emit']
|
||||
if emit:
|
||||
if isinstance(emit, list):
|
||||
for e in emit:
|
||||
out.write(' out << %s;\n' % e)
|
||||
elif emit:
|
||||
out.write(' out << %s;\n' % emit)
|
||||
out.write('\n')
|
||||
out.write(' HANDLE(out.c_str());\n')
|
||||
|
Reference in New Issue
Block a user