generate-text-emphasis-position-property-tests.py (3438B)
1 #!/usr/bin/env python 2 # - * - coding: UTF-8 - * - 3 4 """ 5 This script generates tests text-emphasis-position-property-001 ~ 006 6 which cover all possible values of text-emphasis-position property with 7 all combination of three main writing modes and two orientations. Only 8 test files are generated by this script. It also outputs a list of all 9 tests it generated in the format of Mozilla reftest.list to the stdout. 10 """ 11 12 import itertools 13 14 TEST_FILE = 'text-emphasis-position-property-{:03}{}.html' 15 REF_FILE = 'text-emphasis-position-property-{:03}-ref.html' 16 TEST_TEMPLATE = '''<!DOCTYPE html> 17 <meta charset="utf-8"> 18 <!-- This file was generated automatically by the script 19 ./support/generate-text-emphasis-position-property-tests.py --> 20 <title>CSS Test: text-emphasis-position: {value}, {title}</title> 21 <link rel="author" title="Xidorn Quan" href="https://www.upsuper.org"> 22 <link rel="author" title="Mozilla" href="https://www.mozilla.org"> 23 <link rel="help" href="https://drafts.csswg.org/css-text-decor-3/#text-emphasis-position-property"> 24 <meta name="assert" content="'text-emphasis-position: {value}' with 'writing-mode: {wm}' puts emphasis marks {position} the text."> 25 <link rel="match" href="text-emphasis-position-property-{index:03}-ref.html"> 26 <p>Pass if the emphasis marks are {position} the text below:</p> 27 <div lang="ja" style="line-height: 5; text-emphasis: circle; writing-mode: {wm}; text-orientation: {orient}; text-emphasis-position: {value}">試験テスト</div> 28 ''' 29 30 SUFFIXES = ['', 'a', 'b', 'c', 'd', 'e', 'f', 'g'] 31 32 WRITING_MODES = ["horizontal-tb", "vertical-rl", "vertical-lr"] 33 POSITION_HORIZONTAL = ["over", "under"] 34 POSITION_VERTICAL = ["right", "left"] 35 36 REF_MAP_MIXED = { "over": 1, "under": 2, "right": 3, "left": 4 } 37 REF_MAP_SIDEWAYS = { "right": 5, "left": 6 } 38 POSITION_TEXT = { "over": "over", "under": "under", 39 "right": "to the right of", "left": "to the left of" } 40 41 suffixes = [iter(SUFFIXES) for i in range(6)] 42 43 reftest_items = [] 44 45 def write_file(filename, content): 46 with open(filename, 'wb') as f: 47 f.write(content.encode('UTF-8')) 48 49 def write_test_file(idx, suffix, wm, orient, value, position): 50 filename = TEST_FILE.format(idx, suffix) 51 write_file(filename, TEST_TEMPLATE.format( 52 value=value, wm=wm, orient=orient, index=idx, position=position, 53 title=(wm if orient == "mixed" else "{}, {}".format(wm, orient)))) 54 reftest_items.append("== {} {}".format(filename, REF_FILE.format(idx))) 55 56 def write_test_files(wm, orient, pos1, pos2): 57 idx = (REF_MAP_MIXED if orient == "mixed" else REF_MAP_SIDEWAYS)[pos1] 58 position = POSITION_TEXT[pos1] 59 suffix = suffixes[idx - 1] 60 write_test_file(idx, next(suffix), wm, orient, pos1 + " " + pos2, position) 61 write_test_file(idx, next(suffix), wm, orient, pos2 + " " + pos1, position) 62 63 for wm in WRITING_MODES: 64 if wm == "horizontal-tb": 65 effective_pos = POSITION_HORIZONTAL 66 ineffective_pos = POSITION_VERTICAL 67 else: 68 effective_pos = POSITION_VERTICAL 69 ineffective_pos = POSITION_HORIZONTAL 70 for pos1, pos2 in itertools.product(effective_pos, ineffective_pos): 71 write_test_files(wm, "mixed", pos1, pos2) 72 if wm != "horizontal-tb": 73 write_test_files(wm, "sideways", pos1, pos2) 74 75 print("# START tests from {}".format(__file__)) 76 reftest_items.sort() 77 for item in reftest_items: 78 print(item) 79 print("# END tests from {}".format(__file__))