Skip to content

Commit 32b7899

Browse files
more tests
1 parent 3ef0b41 commit 32b7899

13 files changed

+1029
-91
lines changed

gentest/fixtures/grid/YGGridTestFlows.html

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -242,20 +242,6 @@
242242
<div style="width: 100%; height: 100%"></div>
243243
</div>
244244

245-
<!-- Flow 4.2: Expand Flexible Tracks - Indefinite Free Space -->
246-
<!-- This case generates wrong assertions in yoga. So commenting it for now. Debug why yoga tests generate wrong assertions -->
247-
<!-- <div
248-
id="expand_flexible_indefinite_free_space"
249-
style="
250-
display: grid;
251-
grid-template-columns: 1f r 2fr 1fr;
252-
grid-template-rows: 1fr 2fr;
253-
">
254-
<div style="width: 100px; height: 80px"></div>
255-
<div style="width: 150px; height: 120px"></div>
256-
<div style="width: 120px; height: 100px"></div>
257-
</div> -->
258-
259245
<!-- Flow 4.3: Expand Flexible Tracks - With Min Constraint -->
260246
<div
261247
id="expand_flexible_min_constraint"
@@ -373,24 +359,6 @@
373359
<div style="width: 110px; height: 85px"></div>
374360
</div>
375361

376-
<!-- Flow 5.4: Stretch Auto Tracks - No Stretch (normal) -->
377-
<!-- TODO: Add normal alignment support in yoga -->
378-
<!-- <div
379-
id="stretch_auto_no_stretch"
380-
style="
381-
display: grid;
382-
grid-template-columns: auto auto auto;
383-
grid-template-rows: auto auto;
384-
width: 600px;
385-
height: 400px;
386-
justify-content: normal;
387-
align-content: normal;
388-
">
389-
<div style="width: 100px; height: 80px"></div>
390-
<div style="width: 120px; height: 90px"></div>
391-
<div style="width: 110px; height: 85px"></div>
392-
</div> -->
393-
394362
<!-- Flow 6.3: justify-content: center -->
395363
<div
396364
id="justify_content_center"
@@ -833,17 +801,16 @@
833801
</div>
834802

835803
<!-- Flow 11.2: Content-based Minimum - Aspect Ratio Transfer -->
836-
<!-- Test fails because 2/1 gets converted to 2/1 in cpp, which is invalid in int -->
837-
<!-- <div
804+
<div
838805
id="content_based_min_aspect_ratio"
839806
style="
840807
display: grid;
841808
grid-template-columns: auto auto;
842809
grid-template-rows: auto;
843810
">
844-
<div style="width: 150px; aspect-ratio: 2 / 1"></div>
845-
<div style="height: 100px; aspect-ratio: 1 / 2"></div>
846-
</div> -->
811+
<div style="width: 150px; aspect-ratio: 2"></div>
812+
<div style="height: 100px; aspect-ratio: 0.5"></div>
813+
</div>
847814

848815
<!-- Flow 11.3: Content-based Minimum - Content Size Suggestion -->
849816
<div
@@ -1357,37 +1324,6 @@
13571324

13581325
<!-- COMPLEX INTEGRATION TESTS -->
13591326

1360-
<!-- Complex 1: Mixed Tracks with Spanning and Alignment -->
1361-
<!-- <div
1362-
id="complex_mixed_spanning_alignment"
1363-
style="
1364-
display: grid;
1365-
grid-template-columns: 100px auto 1fr 2fr;
1366-
grid-template-rows: 80px auto 1fr;
1367-
width: 600px;
1368-
height: 400px;
1369-
gap: 10px;
1370-
justify-content: space-between;
1371-
align-content: center;
1372-
">
1373-
<div
1374-
style="
1375-
width: 250px;
1376-
height: 100%;
1377-
grid-column-start: 1;
1378-
grid-column-end: 3;
1379-
justify-self: end;
1380-
"></div>
1381-
<div style="width: 100%; height: 80px; align-self: center"></div>
1382-
<div
1383-
style="
1384-
width: 100%;
1385-
height: 200px;
1386-
grid-row-start: 2;
1387-
grid-row-end: 4;
1388-
"></div>
1389-
</div> -->
1390-
13911327

13921328
<!-- Complex 3: Flexible Tracks with Min/Max and Content Distribution -->
13931329
<div
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<div
2+
id="complex_mixed_spanning_alignment"
3+
style="
4+
display: grid;
5+
grid-template-columns: 100px auto 1fr 2fr;
6+
grid-template-rows: 80px auto 1fr;
7+
width: 600px;
8+
height: 400px;
9+
gap: 10px;
10+
justify-content: space-between;
11+
align-content: center;
12+
">
13+
<div
14+
style="
15+
width: 250px;
16+
height: 100%;
17+
grid-column-start: 1;
18+
grid-column-end: 3;
19+
justify-self: end;
20+
"></div>
21+
<div style="width: 100%; height: 80px; align-self: center"></div>
22+
<div
23+
style="
24+
width: 100%;
25+
height: 200px;
26+
grid-row-start: 2;
27+
grid-row-end: 4;
28+
"></div>
29+
</div>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
<!-- Test requires adding a parent div with width set to max-content as test-template adds 2 absolute positioned children which measures min-content on browser but yoga supports max-content. -->
3+
<div style="width: max-content" id="grid_expand_flexible_indefinite_free_space_container">
4+
<div style="display: grid; grid-template-columns: 1fr 2fr 1fr; grid-template-rows: 1fr 2fr;">
5+
<div style="width: 100px; height: 80px"></div>
6+
<div style="width: 150px; height: 120px"></div>
7+
<div style="width: 120px; height: 100px"></div>
8+
</div>
9+
</div>

java/tests/generated/com/facebook/yoga/YGGridTestFlows.java

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<ef5db41c62d975ef58bd049e0ab0fec2>>
7+
* @generated SignedSource<<b8c13ab260838c5a59d378993a6ac8db>>
88
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGGridTestFlows.html
99
*/
1010

@@ -4610,6 +4610,77 @@ public void test_content_based_min_definite_length() {
46104610
assertEquals(120f, root_child1.getLayoutHeight(), 0.0f);
46114611
}
46124612

4613+
@Test
4614+
public void test_content_based_min_aspect_ratio() {
4615+
YogaConfig config = YogaConfigFactory.create();
4616+
4617+
final YogaNode root = createNode(config);
4618+
root.setPositionType(YogaPositionType.ABSOLUTE);
4619+
root.setDisplay(YogaDisplay.GRID);
4620+
YogaGridTrackList rootGridTemplateColumns = new YogaGridTrackList();
4621+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
4622+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
4623+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
4624+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
4625+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
4626+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
4627+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
4628+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
4629+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
4630+
root.setGridTemplateColumns(rootGridTemplateColumns);
4631+
YogaGridTrackList rootGridTemplateRows = new YogaGridTrackList();
4632+
rootGridTemplateRows.addTrack(YogaGridTrackValue.auto());
4633+
rootGridTemplateRows.addTrack(YogaGridTrackValue.auto());
4634+
rootGridTemplateRows.addTrack(YogaGridTrackValue.auto());
4635+
rootGridTemplateRows.addTrack(YogaGridTrackValue.auto());
4636+
root.setGridTemplateRows(rootGridTemplateRows);
4637+
4638+
final YogaNode root_child0 = createNode(config);
4639+
root_child0.setWidth(150f);
4640+
root_child0.setAspectRatio(2 / 1f);
4641+
root.addChildAt(root_child0, 0);
4642+
4643+
final YogaNode root_child1 = createNode(config);
4644+
root_child1.setHeight(100f);
4645+
root_child1.setAspectRatio(0.5 / 1f);
4646+
root.addChildAt(root_child1, 1);
4647+
root.setDirection(YogaDirection.LTR);
4648+
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
4649+
4650+
assertEquals(0f, root.getLayoutX(), 0.0f);
4651+
assertEquals(0f, root.getLayoutY(), 0.0f);
4652+
assertEquals(200f, root.getLayoutWidth(), 0.0f);
4653+
assertEquals(100f, root.getLayoutHeight(), 0.0f);
4654+
4655+
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
4656+
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
4657+
assertEquals(150f, root_child0.getLayoutWidth(), 0.0f);
4658+
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
4659+
4660+
assertEquals(150f, root_child1.getLayoutX(), 0.0f);
4661+
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
4662+
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
4663+
assertEquals(100f, root_child1.getLayoutHeight(), 0.0f);
4664+
4665+
root.setDirection(YogaDirection.RTL);
4666+
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
4667+
4668+
assertEquals(0f, root.getLayoutX(), 0.0f);
4669+
assertEquals(0f, root.getLayoutY(), 0.0f);
4670+
assertEquals(200f, root.getLayoutWidth(), 0.0f);
4671+
assertEquals(100f, root.getLayoutHeight(), 0.0f);
4672+
4673+
assertEquals(50f, root_child0.getLayoutX(), 0.0f);
4674+
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
4675+
assertEquals(150f, root_child0.getLayoutWidth(), 0.0f);
4676+
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
4677+
4678+
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
4679+
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
4680+
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
4681+
assertEquals(100f, root_child1.getLayoutHeight(), 0.0f);
4682+
}
4683+
46134684
@Test
46144685
public void test_content_based_min_content_size() {
46154686
YogaConfig config = YogaConfigFactory.create();
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @generated SignedSource<<97a28795d56fc91f96656fc3c0cd7926>>
8+
* generated by gentest/gentest-driver.ts from gentest/fixtures/grid_complex_mixed_spanning_alignment.html
9+
*/
10+
11+
package com.facebook.yoga;
12+
13+
import static org.junit.Assert.assertEquals;
14+
15+
import org.junit.Ignore;
16+
import org.junit.Test;
17+
import org.junit.runner.RunWith;
18+
import org.junit.runners.Parameterized;
19+
import com.facebook.yoga.utils.TestUtils;
20+
21+
@RunWith(Parameterized.class)
22+
public class grid_complex_mixed_spanning_alignment {
23+
@Parameterized.Parameters(name = "{0}")
24+
public static Iterable<TestParametrization.NodeFactory> nodeFactories() {
25+
return TestParametrization.nodeFactories();
26+
}
27+
28+
@Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory;
29+
30+
@Test
31+
public void test_complex_mixed_spanning_alignment() {
32+
YogaConfig config = YogaConfigFactory.create();
33+
34+
final YogaNode root = createNode(config);
35+
root.setJustifyContent(YogaJustify.SPACE_BETWEEN);
36+
root.setAlignContent(YogaAlign.CENTER);
37+
root.setPositionType(YogaPositionType.ABSOLUTE);
38+
root.setWidth(600f);
39+
root.setHeight(400f);
40+
root.setGap(YogaGutter.COLUMN, 10f);
41+
root.setGap(YogaGutter.ROW, 10f);
42+
root.setDisplay(YogaDisplay.GRID);
43+
YogaGridTrackList rootGridTemplateColumns = new YogaGridTrackList();
44+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
45+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
46+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
47+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
48+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
49+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
50+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
51+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
52+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
53+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
54+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
55+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
56+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
57+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
58+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
59+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
60+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
61+
rootGridTemplateColumns.addTrack(YogaGridTrackValue.auto());
62+
root.setGridTemplateColumns(rootGridTemplateColumns);
63+
YogaGridTrackList rootGridTemplateRows = new YogaGridTrackList();
64+
rootGridTemplateRows.addTrack(YogaGridTrackValue.auto());
65+
rootGridTemplateRows.addTrack(YogaGridTrackValue.auto());
66+
rootGridTemplateRows.addTrack(YogaGridTrackValue.auto());
67+
rootGridTemplateRows.addTrack(YogaGridTrackValue.auto());
68+
rootGridTemplateRows.addTrack(YogaGridTrackValue.auto());
69+
rootGridTemplateRows.addTrack(YogaGridTrackValue.auto());
70+
rootGridTemplateRows.addTrack(YogaGridTrackValue.auto());
71+
rootGridTemplateRows.addTrack(YogaGridTrackValue.auto());
72+
rootGridTemplateRows.addTrack(YogaGridTrackValue.auto());
73+
rootGridTemplateRows.addTrack(YogaGridTrackValue.auto());
74+
rootGridTemplateRows.addTrack(YogaGridTrackValue.auto());
75+
rootGridTemplateRows.addTrack(YogaGridTrackValue.auto());
76+
rootGridTemplateRows.addTrack(YogaGridTrackValue.auto());
77+
root.setGridTemplateRows(rootGridTemplateRows);
78+
79+
final YogaNode root_child0 = createNode(config);
80+
root_child0.setJustifySelf(YogaJustify.END);
81+
root_child0.setWidth(250f);
82+
root_child0.setHeightPercent(100f);
83+
root_child0.setGridColumnStart(1);
84+
root_child0.setGridColumnEnd(3);
85+
root.addChildAt(root_child0, 0);
86+
87+
final YogaNode root_child1 = createNode(config);
88+
root_child1.setAlignSelf(YogaAlign.CENTER);
89+
root_child1.setWidthPercent(100f);
90+
root_child1.setHeight(80f);
91+
root.addChildAt(root_child1, 1);
92+
93+
final YogaNode root_child2 = createNode(config);
94+
root_child2.setWidthPercent(100f);
95+
root_child2.setHeight(200f);
96+
root_child2.setGridRowStart(2);
97+
root_child2.setGridRowEnd(4);
98+
root.addChildAt(root_child2, 2);
99+
root.setDirection(YogaDirection.LTR);
100+
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
101+
102+
assertEquals(0f, root.getLayoutX(), 0.0f);
103+
assertEquals(0f, root.getLayoutY(), 0.0f);
104+
assertEquals(600f, root.getLayoutWidth(), 0.0f);
105+
assertEquals(400f, root.getLayoutHeight(), 0.0f);
106+
107+
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
108+
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
109+
assertEquals(250f, root_child0.getLayoutWidth(), 0.0f);
110+
assertEquals(80f, root_child0.getLayoutHeight(), 0.0f);
111+
112+
assertEquals(260f, root_child1.getLayoutX(), 0.0f);
113+
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
114+
assertEquals(110f, root_child1.getLayoutWidth(), 0.0f);
115+
assertEquals(80f, root_child1.getLayoutHeight(), 0.0f);
116+
117+
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
118+
assertEquals(90f, root_child2.getLayoutY(), 0.0f);
119+
assertEquals(100f, root_child2.getLayoutWidth(), 0.0f);
120+
assertEquals(200f, root_child2.getLayoutHeight(), 0.0f);
121+
122+
root.setDirection(YogaDirection.RTL);
123+
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
124+
125+
assertEquals(0f, root.getLayoutX(), 0.0f);
126+
assertEquals(0f, root.getLayoutY(), 0.0f);
127+
assertEquals(600f, root.getLayoutWidth(), 0.0f);
128+
assertEquals(400f, root.getLayoutHeight(), 0.0f);
129+
130+
assertEquals(350f, root_child0.getLayoutX(), 0.0f);
131+
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
132+
assertEquals(250f, root_child0.getLayoutWidth(), 0.0f);
133+
assertEquals(80f, root_child0.getLayoutHeight(), 0.0f);
134+
135+
assertEquals(230f, root_child1.getLayoutX(), 0.0f);
136+
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
137+
assertEquals(110f, root_child1.getLayoutWidth(), 0.0f);
138+
assertEquals(80f, root_child1.getLayoutHeight(), 0.0f);
139+
140+
assertEquals(500f, root_child2.getLayoutX(), 0.0f);
141+
assertEquals(90f, root_child2.getLayoutY(), 0.0f);
142+
assertEquals(100f, root_child2.getLayoutWidth(), 0.0f);
143+
assertEquals(200f, root_child2.getLayoutHeight(), 0.0f);
144+
}
145+
146+
private YogaNode createNode(YogaConfig config) {
147+
return mNodeFactory.create(config);
148+
}
149+
}

0 commit comments

Comments
 (0)