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