generate-text-emphasis-style-property-tests.py (3659B)
1 #!/usr/bin/env python 2 # - * - coding: UTF-8 - * - 3 4 """ 5 This script generates tests text-emphasis-style-property-011 ~ 020 which 6 cover all possible values of text-emphasis-style property, except none 7 and <string>, with horizontal writing mode. It outputs a list of all 8 tests it generated in the format of Mozilla reftest.list to the stdout. 9 """ 10 11 TEST_FILE = 'text-emphasis-style-property-{:03}{}.html' 12 TEST_TEMPLATE = '''<!DOCTYPE html> 13 <meta charset="utf-8"> 14 <!-- This file was generated automatically by the script 15 ./support/generate-text-emphasis-style-property-tests.py --> 16 <title>CSS Test: text-emphasis-style: {title}</title> 17 <link rel="author" title="Xidorn Quan" href="https://www.upsuper.org"> 18 <link rel="author" title="Mozilla" href="https://www.mozilla.org"> 19 <link rel="help" href="https://drafts.csswg.org/css-text-decor-3/#text-emphasis-style-property"> 20 <meta name="assert" content="'text-emphasis-style: {value}' produces {code} as emphasis marks."> 21 <link rel="match" href="text-emphasis-style-property-{index:03}-ref.html"> 22 <p>Pass if there is a '{char}' above every character below:</p> 23 <div lang="ja" style="line-height: 5; text-emphasis-style: {value}">試験テスト</div> 24 ''' 25 26 REF_FILE = 'text-emphasis-style-property-{:03}-ref.html' 27 REF_TEMPLATE = '''<!DOCTYPE html> 28 <meta charset="utf-8"> 29 <!-- This file was generated automatically by the script 30 ./support/generate-text-emphasis-style-property-tests.py --> 31 <title>CSS Reference: text-emphasis-style: {0}</title> 32 <link rel="author" title="Xidorn Quan" href="https://www.upsuper.org"> 33 <link rel="author" title="Mozilla" href="https://www.mozilla.org"> 34 <style> rt {{ font-variant-east-asian: inherit; }} </style> 35 <p>Pass if there is a '{1}' above every character below:</p> 36 <div lang="ja" style="line-height: 5;"><ruby>試<rt>{1}</rt>験<rt>{1}</rt>テ<rt>{1}</rt>ス<rt>{1}</rt>ト<rt>{1}</rt></ruby></div> 37 ''' 38 39 DATA_SET = [ 40 ('dot', 0x2022, 0x25e6), 41 ('circle', 0x25cf, 0x25cb), 42 ('double-circle', 0x25c9, 0x25ce), 43 ('triangle', 0x25b2, 0x25b3), 44 ('sesame', 0xfe45, 0xfe46), 45 ] 46 47 SUFFIXES = ['', 'a', 'b', 'c', 'd', 'e'] 48 49 def get_html_entity(code): 50 return '&#x{:04X};'.format(code) 51 52 def write_file(filename, content): 53 with open(filename, 'wb') as f: 54 f.write(content.encode('UTF-8')) 55 56 def write_test_file(idx, suffix, style, code, name=None): 57 if not name: 58 name = style 59 filename = TEST_FILE.format(idx, suffix) 60 write_file(filename, TEST_TEMPLATE.format(index=idx, value=style, 61 char=get_html_entity(code), 62 code='U+{:04X}'.format(code), 63 title=name)) 64 print("== {} {}".format(filename, REF_FILE.format(idx))) 65 66 idx = 10 67 def write_files(style, code): 68 global idx 69 idx += 1 70 fill, shape = style 71 basic_style = "{} {}".format(fill, shape) 72 write_file(REF_FILE.format(idx), 73 REF_TEMPLATE.format(basic_style, get_html_entity(code))) 74 suffix = iter(SUFFIXES) 75 write_test_file(idx, next(suffix), basic_style, code) 76 write_test_file(idx, next(suffix), "{} {}".format(shape, fill), code) 77 if fill == 'filled': 78 write_test_file(idx, next(suffix), shape, code) 79 if shape == 'circle': 80 write_test_file(idx, next(suffix), fill, code, fill + ', horizontal') 81 82 print("# START tests from {}".format(__file__)) 83 for name, code, _ in DATA_SET: 84 write_files(('filled', name), code) 85 for name, _, code in DATA_SET: 86 write_files(('open', name), code) 87 print("# END tests from {}".format(__file__))