swc/crates/swc_ecma_transforms/scripts/fixtures.py

66 lines
1.8 KiB
Python
Raw Normal View History

2019-12-09 15:02:51 +03:00
#!/usr/bin/env python3
from os import listdir
from os.path import isfile, join
files = [f for f in listdir('./fixtures') if isfile(join('./fixtures', f))]
fm = {}
for f in files:
name = join('./fixtures', f)
2019-12-09 15:02:51 +03:00
if '.DS_Store' in f:
continue
test_name, file_type = f.rsplit('_', 1)
if file_type == 'input.mjs':
file_type = 'input.js'
if file_type == 'input.mjsz':
file_type = 'input.js'
if file_type == 'output.mjs':
file_type = 'output.js'
if file_type == 'output.mjsz':
file_type = 'output.js'
2019-12-09 15:02:51 +03:00
if file_type == 'exec.mjs':
file_type = 'exec.js'
if file_type == 'exec.mjsz':
file_type = 'exec.js'
if not test_name in fm:
fm[test_name] = {}
with open(name, "r") as f:
fm[test_name][file_type] = f.read()
2019-12-09 15:02:51 +03:00
for name in fm:
m = fm[name]
name = name.replace('-', '_')
print()
print('// {}'.format(name))
if 'exec.js' in m:
2019-12-09 15:02:51 +03:00
if 'options.json' in m:
print('test_exec!(syntax(), |_| tr(r#"{}"#), {}_exec, r#"\n{}\n"#);'.format(
m['options.json'],name, m['exec.js']
))
else:
print('test_exec!(syntax(), |_| tr(Default::default()), {}_exec, r#"\n{}\n"#);'.format(
name, m['exec.js']
))
elif 'input.js' in m and 'output.js' in m:
2019-12-09 15:02:51 +03:00
if 'options.json' in m:
print('test!(syntax(),|_| tr(r#"{}"#), {}, r#"\n{}\n"#, r#"\n{}\n"#);'.format(
m['options.json'], name, m['input.js'], m['output.js']
))
else:
print('test!(syntax(),|_| tr(Default::default()), {}, r#"\n{}\n"#, r#"\n{}\n"#);'.format(
name, m['input.js'], m['output.js']
))
elif 'stdout.txt' in m:
pass
else:
print(m.keys())
2019-12-09 15:02:51 +03:00
raise Exception(name, m)