Skip to content

Commit

Permalink
Add legacy text-align support to the test generator
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Jul 28, 2024
1 parent 01e3316 commit b46359c
Show file tree
Hide file tree
Showing 9 changed files with 749 additions and 1 deletion.
11 changes: 11 additions & 0 deletions scripts/gentest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,16 @@ fn generate_node(ident: &str, node: &Value) -> TokenStream {
(quote!(), quote!())
};

let text_align = match style["textAlign"] {
Value::String(ref value) => match value.as_ref() {
"-webkit-left" => quote!(text_align: taffy::style::TextAlign::LegacyLeft,),
"-webkit-right" => quote!(text_align: taffy::style::TextAlign::LegacyRight,),
"-webkit-center" => quote!(text_align: taffy::style::TextAlign::LegacyCenter,),
_ => quote!(),
},
_ => quote!(),
};

let align_items = match style["alignItems"] {
Value::String(ref value) => match value.as_ref() {
"start" => quote!(align_items: Some(taffy::style::AlignItems::Start),),
Expand Down Expand Up @@ -618,6 +628,7 @@ fn generate_node(ident: &str, node: &Value) -> TokenStream {
#box_sizing
#direction
#position
#text_align
#flex_direction
#flex_wrap
#overflow
Expand Down
4 changes: 3 additions & 1 deletion scripts/gentest/test_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,12 @@ function describeElement(e) {

position: parseEnum(e.style.position),
direction: parseEnum(e.style.direction),
flexDirection: parseEnum(e.style.flexDirection),

writingMode: parseEnum(e.style.writingMode),

textAlign: parseEnum(e.style.textAlign),

flexDirection: parseEnum(e.style.flexDirection),
flexWrap: parseEnum(e.style.flexWrap),
overflowX: parseEnum(e.style.overflowX),
overflowY: parseEnum(e.style.overflowY),
Expand Down
18 changes: 18 additions & 0 deletions test_fixtures/block/block_item_text_align_center.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="../../scripts/gentest/test_helper.js"></script>
<link rel="stylesheet" type="text/css" href="../../scripts/gentest/test_base_style.css">
<title>
Test description
</title>
</head>
<body>

<div id="test-root" style="display: block; width: 200px; height: 200px; text-align: -webkit-center;">
<div style="max-width: 100px; height: 50px;"></div>
<div style="max-width: 300px; height: 50px;"></div>
</div>

</body>
</html>
18 changes: 18 additions & 0 deletions test_fixtures/block/block_item_text_align_left.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="../../scripts/gentest/test_helper.js"></script>
<link rel="stylesheet" type="text/css" href="../../scripts/gentest/test_base_style.css">
<title>
Test description
</title>
</head>
<body>

<div id="test-root" style="display: block; width: 200px; height: 200px; text-align: -webkit-left;">
<div style="max-width: 100px; height: 50px;"></div>
<div style="max-width: 300px; height: 50px;"></div>
</div>

</body>
</html>
18 changes: 18 additions & 0 deletions test_fixtures/block/block_item_text_align_right.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="../../scripts/gentest/test_helper.js"></script>
<link rel="stylesheet" type="text/css" href="../../scripts/gentest/test_base_style.css">
<title>
Test description
</title>
</head>
<body>

<div id="test-root" style="display: block; width: 200px; height: 200px; text-align: -webkit-right;">
<div style="max-width: 100px; height: 50px;"></div>
<div style="max-width: 300px; height: 50px;"></div>
</div>

</body>
</html>
226 changes: 226 additions & 0 deletions tests/generated/block/block_item_text_align_center.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b46359c

Please sign in to comment.