tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

generate-text-emphasis-line-height-tests.py (3660B)


      1 #!/usr/bin/env python
      2 # - * - coding: UTF-8 - * -
      3 
      4 """
      5 This script generates tests text-emphasis-line-height-001 ~ 004 except
      6 001z. They test the line height expansion in different directions. This
      7 script outputs a list of all tests it generated in the format of Mozilla
      8 reftest.list to the stdout.
      9 """
     10 
     11 TEST_FILE = 'text-emphasis-line-height-{: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-line-height-tests.py -->
     16 <title>CSS Test: text-emphasis line height, {pos}, {wm}, {tag}</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-position-property">
     20 <meta name="assert" content="text emphasis marks should expand the line height like ruby if necessary">
     21 <link rel="match" href="text-emphasis-line-height-{index:03}-ref.html">
     22 <p>Pass if the emphasis marks are {dir} the black line:</p>
     23 {start}試験テスト{end}
     24 '''
     25 
     26 REF_FILE = 'text-emphasis-line-height-{: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-line-height-tests.py -->
     31 <title>CSS Reference: text-emphasis line height, {pos}</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 the emphasis marks are {dir} the black line:</p>
     36 <div lang="ja" style="line-height: 1; border-{pos}: 1px solid black; writing-mode: {wm}; ruby-position: {posval}"><ruby>試<rt>&#x25CF;</rt>験<rt>&#x25CF;</rt>テ<rt>&#x25CF;</rt>ス<rt>&#x25CF;</rt>ト<rt>&#x25CF;</rt></ruby></div>
     37 '''
     38 
     39 STYLE1 = 'line-height: 1; border-{pos}: 1px solid black; ' + \
     40         'writing-mode: {wm}; text-emphasis-position: {posval};'
     41 STYLE2 = 'text-emphasis: circle;'
     42 
     43 TAGS = [
     44    # (tag, start, end)
     45    ('div', '<div lang="ja" style="{style1}{style2}">', '</div>'),
     46    ('span', '<div lang="ja" style="{style1}"><span style="{style2}">', '</span></div>'),
     47    ]
     48 POSITIONS = [
     49    # pos, text-emphasis-position, ruby-position,
     50    #   writing-modes, dir text
     51    ('top', 'over right', 'over',
     52        ['horizontal-tb'], 'below'),
     53    ('bottom', 'under right', 'under',
     54        ['horizontal-tb'], 'over'),
     55    ('right', 'over right', 'over',
     56        ['vertical-rl', 'vertical-lr'], 'to the left of'),
     57    ('left', 'over left', 'under',
     58        ['vertical-rl', 'vertical-lr'], 'to the right of'),
     59    ]
     60 
     61 import string
     62 
     63 def write_file(filename, content):
     64    with open(filename, 'wb') as f:
     65        f.write(content.encode('UTF-8'))
     66 
     67 print("# START tests from {}".format(__file__))
     68 idx = 0
     69 for (pos, emphasis_pos, ruby_pos, wms, dir) in POSITIONS:
     70    idx += 1
     71    ref_file = REF_FILE.format(idx)
     72    content = REF_TEMPLATE.format(pos=pos, dir=dir, wm=wms[0], posval=ruby_pos)
     73    write_file(ref_file, content)
     74    suffix = iter(string.ascii_lowercase)
     75    for wm in wms:
     76        style1 = STYLE1.format(pos=pos, wm=wm, posval=emphasis_pos)
     77        for (tag, start, end) in TAGS:
     78            test_file = TEST_FILE.format(idx, next(suffix))
     79            content = TEST_TEMPLATE.format(
     80                pos=pos, wm=wm, tag=tag, index=idx, dir=dir,
     81                start=start.format(style1=style1, style2=STYLE2), end=end)
     82            write_file(test_file, content)
     83            print("== {} {}".format(test_file, ref_file))
     84 print("# END tests from {}".format(__file__))