File: build_mantests.py

package info (click to toggle)
jq 1.8.1-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,844 kB
  • sloc: ansic: 28,064; yacc: 888; sh: 841; python: 316; cpp: 314; lex: 192; makefile: 181; javascript: 34
file content (21 lines) | stat: -rwxr-xr-x 872 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python3
import yaml
import re

regex_program_pattern = re.compile(
    r'\b(?:test|match|capture|scan|split|splits|sub|gsub)\s*\(')

with open('content/manual/dev/manual.yml') as source, \
        open('../tests/man.test', 'w') as man, \
        open('../tests/manonig.test', 'w') as manonig:
    manual = yaml.safe_load(source)
    for section in manual.get('sections', []):
        for entry in section.get('entries', []):
            for example in entry.get('examples', []):
                program = example.get('program', '').replace('\n', ' ')
                out = manonig if regex_program_pattern.search(program) else man
                print(program, file=out)
                print(example.get('input', ''), file=out)
                for s in example.get('output', []):
                    print(s, file=out)
                print('', file=out)