generate-text-emphasis-ruby-tests.py (3247B)
1 #!/usr/bin/env python 2 # - * - coding: UTF-8 - * - 3 4 """ 5 This script generates tests text-emphasis-ruby-001 ~ 004 which tests 6 emphasis marks with ruby in four directions. It outputs a list of all 7 tests it generated in the format of Mozilla reftest.list to the stdout. 8 """ 9 10 TEST_FILE = 'text-emphasis-ruby-{:03}{}.html' 11 TEST_TEMPLATE = '''<!DOCTYPE html> 12 <meta charset="utf-8"> 13 <!-- This file was generated automatically by the script 14 ./support/generate-text-emphasis-ruby-tests.py --> 15 <title>CSS Test: text-emphasis and ruby, {wm}, {pos}</title> 16 <link rel="author" title="Xidorn Quan" href="https://www.upsuper.org"> 17 <link rel="author" title="Mozilla" href="https://www.mozilla.org"> 18 <link rel="help" href="https://drafts.csswg.org/css-text-decor-3/#text-emphasis-position-property"> 19 <meta name="assert" content="emphasis marks are drawn outside the ruby"> 20 <link rel="match" href="text-emphasis-ruby-{index:03}-ref.html"> 21 <p>Pass if the emphasis marks are outside the ruby:</p> 22 <div lang="ja" style="line-height: 5; writing-mode: {wm}; ruby-position: {ruby_pos}; text-emphasis-position: {posval}">ルビ<span style="text-emphasis: circle">と<ruby>圏<rt>けん</rt>点<rt>てん</rt></ruby>を</span>同時</div> 23 ''' 24 25 REF_FILE = 'text-emphasis-ruby-{:03}-ref.html' 26 REF_TEMPLATE = '''<!DOCTYPE html> 27 <meta charset="utf-8"> 28 <!-- This file was generated automatically by the script 29 ./support/generate-text-emphasis-ruby-tests.py --> 30 <title>CSS Reference: text-emphasis and ruby, {wm}, {pos}</title> 31 <link rel="author" title="Xidorn Quan" href="https://www.upsuper.org"> 32 <link rel="author" title="Mozilla" href="https://www.mozilla.org"> 33 <style> rtc {{ font-variant-east-asian: inherit; }} </style> 34 <p>Pass if the emphasis marks are outside the ruby:</p> 35 <div lang="ja" style="line-height: 5; writing-mode: {wm}; ruby-position: {posval}">ルビ<ruby>と<rtc>●</rtc>圏<rt>けん</rt><rtc>●</rtc>点<rt>てん</rt><rtc>●</rtc>を<rtc>●</rtc></ruby>同時</div> 36 ''' 37 38 TEST_CASES = [ 39 ('top', 'horizontal-tb', 'over', [ 40 ('horizontal-tb', 'over right')]), 41 ('bottom', 'horizontal-tb', 'under', [ 42 ('horizontal-tb', 'under right')]), 43 ('right', 'vertical-rl', 'over', [ 44 ('vertical-rl', 'over right'), 45 ('vertical-lr', 'over right')]), 46 ('left', 'vertical-rl', 'under', [ 47 ('vertical-rl', 'over left'), 48 ('vertical-lr', 'over left')]), 49 ] 50 51 SUFFIXES = ['', 'a'] 52 53 def write_file(filename, content): 54 with open(filename, 'wb') as f: 55 f.write(content.encode('UTF-8')) 56 57 print("# START tests from {}".format(__file__)) 58 idx = 0 59 for pos, ref_wm, ruby_pos, subtests in TEST_CASES: 60 idx += 1 61 ref_file = REF_FILE.format(idx) 62 ref_content = REF_TEMPLATE.format(pos=pos, wm=ref_wm, posval=ruby_pos) 63 write_file(ref_file, ref_content) 64 suffix = iter(SUFFIXES) 65 for wm, posval in subtests: 66 test_file = TEST_FILE.format(idx, next(suffix)) 67 test_content = TEST_TEMPLATE.format( 68 wm=wm, pos=pos, index=idx, ruby_pos=ruby_pos, posval=posval) 69 write_file(test_file, test_content) 70 print("== {} {}".format(test_file, ref_file)) 71 print("# END tests from {}".format(__file__))