Skip to content

Commit

Permalink
Replace writing modes test generation with a Python script
Browse files Browse the repository at this point in the history
This reduces the number of dependencies and allows us to run the
generation as part of CI.
  • Loading branch information
jgraham authored and pull[bot] committed Nov 25, 2023
1 parent 3eec2dc commit 1904891
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 175 deletions.
24 changes: 0 additions & 24 deletions css/css-writing-modes/tools/generators/README.md

This file was deleted.

86 changes: 86 additions & 0 deletions css/css-writing-modes/tools/generators/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env python3
import os
import string

from typing import List, Tuple

test_template = """<h3>{number}: {title}</h3>
<div class="test">
{html}
</div>"""


def generate_test_list() -> List[Tuple[str, str]]:
test_list = [];
outers = [
["inline-block", '<div class="inline-block">', '</div><span class="next">ZZ</span>'],
["float", '<div class="float">', '</div><span class="next">ZZ</span>'],
["table-cell", '<table><tr><td>', '</td><td class="next">ZZ</td></tr></table>']];
middles = [
None,
["inline-block", '<div class="inline-block">', '</div>']];
targets = [
["block", '<div class="target">HH</div>'],
["inline", '<span class="target">HH</span>'],
["block with borders", '<div class="target border">HHH</div>'],
["inline with borders", '<span class="target border">HHH</span>']];
for outer in outers:
for middle in middles:
for target in targets:
title = target[0];
html = target[1];
if middle is not None:
title += " in " + middle[0];
html = middle[1] + html + middle[2];
title = "Shrink-to-fit " + outer[0] + " with a child of orthogonal " + title;
html = outer[1] + html + outer[2];
test_list.append((title, html));
return test_list


def read_template() -> str:
with open("template.html") as f:
return f.read()


def main():
template = read_template()
test_list = generate_test_list()

dest_dir = os.path.abspath(
os.path.join(os.path.dirname(os.path.abspath(__file__)),
os.path.pardir,
os.path.pardir))

for index in range(-1, len(test_list)):
if index == -1:
offset = 0
suffix = ""
tests = test_list
title = "Shrink-to-fit with orthogonal children"
flags = " combo"
else:
offset = index
suffix = string.ascii_letters[index]
tests = [test_list[index]]
title = tests[0][0]
flags = ""

filename = f"orthogonal-parent-shrink-to-fit-001{suffix}.html"

tests_data = []
for idx, (test_title, html) in enumerate(tests):
number = offset + idx + 1
tests_data.append(test_template.format(number=number,
title=test_title,
html=html))

output = template.replace("{{title}}", title)
output = output.replace("{{flags}}", flags)
output = output.replace("{{tests}}", "\n".join(tests_data))
with open(os.path.join(dest_dir, filename), "w") as f:
f.write(output)


if __name__ == "__main__":
main()
79 changes: 0 additions & 79 deletions css/css-writing-modes/tools/generators/gulpfile.js

This file was deleted.

23 changes: 0 additions & 23 deletions css/css-writing-modes/tools/generators/package.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,48 +1,9 @@
<!DOCTYPE html>
<meta charset="utf-8">
<%
var testlist = [];
var outers = [
["inline-block", '<div class="inline-block">', '</div><span class="next">ZZ</span>'],
["float", '<div class="float">', '</div><span class="next">ZZ</span>'],
["table-cell", '<table><tr><td>', '</td><td class="next">ZZ</td></tr></table>']];
var middles = [
null,
["inline-block", '<div class="inline-block">', '</div>']];
var targets = [
["block", '<div class="target">HH</div>'],
["inline", '<span class="target">HH</span>'],
["block with borders", '<div class="target border">HHH</div>'],
["inline with borders", '<span class="target border">HHH</span>']];
for (var outer of outers) {
for (var middle of middles) {
for (var target of targets) {
var title = target[0];
var html = target[1];
if (middle) {
title += " in " + middle[0];
html = middle[1] + html + middle[2];
}
title = "Shrink-to-fit " + outer[0] + " with a child of orthogonal " + title;
html = outer[1] + html + outer[2];
testlist.push([title, html]);
}
}
}
var min, limit, title;
if (index < 0) {
min = 0;
limit = testlist.length;
title = "Shrink-to-fit with orthogonal children"
} else {
min = index;
limit = index + 1;
title = testlist[index][0];
}
%><title>CSS Writing Modes Test: <%= title %></title>
<title>CSS Writing Modes Test: {{title}}</title>
<link rel="help" href="http://www.w3.org/TR/css-writing-modes-3/#orthogonal-flows" title="7.3. Orthogonal Flows">
<meta name="assert" content="<%= title %>">
<meta name="flags" content="ahem dom<%= index < 0 ? ' combo' : ''%>">
<meta name="assert" content="{{title}}">
<meta name="flags" content="ahem dom{{flags}}">
<link rel="author" title="Koji Ishii" href="mailto:kojiishi@gmail.com">
<link rel="reviewer" title="Gérard Talbot" href="http://www.gtalbot.org/BrowserBugsSection/css21testsuite/"> <!-- 2015-12-23 -->
<script src="/resources/testharness.js"></script>
Expand Down Expand Up @@ -88,13 +49,8 @@
<div id="container">
<p>Test passes if the X-position of the <b>left</b> edge of the orange box and the <b>right</b> edge of the blue box are the same.
<p>If script is enabled, there should be one or more PASS and no FAIL.
<% for (var i = min; i < limit; ++i) {
var test = testlist[i];
%><h3><%= (i + 1) + ": " + test[0] %></h3>
<div class="test">
<%- test[1] %>
{{tests}}
</div>
<% } %></div>
<script>
if (window.location.search == "?wait") {
console.log("Sleeping 5 secs for debug");
Expand Down
3 changes: 2 additions & 1 deletion lint.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ INDENT TABS: css/WOFF2/*
CONSOLE: css/css-shapes/shape-outside/supported-shapes/support/test-utils.js
CONSOLE: css/css-values/viewport-units-css2-001.html
CONSOLE: css/css-writing-modes/orthogonal-parent-shrink-to-fit-001*.html
CONSOLE: css/css-writing-modes/tools/generators/gulpfile.js
CONSOLE: css/css-writing-modes/tools/generators/template.html

TRAILING WHITESPACE: css/css-fonts/support/fonts/gsubtest-lookup3.ufo/features.fea

Expand Down Expand Up @@ -492,6 +492,7 @@ SET TIMEOUT: css/css-writing-modes/orthogonal-parent-shrink-to-fit-001v.html
SET TIMEOUT: css/css-writing-modes/orthogonal-parent-shrink-to-fit-001w.html
SET TIMEOUT: css/css-writing-modes/orthogonal-parent-shrink-to-fit-001x.html
SET TIMEOUT: css/css-writing-modes/support/text-orientation.js
SET TIMEOUT: css/css-writing-modes/tools/generators/template.html
SET TIMEOUT: css/CSS2/backgrounds/background-root-101.xht
SET TIMEOUT: css/CSS2/backgrounds/background-root-102.xht
SET TIMEOUT: css/CSS2/backgrounds/background-root-103.xht
Expand Down
1 change: 1 addition & 0 deletions tools/ci/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"update_built": ["update-built-tests\\.sh",
"conformance-checkers/",
"css/css-ui/",
"css/css-writing-modes/",
"html/",
"infrastructure/",
"mimesniff/"],
Expand Down
1 change: 1 addition & 0 deletions tools/ci/update_built.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"conformance-checkers/tools/url.py"],
"css-images": ["css/css-images/tools/generate_object_view_box_tests.py"],
"css-ui": ["css/css-ui/tools/appearance-build-webkit-reftests.py"],
"css-writing-modes": ["css/css-writing-modes/tools/generators/generate.py"],
# FIXME: https://github.com/web-platform-tests/wpt/issues/32060
# "css-text": ["css/css-text/line-breaking/tools/generate-segment-break-transformation-rules-tests.py"],
# "css-text-decor": ["css/css-text-decor/tools/generate-text-emphasis-line-height-tests.py",
Expand Down

0 comments on commit 1904891

Please sign in to comment.