build_mantests.py
This file
Path
docs/build_mantests.py
21 lines · 872 bytes · Python
Last changed by
Not known.
History of this fileTake it
1#!/usr/bin/env python32import yaml3import re45regex_program_pattern = re.compile(6 r'\b(?:test|match|capture|scan|split|splits|sub|gsub)\s*\(')78with open('content/manual/dev/manual.yml') as source, \9 open('../tests/man.test', 'w') as man, \10 open('../tests/manonig.test', 'w') as manonig:11 manual = yaml.safe_load(source)12 for section in manual.get('sections', []):13 for entry in section.get('entries', []):14 for example in entry.get('examples', []):15 program = example.get('program', '').replace('\n', ' ')16 out = manonig if regex_program_pattern.search(program) else man17 print(program, file=out)18 print(example.get('input', ''), file=out)19 for s in example.get('output', []):20 print(s, file=out)21 print('', file=out)