diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/css/css-text-decor/tools | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/css/css-text-decor/tools')
5 files changed, 404 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/css-text-decor/tools/generate-text-emphasis-line-height-tests.py b/testing/web-platform/tests/css/css-text-decor/tools/generate-text-emphasis-line-height-tests.py new file mode 100644 index 0000000000..e2a4457f38 --- /dev/null +++ b/testing/web-platform/tests/css/css-text-decor/tools/generate-text-emphasis-line-height-tests.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python +# - * - coding: UTF-8 - * - + +""" +This script generates tests text-emphasis-line-height-001 ~ 004 except +001z. They test the line height expansion in different directions. This +script outputs a list of all tests it generated in the format of Mozilla +reftest.list to the stdout. +""" + +TEST_FILE = 'text-emphasis-line-height-{:03}{}.html' +TEST_TEMPLATE = '''<!DOCTYPE html> +<meta charset="utf-8"> +<!-- This file was generated automatically by the script + ./support/generate-text-emphasis-line-height-tests.py --> +<title>CSS Test: text-emphasis line height, {pos}, {wm}, {tag}</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 marks should expand the line height like ruby if necessary"> +<link rel="match" href="text-emphasis-line-height-{index:03}-ref.html"> +<p>Pass if the emphasis marks are {dir} the black line:</p> +{start}試験テスト{end} +''' + +REF_FILE = 'text-emphasis-line-height-{:03}-ref.html' +REF_TEMPLATE='''<!DOCTYPE html> +<meta charset="utf-8"> +<!-- This file was generated automatically by the script + ./support/generate-text-emphasis-line-height-tests.py --> +<title>CSS Reference: text-emphasis line height, {pos}</title> +<link rel="author" title="Xidorn Quan" href="https://www.upsuper.org"> +<link rel="author" title="Mozilla" href="https://www.mozilla.org"> +<style> rt {{ font-variant-east-asian: inherit; }} </style> +<p>Pass if the emphasis marks are {dir} the black line:</p> +<div lang="ja" style="line-height: 1; border-{pos}: 1px solid black; writing-mode: {wm}; ruby-position: {posval}"><ruby>試<rt>●</rt>験<rt>●</rt>テ<rt>●</rt>ス<rt>●</rt>ト<rt>●</rt></ruby></div> +''' + +STYLE1 = 'line-height: 1; border-{pos}: 1px solid black; ' + \ + 'writing-mode: {wm}; text-emphasis-position: {posval};' +STYLE2 = 'text-emphasis: circle;' + +TAGS = [ + # (tag, start, end) + ('div', '<div lang="ja" style="{style1}{style2}">', '</div>'), + ('span', '<div lang="ja" style="{style1}"><span style="{style2}">', '</span></div>'), + ] +POSITIONS = [ + # pos, text-emphasis-position, ruby-position, + # writing-modes, dir text + ('top', 'over right', 'over', + ['horizontal-tb'], 'below'), + ('bottom', 'under right', 'under', + ['horizontal-tb'], 'over'), + ('right', 'over right', 'over', + ['vertical-rl', 'vertical-lr'], 'to the left of'), + ('left', 'over left', 'under', + ['vertical-rl', 'vertical-lr'], 'to the right of'), + ] + +import string + +def write_file(filename, content): + with open(filename, 'wb') as f: + f.write(content.encode('UTF-8')) + +print("# START tests from {}".format(__file__)) +idx = 0 +for (pos, emphasis_pos, ruby_pos, wms, dir) in POSITIONS: + idx += 1 + ref_file = REF_FILE.format(idx) + content = REF_TEMPLATE.format(pos=pos, dir=dir, wm=wms[0], posval=ruby_pos) + write_file(ref_file, content) + suffix = iter(string.ascii_lowercase) + for wm in wms: + style1 = STYLE1.format(pos=pos, wm=wm, posval=emphasis_pos) + for (tag, start, end) in TAGS: + test_file = TEST_FILE.format(idx, next(suffix)) + content = TEST_TEMPLATE.format( + pos=pos, wm=wm, tag=tag, index=idx, dir=dir, + start=start.format(style1=style1, style2=STYLE2), end=end) + write_file(test_file, content) + print("== {} {}".format(test_file, ref_file)) +print("# END tests from {}".format(__file__)) diff --git a/testing/web-platform/tests/css/css-text-decor/tools/generate-text-emphasis-position-property-tests.py b/testing/web-platform/tests/css/css-text-decor/tools/generate-text-emphasis-position-property-tests.py new file mode 100644 index 0000000000..f2baf02332 --- /dev/null +++ b/testing/web-platform/tests/css/css-text-decor/tools/generate-text-emphasis-position-property-tests.py @@ -0,0 +1,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__)) diff --git a/testing/web-platform/tests/css/css-text-decor/tools/generate-text-emphasis-ruby-tests.py b/testing/web-platform/tests/css/css-text-decor/tools/generate-text-emphasis-ruby-tests.py new file mode 100644 index 0000000000..f1158f5f84 --- /dev/null +++ b/testing/web-platform/tests/css/css-text-decor/tools/generate-text-emphasis-ruby-tests.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# - * - coding: UTF-8 - * - + +""" +This script generates tests text-emphasis-ruby-001 ~ 004 which tests +emphasis marks with ruby in four directions. It outputs a list of all +tests it generated in the format of Mozilla reftest.list to the stdout. +""" + +TEST_FILE = 'text-emphasis-ruby-{:03}{}.html' +TEST_TEMPLATE = '''<!DOCTYPE html> +<meta charset="utf-8"> +<!-- This file was generated automatically by the script + ./support/generate-text-emphasis-ruby-tests.py --> +<title>CSS Test: text-emphasis and ruby, {wm}, {pos}</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="emphasis marks are drawn outside the ruby"> +<link rel="match" href="text-emphasis-ruby-{index:03}-ref.html"> +<p>Pass if the emphasis marks are outside the ruby:</p> +<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> +''' + +REF_FILE = 'text-emphasis-ruby-{:03}-ref.html' +REF_TEMPLATE = '''<!DOCTYPE html> +<meta charset="utf-8"> +<!-- This file was generated automatically by the script + ./support/generate-text-emphasis-ruby-tests.py --> +<title>CSS Reference: text-emphasis and ruby, {wm}, {pos}</title> +<link rel="author" title="Xidorn Quan" href="https://www.upsuper.org"> +<link rel="author" title="Mozilla" href="https://www.mozilla.org"> +<style> rtc {{ font-variant-east-asian: inherit; }} </style> +<p>Pass if the emphasis marks are outside the ruby:</p> +<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> +''' + +TEST_CASES = [ + ('top', 'horizontal-tb', 'over', [ + ('horizontal-tb', 'over right')]), + ('bottom', 'horizontal-tb', 'under', [ + ('horizontal-tb', 'under right')]), + ('right', 'vertical-rl', 'over', [ + ('vertical-rl', 'over right'), + ('vertical-lr', 'over right')]), + ('left', 'vertical-rl', 'under', [ + ('vertical-rl', 'over left'), + ('vertical-lr', 'over left')]), + ] + +SUFFIXES = ['', 'a'] + +def write_file(filename, content): + with open(filename, 'wb') as f: + f.write(content.encode('UTF-8')) + +print("# START tests from {}".format(__file__)) +idx = 0 +for pos, ref_wm, ruby_pos, subtests in TEST_CASES: + idx += 1 + ref_file = REF_FILE.format(idx) + ref_content = REF_TEMPLATE.format(pos=pos, wm=ref_wm, posval=ruby_pos) + write_file(ref_file, ref_content) + suffix = iter(SUFFIXES) + for wm, posval in subtests: + test_file = TEST_FILE.format(idx, next(suffix)) + test_content = TEST_TEMPLATE.format( + wm=wm, pos=pos, index=idx, ruby_pos=ruby_pos, posval=posval) + write_file(test_file, test_content) + print("== {} {}".format(test_file, ref_file)) +print("# END tests from {}".format(__file__)) diff --git a/testing/web-platform/tests/css/css-text-decor/tools/generate-text-emphasis-style-property-010-tests.sh b/testing/web-platform/tests/css/css-text-decor/tools/generate-text-emphasis-style-property-010-tests.sh new file mode 100644 index 0000000000..0cf60db1b0 --- /dev/null +++ b/testing/web-platform/tests/css/css-text-decor/tools/generate-text-emphasis-style-property-010-tests.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +# This script generates tests text-emphasis-style-property-010* except +# 010Cn. The tests generated cover all characters listed in the unicode +# data file which should not have emphasis mark specified in the spec. +# This script downloads UnicodeData.txt from the website of the Unicode +# Consortium and extract the characters form that file. It requires +# python (either 2.5+ or 3.x), awk, and wget to work. 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. Other +# information has been redirected to the stderr. + +UNICODE_DATA_FILE='UnicodeData.txt' +UNICODE_DATA_URL="http://www.unicode.org/Public/8.0.0/ucd/$UNICODE_DATA_FILE" +UNICODE_DATA_DIGEST='38b17e1118206489a7e0ab5d29d7932212d38838df7d3ec025ecb58e8798ec20' + +TEST_FILE='text-emphasis-style-property-010%s.html' +REF_FILE='text-emphasis-style-property-010-ref.html' + +digest_file() { + python -c "import hashlib; +print(hashlib.sha256(open('$1', 'rb').read()).hexdigest())" +} + +check_file() { + [[ -f "$UNICODE_DATA_FILE" ]] || return 1 + digest=`digest_file "$UNICODE_DATA_FILE"` + [[ "$digest" == "$UNICODE_DATA_DIGEST" ]] || return 2 +} + +download_data() { + check_file + if [[ $? -eq 2 ]]; then + echo "Removing incorrect data file..." >&2 + rm "$UNICODE_DATA_FILE" + fi + wget -nc -O"$UNICODE_DATA_FILE" "$UNICODE_DATA_URL" >&2 + + check_file + if [[ $? -ne 0 ]]; then + echo "Failed to get the correct unicode data file!" >&2 + exit 1 + fi +} + +list_codepoints() { + awk -F';' "\$3 == \"$1\" { print \" 0x\"\$1\",\" }" "$UNICODE_DATA_FILE" +} + +write_test_file() { + filename=`printf "$TEST_FILE" $1` + echo "== $filename $REF_FILE" + cat <<EOF > $filename +<!DOCTYPE html> +<meta charset="utf-8"> +<!-- This file was generated automatically by the script + ./support/generate-text-emphasis-style-property-010-tests.sh --> +<title>CSS Test: text-emphasis, $1</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-style-property"> +<meta name="assert" content="Emphasis marks should not be rendered for characters in general category $1"> +<link rel="match" href="text-emphasis-style-property-010-ref.html"> +<p>Pass if there is nothing rendered below:</p> +<div style="color: white; white-space: pre-wrap; text-emphasis: filled circle red"> +<script> + var codepoints = [ +`list_codepoints "$1"` + ]; + document.write(codepoints.map(function (code) { + return String.fromCodePoint(code); + }).join(' ')); +</script> +</div> +EOF +} + +download_data +echo "# START tests from $0" +for c in Zs Zl Zp Cc Cf; do + write_test_file "$c" +done +echo "# END tests from $0" diff --git a/testing/web-platform/tests/css/css-text-decor/tools/generate-text-emphasis-style-property-tests.py b/testing/web-platform/tests/css/css-text-decor/tools/generate-text-emphasis-style-property-tests.py new file mode 100644 index 0000000000..b6ad1f7291 --- /dev/null +++ b/testing/web-platform/tests/css/css-text-decor/tools/generate-text-emphasis-style-property-tests.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python +# - * - coding: UTF-8 - * - + +""" +This script generates tests text-emphasis-style-property-011 ~ 020 which +cover all possible values of text-emphasis-style property, except none +and <string>, with horizontal writing mode. It outputs a list of all +tests it generated in the format of Mozilla reftest.list to the stdout. +""" + +TEST_FILE = 'text-emphasis-style-property-{:03}{}.html' +TEST_TEMPLATE = '''<!DOCTYPE html> +<meta charset="utf-8"> +<!-- This file was generated automatically by the script + ./support/generate-text-emphasis-style-property-tests.py --> +<title>CSS Test: text-emphasis-style: {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-style-property"> +<meta name="assert" content="'text-emphasis-style: {value}' produces {code} as emphasis marks."> +<link rel="match" href="text-emphasis-style-property-{index:03}-ref.html"> +<p>Pass if there is a '{char}' above every character below:</p> +<div lang="ja" style="line-height: 5; text-emphasis-style: {value}">試験テスト</div> +''' + +REF_FILE = 'text-emphasis-style-property-{:03}-ref.html' +REF_TEMPLATE = '''<!DOCTYPE html> +<meta charset="utf-8"> +<!-- This file was generated automatically by the script + ./support/generate-text-emphasis-style-property-tests.py --> +<title>CSS Reference: text-emphasis-style: {0}</title> +<link rel="author" title="Xidorn Quan" href="https://www.upsuper.org"> +<link rel="author" title="Mozilla" href="https://www.mozilla.org"> +<style> rt {{ font-variant-east-asian: inherit; }} </style> +<p>Pass if there is a '{1}' above every character below:</p> +<div lang="ja" style="line-height: 5;"><ruby>試<rt>{1}</rt>験<rt>{1}</rt>テ<rt>{1}</rt>ス<rt>{1}</rt>ト<rt>{1}</rt></ruby></div> +''' + +DATA_SET = [ + ('dot', 0x2022, 0x25e6), + ('circle', 0x25cf, 0x25cb), + ('double-circle', 0x25c9, 0x25ce), + ('triangle', 0x25b2, 0x25b3), + ('sesame', 0xfe45, 0xfe46), + ] + +SUFFIXES = ['', 'a', 'b', 'c', 'd', 'e'] + +def get_html_entity(code): + return '&#x{:04X};'.format(code) + +def write_file(filename, content): + with open(filename, 'wb') as f: + f.write(content.encode('UTF-8')) + +def write_test_file(idx, suffix, style, code, name=None): + if not name: + name = style + filename = TEST_FILE.format(idx, suffix) + write_file(filename, TEST_TEMPLATE.format(index=idx, value=style, + char=get_html_entity(code), + code='U+{:04X}'.format(code), + title=name)) + print("== {} {}".format(filename, REF_FILE.format(idx))) + +idx = 10 +def write_files(style, code): + global idx + idx += 1 + fill, shape = style + basic_style = "{} {}".format(fill, shape) + write_file(REF_FILE.format(idx), + REF_TEMPLATE.format(basic_style, get_html_entity(code))) + suffix = iter(SUFFIXES) + write_test_file(idx, next(suffix), basic_style, code) + write_test_file(idx, next(suffix), "{} {}".format(shape, fill), code) + if fill == 'filled': + write_test_file(idx, next(suffix), shape, code) + if shape == 'circle': + write_test_file(idx, next(suffix), fill, code, fill + ', horizontal') + +print("# START tests from {}".format(__file__)) +for name, code, _ in DATA_SET: + write_files(('filled', name), code) +for name, _, code in DATA_SET: + write_files(('open', name), code) +print("# END tests from {}".format(__file__)) |