File: generate-text-emphasis-position-property-tests.py

package info (click to toggle)
thunderbird 1%3A140.3.1esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,608,628 kB
  • sloc: cpp: 7,671,698; javascript: 5,901,131; ansic: 3,898,955; python: 1,413,270; xml: 653,997; asm: 462,284; java: 180,948; sh: 113,489; makefile: 20,460; perl: 14,288; objc: 13,059; yacc: 4,583; pascal: 3,352; lex: 1,720; ruby: 1,222; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (79 lines) | stat: -rw-r--r-- 3,438 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
# - * - coding: UTF-8 - * -

"""
This script generates tests text-emphasis-position-property-001 ~ 006
which cover all possible values of text-emphasis-position property with
all combination of three main writing modes and two orientations. Only
test files are generated by this script. It also outputs a list of all
tests it generated in the format of Mozilla reftest.list to the stdout.
"""

import itertools

TEST_FILE = 'text-emphasis-position-property-{:03}{}.html'
REF_FILE = 'text-emphasis-position-property-{:03}-ref.html'
TEST_TEMPLATE = '''<!DOCTYPE html>
<meta charset="utf-8">
<!-- This file was generated automatically by the script
     ./support/generate-text-emphasis-position-property-tests.py -->
<title>CSS Test: text-emphasis-position: {value}, {title}</title>
<link rel="author" title="Xidorn Quan" href="https://www.upsuper.org">
<link rel="author" title="Mozilla" href="https://www.mozilla.org">
<link rel="help" href="https://drafts.csswg.org/css-text-decor-3/#text-emphasis-position-property">
<meta name="assert" content="'text-emphasis-position: {value}' with 'writing-mode: {wm}' puts emphasis marks {position} the text.">
<link rel="match" href="text-emphasis-position-property-{index:03}-ref.html">
<p>Pass if the emphasis marks are {position} the text below:</p>
<div lang="ja" style="line-height: 5; text-emphasis: circle; writing-mode: {wm}; text-orientation: {orient}; text-emphasis-position: {value}">試験テスト</div>
'''

SUFFIXES = ['', 'a', 'b', 'c', 'd', 'e', 'f', 'g']

WRITING_MODES = ["horizontal-tb", "vertical-rl", "vertical-lr"]
POSITION_HORIZONTAL = ["over", "under"]
POSITION_VERTICAL = ["right", "left"]

REF_MAP_MIXED = { "over": 1, "under": 2, "right": 3, "left": 4 }
REF_MAP_SIDEWAYS = { "right": 5, "left": 6 }
POSITION_TEXT = { "over": "over", "under": "under",
                  "right": "to the right of", "left": "to the left of" }

suffixes = [iter(SUFFIXES) for i in range(6)]

reftest_items = []

def write_file(filename, content):
    with open(filename, 'wb') as f:
        f.write(content.encode('UTF-8'))

def write_test_file(idx, suffix, wm, orient, value, position):
    filename = TEST_FILE.format(idx, suffix)
    write_file(filename, TEST_TEMPLATE.format(
        value=value, wm=wm, orient=orient, index=idx, position=position,
        title=(wm if orient == "mixed" else "{}, {}".format(wm, orient))))
    reftest_items.append("== {} {}".format(filename, REF_FILE.format(idx)))

def write_test_files(wm, orient, pos1, pos2):
    idx = (REF_MAP_MIXED if orient == "mixed" else REF_MAP_SIDEWAYS)[pos1]
    position = POSITION_TEXT[pos1]
    suffix = suffixes[idx - 1]
    write_test_file(idx, next(suffix), wm, orient, pos1 + " " + pos2, position)
    write_test_file(idx, next(suffix), wm, orient, pos2 + " " + pos1, position)

for wm in WRITING_MODES:
    if wm == "horizontal-tb":
        effective_pos = POSITION_HORIZONTAL
        ineffective_pos = POSITION_VERTICAL
    else:
        effective_pos = POSITION_VERTICAL
        ineffective_pos = POSITION_HORIZONTAL
    for pos1, pos2 in itertools.product(effective_pos, ineffective_pos):
        write_test_files(wm, "mixed", pos1, pos2)
        if wm != "horizontal-tb":
            write_test_files(wm, "sideways", pos1, pos2)

print("# START tests from {}".format(__file__))
reftest_items.sort()
for item in reftest_items:
    print(item)
print("# END tests from {}".format(__file__))